Portions created by the Initial Developer are Copyright (C) 2008-2015 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; 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 (isset($_REQUEST["id"])) { $action = "update"; $domain_setting_uuid = check_str($_REQUEST["id"]); } else { $action = "add"; } //set the domain_uuid if (strlen($_GET["domain_uuid"]) > 0) { $domain_uuid = check_str($_GET["domain_uuid"]); } //get http post variables and set them to php variables if (count($_POST) > 0) { $domain_setting_category = strtolower(check_str($_POST["domain_setting_category"])); $domain_setting_subcategory = strtolower(check_str($_POST["domain_setting_subcategory"])); $domain_setting_name = strtolower(check_str($_POST["domain_setting_name"])); $domain_setting_value = check_str($_POST["domain_setting_value"]); $domain_setting_order = check_str($_POST["domain_setting_order"]); $domain_setting_enabled = strtolower(check_str($_POST["domain_setting_enabled"])); $domain_setting_description = check_str($_POST["domain_setting_description"]); } if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { $domain_setting_uuid = check_str($_POST["domain_setting_uuid"]); } //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 * from v_dialplans "; $sql .= "where domain_uuid = '".$domain_uuid."' "; $sql .= "and app_uuid = '9f356fe7-8cf8-4c14-8fe2-6daf89304458' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as $row) { $dialplan_uuid = $row["dialplan_uuid"]; } unset ($prep_statement); //get the action $sql = "select * 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=%' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $detail_action = "add"; foreach ($result as $row) { $dialplan_detail_uuid = $row["dialplan_detail_uuid"]; $detail_action = "update"; } unset ($prep_statement); //update the timezone if ($detail_action == "update") { $sql = "update v_dialplan_details "; $sql .= "set dialplan_detail_data = 'timezone=".$domain_setting_value."' "; $sql .= "where dialplan_detail_uuid = '".$dialplan_detail_uuid."' "; } else { $dialplan_detail_uuid = uuid(); $dialplan_detail_group = 0; $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_inline, "; $sql .= "dialplan_detail_group "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'".$domain_uuid."', "; $sql .= "'".$dialplan_detail_uuid."', "; $sql .= "'".$dialplan_uuid."', "; $sql .= "'action', "; $sql .= "'set', "; $sql .= "'timezone=".$domain_setting_value."', "; $sql .= "'true', "; $sql .= "'".$dialplan_detail_group."' "; $sql .= "); "; } $db->query($sql); unset($sql); } //add the domain if ($action == "add" && permission_exists('domain_setting_add')) { $sql = "insert into v_domain_settings "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "domain_setting_uuid, "; $sql .= "domain_setting_category, "; $sql .= "domain_setting_subcategory, "; $sql .= "domain_setting_name, "; $sql .= "domain_setting_value, "; $sql .= "domain_setting_order, "; $sql .= "domain_setting_enabled, "; $sql .= "domain_setting_description "; $sql .= ")"; $sql .= "values "; $sql .= "("; $sql .= "'$domain_uuid', "; $sql .= "'".uuid()."', "; $sql .= "'$domain_setting_category', "; $sql .= "'$domain_setting_subcategory', "; $sql .= "'$domain_setting_name', "; $sql .= "'$domain_setting_value', "; $sql .= "$domain_setting_order, "; $sql .= "'$domain_setting_enabled', "; $sql .= "'$domain_setting_description' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //if ($action == "add") //update the domain if ($action == "update" && permission_exists('domain_setting_edit')) { $sql = "update v_domain_settings set "; $sql .= "domain_setting_category = '$domain_setting_category', "; $sql .= "domain_setting_subcategory = '$domain_setting_subcategory', "; $sql .= "domain_setting_name = '$domain_setting_name', "; $sql .= "domain_setting_value = '$domain_setting_value', "; $sql .= "domain_setting_order = $domain_setting_order, "; $sql .= "domain_setting_enabled = '$domain_setting_enabled', "; $sql .= "domain_setting_description = '$domain_setting_description' "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and domain_setting_uuid = '$domain_setting_uuid'"; $db->exec(check_sql($sql)); unset($sql); } //if ($action == "update") //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 = '".$_SESSION["domain_uuid"]."' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); $time_zone_found = false; 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 = '".$_SESSION["domain_uuid"]."' "; $sub_prep_statement = $db->prepare(check_sql($sql)); $sub_prep_statement->execute(); $sub_result = $sub_prep_statement->fetchAll(PDO::FETCH_NAMED); 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; } } } //add the time zone if (!$time_zone_found) { //$dialplan_detail_uuid = uuid(); $dialplan_detail_uuid = "eb3b3a4e-88ea-4306-b2a8-9f52d3c95f2f"; $sql = "insert into v_dialplan_details "; $sql .= "("; $sql .= "domain_uuid, "; $sql .= "dialplan_uuid, "; $sql .= "dialplan_detail_uuid, "; $sql .= "dialplan_detail_tag, "; $sql .= "dialplan_detail_type, "; $sql .= "dialplan_detail_data, "; $sql .= "dialplan_detail_group, "; $sql .= "dialplan_detail_order "; $sql .= ") "; $sql .= "values "; $sql .= "("; $sql .= "'".$_SESSION["domain_uuid"]."', "; //8cfd9525-6ccf-4c2c-813a-bca5809067cd $sql .= "'$dialplan_uuid', "; //807b4aa6-4478-4663-a661-779397c1d542 $sql .= "'$dialplan_detail_uuid', "; $sql .= "'action', "; $sql .= "'set', "; $sql .= "'timezone=$domain_setting_value', "; if (strlen($dialplan_detail_group) > 0) { $sql .= "'$dialplan_detail_group', "; } else { $sql .= "null, "; } $sql .= "'15' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); } //update the time zone if ($time_zone_found) { $sql = "update v_dialplan_details set "; $sql .= "dialplan_detail_data = 'timezone=".$domain_setting_value."' "; $sql .= "where domain_uuid = '".$_SESSION["domain_uuid"]."' "; $sql .= "and dialplan_uuid = '$dialplan_uuid' "; $sql .= "and dialplan_detail_uuid = '$dialplan_detail_uuid' "; $db->exec(check_sql($sql)); unset($sql); } } } //redirect the browser if ($action == "update") { $_SESSION["message"] = $text['message-update']; } if ($action == "add") { $_SESSION["message"] = $text['message-add']; } header("Location: domain_edit.php?id=".$domain_uuid); return; } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET)>0 && $_POST["persistformvar"] != "true") { $domain_setting_uuid = check_str($_GET["id"]); $sql = "select * from v_domain_settings "; $sql .= "where domain_uuid = '$domain_uuid' "; $sql .= "and domain_setting_uuid = '$domain_setting_uuid' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $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"]; break; //limit to 1 row } unset ($prep_statement); } //show the header require_once "resources/header.php"; if ($action == "update") { $document['title'] = $text['title-domain_setting-edit']; } elseif ($action == "add") { $document['title'] = $text['title-domain_setting-add']; } //show the content 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 "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
"; if ($action == "update") { echo $text['header-domain_setting-edit']; } if ($action == "add") { echo $text['header-domain_setting-add']; } echo ""; echo " "; echo " \n"; echo "
\n"; if ($action == "update") { echo $text['description-domain_setting-edit']; } if ($action == "add") { echo $text['description-domain_setting-add']; } echo "

