hunt_group_call_forward_edit.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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. require_once "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') || permission_exists('hunt_group_call_forward')) {
  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. function destination_select($select_name, $select_value, $select_default) {
  36. if (strlen($select_value) == 0) { $select_value = $select_default; }
  37. echo " <select class='formfld' style='width: 40px;' name='$select_name'>\n";
  38. echo " <option value=''></option>\n";
  39. $i=5;
  40. while($i<=100) {
  41. if ($select_value == $i) {
  42. echo " <option value='$i' selected='selected'>$i</option>\n";
  43. }
  44. else {
  45. echo " <option value='$i'>$i</option>\n";
  46. }
  47. $i=$i+5;
  48. }
  49. echo "</select>\n";
  50. }
  51. //show the header
  52. require_once "resources/header.php";
  53. $page["title"] = $text['title-hunt-group_call_forward'];
  54. //get the hunt_group_uuid
  55. $hunt_group_uuid = $_REQUEST["id"];
  56. //hunt_group information used to determine if this is an add or an update
  57. $sql = "select * from v_hunt_groups ";
  58. $sql .= "where domain_uuid = '$domain_uuid' ";
  59. $sql .= "and hunt_group_uuid = '$hunt_group_uuid' ";
  60. if (!(permission_exists('hunt_group_add') || permission_exists('hunt_group_edit'))) {
  61. $sql .= "and hunt_group_user_list like '%|".$_SESSION["username"]."|%' ";
  62. }
  63. $prep_statement = $db->prepare(check_sql($sql));
  64. $prep_statement->execute();
  65. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  66. foreach ($result as &$row) {
  67. $hunt_group_uuid = $row["hunt_group_uuid"];
  68. $hunt_group_extension = $row["hunt_group_extension"];
  69. }
  70. unset ($prep_statement);
  71. if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) {
  72. //get http post variables and set them to php variables
  73. if (count($_POST)>0) {
  74. $call_forward_enabled = check_str($_POST["call_forward_enabled"]);
  75. $call_forward_number = check_str($_POST["call_forward_number"]);
  76. $hunt_group_call_prompt = check_str($_POST["hunt_group_call_prompt"]);
  77. if (strlen($call_forward_number) > 0) {
  78. $call_forward_number = preg_replace("~[^0-9]~", "",$call_forward_number);
  79. }
  80. //set the default
  81. if (strlen($hunt_group_call_prompt) == 0) {
  82. $hunt_group_call_prompt = 'false';
  83. }
  84. }
  85. //check for all required data
  86. //if (strlen($call_forward_enabled) == 0) { $msg .= $text['message-required'].$text['label-call_forward']."<br>\n"; }
  87. //if (strlen($call_forward_number) == 0) { $msg .= $text['message-required'].$text['label-number']."<br>\n"; }
  88. //if (strlen($hunt_group_call_prompt) == 0) { $msg .= $text['message-required'].$text['label-call_prompt']."<br>\n"; }
  89. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  90. require_once "resources/header.php";
  91. require_once "resources/persist_form_var.php";
  92. echo "<div align='center'>\n";
  93. echo "<table><tr><td>\n";
  94. echo $msg."<br />";
  95. echo "</td></tr></table>\n";
  96. persistformvar($_POST);
  97. echo "</div>\n";
  98. require_once "resources/footer.php";
  99. return;
  100. }
  101. //call forward is enabled so disable the hunt group
  102. if ($call_forward_enabled == "true") {
  103. $sql = "update v_hunt_groups set hunt_group_enabled = 'false' ";
  104. $sql .= "where hunt_group_extension = '$hunt_group_extension' ";
  105. $sql .= "and (hunt_group_type = 'simultaneous' or hunt_group_type = 'sequentially') ";
  106. $db->exec(check_sql($sql));
  107. }
  108. //call forward is disabled so enable the hunt group
  109. if ($call_forward_enabled == "false" || $call_forward_enabled == "") {
  110. $sql = "update v_hunt_groups set hunt_group_enabled = 'true' ";
  111. $sql .= "where hunt_group_extension = '$hunt_group_extension' ";
  112. $sql .= "and (hunt_group_type = 'simultaneous' or hunt_group_type = 'sequentially') ";
  113. $db->exec(check_sql($sql));
  114. }
  115. //set the default action to add
  116. $call_forward_action = "add";
  117. //hunt_group information used to determine if this is an add or an update
  118. $sql = "select * from v_hunt_groups ";
  119. $sql .= "where domain_uuid = '$domain_uuid' ";
  120. $sql .= "and hunt_group_type = 'call_forward' ";
  121. $sql .= "and hunt_group_extension in ( ";
  122. $sql .= "select hunt_group_extension from v_hunt_groups ";
  123. $sql .= "where domain_uuid = '$domain_uuid' ";
  124. $sql .= "and hunt_group_uuid = '$hunt_group_uuid' ";
  125. if (!(permission_exists('hunt_group_add') || permission_exists('hunt_group_edit'))) {
  126. $sql .= "and hunt_group_user_list like '%|".$_SESSION["username"]."|%' ";
  127. }
  128. $sql .= ") ";
  129. $prep_statement = $db->prepare(check_sql($sql));
  130. $prep_statement->execute();
  131. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  132. foreach ($result as &$row) {
  133. if ($row["hunt_group_type"] == 'call_forward') {
  134. $call_forward_action = "update";
  135. $call_forward_uuid = $row["hunt_group_uuid"];
  136. }
  137. }
  138. unset ($prep_statement);
  139. //call forward config
  140. $huntgroup_name = 'call_forward_'.$hunt_group_extension;
  141. $hunt_group_type = 'call_forward';
  142. $hunt_group_context = $_SESSION['context'];
  143. $hunt_group_timeout = '3600';
  144. $hunt_group_timeout_destination = $hunt_group_extension;
  145. $hunt_group_timeout_type = 'voicemail';
  146. $hunt_group_ring_back = 'us-ring';
  147. $hunt_group_cid_name_prefix = '';
  148. $hunt_group_pin = '';
  149. $huntgroup_caller_announce = 'false';
  150. $hunt_group_user_list = '';
  151. $hunt_group_enabled = $call_forward_enabled;
  152. $hunt_group_description = 'call forward '.$hunt_group_extension;
  153. if ($call_forward_action == "add" && permission_exists('hunt_group_add')) {
  154. $call_forward_uuid = uuid();
  155. $sql = "insert into v_hunt_groups ";
  156. $sql .= "(";
  157. $sql .= "domain_uuid, ";
  158. $sql .= "hunt_group_uuid, ";
  159. $sql .= "hunt_group_extension, ";
  160. $sql .= "hunt_group_name, ";
  161. $sql .= "hunt_group_type, ";
  162. $sql .= "hunt_group_context, ";
  163. $sql .= "hunt_group_timeout, ";
  164. $sql .= "hunt_group_timeout_destination, ";
  165. $sql .= "hunt_group_timeout_type, ";
  166. $sql .= "hunt_group_ringback, ";
  167. $sql .= "hunt_group_cid_name_prefix, ";
  168. $sql .= "hunt_group_pin, ";
  169. $sql .= "hunt_group_call_prompt, ";
  170. $sql .= "hunt_group_caller_announce, ";
  171. $sql .= "hunt_group_user_list, ";
  172. $sql .= "hunt_group_enabled, ";
  173. $sql .= "hunt_group_description ";
  174. $sql .= ")";
  175. $sql .= "values ";
  176. $sql .= "(";
  177. $sql .= "'$domain_uuid', ";
  178. $sql .= "'$call_forward_uuid', ";
  179. $sql .= "'$hunt_group_extension', ";
  180. $sql .= "'$huntgroup_name', ";
  181. $sql .= "'$hunt_group_type', ";
  182. $sql .= "'$hunt_group_context', ";
  183. $sql .= "'$hunt_group_timeout', ";
  184. $sql .= "'$hunt_group_timeout_destination', ";
  185. $sql .= "'$hunt_group_timeout_type', ";
  186. $sql .= "'$hunt_group_ring_back', ";
  187. $sql .= "'$hunt_group_cid_name_prefix', ";
  188. $sql .= "'$hunt_group_pin', ";
  189. $sql .= "'$hunt_group_call_prompt', ";
  190. $sql .= "'$huntgroup_caller_announce', ";
  191. $sql .= "'$hunt_group_user_list', ";
  192. $sql .= "'$hunt_group_enabled', ";
  193. $sql .= "'$hunt_group_description' ";
  194. $sql .= ")";
  195. if ($v_debug) {
  196. echo $sql."<br />";
  197. }
  198. $db->exec(check_sql($sql));
  199. unset($sql);
  200. //delete related v_hunt_group_destinations
  201. $sql = "delete from v_hunt_group_destinations where hunt_group_uuid = '$call_forward_uuid' ";
  202. $db->exec(check_sql($sql));
  203. if (extension_exists($call_forward_number)) {
  204. $destination_data = $call_forward_number;
  205. $destination_type = 'extension';
  206. }
  207. $destination_profile = 'internal';
  208. $destination_timeout = '';
  209. $destination_order = '1';
  210. $destination_enabled = 'true';
  211. $destination_description = 'call forward';
  212. $hunt_group_destination_uuid = uuid();
  213. $sql = "insert into v_hunt_group_destinations ";
  214. $sql .= "(";
  215. $sql .= "domain_uuid, ";
  216. $sql .= "hunt_group_uuid, ";
  217. $sql .= "hunt_group_destination_uuid, ";
  218. $sql .= "destination_data, ";
  219. $sql .= "destination_type, ";
  220. $sql .= "destination_profile, ";
  221. $sql .= "destination_timeout, ";
  222. $sql .= "destination_order, ";
  223. $sql .= "destination_enabled, ";
  224. $sql .= "destination_description ";
  225. $sql .= ")";
  226. $sql .= "values ";
  227. $sql .= "(";
  228. $sql .= "'$domain_uuid', ";
  229. $sql .= "'$call_forward_uuid', ";
  230. $sql .= "'$hunt_group_destination_uuid', ";
  231. $sql .= "'$destination_data', ";
  232. $sql .= "'$destination_type', ";
  233. $sql .= "'$destination_profile', ";
  234. $sql .= "'$destination_timeout', ";
  235. $sql .= "'$destination_order', ";
  236. $sql .= "'$destination_enabled', ";
  237. $sql .= "'$destination_description' ";
  238. $sql .= ")";
  239. $db->exec(check_sql($sql));
  240. unset($sql);
  241. } //if ($call_forward_action == "add")
  242. if ($call_forward_action == "update" && permission_exists('hunt_group_call_forward')) {
  243. $sql = "update v_hunt_groups set ";
  244. $sql .= "hunt_group_extension = '$hunt_group_extension', ";
  245. $sql .= "hunt_group_name = '$huntgroup_name', ";
  246. $sql .= "hunt_group_type = '$hunt_group_type', ";
  247. $sql .= "hunt_group_context = '$hunt_group_context', ";
  248. $sql .= "hunt_group_timeout = '$hunt_group_timeout', ";
  249. $sql .= "hunt_group_timeout_destination = '$hunt_group_timeout_destination', ";
  250. $sql .= "hunt_group_timeout_type = '$hunt_group_timeout_type', ";
  251. $sql .= "hunt_group_ringback = '$hunt_group_ring_back', ";
  252. $sql .= "hunt_group_cid_name_prefix = '$hunt_group_cid_name_prefix', ";
  253. $sql .= "hunt_group_pin = '$hunt_group_pin', ";
  254. $sql .= "hunt_group_call_prompt = '$hunt_group_call_prompt', ";
  255. $sql .= "hunt_group_caller_announce = '$huntgroup_caller_announce', ";
  256. $sql .= "hunt_group_user_list = '$hunt_group_user_list', ";
  257. $sql .= "hunt_group_enabled = '$hunt_group_enabled', ";
  258. $sql .= "hunt_group_description = '$hunt_group_description' ";
  259. $sql .= "where domain_uuid = '$domain_uuid' ";
  260. $sql .= "and hunt_group_uuid = '$call_forward_uuid'";
  261. $db->exec(check_sql($sql));
  262. unset($sql);
  263. //set the variables
  264. $destination_data = $call_forward_number;
  265. if (extension_exists($call_forward_number)) {
  266. $destination_type = 'extension';
  267. }
  268. else {
  269. $destination_type = 'sip uri';
  270. }
  271. $destination_profile = 'internal';
  272. $destination_timeout = '';
  273. $destination_order = '1';
  274. $destination_enabled = 'true';
  275. $destination_description = 'call forward';
  276. //delete related v_hunt_group_destinations
  277. $sql = "delete from v_hunt_group_destinations where hunt_group_uuid = '$call_forward_uuid' ";
  278. $db->exec(check_sql($sql));
  279. //insert the v_hunt_group_destinations
  280. $hunt_group_destination_uuid = uuid();
  281. $sql = "insert into v_hunt_group_destinations ";
  282. $sql .= "(";
  283. $sql .= "hunt_group_destination_uuid, ";
  284. $sql .= "domain_uuid, ";
  285. $sql .= "hunt_group_uuid, ";
  286. $sql .= "destination_data, ";
  287. $sql .= "destination_type, ";
  288. $sql .= "destination_profile, ";
  289. $sql .= "destination_timeout, ";
  290. $sql .= "destination_order, ";
  291. $sql .= "destination_enabled, ";
  292. $sql .= "destination_description ";
  293. $sql .= ")";
  294. $sql .= "values ";
  295. $sql .= "(";
  296. $sql .= "'$hunt_group_destination_uuid', ";
  297. $sql .= "'$domain_uuid', ";
  298. $sql .= "'$call_forward_uuid', ";
  299. $sql .= "'$destination_data', ";
  300. $sql .= "'$destination_type', ";
  301. $sql .= "'$destination_profile', ";
  302. $sql .= "'$destination_timeout', ";
  303. $sql .= "'$destination_order', ";
  304. $sql .= "'$destination_enabled', ";
  305. $sql .= "'$destination_description' ";
  306. $sql .= ")";
  307. $db->exec(check_sql($sql));
  308. unset($sql);
  309. } //if ($call_forward_action == "update")
  310. //synchronize the xml config
  311. save_hunt_group_xml();
  312. //synchronize the xml config
  313. save_dialplan_xml();
  314. //redirect the user
  315. require_once "resources/header.php";
  316. echo "<meta http-equiv=\"refresh\" content=\"3;url=".PROJECT_PATH."/app/hunt_group/hunt_group_call_forward.php\">\n";
  317. echo "<div align='center'>\n";
  318. echo $text['message-update']."<br />\n";
  319. echo "</div>\n";
  320. require_once "resources/footer.php";
  321. return;
  322. } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
  323. //pre-populate the form
  324. $sql = "select * from v_hunt_groups ";
  325. $sql .= "where domain_uuid = '$domain_uuid' ";
  326. $sql .= "and hunt_group_type = 'call_forward' ";
  327. $sql .= "and hunt_group_extension = '$hunt_group_extension' ";
  328. $prep_statement = $db->prepare(check_sql($sql));
  329. $prep_statement->execute();
  330. $result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
  331. foreach ($result as &$row) {
  332. $hunt_group_uuid = $row["hunt_group_uuid"];
  333. $hunt_group_extension = $row["hunt_group_extension"];
  334. $huntgroup_name = $row["hunt_group_name"];
  335. $hunt_group_type = $row["hunt_group_type"];
  336. $hunt_group_context = $row["hunt_group_context"];
  337. $hunt_group_timeout = $row["hunt_group_timeout"];
  338. $hunt_group_timeout_destination = $row["hunt_group_timeout_destination"];
  339. $hunt_group_timeout_type = $row["hunt_group_timeout_type"];
  340. $hunt_group_ring_back = $row["hunt_group_ringback"];
  341. $hunt_group_cid_name_prefix = $row["hunt_group_cid_name_prefix"];
  342. $hunt_group_pin = $row["hunt_group_pin"];
  343. $hunt_group_call_prompt = $row["hunt_group_call_prompt"];
  344. $huntgroup_caller_announce = $row["hunt_group_caller_announce"];
  345. $hunt_group_user_list = $row["hunt_group_user_list"];
  346. $hunt_group_enabled = $row["hunt_group_enabled"];
  347. $hunt_group_description = $row["hunt_group_description"];
  348. if ($row["hunt_group_type"] == 'call_forward') {
  349. $call_forward_enabled = $hunt_group_enabled;
  350. }
  351. if ($row["hunt_group_type"] == 'call_forward') {
  352. $sql = "select * from v_hunt_group_destinations ";
  353. $sql .= "where hunt_group_uuid = '$hunt_group_uuid' ";
  354. $prep_statement_2 = $db->prepare(check_sql($sql));
  355. $prep_statement_2->execute();
  356. $result2 = $prep_statement_2->fetchAll(PDO::FETCH_NAMED);
  357. $x=1;
  358. foreach ($result2 as &$row2) {
  359. if ($row["hunt_group_type"] == 'call_forward') {
  360. if (strlen($row2["destination_data"]) > 0) {
  361. $call_forward_number = $row2["destination_data"];
  362. }
  363. }
  364. }
  365. unset ($prep_statement_2);
  366. }
  367. }
  368. unset ($prep_statement);
  369. //show the content
  370. echo "<div align='center'>";
  371. echo "<table width='100%' border='0' cellpadding='0' cellspacing=''>\n";
  372. echo "<tr class='border'>\n";
  373. echo " <td align=\"center\">\n";
  374. echo " <br>";
  375. echo "<form method='post' name='frm' action=''>\n";
  376. echo "<table width='100%' border='0' cellpadding='6' cellspacing='0'>\n";
  377. echo "<tr>\n";
  378. echo "<td align='left' width='30%' nowrap>\n";
  379. echo " <b>".$text['header-hunt-group_call_forward']."</b>\n";
  380. echo "</td>\n";
  381. echo "<td width='70%' align='right'>\n";
  382. echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick=\"window.location='hunt_group_call_forward.php'\" value='".$text['button-back']."'>\n";
  383. echo "</td>\n";
  384. echo "</tr>\n";
  385. echo "<tr>\n";
  386. echo "<td colspan='2'>\n";
  387. echo " ".$text['description-hunt_group_call_forward_edit']." ".$hunt_group_extension."<br /><br />\n";
  388. echo "</td>\n";
  389. echo "</tr>\n";
  390. echo "<tr>\n";
  391. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  392. echo " <strong>".$text['label-call_forward'].":</strong>\n";
  393. echo "</td>\n";
  394. echo "<td class='vtable' align='left'>\n";
  395. if ($call_forward_enabled == "true") {
  396. echo " <input type='radio' name='call_forward_enabled' value='true' checked='checked'/> ".$text['option-enabled']." \n";
  397. }
  398. else {
  399. echo " <input type='radio' name='call_forward_enabled' value='true' /> ".$text['option-enabled']." \n";
  400. }
  401. if ($call_forward_enabled == "false" || $call_forward_enabled == "") {
  402. echo " <input type='radio' name='call_forward_enabled' value='false' checked='checked' /> ".$text['option-disabled']." \n";
  403. }
  404. else {
  405. echo " <input type='radio' name='call_forward_enabled' value='false' /> ".$text['option-disabled']." \n";
  406. }
  407. echo "<br />\n";
  408. echo "<br />\n";
  409. echo "</td>\n";
  410. echo "</tr>\n";
  411. echo "<tr>\n";
  412. echo "<td class='vncell' valign='top' align='left' nowrap>\n";
  413. echo " ".$text['label-number'].":\n";
  414. echo "</td>\n";
  415. echo "<td class='vtable' align='left'>\n";
  416. echo " <input class='formfld' type='text' name='call_forward_number' maxlength='255' value=\"$call_forward_number\">\n";
  417. echo "<br />\n";
  418. echo "</td>\n";
  419. echo "</tr>\n";
  420. echo "<tr>\n";
  421. echo "<td colspan='2'>\n";
  422. echo " <br />\n";
  423. echo "</td>\n";
  424. echo "</tr>\n";
  425. echo "<tr>\n";
  426. echo "<td colspan='2'>\n";
  427. echo " <br />\n";
  428. echo "</td>\n";
  429. echo "</tr>\n";
  430. echo " <tr>\n";
  431. echo " <td colspan='2' align='right'>\n";
  432. if ($action == "update") {
  433. echo " <input type='hidden' name='id' value='$call_forward_uuid'>\n";
  434. }
  435. echo " <input type='submit' name='submit' class='btn' value='".$text['button-save']."'>\n";
  436. echo " </td>\n";
  437. echo " </tr>";
  438. echo "</table>";
  439. echo "</form>";
  440. echo " </td>";
  441. echo " </tr>";
  442. echo "</table>";
  443. echo "</div>";
  444. //show the footer
  445. require_once "resources/footer.php";
  446. ?>