hunt_group_destination_edit.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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_add') || permission_exists('hunt_group_edit')) {
  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. //set the action as an add or an update
  36. if (isset($_REQUEST["id"])) {
  37. $action = "update";
  38. $hunt_group_destination_uuid = check_str($_REQUEST["id"]);
  39. }
  40. else {
  41. $action = "add";
  42. }
  43. if (isset($_REQUEST["id2"])) {
  44. $hunt_group_uuid = check_str($_REQUEST["id2"]);
  45. }
  46. //get the http values and set them as variables
  47. if (count($_POST)>0) {
  48. if (isset($_POST["hunt_group_uuid"])) {
  49. $hunt_group_uuid = check_str($_POST["hunt_group_uuid"]);
  50. }
  51. $destination_data = check_str($_POST["destination_data"]);
  52. $destination_type = check_str($_POST["destination_type"]);
  53. $destination_timeout = check_str($_POST["destination_timeout"]);
  54. $destination_order = check_str($_POST["destination_order"]);
  55. $destination_enabled = check_str($_POST["destination_enabled"]);
  56. $destination_description = check_str($_POST["destination_description"]);
  57. }
  58. if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
  59. $msg = '';
  60. if ($action == "update") {
  61. $hunt_group_destination_uuid = check_str($_POST["hunt_group_destination_uuid"]);
  62. }
  63. //check for all required data
  64. if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']."domain_uuid<br>\n"; }
  65. if (strlen($destination_data) == 0) { $msg .= $text['message-required'].$text['label-destination']."<br>\n"; }
  66. if (strlen($destination_type) == 0) { $msg .= $text['message-required'].$text['label-type']."<br>\n"; }
  67. //if (strlen($destination_timeout) == 0) { $msg .= $text['message-required'].$text['label-timeout']."<br>\n"; }
  68. //if (strlen($destination_order) == 0) { $msg .= $text['message-required'].$text['label-order']."<br>\n"; }
  69. //if (strlen($destination_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."<br>\n"; }
  70. //if (strlen($destination_description) == 0) { $msg .= $text['message-required'].$text['label-description']."<br>\n"; }
  71. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  72. require_once "resources/header.php";
  73. require_once "resources/persist_form_var.php";
  74. echo "<div align='center'>\n";
  75. echo "<table><tr><td>\n";
  76. echo $msg."<br />";
  77. echo "</td></tr></table>\n";
  78. persistformvar($_POST);
  79. echo "</div>\n";
  80. require_once "resources/footer.php";
  81. return;
  82. }
  83. //add or update the database
  84. if ($_POST["persistformvar"] != "true") {
  85. if ($action == "add" && permission_exists('hunt_group_add')) {
  86. $hunt_group_destination_uuid = uuid();
  87. $sql = "insert into v_hunt_group_destinations ";
  88. $sql .= "(";
  89. $sql .= "domain_uuid, ";
  90. $sql .= "hunt_group_uuid, ";
  91. $sql .= "hunt_group_destination_uuid, ";
  92. $sql .= "destination_data, ";
  93. $sql .= "destination_type, ";
  94. $sql .= "destination_timeout, ";
  95. $sql .= "destination_order, ";
  96. $sql .= "destination_enabled, ";
  97. $sql .= "destination_description ";
  98. $sql .= ")";
  99. $sql .= "values ";
  100. $sql .= "(";
  101. $sql .= "'$domain_uuid', ";
  102. $sql .= "'$hunt_group_uuid', ";
  103. $sql .= "'$hunt_group_destination_uuid', ";
  104. $sql .= "'$destination_data', ";
  105. $sql .= "'$destination_type', ";
  106. $sql .= "'$destination_timeout', ";
  107. $sql .= "'$destination_order', ";
  108. $sql .= "'$destination_enabled', ";
  109. $sql .= "'$destination_description' ";
  110. $sql .= ")";
  111. $db->exec(check_sql($sql));
  112. unset($sql);
  113. //synchronize the xml config
  114. save_hunt_group_xml();
  115. require_once "resources/header.php";
  116. echo "<meta http-equiv=\"refresh\" content=\"2;url=hunt_group_edit.php?id=".$hunt_group_uuid."\">\n";
  117. echo "<div align='center'>\n";
  118. echo $text['message-add']."\n";
  119. echo "</div>\n";
  120. require_once "resources/footer.php";
  121. return;
  122. } //if ($action == "add")
  123. if ($action == "update" && permission_exists('hunt_group_edit')) {
  124. $sql = "update v_hunt_group_destinations set ";
  125. $sql .= "domain_uuid = '$domain_uuid', ";
  126. $sql .= "hunt_group_uuid = '$hunt_group_uuid', ";
  127. $sql .= "destination_data = '$destination_data', ";
  128. $sql .= "destination_type = '$destination_type', ";
  129. $sql .= "destination_timeout = '$destination_timeout', ";
  130. $sql .= "destination_order = '$destination_order', ";
  131. $sql .= "destination_enabled = '$destination_enabled', ";
  132. $sql .= "destination_description = '$destination_description' ";
  133. $sql .= "where domain_uuid = '$domain_uuid' ";
  134. $sql .= "and hunt_group_destination_uuid = '$hunt_group_destination_uuid'";
  135. $db->exec(check_sql($sql));
  136. //synchronize the xml config
  137. save_hunt_group_xml();
  138. require_once "resources/header.php";
  139. echo "<meta http-equiv=\"refresh\" content=\"2;url=hunt_group_edit.php?id=".$hunt_group_uuid."\">\n";
  140. echo "<div align='center'>\n";
  141. echo $text['message-update']."\n";
  142. echo "</div>\n";
  143. require_once "resources/footer.php";
  144. return;
  145. } //if ($action == "update")
  146. } //if ($_POST["persistformvar"] != "true")
  147. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  148. //pre-populate the form
  149. if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
  150. $hunt_group_destination_uuid = $_GET["id"];
  151. $sql = "select * from v_hunt_group_destinations ";
  152. $sql .= "where domain_uuid = '$domain_uuid' ";
  153. $sql .= "and hunt_group_destination_uuid = '$hunt_group_destination_uuid' ";
  154. $prep_statement = $db->prepare(check_sql($sql));
  155. $prep_statement->execute();
  156. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  157. foreach ($result as &$row) {
  158. $hunt_group_uuid = $row["hunt_group_uuid"];
  159. $destination_data = $row["destination_data"];
  160. $destination_type = $row["destination_type"];
  161. $destination_timeout = $row["destination_timeout"];
  162. $destination_order = $row["destination_order"];
  163. $destination_enabled = $row["destination_enabled"];
  164. $destination_description = $row["destination_description"];
  165. break; //limit to 1 row
  166. }
  167. unset ($prep_statement);
  168. }
  169. //show the header
  170. require_once "resources/header.php";
  171. if ($action == "add") {
  172. $page["title"] = $text['title-hunt_group_destination_add'];
  173. }
  174. if ($action == "update") {
  175. $page["title"] = $text['title-hunt_group_destination_edit'];
  176. }
  177. //show the content
  178. echo "<div align='center'>";
  179. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  180. echo "<tr class='border'>\n";
  181. echo " <td align=\"left\">\n";
  182. echo " <br>";
  183. echo "<form method='post' name='frm' action=''>\n";
  184. echo "<div align='center'>\n";
  185. echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
  186. echo "<tr>\n";
  187. if ($action == "add") {
  188. echo "<td align='left' width='30%' nowrap><b>".$text['header-hunt_group_destination_add']."</b></td>\n";
  189. }
  190. if ($action == "update") {
  191. echo "<td align='left' width='30%' nowrap><b>".$text['header-hunt_group_destination_edit']."</b></td>\n";
  192. }
  193. echo "<td width='70%' align='right'><input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='hunt_group_edit.php?id=".$hunt_group_uuid."'\" value='".$text['button-back']."'></td>\n";
  194. echo "</tr>\n";
  195. echo "<tr>\n";
  196. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  197. echo " ".$text['label-destination'].":\n";
  198. echo "</td>\n";
  199. echo "<td class='vtable' align='left'>\n";
  200. echo " <input class='formfld' type='text' name='destination_data' maxlength='255' value=\"$destination_data\">\n";
  201. echo "<br />\n";
  202. echo "<b>".$text['description-destination_examples']."</b>...<br>\n";
  203. echo $text['description-destination_example_extension'].": 1001<br />\n";
  204. echo $text['description-destination_example_voicemail'].": 1001<br />\n";
  205. echo $text['description-destination_example_sip_uri_voicemail'].": sofia/internal/*98@\${domain}<br />\n";
  206. echo $text['description-destination_example_sip_uri_external_number'].": sofia/gateway/gatewayname/12081231234<br />\n";
  207. echo $text['description-destination_example_sip_uri_auto_attendant'].": sofia/internal/5002@\${domain}<br />\n";
  208. echo $text['description-destination_example_sip_uri_user'].": /user/1001@\${domain}\n";
  209. echo "</td>\n";
  210. echo "</tr>\n";
  211. echo "<tr>\n";
  212. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  213. echo " ".$text['label-type'].":\n";
  214. echo "</td>\n";
  215. echo "<td class='vtable' align='left'>\n";
  216. echo " <select name='destination_type' class='formfld'>\n";
  217. echo " <option></option>\n";
  218. if ($destination_type == "extension") {
  219. echo " <option selected='yes' value='extension'>".$text['option-extension']."</option>\n";
  220. }
  221. else {
  222. echo " <option value='extension'>".$text['option-extension']."</option>\n";
  223. }
  224. if ($destination_type == "voicemail") {
  225. echo " <option selected='yes' value='voicemail'>".$text['option-voicemail']."</option>\n";
  226. }
  227. else {
  228. echo " <option value='voicemail'>".$text['option-voicemail']."</option>\n";
  229. }
  230. if ($destination_type == "sip uri") {
  231. echo " <option selected='yes' value='sip uri'>".$text['option-sip_uri']."</option>\n";
  232. }
  233. else {
  234. echo " <option value='sip uri'>".$text['option-sip_uri']."</option>\n";
  235. }
  236. echo " </select>\n";
  237. echo "<br />\n";
  238. echo "\n";
  239. echo "</td>\n";
  240. echo "</tr>\n";
  241. echo "<tr>\n";
  242. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  243. echo " ".$text['label-timeout'].":\n";
  244. echo "</td>\n";
  245. echo "<td class='vtable' align='left'>\n";
  246. echo " <select name='destination_timeout' class='formfld'>\n";
  247. echo " <option></option>\n";
  248. if (strlen($destination_timeout)> 0) {
  249. echo " <option selected='yes' value='".htmlspecialchars($destination_timeout)."'>".htmlspecialchars($destination_timeout)."</option>\n";
  250. }
  251. $i=0;
  252. while($i<=301) {
  253. echo " <option value='$i'>$i</option>\n";
  254. $i++;
  255. }
  256. echo " </select>\n";
  257. echo "<br />\n";
  258. echo $text['description-destination_timeout']."\n";
  259. echo "</td>\n";
  260. echo "</tr>\n";
  261. echo "<tr>\n";
  262. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  263. echo " ".$text['label-order'].":\n";
  264. echo "</td>\n";
  265. echo "<td class='vtable' align='left'>\n";
  266. echo " <select name='destination_order' class='formfld'>\n";
  267. if (strlen($destination_order)> 0) {
  268. echo " <option selected='yes' value='".htmlspecialchars($destination_order)."'>".htmlspecialchars($destination_order)."</option>\n";
  269. }
  270. $i=0;
  271. while($i<=301) {
  272. if (strlen($i) == 1) {
  273. echo " <option value='00$i'>00$i</option>\n";
  274. }
  275. if (strlen($i) == 2) {
  276. echo " <option value='0$i'>0$i</option>\n";
  277. }
  278. if (strlen($i) == 3) {
  279. echo " <option value='$i'>$i</option>\n";
  280. }
  281. $i++;
  282. }
  283. echo " </select>\n";
  284. echo "<br />\n";
  285. echo $text['description-destination_order']."\n";
  286. echo "</td>\n";
  287. echo "</tr>\n";
  288. echo "<tr>\n";
  289. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  290. echo " ".$text['label-enabled'].":\n";
  291. echo "</td>\n";
  292. echo "<td class='vtable' align='left'>\n";
  293. echo " <select class='formfld' name='destination_enabled'>\n";
  294. echo " <option value=''></option>\n";
  295. if ($destination_enabled == "true" || strlen($destination_enabled) == 0) {
  296. echo " <option value='true' selected >".$text['option-true']."</option>\n";
  297. }
  298. else {
  299. echo " <option value='true'>".$text['option-true']."</option>\n";
  300. }
  301. if ($destination_enabled == "false") {
  302. echo " <option value='false' selected >".$text['option-false']."</option>\n";
  303. }
  304. else {
  305. echo " <option value='false'>".$text['option-false']."</option>\n";
  306. }
  307. echo " </select>\n";
  308. echo "<br />\n";
  309. echo "\n";
  310. echo "</td>\n";
  311. echo "</tr>\n";
  312. echo "<tr>\n";
  313. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  314. echo " ".$text['label-description'].":\n";
  315. echo "</td>\n";
  316. echo "<td class='vtable' align='left'>\n";
  317. echo " <input class='formfld' type='text' name='destination_description' maxlength='255' value=\"$destination_description\">\n";
  318. echo "<br />\n";
  319. echo $text['description-description']."\n";
  320. echo "</td>\n";
  321. echo "</tr>\n";
  322. echo " <tr>\n";
  323. echo " <td colspan='2' align='right'>\n";
  324. echo " <input type='hidden' name='hunt_group_uuid' value='$hunt_group_uuid'>\n";
  325. if ($action == "update") {
  326. echo " <input type='hidden' name='hunt_group_destination_uuid' value='$hunt_group_destination_uuid'>\n";
  327. }
  328. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  329. echo " </td>\n";
  330. echo " </tr>";
  331. echo "</table>";
  332. echo "</form>";
  333. echo " </td>";
  334. echo " </tr>";
  335. echo "</table>";
  336. echo "</div>";
  337. //show the footer
  338. require_once "resources/footer.php";
  339. ?>