Bootswatch, Summernote, and Captcheck mods for Mods for HESK (mods-for-hesk.com). In use at support.netsyms.com.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

move_category.php 6.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. *
  4. * This file is part of HESK - PHP Help Desk Software.
  5. *
  6. * (c) Copyright Klemen Stirn. All rights reserved.
  7. * https://www.hesk.com
  8. *
  9. * For the full copyright and license agreement information visit
  10. * https://www.hesk.com/eula.php
  11. *
  12. */
  13. define('IN_SCRIPT', 1);
  14. define('HESK_PATH', '../');
  15. /* Get all the required files and functions */
  16. require(HESK_PATH . 'hesk_settings.inc.php');
  17. require(HESK_PATH . 'inc/common.inc.php');
  18. require(HESK_PATH . 'inc/admin_functions.inc.php');
  19. hesk_load_database_functions();
  20. require(HESK_PATH . 'inc/email_functions.inc.php');
  21. hesk_session_start();
  22. hesk_dbConnect();
  23. hesk_isLoggedIn();
  24. $modsForHesk_settings = mfh_getSettings();
  25. /* Check permissions for this feature */
  26. if (hesk_checkPermission('can_change_cat', 0)) {
  27. hesk_checkPermission('can_change_own_cat');
  28. }
  29. /* A security check */
  30. hesk_token_check('POST');
  31. /* Ticket ID */
  32. $trackingID = hesk_cleanID() or die($hesklang['int_error'] . ': ' . $hesklang['no_trackID']);
  33. /* Category ID */
  34. $category = intval(hesk_POST('category', -1));
  35. if ($category < 1) {
  36. hesk_process_messages($hesklang['incat'], 'admin_ticket.php?track=' . $trackingID . '&Refresh=' . rand(10000, 99999), 'NOTICE');
  37. }
  38. /* Get new category details */
  39. $res = hesk_dbQuery("SELECT `name`,`autoassign` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "categories` WHERE `id`='{$category}' LIMIT 1");
  40. if (hesk_dbNumRows($res) != 1) {
  41. hesk_error("$hesklang[int_error]: $hesklang[kb_cat_inv].");
  42. }
  43. $row = hesk_dbFetchAssoc($res);
  44. /* Should tickets in new category be auto-assigned if necessary? */
  45. if (!$row['autoassign']) {
  46. $hesk_settings['autoassign'] = false;
  47. }
  48. /* Is user allowed to view tickets in new category? */
  49. $category_ok = hesk_okCategory($category, 0);
  50. // Is user allowed to move tickets to this category?
  51. if ( ! $category_ok && ! hesk_checkPermission('can_change_cat', 0) ) {
  52. hesk_process_messages($hesklang['noauth_move'],'admin_main.php');
  53. }
  54. /* Get details about the original ticket */
  55. $res = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` WHERE `trackid`='" . hesk_dbEscape($trackingID) . "' LIMIT 1");
  56. if (hesk_dbNumRows($res) != 1) {
  57. hesk_error($hesklang['ticket_not_found']);
  58. }
  59. $ticket = hesk_dbFetchAssoc($res);
  60. /* Is the ticket assigned to someone? If yes, check that the user has access to category or change to unassigned */
  61. $need_to_reassign = 0;
  62. if ($ticket['owner']) {
  63. if ($ticket['owner'] == $_SESSION['id'] && !$category_ok) {
  64. $need_to_reassign = 1;
  65. } else {
  66. $res = hesk_dbQuery("SELECT `isadmin`,`categories` FROM `" . hesk_dbEscape($hesk_settings['db_pfix']) . "users` WHERE `id`='" . intval($ticket['owner']) . "' LIMIT 1");
  67. if (hesk_dbNumRows($res) != 1) {
  68. $need_to_reassign = 1;
  69. } else {
  70. $tmp = hesk_dbFetchAssoc($res);
  71. if (!hesk_okCategory($category, 0, $tmp['isadmin'], explode(',', $tmp['categories']))) {
  72. $need_to_reassign = 1;
  73. }
  74. }
  75. }
  76. }
  77. /* Reassign automatically if possible */
  78. $autoassign_owner = null;
  79. if ($need_to_reassign || !$ticket['owner']) {
  80. $need_to_reassign = 1;
  81. $autoassign_owner = hesk_autoAssignTicket($category);
  82. if ($autoassign_owner) {
  83. $ticket['owner'] = $autoassign_owner['id'];
  84. } else {
  85. $ticket['owner'] = 0;
  86. }
  87. }
  88. hesk_dbQuery("UPDATE `" . hesk_dbEscape($hesk_settings['db_pfix']) . "tickets` SET `category`='" . intval($category) . "', `owner`='" . intval($ticket['owner']) . "' WHERE `trackid`='" . hesk_dbEscape($trackingID) . "'");
  89. /* Log that ticket is being moved */
  90. mfh_insert_audit_trail_record($ticket['id'], 'TICKET', 'audit_moved_category', hesk_date(), array(
  91. 0 => $_SESSION['name'] . ' (' . $_SESSION['user'] . ')',
  92. 1 => $row['name']
  93. ));
  94. if ($autoassign_owner) {
  95. mfh_insert_audit_trail_record($ticket['id'], 'TICKET', 'audit_autoassigned', hesk_date(), array(
  96. 0 => $autoassign_owner['name'] . ' (' . $autoassign_owner['user'] . ')'
  97. ));
  98. }
  99. $ticket['category'] = $category;
  100. /* --> Prepare message */
  101. // 1. Generate the array with ticket info that can be used in emails
  102. $info = array(
  103. 'email' => $ticket['email'],
  104. 'category' => $ticket['category'],
  105. 'priority' => $ticket['priority'],
  106. 'owner' => $ticket['owner'],
  107. 'trackid' => $ticket['trackid'],
  108. 'status' => $ticket['status'],
  109. 'name' => $ticket['name'],
  110. 'subject' => $ticket['subject'],
  111. 'message' => $ticket['message'],
  112. 'attachments' => $ticket['attachments'],
  113. 'dt' => hesk_date($ticket['dt'], true),
  114. 'lastchange' => hesk_date($ticket['lastchange'], true),
  115. 'id' => $ticket['id'],'time_worked' => $ticket['time_worked'],
  116. 'last_reply_by' => hesk_getReplierName($ticket),
  117. );
  118. // 2. Add custom fields to the array
  119. foreach ($hesk_settings['custom_fields'] as $k => $v) {
  120. $info[$k] = $v['use'] ? $ticket[$k] : '';
  121. }
  122. // 3. Make sure all values are properly formatted for email
  123. $ticket = hesk_ticketToPlain($info, 1, 0);
  124. /* Need to notify any staff? */
  125. /* --> From autoassign? */
  126. if ($need_to_reassign && !empty($autoassign_owner['email'])) {
  127. hesk_notifyAssignedStaff($autoassign_owner, 'ticket_assigned_to_you', $modsForHesk_settings);
  128. } /* --> No autoassign, find and notify appropriate staff */
  129. elseif (!$ticket['owner']) {
  130. hesk_notifyStaff('category_moved', "`notify_new_unassigned`='1' AND `id`!=" . intval($_SESSION['id']), $modsForHesk_settings);
  131. }
  132. /* Is the user allowed to view tickets in the new category? */
  133. if ($category_ok) {
  134. /* Ticket has an owner */
  135. if ($ticket['owner']) {
  136. /* Staff is owner or can view tickets assigned to others */
  137. if ($ticket['owner'] == $_SESSION['id'] || hesk_checkPermission('can_view_ass_others', 0)) {
  138. hesk_process_messages($hesklang['moved_to'], 'admin_ticket.php?track=' . $trackingID . '&Refresh=' . rand(10000, 99999), 'SUCCESS');
  139. } else {
  140. hesk_process_messages($hesklang['moved_to'], 'admin_main.php', 'SUCCESS');
  141. }
  142. } /* Ticket is unassigned, staff can view unassigned tickets */
  143. elseif (hesk_checkPermission('can_view_unassigned', 0)) {
  144. hesk_process_messages($hesklang['moved_to'], 'admin_ticket.php?track=' . $trackingID . '&Refresh=' . rand(10000, 99999), 'SUCCESS');
  145. } /* Ticket is unassigned, staff cannot view unassigned tickets */
  146. else {
  147. hesk_process_messages($hesklang['moved_to'], 'admin_main.php', 'SUCCESS');
  148. }
  149. } else {
  150. hesk_process_messages($hesklang['moved_to'], 'admin_main.php', 'SUCCESS');
  151. }
  152. ?>