XoopsModules25x /
xhelp
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php declare(strict_types=1); |
||
| 2 | |||
| 3 | /* |
||
| 4 | * You may not change or alter any portion of this comment or credits |
||
| 5 | * of supporting developers from this source code or any supporting source code |
||
| 6 | * which is considered copyrighted (c) material of the original comment or credit authors. |
||
| 7 | * |
||
| 8 | * This program is distributed in the hope that it will be useful, |
||
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
| 11 | */ |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @copyright {@link https://xoops.org/ XOOPS Project} |
||
| 15 | * @license {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later} |
||
| 16 | * @author Brian Wahoff <[email protected]> |
||
| 17 | * @author Eric Juden <[email protected]> |
||
| 18 | * @author XOOPS Development Team |
||
| 19 | */ |
||
| 20 | |||
| 21 | use Xmf\Request; |
||
| 22 | use XoopsModules\Xhelp; |
||
| 23 | |||
| 24 | require_once __DIR__ . '/header.php'; |
||
| 25 | xoops_load('XoopsPagenav'); |
||
| 26 | |||
| 27 | $helper = Xhelp\Helper::getInstance(); |
||
| 28 | |||
| 29 | /** @var \XoopsModules\Xhelp\StaffHandler $staffHandler */ |
||
| 30 | $staffHandler = $helper->getHandler('Staff'); |
||
| 31 | /** @var \XoopsModules\Xhelp\DepartmentHandler $departmentHandler */ |
||
| 32 | $departmentHandler = $helper->getHandler('Department'); |
||
| 33 | /** @var \XoopsModules\Xhelp\TicketHandler $ticketHandler */ |
||
| 34 | $ticketHandler = $helper->getHandler('Ticket'); |
||
| 35 | /** @var \XoopsModules\Xhelp\SavedSearchHandler $savedSearchHandler */ |
||
| 36 | $savedSearchHandler = $helper->getHandler('SavedSearch'); |
||
| 37 | /** @var \XoopsModules\Xhelp\TicketFieldHandler $ticketFieldHandler */ |
||
| 38 | $ticketFieldHandler = $helper->getHandler('TicketField'); |
||
| 39 | |||
| 40 | if (!$xoopsUser) { |
||
| 41 | redirect_header(XOOPS_URL, 3, _NOPERM); |
||
| 42 | } |
||
| 43 | |||
| 44 | if (!$staffHandler->isStaff($xoopsUser->getVar('uid'))) { |
||
| 45 | $helper->redirect('index.php', 3, _NOPERM); |
||
| 46 | } |
||
| 47 | |||
| 48 | if ($xoopsUser) { |
||
| 49 | $start = $limit = 0; |
||
| 50 | $page_vars = ['limit', 'start', 'sort', 'order']; |
||
| 51 | $sort_order = ['ASC', 'DESC']; |
||
| 52 | $sort = ''; |
||
| 53 | $order = ''; |
||
| 54 | $displayName = $helper->getConfig('xhelp_displayName'); // Determines if username or real name is displayed |
||
| 55 | $returnPage = false; |
||
| 56 | $aReturnPages = ['profile']; |
||
| 57 | if (Request::hasVar('return', 'GET') && in_array($_GET['return'], $aReturnPages)) { |
||
| 58 | $returnPage = $_GET['return']; |
||
| 59 | } |
||
| 60 | |||
| 61 | foreach ($page_vars as $var) { |
||
| 62 | if (isset($_REQUEST[$var])) { |
||
| 63 | $$var = $_REQUEST[$var]; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | $limit = $limit; |
||
| 67 | $start = $start; |
||
| 68 | $sort = \mb_strtolower($sort); |
||
| 69 | $order = (in_array(mb_strtoupper($order), $sort_order) ? $order : 'ASC'); |
||
| 70 | $sort_columns = [ |
||
| 71 | 'id', |
||
| 72 | 'priority', |
||
| 73 | 'elapsed', |
||
| 74 | 'lastupdate', |
||
| 75 | 'status', |
||
| 76 | 'subject', |
||
| 77 | 'department', |
||
| 78 | 'ownership', |
||
| 79 | 'uid', |
||
| 80 | ]; |
||
| 81 | $sort = (in_array($sort, $sort_columns) ? $sort : ''); |
||
| 82 | $hasCustFields = false; |
||
| 83 | |||
| 84 | // Make sure start is greater than 0 |
||
| 85 | $start = max($start, 0); |
||
| 86 | |||
| 87 | // Make sure limit is set |
||
| 88 | if (!$limit) { |
||
| 89 | $limit = $helper->getConfig('xhelp_staffTicketCount'); |
||
| 90 | } |
||
| 91 | |||
| 92 | $pagenav_vars = "limit=$limit"; |
||
| 93 | $uid = $xoopsUser->getVar('uid'); |
||
| 94 | |||
| 95 | $viewResults = false; |
||
| 96 | $op = 'default'; |
||
| 97 | if (Request::hasVar('op', 'REQUEST')) { |
||
| 98 | $op = $_REQUEST['op']; |
||
| 99 | } |
||
| 100 | |||
| 101 | switch ($op) { |
||
| 102 | case 'edit': |
||
| 103 | if (Request::hasVar('id', 'REQUEST') && 0 != $_REQUEST['id']) { |
||
| 104 | $searchid = Request::getInt('id', 0, 'REQUEST'); |
||
| 105 | if (!array_key_exists($searchid, $aSavedSearches)) { |
||
| 106 | if (false !== $returnPage) { |
||
| 107 | $helper->redirect($returnPage . '.php', 3, _XHELP_MSG_NO_EDIT_SEARCH); |
||
| 108 | } else { |
||
| 109 | $helper->redirect('search.php', 3, _XHELP_MSG_NO_EDIT_SEARCH); |
||
| 110 | } |
||
| 111 | } |
||
| 112 | } else { |
||
| 113 | if (false !== $returnPage) { |
||
| 114 | $helper->redirect($returnPage . '.php', 3, _XHELP_MSG_NO_ID); |
||
| 115 | } else { |
||
| 116 | $helper->redirect('search.php', 3, _XHELP_MSG_NO_ID); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | $myDepts = []; |
||
| 120 | $GLOBALS['xoopsOption']['template_main'] = 'xhelp_editSearch.tpl'; // Set template |
||
| 121 | require_once XOOPS_ROOT_PATH . '/header.php'; // Include the page header |
||
| 122 | $mySearch = $savedSearchHandler->get($searchid); |
||
| 123 | $xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL); |
||
| 124 | if (is_object($mySearch)) { // Go through saved search info, set values on page |
||
| 125 | $vars = [ |
||
| 126 | 'ticketid', |
||
| 127 | 'department', |
||
| 128 | 'description', |
||
| 129 | 'subject', |
||
| 130 | 'priority', |
||
| 131 | 'status', |
||
| 132 | 'state', |
||
| 133 | 'uid', |
||
| 134 | 'submittedBy', |
||
| 135 | 'ownership', |
||
| 136 | 'closedBy', |
||
| 137 | ]; |
||
| 138 | $ticketid = ''; |
||
| 139 | $department = -1; |
||
| 140 | $description = ''; |
||
| 141 | $subject = ''; |
||
| 142 | $priority = -1; |
||
| 143 | $status = -1; |
||
| 144 | $state = -1; |
||
| 145 | $uid = ''; |
||
| 146 | $submittedBy = ''; |
||
| 147 | $ownership = ''; |
||
| 148 | $closedBy = ''; |
||
| 149 | |||
| 150 | $fields = $ticketFieldHandler->getObjects(); |
||
| 151 | $aFields = []; |
||
| 152 | $aFieldnames = []; |
||
| 153 | foreach ($fields as $field) { |
||
| 154 | $vars[] = $field->getVar('fieldname'); |
||
| 155 | ${$field->getVar('fieldname')} = ''; |
||
| 156 | $values = $field->getVar('fieldvalues'); |
||
| 157 | if (XHELP_CONTROL_YESNO == $field->getVar('controltype')) { |
||
| 158 | $values = ((1 == $values) ? _YES : _NO); |
||
| 159 | } |
||
| 160 | $defaultValue = $field->getVar('defaultvalue'); |
||
| 161 | $aFields[$field->getVar('id')] = [ |
||
| 162 | 'name' => $field->getVar('name'), |
||
| 163 | 'desc' => $field->getVar('description'), |
||
| 164 | 'fieldname' => $field->getVar('fieldname'), |
||
| 165 | 'defaultvalue' => $defaultValue, |
||
| 166 | 'controltype' => $field->getVar('controltype'), |
||
| 167 | 'required' => $field->getVar('required'), |
||
| 168 | 'fieldlength' => $field->getVar('fieldlength') < 50 ? $field->getVar('fieldlength') : 50, |
||
| 169 | 'maxlength' => $field->getVar('fieldlength'), |
||
| 170 | 'weight' => $field->getVar('weight'), |
||
| 171 | 'fieldvalues' => $values, |
||
| 172 | 'validation' => $field->getVar('validation'), |
||
| 173 | ]; |
||
| 174 | $aFieldnames[$field->getVar('id')] = $field->getVar('fieldname'); |
||
| 175 | } |
||
| 176 | unset($fields); |
||
| 177 | |||
| 178 | $criteria = unserialize($mySearch->getVar('search')); |
||
| 179 | $pagenav_vars = $mySearch->getVar('pagenav_vars'); |
||
| 180 | $searchLimit = $criteria->getLimit(); |
||
| 181 | $searchStart = $criteria->getStart(); |
||
| 182 | $criteria = get_object_vars($criteria); |
||
| 183 | $critElements = $criteria['criteriaElements']; |
||
| 184 | $hasSubmittedBy = false; |
||
| 185 | foreach ($critElements as $critEle) { |
||
| 186 | $critEle = get_object_vars($critEle); |
||
| 187 | $colName = $critEle['column']; |
||
| 188 | if (in_array($colName, $vars)) { |
||
| 189 | switch ($colName) { |
||
| 190 | case 'department': |
||
| 191 | case 'status': |
||
| 192 | $eleValue = str_replace('(', '', $critEle['value']); |
||
| 193 | $eleValue = str_replace(')', '', $eleValue); |
||
| 194 | ${$colName} = $eleValue; |
||
| 195 | ${$colName} = explode(',', ${$colName}); |
||
| 196 | break; |
||
| 197 | case 'uid': |
||
| 198 | if (!$hasSubmittedBy) { |
||
| 199 | $submitted_string = mb_strstr($pagenav_vars, 'submittedBy='); |
||
| 200 | if ($submitted_string) { |
||
| 201 | $end_string = mb_strpos($submitted_string, '&'); |
||
| 202 | $submitted_string_sub = mb_substr($submitted_string, 0, $end_string); |
||
| 203 | if ($submitted_string_sub) { |
||
| 204 | $submitted_string = $submitted_string_sub; |
||
| 205 | } |
||
| 206 | $submitted_string = explode('=', $submitted_string); |
||
| 207 | $submitted_string = $submitted_string[1]; |
||
| 208 | $submittedBy = $xoopsUser::getUnameFromId((int)$submitted_string); |
||
| 209 | $hasSubmittedBy = true; |
||
| 210 | } |
||
| 211 | } |
||
| 212 | break; |
||
| 213 | default: |
||
| 214 | $eleValue = $critEle['value']; |
||
| 215 | $eleLength = mb_strlen($eleValue); |
||
| 216 | $firstSpot = mb_strpos($eleValue, '%'); |
||
| 217 | $lastSpot = mb_strrpos($eleValue, '%'); |
||
| 218 | if (false !== $firstSpot && false !== $lastSpot) { |
||
| 219 | $eleValue = mb_substr($eleValue, 1, $eleLength - 2); |
||
| 220 | } |
||
| 221 | ${$colName} = $eleValue; |
||
| 222 | break; |
||
| 223 | } |
||
| 224 | $arr_key = array_search($colName, $aFieldnames, true); |
||
| 225 | if (false !== $arr_key) { |
||
| 226 | $aFields[$arr_key]['defaultvalue'] = ${$colName}; |
||
| 227 | } |
||
| 228 | } |
||
| 229 | } |
||
| 230 | foreach ($vars as $var) { |
||
| 231 | $xoopsTpl->assign('xhelp_search' . $var, $$var); |
||
| 232 | } |
||
| 233 | |||
| 234 | $xoopsTpl->assign('xhelp_custFields', $aFields); |
||
| 235 | if (!empty($aFields)) { |
||
| 236 | $xoopsTpl->assign('xhelp_hasCustFields', true); |
||
| 237 | } else { |
||
| 238 | $xoopsTpl->assign('xhelp_hasCustFields', false); |
||
| 239 | } |
||
| 240 | $session->set('xhelp_custFields', $aFields); |
||
| 241 | $staff = Xhelp\Utility::getStaff($displayName); |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 242 | $xoopsTpl->assign('xhelp_staff', $staff); |
||
| 243 | /** @var \XoopsModules\Xhelp\MembershipHandler $membershipHandler */ |
||
| 244 | $membershipHandler = $helper->getHandler('Membership'); |
||
| 245 | if (1 == $helper->getConfig('xhelp_deptVisibility')) { // Apply dept visibility to staff members? |
||
| 246 | $depts = $membershipHandler->getVisibleDepartments($xoopsUser->getVar('uid')); |
||
| 247 | } else { |
||
| 248 | $depts = $membershipHandler->membershipByStaff($xoopsUser->getVar('uid')); |
||
| 249 | } |
||
| 250 | foreach ($depts as $dept) { |
||
| 251 | $myDepts[$dept->getVar('id')] = $dept->getVar('department'); |
||
| 252 | } |
||
| 253 | unset($depts); |
||
| 254 | asort($myDepts); |
||
| 255 | $myDepts[-1] = _XHELP_TEXT_SELECT_ALL; |
||
| 256 | $xoopsTpl->assign('xhelp_depts', $myDepts); |
||
| 257 | |||
| 258 | /** @var \XoopsModules\Xhelp\StatusHandler $statusHandler */ |
||
| 259 | $statusHandler = $helper->getHandler('Status'); |
||
| 260 | $crit_stat = new \Criteria('', ''); |
||
| 261 | $crit_stat->setSort('description'); |
||
| 262 | $crit_stat->setOrder('ASC'); |
||
| 263 | $statuses = $statusHandler->getObjects($crit_stat); |
||
| 264 | $aStatuses = []; |
||
| 265 | foreach ($statuses as $status) { |
||
| 266 | $aStatuses[$status->getVar('id')] = $status->getVar('description'); |
||
| 267 | } |
||
| 268 | unset($statuses); |
||
| 269 | $xoopsTpl->assign('xhelp_statuses', $aStatuses); |
||
| 270 | $xoopsTpl->assign('xhelp_searchid', $mySearch->getVar('id')); |
||
| 271 | $xoopsTpl->assign('xhelp_searchName', $mySearch->getVar('name')); |
||
| 272 | $xoopsTpl->assign('xhelp_searchLimit', $searchLimit); |
||
| 273 | $xoopsTpl->assign('xhelp_searchStart', $searchStart); |
||
| 274 | $xoopsTpl->assign('xhelp_priorities', [5, 4, 3, 2, 1]); |
||
| 275 | $xoopsTpl->assign('xhelp_priorities_desc', [ |
||
| 276 | 5 => _XHELP_PRIORITY5, |
||
| 277 | 4 => _XHELP_PRIORITY4, |
||
| 278 | 3 => _XHELP_PRIORITY3, |
||
| 279 | 2 => _XHELP_PRIORITY2, |
||
| 280 | 1 => _XHELP_PRIORITY1, |
||
| 281 | ]); |
||
| 282 | $xoopsTpl->assign('xhelp_imagePath', XHELP_BASE_URL . '/assets/images/'); |
||
| 283 | $xoopsTpl->assign('xhelp_returnPage', $returnPage); |
||
| 284 | } |
||
| 285 | |||
| 286 | break; |
||
| 287 | case 'editSave': |
||
| 288 | |||
| 289 | break; |
||
| 290 | case 'search': |
||
| 291 | default: |
||
| 292 | $GLOBALS['xoopsOption']['template_main'] = 'xhelp_search.tpl'; // Set template |
||
| 293 | require_once XOOPS_ROOT_PATH . '/header.php'; // Include the page header |
||
| 294 | |||
| 295 | $xoopsTpl->assign('xhelp_imagePath', XHELP_BASE_URL . '/assets/images/'); |
||
| 296 | $xoopsTpl->assign('xhelp_uid', $uid); |
||
| 297 | $xoopsTpl->assign('xhelp_returnPage', $returnPage); |
||
| 298 | $xoopsTpl->assign('xhelp_baseURL', XHELP_BASE_URL); |
||
| 299 | $viewResults = false; |
||
| 300 | |||
| 301 | // Start of hack by trabis/tdm |
||
| 302 | $recieve_datemin = 0; |
||
| 303 | $recieve_datemax = 0; |
||
| 304 | $datemin_use = 0; |
||
| 305 | $datemax_use = 0; |
||
| 306 | |||
| 307 | if (Request::hasVar('datemin_use', 'REQUEST')) { |
||
| 308 | $datemin_use = 1; |
||
| 309 | } |
||
| 310 | if (Request::hasVar('datemax_use', 'REQUEST')) { |
||
| 311 | $datemax_use = 1; |
||
| 312 | } |
||
| 313 | |||
| 314 | $date_criteria = new \CriteriaCompo(); |
||
| 315 | if (Request::hasVar('recieve_datemin', 'REQUEST') && 1 === $datemin_use) { |
||
| 316 | $recieve_datemin = strtotime($_REQUEST['recieve_datemin']); |
||
| 317 | $date_criteria->add(new \Criteria('t.posted', (string)$recieve_datemin, '>=')); |
||
| 318 | } |
||
| 319 | if (Request::hasVar('recieve_datemax', 'REQUEST') && 1 === $datemax_use) { |
||
| 320 | $recieve_datemax = strtotime($_REQUEST['recieve_datemax']) + 60 * 60 * 24 - 1; |
||
| 321 | $date_criteria->add(new \Criteria('t.posted', (string)$recieve_datemax, '<=')); |
||
| 322 | } |
||
| 323 | |||
| 324 | //recherche recieve_date |
||
| 325 | xoops_load('XoopsFormLoader'); |
||
| 326 | $aff_date = new \XoopsFormElementTray('', ''); |
||
| 327 | $date_min = new \XoopsFormTextDateSelect(_XHELP_TEXT_DATE_MIN, 'recieve_datemin', 10, strtotime((string)$recieve_datemin)); |
||
| 328 | //No request done, set default value for form |
||
| 329 | if (0 == $recieve_datemin) { |
||
| 330 | $datemin_use = 1; |
||
| 331 | } |
||
| 332 | $date_min_use = new \XoopsFormCheckBox('', 'datemin_use', $datemin_use); |
||
| 333 | $date_min_use->addOption(1, _XHELP_TEXT_USE); |
||
| 334 | //No request done, set default value for form |
||
| 335 | $date_max = new \XoopsFormTextDateSelect(_XHELP_TEXT_DATE_MAX, 'recieve_datemax', 10, strtotime((string)$recieve_datemax)); |
||
| 336 | if (0 == $recieve_datemax) { |
||
| 337 | $datemax_use = 1; |
||
| 338 | } |
||
| 339 | $date_max_use = new \XoopsFormCheckBox('', 'datemax_use', $datemax_use); |
||
| 340 | $date_max_use->addOption('1', _XHELP_TEXT_USE); |
||
| 341 | |||
| 342 | $aff_date->addElement($date_min); |
||
| 343 | $aff_date->addElement($date_min_use); |
||
| 344 | $aff_date->addElement($date_max); |
||
| 345 | $aff_date->addElement($date_max_use); |
||
| 346 | $dateform = $aff_date->render(); |
||
| 347 | |||
| 348 | $xoopsTpl->assign('dateform', $dateform); |
||
| 349 | // End of hack |
||
| 350 | |||
| 351 | // If search submitted, or moving to another page of search results, or submitted a saved search |
||
| 352 | if (Request::hasVar('search', 'POST') || isset($_GET['start']) || isset($_REQUEST['savedSearch'])) { |
||
| 353 | if (Request::hasVar('savedSearch', 'REQUEST') && 0 != $_REQUEST['savedSearch']) { // If this is a saved search |
||
| 354 | if (isset($_POST['delete_savedSearch'])) { // If deleting saved search |
||
| 355 | $mySavedSearch = $aSavedSearches[Request::getInt('savedSearch', 0, 'REQUEST')]; // Retrieve saved search |
||
| 356 | if (XHELP_GLOBAL_UID == $mySavedSearch['uid']) { |
||
| 357 | $helper->redirect('search.php', 3, _XHELP_MSG_NO_DEL_SEARCH); |
||
| 358 | } |
||
| 359 | $criteria = new \Criteria('id', $mySavedSearch['id']); |
||
| 360 | if ($savedSearchHandler->deleteAll($criteria)) { |
||
| 361 | $session->del('xhelp_savedSearches'); |
||
| 362 | $helper->redirect('search.php'); |
||
| 363 | } else { |
||
| 364 | $helper->redirect('search.php', 3, _XHELP_MESSAGE_DELETE_SEARCH_ERR); |
||
| 365 | } |
||
| 366 | } else { // If not deleting saved search |
||
| 367 | $mySavedSearch = $savedSearchHandler->get($_REQUEST['savedSearch']); |
||
| 368 | $criteria = unserialize($mySavedSearch->getVar('search')); // Set $criteria object |
||
| 369 | $pagenav_vars = $mySavedSearch->getVar('pagenav_vars'); // set pagenav vars |
||
| 370 | |||
| 371 | if (0 != $criteria->getLimit()) { |
||
| 372 | $limit = $criteria->getLimit(); // Set limit |
||
| 373 | } |
||
| 374 | $start = $criteria->getStart(); // Set start |
||
| 375 | |||
| 376 | $custFields = $session->get('xhelp_custFields'); |
||
| 377 | if ($custFields) { // Custom fields |
||
| 378 | $hasCustFields = true; |
||
| 379 | } |
||
| 380 | } |
||
| 381 | } elseif (Request::hasVar('search', 'POST') |
||
| 382 | || isset($_GET['start'])) { // If this is a new search or next page in search results |
||
| 383 | $criteria = new \CriteriaCompo(new \Criteria('uid', $xoopsUser->getVar('uid'), '=', 'j')); |
||
| 384 | $vars = [ |
||
| 385 | 'ticketid', |
||
| 386 | 'department', |
||
| 387 | 'description', |
||
| 388 | 'subject', |
||
| 389 | 'priority', |
||
| 390 | 'status', |
||
| 391 | 'state', |
||
| 392 | 'submittedBy', |
||
| 393 | 'ownership', |
||
| 394 | 'closedBy', |
||
| 395 | ]; |
||
| 396 | //hack |
||
| 397 | $criteria->add($date_criteria); |
||
| 398 | //end of hack |
||
| 399 | $custFields = $session->get('xhelp_custFields'); |
||
| 400 | if ($custFields) { // Custom fields |
||
| 401 | $hasCustFields = false; |
||
| 402 | foreach ($custFields as $field) { |
||
| 403 | $fieldname = $field['fieldname']; |
||
| 404 | if (isset($_REQUEST[$fieldname]) && '' != \Xmf\Request::getString($fieldname, '', 'REQUEST') |
||
| 405 | && -1 != \Xmf\Request::getString($fieldname, '', 'REQUEST')) { |
||
| 406 | $hasCustFields = true; |
||
| 407 | $criteria->add(new \Criteria($fieldname, '%' . \Xmf\Request::getString($fieldname, '', 'REQUEST') . '%', 'LIKE', 'f')); |
||
| 408 | } |
||
| 409 | } |
||
| 410 | } |
||
| 411 | // Finished with session var - delete it now |
||
| 412 | $session->del('xhelp_custFields'); |
||
| 413 | |||
| 414 | foreach ($vars as $var) { |
||
| 415 | if (isset($_POST[$var])) { |
||
| 416 | $$var = $_POST[$var]; |
||
| 417 | } elseif (isset($_GET[$var])) { |
||
| 418 | $$var = $_GET[$var]; |
||
| 419 | } |
||
| 420 | } |
||
| 421 | |||
| 422 | if (isset($ticketid) && $ticketid = (int)$ticketid) { |
||
| 423 | $criteria->add(new \Criteria('id', (string)$ticketid, '=', 't')); |
||
| 424 | $pagenav_vars .= "&ticketid=$ticketid"; |
||
| 425 | } |
||
| 426 | |||
| 427 | if (isset($department)) { |
||
| 428 | if (!in_array('-1', $department)) { |
||
| 429 | $department = array_filter($department); |
||
| 430 | $criteria->add(new \Criteria('department', '(' . implode(',', $department) . ')', 'IN', 't')); |
||
| 431 | $pagenav_vars .= '&department[]=' . implode('&department[]=', $department); |
||
| 432 | } |
||
| 433 | } |
||
| 434 | |||
| 435 | if (isset($description) && $description) { |
||
| 436 | $criteria->add(new \Criteria('description', "%$description%", 'LIKE', 't')); |
||
| 437 | $pagenav_vars .= "&description=$description"; |
||
| 438 | } |
||
| 439 | |||
| 440 | if (isset($subject) && $subject) { |
||
| 441 | $criteria->add(new \Criteria('subject', "%$subject%", 'LIKE', 't')); |
||
| 442 | $pagenav_vars .= "&subject=$subject"; |
||
| 443 | } |
||
| 444 | |||
| 445 | if (isset($priority) && (-1 != $priority)) { |
||
| 446 | $priority = (int)$priority; |
||
| 447 | $criteria->add(new \Criteria('priority', (string)$priority, '=', 't')); |
||
| 448 | $pagenav_vars .= "&priority=$priority"; |
||
| 449 | } |
||
| 450 | |||
| 451 | if (isset($status)) { |
||
| 452 | if (is_array($status)) { |
||
| 453 | $status = array_filter($status); |
||
| 454 | $criteria->add(new \Criteria('status', '(' . implode(',', $status) . ')', 'IN', 't')); |
||
| 455 | $pagenav_vars .= '&status[]=' . implode('&status[]=', $status); |
||
| 456 | } else { |
||
| 457 | $criteria->add(new \Criteria('status', (int)$status, '=', 't')); |
||
| 458 | $pagenav_vars .= "&status=$status"; |
||
| 459 | } |
||
| 460 | } else { // Only evaluate if status is not set |
||
| 461 | if (isset($state) && -1 != $state) { |
||
| 462 | $criteria->add(new \Criteria('state', (int)$state, '=', 's')); |
||
| 463 | $pagenav_vars .= "&state=$state"; |
||
| 464 | } |
||
| 465 | } |
||
| 466 | |||
| 467 | if (isset($submittedBy) && $submittedBy) { |
||
| 468 | if (mb_strlen($submittedBy) > 0) { |
||
| 469 | if (!is_numeric($submittedBy)) { |
||
| 470 | /** @var \XoopsMemberHandler $memberHandler */ |
||
| 471 | $memberHandler = xoops_getHandler('member'); |
||
| 472 | $users = $memberHandler->getUsers(new \Criteria('uname', $submittedBy)); |
||
| 473 | if ($users) { |
||
|
0 ignored issues
–
show
The expression
$users of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using Loading history...
|
|||
| 474 | $submittedBy = $users[0]->getVar('uid'); |
||
| 475 | } elseif ($users = $memberHandler->getUsers(new \Criteria('email', "%$submittedBy%", 'LIKE'))) { |
||
| 476 | $submittedBy = $users[0]->getVar('uid'); |
||
| 477 | } else { |
||
| 478 | $submittedBy = -1; |
||
| 479 | } |
||
| 480 | } |
||
| 481 | $submittedBy = (int)$submittedBy; |
||
| 482 | $criteria->add(new \Criteria('uid', (string)$submittedBy, '=', 't')); |
||
| 483 | $pagenav_vars .= "&submittedBy=$submittedBy"; |
||
| 484 | } |
||
| 485 | } |
||
| 486 | if (isset($ownership) && (-1 != $ownership)) { |
||
| 487 | $ownership = (int)$ownership; |
||
| 488 | $criteria->add(new \Criteria('ownership', (string)$ownership, '=', 't')); |
||
| 489 | $pagenav_vars .= "&ownership=$ownership"; |
||
| 490 | } |
||
| 491 | if (isset($closedBy) && (-1 != $closedBy)) { |
||
| 492 | $closedBy = (int)$closedBy; |
||
| 493 | $criteria->add(new \Criteria('closedBy', (string)$closedBy, '=', 't')); |
||
| 494 | $pagenav_vars .= "&closedBy=$closedBy"; |
||
| 495 | } |
||
| 496 | $criteria->setStart($start); |
||
| 497 | $criteria->setLimit($limit); |
||
| 498 | $criteria->setSort($sort); |
||
| 499 | $criteria->setOrder($order); |
||
| 500 | |||
| 501 | if (Request::hasVar('save', 'POST') && 1 === $_POST['save']) { |
||
| 502 | if (Request::hasVar('searchid', 'POST') && 0 != $_POST['searchid']) { |
||
| 503 | $exSearch = $savedSearchHandler->get(Request::getInt('searchid', 0, 'POST')); |
||
| 504 | $exSearch->setVar('uid', $xoopsUser->getVar('uid')); |
||
| 505 | $exSearch->setVar('name', \Xmf\Request::getString('searchName', '', 'POST')); |
||
| 506 | $exSearch->setVar('search', serialize($criteria)); |
||
| 507 | $exSearch->setVar('pagenav_vars', $pagenav_vars); |
||
| 508 | $exSearch->setVar('hasCustFields', ($hasCustFields ? 1 : 0)); |
||
| 509 | |||
| 510 | if ($savedSearchHandler->insert($exSearch)) { // If saved, store savedSearches in a session var |
||
| 511 | $session->del('xhelp_savedSearches'); |
||
| 512 | } |
||
| 513 | unset($exSearch); |
||
| 514 | if (false !== $returnPage) { |
||
| 515 | $helper->redirect($returnPage . '.php'); |
||
| 516 | } |
||
| 517 | } else { |
||
| 518 | if ('' != \Xmf\Request::getString('searchName', '', 'POST')) { |
||
| 519 | /** @var \XoopsModules\Xhelp\SavedSearch $newSearch */ |
||
| 520 | $newSearch = $savedSearchHandler->create(); |
||
| 521 | $newSearch->setVar('uid', $xoopsUser->getVar('uid')); |
||
| 522 | $newSearch->setVar('name', \Xmf\Request::getString('searchName', '', 'POST')); |
||
| 523 | $newSearch->setVar('search', serialize($criteria)); |
||
| 524 | $newSearch->setVar('pagenav_vars', $pagenav_vars); |
||
| 525 | $newSearch->setVar('hasCustFields', ($hasCustFields ? 1 : 0)); |
||
| 526 | |||
| 527 | if ($savedSearchHandler->insert($newSearch)) { // If saved, store savedSearches in a session var |
||
| 528 | $session->del('xhelp_savedSearches'); |
||
| 529 | } |
||
| 530 | unset($newSearch); |
||
| 531 | if (false !== $returnPage) { |
||
| 532 | $helper->redirect($returnPage . '.php'); |
||
| 533 | } |
||
| 534 | } |
||
| 535 | } |
||
| 536 | } |
||
| 537 | } |
||
| 538 | $viewResults = true; |
||
| 539 | |||
| 540 | $tickets = $ticketHandler->getObjectsByStaff($criteria, false, $hasCustFields); |
||
| 541 | |||
| 542 | $total = $ticketHandler->getCountByStaff($criteria, $hasCustFields); |
||
| 543 | //$pageNav = new XoopsPageNav($total, $limit, $start, "start", "limit=$limit&department=$search_department&description=$search_description&subject=$search_subject&priority=$search_priority&status=$search_status&submittedBy=$search_submittedBy&ownership=$search_ownership&closedBy=$search_closedBy"); // New PageNav object |
||
| 544 | $pageNav = new \XoopsPageNav($total, $limit, $start, 'start', $pagenav_vars); |
||
| 545 | $xoopsTpl->assign('xhelp_pagenav', $pageNav->renderNav()); |
||
| 546 | unset($pageNav); |
||
| 547 | /** @var \XoopsMemberHandler $memberHandler */ |
||
| 548 | $memberHandler = xoops_getHandler('member'); |
||
| 549 | foreach ($tickets as $ticket) { |
||
| 550 | $user = $memberHandler->getUser($ticket->getVar('uid')); |
||
| 551 | $owner = $memberHandler->getUser($ticket->getVar('ownership')); |
||
| 552 | //$closer = $memberHandler->getUser($ticket->getVar('closedBy')); |
||
| 553 | $department = $departmentHandler->get($ticket->getVar('department')); |
||
| 554 | //if ($owner) { |
||
| 555 | $overdue = false; |
||
| 556 | if ($ticket->isOverdue()) { |
||
| 557 | $overdue = true; |
||
| 558 | } |
||
| 559 | |||
| 560 | $aTickets[$ticket->getVar('id')] = [ |
||
| 561 | 'id' => $ticket->getVar('id'), |
||
| 562 | 'uid' => $ticket->getVar('uid'), |
||
| 563 | 'uname' => $user ? $user->getVar('uname') : $xoopsConfig['anonymous'], |
||
| 564 | 'userinfo' => XOOPS_URL . '/userinfo.php?uid=' . $ticket->getVar('uid'), |
||
| 565 | 'subject' => xoops_substr($ticket->getVar('subject'), 0, 35), |
||
| 566 | 'full_subject' => $ticket->getVar('subject'), |
||
| 567 | 'description' => $ticket->getVar('description'), |
||
| 568 | 'department' => $department->getVar('department'), |
||
| 569 | 'departmentid' => $department->getVar('id'), |
||
| 570 | 'departmenturl' => Xhelp\Utility::createURI('index.php', [ |
||
| 571 | 'op' => 'staffViewAll', |
||
| 572 | 'dept' => $department->getVar('id'), |
||
| 573 | ]), |
||
| 574 | 'priority' => $ticket->getVar('priority'), |
||
| 575 | 'status' => Xhelp\Utility::getStatus($ticket->getVar('status')), |
||
| 576 | 'posted' => $ticket->posted(), |
||
| 577 | 'totalTimeSpent' => $ticket->getVar('totalTimeSpent'), |
||
| 578 | 'ownership' => ($owner |
||
| 579 | && '' != $owner->getVar('uname')) ? $owner->getVar('uname') : _XHELP_NO_OWNER, |
||
| 580 | 'ownerid' => ($owner && 0 != $owner->getVar('uid')) ? $owner->getVar('uid') : 0, |
||
| 581 | 'ownerinfo' => ($owner && 0 != $owner->getVar('uid')) ? XOOPS_URL . '/userinfo.php?uid=' . $owner->getVar('uid') : 0, |
||
| 582 | 'closedBy' => $ticket->getVar('closedBy'), |
||
| 583 | 'closedByUname' => $xoopsUser::getUnameFromId($ticket->getVar('closedBy')), |
||
| 584 | 'url' => XOOPS_URL . '/modules/xhelp/ticket.php?id=' . $ticket->getVar('id'), |
||
| 585 | 'elapsed' => $ticket->elapsed(), |
||
| 586 | 'lastUpdate' => $ticket->lastUpdate(), |
||
| 587 | 'overdue' => $overdue, |
||
| 588 | ]; |
||
| 589 | unset($user); |
||
| 590 | unset($owner); |
||
| 591 | //$closer = $memberHandler->getUser($ticket->getVar('closedBy')); |
||
| 592 | unset($department); |
||
| 593 | } |
||
| 594 | unset($tickets); |
||
| 595 | $xoopsTpl->assign('xhelp_viewResults', $viewResults); |
||
| 596 | if (isset($aTickets)) { |
||
| 597 | $xoopsTpl->assign('xhelp_allTickets', $aTickets); |
||
| 598 | $xoopsTpl->assign('xhelp_has_tickets', true); |
||
| 599 | } else { |
||
| 600 | $xoopsTpl->assign('xhelp_allTickets', 0); |
||
| 601 | $xoopsTpl->assign('xhelp_has_tickets', false); |
||
| 602 | } |
||
| 603 | |||
| 604 | $tpl_cols = []; |
||
| 605 | //Setup Column Sorting Vars |
||
| 606 | foreach ($sort_columns as $col) { |
||
| 607 | $col_qs = ['sort' => $col]; |
||
| 608 | if ($sort == $col) { |
||
| 609 | $col_qs_order = ($order == $sort_order[0] ? $sort_order[1] : $sort_order[0]); |
||
| 610 | $col_sortby = true; |
||
| 611 | } else { |
||
| 612 | $col_qs_order = $order; |
||
| 613 | $col_sortby = false; |
||
| 614 | } |
||
| 615 | $tpl_cols[$col] = [ |
||
| 616 | 'url' => "search.php?$pagenav_vars&start=$start&sort=$col&order=$col_qs_order", |
||
| 617 | 'urltitle' => _XHELP_TEXT_SORT_TICKETS, |
||
| 618 | 'sortby' => $col_sortby, |
||
| 619 | 'sortdir' => \mb_strtolower($col_qs_order), |
||
| 620 | ]; |
||
| 621 | } |
||
| 622 | $xoopsTpl->assign('xhelp_cols', $tpl_cols); |
||
| 623 | } else { |
||
| 624 | $xoopsTpl->assign('xhelp_viewResults', $viewResults); |
||
| 625 | } |
||
| 626 | $xoopsTpl->assign('xhelp_savedSearches', $aSavedSearches); |
||
| 627 | $xoopsTpl->assign('xhelp_text_allTickets', _XHELP_TEXT_SEARCH_RESULTS); |
||
| 628 | $xoopsTpl->assign('xhelp_priorities', [5, 4, 3, 2, 1]); |
||
| 629 | $xoopsTpl->assign('xhelp_priorities_desc', [ |
||
| 630 | 5 => _XHELP_PRIORITY5, |
||
| 631 | 4 => _XHELP_PRIORITY4, |
||
| 632 | 3 => _XHELP_PRIORITY3, |
||
| 633 | 2 => _XHELP_PRIORITY2, |
||
| 634 | 1 => _XHELP_PRIORITY1, |
||
| 635 | ]); |
||
| 636 | $staff = Xhelp\Utility::getStaff($displayName); |
||
| 637 | $xoopsTpl->assign('xhelp_staff', $staff); |
||
| 638 | /** @var \XoopsModules\Xhelp\MembershipHandler $membershipHandler */ |
||
| 639 | $membershipHandler = $helper->getHandler('Membership'); |
||
| 640 | if (1 == $helper->getConfig('xhelp_deptVisibility')) { // Apply dept visibility to staff members? |
||
| 641 | $depts = $membershipHandler->getVisibleDepartments($xoopsUser->getVar('uid')); |
||
| 642 | } else { |
||
| 643 | $depts = $membershipHandler->membershipByStaff($xoopsUser->getVar('uid')); |
||
| 644 | } |
||
| 645 | foreach ($depts as $dept) { |
||
| 646 | $myDepts[$dept->getVar('id')] = $dept->getVar('department'); |
||
| 647 | } |
||
| 648 | unset($depts); |
||
| 649 | asort($myDepts); |
||
| 650 | $myDepts[-1] = _XHELP_TEXT_SELECT_ALL; |
||
| 651 | $xoopsTpl->assign('xhelp_depts', $myDepts); |
||
| 652 | $xoopsTpl->assign('xhelp_batch_form', 'index.php'); |
||
| 653 | $xoopsTpl->assign('xoops_module_header', $xhelp_module_header); |
||
| 654 | |||
| 655 | /** @var \XoopsModules\Xhelp\StatusHandler $statusHandler */ |
||
| 656 | $statusHandler = $helper->getHandler('Status'); |
||
| 657 | $crit_stat = new \Criteria('', ''); |
||
| 658 | $crit_stat->setSort('description'); |
||
| 659 | $crit_stat->setOrder('ASC'); |
||
| 660 | $statuses = $statusHandler->getObjects($crit_stat); |
||
| 661 | $aStatuses = []; |
||
| 662 | foreach ($statuses as $status) { |
||
| 663 | $aStatuses[$status->getVar('id')] = [ |
||
| 664 | 'id' => $status->getVar('id'), |
||
| 665 | 'desc' => $status->getVar('description'), |
||
| 666 | 'state' => $status->getVar('state'), |
||
| 667 | ]; |
||
| 668 | } |
||
| 669 | unset($statuses); |
||
| 670 | $xoopsTpl->assign('xhelp_statuses', $aStatuses); |
||
| 671 | |||
| 672 | $fields = $ticketFieldHandler->getObjects(); |
||
| 673 | $aFields = []; |
||
| 674 | foreach ($fields as $field) { |
||
| 675 | $values = $field->getVar('fieldvalues'); |
||
| 676 | if (XHELP_CONTROL_YESNO == $field->getVar('controltype')) { |
||
| 677 | //$values = array(1 => _YES, 0 => _NO); |
||
| 678 | $values = ((1 == $values) ? _YES : _NO); |
||
| 679 | } |
||
| 680 | $defaultValue = $field->getVar('defaultvalue'); |
||
| 681 | |||
| 682 | $aFields[$field->getVar('id')] = [ |
||
| 683 | 'name' => $field->getVar('name'), |
||
| 684 | 'desc' => $field->getVar('description'), |
||
| 685 | 'fieldname' => $field->getVar('fieldname'), |
||
| 686 | 'defaultvalue' => $defaultValue, |
||
| 687 | 'controltype' => $field->getVar('controltype'), |
||
| 688 | 'required' => $field->getVar('required'), |
||
| 689 | 'fieldlength' => $field->getVar('fieldlength') < 50 ? $field->getVar('fieldlength') : 50, |
||
| 690 | 'maxlength' => $field->getVar('fieldlength'), |
||
| 691 | 'weight' => $field->getVar('weight'), |
||
| 692 | 'fieldvalues' => $values, |
||
| 693 | 'validation' => $field->getVar('validation'), |
||
| 694 | ]; |
||
| 695 | } |
||
| 696 | unset($fields); |
||
| 697 | $xoopsTpl->assign('xhelp_custFields', $aFields); |
||
| 698 | if (!empty($aFields)) { |
||
| 699 | $xoopsTpl->assign('xhelp_hasCustFields', true); |
||
| 700 | } else { |
||
| 701 | $xoopsTpl->assign('xhelp_hasCustFields', false); |
||
| 702 | } |
||
| 703 | |||
| 704 | $session->set('xhelp_custFields', $aFields); |
||
| 705 | break; |
||
| 706 | } |
||
| 707 | |||
| 708 | require_once XOOPS_ROOT_PATH . '/footer.php'; |
||
| 709 | } else { // If not a user |
||
| 710 | redirect_header(XOOPS_URL . '/user.php', 3); |
||
| 711 | } |
||
| 712 |