Portions created by the Initial Developer are Copyright (C) 2008-2020 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('domain_setting_add') || permission_exists('domain_setting_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //retrieve allowed setting categories if (!permission_exists('domain_setting_category_edit')) { if (is_array($_SESSION['settings']) && sizeof($_SESSION['settings']) > 0) { foreach ($_SESSION['groups'] as $index => $group) { $group_name = $group['group_name']; if (is_array($_SESSION['settings'][$group_name]) && sizeof($_SESSION['settings'][$group_name]) > 0) { foreach ($_SESSION['settings'][$group_name] as $category) { $categories[] = strtolower($category); } } } } if (is_array($categories) && sizeof($categories) > 0) { $allowed_categories = array_unique($categories); sort($allowed_categories, SORT_NATURAL); } unset($group, $group_name, $index, $category, $categories); } //action add or update if (is_uuid($_REQUEST["id"])) { $action = "update"; $domain_setting_uuid = $_REQUEST["id"]; } else { $action = "add"; } //set the domain_uuid if (is_uuid($_GET["domain_uuid"])) { $domain_uuid = $_GET["domain_uuid"]; } //get http post variables and set them to php variables if (count($_POST) > 0) { $domain_setting_category = strtolower($_POST["domain_setting_category"]); $domain_setting_subcategory = strtolower($_POST["domain_setting_subcategory"]); $domain_setting_name = strtolower($_POST["domain_setting_name"]); $domain_setting_value = $_POST["domain_setting_value"]; $domain_setting_order = $_POST["domain_setting_order"]; $domain_setting_enabled = strtolower($_POST["domain_setting_enabled"]); $domain_setting_description = $_POST["domain_setting_description"]; } if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { $domain_setting_uuid = $_POST["domain_setting_uuid"]; } //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: ../domains/domain_edit.php?id='.$domain_uuid); exit; } //check for all required/authorized data 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']."
\n"; } if (strlen($domain_setting_subcategory) == 0) { $msg .= $text['message-required'].$text['label-subcategory']."
\n"; } if (strlen($domain_setting_name) == 0) { $msg .= $text['message-required'].$text['label-type']."
\n"; } //if (strlen($domain_setting_value) == 0) { $msg .= $text['message-required'].$text['label-value']."
\n"; } if (strlen($domain_setting_order) == 0) { $msg .= $text['message-required'].$text['label-order']."
\n"; } if (strlen($domain_setting_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."
\n"; } //if (strlen($domain_setting_description) == 0) { $msg .= $text['message-required'].$text['label-description']."
\n"; } if (strlen($msg) > 0 && strlen($_POST["persistformvar"]) == 0) { require_once "resources/header.php"; require_once "resources/persist_form_var.php"; echo "
\n"; echo "
\n"; echo $msg."
"; echo "
\n"; persistformvar($_POST); echo "
\n"; require_once "resources/footer.php"; return; } //add or update the database if ($_POST["persistformvar"] != "true") { // fix null $domain_setting_order = $domain_setting_order != '' ? $domain_setting_order : 'null'; //update switch timezone variables if ($domain_setting_category == "domain" && $domain_setting_subcategory == "time_zone" && $domain_setting_name == "name" ) { //get the dialplan_uuid $sql = "select dialplan_uuid from v_dialplans "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and app_uuid = '9f356fe7-8cf8-4c14-8fe2-6daf89304458' "; $parameters['domain_uuid'] = $domain_uuid; $database = new database; $dialplan_uuid = $database->select($sql, $parameters, 'column'); unset($sql, $parameters); //get the action $sql = "select dialplan_detail_uuid from v_dialplan_details "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and dialplan_uuid = :dialplan_uuid "; $sql .= "and dialplan_detail_tag = 'action' "; $sql .= "and dialplan_detail_type = 'set' "; $sql .= "and dialplan_detail_data like 'timezone=%' "; $parameters['domain_uuid'] = $domain_uuid; $parameters['dialplan_uuid'] = $dialplan_uuid; $database = new database; $dialplan_detail_uuid = $database->select($sql, $parameters, 'column'); $detail_action = is_uuid($dialplan_detail_uuid) ? 'update' : 'add'; unset($sql, $parameters); //update the timezone $p = new permissions; if ($detail_action == "update") { $array['dialplan_details'][0]['dialplan_detail_uuid'] = $dialplan_detail_uuid; $array['dialplan_details'][0]['dialplan_detail_data'] = 'timezone='.$domain_setting_value; $p->add('dialplan_detail_edit', 'temp'); } else { $array['dialplan_details'][0]['dialplan_detail_uuid'] = uuid(); $array['dialplan_details'][0]['domain_uuid'] = $domain_uuid; $array['dialplan_details'][0]['dialplan_uuid'] = $dialplan_uuid; $array['dialplan_details'][0]['dialplan_detail_tag'] = 'action'; $array['dialplan_details'][0]['dialplan_detail_type'] = 'set'; $array['dialplan_details'][0]['dialplan_detail_data'] = 'timezone='.$domain_setting_value; $array['dialplan_details'][0]['dialplan_detail_inline'] = 'true'; $array['dialplan_details'][0]['dialplan_detail_group'] = '0'; $p->add('dialplan_detail_add', 'temp'); } if (is_array($array) && sizeof($array) != 0) { $database = new database; $database->app_name = 'domain_settings'; $database->app_uuid = 'b31e723a-bf70-670c-a49b-470d2a232f71'; $database->save($array); unset($array); $p->delete('dialplan_detail_edit', 'temp'); $p->delete('dialplan_detail_add', 'temp'); } //get the dialplan uuid $sql = "select domain_name from v_domains "; $sql .= "where domain_uuid = :domain_uuid "; $parameters['domain_uuid'] = $domain_uuid; $database = new database; $domain_name = $database->select($sql, $parameters, 'column'); unset($sql, $parameters); //update the dialplan xml $dialplans = new dialplan; $dialplans->source = "details"; $dialplans->destination = "database"; $dialplans->uuid = $dialplan_uuid; $dialplans->xml(); //clear the cache $cache = new cache; $cache->delete("dialplan:".$domain_name); } //add if ($action == "add" && permission_exists('domain_setting_add')) { $array['domain_settings'][0]['domain_setting_uuid'] = uuid(); } //update if ($action == "update" && permission_exists('domain_setting_edit')) { $array['domain_settings'][0]['domain_setting_uuid'] = $domain_setting_uuid; } //execute if (is_uuid($array['domain_settings'][0]['domain_setting_uuid'])) { $array['domain_settings'][0]['domain_uuid'] = $domain_uuid; $array['domain_settings'][0]['domain_setting_category'] = $domain_setting_category; $array['domain_settings'][0]['domain_setting_subcategory'] = $domain_setting_subcategory; $array['domain_settings'][0]['domain_setting_name'] = $domain_setting_name; $array['domain_settings'][0]['domain_setting_value'] = $domain_setting_value; $array['domain_settings'][0]['domain_setting_order'] = $domain_setting_order; $array['domain_settings'][0]['domain_setting_enabled'] = $domain_setting_enabled; $array['domain_settings'][0]['domain_setting_description'] = $domain_setting_description; $database = new database; $database->app_name = 'domain_settings'; $database->app_uuid = 'b31e723a-bf70-670c-a49b-470d2a232f71'; $database->save($array); unset($array); } //update time zone if ($domain_setting_category == "domain" && $domain_setting_subcategory == "time_zone" && $domain_setting_name == "name" && strlen($domain_setting_value) > 0 ) { $sql = "select * from v_dialplans "; $sql .= "where app_uuid = '34dd307b-fffe-4ead-990c-3d070e288126' "; $sql .= "and domain_uuid = :domain_uuid "; $parameters['domain_uuid'] = $_SESSION["domain_uuid"]; $database = new database; $result = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); $time_zone_found = false; if (is_array($result) && sizeof($result) != 0) { foreach ($result as &$row) { //get the dialplan_uuid $dialplan_uuid = $row["dialplan_uuid"]; //get the dialplan details $sql = "select * from v_dialplan_details "; $sql .= "where dialplan_uuid = :dialplan_uuid "; $sql .= "and domain_uuid = :domain_uuid "; $parameters['dialplan_uuid'] = $dialplan_uuid; $parameters['domain_uuid'] = $_SESSION["domain_uuid"]; $database = new database; $sub_result = $database->select($sql, $parameters, 'all'); if (is_array($sub_result) && sizeof($sub_result) != 0) { foreach ($sub_result as $field) { $dialplan_detail_uuid = $field["dialplan_detail_uuid"]; $dialplan_detail_tag = $field["dialplan_detail_tag"]; //action //condition $dialplan_detail_type = $field["dialplan_detail_type"]; //set $dialplan_detail_data = $field["dialplan_detail_data"]; $dialplan_detail_group = $field["dialplan_detail_group"]; if ($dialplan_detail_tag == "action" && $dialplan_detail_type == "set") { $data_array = explode("=", $dialplan_detail_data); if ($data_array[0] == "timezone") { $time_zone_found = true; break; } } } } unset($sql, $parameters, $sub_result, $field); //add the time zone if (!$time_zone_found) { $dialplan_detail_uuid = "eb3b3a4e-88ea-4306-b2a8-9f52d3c95f2f"; $array['dialplan_details'][0]['domain_uuid'] = $_SESSION["domain_uuid"]; //8cfd9525-6ccf-4c2c-813a-bca5809067cd $array['dialplan_details'][0]['dialplan_uuid'] = $dialplan_uuid; //807b4aa6-4478-4663-a661-779397c1d542 $array['dialplan_details'][0]['dialplan_detail_uuid'] = $dialplan_detail_uuid; $array['dialplan_details'][0]['dialplan_detail_tag'] = 'action'; $array['dialplan_details'][0]['dialplan_detail_type'] = 'set'; $array['dialplan_details'][0]['dialplan_detail_data'] = 'timezone='.$domain_setting_value; $array['dialplan_details'][0]['dialplan_detail_group'] = $dialplan_detail_group; $array['dialplan_details'][0]['dialplan_detail_order'] = '15'; $p = new permissions; $p->add('dialplan_detail_add', 'temp'); } //update the time zone if ($time_zone_found) { $array['dialplan_details'][0]['dialplan_detail_uuid'] = $dialplan_detail_uuid; $array['dialplan_details'][0]['dialplan_detail_data'] = 'timezone='.$domain_setting_value; $p = new permissions; $p->add('dialplan_detail_edit', 'temp'); } //execute if (is_array($array) && sizeof($array) != 0) { $database = new database; $database->app_name = 'domain_settings'; $database->app_uuid = 'b31e723a-bf70-670c-a49b-470d2a232f71'; $database->save($array); unset($array); $p->delete('dialplan_detail_add', 'temp'); $p->delete('dialplan_detail_edit', 'temp'); } } } } //redirect the browser if ($action == "update") { message::add($text['message-update']); } if ($action == "add") { message::add($text['message-add']); } header("Location: ".PROJECT_PATH."/core/domains/domain_edit.php?id=".$domain_uuid); exit; } } //pre-populate the form if (count($_GET)>0 && $_POST["persistformvar"] != "true" && is_uuid($_GET["id"])) { $domain_setting_uuid = $_GET["id"]; $sql = "select * from v_domain_settings "; $sql .= "where domain_uuid = :domain_uuid "; $sql .= "and domain_setting_uuid = :domain_setting_uuid "; $parameters['domain_uuid'] = $domain_uuid; $parameters['domain_setting_uuid'] = $domain_setting_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && sizeof($row) != 0) { $domain_setting_category = $row["domain_setting_category"]; $domain_setting_subcategory = $row["domain_setting_subcategory"]; $domain_setting_name = $row["domain_setting_name"]; $domain_setting_value = $row["domain_setting_value"]; $domain_setting_order = $row["domain_setting_order"]; $domain_setting_enabled = $row["domain_setting_enabled"]; $domain_setting_description = $row["domain_setting_description"]; } unset($sql, $parameters); } //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //include the header if ($action == "update") { $document['title'] = $text['title-domain_setting-edit']; } elseif ($action == "add") { $document['title'] = $text['title-domain_setting-add']; } require_once "resources/header.php"; //show the content echo "
\n"; echo "
\n"; echo "
"; if ($action == "update") { echo "".$text['header-domain_setting-edit'].""; } if ($action == "add") { echo "".$text['header-domain_setting-add'].""; } echo "
\n"; echo "
\n"; 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)]); echo button::create(['type'=>'button','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'onclick'=>'submit_form();']); echo "
\n"; echo "
\n"; echo "
\n"; if ($action == "update") { echo $text['description-domain_setting-edit']."\n"; } if ($action == "add") { echo $text['description-domain_setting-add']."\n"; } echo "

