Portions created by the Initial Developer are Copyright (C) 2008-2012 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 require_once "app_languages.php"; foreach($text['button-save'] as $key => $value) { $languages[$key] = ''; } foreach($text as $key => $value) { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } //action add or update if (isset($_REQUEST["id"])) { $action = "update"; $domain_setting_uuid = check_str($_REQUEST["id"]); } else { $action = "add"; } 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 data //if (strlen($domain_setting_category) == 0) { $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") { $domain_setting_order = ($domain_setting_order != '') ? $domain_setting_order : 'null'; //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 "
"; echo "\n"; echo "\n"; echo " "; echo " "; echo "
\n"; echo "
"; 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 "\n"; if ($name == "array") { 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 " "; 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['header-domain_setting-add']; } echo "

\n"; echo "
\n"; echo " ".$text['label-category'].":\n"; echo "\n"; echo " \n"; 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 == "email" && $subcategory == "smtp_password" && $name == "var" ) { echo " \n"; } elseif ($category == "provision" && $subcategory == "password" && $name == "var" ) { echo " \n"; } elseif ($category == "theme" && $subcategory == "background_color" && $name == "array") { // source: http://rightjs.org echo " "; echo " "; echo " "; echo " \n"; echo " "; } else { echo " \n"; } echo "
\n"; echo $text['description-value']."\n"; echo "
\n"; echo " ".$text['label-order']."\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-order']."\n"; echo "
\n"; echo " ".$text['label-enabled'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-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 " \n"; echo "
"; echo ""; echo "
"; echo "
"; //include the footer require_once "resources/footer.php"; ?>