Devices: Database class integration.

This commit is contained in:
Nate
2019-08-03 20:21:56 -06:00
parent bc786a8f65
commit f841650075
26 changed files with 1420 additions and 1789 deletions

View File

@@ -31,17 +31,28 @@
//delete the group from the menu item
if ($_REQUEST["a"] == "delete" && permission_exists("device_vendor_function_delete") && $_REQUEST["id"] != '') {
//get the id
$device_vendor_function_group_uuid = check_str($_REQUEST["id"]);
$device_vendor_function_uuid = check_str($_REQUEST["device_vendor_function_uuid"]);
$device_vendor_uuid = check_str($_REQUEST["device_vendor_uuid"]);
//delete the group from the users
$sql = "delete from v_device_vendor_function_groups ";
$sql .= "where device_vendor_function_group_uuid = '".$device_vendor_function_group_uuid."' ";
$db->exec(check_sql($sql));
$device_vendor_function_group_uuid = $_REQUEST["id"];
$device_vendor_function_uuid = $_REQUEST["device_vendor_function_uuid"];
$device_vendor_uuid = $_REQUEST["device_vendor_uuid"];
//delete the device vendor function group
$array['device_vendor_function_groups'][0]['device_vendor_function_group_uuid'] = $device_vendor_function_group_uuid;
$p = new permissions;
$p->add('device_vendor_function_group_delete', 'temp');
$database = new database;
$database->app_name = 'devices';
$database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
$database->delete($array);
unset($array);
$p->delete('device_vendor_function_group_delete', 'temp');
//redirect the browser
message::add($text['message-delete']);
header("Location: device_vendor_function_edit.php?id=".escape($device_vendor_function_uuid) ."&device_vendor_uuid=".escape($device_vendor_uuid));
return;
exit;
}
//check permissions
@@ -55,9 +66,9 @@
}
//action add or update
if (isset($_REQUEST["id"])) {
if (is_uuid($_REQUEST["id"])) {
$action = "update";
$device_vendor_function_uuid = check_str($_REQUEST["id"]);
$device_vendor_function_uuid = $_REQUEST["id"];
}
else {
$action = "add";
@@ -68,17 +79,17 @@
$text = $language->get();
//set the parent uuid
if (strlen($_GET["device_vendor_uuid"]) > 0) {
$device_vendor_uuid = check_str($_GET["device_vendor_uuid"]);
if (is_uuid($_GET["device_vendor_uuid"])) {
$device_vendor_uuid = $_GET["device_vendor_uuid"];
}
//get http post variables and set them to php variables
if (count($_POST)>0) {
//$label = check_str($_POST["label"]);
$name = check_str($_POST["name"]);
$value = check_str($_POST["value"]);
$enabled = check_str($_POST["enabled"]);
$description = check_str($_POST["description"]);
//$label = $_POST["label"];
$name = $_POST["name"];
$value = $_POST["value"];
$enabled = $_POST["enabled"];
$description = $_POST["description"];
}
//process the http variables
@@ -86,7 +97,7 @@
//get the uuid
if ($action == "update") {
$device_vendor_function_uuid = check_str($_POST["device_vendor_function_uuid"]);
$device_vendor_function_uuid = $_POST["device_vendor_function_uuid"];
}
//check for all required data
@@ -115,125 +126,107 @@
//add vendor functions
if ($action == "add" && permission_exists('device_vendor_function_add')) {
$device_vendor_function_uuid = uuid();
$sql = "insert into v_device_vendor_functions ";
$sql .= "(";
$sql .= "device_vendor_function_uuid, ";
$sql .= "device_vendor_uuid, ";
//$sql .= "label, ";
$sql .= "name, ";
$sql .= "value, ";
$sql .= "enabled, ";
$sql .= "description ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$device_vendor_function_uuid."', ";
$sql .= "'$device_vendor_uuid', ";
//$sql .= "'$label', ";
$sql .= "'$name', ";
$sql .= "'$value', ";
$sql .= "'$enabled', ";
$sql .= "'$description' ";
$sql .= ")";
$db->exec(check_sql($sql));
unset($sql);
} //if ($action == "add")
$array['device_vendor_functions'][0]['device_vendor_function_uuid'] = $device_vendor_function_uuid;
}
//update vendor functions
if ($action == "update" && permission_exists('device_vendor_function_edit')) {
$sql = "update v_device_vendor_functions set ";
$sql .= "device_vendor_uuid = '$device_vendor_uuid', ";
//$sql .= "label = '$label', ";
$sql .= "name = '$name', ";
$sql .= "value = '$value', ";
$sql .= "enabled = '$enabled', ";
$sql .= "description = '$description' ";
$sql .= "where device_vendor_function_uuid = '$device_vendor_function_uuid'";
$db->exec(check_sql($sql));
unset($sql);
} //if ($action == "update")
$array['device_vendor_functions'][0]['device_vendor_function_uuid'] = $device_vendor_function_uuid;
}
//execute
if (is_array($array) && @sizeof($array) != 0) {
$array['device_vendor_functions'][0]['device_vendor_uuid'] = $device_vendor_uuid;
//$array['device_vendor_functions'][0]['label'] = $label;
$array['device_vendor_functions'][0]['name'] = $name;
$array['device_vendor_functions'][0]['value'] = $value;
$array['device_vendor_functions'][0]['enabled'] = $enabled;
$array['device_vendor_functions'][0]['description'] = $description;
$database = new database;
$database->app_name = 'devices';
$database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
$database->save($array);
unset($array);
}
//add a group to the menu
if (permission_exists('device_vendor_function_add') && $_REQUEST["group_uuid_name"] != '') {
//get the group uuid and group_name
$group_data = explode('|', check_str($_REQUEST["group_uuid_name"]));
$group_data = explode('|', $_REQUEST["group_uuid_name"]);
$group_uuid = $group_data[0];
$group_name = $group_data[1];
//add the group to the menu
if (strlen($device_vendor_function_uuid) > 0) {
if (is_uuid($device_vendor_function_uuid)) {
$device_vendor_function_group_uuid = uuid();
$sql = "insert into v_device_vendor_function_groups ";
$sql .= "(";
$sql .= "device_vendor_function_group_uuid, ";
$sql .= "device_vendor_function_uuid, ";
$sql .= "device_vendor_uuid, ";
$sql .= "group_name, ";
$sql .= "group_uuid ";
$sql .= ")";
$sql .= "values ";
$sql .= "(";
$sql .= "'".$device_vendor_function_group_uuid."', ";
$sql .= "'".$device_vendor_function_uuid."', ";
$sql .= "'".$device_vendor_uuid."', ";
$sql .= "'".$group_name."', ";
$sql .= "'".$group_uuid."' ";
$sql .= ")";
$db->exec($sql);
$array['device_vendor_function_groups'][0]['device_vendor_function_group_uuid'] = $device_vendor_function_group_uuid;
$array['device_vendor_function_groups'][0]['device_vendor_function_uuid'] = $device_vendor_function_uuid;
$array['device_vendor_function_groups'][0]['device_vendor_uuid'] = $device_vendor_uuid;
$array['device_vendor_function_groups'][0]['group_name'] = $group_name;
$array['device_vendor_function_groups'][0]['group_uuid'] = $group_uuid;
$p = new permissions;
$p->add('device_vendor_function_group_add', 'temp');
$database = new database;
$database->app_name = 'devices';
$database->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
$database->save($array);
unset($array);
$p->delete('device_vendor_function_group_add', 'temp');
}
}
//redirect the user
$_SESSION["message"] = $text['message-'.$action];
header("Location: device_vendor_function_edit.php?id=".escape($device_vendor_function_uuid) ."&device_vendor_uuid=".escape($device_vendor_uuid));
return;
} //if ($_POST["persistformvar"] != "true")
} //(count($_POST)>0 && strlen($_POST["persistformvar"]) == 0)
exit;
}
}
//pre-populate the form
if (count($_GET) > 0 && $_POST["persistformvar"] != "true") {
$device_vendor_function_uuid = check_str($_GET["id"]);
$device_vendor_function_uuid = $_GET["id"];
$sql = "select * from v_device_vendor_functions ";
$sql .= "where device_vendor_function_uuid = '$device_vendor_function_uuid' ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$device_vendor_functions = $prep_statement->fetchAll(PDO::FETCH_NAMED);
foreach ($device_vendor_functions as &$row) {
$sql .= "where device_vendor_function_uuid = :device_vendor_function_uuid ";
$parameters['device_vendor_function_uuid'] = $device_vendor_function_uuid;
$database = new database;
$row = $database->select($sql, $parameters, 'row');
if (is_array($row) && @sizeof($row) != 0) {
//$label = $row["label"];
$name = $row["name"];
$value = $row["value"];
$enabled = $row["enabled"];
$description = $row["description"];
}
unset ($prep_statement);
unset($sql, $parameters, $row);
}
//group groups assigned
//get function groups assigned
$sql = "select ";
$sql .= " fg.*, g.domain_uuid as group_domain_uuid ";
$sql .= "fg.*, g.domain_uuid as group_domain_uuid ";
$sql .= "from ";
$sql .= " v_device_vendor_function_groups as fg, ";
$sql .= " v_groups as g ";
$sql .= "v_device_vendor_function_groups as fg, ";
$sql .= "v_groups as g ";
$sql .= "where ";
$sql .= " fg.group_uuid = g.group_uuid ";
$sql .= " and fg.device_vendor_uuid = :device_vendor_uuid ";
//$sql .= " and fg.device_vendor_uuid = '$device_vendor_uuid' ";
$sql .= " and fg.device_vendor_function_uuid = :device_vendor_function_uuid ";
//$sql .= " and fg.device_vendor_function_uuid = '$device_vendor_function_uuid' ";
$sql .= "fg.group_uuid = g.group_uuid ";
$sql .= "and fg.device_vendor_uuid = :device_vendor_uuid ";
$sql .= "and fg.device_vendor_function_uuid = :device_vendor_function_uuid ";
$sql .= "order by ";
$sql .= " g.domain_uuid desc, ";
$sql .= " g.group_name asc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->bindParam(':device_vendor_uuid', $device_vendor_uuid);
$prep_statement->bindParam(':device_vendor_function_uuid', $device_vendor_function_uuid);
$prep_statement->execute();
$function_groups = $prep_statement->fetchAll(PDO::FETCH_NAMED);
unset($sql, $prep_statement);
$sql .= "g.domain_uuid desc, ";
$sql .= "g.group_name asc ";
$parameters['device_vendor_uuid'] = $device_vendor_uuid;
$parameters['device_vendor_function_uuid'] = $device_vendor_function_uuid;
$database = new database;
$function_groups = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//set the assigned_groups array
if (is_array($menu_item_groups)) {
foreach($menu_item_groups as $field) {
if (is_array($function_groups) && @sizeof($function_groups) != 0) {
foreach($function_groups as $field) {
if (strlen($field['group_name']) > 0) {
$assigned_groups[] = $field['group_uuid'];
}
@@ -242,14 +235,20 @@
//get the groups
$sql = "select * from v_groups ";
if (sizeof($assigned_groups) > 0) {
$sql .= "where group_uuid not in ('".implode("','",$assigned_groups)."') ";
if (is_array($assigned_groups) && @sizeof($assigned_groups) != 0) {
$sql .= "where ";
foreach ($assigned_groups as $index => $group_uuid) {
$sql_where[] = 'group_uuid <> :group_uuid_'.$index;
$parameters['group_uuid_'.$index] = $group_uuid;
}
if (is_array($sql_where) && @sizeof($sql_where) != 0) {
$sql .= implode(' and ', $sql_where);
}
}
$sql .= "order by domain_uuid desc, group_name asc ";
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$groups = $prep_statement->fetchAll(PDO::FETCH_NAMED);
unset($sql, $prep_statement);
$database = new database;
$groups = $database->select($sql, $parameters, 'all');
unset($sql, $parameters, $sql_where, $index);
//show the header
require_once "resources/header.php";
@@ -298,13 +297,10 @@
echo "</td>\n";
echo "</tr>\n";
//echo "<pre>\n";
//print_r($function_groups);
//echo "</pre>\n";
echo " <tr>";
echo " <td class='vncell' valign='top'>".$text['label-groups']."</td>";
echo " <td class='vtable'>";
if (is_array($function_groups)) {
if (is_array($function_groups) && @sizeof($function_groups) != 0) {
echo "<table cellpadding='0' cellspacing='0' border='0'>\n";
foreach($function_groups as $field) {
if (strlen($field['group_name']) > 0) {
@@ -322,7 +318,7 @@
}
echo "</table>\n";
}
if (is_array($groups)) {
if (is_array($groups) && @sizeof($groups) != 0) {
echo "<br />\n";
echo "<select name='group_uuid_name' class='formfld' style='width: auto; margin-right: 3px;'>\n";
echo " <option value=''></option>\n";