hunt_group_delete.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2012
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. include "root.php";
  22. require_once "resources/require.php";
  23. require_once "resources/check_auth.php";
  24. //check permissions
  25. if (permission_exists('hunt_group_delete')) {
  26. //access granted
  27. }
  28. else {
  29. echo "access denied";
  30. exit;
  31. }
  32. //add multi-lingual support
  33. $language = new text;
  34. $text = $language->get();
  35. //get the id
  36. if (count($_GET)>0) {
  37. $id = $_GET["id"];
  38. }
  39. if (strlen($id)>0) {
  40. //start the atomic transaction
  41. $count = $db->exec("BEGIN;");
  42. //get the dialplan uuid
  43. $sql = "select * from v_hunt_groups ";
  44. $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  45. $sql .= "and hunt_group_uuid = '$id' ";
  46. $prep_statement = $db->prepare($sql);
  47. $prep_statement->execute();
  48. while($row = $prep_statement->fetch(PDO::FETCH_ASSOC)) {
  49. $dialplan_uuid = $row['dialplan_uuid'];
  50. }
  51. //delete child data
  52. $sql = "delete from v_hunt_group_destinations ";
  53. $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  54. $sql .= "and hunt_group_uuid = '$id' ";
  55. $db->query($sql);
  56. unset($sql);
  57. //delete parent data
  58. $sql = "delete from v_hunt_groups ";
  59. $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  60. $sql .= "and hunt_group_uuid = '$id' ";
  61. $db->query($sql);
  62. unset($sql);
  63. //delete the dialplan entry
  64. $sql = "delete from v_dialplans ";
  65. $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  66. $sql .= "and dialplan_uuid = '$dialplan_uuid' ";
  67. //echo $sql."<br>\n";
  68. $db->query($sql);
  69. unset($sql);
  70. //delete the dialplan details
  71. $sql = "delete from v_dialplan_details ";
  72. $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  73. $sql .= "and dialplan_uuid = '$dialplan_uuid' ";
  74. //echo $sql."<br>\n";
  75. $db->query($sql);
  76. unset($sql);
  77. //commit the atomic transaction
  78. $count = $db->exec("COMMIT;");
  79. //synchronize the xml config
  80. save_hunt_group_xml();
  81. //delete the dialplan context from memcache
  82. $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
  83. if ($fp) {
  84. $switch_cmd = "memcache delete dialplan:".$_SESSION["context"]."@".$_SESSION['domain_name'];
  85. $switch_result = event_socket_request($fp, 'api '.$switch_cmd);
  86. }
  87. }
  88. //redirect the user
  89. require_once "resources/header.php";
  90. echo "<meta http-equiv=\"refresh\" content=\"2;url=hunt_groups.php\">\n";
  91. echo "<div align='center'>\n";
  92. echo $text['message-delete']."\n";
  93. echo "</div>\n";
  94. require_once "resources/footer.php";
  95. return;
  96. ?>