hunt_group_edit.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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. require_once "resources/paging.php";
  25. //check permissions
  26. if (permission_exists('hunt_group_add') || permission_exists('hunt_group_edit')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. //add multi-lingual support
  34. $language = new text;
  35. $text = $language->get();
  36. //action add or update
  37. if (isset($_REQUEST["id"])) {
  38. $action = "update";
  39. $hunt_group_uuid = check_str($_REQUEST["id"]);
  40. $dialplan_uuid = check_str($_REQUEST["dialplan_uuid"]);
  41. }
  42. else {
  43. $action = "add";
  44. }
  45. //get the http values and set them as variables
  46. if (count($_POST)>0) {
  47. $hunt_group_extension = check_str($_POST["hunt_group_extension"]);
  48. $hunt_group_name = check_str($_POST["hunt_group_name"]);
  49. $hunt_group_type = check_str($_POST["hunt_group_type"]);
  50. $hunt_group_timeout = check_str($_POST["hunt_group_timeout"]);
  51. $hunt_group_timeout_destination = check_str($_POST["hunt_group_timeout_destination"]);
  52. $hunt_group_timeout_type = check_str($_POST["hunt_group_timeout_type"]);
  53. $hunt_group_ringback = check_str($_POST["hunt_group_ringback"]);
  54. $hunt_group_cid_name_prefix = check_str($_POST["hunt_group_cid_name_prefix"]);
  55. $hunt_group_pin = check_str($_POST["hunt_group_pin"]);
  56. $hunt_group_caller_announce = check_str($_POST["hunt_group_caller_announce"]);
  57. //prepare the user list for the database
  58. $hunt_group_user_list = $_POST["hunt_group_user_list"];
  59. if (strlen($hunt_group_user_list) > 0) {
  60. $hunt_group_user_list_array = explode("\n", $hunt_group_user_list);
  61. if (count($hunt_group_user_list_array) == 0) {
  62. $hunt_group_user_list = '';
  63. }
  64. else {
  65. $hunt_group_user_list = '|';
  66. foreach($hunt_group_user_list_array as $user){
  67. if(strlen(trim($user)) > 0) {
  68. $hunt_group_user_list .= check_str(trim($user))."|";
  69. }
  70. }
  71. }
  72. }
  73. $hunt_group_enabled = check_str($_POST["hunt_group_enabled"]);
  74. $hunt_group_description = check_str($_POST["hunt_group_description"]);
  75. //remove invalid characters
  76. $hunt_group_cid_name_prefix = str_replace(":", "-", $hunt_group_cid_name_prefix);
  77. $hunt_group_cid_name_prefix = str_replace("\"", "", $hunt_group_cid_name_prefix);
  78. $hunt_group_cid_name_prefix = str_replace("@", "", $hunt_group_cid_name_prefix);
  79. $hunt_group_cid_name_prefix = str_replace("\\", "", $hunt_group_cid_name_prefix);
  80. $hunt_group_cid_name_prefix = str_replace("/", "", $hunt_group_cid_name_prefix);
  81. //set default
  82. if (strlen($hunt_group_caller_announce) == 0) { $hunt_group_caller_announce = "false"; }
  83. }
  84. if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
  85. $msg = '';
  86. if ($action == "update") {
  87. $hunt_group_uuid = check_str($_POST["hunt_group_uuid"]);
  88. }
  89. //check for all required data
  90. if (strlen($domain_uuid) == 0) { $msg .= $text['message-required']."domain_uuid<br>\n"; }
  91. if (strlen($hunt_group_extension) == 0) { $msg .= $text['message-required'].$text['label-extension']."<br>\n"; }
  92. if (strlen($hunt_group_name) == 0) { $msg .= $text['message-required'].$text['label-name']."<br>\n"; }
  93. if (strlen($hunt_group_type) == 0) { $msg .= $text['message-required'].$text['label-strategy']."<br>\n"; }
  94. if (strlen($hunt_group_timeout) == 0) { $msg .= $text['message-required'].$text['label-timeout']."<br>\n"; }
  95. if (strlen($hunt_group_timeout_destination) == 0) { $msg .= $text['message-required'].$text['label-timeout_destination']."<br>\n"; }
  96. if (strlen($hunt_group_timeout_type) == 0) { $msg .= $text['message-required'].$text['label-timeout_type']."<br>\n"; }
  97. //if (strlen($hunt_group_ringback) == 0) { $msg .= $text['message-required'].$text['label-ring_back']."<br>\n"; }
  98. //if (strlen($hunt_group_cid_name_prefix) == 0) { $msg .= $text['message-required'].$text['label-caller_id_name_prefix']."<br>\n"; }
  99. //if (strlen($hunt_group_pin) == 0) { $msg .= $text['message-required'].$text['label-pin_number']."<br>\n"; }
  100. if (strlen($hunt_group_caller_announce) == 0) { $msg .= $text['message-required'].$text['label-caller_announce']."<br>\n"; }
  101. //if (strlen($hunt_group_user_list) == 0) { $msg .= $text['message-required'].$text['label-user_list']."<br>\n"; }
  102. //if (strlen($hunt_group_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."<br>\n"; }
  103. //if (strlen($hunt_group_description) == 0) { $msg .= $text['message-required'].$text['label-description']."<br>\n"; }
  104. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  105. require_once "resources/header.php";
  106. require_once "resources/persist_form_var.php";
  107. echo "<div align='center'>\n";
  108. echo "<table><tr><td>\n";
  109. echo $msg."<br />";
  110. echo "</td></tr></table>\n";
  111. persistformvar($_POST);
  112. echo "</div>\n";
  113. require_once "resources/footer.php";
  114. return;
  115. }
  116. //add or update the database
  117. if ($_POST["persistformvar"] != "true") {
  118. if ($action == "add" && permission_exists('hunt_group_add')) {
  119. //add to the table
  120. $dialplan_uuid = uuid();
  121. $hunt_group_uuid = uuid();
  122. $sql = "insert into v_hunt_groups ";
  123. $sql .= "(";
  124. $sql .= "domain_uuid, ";
  125. $sql .= "dialplan_uuid, ";
  126. $sql .= "hunt_group_uuid, ";
  127. $sql .= "hunt_group_extension, ";
  128. $sql .= "hunt_group_name, ";
  129. $sql .= "hunt_group_type, ";
  130. $sql .= "hunt_group_context, ";
  131. $sql .= "hunt_group_timeout, ";
  132. $sql .= "hunt_group_timeout_destination, ";
  133. $sql .= "hunt_group_timeout_type, ";
  134. $sql .= "hunt_group_ringback, ";
  135. $sql .= "hunt_group_cid_name_prefix, ";
  136. $sql .= "hunt_group_pin, ";
  137. $sql .= "hunt_group_caller_announce, ";
  138. $sql .= "hunt_group_user_list, ";
  139. $sql .= "hunt_group_enabled, ";
  140. $sql .= "hunt_group_description ";
  141. $sql .= ")";
  142. $sql .= "values ";
  143. $sql .= "(";
  144. $sql .= "'$domain_uuid', ";
  145. $sql .= "'$dialplan_uuid', ";
  146. $sql .= "'$hunt_group_uuid', ";
  147. $sql .= "'$hunt_group_extension', ";
  148. $sql .= "'$hunt_group_name', ";
  149. $sql .= "'$hunt_group_type', ";
  150. $sql .= "'".$_SESSION['context']."', ";
  151. $sql .= "'$hunt_group_timeout', ";
  152. $sql .= "'$hunt_group_timeout_destination', ";
  153. $sql .= "'$hunt_group_timeout_type', ";
  154. $sql .= "'$hunt_group_ringback', ";
  155. $sql .= "'$hunt_group_cid_name_prefix', ";
  156. $sql .= "'$hunt_group_pin', ";
  157. $sql .= "'$hunt_group_caller_announce', ";
  158. $sql .= "'$hunt_group_user_list', ";
  159. $sql .= "'$hunt_group_enabled', ";
  160. $sql .= "'$hunt_group_description' ";
  161. $sql .= ")";
  162. $db->exec(check_sql($sql));
  163. unset($sql);
  164. //synchronize the xml config
  165. save_hunt_group_xml();
  166. //redirect the user
  167. require_once "resources/header.php";
  168. echo "<meta http-equiv=\"refresh\" content=\"2;url=hunt_groups.php\">\n";
  169. echo "<div align='center'>\n";
  170. echo $text['message-add']."\n";
  171. echo "</div>\n";
  172. require_once "resources/footer.php";
  173. return;
  174. } //if ($action == "add")
  175. if ($action == "update" && permission_exists('hunt_group_edit')) {
  176. //update the table
  177. $sql = "update v_hunt_groups set ";
  178. $sql .= "hunt_group_extension = '$hunt_group_extension', ";
  179. $sql .= "hunt_group_name = '$hunt_group_name', ";
  180. $sql .= "hunt_group_type = '$hunt_group_type', ";
  181. $sql .= "hunt_group_context = '".$_SESSION['context']."', ";
  182. $sql .= "hunt_group_timeout = '$hunt_group_timeout', ";
  183. $sql .= "hunt_group_timeout_destination = '$hunt_group_timeout_destination', ";
  184. $sql .= "hunt_group_timeout_type = '$hunt_group_timeout_type', ";
  185. $sql .= "hunt_group_ringback = '$hunt_group_ringback', ";
  186. $sql .= "hunt_group_cid_name_prefix = '$hunt_group_cid_name_prefix', ";
  187. $sql .= "hunt_group_pin = '$hunt_group_pin', ";
  188. $sql .= "hunt_group_caller_announce = '$hunt_group_caller_announce', ";
  189. if (if_group("admin") || if_group("superadmin")) {
  190. $sql .= "hunt_group_user_list = '$hunt_group_user_list', ";
  191. }
  192. $sql .= "hunt_group_enabled = '$hunt_group_enabled', ";
  193. $sql .= "hunt_group_description = '$hunt_group_description' ";
  194. $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  195. $sql .= "and hunt_group_uuid = '$hunt_group_uuid'";
  196. $db->exec(check_sql($sql));
  197. unset($sql);
  198. //update the dialplan entry
  199. require_once "resources/classes/dialplan.php";
  200. $dialplan = new dialplan;
  201. $dialplan->domain_uuid = $_SESSION['domain_uuid'];
  202. $dialplan->app_uuid = $app_uuid;
  203. $dialplan->dialplan_uuid = $dialplan_uuid;
  204. $dialplan->dialplan_name = $hunt_group_name;
  205. //$dialplan->dialplan_continue = $dialplan_continue;
  206. //$dialplan->dialplan_order = '330';
  207. $dialplan->dialplan_context = $_SESSION['context'];
  208. $dialplan->dialplan_enabled = $hunt_group_enabled;
  209. $dialplan->dialplan_description = $hunt_group_description;
  210. $dialplan->dialplan_update();
  211. unset($dialplan);
  212. //update the condition
  213. $sql = "update v_dialplan_details set ";
  214. $sql .= "dialplan_detail_data = '^".$hunt_group_extension."$' ";
  215. $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  216. $sql .= "and dialplan_detail_tag = 'condition' ";
  217. $sql .= "and dialplan_detail_type = 'destination_number' ";
  218. $sql .= "and dialplan_uuid = '$dialplan_uuid' ";
  219. $sql .= "and dialplan_detail_group = '1' ";
  220. $db->query($sql);
  221. unset($sql);
  222. //update the action
  223. $sql = "update v_dialplan_details set ";
  224. $sql .= "dialplan_detail_data = 'v_huntgroup_".$_SESSION['domain_name']."_".$hunt_group_extension.".lua', ";
  225. $sql .= "dialplan_detail_type = 'lua' ";
  226. $sql .= "where domain_uuid = '".$_SESSION['domain_uuid']."' ";
  227. $sql .= "and dialplan_detail_tag = 'action' ";
  228. $sql .= "and dialplan_uuid = '$dialplan_uuid' ";
  229. $sql .= "and dialplan_detail_type = 'lua' ";
  230. $sql .= "and dialplan_detail_group = '1' ";
  231. $db->query($sql);
  232. //synchronize the xml config
  233. save_hunt_group_xml();
  234. //delete the dialplan context from memcache
  235. $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
  236. if ($fp) {
  237. $switch_cmd = "memcache delete dialplan:".$_SESSION["context"]."@".$_SESSION['domain_name'];
  238. $switch_result = event_socket_request($fp, 'api '.$switch_cmd);
  239. }
  240. //rediret the user
  241. require_once "resources/header.php";
  242. echo "<meta http-equiv=\"refresh\" content=\"2;url=hunt_groups.php\">\n";
  243. echo "<div align='center'>\n";
  244. echo $text['message-update']."\n";
  245. echo "</div>\n";
  246. require_once "resources/footer.php";
  247. return;
  248. } //if ($action == "update")
  249. } //if ($_POST["persistformvar"] != "true")
  250. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  251. //pre-populate the form
  252. if (count($_GET)>0 && $_POST["persistformvar"] != "true") {
  253. $hunt_group_uuid = $_GET["id"];
  254. $sql = "select * from v_hunt_groups ";
  255. $sql .= "where hunt_group_uuid = '$hunt_group_uuid' ";
  256. $sql .= "and domain_uuid = '$domain_uuid' ";
  257. $sql .- "hunt_group_enabled = 'true' ";
  258. $prep_statement = $db->prepare(check_sql($sql));
  259. $prep_statement->execute();
  260. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  261. foreach ($result as &$row) {
  262. $dialplan_uuid = $row["dialplan_uuid"];
  263. $hunt_group_extension = $row["hunt_group_extension"];
  264. $hunt_group_name = $row["hunt_group_name"];
  265. $hunt_group_type = $row["hunt_group_type"];
  266. $hunt_group_timeout = $row["hunt_group_timeout"];
  267. $hunt_group_timeout_destination = $row["hunt_group_timeout_destination"];
  268. $hunt_group_timeout_type = $row["hunt_group_timeout_type"];
  269. $hunt_group_ringback = $row["hunt_group_ringback"];
  270. $hunt_group_cid_name_prefix = $row["hunt_group_cid_name_prefix"];
  271. $hunt_group_pin = $row["hunt_group_pin"];
  272. $hunt_group_caller_announce = $row["hunt_group_caller_announce"];
  273. $hunt_group_user_list = $row["hunt_group_user_list"];
  274. $hunt_group_enabled = $row["hunt_group_enabled"];
  275. $hunt_group_description = $row["hunt_group_description"];
  276. break; //limit to 1 row
  277. }
  278. unset ($prep_statement);
  279. }
  280. //show the header
  281. require_once "resources/header.php";
  282. $page["title"] = $text['title-hunt_group'];
  283. //show the content
  284. echo "<div align='center'>";
  285. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  286. echo "<tr class='border'>\n";
  287. echo "<td align=\"left\">\n";
  288. echo "<br>";
  289. echo "<form method='post' name='frm' action=''>\n";
  290. echo "<div align='center'>\n";
  291. echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
  292. echo "<tr>\n";
  293. echo "<td align='left' colspan='2'>\n";
  294. echo "<table width='100%'>\n";
  295. echo "<tr>\n";
  296. echo "<td align='left' width='30%' nowrap>\n";
  297. echo " <span class='vexpl'>\n";
  298. echo " <strong>".$text['header-hunt_group']."</strong><br>\n";
  299. echo " </span>\n";
  300. echo "</td>\n";
  301. echo "<td width='70%' align='right'>\n";
  302. if ($action != "add") {
  303. echo " <input type='button' class='btn' name='' alt='".$text['button-copy']."' onclick=\"var new_ext = prompt('".$text['message_extension']."'); if (new_ext != null) { window.location='hunt_group_copy.php?id=".$hunt_group_uuid."&ext=' + new_ext; }\" value='".$text['button-copy']."'>\n";
  304. }
  305. echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='hunt_groups.php'\" value='".$text['button-back']."'>\n";
  306. echo "</td>\n";
  307. echo "</tr>\n";
  308. echo "<tr>\n";
  309. echo "<td align='left' colspan='2'>\n";
  310. echo " ".$text['description-hunt_group']."\n";
  311. echo " </span><br />\n";
  312. echo "<br />\n";
  313. echo "</td>\n";
  314. echo "</tr>\n";
  315. echo "</table>\n";
  316. echo "</td>\n";
  317. echo "</tr>\n";
  318. echo "<tr>\n";
  319. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  320. echo " ".$text['label-name'].":\n";
  321. echo "</td>\n";
  322. echo "<td class='vtable' align='left'>\n";
  323. echo " <input class='formfld' type='text' name='hunt_group_name' maxlength='255' value=\"$hunt_group_name\">\n";
  324. echo "<br />\n";
  325. echo $text['description-name']."\n";
  326. echo "</td>\n";
  327. echo "</tr>\n";
  328. echo "<tr>\n";
  329. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  330. echo " ".$text['label-extension'].":\n";
  331. echo "</td>\n";
  332. echo "<td class='vtable' align='left'>\n";
  333. echo " <input class='formfld' type='text' name='hunt_group_extension' maxlength='255' value=\"$hunt_group_extension\">\n";
  334. echo "<br />\n";
  335. echo $text['description-extension']."\n";
  336. echo "</td>\n";
  337. echo "</tr>\n";
  338. echo "<tr>\n";
  339. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  340. echo " ".$text['label-strategy'].":\n";
  341. echo "</td>\n";
  342. echo "<td class='vtable' align='left'>\n";
  343. echo " <select class='formfld' name='hunt_group_type'>\n";
  344. echo " <option value=''></option>\n";
  345. if ($hunt_group_type == "simultaneous") {
  346. echo " <option value='simultaneous' selected='selected'>".$text['option-simultaneous']."</option>\n";
  347. }
  348. else {
  349. echo " <option value='simultaneous'>".$text['option-simultaneous']."</option>\n";
  350. }
  351. if ($hunt_group_type == "sequentially") {
  352. echo " <option value='sequentially' selected='selected'>".$text['option-sequential']."</option>\n";
  353. }
  354. else {
  355. echo " <option value='sequentially'>".$text['option-sequential']."</option>\n";
  356. }
  357. echo " </select>\n";
  358. echo "<br />\n";
  359. echo "\n";
  360. echo "</td>\n";
  361. echo "</tr>\n";
  362. echo "<tr>\n";
  363. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  364. echo " ".$text['label-timeout'].":\n";
  365. echo "</td>\n";
  366. echo "<td class='vtable' align='left'>\n";
  367. echo " <input class='formfld' type='text' name='hunt_group_timeout' maxlength='255' value=\"$hunt_group_timeout\">\n";
  368. echo "<br />\n";
  369. echo $text['description-timeout']."\n";
  370. echo "</td>\n";
  371. echo "</tr>\n";
  372. echo "<tr>\n";
  373. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  374. echo " ".$text['label-timeout_destination'].":\n";
  375. echo "</td>\n";
  376. echo "<td class='vtable' align='left'>\n";
  377. echo " <input class='formfld' type='text' name='hunt_group_timeout_destination' maxlength='255' value=\"$hunt_group_timeout_destination\">\n";
  378. echo "<br />\n";
  379. echo $text['description-timeout_destination']."\n";
  380. echo "</td>\n";
  381. echo "</tr>\n";
  382. echo "<tr>\n";
  383. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  384. echo " ".$text['label-timeout_type'].":\n";
  385. echo "</td>\n";
  386. echo "<td class='vtable' align='left'>\n";
  387. echo " <select class='formfld' name='hunt_group_timeout_type'>\n";
  388. echo " <option value=''></option>\n";
  389. if ($hunt_group_timeout_type == "extension") {
  390. echo " <option value='extension' SELECTED >".$text['option-extension']."</option>\n";
  391. }
  392. else {
  393. echo " <option value='extension'>".$text['option-extension']."</option>\n";
  394. }
  395. if ($hunt_group_timeout_type == "voicemail") {
  396. echo " <option value='voicemail' SELECTED >".$text['option-voicemail']."</option>\n";
  397. }
  398. else {
  399. echo " <option value='voicemail'>".$text['option-voicemail']."</option>\n";
  400. }
  401. if ($hunt_group_timeout_type == "sip uri") {
  402. echo " <option value='sip uri' SELECTED >".$text['option-sip_uri']."</option>\n";
  403. }
  404. else {
  405. echo " <option value='sip uri'>".$text['option-sip_uri']."</option>\n";
  406. }
  407. echo " </select>\n";
  408. echo "<br />\n";
  409. echo $text['description-timeout_type']."\n";
  410. echo "</td>\n";
  411. echo "</tr>\n";
  412. echo "<tr>\n";
  413. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  414. echo " ".$text['label-ring_back'].":\n";
  415. echo "</td>\n";
  416. echo "<td class='vtable' align='left'>\n";
  417. $select_options = "";
  418. if ($hunt_group_ringback == "\${us-ring}" || $hunt_group_ringback == "us-ring") {
  419. $select_options .= " <option value='\${us-ring}' selected='selected'>us-ring</option>\n";
  420. }
  421. else {
  422. $select_options .= " <option value='\${us-ring}'>us-ring</option>\n";
  423. }
  424. if ($hunt_group_ringback == "\${fr-ring}" || $hunt_group_ringback == "fr-ring") {
  425. $select_options .= " <option value='\${fr-ring}' selected='selected'>fr-ring</option>\n";
  426. }
  427. else {
  428. $select_options .= " <option value='\${fr-ring}'>fr-ring</option>\n";
  429. }
  430. if ($hunt_group_ringback == "\${uk-ring}" || $hunt_group_ringback == "uk-ring") {
  431. $select_options .= " <option value='\${uk-ring}' selected='selected'>uk-ring</option>\n";
  432. }
  433. else {
  434. $select_options .= " <option value='\${uk-ring}'>uk-ring</option>\n";
  435. }
  436. if ($hunt_group_ringback == "\${rs-ring}" || $hunt_group_ringback == "rs-ring") {
  437. $select_options .= " <option value='\${rs-ring}' selected='selected'>rs-ring</option>\n";
  438. }
  439. else {
  440. $select_options .= " <option value='\${rs-ring}'>rs-ring</option>\n";
  441. }
  442. if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/music_on_hold')) {
  443. require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
  444. $moh = new switch_music_on_hold;
  445. $moh->select_name = "hunt_group_ringback";
  446. $moh->select_value = $hunt_group_ringback;
  447. $moh->select_options = $select_options;
  448. echo $moh->select();
  449. }
  450. else {
  451. echo " <select class='formfld' name='hunt_group_ringback'>\n";
  452. //echo " <option value=''></option>\n";
  453. echo $select_options;
  454. echo " </select>\n";
  455. }
  456. echo "<br />\n";
  457. echo $text['description-ring_back']."\n";
  458. echo "</td>\n";
  459. echo "</tr>\n";
  460. echo "<tr>\n";
  461. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  462. echo " ".$text['label-caller_id_name_prefix'].":\n";
  463. echo "</td>\n";
  464. echo "<td class='vtable' align='left'>\n";
  465. echo " <input class='formfld' type='text' name='hunt_group_cid_name_prefix' maxlength='255' value=\"$hunt_group_cid_name_prefix\">\n";
  466. echo "<br />\n";
  467. echo $text['description-caller_id_name_prefix']."\n";
  468. echo "</td>\n";
  469. echo "</tr>\n";
  470. echo "<tr>\n";
  471. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  472. echo " ".$text['label-pin_number'].":\n";
  473. echo "</td>\n";
  474. echo "<td class='vtable' align='left'>\n";
  475. echo " <input class='formfld' type='text' name='hunt_group_pin' maxlength='255' value=\"$hunt_group_pin\">\n";
  476. echo "<br />\n";
  477. echo $text['description-pin_number']."\n";
  478. echo "</td>\n";
  479. echo "</tr>\n";
  480. if (!$fp) {
  481. $fp = event_socket_create($_SESSION['event_socket_ip_address'], $_SESSION['event_socket_port'], $_SESSION['event_socket_password']);
  482. }
  483. if (switch_module_is_running($fp, 'mod_spidermonkey')) {
  484. echo "<tr>\n";
  485. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  486. echo " ".$text['label-caller_announce'].":\n";
  487. echo "</td>\n";
  488. echo "<td class='vtable' align='left'>\n";
  489. echo " <select class='formfld' name='hunt_group_caller_announce'>\n";
  490. echo " <option value=''></option>\n";
  491. if ($hunt_group_caller_announce == "true") {
  492. echo " <option value='true' selected='selected'>".$text['option-true']."</option>\n";
  493. }
  494. else {
  495. echo " <option value='true'>".$text['option-true']."</option>\n";
  496. }
  497. if ($hunt_group_caller_announce == "false") {
  498. echo " <option value='false' selected='selected'>".$text['option-false']."</option>\n";
  499. }
  500. else {
  501. echo " <option value='false'>".$text['option-false']."</option>\n";
  502. }
  503. echo " </select>\n";
  504. echo "<br />\n";
  505. echo "\n";
  506. echo "</td>\n";
  507. echo "</tr>\n";
  508. }
  509. if (if_group("admin") || if_group("superadmin")) {
  510. echo "<tr>\n";
  511. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  512. echo " ".$text['label-user_list'].":\n";
  513. echo "</td>\n";
  514. echo "<td class='vtable' align='left'>\n";
  515. $onchange = "document.getElementById('hunt_group_user_list').value += document.getElementById('username').value + '\\n';";
  516. $table_name = 'v_users'; $field_name = 'username'; $field_current_value = ''; $sql_where_optional = "where domain_uuid = '$domain_uuid' and user_enabled = 'true' ";
  517. echo html_select_on_change($db, $table_name, $field_name, $sql_where_optional, $field_current_value, $onchange);
  518. echo "<br />\n";
  519. echo $text['description-user_list_select']."\n";
  520. echo "<br />\n";
  521. echo "<br />\n";
  522. //replace the vertical bar with a line feed to display in the textarea
  523. $hunt_group_user_list = trim($hunt_group_user_list, "|");
  524. $hunt_group_user_list_array = explode("|", $hunt_group_user_list);
  525. $hunt_group_user_list = '';
  526. foreach($hunt_group_user_list_array as $user){
  527. $hunt_group_user_list .= trim($user)."\n";
  528. }
  529. echo " <textarea name=\"hunt_group_user_list\" id=\"hunt_group_user_list\" class=\"formfld\" cols=\"30\" rows=\"3\" wrap=\"off\">$hunt_group_user_list</textarea>\n";
  530. echo " <br>\n";
  531. echo $text['description-user_list_textarea']."\n";
  532. echo "<br />\n";
  533. echo "</td>\n";
  534. echo "</tr>\n";
  535. }
  536. echo "<tr>\n";
  537. echo "<td class='vncellreq' valign='top' align='left' nowrap>\n";
  538. echo " ".$text['label-enabled'].":\n";
  539. echo "</td>\n";
  540. echo "<td class='vtable' align='left'>\n";
  541. echo " <select class='formfld' name='hunt_group_enabled'>\n";
  542. echo " <option value=''></option>\n";
  543. if ($hunt_group_enabled == "true" || strlen($hunt_group_enabled) == 0) {
  544. echo " <option value='true' selected >".$text['option-true']."</option>\n";
  545. }
  546. else {
  547. echo " <option value='true'>".$text['option-true']."</option>\n";
  548. }
  549. if ($hunt_group_enabled == "false") {
  550. echo " <option value='false' selected >".$text['option-false']."</option>\n";
  551. }
  552. else {
  553. echo " <option value='false'>".$text['option-false']."</option>\n";
  554. }
  555. echo " </select>\n";
  556. echo "<br />\n";
  557. echo $text['description-enabled']."\n";
  558. echo "</td>\n";
  559. echo "</tr>\n";
  560. echo "<tr>\n";
  561. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  562. echo " ".$text['label-description'].":\n";
  563. echo "</td>\n";
  564. echo "<td class='vtable' align='left'>\n";
  565. echo " <input class='formfld' type='text' name='hunt_group_description' maxlength='255' value=\"$hunt_group_description\">\n";
  566. echo "<br />\n";
  567. echo $text['description-description']."\n";
  568. echo "</td>\n";
  569. echo "</tr>\n";
  570. echo " <tr>\n";
  571. echo " <td colspan='2' align='right'>\n";
  572. if ($action == "update") {
  573. echo " <input type='hidden' name='dialplan_uuid' value='$dialplan_uuid'>\n";
  574. echo " <input type='hidden' name='hunt_group_uuid' value='$hunt_group_uuid'>\n";
  575. }
  576. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  577. echo " </td>\n";
  578. echo " </tr>";
  579. echo "</table>";
  580. echo "</form>";
  581. echo " </td>";
  582. echo " </tr>";
  583. echo "</table>";
  584. echo "</div>";
  585. //list hunt group destinations
  586. if ($action == "update") {
  587. echo "<div align='center'>";
  588. echo "<table width='100%' border='0' cellpadding='0' cellspacing='2'>\n";
  589. echo "<tr class='border'>\n";
  590. echo " <td align=\"center\">\n";
  591. echo " <br>";
  592. echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
  593. echo " <tr>\n";
  594. echo " <td align='left'><p><span class='vexpl'>\n";
  595. echo " <span class='red'><strong>".$text['header-hunt_group_destinations']."</strong></span><br>\n";
  596. echo " ".$text['description-hunt_group_destinations']."\n";
  597. echo " </span></p></td>\n";
  598. echo " </tr>\n";
  599. echo "</table>\n";
  600. echo "<br />\n";
  601. $sql = " select * from v_hunt_group_destinations ";
  602. $sql .= " where domain_uuid = '$domain_uuid' ";
  603. $sql .= " and hunt_group_uuid = '$hunt_group_uuid' ";
  604. $sql .= " order by destination_order, destination_data asc";
  605. $prep_statement = $db->prepare(check_sql($sql));
  606. $prep_statement->execute();
  607. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  608. $result_count = count($result);
  609. unset ($prep_statement, $sql);
  610. $c = 0;
  611. $row_style["0"] = "row_style0";
  612. $row_style["1"] = "row_style1";
  613. echo "<div align='center'>\n";
  614. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  615. echo "<tr>\n";
  616. echo "<th align='center'>".$text['label-destination']."</th>\n";
  617. echo "<th align='center'>".$text['label-type']."</th>\n";
  618. echo "<th align='center'>".$text['label-profile']."</th>\n";
  619. echo "<th align='center'>".$text['label-order']."</th>\n";
  620. echo "<th align='center'>".$text['label-description']."</th>\n";
  621. echo "<td align='right' width='42'>\n";
  622. if (permission_exists('hunt_group_add')) {
  623. echo " <a href='hunt_group_destination_edit.php?id2=".$hunt_group_uuid."' alt='".$text['button-add']."'>$v_link_label_add</a>\n";
  624. }
  625. echo "</td>\n";
  626. echo "<tr>\n";
  627. if ($result_count > 0) {
  628. foreach($result as $row) {
  629. echo "<tr >\n";
  630. echo " <td valign='top' class='".$row_style[$c]."'>&nbsp;&nbsp;".$row['destination_data']."</td>\n";
  631. echo " <td valign='top' class='".$row_style[$c]."'>&nbsp;&nbsp;";
  632. switch($row['destination_type']) {
  633. case "extension" : echo $text['option-extension']; break;
  634. case "voicemail" : echo $text['option-voicemail']; break;
  635. case "sip uri" : echo $text['option-sip_uri']; break;
  636. }
  637. echo "</td>\n";
  638. echo " <td valign='top' class='".$row_style[$c]."'>&nbsp;&nbsp;".$row['destination_profile']."</td>\n";
  639. echo " <td valign='top' class='".$row_style[$c]."'>&nbsp;&nbsp;".$row['destination_order']."</td>\n";
  640. echo " <td valign='top' class='row_stylebg' width='30%'>".$row['destination_description']."&nbsp;</td>\n";
  641. echo " <td valign='top' align='right'>\n";
  642. if (permission_exists('hunt_group_edit')) {
  643. echo " <a href='hunt_group_destination_edit.php?id=".$row['hunt_group_destination_uuid']."&id2=".$hunt_group_uuid."' alt='".$text['button-edit']."'>$v_link_label_edit</a>\n";
  644. }
  645. if (permission_exists('hunt_group_delete')) {
  646. echo " <a href='hunt_group_destination_delete.php?id=".$row['hunt_group_destination_uuid']."&id2=".$hunt_group_uuid."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>\n";
  647. }
  648. echo " </td>\n";
  649. echo "</tr>\n";
  650. if ($c==0) { $c=1; } else { $c=0; }
  651. } //end foreach
  652. unset($sql, $result, $row_count);
  653. } //end if results
  654. echo "<tr>\n";
  655. echo "<td colspan='6'>\n";
  656. echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
  657. echo " <tr>\n";
  658. echo " <td width='33.3%' nowrap>&nbsp;</td>\n";
  659. echo " <td width='33.3%' align='center' nowrap>$paging_controls</td>\n";
  660. echo " <td width='33.3%' align='right'>\n";
  661. if (permission_exists('hunt_group_add')) {
  662. echo " <a href='hunt_group_destination_edit.php?id2=".$hunt_group_uuid."' alt='".$text['button-add']."'>$v_link_label_add</a>\n";
  663. }
  664. echo " </td>\n";
  665. echo " </tr>\n";
  666. echo " </table>\n";
  667. echo "</td>\n";
  668. echo "</tr>\n";
  669. echo "</table>";
  670. echo "</div>";
  671. echo "<br><br>";
  672. echo "<br><br>";
  673. echo "</td>";
  674. echo "</tr>";
  675. echo "</table>";
  676. echo "</div>";
  677. echo "<br><br>";
  678. } //end if update
  679. //show the footer
  680. require_once "resources/footer.php";
  681. ?>