Portions created by the Initial Developer are Copyright (C) 2008-2017 the Initial Developer. All Rights Reserved. Contributor(s): Matthew Vale */ //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; require_once "resources/paging.php"; //check permissions if (permission_exists('number_translation_add') || permission_exists('number_translation_edit') ) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //set the action as an add or an update if (is_uuid($_REQUEST["id"])) { $action = "update"; $number_translation_uuid = $_REQUEST["id"]; } else { $action = "add"; } if (strlen($_REQUEST["app_uuid"]) > 0) { $app_uuid = $_REQUEST["app_uuid"]; } //get the http post values and set them as php variables if (count($_POST) > 0) { $hostname = check_str($_POST["hostname"]); $number_translation_name = check_str($_POST["number_translation_name"]); $number_translation_enabled = check_str($_POST["number_translation_enabled"]); $number_translation_description = check_str($_POST["number_translation_description"]); } //process and save the data if (count($_POST) > 0 && strlen($_POST["persistformvar"]) == 0) { //get the number_translation uuid if ($action == "update") { $number_translation_uuid = check_str($_POST["number_translation_uuid"]); } //check for all required data $msg = ''; if (strlen($number_translation_name) == 0) { $msg .= $text['message-required'].$text['label-name']."
\n"; } if (strlen($number_translation_enabled) == 0) { $msg .= $text['message-required'].$text['label-enabled']."
\n"; } //if (strlen($number_translation_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; } //remove the invalid characters from the number_translation name $number_translation_name = $_POST["number_translation_name"]; $number_translation_name = str_replace(" ", "_", $number_translation_name); $number_translation_name = str_replace("/", "", $number_translation_name); //build the array $x = 0; if (isset($_POST["number_translation_uuid"])) { $array['number_translations'][$x]['number_translation_uuid'] = $_POST["number_translation_uuid"]; } $array['number_translations'][$x]['number_translation_name'] = $number_translation_name; $array['number_translations'][$x]['number_translation_enabled'] = $_POST["number_translation_enabled"]; $array['number_translations'][$x]['number_translation_description'] = $_POST["number_translation_description"]; $y = 0; if (is_array($_POST["number_translation_details"])) { foreach ($_POST["number_translation_details"] as $row) { if (strlen($row["number_translation_detail_regex"]) > 0) { if (strlen($row["number_translation_detail_uuid"]) > 0) { $array['number_translations'][$x]['number_translation_details'][$y]['number_translation_detail_uuid'] = $row["number_translation_detail_uuid"]; }else{ $array['number_translations'][$x]['number_translation_details'][$y]['number_translation_uuid'] = $_POST["number_translation_uuid"]; } $array['number_translations'][$x]['number_translation_details'][$y]['number_translation_detail_regex'] = $row["number_translation_detail_regex"]; $array['number_translations'][$x]['number_translation_details'][$y]['number_translation_detail_replace'] = $row["number_translation_detail_replace"]; $array['number_translations'][$x]['number_translation_details'][$y]['number_translation_detail_order'] = $row["number_translation_detail_order"]; } $y++; } } //add or update the database if ($_POST["persistformvar"] != "true") { $permissions = new permissions; $permissions->add('number_translation_detail_add', 'temp'); $permissions->add('number_translation_detail_edit', 'temp'); $database = new database; $database->app_name = 'number_translations'; $database->save($array); $permissions->delete('number_translation_detail_add', 'temp'); $permissions->delete('number_translation_detail_edit', 'temp'); if ($database->message['code'] != '200'){ messages::add('Failed to update record(s), database reported:'.$database->message['message'], 'negative'); header("Location: ?id=$number_translation_uuid"); exit; } } //update the number_translation xml $number_translations = new number_translation; $number_translations->xml(); //set the message if ($action == "add") { messages::add($text['message-add']); } else if ($action == "update") { messages::add($text['message-update']); } header("Location: ?id=$number_translation_uuid"); exit; } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET) > 0 && $_POST["persistformvar"] != "true") { $sql = "select * from v_number_translations "; $sql .= "where number_translation_uuid = '$number_translation_uuid' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); if (is_array($result)) foreach ($result as &$row) { $domain_uuid = $row["domain_uuid"]; //$app_uuid = $row["app_uuid"]; $hostname = $row["hostname"]; $number_translation_name = $row["number_translation_name"]; $number_translation_enabled = $row["number_translation_enabled"]; $number_translation_description = $row["number_translation_description"]; } unset ($prep_statement); } //get the number_translation details in an array $sql = "select * from v_number_translation_details "; $sql .= "where number_translation_uuid = '$number_translation_uuid' "; $sql .= "order by number_translation_detail_order asc"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $results = $prep_statement->fetchAll(PDO::FETCH_NAMED); $results_count = count($result); unset ($prep_statement, $sql); //show the header require_once "resources/header.php"; $document['title'] = $text['title-number_translation_edit']; //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" ".$text['title-number_translation_edit']."
\n"; echo "
\n"; echo " 0) ? "?app_uuid=".$app_uuid : null)."';\" value='".$text['button-back']."'>\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['description-number_translation-edit']."\n"; echo " \n"; echo "
"; echo "
\n"; echo "\n"; echo "\n"; echo ""; echo ""; echo ""; 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-name']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['label-hostname']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['description-hostname']."\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['label-description']."\n"; echo " \n"; echo " \n"; echo "
\n"; echo "
"; echo "

"; //number_translation details if ($action == "update") { ?> 0) { echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $x=0; $results[]['number_translation_uuid'] = $number_translation_uuid; foreach($results as $index => $row) { //get the values from the database and set as variables $number_translation_detail_uuid = $row['number_translation_detail_uuid']; $number_translation_detail_regex = $row['number_translation_detail_regex']; $number_translation_detail_replace = $row['number_translation_detail_replace']; $number_translation_detail_order = (strlen($row['number_translation_detail_order']) > 0 ? $row['number_translation_detail_order'] : $number_translation_detail_order + 5 ); //no border on last row $no_border = (strlen($number_translation_detail_uuid) == 0) ? "border: none;" : null; //begin the row echo "\n"; //determine whether to hide the element if (strlen($number_translation_detail_regex) == 0) { $element['hidden'] = false; $element['visibility'] = ""; } else { $element['hidden'] = true; $element['visibility'] = "display: none;"; } //add the primary key uuid if (strlen($number_translation_detail_uuid) > 0) { echo " \n"; } //regex echo "\n"; //replace echo "\n"; //order echo "\n"; //tools echo " \n"; //end the row echo "\n"; //increment the value $x++; } unset($sql, $result, $row_count); echo "
".$text['label-regex']."".$text['label-replace']."".$text['label-order']." 
\n"; if ($element['hidden']) { echo " \n"; } echo " \n"; echo "\n"; if ($element['hidden']) { echo " \n"; } echo " \n"; echo "\n"; if ($element['hidden']) { echo " \n"; } echo " \n"; echo "\n"; if ($element['hidden']) { //echo " $v_link_label_edit\n"; echo " $v_link_label_delete\n"; } echo "
"; } //end if results } //end if update echo "
\n"; echo "
\n"; if ($action == "update") { echo " \n"; } echo " \n"; echo "
\n"; echo "

\n"; echo "
"; if (file_exists($_SERVER["PROJECT_ROOT"]."/app/billing/app_config.php")){ echo "

".$text['billing-warning']."

"; } //show the footer require_once "resources/footer.php"; ?>