Variables: Database class integration.
This commit is contained in:
+55
-89
@@ -43,9 +43,9 @@
|
||||
$text = $language->get();
|
||||
|
||||
//set the action as an add or an update
|
||||
if (isset($_REQUEST["id"])) {
|
||||
if (is_uuid($_REQUEST["id"]) {
|
||||
$action = "update";
|
||||
$var_uuid = check_str($_REQUEST["id"]);
|
||||
$var_uuid = $_REQUEST["id"];
|
||||
}
|
||||
else {
|
||||
$action = "add";
|
||||
@@ -53,18 +53,18 @@
|
||||
|
||||
//set http values as php variables
|
||||
if (count($_POST) > 0) {
|
||||
$var_category = check_str(trim($_POST["var_category"]));
|
||||
$var_name = check_str(trim($_POST["var_name"]));
|
||||
$var_value = check_str(trim($_POST["var_value"]));
|
||||
$var_command = check_str(trim($_POST["var_command"]));
|
||||
$var_hostname = check_str(trim($_POST["var_hostname"]));
|
||||
$var_enabled = check_str(trim($_POST["var_enabled"]));
|
||||
$var_order = check_str(trim($_POST["var_order"]));
|
||||
$var_description = check_str(trim($_POST["var_description"]));
|
||||
$var_category = trim($_POST["var_category"]);
|
||||
$var_name = trim($_POST["var_name"]);
|
||||
$var_value = trim($_POST["var_value"]);
|
||||
$var_command = trim($_POST["var_command"]);
|
||||
$var_hostname = trim($_POST["var_hostname"]);
|
||||
$var_enabled = trim($_POST["var_enabled"]);
|
||||
$var_order = trim($_POST["var_order"]);
|
||||
$var_description = trim($_POST["var_description"]);
|
||||
$var_description = str_replace("''", "'", $var_description);
|
||||
|
||||
if (strlen($_POST["var_category_other"]) > 0) {
|
||||
$var_category = check_str(trim($_POST["var_category_other"]));
|
||||
$var_category = trim($_POST["var_category_other"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@
|
||||
|
||||
//get the uuid
|
||||
if ($action == "update") {
|
||||
$var_uuid = check_str($_POST["var_uuid"]);
|
||||
$var_uuid = $_POST["var_uuid"];
|
||||
}
|
||||
|
||||
//check for all required data
|
||||
@@ -100,71 +100,37 @@
|
||||
//add or update the database
|
||||
if ($_POST["persistformvar"] != "true") {
|
||||
if ($action == "add" && permission_exists('var_add')) {
|
||||
//insert the variable
|
||||
//begin insert array
|
||||
$var_uuid = uuid();
|
||||
$sql = "insert into v_vars ";
|
||||
$sql .= "(";
|
||||
$sql .= "var_uuid, ";
|
||||
$sql .= "var_category, ";
|
||||
$sql .= "var_name, ";
|
||||
$sql .= "var_value, ";
|
||||
$sql .= "var_command, ";
|
||||
$sql .= "var_hostname, ";
|
||||
$sql .= "var_enabled, ";
|
||||
$sql .= "var_order, ";
|
||||
$sql .= "var_description ";
|
||||
$sql .= ")";
|
||||
$sql .= "values ";
|
||||
$sql .= "(";
|
||||
$sql .= "'$var_uuid', ";
|
||||
$sql .= "'$var_category', ";
|
||||
$sql .= "'$var_name', ";
|
||||
$sql .= "'$var_value', ";
|
||||
$sql .= "'$var_command', ";
|
||||
if (strlen($var_hostname) > 0) {
|
||||
$sql .= "'$var_hostname', ";
|
||||
}
|
||||
else {
|
||||
$sql .= "null, ";
|
||||
}
|
||||
$sql .= "'$var_enabled', ";
|
||||
$sql .= "'$var_order', ";
|
||||
$sql .= "'".base64_encode($var_description)."' ";
|
||||
$sql .= ")";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
|
||||
//unset the user defined variables
|
||||
$_SESSION["user_defined_variables"] = "";
|
||||
|
||||
//synchronize the configuration
|
||||
save_var_xml();
|
||||
|
||||
//set the message and redirect the user
|
||||
$array['vars'][0]['var_uuid'] = $var_uuid;
|
||||
//set message
|
||||
message::add($text['message-add']);
|
||||
header("Location: vars.php");
|
||||
return;
|
||||
} //if ($action == "add")
|
||||
}
|
||||
|
||||
if ($action == "update" && permission_exists('var_edit')) {
|
||||
//update the variables
|
||||
$sql = "update v_vars set ";
|
||||
$sql .= "var_category = '$var_category', ";
|
||||
$sql .= "var_name = '$var_name', ";
|
||||
$sql .= "var_value = '$var_value', ";
|
||||
$sql .= "var_command = '$var_command', ";
|
||||
if (strlen($var_hostname) > 0) {
|
||||
$sql .= "var_hostname = '$var_hostname', ";
|
||||
}
|
||||
else {
|
||||
$sql .= "var_hostname = null, ";
|
||||
}
|
||||
$sql .= "var_enabled = '$var_enabled', ";
|
||||
$sql .= "var_order = '$var_order', ";
|
||||
$sql .= "var_description = '".base64_encode($var_description)."' ";
|
||||
$sql .= "where var_uuid = '$var_uuid' ";
|
||||
$db->exec(check_sql($sql));
|
||||
unset($sql);
|
||||
//begin update array
|
||||
$array['vars'][0]['var_uuid'] = $var_uuid;
|
||||
//set message
|
||||
message::add($text['message-update']);
|
||||
}
|
||||
|
||||
if (is_array($array) && @sizeof($array) != 0) {
|
||||
//add common fields to array
|
||||
$array['vars'][0]['var_category'] = $var_category;
|
||||
$array['vars'][0]['var_name'] = $var_name;
|
||||
$array['vars'][0]['var_value'] = $var_value;
|
||||
$array['vars'][0]['var_command'] = $var_command;
|
||||
$array['vars'][0]['var_hostname'] = $var_hostname != '' ? $var_hostname : null;
|
||||
$array['vars'][0]['var_enabled'] = $var_enabled;
|
||||
$array['vars'][0]['var_order'] = $var_order;
|
||||
$array['vars'][0]['var_description'] = base64_encode($var_description);
|
||||
|
||||
//execute insert/update
|
||||
$database = new database;
|
||||
$database->app_name = 'vars';
|
||||
$database->app_uuid = '54e08402-c1b8-0a9d-a30a-f569fc174dd8';
|
||||
$database->save($array);
|
||||
unset($array);
|
||||
|
||||
//unset the user defined variables
|
||||
$_SESSION["user_defined_variables"] = "";
|
||||
@@ -172,23 +138,23 @@
|
||||
//synchronize the configuration
|
||||
save_var_xml();
|
||||
|
||||
//set the message and redirect the user
|
||||
message::add($text['message-update']);
|
||||
//redirect
|
||||
header("Location: vars.php");
|
||||
return;
|
||||
} //if ($action == "update")
|
||||
} //if ($_POST["persistformvar"] != "true")
|
||||
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//pre-populate the form
|
||||
if (is_array($_GET) && $_POST["persistformvar"] != "true") {
|
||||
if (is_array($_GET) && is_uuid($_GET["id"]) && $_POST["persistformvar"] != "true") {
|
||||
$var_uuid = $_GET["id"];
|
||||
$sql = "select * from v_vars ";
|
||||
$sql .= "where var_uuid = '$var_uuid' ";
|
||||
$prep_statement = $db->prepare(check_sql($sql));
|
||||
$prep_statement->execute();
|
||||
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
|
||||
foreach ($result as &$row) {
|
||||
$sql .= "where var_uuid = :var_uuid ";
|
||||
$parameters['something'] = $var_uuid;
|
||||
$database = new database;
|
||||
$row = $database->select($sql, $parameters, 'row');
|
||||
if (is_array($row) && @sizeof($row) != 0) {
|
||||
$var_category = $row["var_category"];
|
||||
$var_name = $row["var_name"];
|
||||
$var_value = $row["var_value"];
|
||||
@@ -198,7 +164,7 @@
|
||||
$var_order = $row["var_order"];
|
||||
$var_description = base64_decode($row["var_description"]);
|
||||
}
|
||||
unset ($prep_statement);
|
||||
unset($sql, $parameters);
|
||||
}
|
||||
|
||||
//include header
|
||||
@@ -326,8 +292,8 @@
|
||||
echo "</td>\n";
|
||||
echo "<td class='vtable' align='left'>\n";
|
||||
echo " <select name='var_order' class='formfld'>\n";
|
||||
$i=0;
|
||||
while($i<=999) {
|
||||
$i = 0;
|
||||
while ($i <= 999) {
|
||||
$selected = ($var_order == $i) ? "selected='selected'" : null;
|
||||
if (strlen($i) == 1) {
|
||||
echo " <option value='00$i' ".$selected.">00$i</option>\n";
|
||||
@@ -446,4 +412,4 @@
|
||||
//include header
|
||||
require_once "resources/footer.php";
|
||||
|
||||
?>
|
||||
?>
|
||||
Reference in New Issue
Block a user