domain_setting_edit.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  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-2020
  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_add') || permission_exists('domain_setting_edit')) {
  27. //access granted
  28. }
  29. else {
  30. echo "access denied";
  31. exit;
  32. }
  33. //add multi-lingual support
  34. $language = new text;
  35. $text = $language->get();
  36. //retrieve allowed setting categories
  37. if (!permission_exists('domain_setting_category_edit')) {
  38. if (is_array($_SESSION['settings']) && sizeof($_SESSION['settings']) > 0) {
  39. foreach ($_SESSION['groups'] as $index => $group) {
  40. $group_name = $group['group_name'];
  41. if (is_array($_SESSION['settings'][$group_name]) && sizeof($_SESSION['settings'][$group_name]) > 0) {
  42. foreach ($_SESSION['settings'][$group_name] as $category) {
  43. $categories[] = strtolower($category);
  44. }
  45. }
  46. }
  47. }
  48. if (is_array($categories) && sizeof($categories) > 0) {
  49. $allowed_categories = array_unique($categories);
  50. sort($allowed_categories, SORT_NATURAL);
  51. }
  52. unset($group, $group_name, $index, $category, $categories);
  53. }
  54. //action add or update
  55. if (is_uuid($_REQUEST["id"])) {
  56. $action = "update";
  57. $domain_setting_uuid = $_REQUEST["id"];
  58. }
  59. else {
  60. $action = "add";
  61. }
  62. //set the domain_uuid
  63. if (is_uuid($_GET["domain_uuid"])) {
  64. $domain_uuid = $_GET["domain_uuid"];
  65. }
  66. //get http post variables and set them to php variables
  67. if (count($_POST) > 0) {
  68. $domain_setting_category = strtolower($_POST["domain_setting_category"]);
  69. $domain_setting_subcategory = strtolower($_POST["domain_setting_subcategory"]);
  70. $domain_setting_name = strtolower($_POST["domain_setting_name"]);
  71. $domain_setting_value = $_POST["domain_setting_value"];
  72. $domain_setting_order = $_POST["domain_setting_order"];
  73. $domain_setting_enabled = strtolower($_POST["domain_setting_enabled"]);
  74. $domain_setting_description = $_POST["domain_setting_description"];
  75. }
  76. if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) {
  77. $msg = '';
  78. if ($action == "update") {
  79. $domain_setting_uuid = $_POST["domain_setting_uuid"];
  80. }
  81. //validate the token
  82. $token = new token;
  83. if (!$token->validate($_SERVER['PHP_SELF'])) {
  84. message::add($text['message-invalid_token'],'negative');
  85. header('Location: ../domains/domain_edit.php?id='.$domain_uuid);
  86. exit;
  87. }
  88. //check for all required/authorized data
  89. if (strlen($domain_setting_category) == 0 || (is_array($allowed_categories) && sizeof($allowed_categories) > 0 && !in_array(strtolower($domain_setting_category), $allowed_categories))) { $msg .= $text['message-required'].$text['label-category']."<br>\n"; }
  90. if (strlen($domain_setting_subcategory) == 0) { $msg .= $text['message-required'].$text['label-subcategory']."<br>\n"; }
  91. if (strlen($domain_setting_name) == 0) { $msg .= $text['message-required'].$text['label-type']."<br>\n"; }
  92. //if (strlen($domain_setting_value) == 0) { $msg .= $text['message-required'].$text['label-value']."<br>\n"; }
  93. if (strlen($domain_setting_order) == 0) { $msg .= $text['message-required'].$text['label-order']."<br>\n"; }
  94. if (strlen($domain_setting_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."<br>\n"; }
  95. //if (strlen($domain_setting_description) == 0) { $msg .= $text['message-required'].$text['label-description']."<br>\n"; }
  96. if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) {
  97. require_once "resources/header.php";
  98. require_once "resources/persist_form_var.php";
  99. echo "<div align='center'>\n";
  100. echo "<table><tr><td>\n";
  101. echo $msg."<br />";
  102. echo "</td></tr></table>\n";
  103. persistformvar($_POST);
  104. echo "</div>\n";
  105. require_once "resources/footer.php";
  106. return;
  107. }
  108. //add or update the database
  109. if ($_POST["persistformvar"] != "true") {
  110. // fix null
  111. $domain_setting_order = $domain_setting_order != '' ? $domain_setting_order : 'null';
  112. //update switch timezone variables
  113. if ($domain_setting_category == "domain" && $domain_setting_subcategory == "time_zone" && $domain_setting_name == "name" ) {
  114. //get the dialplan_uuid
  115. $sql = "select dialplan_uuid from v_dialplans ";
  116. $sql .= "where domain_uuid = :domain_uuid ";
  117. $sql .= "and app_uuid = '9f356fe7-8cf8-4c14-8fe2-6daf89304458' ";
  118. $parameters['domain_uuid'] = $domain_uuid;
  119. $database = new database;
  120. $dialplan_uuid = $database->select($sql, $parameters, 'column');
  121. unset($sql, $parameters);
  122. //get the action
  123. $sql = "select dialplan_detail_uuid from v_dialplan_details ";
  124. $sql .= "where domain_uuid = :domain_uuid ";
  125. $sql .= "and dialplan_uuid = :dialplan_uuid ";
  126. $sql .= "and dialplan_detail_tag = 'action' ";
  127. $sql .= "and dialplan_detail_type = 'set' ";
  128. $sql .= "and dialplan_detail_data like 'timezone=%' ";
  129. $parameters['domain_uuid'] = $domain_uuid;
  130. $parameters['dialplan_uuid'] = $dialplan_uuid;
  131. $database = new database;
  132. $dialplan_detail_uuid = $database->select($sql, $parameters, 'column');
  133. $detail_action = is_uuid($dialplan_detail_uuid) ? 'update' : 'add';
  134. unset($sql, $parameters);
  135. //update the timezone
  136. $p = new permissions;
  137. if ($detail_action == "update") {
  138. $array['dialplan_details'][0]['dialplan_detail_uuid'] = $dialplan_detail_uuid;
  139. $array['dialplan_details'][0]['dialplan_detail_data'] = 'timezone='.$domain_setting_value;
  140. $p->add('dialplan_detail_edit', 'temp');
  141. }
  142. else {
  143. $array['dialplan_details'][0]['dialplan_detail_uuid'] = uuid();
  144. $array['dialplan_details'][0]['domain_uuid'] = $domain_uuid;
  145. $array['dialplan_details'][0]['dialplan_uuid'] = $dialplan_uuid;
  146. $array['dialplan_details'][0]['dialplan_detail_tag'] = 'action';
  147. $array['dialplan_details'][0]['dialplan_detail_type'] = 'set';
  148. $array['dialplan_details'][0]['dialplan_detail_data'] = 'timezone='.$domain_setting_value;
  149. $array['dialplan_details'][0]['dialplan_detail_inline'] = 'true';
  150. $array['dialplan_details'][0]['dialplan_detail_group'] = '0';
  151. $p->add('dialplan_detail_add', 'temp');
  152. }
  153. if (is_array($array) && sizeof($array) != 0) {
  154. $database = new database;
  155. $database->app_name = 'domain_settings';
  156. $database->app_uuid = 'b31e723a-bf70-670c-a49b-470d2a232f71';
  157. $database->save($array);
  158. unset($array);
  159. $p->delete('dialplan_detail_edit', 'temp');
  160. $p->delete('dialplan_detail_add', 'temp');
  161. }
  162. //get the dialplan uuid
  163. $sql = "select domain_name from v_domains ";
  164. $sql .= "where domain_uuid = :domain_uuid ";
  165. $parameters['domain_uuid'] = $domain_uuid;
  166. $database = new database;
  167. $domain_name = $database->select($sql, $parameters, 'column');
  168. unset($sql, $parameters);
  169. //update the dialplan xml
  170. $dialplans = new dialplan;
  171. $dialplans->source = "details";
  172. $dialplans->destination = "database";
  173. $dialplans->uuid = $dialplan_uuid;
  174. $dialplans->xml();
  175. //clear the cache
  176. $cache = new cache;
  177. $cache->delete("dialplan:".$domain_name);
  178. }
  179. //add
  180. if ($action == "add" && permission_exists('domain_setting_add')) {
  181. $array['domain_settings'][0]['domain_setting_uuid'] = uuid();
  182. }
  183. //update
  184. if ($action == "update" && permission_exists('domain_setting_edit')) {
  185. $array['domain_settings'][0]['domain_setting_uuid'] = $domain_setting_uuid;
  186. }
  187. //execute
  188. if (is_uuid($array['domain_settings'][0]['domain_setting_uuid'])) {
  189. $array['domain_settings'][0]['domain_uuid'] = $domain_uuid;
  190. $array['domain_settings'][0]['domain_setting_category'] = $domain_setting_category;
  191. $array['domain_settings'][0]['domain_setting_subcategory'] = $domain_setting_subcategory;
  192. $array['domain_settings'][0]['domain_setting_name'] = $domain_setting_name;
  193. $array['domain_settings'][0]['domain_setting_value'] = $domain_setting_value;
  194. $array['domain_settings'][0]['domain_setting_order'] = $domain_setting_order;
  195. $array['domain_settings'][0]['domain_setting_enabled'] = $domain_setting_enabled;
  196. $array['domain_settings'][0]['domain_setting_description'] = $domain_setting_description;
  197. $database = new database;
  198. $database->app_name = 'domain_settings';
  199. $database->app_uuid = 'b31e723a-bf70-670c-a49b-470d2a232f71';
  200. $database->save($array);
  201. unset($array);
  202. }
  203. //update time zone
  204. if ($domain_setting_category == "domain" && $domain_setting_subcategory == "time_zone" && $domain_setting_name == "name" && strlen($domain_setting_value) > 0 ) {
  205. $sql = "select * from v_dialplans ";
  206. $sql .= "where app_uuid = '34dd307b-fffe-4ead-990c-3d070e288126' ";
  207. $sql .= "and domain_uuid = :domain_uuid ";
  208. $parameters['domain_uuid'] = $_SESSION["domain_uuid"];
  209. $database = new database;
  210. $result = $database->select($sql, $parameters, 'all');
  211. unset($sql, $parameters);
  212. $time_zone_found = false;
  213. if (is_array($result) && sizeof($result) != 0) {
  214. foreach ($result as &$row) {
  215. //get the dialplan_uuid
  216. $dialplan_uuid = $row["dialplan_uuid"];
  217. //get the dialplan details
  218. $sql = "select * from v_dialplan_details ";
  219. $sql .= "where dialplan_uuid = :dialplan_uuid ";
  220. $sql .= "and domain_uuid = :domain_uuid ";
  221. $parameters['dialplan_uuid'] = $dialplan_uuid;
  222. $parameters['domain_uuid'] = $_SESSION["domain_uuid"];
  223. $database = new database;
  224. $sub_result = $database->select($sql, $parameters, 'all');
  225. if (is_array($sub_result) && sizeof($sub_result) != 0) {
  226. foreach ($sub_result as $field) {
  227. $dialplan_detail_uuid = $field["dialplan_detail_uuid"];
  228. $dialplan_detail_tag = $field["dialplan_detail_tag"]; //action //condition
  229. $dialplan_detail_type = $field["dialplan_detail_type"]; //set
  230. $dialplan_detail_data = $field["dialplan_detail_data"];
  231. $dialplan_detail_group = $field["dialplan_detail_group"];
  232. if ($dialplan_detail_tag == "action" && $dialplan_detail_type == "set") {
  233. $data_array = explode("=", $dialplan_detail_data);
  234. if ($data_array[0] == "timezone") {
  235. $time_zone_found = true;
  236. break;
  237. }
  238. }
  239. }
  240. }
  241. unset($sql, $parameters, $sub_result, $field);
  242. //add the time zone
  243. if (!$time_zone_found) {
  244. $dialplan_detail_uuid = "eb3b3a4e-88ea-4306-b2a8-9f52d3c95f2f";
  245. $array['dialplan_details'][0]['domain_uuid'] = $_SESSION["domain_uuid"]; //8cfd9525-6ccf-4c2c-813a-bca5809067cd
  246. $array['dialplan_details'][0]['dialplan_uuid'] = $dialplan_uuid; //807b4aa6-4478-4663-a661-779397c1d542
  247. $array['dialplan_details'][0]['dialplan_detail_uuid'] = $dialplan_detail_uuid;
  248. $array['dialplan_details'][0]['dialplan_detail_tag'] = 'action';
  249. $array['dialplan_details'][0]['dialplan_detail_type'] = 'set';
  250. $array['dialplan_details'][0]['dialplan_detail_data'] = 'timezone='.$domain_setting_value;
  251. $array['dialplan_details'][0]['dialplan_detail_group'] = $dialplan_detail_group;
  252. $array['dialplan_details'][0]['dialplan_detail_order'] = '15';
  253. $p = new permissions;
  254. $p->add('dialplan_detail_add', 'temp');
  255. }
  256. //update the time zone
  257. if ($time_zone_found) {
  258. $array['dialplan_details'][0]['dialplan_detail_uuid'] = $dialplan_detail_uuid;
  259. $array['dialplan_details'][0]['dialplan_detail_data'] = 'timezone='.$domain_setting_value;
  260. $p = new permissions;
  261. $p->add('dialplan_detail_edit', 'temp');
  262. }
  263. //execute
  264. if (is_array($array) && sizeof($array) != 0) {
  265. $database = new database;
  266. $database->app_name = 'domain_settings';
  267. $database->app_uuid = 'b31e723a-bf70-670c-a49b-470d2a232f71';
  268. $database->save($array);
  269. unset($array);
  270. $p->delete('dialplan_detail_add', 'temp');
  271. $p->delete('dialplan_detail_edit', 'temp');
  272. }
  273. }
  274. }
  275. }
  276. //redirect the browser
  277. if ($action == "update") {
  278. message::add($text['message-update']);
  279. }
  280. if ($action == "add") {
  281. message::add($text['message-add']);
  282. }
  283. header("Location: ".PROJECT_PATH."/core/domains/domain_edit.php?id=".$domain_uuid);
  284. exit;
  285. }
  286. }
  287. //pre-populate the form
  288. if (count($_GET)>0 && $_POST["persistformvar"] != "true" && is_uuid($_GET["id"])) {
  289. $domain_setting_uuid = $_GET["id"];
  290. $sql = "select * from v_domain_settings ";
  291. $sql .= "where domain_uuid = :domain_uuid ";
  292. $sql .= "and domain_setting_uuid = :domain_setting_uuid ";
  293. $parameters['domain_uuid'] = $domain_uuid;
  294. $parameters['domain_setting_uuid'] = $domain_setting_uuid;
  295. $database = new database;
  296. $row = $database->select($sql, $parameters, 'row');
  297. if (is_array($row) && sizeof($row) != 0) {
  298. $domain_setting_category = $row["domain_setting_category"];
  299. $domain_setting_subcategory = $row["domain_setting_subcategory"];
  300. $domain_setting_name = $row["domain_setting_name"];
  301. $domain_setting_value = $row["domain_setting_value"];
  302. $domain_setting_order = $row["domain_setting_order"];
  303. $domain_setting_enabled = $row["domain_setting_enabled"];
  304. $domain_setting_description = $row["domain_setting_description"];
  305. }
  306. unset($sql, $parameters);
  307. }
  308. //create token
  309. $object = new token;
  310. $token = $object->create($_SERVER['PHP_SELF']);
  311. //include the header
  312. if ($action == "update") {
  313. $document['title'] = $text['title-domain_setting-edit'];
  314. }
  315. elseif ($action == "add") {
  316. $document['title'] = $text['title-domain_setting-add'];
  317. }
  318. require_once "resources/header.php";
  319. //show the content
  320. echo "<form name='frm' id='frm' method='post'>\n";
  321. echo "<div class='action_bar' id='action_bar'>\n";
  322. echo " <div class='heading'>";
  323. if ($action == "update") {
  324. echo "<b>".$text['header-domain_setting-edit']."</b>";
  325. }
  326. if ($action == "add") {
  327. echo "<b>".$text['header-domain_setting-add']."</b>";
  328. }
  329. echo " </div>\n";
  330. echo " <div class='actions'>\n";
  331. echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'style'=>'margin-right: 15px;','link'=>PROJECT_PATH.'/core/domains/domain_edit.php?id='.urlencode($domain_uuid)]);
  332. echo button::create(['type'=>'button','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'onclick'=>'submit_form();']);
  333. echo " </div>\n";
  334. echo " <div style='clear: both;'></div>\n";
  335. echo "</div>\n";
  336. if ($action == "update") {
  337. echo $text['description-domain_setting-edit']."\n";
  338. }
  339. if ($action == "add") {
  340. echo $text['description-domain_setting-add']."\n";
  341. }
  342. echo "<br /><br />\n";
  343. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  344. echo "<tr>\n";
  345. echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  346. echo " ".$text['label-category']."\n";
  347. echo "</td>\n";
  348. echo "<td width='70%' class='vtable' align='left'>\n";
  349. if (permission_exists('domain_setting_category_edit')) {
  350. if ($action == 'add') {
  351. $domain_setting_category = $_GET['domain_setting_category'];
  352. }
  353. echo " <input type='text' class='formfld' name='domain_setting_category' id='domain_setting_category' maxlength='255' value=\"".escape($domain_setting_category)."\">\n";
  354. }
  355. else {
  356. echo " <select class='formfld' name='domain_setting_category' id='domain_setting_category' onchange=\"$('#domain_setting_subcategory').trigger('focus');\">\n";
  357. echo " <option value=''></option>\n";
  358. if (is_array($allowed_categories) && sizeof($allowed_categories) > 0) {
  359. foreach ($allowed_categories as $category) {
  360. $selected = ($domain_setting_category == $category) ? 'selected' : null;
  361. echo " <option value='".escape($category)."' ".$selected.">".ucwords(str_replace('_',' ',escape($category)))."</option>\n";
  362. }
  363. }
  364. echo " </select>";
  365. }
  366. echo "<br />\n";
  367. echo $text['description-category']."\n";
  368. echo "</td>\n";
  369. echo "</tr>\n";
  370. echo "<tr>\n";
  371. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  372. echo " ".$text['label-subcategory']."\n";
  373. echo "</td>\n";
  374. echo "<td class='vtable' align='left'>\n";
  375. echo " <input class='formfld lowercase' type='text' name='domain_setting_subcategory' id='domain_setting_subcategory' maxlength='255' value=\"".escape($domain_setting_subcategory)."\">\n";
  376. echo "<br />\n";
  377. echo $text['description-subcategory']."\n";
  378. echo "</td>\n";
  379. echo "</tr>\n";
  380. echo "<tr>\n";
  381. echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  382. echo " ".$text['label-type']."\n";
  383. echo "</td>\n";
  384. echo "<td class='vtable' align='left'>\n";
  385. echo " <input class='formfld lowercase' type='text' name='domain_setting_name' id='domain_setting_name' maxlength='255' value=\"".escape($domain_setting_name)."\">\n";
  386. echo "<br />\n";
  387. echo $text['description-type']."\n";
  388. echo "</td>\n";
  389. echo "</tr>\n";
  390. echo "<tr>\n";
  391. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  392. echo " ".$text['label-value']."\n";
  393. echo "</td>\n";
  394. echo "<td class='vtable' align='left'>\n";
  395. $category = $row['domain_setting_category'];
  396. $subcategory = $row['domain_setting_subcategory'];
  397. $name = $row['domain_setting_name'];
  398. if ($category == "domain" && $subcategory == "menu" && $name == "uuid" ) {
  399. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value' style=''>\n";
  400. echo " <option value=''></option>\n";
  401. $sql = "select * from v_menus ";
  402. $sql .= "order by menu_language, menu_name asc ";
  403. $database = new database;
  404. $sub_result = $database->select($sql, null, 'all');
  405. if (is_array($sub_result) && sizeof($sub_result) != 0) {
  406. foreach ($sub_result as $sub_row) {
  407. $selected = strtolower($row['domain_setting_value']) == strtolower($sub_row["menu_uuid"]) ? "selected='selected'" : null;
  408. echo " <option value='".strtolower(escape($sub_row["menu_uuid"]))."' ".$selected.">".escape($sub_row["menu_language"])." - ".escape($sub_row["menu_name"])."</option>\n";
  409. }
  410. }
  411. unset($sql, $sub_result, $sub_row, $selected);
  412. echo " </select>\n";
  413. }
  414. elseif ($category == "domain" && $subcategory == "template" && $name == "name" ) {
  415. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value' style=''>\n";
  416. echo " <option value=''></option>\n";
  417. //add all the themes to the list
  418. $theme_dir = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes';
  419. if ($handle = opendir($_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/themes')) {
  420. while (false !== ($dir_name = readdir($handle))) {
  421. if ($dir_name != "." && $dir_name != ".." && $dir_name != ".svn" && $dir_name != ".git" && is_dir($theme_dir.'/'.$dir_name)) {
  422. $dir_label = str_replace('_', ' ', $dir_name);
  423. $dir_label = str_replace('-', ' ', $dir_label);
  424. if ($dir_name == $row['domain_setting_value']) {
  425. echo " <option value='".escape($dir_name)."' selected='selected'>".escape($dir_label)."</option>\n";
  426. }
  427. else {
  428. echo " <option value='".escape($dir_name)."'>".escape($dir_label)."</option>\n";
  429. }
  430. }
  431. }
  432. closedir($handle);
  433. }
  434. echo " </select>\n";
  435. }
  436. elseif ($category == "domain" && $subcategory == "language" && $name == "code" ) {
  437. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value' style=''>\n";
  438. echo " <option value=''></option>\n";
  439. foreach ($_SESSION['app']['languages'] as $key => $value) {
  440. if ($row['domain_setting_value'] == $value) {
  441. echo " <option value='".escape($value)."' selected='selected'>".escape($value)."</option>\n";
  442. }
  443. else {
  444. echo " <option value='".escape($value)."'>".escape($value)."</option>\n";
  445. }
  446. }
  447. echo " </select>\n";
  448. }
  449. elseif ($category == "domain" && $subcategory == "time_zone" && $name == "name" ) {
  450. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value' style=''>\n";
  451. echo " <option value=''></option>\n";
  452. //$list = DateTimeZone::listAbbreviations();
  453. $time_zone_identifiers = DateTimeZone::listIdentifiers();
  454. $previous_category = '';
  455. $x = 0;
  456. foreach ($time_zone_identifiers as $key => $val) {
  457. $time_zone = explode("/", $val);
  458. $category = $time_zone[0];
  459. if ($category != $previous_category) {
  460. if ($x > 0) {
  461. echo " </optgroup>\n";
  462. }
  463. echo " <optgroup label='".escape($category)."'>\n";
  464. }
  465. if (strlen($val) > 0) {
  466. $time_zone_offset = get_time_zone_offset($val)/3600;
  467. $time_zone_offset_hours = floor($time_zone_offset);
  468. $time_zone_offset_minutes = ($time_zone_offset - $time_zone_offset_hours) * 60;
  469. $time_zone_offset_minutes = number_pad($time_zone_offset_minutes, 2);
  470. if ($time_zone_offset > 0) {
  471. $time_zone_offset_hours = number_pad($time_zone_offset_hours, 2);
  472. $time_zone_offset_hours = "+".$time_zone_offset_hours;
  473. }
  474. else {
  475. $time_zone_offset_hours = str_replace("-", "", $time_zone_offset_hours);
  476. $time_zone_offset_hours = "-".number_pad($time_zone_offset_hours, 2);
  477. }
  478. }
  479. if ($val == $row['domain_setting_value']) {
  480. echo " <option value='".escape($val)."' selected='selected'>(UTC ".escape($time_zone_offset_hours).":".escape($time_zone_offset_minutes).") ".$val."</option>\n";
  481. }
  482. else {
  483. echo " <option value='".escape($val)."'>(UTC ".escape($time_zone_offset_hours).":".escape($time_zone_offset_minutes).") ".escape($val)."</option>\n";
  484. }
  485. $previous_category = $category;
  486. $x++;
  487. }
  488. echo " </select>\n";
  489. }
  490. elseif ($category == "domain" && $subcategory == "time_format" && $name == "text" ) {
  491. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  492. echo " <option value='24h' ".(($domain_setting_value == "24h") ? "selected='selected'" : null).">".$text['label-24-hour']."</option>\n";
  493. echo " <option value='12h' ".(($domain_setting_value == "12h") ? "selected='selected'" : null).">".$text['label-12-hour']."</option>\n";
  494. echo " </select>\n";
  495. }
  496. elseif ($subcategory == 'password' || substr_count($subcategory, '_password') > 0 || $category == "login" && $subcategory == "password_reset_key" && $name == "text") {
  497. echo " <input class='formfld' type='password' id='domain_setting_value' name='domain_setting_value' maxlength='255' onmouseover=\"this.type='text';\" onfocus=\"this.type='text';\" onmouseout=\"if (!$(this).is(':focus')) { this.type='password'; }\" onblur=\"this.type='password';\" value=\"".escape($row['domain_setting_value'])."\">\n";
  498. }
  499. elseif ($category == "theme" && substr_count($subcategory, "_color") > 0 && ($name == "text" || $name == 'array')) {
  500. echo " <input type='text' class='formfld colorpicker' id='domain_setting_value' name='domain_setting_value' value=\"".escape($row['domain_setting_value'])."\">\n";
  501. }
  502. elseif ($category == "theme" && substr_count($subcategory, "_font") > 0 && $name == "text") {
  503. $row['domain_setting_value'] = str_replace('"', "'", $row['domain_setting_value']);
  504. if ($fonts = get_available_fonts('alpha')) {
  505. echo " <select class='formfld' id='sel_domain_setting_value' onchange=\"if (this.selectedIndex == $('select#sel_domain_setting_value option').length - 1) { $('#txt_domain_setting_value').val('').fadeIn('fast'); $('#txt_domain_setting_value').trigger('focus'); } else { $('#txt_domain_setting_value').fadeOut('fast', function(){ $('#txt_domain_setting_value').val($('#sel_domain_setting_value').val()) }); } \">\n";
  506. echo " <option value=''></option>\n";
  507. echo " <optgroup label='".$text['label-web_fonts']."'>\n";
  508. $option_found = false;
  509. foreach ($fonts as $n => $font) {
  510. if ($row['domain_setting_value'] == $font) {
  511. $selected = 'selected';
  512. $option_found = true;
  513. }
  514. else {
  515. unset($selected);
  516. }
  517. echo " <option value='".escape($font)."' ".$selected.">".escape($font)."</option>\n";
  518. }
  519. echo " </optgroup>\n";
  520. echo " <option value='' disabled='disabled'></option>\n";
  521. echo " <option value='' ".(($row['domain_setting_value'] != '' && $option_found == false) ? 'selected' : null).">".$text['label-other']."...</option>\n";
  522. echo " </select>";
  523. echo " <input type='text' class='formfld' ".(($row['domain_setting_value'] == '' || $option_found) ? "style='display: none;'" : null)." id='txt_domain_setting_value' name='domain_setting_value' value=\"".escape($row['domain_setting_value'])."\">\n";
  524. }
  525. else {
  526. echo " <input type='text' class='formfld' id='domain_setting_value' name='domain_setting_value' value=\"".escape($row['domain_setting_value'])."\">\n";
  527. }
  528. }
  529. elseif ($category == "fax" && $subcategory == "page_size" && $name == "text" ) {
  530. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value' style=''>\n";
  531. echo " <option value='letter' ".(($row['domain_setting_value'] == 'letter') ? 'selected' : null).">Letter</option>";
  532. echo " <option value='legal' ".(($row['domain_setting_value'] == 'legal') ? 'selected' : null).">Legal</option>";
  533. echo " <option value='a4' ".(($row['domain_setting_value'] == 'a4') ? 'selected' : null).">A4</option>";
  534. echo " </select>";
  535. }
  536. elseif ($category == "fax" && $subcategory == "resolution" && $name == "text" ) {
  537. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value' style=''>\n";
  538. echo " <option value='normal' ".(($row['domain_setting_value'] == 'normal') ? 'selected' : null).">".$text['label-normal']."</option>";
  539. echo " <option value='fine' ".(($row['domain_setting_value'] == 'fine') ? 'selected' : null).">".$text['label-fine']."</option>";
  540. echo " <option value='superfine' ".(($row['domain_setting_value'] == 'superfine') ? 'selected' : null).">".$text['label-superfine']."</option>";
  541. echo " </select>";
  542. }
  543. elseif ($category == "provision" && $subcategory == "aastra_time_format" && $name == "text" ) {
  544. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  545. echo " <option value='1' ".(($domain_setting_value == "1") ? "selected='selected'" : null).">".$text['label-24-hour']."</option>\n";
  546. echo " <option value='0' ".(($domain_setting_value == "0") ? "selected='selected'" : null).">".$text['label-12-hour']."</option>\n";
  547. echo " </select>\n";
  548. }
  549. elseif ($category == "provision" && $subcategory == "aastra_date_format" && $name == "text" ) {
  550. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  551. echo " <option value='0' ".(($domain_setting_value == "0") ? "selected='selected'" : null).">WWW MMM DD</option>\n";
  552. echo " <option value='1' ".(($domain_setting_value == "1") ? "selected='selected'" : null).">DD-MMM-YY</option>\n";
  553. echo " <option value='2' ".(($domain_setting_value == "2") ? "selected='selected'" : null).">YYYY-MM-DD</option>\n";
  554. echo " <option value='3' ".(($domain_setting_value == "3") ? "selected='selected'" : null).">DD/MM/YYYY</option>\n";
  555. echo " <option value='4' ".(($domain_setting_value == "4") ? "selected='selected'" : null).">DD/MM/YY</option>\n";
  556. echo " <option value='5' ".(($domain_setting_value == "5") ? "selected='selected'" : null).">DD-MM-YY</option>\n";
  557. echo " <option value='6' ".(($domain_setting_value == "6") ? "selected='selected'" : null).">MM/DD/YY</option>\n";
  558. echo " <option value='7' ".(($domain_setting_value == "7") ? "selected='selected'" : null).">MMM DD</option>\n";
  559. echo " </select>\n";
  560. }
  561. elseif ($category == "theme" && $subcategory == "domain_visible" && $name == "text" ) {
  562. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  563. echo " <option value='false' ".(($row['domain_setting_value'] == "false") ? "selected='selected'" : null).">".$text['label-false']."</option>\n";
  564. echo " <option value='true' ".(($row['domain_setting_value'] == "true") ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
  565. echo " </select>\n";
  566. }
  567. elseif ($category == "theme" && $subcategory == "cache" && $name == "boolean" ) {
  568. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  569. echo " <option value='true' ".(($row['domain_setting_value'] == "true") ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
  570. echo " <option value='false' ".(($row['domain_setting_value'] == "false") ? "selected='selected'" : null).">".$text['label-false']."</option>\n";
  571. echo " </select>\n";
  572. }
  573. elseif (
  574. ($category == "theme" && $subcategory == "menu_main_icons" && $name == "boolean") ||
  575. ($category == "theme" && $subcategory == "menu_sub_icons" && $name == "boolean")
  576. ) {
  577. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  578. echo " <option value='true' ".(($row['domain_setting_value'] == "true") ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
  579. echo " <option value='false' ".(($row['domain_setting_value'] == "false") ? "selected='selected'" : null).">".$text['label-false']."</option>\n";
  580. echo " </select>\n";
  581. }
  582. elseif ($category == "theme" && $subcategory == "menu_brand_type" && $name == "text" ) {
  583. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  584. echo " <option value='image' ".(($row['domain_setting_value'] == "image") ? "selected='selected'" : null).">".$text['label-image']."</option>\n";
  585. echo " <option value='text' ".(($row['domain_setting_value'] == "text") ? "selected='selected'" : null).">".$text['label-text']."</option>\n";
  586. echo " <option value='none' ".(($row['domain_setting_value'] == "none") ? "selected='selected'" : null).">".$text['label-none']."</option>\n";
  587. echo " </select>\n";
  588. }
  589. elseif ($category == "theme" && $subcategory == "menu_style" && $name == "text" ) {
  590. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  591. echo " <option value='fixed' ".(($row['domain_setting_value'] == "fixed") ? "selected='selected'" : null).">".$text['label-fixed']."</option>\n";
  592. echo " <option value='static' ".(($row['domain_setting_value'] == "static") ? "selected='selected'" : null).">".$text['label-static']."</option>\n";
  593. echo " <option value='inline' ".(($row['domain_setting_value'] == "inline") ? "selected='selected'" : null).">".$text['label-inline']."</option>\n";
  594. echo " <option value='side' ".(($row['domain_setting_value'] == "side") ? "selected='selected'" : null).">".$text['label-side']."</option>\n";
  595. echo " </select>\n";
  596. }
  597. elseif ($category == "theme" && $subcategory == "menu_position" && $name == "text" ) {
  598. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  599. echo " <option value='top' ".(($row['domain_setting_value'] == "top") ? "selected='selected'" : null).">".$text['label-top']."</option>\n";
  600. echo " <option value='bottom' ".(($row['domain_setting_value'] == "bottom") ? "selected='selected'" : null).">".$text['label-bottom']."</option>\n";
  601. echo " </select>\n";
  602. }
  603. elseif ($category == "theme" && $subcategory == "logo_align" && $name == "text" ) {
  604. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  605. echo " <option value='left' ".(($row['domain_setting_value'] == "left") ? "selected='selected'" : null).">".$text['label-left']."</option>\n";
  606. echo " <option value='center' ".(($row['domain_setting_value'] == "center") ? "selected='selected'" : null).">".$text['label-center']."</option>\n";
  607. echo " <option value='right' ".(($row['domain_setting_value'] == "right") ? "selected='selected'" : null).">".$text['label-right']."</option>\n";
  608. echo " </select>\n";
  609. }
  610. elseif ($category == "theme" && $subcategory == "custom_css_code" && $name == "text" ) {
  611. echo " <textarea class='formfld' style='min-width: 100%; height: 300px; font-family: courier, monospace; overflow: auto; resize: vertical' id='domain_setting_value' name='domain_setting_value' wrap='off'>".$row['domain_setting_value']."</textarea>\n";
  612. }
  613. elseif ($category == "theme" && $subcategory == "button_icons" && $name == "text" ) {
  614. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  615. echo " <option value='auto'>".$text['option-button_icons_auto']."</option>\n";
  616. echo " <option value='only' ".($row['domain_setting_value'] == "only" ? "selected='selected'" : null).">".$text['option-button_icons_only']."</option>\n";
  617. echo " <option value='always' ".($row['domain_setting_value'] == "always" ? "selected='selected'" : null).">".$text['option-button_icons_always']."</option>\n";
  618. echo " <option value='never' ".($row['domain_setting_value'] == "never" ? "selected='selected'" : null).">".$text['option-button_icons_never']."</option>\n";
  619. echo " </select>\n";
  620. }
  621. elseif ($category == "voicemail" && $subcategory == "voicemail_file" && $name == "text" ) {
  622. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  623. echo " <option value='listen' ".(($row['domain_setting_value'] == "listen") ? "selected='selected'" : null).">".$text['option-voicemail_file_listen']."</option>\n";
  624. echo " <option value='link' ".(($row['domain_setting_value'] == "link") ? "selected='selected'" : null).">".$text['option-voicemail_file_link']."</option>\n";
  625. echo " <option value='attach' ".(($row['domain_setting_value'] == "attach") ? "selected='selected'" : null).">".$text['option-voicemail_file_attach']."</option>\n";
  626. echo " </select>\n";
  627. }
  628. elseif ($category == "voicemail" && $subcategory == "keep_local" && $name == "boolean" ) {
  629. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  630. echo " <option value='true' ".(($row['domain_setting_value'] == "true") ? "selected='selected'" : null).">".$text['label-true']."</option>\n";
  631. echo " <option value='false' ".(($row['domain_setting_value'] == "false") ? "selected='selected'" : null).">".$text['label-false']."</option>\n";
  632. echo " </select>\n";
  633. }
  634. elseif ($category == "recordings" && $subcategory == "storage_type" && $name == "text" ) {
  635. echo " <select class='formfld' id='domain_setting_value' name='domain_setting_value'>\n";
  636. echo " <option value='file'>".$text['label-file']."</option>\n";
  637. echo " <option value='base64' ".(($row['domain_setting_value'] == "base64") ? "selected='selected'" : null).">".$text['label-base64']."</option>\n";
  638. echo " </select>\n";
  639. }
  640. elseif (is_json($row['domain_setting_value'])) {
  641. echo " <textarea class='formfld' style='width: 100%; height: 80px; font-family: courier, monospace; overflow: auto;' id='domain_setting_value' name='domain_setting_value' wrap='off'>".$row['domain_setting_value']."</textarea>\n";
  642. }
  643. else {
  644. echo " <input class='formfld' type='text' id='domain_setting_value' name='domain_setting_value' value=\"".escape($row['domain_setting_value'])."\">\n";
  645. }
  646. echo "<br />\n";
  647. echo $text['description-value']."\n";
  648. if ($category == "theme" && substr_count($subcategory, "_font") > 0 && $name == "text") {
  649. echo "&nbsp;&nbsp;".$text['label-reference'].": <a href='https://www.google.com/fonts' target='_blank'>".$text['label-web_fonts']."</a>\n";
  650. }
  651. echo "</td>\n";
  652. echo "</tr>\n";
  653. echo "</table>\n";
  654. echo "<div id='tr_order' ".(($domain_setting_name != 'array') ? "style='display: none;'" : null).">\n";
  655. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  656. echo "<tr>\n";
  657. echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
  658. echo " ".$text['label-order']."\n";
  659. echo "</td>\n";
  660. echo "<td width='70%' class='vtable' align='left'>\n";
  661. echo " <select name='domain_setting_order' class='formfld'>\n";
  662. $i=0;
  663. while($i<=999) {
  664. $selected = ($i == $domain_setting_order) ? "selected" : null;
  665. if (strlen($i) == 1) {
  666. echo " <option value='00$i' ".$selected.">00$i</option>\n";
  667. }
  668. if (strlen($i) == 2) {
  669. echo " <option value='0$i' ".$selected.">0$i</option>\n";
  670. }
  671. if (strlen($i) == 3) {
  672. echo " <option value='$i' ".$selected.">$i</option>\n";
  673. }
  674. $i++;
  675. }
  676. echo " </select>\n";
  677. echo " <br />\n";
  678. echo $text['description-order']."\n";
  679. echo "</td>\n";
  680. echo "</tr>\n";
  681. echo "</table>\n";
  682. echo "</div>\n";
  683. echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  684. echo "<tr>\n";
  685. echo "<td width='30%' class='vncellreq' valign='top' align='left' nowrap>\n";
  686. echo " ".$text['label-enabled']."\n";
  687. echo "</td>\n";
  688. echo "<td width='70%' class='vtable' align='left'>\n";
  689. echo " <select class='formfld' name='domain_setting_enabled'>\n";
  690. if ($domain_setting_enabled == "true") {
  691. echo " <option value='true' selected='selected'>".$text['label-true']."</option>\n";
  692. }
  693. else {
  694. echo " <option value='true'>".$text['label-true']."</option>\n";
  695. }
  696. if ($domain_setting_enabled == "false") {
  697. echo " <option value='false' selected='selected'>".$text['label-false']."</option>\n";
  698. }
  699. else {
  700. echo " <option value='false'>".$text['label-false']."</option>\n";
  701. }
  702. echo " </select>\n";
  703. echo "<br />\n";
  704. echo $text['description-setting_enabled']."\n";
  705. echo "</td>\n";
  706. echo "</tr>\n";
  707. echo "<tr>\n";
  708. echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
  709. echo " ".$text['label-description']."\n";
  710. echo "</td>\n";
  711. echo "<td class='vtable' align='left'>\n";
  712. echo " <input class='formfld' type='text' name='domain_setting_description' maxlength='255' value=\"".escape($domain_setting_description)."\">\n";
  713. echo "<br />\n";
  714. echo $text['description-description']."\n";
  715. echo "</td>\n";
  716. echo "</tr>\n";
  717. echo "</table>";
  718. echo "<br /><br />";
  719. echo "<input type='hidden' name='domain_uuid' value='".escape($domain_uuid)."'>\n";
  720. if ($action == "update") {
  721. echo "<input type='hidden' name='domain_setting_uuid' value='".escape($domain_setting_uuid)."'>\n";
  722. }
  723. echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
  724. echo "</form>";
  725. echo "<script>\n";
  726. //capture enter key to submit form
  727. echo " $(window).on('keypress',function(event){\n";
  728. echo " if (event.which == 13) { submit_form(); }\n";
  729. echo " });\n";
  730. //hide/convert password fields then submit form
  731. echo " function submit_form() {\n";
  732. echo " $('input:password').css('visibility','hidden');\n";
  733. echo " $('input:password').attr({type:'text'});\n";
  734. echo " $('form#frm').submit();\n";
  735. echo " }\n";
  736. //define lowercase class
  737. echo " $('.lowercase').on('blur',function(){ this.value = this.value.toLowerCase(); });";
  738. //show order if array
  739. echo " $('#domain_setting_name').on('keyup',function(){ \n";
  740. echo " (this.value.toLowerCase() == 'array') ? $('#tr_order').slideDown('fast') : $('#tr_order').slideUp('fast');\n";
  741. echo " });\n";
  742. echo "</script>\n";
  743. //include the footer
  744. require_once "resources/footer.php";
  745. ?>