v_ticket_create.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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 "includes/require.php";
  25. require_once "includes/checkauth.php";
  26. if (permission_exists('ticket_add') || permission_exists('ticket_update')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. require_once "includes/header.php";
  34. $v_domain = $_SESSION['domains'][$domain_uuid]['domain'];
  35. //get a list of Available Queues
  36. $sql = "";
  37. $sql .= "select * from v_ticket_queues ";
  38. $sql .= "where domain_uuid = '$domain_uuid' ";
  39. $sql .= "order by queue_name ";
  40. $prep_statement = $db->prepare(check_sql($sql));
  41. $prep_statement->execute();
  42. $x = 0;
  43. $result = $prep_statement->fetchAll();
  44. foreach ($result as &$row) {
  45. $queues[$x] = $row;
  46. $x++;
  47. }
  48. unset ($prep_statement);
  49. //add or update the database
  50. if (isset($_REQUEST["id"])) {
  51. $action = "update";
  52. $profile_id = check_str($_REQUEST["id"]);
  53. } else {
  54. $action = "add";
  55. }
  56. if ($action == "update") {
  57. // TODO: Check to see if Ticket Exists and user has access to that ticket then redirect to that ticket else Display Ticket Error
  58. }
  59. if ((!isset($_REQUEST['submit'])) || ($_REQUEST['submit'] != 'Save')) {
  60. // If we arent saving a Profile Display the form.
  61. include "ticket_create.php";
  62. goto end;
  63. }
  64. foreach ($_REQUEST as $field => $data){
  65. $request[$field] = check_str($data);
  66. }
  67. // DataChecking Goes Here
  68. $error = "";
  69. if (strlen($request['subject']) < 1) $error .= "Ticket Subject is a Required Field<br />\n";
  70. if (strlen($request['problem_description']) < 1) $error .= "Ticket Body is a Required Field<br />\n";
  71. if (strlen($error) > 0) {
  72. include "errors.php";
  73. $profile = $request;
  74. include "profile_edit.php";
  75. goto end;
  76. }
  77. // Save New Entry
  78. if ($action == "add" && permission_exists('ticket_add')) {
  79. $ticket_uuid = uuid();
  80. $sql = "";
  81. $sql .= "insert into v_tickets (";
  82. $sql .= "domain_uuid, ";
  83. $sql .= "queue_id, ";
  84. $sql .= "user_uuid, ";
  85. $sql .= "customer_id, ";
  86. $sql .= "subject, ";
  87. $sql .= "create_user_id, ";
  88. $sql .= "create_stamp, ";
  89. $sql .= "last_update_user_uuid, ";
  90. $sql .= "last_update_stamp, ";
  91. $sql .= "ticket_uuid, ";
  92. $sql .= "ticket_status, ";
  93. $sql .= "customer_ticket_number ";
  94. $sql .= ") values (";
  95. $sql .= "$domain_uuid, ";
  96. $sql .= "'" . $request['queue_id'] . "', ";
  97. $sql .= "'" . $_SESSION['user_uuid'] . "', ";
  98. $sql .= "'" . $_SESSION['customer_id'] . "', ";
  99. $sql .= "'" . $request['subject'] . "', ";
  100. $sql .= "'" . $_SESSION['user_uuid'] . "', ";
  101. $sql .= "now(), ";
  102. $sql .= "'" . $_SESSION['user_uuid'] . "', ";
  103. $sql .= "now(), ";
  104. $sql .= "'" . $ticket_uuid . "', ";
  105. $sql .= "'1', ";
  106. $sql .= "'" . $request['customer_ticket_number'] . "'";
  107. $sql .= ") ";
  108. if ($db_type == "pgsql") {
  109. $sql .= "RETURNING ticket_id;";
  110. $prep_statement = $db->prepare(check_sql($sql));
  111. $prep_statement->execute();
  112. $result = $prep_statement->fetchAll();
  113. $ticket_id = $result[0]['ticket_id'];
  114. } elseif ($db_type == "sqlite" || $db_type == "mysql" ) {
  115. $db->exec(check_sql($sql));
  116. $ticket_id = $db->lastInsertId();
  117. }
  118. $ticket_number = date("ymd") . "-" . sprintf("%03d", substr($ticket_id, -3));
  119. $sql = "UPDATE v_tickets set ticket_number = '". $ticket_number. "' where ticket_id = " . $ticket_id . " ";
  120. $db->exec(check_sql($sql));
  121. $sql = "";
  122. $sql .= "INSERT into v_ticket_notes (";
  123. $sql .= "ticket_id, ";
  124. $sql .= "create_user_id, ";
  125. $sql .= "create_stamp, ";
  126. $sql .= "ticket_note ";
  127. $sql .= ") VALUES ( ";
  128. $sql .= "$ticket_id, ";
  129. $sql .= "'" . $_SESSION['user_uuid'] . "', ";
  130. $sql .= "now(), ";
  131. $sql .= "'" . base64_encode($request['problem_description']) . "' ";
  132. $sql .= ") ";
  133. $db->exec(check_sql($sql));
  134. $sql = "";
  135. $sql .= "SELECT * from v_ticket_queues ";
  136. $sql .= "where queue_id = " . $request['queue_id'] . " ";
  137. $sql .= "and domain_uuid = $domain_uuid ";
  138. $prep_statement = $db->prepare(check_sql($sql));
  139. $prep_statement->execute();
  140. $x = 0;
  141. $result = $prep_statement->fetchAll();
  142. foreach ($result as &$row) {
  143. $queue = $row;
  144. break;
  145. }
  146. $subject = sprintf("[%s] New Ticket: %s", $queue['queue_name'], $request['subject']);
  147. $to = $queue['queue_email'];
  148. $message = "";
  149. $message .= "Ticket Number $ticketnumber has been created by $username in " . $queue['queue_name'] . "\n";
  150. $message .= "Ticket Link: http://" . $_SESSION['v_domain'] . PROJECT_PATH . "/app/tickets/v_ticket_update.php?uuid=" . urlencode($ticket_uuid). "\n";
  151. $message .= "Ticket body: \n";
  152. $message .= $request['problem_description'] . "\n";
  153. $from = "From: " . $_SESSION['support_email'];
  154. mail($to, $subject, $message, $from);
  155. unset ($prep_statement);
  156. goto writeout;
  157. }
  158. writeout:
  159. include "update_complete.php";
  160. end:
  161. //show the footer
  162. require_once "includes/footer.php";
  163. ?>