domain_settings.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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-2019
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes
  22. require_once "root.php";
  23. require_once "resources/require.php";
  24. require_once "resources/check_auth.php";
  25. //check permissions
  26. if (permission_exists('domain_setting_view')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. //get the http post data
  34. if ($_POST['action'] != '') {
  35. $action = $_POST['action'];
  36. $domain_uuid = $_POST['domain_uuid'];
  37. $domain_settings = $_POST['domain_settings'];
  38. $domain_uuid_target = $_POST['domain_uuid_target'];
  39. //process the http post data by action
  40. if (is_array($domain_settings) && @sizeof($domain_settings) != 0) {
  41. switch ($action) {
  42. case 'copy':
  43. if (permission_exists('domain_setting_add') && permission_exists('domain_select') && count($_SESSION['domains']) > 1) {
  44. $obj = new domain_settings;
  45. $obj->domain_uuid = $domain_uuid;
  46. $obj->domain_uuid_target = $domain_uuid_target;
  47. $obj->copy($domain_settings);
  48. }
  49. break;
  50. case 'toggle':
  51. if (permission_exists('domain_setting_edit')) {
  52. $obj = new domain_settings;
  53. $obj->domain_uuid = $domain_uuid;
  54. $obj->toggle($domain_settings);
  55. }
  56. break;
  57. case 'delete':
  58. if (permission_exists('domain_setting_delete')) {
  59. $obj = new domain_settings;
  60. $obj->domain_uuid = $domain_uuid;
  61. $obj->delete($domain_settings);
  62. }
  63. break;
  64. }
  65. }
  66. //redirect
  67. header('Location: '.PROJECT_PATH.'/core/domains/domain_edit.php?id='.urlencode($_REQUEST['domain_uuid']));
  68. exit;
  69. }
  70. //get the variables
  71. $order_by = $_GET["order_by"];
  72. $order = $_GET["order"];
  73. //prepare to page the results
  74. $sql = "select count(domain_setting_uuid) from v_domain_settings ";
  75. $sql .= "where domain_uuid = :domain_uuid ";
  76. $parameters['domain_uuid'] = $domain_uuid;
  77. $database = new database;
  78. $num_rows = $database->select($sql, $parameters, 'column');
  79. //get the list
  80. $sql = str_replace('count(domain_setting_uuid)', '*', $sql);
  81. if ($order_by == '') {
  82. $sql .= " order by domain_setting_category, domain_setting_subcategory, domain_setting_order asc, domain_setting_name, domain_setting_value ";
  83. }
  84. else {
  85. $sql .= order_by($order_by, $order);
  86. }
  87. $database = new database;
  88. $domain_settings = $database->select($sql, $parameters, 'all');
  89. unset($sql, $parameters);
  90. //create token
  91. $object = new token;
  92. $token = $object->create('/core/domain_settings/domain_settings.php');
  93. //copy settings javascript
  94. if (
  95. permission_exists("domain_select") &&
  96. permission_exists("domain_setting_add") &&
  97. is_array($_SESSION['domains']) &&
  98. @sizeof($_SESSION['domains']) > 1
  99. ) {
  100. echo "<script language='javascript' type='text/javascript'>\n";
  101. echo " var fade_speed = 400;\n";
  102. echo " function show_domains() {\n";
  103. echo " $('#button_copy').fadeOut(fade_speed, function() {\n";
  104. echo " $('#button_reset').fadeIn(fade_speed);\n";
  105. echo " $('#target_domain').fadeIn(fade_speed);\n";
  106. echo " $('#button_paste').fadeIn(fade_speed);\n";
  107. echo " document.getElementById('domain_uuid_target').value = '';\n";
  108. echo " });";
  109. echo " }";
  110. echo " function hide_domains() {\n";
  111. echo " $('#button_reset').fadeOut(fade_speed);\n";
  112. echo " $('#target_domain').fadeOut(fade_speed);\n";
  113. echo " $('#button_paste').fadeOut(fade_speed, function() {\n";
  114. echo " $('#button_copy').fadeIn(fade_speed);\n";
  115. echo " document.getElementById('target_domain').selectedIndex = 0;\n";
  116. echo " document.getElementById('domain_uuid_target').value = '';\n";
  117. echo " });\n";
  118. echo " }\n";
  119. echo "</script>";
  120. }
  121. //show the content
  122. echo "<div class='action_bar' id='action_bar_sub'>\n";
  123. echo " <div class='heading'><b id='heading_sub'>".$text['header-domain_settings']." (".$num_rows.")</b></div>\n";
  124. echo " <div class='actions'>\n";
  125. echo button::create(['type'=>'button','id'=>'action_bar_sub_button_back','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'style'=>'margin-right: 15px; display: none;','link'=>'domains.php']);
  126. if (permission_exists('domain_setting_add')) {
  127. echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>PROJECT_PATH."/core/domain_settings/domain_setting_edit.php?domain_uuid=".urlencode($domain_uuid)]);
  128. }
  129. if (permission_exists("domain_select") && permission_exists("domain_setting_add") && $num_rows) {
  130. echo button::create(['type'=>'button','label'=>$text['button-copy'],'id'=>'button_copy','icon'=>$_SESSION['theme']['button_icon_copy'],'onclick'=>'show_domains();']);
  131. echo button::create(['type'=>'button','label'=>$text['button-reset'],'id'=>'button_reset','icon'=>$_SESSION['theme']['button_icon_reset'],'style'=>'display: none;','onclick'=>'hide_domains();']);
  132. echo "<select class='formfld' style='display: none; width: auto;' id='target_domain' onchange=\"document.getElementById('domain_uuid_target').value = this.options[this.selectedIndex].value;\">\n";
  133. echo " <option value='' selected='selected' disabled='disabled'>".$text['label-domain']."...</option>\n";
  134. foreach ($_SESSION['domains'] as $domain) {
  135. if ($domain['domain_uuid'] == $domain_uuid) { continue; }
  136. echo " <option value='".escape($domain["domain_uuid"])."'>".escape($domain["domain_name"])."</option>\n";
  137. }
  138. if (permission_exists('default_setting_add') && permission_exists('default_setting_edit')) {
  139. echo " <option value='' disabled='disabled'></option>\n";
  140. echo " <option value='default'>".$text['label-default_settings']."</option>\n";
  141. }
  142. echo " </select>";
  143. echo button::create(['type'=>'button','label'=>$text['button-paste'],'id'=>'button_paste','icon'=>$_SESSION['theme']['button_icon_paste'],'style'=>'display: none;','onclick'=>"if (confirm('".$text['confirm-copy']."')) { list_action_set('copy'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
  144. }
  145. if (permission_exists('domain_setting_edit') && $num_rows) {
  146. echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'onclick'=>"if (confirm('".$text['confirm-toggle']."')) { list_action_set('toggle'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
  147. }
  148. if (permission_exists('domain_setting_delete') && $num_rows) {
  149. echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
  150. }
  151. if (permission_exists('default_setting_view') && $num_rows) {
  152. echo button::create(['type'=>'button','label'=>$text['button-reload'],'icon'=>$_SESSION['theme']['button_icon_reload'],'style'=>'margin-left: 15px;','link'=>PROJECT_PATH.'/core/default_settings/default_settings_reload.php?id='.$domain_uuid]);
  153. }
  154. echo " </div>\n";
  155. echo " <div style='clear: both;'></div>\n";
  156. echo "</div>\n";
  157. echo $text['header_description-domain_settings']."\n";
  158. echo "<br /><br />\n";
  159. echo "<form id='form_list' method='post' action='".PROJECT_PATH."/core/domain_settings/domain_settings.php'>\n";
  160. echo "<input type='hidden' id='action' name='action' value=''>\n";
  161. echo "<input type='hidden' name='domain_uuid' value='".escape($domain_uuid)."'>\n";
  162. echo "<input type='hidden' name='domain_uuid_target' id='domain_uuid_target' value=''>\n";
  163. echo "<table class='list'>\n";
  164. if (is_array($domain_settings) && @sizeof($domain_settings) != 0) {
  165. $x = 0;
  166. foreach ($domain_settings as $row) {
  167. $domain_setting_category = strtolower($row['domain_setting_category']);
  168. $label_domain_setting_category = $row['domain_setting_category'];
  169. switch (strtolower($label_domain_setting_category)) {
  170. case "api" : $label_domain_setting_category = "API"; break;
  171. case "cdr" : $label_domain_setting_category = "CDR"; break;
  172. case "ldap" : $label_domain_setting_category = "LDAP"; break;
  173. case "ivr_menu" : $label_domain_setting_category = "IVR Menu"; break;
  174. default:
  175. $label_domain_setting_category = str_replace("_", " ", $label_domain_setting_category);
  176. $label_domain_setting_category = str_replace("-", " ", $label_domain_setting_category);
  177. $label_domain_setting_category = ucwords($label_domain_setting_category);
  178. }
  179. if ($previous_domain_setting_category != $row['domain_setting_category']) {
  180. if ($previous_domain_setting_category != '') {
  181. echo "</table>\n";
  182. echo "<br>\n";
  183. }
  184. echo "<b>".escape($label_domain_setting_category)."</b><br>\n";
  185. echo "<table class='list'>\n";
  186. echo "<tr class='list-header'>\n";
  187. if (permission_exists('domain_setting_add') || permission_exists('domain_setting_edit') || permission_exists('domain_setting_delete')) {
  188. echo " <th class='checkbox'>\n";
  189. echo " <input type='checkbox' id='checkbox_all_".$domain_setting_category."' name='checkbox_all' onclick=\"list_all_toggle('".$domain_setting_category."');\">\n";
  190. echo " </th>\n";
  191. }
  192. if ($_GET['show'] == 'all' && permission_exists('domain_setting_all')) {
  193. echo th_order_by('domain_name', $text['label-domain'], $order_by, $order);
  194. }
  195. echo th_order_by('domain_setting_subcategory', $text['label-subcategory'], $order_by, $order, null, "class='pct-35'");
  196. echo th_order_by('domain_setting_name', $text['label-type'], $order_by, $order, null, "class='pct-10 hide-sm-dn'");
  197. echo th_order_by('domain_setting_value', $text['label-value'], $order_by, $order, null, "class='pct-30'");
  198. echo th_order_by('domain_setting_enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
  199. echo " <th class='pct-25 hide-sm-dn'>".$text['label-description']."</th>\n";
  200. if (permission_exists('domain_setting_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  201. echo " <td class='action-button'>&nbsp;</td>\n";
  202. }
  203. echo "</tr>\n";
  204. }
  205. if (permission_exists('domain_setting_edit')) {
  206. $list_row_url = PROJECT_PATH."/core/domain_settings/domain_setting_edit.php?domain_uuid=".escape($row['domain_uuid'])."&id=".escape($row['domain_setting_uuid']);
  207. }
  208. echo "<tr class='list-row' href='".$list_row_url."'>\n";
  209. if (permission_exists('domain_setting_add') || permission_exists('domain_setting_edit') || permission_exists('domain_setting_delete')) {
  210. echo " <td class='checkbox'>\n";
  211. echo " <input type='checkbox' name='domain_settings[$x][checked]' id='checkbox_".$x."' class='checkbox_".$domain_setting_category."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all_".$domain_setting_category."').checked = false; }\">\n";
  212. echo " <input type='hidden' name='domain_settings[$x][uuid]' value='".escape($row['domain_setting_uuid'])."' />\n";
  213. echo " </td>\n";
  214. }
  215. echo " <td class='overflow no-wrap'>";
  216. if (permission_exists('domain_setting_edit')) {
  217. echo " <a href='".$list_row_url."'>".escape($row['domain_setting_subcategory'])."</a>";
  218. }
  219. else {
  220. echo escape($row['domain_setting_subcategory']);
  221. }
  222. echo " </td>\n";
  223. echo " <td class='hide-sm-dn'>".escape($row['domain_setting_name'])."</td>\n";
  224. echo " <td class='overflow no-wrap'>\n";
  225. $category = $row['domain_setting_category'];
  226. $subcategory = $row['domain_setting_subcategory'];
  227. $name = $row['domain_setting_name'];
  228. if ($category == "domain" && $subcategory == "menu" && $name == "uuid" ) {
  229. $sql = "select * from v_menus ";
  230. $sql .= "where menu_uuid = :menu_uuid ";
  231. $parameters['menu_uuid'] = $row['domain_setting_value'];
  232. $database = new database;
  233. $sub_result = $database->select($sql, $parameters, 'all');
  234. if (is_array($sub_result) && sizeof($sub_result) != 0) {
  235. foreach ($sub_result as &$sub_row) {
  236. echo escape($sub_row["menu_language"])." - ".escape($sub_row["menu_name"])."\n";
  237. }
  238. }
  239. unset($sql, $parameters, $sub_result, $sub_row);
  240. }
  241. else if ($category == "domain" && $subcategory == "template" && $name == "name" ) {
  242. echo " ".ucwords($row['domain_setting_value']);
  243. }
  244. else if ($category == "domain" && $subcategory == "time_format" && $name == "text" ) {
  245. switch ($row['domain_setting_value']) {
  246. case '12h': echo $text['label-12-hour']; break;
  247. case '24h': echo $text['label-24-hour']; break;
  248. }
  249. }
  250. else if (
  251. ( $category == "theme" && $subcategory == "menu_main_icons" && $name == "boolean" ) ||
  252. ( $category == "theme" && $subcategory == "menu_sub_icons" && $name == "boolean" ) ||
  253. ( $category == "theme" && $subcategory == "menu_brand_type" && $name == "text" ) ||
  254. ( $category == "theme" && $subcategory == "menu_style" && $name == "text" ) ||
  255. ( $category == "theme" && $subcategory == "menu_position" && $name == "text" ) ||
  256. ( $category == "theme" && $subcategory == "logo_align" && $name == "text" )
  257. ) {
  258. echo " ".$text['label-'.escape($row['domain_setting_value'])];
  259. }
  260. else if ($subcategory == 'password' || substr_count($subcategory, '_password') > 0 || $category == "login" && $subcategory == "password_reset_key" && $name == "text") {
  261. echo " ".str_repeat('*', strlen(escape($row['domain_setting_value'])));
  262. }
  263. else if ($category == 'theme' && $subcategory == 'button_icons' && $name == 'text') {
  264. echo " ".$text['option-button_icons_'.$row['domain_setting_value']]."\n";
  265. }
  266. else if ($category == "theme" && substr_count($subcategory, "_color") > 0 && ($name == "text" || $name == 'array')) {
  267. echo " ".(img_spacer('15px', '15px', 'background: '.escape($row['domain_setting_value']).'; margin-right: 4px; vertical-align: middle; border: 1px solid '.(color_adjust($row['domain_setting_value'], -0.18)).'; padding: -1px;'));
  268. echo "<span style=\"font-family: 'Courier New'; line-height: 6pt;\">".escape($row['domain_setting_value'])."</span>\n";
  269. }
  270. else if ($category == 'recordings' && $subcategory == 'storage_type' && $name == 'text') {
  271. echo " ".$text['label-'.$row['domain_setting_value']]."\n";
  272. }
  273. else {
  274. echo " ".escape($row['domain_setting_value'])."\n";
  275. }
  276. echo " </td>\n";
  277. if (permission_exists('domain_setting_edit')) {
  278. echo " <td class='no-link center'>\n";
  279. echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['domain_setting_enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
  280. }
  281. else {
  282. echo " <td class='center'>\n";
  283. echo $text['label-'.$row['domain_setting_enabled']];
  284. }
  285. echo " </td>\n";
  286. echo " <td class='description overflow hide-sm-dn' title=\"".escape($row['domain_setting_description'])."\">".escape($row['domain_setting_description'])."&nbsp;</td>\n";
  287. if (permission_exists('domain_setting_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
  288. echo " <td class='action-button'>\n";
  289. echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
  290. echo " </td>\n";
  291. }
  292. echo "</tr>\n";
  293. //set the previous category
  294. $previous_domain_setting_category = $row['domain_setting_category'];
  295. $x++;
  296. }
  297. unset($domain_settings);
  298. }
  299. echo "</table>\n";
  300. echo "<br />\n";
  301. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  302. echo "</form>\n";
  303. //make sub action bar sticky
  304. echo "<script>\n";
  305. echo " window.addEventListener('scroll', function(){\n";
  306. echo " action_bar_scroll('action_bar_sub', 300, heading_modify, heading_restore);\n";
  307. echo " }, false);\n";
  308. echo " function heading_modify() {\n";
  309. echo " document.getElementById('action_bar_sub_button_back').style.display = 'inline-block';\n";
  310. echo " }\n";
  311. echo " function heading_restore() {\n";
  312. echo " document.getElementById('action_bar_sub_button_back').style.display = 'none';\n";
  313. echo " }\n";
  314. echo "</script>\n";
  315. ?>