These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | //$Id: addTicket.php,v 1.88 2006/01/03 20:40:33 eric_juden Exp $ |
||
3 | if(isset($_GET['deptid'])){ |
||
4 | $dept_id = intval($_GET['deptid']); |
||
5 | } |
||
6 | |||
7 | if(isset($_GET['view_id'])){ |
||
8 | $view_id = intval($_GET['view_id']); |
||
9 | setCookie("xhelp_logMode", $view_id,time()+60*60*24*30); |
||
10 | if(isset($dept_id)){ |
||
11 | header("Location: addTicket.php&deptid=$dept_id"); |
||
12 | } else { |
||
13 | header("Location: addTicket.php"); |
||
14 | } |
||
15 | } else { |
||
16 | if(!isset($_COOKIE['xhelp_logMode'])){ |
||
17 | setCookie("xhelp_logMode", 1, time()+60*60*24*30); |
||
18 | } else { |
||
19 | setCookie("xhelp_logMode", $_COOKIE['xhelp_logMode'], time()+60*60*24*30); |
||
20 | } |
||
21 | } |
||
22 | |||
23 | require_once('header.php'); |
||
24 | require_once(XHELP_INCLUDE_PATH.'/events.php'); |
||
25 | |||
26 | /* $_eventsrv->advise('new_ticket', xhelp_notificationService::singleton()); |
||
27 | $_eventsrv->advise('new_ticket', xhelp_logService::singleton()); |
||
28 | $_eventsrv->advise('new_ticket', xhelp_cacheService::singleton()); |
||
29 | $_eventsrv->advise('new_response', xhelp_logService::singleton()); |
||
30 | $_eventsrv->advise('new_response', xhelp_notificationService::singleton()); |
||
31 | $_eventsrv->advise('update_owner', xhelp_notificationService::singleton()); |
||
32 | $_eventsrv->advise('update_owner', xhelp_logService::singleton()); */ |
||
33 | |||
34 | $hTicket =& xhelpGetHandler('ticket'); |
||
35 | $hStaff =& xhelpGetHandler('staff'); |
||
36 | $hGroupPerm =& xoops_gethandler('groupperm'); |
||
37 | $hMember =& xoops_gethandler('member'); |
||
38 | $hMembership =& xhelpGetHandler('membership'); |
||
39 | $hFieldDept =& xhelpGetHandler('ticketFieldDepartment'); |
||
40 | |||
41 | $module_id = $xoopsModule->getVar('mid'); |
||
42 | |||
43 | if($xoopsUser){ |
||
44 | if(!isset($dept_id)){ |
||
45 | $dept_id = xhelpGetMeta("default_department"); |
||
46 | } |
||
47 | |||
48 | if(isset($_GET['saveTicket']) && $_GET['saveTicket'] == 1){ |
||
49 | _saveTicket(); |
||
50 | } |
||
51 | |||
52 | if(!isset($_POST['addTicket'])){ // Initial load of page |
||
53 | $xoopsOption['template_main'] = 'xhelp_addTicket.html'; // Always set main template before including the header |
||
54 | include(XOOPS_ROOT_PATH . '/header.php'); |
||
55 | |||
56 | $hDepartments =& xhelpGetHandler('department'); // Department handler |
||
57 | $crit = new Criteria('',''); |
||
58 | $crit->setSort('department'); |
||
59 | $departments =& $hDepartments->getObjects($crit); |
||
60 | View Code Duplication | if(count($departments) == 0){ |
|
61 | $message = _XHELP_MESSAGE_NO_DEPTS; |
||
62 | redirect_header(XHELP_BASE_URL."/index.php", 3, $message); |
||
63 | } |
||
64 | $aDept = array(); |
||
65 | $myGroups =& $hMember->getGroupsByUser($xoopsUser->getVar('uid')); |
||
66 | if(($xhelp_isStaff) && ($xoopsModuleConfig['xhelp_deptVisibility'] == 0)){ // If staff are not applied |
||
67 | View Code Duplication | foreach($departments as $dept){ |
|
68 | $deptid = $dept->getVar('id'); |
||
69 | $aDept[] = array('id'=>$deptid, |
||
70 | 'department'=>$dept->getVar('department')); |
||
71 | } |
||
72 | } else { |
||
73 | foreach($departments as $dept){ |
||
74 | $deptid = $dept->getVar('id'); |
||
75 | foreach($myGroups as $group){ // Check for user to be in multiple groups |
||
76 | if($hGroupPerm->checkRight(_XHELP_GROUP_PERM_DEPT, $deptid, $group, $module_id)){ |
||
77 | //Assign the first value to $dept_id incase the default department property not set |
||
78 | if ($dept_id == null) { |
||
79 | $dept_id = $deptid; |
||
80 | } |
||
81 | $aDept[] = array('id'=>$deptid, |
||
82 | 'department'=>$dept->getVar('department')); |
||
83 | break; |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | |||
89 | // User Dept visibility check |
||
90 | if(empty($aDept)){ |
||
91 | $message = _XHELP_MESSAGE_NO_DEPTS; |
||
92 | redirect_header(XHELP_BASE_URL."/index.php", 3, $message); |
||
93 | } |
||
94 | |||
95 | $xoopsTpl->assign('xhelp_isUser', true); |
||
96 | |||
97 | if($xhelp_isStaff){ |
||
98 | $checkStaff =& $hStaff->getByUid($xoopsUser->getVar('uid')); |
||
99 | View Code Duplication | if(!$hasRights = $checkStaff->checkRoleRights(XHELP_SEC_TICKET_ADD)){ |
|
100 | $message = _XHELP_MESSAGE_NO_ADD_TICKET; |
||
101 | redirect_header(XHELP_BASE_URL."/index.php", 3, $message); |
||
102 | } |
||
103 | unset($checkStaff); |
||
104 | |||
105 | if($hasRights = $xhelp_staff->checkRoleRights(XHELP_SEC_TICKET_OWNERSHIP, $dept_id)){ |
||
106 | $staff =& $hMembership->xoopsUsersByDept($dept_id); |
||
107 | |||
108 | $aOwnership = array(); |
||
109 | $aOwnership[0] = _XHELP_NO_OWNER; |
||
110 | foreach($staff as $stf){ |
||
111 | $aOwnership[$stf->getVar('uid')] = $stf->getVar('uname'); |
||
112 | } |
||
113 | $xoopsTpl->assign('xhelp_aOwnership', $aOwnership); |
||
114 | } else { |
||
115 | $xoopsTpl->assign('xhelp_aOwnership', false); |
||
116 | } |
||
117 | } |
||
118 | |||
119 | $has_mimes = false; |
||
120 | if($xoopsModuleConfig['xhelp_allowUpload']){ |
||
121 | // Get available mimetypes for file uploading |
||
122 | $hMime =& xhelpGetHandler('mimetype'); |
||
123 | $xhelp =& xhelpGetModule(); |
||
124 | $mid = $xhelp->getVar('mid'); |
||
125 | if(!$xhelp_isStaff){ |
||
126 | $crit = new Criteria('mime_user', 1); |
||
127 | } else { |
||
128 | $crit = new Criteria('mime_admin', 1); |
||
129 | } |
||
130 | $mimetypes =& $hMime->getObjects($crit); |
||
131 | $mimes = ''; |
||
132 | View Code Duplication | foreach($mimetypes as $mime){ |
|
133 | if($mimes == ''){ |
||
134 | $mimes = $mime->getVar('mime_ext'); |
||
135 | } else { |
||
136 | $mimes .= ", " . $mime->getVar('mime_ext'); |
||
137 | } |
||
138 | } |
||
139 | $xoopsTpl->assign('xhelp_mimetypes', $mimes); |
||
140 | } |
||
141 | |||
142 | $xoopsTpl->assign('xhelp_has_logUser', false); |
||
143 | if($xhelp_isStaff){ |
||
144 | $checkStaff =& $hStaff->getByUid($xoopsUser->getVar('uid')); |
||
145 | if($hasRights = $checkStaff->checkRoleRights(XHELP_SEC_TICKET_LOGUSER)){ |
||
146 | $xoopsTpl->assign('xhelp_has_logUser', true); |
||
147 | } |
||
148 | unset($checkStaff); |
||
149 | } |
||
150 | |||
151 | // Get current dept's custom fields |
||
152 | $fields =& $hFieldDept->fieldsByDepartment($dept_id, true); |
||
153 | |||
154 | if (!$savedFields =& $_xhelpSession->get('xhelp_custFields')) { |
||
155 | $savedFields = array(); |
||
156 | } |
||
157 | |||
158 | $aFields = array(); |
||
159 | View Code Duplication | foreach($fields as $field){ |
|
160 | $values = $field->getVar('fieldvalues'); |
||
161 | if ($field->getVar('controltype') == XHELP_CONTROL_YESNO) { |
||
162 | $values = array(1 => _YES, 0 => _NO); |
||
163 | } |
||
164 | |||
165 | // Check for values already submitted, and fill those values in |
||
166 | if(array_key_exists($field->getVar('fieldname'), $savedFields)){ |
||
167 | $defaultValue = $savedFields[$field->getVar('fieldname')]; |
||
168 | } else { |
||
169 | $defaultValue = $field->getVar('defaultvalue'); |
||
170 | } |
||
171 | |||
172 | $aFields[$field->getVar('id')] = |
||
173 | array('name' => $field->getVar('name'), |
||
174 | 'desc' => $field->getVar('description'), |
||
175 | 'fieldname' => $field->getVar('fieldname'), |
||
176 | 'defaultvalue' => $defaultValue, |
||
177 | 'controltype' => $field->getVar('controltype'), |
||
178 | 'required' => $field->getVar('required'), |
||
179 | 'fieldlength' => ($field->getVar('fieldlength') < 50 ? $field->getVar('fieldlength') : 50), |
||
180 | 'maxlength' => $field->getVar('fieldlength'), |
||
181 | 'weight' => $field->getVar('weight'), |
||
182 | 'fieldvalues' => $values, |
||
183 | 'validation' => $field->getVar('validation')); |
||
184 | } |
||
185 | $xoopsTpl->assign('xhelp_custFields', $aFields); |
||
186 | if(!empty($aFields)){ |
||
187 | $xoopsTpl->assign('xhelp_hasCustFields', true); |
||
188 | } else { |
||
189 | $xoopsTpl->assign('xhelp_hasCustFields', false); |
||
190 | } |
||
191 | |||
192 | $javascript = "<script type=\"text/javascript\" src=\"". XHELP_BASE_URL ."/include/functions.js\"></script> |
||
193 | <script type=\"text/javascript\" src='".XHELP_SCRIPT_URL."/addTicketDeptChange.php?client'></script> |
||
194 | <script type=\"text/javascript\"> |
||
195 | <!-- |
||
196 | function departments_onchange() |
||
197 | { |
||
198 | dept = xoopsGetElementById('departments'); |
||
199 | var wl = new xhelpweblib(fieldHandler); |
||
200 | wl.customfieldsbydept(dept.value);\n"; |
||
201 | |||
202 | if($xhelp_isStaff){ |
||
203 | $javascript .= "var w = new xhelpweblib(staffHandler); |
||
204 | w.staffbydept(dept.value);\n"; |
||
205 | } |
||
206 | $javascript .= "} |
||
207 | |||
208 | var staffHandler = { |
||
209 | staffbydept: function(result){"; |
||
210 | if($xhelp_isStaff){ |
||
211 | if (isset($_COOKIE['xhelp_logMode']) && $_COOKIE['xhelp_logMode'] == 2 && $xhelp_staff->checkRoleRights(XHELP_SEC_TICKET_OWNERSHIP, $dept_id)) { |
||
212 | $javascript .= "var sel = gE('owner');"; |
||
213 | $javascript .= "xhelpFillStaffSelect(sel, result);\n"; |
||
214 | } |
||
215 | } |
||
216 | $javascript .= "} |
||
217 | } |
||
218 | |||
219 | var fieldHandler = { |
||
220 | customfieldsbydept: function(result){ |
||
221 | var tbl = gE('tblAddTicket');\n"; |
||
222 | if ($xhelp_isStaff && isset($_COOKIE['xhelp_logMode']) && $_COOKIE['xhelp_logMode'] == 2) { |
||
223 | $javascript.="var beforeele = gE('privResponse');\n"; |
||
224 | } else { |
||
225 | $javascript.="var beforeele = gE('addButtons');\n"; |
||
226 | } |
||
227 | $javascript.="tbody = tbl.tBodies[0];\n"; |
||
228 | $javascript .="xhelpFillCustomFlds(tbody, result, beforeele); |
||
229 | } |
||
230 | } |
||
231 | |||
232 | function window_onload() |
||
233 | { |
||
234 | xhelpDOMAddEvent(xoopsGetElementById('departments'), 'change', departments_onchange, true); |
||
235 | } |
||
236 | |||
237 | window.setTimeout('window_onload()', 1500); |
||
238 | //--> |
||
239 | </script>"; |
||
240 | $xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL); |
||
241 | $xoopsTpl->assign('xhelp_includeURL', XHELP_INCLUDE_URL); |
||
242 | $xoopsTpl->assign('xoops_module_header', $javascript. $xhelp_module_header); |
||
243 | $xoopsTpl->assign('xhelp_allowUpload', $xoopsModuleConfig['xhelp_allowUpload']); |
||
244 | $xoopsTpl->assign('xhelp_text_lookup', _XHELP_TEXT_LOOKUP); |
||
245 | $xoopsTpl->assign('xhelp_text_email', _XHELP_TEXT_EMAIL); |
||
246 | $xoopsTpl->assign('xhelp_imagePath', XOOPS_URL . '/modules/xhelp/images/'); |
||
247 | $xoopsTpl->assign('xhelp_departments', $aDept); |
||
248 | $xoopsTpl->assign('xhelp_current_file', basename(__file__)); |
||
249 | $xoopsTpl->assign('xhelp_priorities', array(5, 4, 3, 2, 1)); |
||
250 | $xoopsTpl->assign('xhelp_priorities_desc', array('5' => _XHELP_PRIORITY5, '4' => _XHELP_PRIORITY4,'3' => _XHELP_PRIORITY3, '2' => _XHELP_PRIORITY2, '1' => _XHELP_PRIORITY1)); |
||
251 | $xoopsTpl->assign('xhelp_default_priority', XHELP_DEFAULT_PRIORITY); |
||
252 | $xoopsTpl->assign('xhelp_currentUser', $xoopsUser->getVar('uid')); |
||
253 | $xoopsTpl->assign('xhelp_numTicketUploads', $xoopsModuleConfig['xhelp_numTicketUploads']); |
||
254 | if(isset($_POST['logFor'])){ |
||
255 | $uid = $_POST['logFor']; |
||
256 | $username = $xoopsUser->getUnameFromId($uid); |
||
257 | $xoopsTpl->assign('xhelp_username', $username); |
||
258 | $xoopsTpl->assign('xhelp_user_id', $uid); |
||
259 | } else { |
||
260 | $uid = $xoopsUser->getVar('uid'); |
||
261 | $username = $xoopsUser->getVar('uname'); |
||
262 | $xoopsTpl->assign('xhelp_username', $username); |
||
263 | $xoopsTpl->assign('xhelp_user_id', $uid); |
||
264 | } |
||
265 | $xoopsTpl->assign('xhelp_isStaff', $xhelp_isStaff); |
||
266 | if(!isset($_COOKIE['xhelp_logMode'])){ |
||
267 | $xoopsTpl->assign('xhelp_logMode', 1); |
||
268 | } else { |
||
269 | $xoopsTpl->assign('xhelp_logMode', $_COOKIE['xhelp_logMode']); |
||
270 | } |
||
271 | |||
272 | if($xhelp_isStaff){ |
||
273 | if(isset($_COOKIE['xhelp_logMode']) && $_COOKIE['xhelp_logMode'] == 2){ |
||
274 | $hStatus =& xhelpGetHandler('status'); |
||
275 | $crit = new Criteria('', ''); |
||
276 | $crit->setSort('description'); |
||
277 | $crit->setOrder('ASC'); |
||
278 | $statuses =& $hStatus->getObjects($crit); |
||
279 | $aStatuses = array(); |
||
280 | View Code Duplication | foreach($statuses as $status){ |
|
281 | $aStatuses[$status->getVar('id')] = array('id' => $status->getVar('id'), |
||
282 | 'desc' => $status->getVar('description'), |
||
283 | 'state' => $status->getVar('state')); |
||
284 | } |
||
285 | |||
286 | $xoopsTpl->assign('xhelp_statuses', $aStatuses); |
||
287 | } |
||
288 | $xoopsTpl->assign('xhelp_savedSearches', $aSavedSearches); |
||
289 | } |
||
290 | |||
291 | $errors = array(); |
||
292 | $aElements = array(); |
||
293 | View Code Duplication | if($validateErrors =& $_xhelpSession->get('xhelp_validateError')){ |
|
294 | foreach($validateErrors as $fieldname=>$error){ |
||
295 | if(!empty($error['errors'])){ |
||
296 | $aElements[] = $fieldname; |
||
297 | foreach($error['errors'] as $err){ |
||
298 | $errors[$fieldname] = $err; |
||
299 | } |
||
300 | } |
||
301 | } |
||
302 | $xoopsTpl->assign('xhelp_errors', $errors); |
||
303 | } else { |
||
304 | $xoopsTpl->assign('xhelp_errors', null); |
||
305 | } |
||
306 | |||
307 | $elements = array('subject', 'description'); |
||
308 | View Code Duplication | foreach($elements as $element){ // Foreach element in the predefined list |
|
309 | $xoopsTpl->assign("xhelp_element_$element", "formButton"); |
||
310 | foreach($aElements as $aElement){ // Foreach that has an error |
||
311 | if($aElement == $element){ // If the names are equal |
||
312 | $xoopsTpl->assign("xhelp_element_$element", "validateError"); |
||
313 | break; |
||
314 | } |
||
315 | } |
||
316 | } |
||
317 | |||
318 | if ($ticket =& $_xhelpSession->get('xhelp_ticket')) { |
||
319 | $xoopsTpl->assign('xhelp_ticket_uid', $ticket['uid']); |
||
320 | $xoopsTpl->assign('xhelp_ticket_username', $xoopsUser->getUnameFromId($ticket['uid'])); |
||
321 | $xoopsTpl->assign('xhelp_ticket_subject', stripslashes($ticket['subject'])); |
||
322 | $xoopsTpl->assign('xhelp_ticket_description', stripslashes($ticket['description'])); |
||
323 | $xoopsTpl->assign('xhelp_ticket_department', $ticket['department']); |
||
324 | $xoopsTpl->assign('xhelp_ticket_priority', $ticket['priority']); |
||
325 | } else { |
||
326 | $xoopsTpl->assign('xhelp_ticket_uid', $uid); |
||
327 | $xoopsTpl->assign('xhelp_ticket_username', $username); |
||
328 | $xoopsTpl->assign('xhelp_ticket_subject', null); |
||
329 | $xoopsTpl->assign('xhelp_ticket_description', null); |
||
330 | $xoopsTpl->assign('xhelp_ticket_department', $dept_id); |
||
331 | $xoopsTpl->assign('xhelp_ticket_priority', XHELP_DEFAULT_PRIORITY); |
||
332 | } |
||
333 | |||
334 | if($response =& $_xhelpSession->get('xhelp_response')){ |
||
335 | $xoopsTpl->assign('xhelp_response_uid', $response['uid']); |
||
336 | $xoopsTpl->assign('xhelp_response_message', $response['message']); |
||
337 | $xoopsTpl->assign('xhelp_response_timespent', $response['timeSpent']); |
||
338 | $xoopsTpl->assign('xhelp_response_userIP', $response['userIP']); |
||
339 | $xoopsTpl->assign('xhelp_response_private', $response['private']); |
||
340 | $xoopsTpl->assign('xhelp_ticket_status', $response['status']); |
||
341 | $xoopsTpl->assign('xhelp_ticket_ownership', $response['owner']); |
||
342 | } else { |
||
343 | $xoopsTpl->assign('xhelp_response_uid', null); |
||
344 | $xoopsTpl->assign('xhelp_response_message', null); |
||
345 | $xoopsTpl->assign('xhelp_response_timeSpent', null); |
||
346 | $xoopsTpl->assign('xhelp_response_userIP', null); |
||
347 | $xoopsTpl->assign('xhelp_response_private', null); |
||
348 | $xoopsTpl->assign('xhelp_ticket_status', 1); |
||
349 | $xoopsTpl->assign('xhelp_ticket_ownership', 0); |
||
350 | } |
||
351 | |||
352 | require(XOOPS_ROOT_PATH.'/footer.php'); //Include the page footer |
||
353 | } else { |
||
354 | $dept_id = intval($_POST['departments']); |
||
355 | |||
356 | require_once(XHELP_CLASS_PATH.'/validator.php'); |
||
357 | $v = array(); |
||
358 | $v['subject'][] = new ValidateLength($_POST['subject'], 2, 255); |
||
359 | $v['description'][] = new ValidateLength($_POST['description'], 2); |
||
360 | |||
361 | // Get current dept's custom fields |
||
362 | $fields =& $hFieldDept->fieldsByDepartment($dept_id, true); |
||
363 | $aFields = array(); |
||
364 | |||
365 | View Code Duplication | foreach($fields as $field){ |
|
366 | $values = $field->getVar('fieldvalues'); |
||
367 | if ($field->getVar('controltype') == XHELP_CONTROL_YESNO) { |
||
368 | $values = array(1 => _YES, 0 => _NO); |
||
369 | } |
||
370 | $fieldname = $field->getVar('fieldname'); |
||
371 | |||
372 | if($field->getVar('controltype') != XHELP_CONTROL_FILE) { |
||
373 | $checkField = $_POST[$fieldname]; |
||
374 | } else { |
||
375 | $checkField = $_FILES[$fieldname]; |
||
376 | } |
||
377 | |||
378 | $v[$fieldname][] = new ValidateRegex($checkField, $field->getVar('validation'), $field->getVar('required')); |
||
379 | |||
380 | $aFields[$field->getVar('id')] = |
||
381 | array('name' => $field->getVar('name'), |
||
382 | 'desc' => $field->getVar('description'), |
||
383 | 'fieldname' => $field->getVar('fieldname'), |
||
384 | 'defaultvalue' => $field->getVar('defaultvalue'), |
||
385 | 'controltype' => $field->getVar('controltype'), |
||
386 | 'required' => $field->getVar('required'), |
||
387 | 'fieldlength' => $field->getVar('fieldlength'), |
||
388 | 'maxlength' => ($field->getVar('fieldlength') < 50 ? $field->getVar('fieldlength') : 50), |
||
389 | 'weight' => $field->getVar('weight'), |
||
390 | 'fieldvalues' => $values, |
||
391 | 'validation' => $field->getVar('validation')); |
||
392 | } |
||
393 | |||
394 | _saveTicket($aFields); // Save ticket information in a session |
||
0 ignored issues
–
show
$aFields is of type array , but the function expects a string .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
395 | |||
396 | // Perform each validation |
||
397 | $fields = array(); |
||
398 | $errors = array(); |
||
399 | View Code Duplication | foreach($v as $fieldname=>$validator) { |
|
400 | if (!xhelpCheckRules($validator, $errors)) { |
||
401 | //Mark field with error |
||
402 | $fields[$fieldname]['haserrors'] = true; |
||
403 | $fields[$fieldname]['errors'] = $errors; |
||
404 | } else { |
||
405 | $fields[$fieldname]['haserrors'] = false; |
||
406 | } |
||
407 | } |
||
408 | |||
409 | View Code Duplication | if(!empty($errors)){ |
|
410 | $_xhelpSession->set('xhelp_validateError', $fields); |
||
411 | $message = _XHELP_MESSAGE_VALIDATE_ERROR; |
||
412 | header("Location: ".XHELP_BASE_URL."/addTicket.php"); |
||
413 | exit(); |
||
414 | } |
||
415 | |||
416 | //$hTicket =& xhelpGetHandler('ticket'); |
||
417 | $ticket =& $hTicket->create(); |
||
418 | $ticket->setVar('uid', $_POST['user_id']); |
||
419 | $ticket->setVar('subject', $_POST['subject']); |
||
420 | $ticket->setVar('description', $_POST['description']); |
||
421 | $ticket->setVar('department', $dept_id); |
||
422 | $ticket->setVar('priority', $_POST['priority']); |
||
423 | if($xhelp_isStaff && $_COOKIE['xhelp_logMode'] == 2){ |
||
424 | $ticket->setVar('status', $_POST['status']); // Set status |
||
425 | if (isset($_POST['owner'])) { //Check if user claimed ownership |
||
426 | if ($_POST['owner'] > 0) { |
||
427 | $oldOwner = 0; |
||
428 | $_xhelpSession->set('xhelp_oldOwner', $oldOwner); |
||
429 | $ticket->setVar('ownership', $_POST['owner']); |
||
430 | $_xhelpSession->set('xhelp_changeOwner', true); |
||
431 | } |
||
432 | } |
||
433 | $_xhelpSession->set('xhelp_ticket_ownership', $_POST['owner']); // Store in session |
||
434 | } else { |
||
435 | $ticket->setVar('status', 1); |
||
436 | } |
||
437 | $ticket->setVar('posted', time()); |
||
438 | $ticket->setVar('userIP', getenv("REMOTE_ADDR")); |
||
439 | $ticket->setVar('overdueTime', $ticket->getVar('posted') + ($xoopsModuleConfig['xhelp_overdueTime'] *60*60)); |
||
440 | |||
441 | $aUploadFiles = array(); |
||
442 | View Code Duplication | if($xoopsModuleConfig['xhelp_allowUpload']){ |
|
443 | foreach($_FILES as $key=>$aFile){ |
||
444 | $pos = strpos($key, 'userfile'); |
||
445 | if($pos !== false && is_uploaded_file($aFile['tmp_name'])){ // In the userfile array and uploaded file? |
||
446 | if ($ret = $ticket->checkUpload($key, $allowed_mimetypes, $errors)) { |
||
447 | $aUploadFiles[$key] = $aFile; |
||
448 | } else { |
||
449 | $errorstxt = implode('<br />', $errors); |
||
450 | $message = sprintf(_XHELP_MESSAGE_FILE_ERROR, $errorstxt); |
||
451 | redirect_header(XHELP_BASE_URL."/addTicket.php", 5, $message); |
||
452 | } |
||
453 | } |
||
454 | } |
||
455 | } |
||
456 | |||
457 | if($hTicket->insert($ticket)){ |
||
458 | |||
459 | $hMember =& xoops_gethandler('member'); |
||
460 | $newUser =& $hMember->getUser($ticket->getVar('uid')); |
||
461 | $ticket->addSubmitter($newUser->getVar('email'), $newUser->getVar('uid')); |
||
462 | |||
463 | View Code Duplication | if(count($aUploadFiles) > 0){ // Has uploaded files? |
|
464 | foreach($aUploadFiles as $key=>$aFile){ |
||
465 | $file = $ticket->storeUpload($key, null, $allowed_mimetypes); |
||
466 | $_eventsrv->trigger('new_file', array(&$ticket, &$file)); |
||
467 | } |
||
468 | } |
||
469 | |||
470 | // Add custom field values to db |
||
471 | $hTicketValues = xhelpGetHandler('ticketValues'); |
||
472 | $ticketValues = $hTicketValues->create(); |
||
473 | |||
474 | View Code Duplication | foreach($aFields as $field){ |
|
475 | $fieldname = $field['fieldname']; |
||
476 | $fieldtype = $field['controltype']; |
||
477 | |||
478 | if($fieldtype == XHELP_CONTROL_FILE){ // If custom field was a file upload |
||
479 | if($xoopsModuleConfig['xhelp_allowUpload']){ // If uploading is allowed |
||
480 | if(is_uploaded_file($_FILES[$fieldname]['tmp_name'])){ |
||
481 | if (!$ret = $ticket->checkUpload($fieldname, $allowed_mimetypes, $errors)) { |
||
482 | $errorstxt = implode('<br />', $errors); |
||
483 | |||
484 | $message = sprintf(_XHELP_MESSAGE_FILE_ERROR, $errorstxt); |
||
485 | redirect_header(XHELP_BASE_URL."/addTicket.php", 5, $message); |
||
486 | } |
||
487 | if($file = $ticket->storeUpload($fieldname, -1, $allowed_mimetypes)){ |
||
488 | $ticketValues->setVar($fieldname, $file->getVar('id') . "_" . $_FILES[$fieldname]['name']); |
||
489 | } |
||
490 | } |
||
491 | } |
||
492 | } else { |
||
493 | $fieldvalue = $_POST[$fieldname]; |
||
494 | $ticketValues->setVar($fieldname, $fieldvalue); |
||
495 | } |
||
496 | } |
||
497 | $ticketValues->setVar('ticketid', $ticket->getVar('id')); |
||
498 | |||
499 | if(!$hTicketValues->insert($ticketValues)){ |
||
500 | $message = _XHELP_MESSAGE_NO_CUSTFLD_ADDED; |
||
501 | } |
||
502 | |||
503 | $_eventsrv->trigger('new_ticket', array(&$ticket)); |
||
504 | |||
505 | if ($_xhelpSession->get('xhelp_changeOwner')) { |
||
506 | $oldOwner = $_xhelpSession->get('xhelp_oldOwner'); |
||
507 | $_eventsrv->trigger('update_owner', array(&$ticket, $oldOwner, $xoopsUser->getVar('uid'))); |
||
508 | $_xhelpSession->del('xhelp_changeOwner'); |
||
509 | $_xhelpSession->del('xhelp_oldOwner'); |
||
510 | $_xhelpSession->del('xhelp_ticket_ownership'); |
||
511 | } |
||
512 | |||
513 | // Add response |
||
514 | if($xhelp_isStaff && $_COOKIE['xhelp_logMode'] == 2){ // Make sure user is a staff member and is using advanced form |
||
515 | if($_POST['response'] != ''){ // Don't run if no value for response |
||
516 | $hResponse =& xhelpGetHandler('responses'); |
||
517 | $newResponse =& $hResponse->create(); |
||
518 | $newResponse->setVar('uid', $xoopsUser->getVar('uid')); |
||
519 | $newResponse->setVar('ticketid', $ticket->getVar('id')); |
||
520 | $newResponse->setVar('message', $_POST['response']); |
||
521 | $newResponse->setVar('timeSpent', $_POST['timespent']); |
||
522 | $newResponse->setVar('updateTime', $ticket->getVar('posted')); |
||
523 | $newResponse->setVar('userIP', $ticket->getVar('userIP')); |
||
524 | if(isset($_POST['private'])){ |
||
525 | $newResponse->setVar('private', $_POST['private']); |
||
526 | } |
||
527 | if($hResponse->insert($newResponse)){ |
||
528 | $_eventsrv->trigger('new_response', array(&$ticket, &$newResponse)); |
||
529 | $_xhelpSession->del('xhelp_response'); |
||
530 | } |
||
531 | } |
||
532 | } |
||
533 | |||
534 | $_xhelpSession->del('xhelp_ticket'); |
||
535 | $_xhelpSession->del('xhelp_validateError'); |
||
536 | $_xhelpSession->del('xhelp_custFields'); |
||
537 | |||
538 | $message = _XHELP_MESSAGE_ADDTICKET; |
||
539 | } else { |
||
540 | //$_xhelpSession->set('xhelp_ticket', $ticket); |
||
541 | $message = _XHELP_MESSAGE_ADDTICKET_ERROR . $ticket->getHtmlErrors(); // Unsuccessfully added new ticket |
||
542 | } |
||
543 | redirect_header(XHELP_BASE_URL."/index.php", 5, $message); |
||
544 | } |
||
545 | } else { // If not a user |
||
546 | $config_handler =& xoops_gethandler('config'); |
||
547 | //$xoopsConfigUser =& $config_handler->getConfigsByCat(XOOPS_CONF_USER); |
||
548 | $xoopsConfigUser = array(); |
||
549 | $crit = new CriteriaCompo(new Criteria('conf_name', 'allow_register'), 'OR'); |
||
550 | $crit->add(new Criteria('conf_name', 'activation_type'), 'OR'); |
||
551 | $myConfigs =& $config_handler->getConfigs($crit); |
||
552 | |||
553 | foreach($myConfigs as $myConf){ |
||
554 | $xoopsConfigUser[$myConf->getVar('conf_name')] = $myConf->getVar('conf_value'); |
||
555 | } |
||
556 | View Code Duplication | if ($xoopsConfigUser['allow_register'] == 0) { // Use to doublecheck that anonymous users are allowed to register |
|
557 | header("Location: ".XHELP_BASE_URL."/error.php"); |
||
558 | } else { |
||
559 | header("Location: ".XHELP_BASE_URL."/anon_addTicket.php"); |
||
560 | } |
||
561 | exit(); |
||
562 | } |
||
563 | |||
564 | function _saveTicket($fields = "") |
||
0 ignored issues
–
show
_saveTicket uses the super-global variable $_POST which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() _saveTicket uses the super-global variable $_COOKIE which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
565 | { |
||
566 | global $_xhelpSession, $xhelp_isStaff; |
||
0 ignored issues
–
show
Compatibility
Best Practice
introduced
by
Use of
global functionality is not recommended; it makes your code harder to test, and less reusable.
Instead of relying on 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
![]() |
|||
567 | $_xhelpSession->set('xhelp_ticket', |
||
568 | array('uid' => $_POST['user_id'], |
||
569 | 'subject' => $_POST['subject'], |
||
570 | 'description' => htmlspecialchars($_POST['description'], ENT_QUOTES), |
||
571 | 'department' => $_POST['departments'], |
||
572 | 'priority' => $_POST['priority'])); |
||
573 | |||
574 | if($xhelp_isStaff && $_COOKIE['xhelp_logMode'] == 2){ |
||
575 | $_xhelpSession->set('xhelp_response', |
||
576 | array('uid' => $_POST['user_id'], |
||
577 | 'message' => $_POST['response'], |
||
578 | 'timeSpent' => $_POST['timespent'], |
||
579 | 'userIP' => getenv("REMOTE_ADDR"), |
||
580 | 'private' => (isset($_POST['private'])) ? 1 : 0, |
||
581 | 'status' => $_POST['status'], |
||
582 | 'owner' => $_POST['owner'])); |
||
583 | } |
||
584 | |||
585 | if($fields != ""){ |
||
586 | $_xhelpSession->set('xhelp_custFields', $fields); |
||
587 | } |
||
588 | |||
589 | return true; |
||
590 | } |
||
591 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.