bulk_account_settings_extensions.php 19 KB

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