\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo " ".$text['label-category']."\n"; echo "\n"; if (permission_exists('domain_setting_category_edit')) { if ($action == 'add') { $domain_setting_category = $_GET['domain_setting_category']; } echo " \n"; } else { echo " "; } echo "
\n"; echo $text['description-category']."\n"; echo "
\n"; echo " ".$text['label-subcategory']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-subcategory']."\n"; echo "
\n"; echo " ".$text['label-type']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-type']."\n"; echo "
\n"; echo " ".$text['label-value']."\n"; echo "\n"; $category = $row['domain_setting_category']; $subcategory = $row['domain_setting_subcategory']; $name = $row['domain_setting_name']; if ($category == "domain" && $subcategory == "menu" && $name == "uuid" ) { echo " \n"; } elseif ($category == "domain" && $subcategory == "template" && $name == "name" ) { echo " \n"; } elseif ($category == "domain" && $subcategory == "language" && $name == "code" ) { echo " \n"; } elseif ($category == "domain" && $subcategory == "time_zone" && $name == "name" ) { echo " \n"; } elseif ($category == "domain" && $subcategory == "time_format" && $name == "text" ) { echo " \n"; } elseif ($subcategory == 'password' || substr_count($subcategory, '_password') > 0 || $category == "login" && $subcategory == "password_reset_key" && $name == "text") { echo " \n"; } elseif ($category == "theme" && substr_count($subcategory, "_color") > 0 && ($name == "text" || $name == 'array')) { echo " \n"; } elseif ($category == "theme" && substr_count($subcategory, "_font") > 0 && $name == "text") { $row['domain_setting_value'] = str_replace('"', "'", $row['domain_setting_value']); if ($fonts = get_available_fonts('alpha')) { echo " "; echo " \n"; } else { echo " \n"; } } elseif ($category == "fax" && $subcategory == "page_size" && $name == "text" ) { echo " "; } elseif ($category == "fax" && $subcategory == "resolution" && $name == "text" ) { echo " "; } elseif ($category == "provision" && $subcategory == "aastra_time_format" && $name == "text" ) { echo " \n"; } elseif ($category == "provision" && $subcategory == "aastra_date_format" && $name == "text" ) { echo " \n"; } elseif ($category == "theme" && $subcategory == "domain_visible" && $name == "text" ) { echo " \n"; } elseif ($category == "theme" && $subcategory == "cache" && $name == "boolean" ) { echo " \n"; } elseif ( ($category == "theme" && $subcategory == "menu_main_icons" && $name == "boolean") || ($category == "theme" && $subcategory == "menu_sub_icons" && $name == "boolean") ) { echo " \n"; } elseif ($category == "theme" && $subcategory == "menu_brand_type" && $name == "text" ) { echo " \n"; } elseif ($category == "theme" && $subcategory == "menu_style" && $name == "text" ) { echo " \n"; } elseif ($category == "theme" && $subcategory == "menu_position" && $name == "text" ) { echo " \n"; } elseif ($category == "theme" && $subcategory == "logo_align" && $name == "text" ) { echo " \n"; } elseif ($category == "theme" && $subcategory == "custom_css_code" && $name == "text" ) { echo " \n"; } elseif ($category == "theme" && $subcategory == "button_icons" && $name == "text" ) { echo " \n"; } elseif ($category == "voicemail" && $subcategory == "voicemail_file" && $name == "text" ) { echo " \n"; } elseif ($category == "voicemail" && $subcategory == "keep_local" && $name == "boolean" ) { echo " \n"; } elseif ($category == "recordings" && $subcategory == "storage_type" && $name == "text" ) { echo " \n"; } elseif (is_json($row['domain_setting_value'])) { echo " \n"; } else { echo " \n"; } echo "
\n"; echo $text['description-value']."\n"; if ($category == "theme" && substr_count($subcategory, "_font") > 0 && $name == "text") { echo "  ".$text['label-reference'].": ".$text['label-web_fonts']."\n"; } echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo " ".$text['label-order']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-order']."\n"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
\n"; echo " ".$text['label-enabled']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-setting_enabled']."\n"; echo "
\n"; echo " ".$text['label-description']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-description']."\n"; echo "
"; echo "

"; echo "\n"; if ($action == "update") { echo "\n"; } echo "\n"; echo "
"; echo "\n"; //include the footer require_once "resources/footer.php"; ?>