bulk_account_settings_extensions.php 19 KB

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