bulk_account_settings_extensions.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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-2016
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. KonradSC <[email protected]>
  20. */
  21. //includes
  22. include "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. require_once "resources/paging.php";
  26. //include the class
  27. require_once "resources/check_auth.php";
  28. //check permissions
  29. require_once "resources/check_auth.php";
  30. if (permission_exists('bulk_account_settings_extensions')) {
  31. //access granted
  32. }
  33. else {
  34. echo "access denied";
  35. exit;
  36. }
  37. //add multi-lingual support
  38. $language = new text;
  39. $text = $language->get();
  40. //get the http values and set them as variables
  41. $order_by = check_str($_GET["order_by"]);
  42. $order = check_str($_GET["order"]);
  43. $option_selected = check_str($_GET["option_selected"]);
  44. //handle search term
  45. $search = check_str($_GET["search"]);
  46. if (strlen($search) > 0) {
  47. $sql_mod = "and ( ";
  48. $sql_mod .= "extension ILIKE '%".$search."%' ";
  49. $sql_mod .= "or accountcode ILIKE '%".$search."%' ";
  50. $sql_mod .= "or call_group ILIKE '%".$search."%' ";
  51. $sql_mod .= "or description ILIKE '%".$search."%' ";
  52. if (($option_selected == "") or ($option_selected == 'call_group') or ($option_selected == 'accountcode')) {} else {
  53. $sql_mod .= "or ".$option_selected." ILIKE '%".$search."%' ";
  54. }
  55. $sql_mod .= ") ";
  56. }
  57. if (strlen($order_by) < 1) {
  58. $order_by = "extension";
  59. $order = "ASC";
  60. }
  61. $domain_uuid = $_SESSION['domain_uuid'];
  62. //get total extension count from the database
  63. $sql = "select count(*) as num_rows from v_extensions where domain_uuid = '".$_SESSION['domain_uuid']."' ".$sql_mod." ";
  64. $prep_statement = $db->prepare($sql);
  65. if ($prep_statement) {
  66. $prep_statement->execute();
  67. $row = $prep_statement->fetch(PDO::FETCH_ASSOC);
  68. $total_extensions = $row['num_rows'];
  69. if (($db_type == "pgsql") or ($db_type == "mysql")) {
  70. $numeric_extensions = $row['num_rows'];
  71. }
  72. }
  73. unset($prep_statement, $row);
  74. //prepare to page the results
  75. $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
  76. $param = "&search=".$search."&option_selected=".$option_selected;
  77. if (!isset($_GET['page'])) { $_GET['page'] = 0; }
  78. $_GET['page'] = check_str($_GET['page']);
  79. list($paging_controls_mini, $rows_per_page, $var_3) = paging($total_extensions, $param, $rows_per_page, true); //top
  80. list($paging_controls, $rows_per_page, $var_3) = paging($total_extensions, $param, $rows_per_page); //bottom
  81. $offset = $rows_per_page * $_GET['page'];
  82. //get all the extensions from the database
  83. $sql = "SELECT \n";
  84. $sql .= "description, \n";
  85. $sql .= "extension, \n";
  86. $sql .= "extension_uuid, \n";
  87. if (($option_selected == "") or ($option_selected == 'call_group') or ($option_selected == 'accountcode')) {} else {
  88. $sql .= "".$option_selected.", \n";
  89. }
  90. $sql .= "accountcode, \n";
  91. $sql .= "call_group \n";
  92. $sql .= "FROM v_extensions \n";
  93. $sql .= "WHERE domain_uuid = '$domain_uuid' \n";
  94. $sql .= $sql_mod; //add search mod from above
  95. $sql .= "ORDER BY ".$order_by." ".$order." \n";
  96. $sql .= "limit $rows_per_page offset $offset ";
  97. $database = new database;
  98. $database->select($sql);
  99. $directory = $database->result;
  100. unset($database,$result);
  101. //additional includes
  102. require_once "resources/header.php";
  103. $document['title'] = $text['title-extensions_settings'];
  104. //set the alternating styles
  105. $c = 0;
  106. $row_style["0"] = "row_style0";
  107. $row_style["1"] = "row_style1";
  108. //show the content
  109. echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n";
  110. echo " <tr>\n";
  111. echo " <td align='left' width='100%'>\n";
  112. echo " <b>".$text['header-extensions']." (".$numeric_extensions.")</b><br>\n";
  113. //options list
  114. echo "<form name='frm' method='get' id=option_selected>\n";
  115. echo " <select class='formfld' name='option_selected' onchange=\"this.form.submit();\">\n";
  116. echo " <option value=''>".$text['label-extension_null']."</option>\n";
  117. if ($option_selected == "accountcode") {
  118. echo " <option value='accountcode' selected='selected'>".$text['label-accountcode']."</option>\n";
  119. }
  120. else {
  121. echo " <option value='accountcode'>".$text['label-accountcode']."</option>\n";
  122. }
  123. if ($option_selected == "call_group") {
  124. echo " <option value='call_group' selected='selected'>".$text['label-call_group']."</option>\n";
  125. }
  126. else {
  127. echo " <option value='call_group'>".$text['label-call_group']."</option>\n";
  128. }
  129. if ($option_selected == "call_timeout") {
  130. echo " <option value='call_timeout' selected='selected'>".$text['label-call_timeout']."</option>\n";
  131. }
  132. else {
  133. echo " <option value='call_timeout'>".$text['label-call_timeout']."</option>\n";
  134. }
  135. if ($option_selected == "emergency_caller_id_name") {
  136. echo " <option value='emergency_caller_id_name' selected='selected'>".$text['label-emergency_caller_id_name']."</option>\n";
  137. }
  138. else {
  139. echo " <option value='emergency_caller_id_name'>".$text['label-emergency_caller_id_name']."</option>\n";
  140. }
  141. if ($option_selected == "emergency_caller_id_number") {
  142. echo " <option value='emergency_caller_id_number' selected='selected'>".$text['label-emergency_caller_id_number']."</option>\n";
  143. }
  144. else {
  145. echo " <option value='emergency_caller_id_number'>".$text['label-emergency_caller_id_number']."</option>\n";
  146. }
  147. if ($option_selected == "enabled") {
  148. echo " <option value='enabled' selected='selected'>".$text['label-enabled']."</option>\n";
  149. }
  150. else {
  151. echo " <option value='enabled'>".$text['label-enabled']."</option>\n";
  152. }
  153. if ($option_selected == "hold_music") {
  154. echo " <option value='hold_music' selected='selected'>".$text['label-hold_music']."</option>\n";
  155. }
  156. else {
  157. echo " <option value='hold_music'>".$text['label-hold_music']."</option>\n";
  158. }
  159. if ($option_selected == "limit_max") {
  160. echo " <option value='limit_max' selected='selected'>".$text['label-limit_max']."</option>\n";
  161. }
  162. else {
  163. echo " <option value='limit_max'>".$text['label-limit_max']."</option>\n";
  164. }
  165. if ($option_selected == "outbound_caller_id_name") {
  166. echo " <option value='outbound_caller_id_name' selected='selected'>".$text['label-outbound_caller_id_name']."</option>\n";
  167. }
  168. else {
  169. echo " <option value='outbound_caller_id_name'>".$text['label-outbound_caller_id_name']."</option>\n";
  170. }
  171. if ($option_selected == "outbound_caller_id_number") {
  172. echo " <option value='outbound_caller_id_number' selected='selected'>".$text['label-outbound_caller_id_number']."</option>\n";
  173. }
  174. else {
  175. echo " <option value='outbound_caller_id_number'>".$text['label-outbound_caller_id_number']."</option>\n";
  176. }
  177. if ($option_selected == "toll_allow") {
  178. echo " <option value='toll_allow' selected='selected'>".$text['label-toll_allow']."</option>\n";
  179. }
  180. else {
  181. echo " <option value='toll_allow'>".$text['label-toll_allow']."</option>\n";
  182. }
  183. if ($option_selected == "sip_force_expires") {
  184. echo " <option value='sip_force_expires' selected='selected'>".$text['label-sip_force_expires']."</option>\n";
  185. }
  186. else {
  187. echo " <option value='sip_force_expires'>".$text['label-sip_force_expires']."</option>\n";
  188. }
  189. echo " </select>\n";
  190. echo " </form>\n";
  191. echo "<br />\n";
  192. echo $text['description-extension_settings_description']."\n";
  193. echo "</td>\n";
  194. echo " <td align='right' width='100%' style='vertical-align: top;'>";
  195. echo " <form method='get' action=''>\n";
  196. echo " <td style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
  197. echo " <input type='button' class='btn' alt='".$text['button-back']."' onclick=\"window.location='bulk_account_settings.php'\" value='".$text['button-back']."'>\n";
  198. echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".$search."'>";
  199. echo " <input type='hidden' class='txt' style='width: 150px' name='option_selected' id='option_selected' value='".$option_selected."'>";
  200. echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>";
  201. if ($paging_controls_mini != '') {
  202. echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>\n";
  203. }
  204. echo " </td>\n";
  205. echo " </form>\n";
  206. echo " </tr>\n";
  207. echo " <tr>\n";
  208. echo " <td colspan='2'>\n";
  209. echo " ".$text['description-extensions_settings']."\n";
  210. echo " </td>\n";
  211. echo " </tr>\n";
  212. echo "</table>\n";
  213. echo "<br />";
  214. if (strlen($option_selected) > 0) {
  215. echo "<form name='extensions' method='post' action='bulk_account_settings_extensions_update.php'>\n";
  216. echo "<input class='formfld' type='hidden' name='option_selected' maxlength='255' value=\"$option_selected\">\n";
  217. echo "<table width='auto' border='0' cellpadding='0' cellspacing='0'>\n";
  218. echo "<tr>\n";
  219. //options with a free form input
  220. if($option_selected == 'accountcode' || $option_selected == 'call_group' || $option_selected == 'call_timeout' || $option_selected == 'emergency_caller_id_name' || $option_selected == 'emergency_caller_id_number' || $option_selected == 'limit_max' || $option_selected == 'outbound_caller_id_name' || $option_selected == 'outbound_caller_id_number' || $option_selected == 'toll_allow' || $option_selected == 'sip_force_expires') {
  221. echo "<td class='vtable' align='left'>\n";
  222. echo " <input class='formfld' type='text' name='new_setting' maxlength='255' value=\"$new_setting\">\n";
  223. echo "<br />\n";
  224. echo $text["description-".$option_selected.""]."\n";
  225. echo "</td>\n";
  226. }
  227. //option is Enabled
  228. if($option_selected == 'enabled') {
  229. echo "<td class='vtable' align='left'>\n";
  230. echo " <select class='formfld' name='new_setting'>\n";
  231. echo " <option value='true'>".$text['label-true']."</option>\n";
  232. echo " <option value='false'>".$text['label-false']."</option>\n";
  233. echo " </select>\n";
  234. echo " <br />\n";
  235. echo $text["description-".$option_selected.""]."\n";
  236. echo "</td>\n";
  237. }
  238. //option is hold_music
  239. if($option_selected == 'hold_music') {
  240. echo "<td class='vtable' align='left'>\n";
  241. if (is_dir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/app/music_on_hold')) {
  242. require_once "app/music_on_hold/resources/classes/switch_music_on_hold.php";
  243. $options = '';
  244. $moh = new switch_music_on_hold;
  245. echo $moh->select('new_setting', $hold_music, $options);
  246. }
  247. $new_setting = $hold_music;
  248. echo " <br />\n";
  249. echo $text["description-".$option_selected.""]."\n";
  250. echo "</td>\n";
  251. }
  252. echo "<td align='left'>\n";
  253. echo "<input type='button' class='btn' alt='".$text['button-submit']."' onclick=\"if (confirm('".$text['confirm-update']."')) { document.forms.extensions.submit(); }\" value='".$text['button-submit']."'>\n";
  254. echo "</td>\n";
  255. echo "</tr>\n";
  256. echo "</table>";
  257. echo "<br />";
  258. }
  259. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  260. echo "<tr>\n";
  261. if (is_array($directory)) {
  262. echo "<th style='width: 30px; text-align: center; padding: 0px;'><input type='checkbox' id='chk_all' onchange=\"(this.checked) ? check('all') : check('none');\"></th>";
  263. }
  264. echo th_order_by('extension', $text['label-extension'], $order_by,$order,'','',"option_selected=".$option_selected."&search=".$search."");
  265. if (($option_selected == "") or ($option_selected == 'call_group') or ($option_selected == 'accountcode')) {
  266. } else {
  267. echo th_order_by($option_selected, $text["label-".$option_selected.""], $order_by,$order,'','',"option_selected=".$option_selected."&search=".$search."");
  268. }
  269. echo th_order_by('accountcode', $text['label-accountcode'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  270. echo th_order_by('call_group', $text['label-call_group'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  271. echo th_order_by('description', $text['label-description'], $order_by, $order,'','',"option_selected=".$option_selected."&search=".$search."");
  272. echo "</tr>\n";
  273. if (is_array($directory)) {
  274. foreach($directory as $key => $row) {
  275. $tr_link = (permission_exists('extension_edit')) ? " href='/app/extensions/extension_edit.php?id=".$row['extension_uuid']."'" : null;
  276. echo "<tr ".$tr_link.">\n";
  277. echo " <td valign='top' class='".$row_style[$c]." tr_link_void' style='text-align: center; vertical-align: middle; padding: 0px;'>";
  278. echo " <input type='checkbox' name='id[]' id='checkbox_".$row['extension_uuid']."' value='".$row['extension_uuid']."' onclick=\"if (!this.checked) { document.getElementById('chk_all').checked = false; }\">";
  279. echo " </td>";
  280. $ext_ids[] = 'checkbox_'.$row['extension_uuid'];
  281. echo " <td valign='top' class='".$row_style[$c]."'> ".$row['extension']."&nbsp;</td>\n";
  282. if (($option_selected == "") or ($option_selected == 'call_group') or ($option_selected == 'accountcode')) {
  283. } else {
  284. echo " <td valign='top' class='".$row_style[$c]."'> ".$row[$option_selected]."&nbsp;</td>\n";
  285. }
  286. echo " <td valign='top' class='".$row_style[$c]."'> ".$row['accountcode']."&nbsp;</td>\n";
  287. echo " <td valign='top' class='".$row_style[$c]."'> ".$row['call_group']."&nbsp;</td>\n";
  288. echo " <td valign='top' class='".$row_style[$c]."'> ".$row['description']."</td>\n";
  289. echo "</tr>\n";
  290. $c = ($c) ? 0 : 1;
  291. }
  292. unset($directory, $row);
  293. }
  294. echo "</table>";
  295. echo "</form>";
  296. if (strlen($paging_controls) > 0) {
  297. echo "<br />";
  298. echo $paging_controls."\n";
  299. }
  300. echo "<br /><br />".((is_array($directory)) ? "<br /><br />" : null);
  301. // check or uncheck all checkboxes
  302. if (sizeof($ext_ids) > 0) {
  303. echo "<script>\n";
  304. echo " function check(what) {\n";
  305. echo " document.getElementById('chk_all').checked = (what == 'all') ? true : false;\n";
  306. foreach ($ext_ids as $ext_id) {
  307. echo " document.getElementById('".$ext_id."').checked = (what == 'all') ? true : false;\n";
  308. }
  309. echo " }\n";
  310. echo "</script>\n";
  311. }
  312. if (is_array($directory)) {
  313. // check all checkboxes
  314. key_press('ctrl+a', 'down', 'document', null, null, "check('all');", true);
  315. // delete checked
  316. key_press('delete', 'up', 'document', array('#search'), $text['confirm-delete'], 'document.forms.frm.submit();', true);
  317. }
  318. //show the footer
  319. require_once "resources/footer.php";
  320. ?>