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('database_add') || permission_exists('database_edit')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //action add or update if (is_uuid($_REQUEST["id"])) { $action = "update"; $database_uuid = $_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 = $_POST["database_driver"]; $database_type = $_POST["database_type"]; $database_host = $_POST["database_host"]; $database_port = $_POST["database_port"]; $database_name = $_POST["database_name"]; $database_username = $_POST["database_username"]; $database_password = $_POST["database_password"]; $database_path = $_POST["database_path"]; $database_description = $_POST["database_description"]; } if (count($_POST)>0 && strlen($_POST["persistformvar"]) == 0) { $msg = ''; if ($action == "update") { $database_uuid = $_POST["database_uuid"]; } //delete the database if (permission_exists('database_delete')) { if ($_POST['action'] == 'delete' && is_uuid($database_uuid)) { //prepare $array[0]['checked'] = 'true'; $array[0]['uuid'] = $database_uuid; //delete $obj = new databases; $obj->delete($array); //redirect header('Location: databases.php'); exit; } } //validate the token $token = new token; if (!$token->validate($_SERVER['PHP_SELF'])) { message::add($text['message-invalid_token'],'negative'); header('Location: databases.php'); exit; } //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") { //begin array $array['databases'][0]['database_driver'] = $database_driver; $array['databases'][0]['database_type'] = $database_type; $array['databases'][0]['database_host'] = $database_host; $array['databases'][0]['database_port'] = $database_port; $array['databases'][0]['database_name'] = $database_name; $array['databases'][0]['database_username'] = $database_username; $array['databases'][0]['database_password'] = $database_password; $array['databases'][0]['database_path'] = $database_path; $array['databases'][0]['database_description'] = $database_description; if ($action == "add") { //add new uuid $array['databases'][0]['database_uuid'] = uuid(); $database = new database; $database->app_name = 'databases'; $database->app_uuid = '8d229b6d-1383-fcec-74c6-4ce1682479e2'; $database->save($array); unset($array); //set the defaults require_once "app_defaults.php"; //redirect the browser message::add($text['message-add']); header("Location: databases.php"); exit; } if ($action == "update") { //add uuid to update $array['databases'][0]['database_uuid'] = $database_uuid; $database = new database; $database->app_name = 'databases'; $database->app_uuid = '8d229b6d-1383-fcec-74c6-4ce1682479e2'; $database->save($array); unset($array); //set the defaults $domains_processed = 1; require_once "app_defaults.php"; //redirect the browser message::add($text['message-update']); header("Location: databases.php"); exit; } } } //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 "; $parameters['database_uuid'] = $database_uuid; $database = new database; $row = $database->select($sql, $parameters, 'row'); if (is_array($row) && sizeof($row) != 0) { $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"]; } unset($sql, $parameters, $row); } //create token $object = new token; $token = $object->create($_SERVER['PHP_SELF']); //include the header if ($action == "update") { $document['title'] = $text['title-database-edit']; } if ($action == "add") { $document['title'] = $text['title-database-add']; } require_once "resources/header.php"; //show the content echo "
\n"; echo "
\n"; echo "
"; if ($action == "add") { echo "".$text['header-database-add'].""; } if ($action == "update") { echo "".$text['header-database-edit'].""; } echo "
\n"; echo "
\n"; echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'id'=>'btn_back','style'=>'margin-right: 15px;','link'=>'databases.php']); if ($action == 'update' && permission_exists('database_delete')) { echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'name'=>'btn_delete','style'=>'margin-right: 15px;','onclick'=>"modal_open('modal-delete','btn_delete');"]); } echo button::create(['type'=>'submit','label'=>$text['button-save'],'icon'=>$_SESSION['theme']['button_icon_save'],'id'=>'btn_save','name'=>'action','value'=>'save']); echo "
\n"; echo "
\n"; echo "
\n"; if ($action == 'update' && permission_exists('database_delete')) { echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'submit','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','name'=>'action','value'=>'delete','onclick'=>"modal_close();"])]); } if ($action == "add") { echo $text['description-database-add']."\n"; } if ($action == "update") { echo $text['description-database-edit']."\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 " ".$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 "
"; echo "

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