bulk_account_settings_extensions.php 19 KB

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