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('database_add') || permission_exists('database_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support require_once "app_languages.php"; foreach($text as $key => $value) { $text[$key] = $value[$_SESSION['domain']['language']['code']]; } //action add or update if (isset($_REQUEST["id"])) { $action = "update"; $database_uuid = check_str($_REQUEST["id"]); } else { $action = "add"; } //clear the values $database_driver = ''; $database_type = ''; $database_host = ''; $database_port = ''; $database_name = ''; $database_username = ''; $database_password = ''; $database_path = ''; $database_description = ''; //get http post variables and set them to php variables if (count($_POST)>0) { $database_driver = check_str($_POST["database_driver"]); $database_type = check_str($_POST["database_type"]); $database_host = check_str($_POST["database_host"]); $database_port = check_str($_POST["database_port"]); $database_name = check_str($_POST["database_name"]); $database_username = check_str($_POST["database_username"]); $database_password = check_str($_POST["database_password"]); $database_path = check_str($_POST["database_path"]); $database_description = check_str($_POST["database_description"]); } if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { $database_uuid = check_str($_POST["database_uuid"]); } //check for all required data //if (strlen($database_driver) == 0) { $msg .= $text['message-required'].$text['label-driver']."
\n"; } //if (strlen($database_type) == 0) { $msg .= $text['message-required'].$text['label-type']."
\n"; } //if (strlen($database_host) == 0) { $msg .= $text['message-required'].$text['label-host']."
\n"; } //if (strlen($database_port) == 0) { $msg .= $text['message-required'].$text['label-port']."
\n"; } //if (strlen($database_name) == 0) { $msg .= $text['message-required'].$text['label-name']."
\n"; } //if (strlen($database_username) == 0) { $msg .= $text['message-required'].$text['label-username']."
\n"; } //if (strlen($database_password) == 0) { $msg .= $text['message-required'].$text['label-password']."
\n"; } //if (strlen($database_path) == 0) { $msg .= $text['message-required'].$text['label-path']."
\n"; } //if (strlen($database_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") { if ($action == "add") { //add the data $database_uuid = uuid(); $sql = "insert into v_databases "; $sql .= "("; //$sql .= "domain_uuid, "; $sql .= "database_uuid, "; $sql .= "database_driver, "; $sql .= "database_type, "; $sql .= "database_host, "; $sql .= "database_port, "; $sql .= "database_name, "; $sql .= "database_username, "; $sql .= "database_password, "; $sql .= "database_path, "; $sql .= "database_description "; $sql .= ")"; $sql .= "values "; $sql .= "("; //$sql .= "'$domain_uuid', "; $sql .= "'$database_uuid', "; $sql .= "'$database_driver', "; $sql .= "'$database_type', "; $sql .= "'$database_host', "; $sql .= "'$database_port', "; $sql .= "'$database_name', "; $sql .= "'$database_username', "; $sql .= "'$database_password', "; $sql .= "'$database_path', "; $sql .= "'$database_description' "; $sql .= ")"; $db->exec(check_sql($sql)); unset($sql); //set the defaults require_once "app_defaults.php"; //redirect the browser require_once "resources/header.php"; echo "\n"; echo "
\n"; echo $text['message-add']."\n"; echo "
\n"; require_once "resources/footer.php"; return; } //if ($action == "add") if ($action == "update") { //udpate the database $sql = "update v_databases set "; $sql .= "database_type = '$database_type', "; $sql .= "database_driver = '$database_driver', "; $sql .= "database_host = '$database_host', "; $sql .= "database_port = '$database_port', "; $sql .= "database_name = '$database_name', "; $sql .= "database_username = '$database_username', "; $sql .= "database_password = '$database_password', "; $sql .= "database_path = '$database_path', "; $sql .= "database_description = '$database_description' "; $sql .= "where database_uuid = '$database_uuid' "; $db->exec(check_sql($sql)); unset($sql); //set the defaults $domains_processed = 1; require_once "app_defaults.php"; //redirect the browser require_once "resources/header.php"; echo "\n"; echo "
\n"; echo $text['message-update']."\n"; echo "
\n"; require_once "resources/footer.php"; return; } //if ($action == "update") } //if ($_POST["persistformvar"] != "true") } //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) //pre-populate the form if (count($_GET)>0 && $_POST["persistformvar"] != "true") { $database_uuid = $_GET["id"]; $sql = "select * from v_databases "; $sql .= "where database_uuid = '$database_uuid' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); foreach ($result as &$row) { $database_driver = $row["database_driver"]; $database_type = $row["database_type"]; $database_host = $row["database_host"]; $database_port = $row["database_port"]; $database_name = $row["database_name"]; $database_username = $row["database_username"]; $database_password = $row["database_password"]; $database_path = $row["database_path"]; $database_description = $row["database_description"]; break; //limit to 1 row } unset ($prep_statement); } //show the header require_once "resources/header.php"; if ($action == "update") { $page["title"] = $text['title-database-edit']; } if ($action == "add") { $page["title"] = $text['title-database-add']; } //show the content echo "
"; echo "\n"; echo "\n"; echo " "; echo " "; echo "
\n"; echo "
"; echo "
\n"; echo "
\n"; echo "\n"; echo "\n"; if ($action == "add") { echo "\n"; } if ($action == "update") { 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"; 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 " "; echo "
".$text['header-database-add']."".$text['header-database-edit']."
\n"; if ($action == "add") { echo $text['description-database-add']; } if ($action == "update") { echo $text['description-database-edit']; } echo "

\n"; echo "
\n"; echo " ".$text['label-driver'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-driver']."\n"; echo "
\n"; echo " ".$text['label-type'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-type']."\n"; echo "
\n"; echo " ".$text['label-host'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-host']."\n"; echo "
\n"; echo " ".$text['label-port'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-port']."\n"; echo "
\n"; echo " ".$text['label-name'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-name']."\n"; echo "
\n"; echo " ".$text['label-username'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-username']."\n"; echo "
\n"; echo " ".$text['label-password'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-password']."\n"; echo "
\n"; echo " ".$text['label-path'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-path']."\n"; echo "
\n"; echo " ".$text['label-description'].":\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-description']."\n"; echo "
\n"; if ($action == "update") { echo " \n"; } echo " \n"; echo "
"; echo ""; echo "
"; echo "
"; //include the footer require_once "resources/footer.php"; ?>