2
0

v_ticket_update.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <?php
  2. /* $Id$ */
  3. /*
  4. FusionPBX
  5. Version: MPL 1.1
  6. The contents of this file are subject to the Mozilla Public License Version
  7. 1.1 (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. http://www.mozilla.org/MPL/
  10. Software distributed under the License is distributed on an "AS IS" basis,
  11. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  12. for the specific language governing rights and limitations under the
  13. License.
  14. The Original Code is FusionPBX
  15. The Initial Developer of the Original Code is
  16. Mark J Crane <[email protected]>
  17. Portions created by the Initial Developer are Copyright (C) 2008-2012
  18. the Initial Developer. All Rights Reserved.
  19. Contributor(s):
  20. Ken Rice <[email protected]>
  21. Mark J Crane <[email protected]>
  22. */
  23. include "root.php";
  24. require_once "resources/require.php";
  25. require_once "resources/check_auth.php";
  26. if (permission_exists('ticket_view') || permission_exists('ticket_update')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. require_once "resources/header.php";
  34. $domain_name = $_SESSION['domains'][$domain_uuid]['domain_name'];
  35. // Check to see if we're an admin and if we are set the $isadmin to true for use in the template and sql query building
  36. if (if_group("superadmin") || if_group("admin")){
  37. $isadmin = true;
  38. }
  39. //add or update the database
  40. if (isset($_REQUEST['id']) || isset($_REQUEST['uuid'])) {
  41. $action = "update";
  42. if (isset($_REQUEST["id"])) {
  43. $ticket_id = check_str($_REQUEST["id"]);
  44. }
  45. if (isset($_REQUEST["uuid"])) {
  46. $ticket_uuid = check_str($_REQUEST["uuid"]);
  47. }
  48. } else {
  49. $action = "add";
  50. //Redirect back outta here probably
  51. }
  52. if ($action == "update") {
  53. //get the ticket
  54. $sql = "";
  55. $sql .= "select a.ticket_id, a.queue_id, a.domain_uuid, a.user_uuid, a.customer_id, a.subject, ";
  56. $sql .= "to_char(a.create_stamp, 'MM-DD-YY HH24-MI-SS') as create_stamp, a.create_user_id, ";
  57. $sql .= "a.ticket_status, to_char(a.last_update_stamp, 'MM-DD-YY HH24-MI-SS') as last_update_stamp, ";
  58. $sql .= "a.last_update_user_uuid, a.ticket_uuid, a.ticket_number, a.ticket_owner, a.customer_ticket_number, ";
  59. $sql .= "b.username, c.username as create_username, d.username as last_update_username ";
  60. $sql .= "from v_tickets as a, v_users as b, v_users as c, v_users as d ";
  61. $sql .= "where a.user_uuid = b.id and a.create_user_id = c.id and a.last_update_user_uuid = d.id ";
  62. $sql .= "and a.domain_uuid = '$domain_uuid' ";
  63. if (isset($_REQUEST["id"])) {
  64. $sql .= "and a.ticket_id = '$ticket_id' ";
  65. }
  66. if (isset($_REQUEST["uuid"])) {
  67. $sql .= "and a.ticket_uuid = '$ticket_uuid' ";
  68. }
  69. if (!$isadmin) {
  70. $sql .= "and a.user_uuid = " . $_SESSION['user_uuid'] . " ";
  71. }
  72. $prep_statement = $db->prepare(check_sql($sql));
  73. $prep_statement->execute();
  74. $x = 0;
  75. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  76. foreach ($result as &$row) {
  77. $ticket_header = $row;
  78. $x++;
  79. break;
  80. }
  81. unset ($prep_statement);
  82. if ($x < 1) {
  83. include "bad_ticket_id.php";
  84. goto end;
  85. }
  86. $sql = "";
  87. $sql .= "SELECT * from v_ticket_notes ";
  88. $sql .= "where ticket_id = " . $ticket_header['ticket_id'] . " ";
  89. $sql .= "order by create_stamp ";
  90. $prep_statement = $db->prepare(check_sql($sql));
  91. $prep_statement->execute();
  92. $x = 0;
  93. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  94. foreach ($result as &$row) {
  95. $ticket_notes[$x] = $row;
  96. $x++;
  97. }
  98. unset ($prep_statement);
  99. $sql = "";
  100. $sql .= "select a.*, c.username from v_ticket_queue_members as a, v_users as c ";
  101. $sql .= "where a.user_uuid = c.id ";
  102. $sql .= "and a.queue_id = " . $ticket_header['queue_id'] . " ";
  103. $prep_statement = $db->prepare(check_sql($sql));
  104. $prep_statement->execute();
  105. $x = 0;
  106. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  107. foreach ($result as &$row) {
  108. $queue_members[$x] = $row;
  109. $x++;
  110. }
  111. unset ($prep_statement);
  112. $sql = "";
  113. $sql .= "SELECT * from v_ticket_statuses ";
  114. $sql .= "where domain_uuid = $domain_uuid ";
  115. $sql .= "ORDER by status_id ";
  116. $prep_statement = $db->prepare(check_sql($sql));
  117. $prep_statement->execute();
  118. $x = 0;
  119. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  120. foreach ($result as &$row) {
  121. $ticket_statuses[$x] = $row;
  122. $x++;
  123. }
  124. unset ($prep_statement);
  125. $sql = "";
  126. $sql .= "SELECT * from v_ticket_queues ";
  127. $sql .= "where domain_uuid = $domain_uuid ";
  128. $sql .= "ORDER by queue_name ";
  129. $prep_statement = $db->prepare(check_sql($sql));
  130. $prep_statement->execute();
  131. $x = 0;
  132. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  133. foreach ($result as &$row) {
  134. $ticket_queues[$x] = $row;
  135. $x++;
  136. }
  137. unset ($prep_statement);
  138. }
  139. if ((!isset($_REQUEST['submit'])) || ($_REQUEST['submit'] != 'Save')) {
  140. // If we arent saving a Profile Display the form.
  141. include "ticket_update.php";
  142. goto end;
  143. }
  144. foreach ($_REQUEST as $field => $data){
  145. $request[$field] = check_str($data);
  146. }
  147. if ($action == "update" && permission_exists('ticket_update')) {
  148. if (strlen($request['new_note']) > 0) {
  149. $sql = "";
  150. $sql .= "INSERT into v_ticket_notes (";
  151. $sql .= "ticket_id, ";
  152. $sql .= "create_stamp, ";
  153. $sql .= "create_user_id, ";
  154. $sql .= "ticket_note ";
  155. $sql .= ") values ( ";
  156. $sql .= $ticket_header['ticket_id'] . ", ";
  157. $sql .= "now(), ";
  158. $sql .= $_SESSION['user_uuid'] . ", ";
  159. $sql .= "'" . base64_encode($request['new_note']) . "' ";
  160. $sql .= ")";
  161. $db->exec(check_sql($sql));
  162. $note_added = true;
  163. }
  164. $sql = "";
  165. $sql .= "UPDATE v_tickets set ";
  166. if ($ticket_header['ticket_owner'] != $request['ticket_owner']) {
  167. $sql .= "ticket_owner = " . $request['ticket_owner'] . ", ";
  168. if ($_SESSION['user_uuid'] != $request['ticket_owner']) {
  169. $alert_new_owner = true;
  170. }
  171. }
  172. if ($ticket_header['ticket_status'] != $request['ticket_status']) {
  173. $sql .= "ticket_status = " . $request['ticket_status'] . ", ";
  174. }
  175. if ($ticket_header['queue_id'] != $request['queue_id']) {
  176. $sql .= "queue_id = " . $request['queue_id'] . ", ";
  177. }
  178. $sql .= "last_update_user_uuid = " . $_SESSION['user_uuid'] . ", ";
  179. $sql .= "last_update_stamp = now() ";
  180. $sql .= "where ticket_id = " . $ticket_header['ticket_id'] . " ";
  181. $db->exec(check_sql($sql));
  182. if ($note_added && $request['alert_user']) {
  183. $sql = "select user_email from v_users where id = . " . $ticket_header['user_uuid'];
  184. $prep_statement = $db->prepare(check_sql($sql));
  185. $prep_statement->execute();
  186. $x = 0;
  187. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  188. foreach ($result as &$row) {
  189. $user_email = $row['user_email'];
  190. break;
  191. }
  192. unset ($prep_statement);
  193. if (strlen($user_email) > 1) {
  194. $subject = sprintf("[%s] Ticket %s Updated", $queue['queue_name'], $ticket_header['ticket_number']);
  195. $to = $user_email;
  196. $message = "";
  197. $message .= "Ticket Number $ticketnumber has been update\n";
  198. $message .= "Ticket Link: http://" . $_SESSION['domain_name'] . PROJECT_PATH . "/app/tickets/v_ticket_update.php?uuid=" . urlencode($ticket_uuid). "\n";
  199. $message .= "Ticket update: \n";
  200. $message .= $request['new_notes'] . "\n";
  201. $from = "From: " . $_SESSION['support_email'];
  202. mail($to, $subject, $message, $from);
  203. }
  204. }
  205. if ($alert_new_owner) {
  206. $sql = "select user_email from v_users where id = . " . $request['ticket_owner'];
  207. $prep_statement = $db->prepare(check_sql($sql));
  208. $prep_statement->execute();
  209. $x = 0;
  210. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  211. foreach ($result as &$row) {
  212. $user_email = $row['user_email'];
  213. break;
  214. }
  215. unset ($prep_statement);
  216. if (strlen($user_email) > 1) {
  217. $subject = sprintf("[%s] Ticket %s Updated", $queue['queue_name'], $ticket_header['ticket_number']);
  218. $to = $user_email;
  219. $message = "";
  220. $message .= "Ticket Number $ticketnumber has been update\n";
  221. $message .= "Ticket Link: http://" . $_SESSION['domain_name'] . PROJECT_PATH . "/app/tickets/v_ticket_update.php?uuid=" . urlencode($ticket_uuid). "\n";
  222. $from = "From: " . $_SESSION['support_email'];
  223. mail($to, $subject, $message, $from);
  224. }
  225. }
  226. goto writeout;
  227. }
  228. writeout:
  229. include "update_complete.php";
  230. end:
  231. //show the footer
  232. require_once "resources/footer.php";
  233. ?>