\n"; echo "
\n"; echo " ".$text['label-category']."\n"; echo "\n"; if (permission_exists('domain_setting_category_edit')) { 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" && $subcategory == "body_color" && $name == "text" || $category == "theme" && $subcategory == "body_shadow_color" && $name == "text" || $category == "theme" && $subcategory == "background_color" && $name == "array" || $category == "theme" && $subcategory == "login_shadow_color" && $name == "text" || $category == "theme" && $subcategory == "login_background_color" && $name == "text" || $category == "theme" && $subcategory == "domain_color" && $name == "text" || $category == "theme" && $subcategory == "domain_shadow_color" && $name == "text" || $category == "theme" && $subcategory == "domain_background_color" && $name == "text" || $category == "theme" && $subcategory == "domain_selector_shadow_color" && $name == "text" || $category == "theme" && $subcategory == "footer_color" && $name == "text" || $category == "theme" && $subcategory == "footer_background_color" && $name == "text" || $category == "theme" && $subcategory == "message_default_background_color" && $name == "text" || $category == "theme" && $subcategory == "message_default_color" && $name == "text" || $category == "theme" && $subcategory == "message_negative_background_color" && $name == "text" || $category == "theme" && $subcategory == "message_negative_color" && $name == "text" || $category == "theme" && $subcategory == "message_alert_background_color" && $name == "text" || $category == "theme" && $subcategory == "message_alert_color" && $name == "text" || $category == "theme" && $subcategory == "menu_main_background_color" && $name == "text" || $category == "theme" && $subcategory == "menu_main_text_color" && $name == "text" || $category == "theme" && $subcategory == "menu_main_text_color_hover" && $name == "text" || $category == "theme" && $subcategory == "menu_main_shadow_color" && $name == "text" || $category == "theme" && $subcategory == "menu_sub_background_color" && $name == "text" || $category == "theme" && $subcategory == "menu_sub_background_color_hover" && $name == "text" || $category == "theme" && $subcategory == "menu_sub_text_color" && $name == "text" || $category == "theme" && $subcategory == "menu_sub_text_color_hover" && $name == "text" || $category == "theme" && $subcategory == "menu_sub_shadow_color" && $name == "text" || $category == "theme" && $subcategory == "menu_brand_text_color" && $name == "text" || $category == "theme" && $subcategory == "menu_brand_text_color_hover" && $name == "text" ) { echo " \n"; } elseif ($category == "fax" && $subcategory == "page_size" && $name == "text" ) { echo " "; } elseif ($category == "fax" && $subcategory == "resolution" && $name == "text" ) { echo " "; } elseif ($category == "theme" && $subcategory == "domain_visible" && $name == "text" ) { echo " \n"; } elseif ($category == "theme" && $subcategory == "cache" && $name == "boolean" ) { echo " \n"; } elseif ($category == "theme" && $subcategory == "menu_brand_type" && $name == "text" ) { echo " \n"; } else { echo " \n"; } echo "
\n"; echo $text['description-value']."\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 " \n"; echo " "; 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 "
\n"; echo " \n"; if ($action == "update") { echo " \n"; } echo "
"; echo " \n"; echo "
"; echo "
"; echo "
"; echo "\n"; //include the footer require_once "resources/footer.php"; ?>