Devices (Profiles & Vendors): List view updates.

This commit is contained in:
Nate
2019-11-07 16:01:43 -07:00
parent 449147198d
commit f0f05f5651
5 changed files with 703 additions and 274 deletions

View File

@@ -663,24 +663,13 @@
}
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-device_profile_enabled']."\n";
echo "</td>\n";
echo "<td class='vtable' style='position: relative;' align='left'>\n";
echo " <select class='formfld' name='device_profile_enabled'>\n";
echo " <option value=''></option>\n";
if ($device_profile_enabled == "true") {
echo " <option value='true' selected='selected'>".$text['label-true']."</option>\n";
}
else {
echo " <option value='true'>".$text['label-true']."</option>\n";
}
if ($device_profile_enabled == "false") {
echo " <option value='false' selected='selected'>".$text['label-false']."</option>\n";
}
else {
echo " <option value='false'>".$text['label-false']."</option>\n";
}
echo " <option value='true'>".$text['label-true']."</option>\n";
echo " <option value='false' ".($device_profile_enabled == "false" ? "selected='selected'" : null).">".$text['label-false']."</option>\n";
echo " </select>\n";
echo "<br />\n";
echo $text['description-device_profile_enabled']."\n";

View File

@@ -27,6 +27,7 @@
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/paging.php";
//check permissions
if (permission_exists('device_profile_view')) {
@@ -41,25 +42,46 @@
$language = new text;
$text = $language->get();
//get the action
if (is_array($_POST["device_profiles"])) {
$device_profiles = $_POST["device_profiles"];
foreach($device_profiles as $row) {
if ($row['action'] == 'delete') {
$action = 'delete';
break;
}
//get posted data
if (is_array($_POST['profiles'])) {
$action = $_POST['action'];
$search = $_POST['search'];
$profiles = $_POST['profiles'];
}
//copy the device profiles
if (permission_exists('device_profile_add')) {
if ($action == 'copy' && is_array($profiles) && @sizeof($profiles) != 0) {
//copy
$obj = new device;
$obj->copy_profiles($profiles);
//redirect
header('Location: device_profiles.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//delete the device_profiles
//toggle the device profiles
if (permission_exists('device_profile_edit')) {
if ($action == 'toggle' && is_array($profiles) && @sizeof($profiles) != 0) {
//toggle
$obj = new device;
$obj->toggle_profiles($profiles);
//redirect
header('Location: device_profiles.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//delete the device profiles
if (permission_exists('device_profile_delete')) {
if ($action == "delete") {
//download
$obj = new device_profiles;
$obj->delete($device_profiles);
//delete message
message::add($text['message-delete']);
if ($action == 'delete' && is_array($profiles) && @sizeof($profiles) != 0) {
//delete
$obj = new device;
$obj->delete_profiles($profiles);
//redirect
header('Location: device_profiles.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
@@ -67,28 +89,9 @@
$order_by = $_GET["order_by"];
$order = $_GET["order"];
//validate the order by
if (strlen($order_by) > 0) {
$order_by = preg_replace('#[^a-zA-Z0-9_\-]#', '', $order_by);
}
//validate the order
switch ($order) {
case 'asc':
break;
case 'desc':
break;
default:
$order = '';
}
//search string
if (isset($_GET["search"])) {
$search = strtolower($_GET["search"]);
}
//add the search
if (isset($search)) {
//add the search term
$search = strtolower($_GET["search"]);
if (strlen($search) > 0) {
$sql_search = "and (";
$sql_search .= " lower(device_profile_name) like :search ";
$sql_search .= " or lower(device_profile_description) like :search ";
@@ -96,22 +99,14 @@
$parameters['search'] = '%'.$search.'%';
}
//additional includes
require_once "resources/header.php";
require_once "resources/paging.php";
//get the count
$sql = "select count(device_profile_uuid) from v_device_profiles ";
if ($_GET['show'] == "all" && permission_exists('device_profile_all')) {
$sql .= "where 1 = 1 ";
}
else {
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql = "select count(*) from v_device_profiles ";
$sql .= "where true ";
if ($_GET['show'] != "all" || !permission_exists('device_profile_all')) {
$sql .= "and (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['domain_uuid'] = $domain_uuid;
}
if (isset($sql_search)) {
$sql .= $sql_search;
}
$sql .= $sql_search;
$database = new database;
$num_rows = $database->select($sql, $parameters, 'column');
@@ -123,123 +118,100 @@
}
$page = $_GET['page'];
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
list($paging_controls_mini, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page, true); //top
list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page); //bottom
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page); //bottom
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true); //top
$offset = $rows_per_page * $page;
//get the list
$sql = "select * from v_device_profiles ";
if ($_GET['show'] == "all" && permission_exists('device_profile_all')) {
$sql .= "where 1 = 1 ";
}
else {
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$parameters['domain_uuid'] = $domain_uuid;
}
if (isset($sql_search)) {
$sql .= $sql_search;
}
if (strlen($order_by) > 0) { $sql .= "order by $order_by $order "; }
$sql .= "limit :rows_per_page offset :offset ";
$parameters['rows_per_page'] = $rows_per_page;
$parameters['offset'] = $offset;
$sql = str_replace('count(*)', '*', $sql);
$sql .= order_by($order_by, $order, 'device_profile_name', 'asc');
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
$device_profiles = $database->select($sql, $parameters, 'all');
unset ($sql, $parameters);
unset($sql, $parameters);
//alternate the row style
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//define the checkbox_toggle function
//echo "<script type=\"text/javascript\">\n";
//echo " function checkbox_toggle(item) {\n";
//echo " var inputs = document.getElementsByTagName(\"input\");\n";
//echo " for (var i = 0, max = inputs.length; i < max; i++) {\n";
//echo " if (inputs[i].type === 'checkbox') {\n";
//echo " if (document.getElementById('checkbox_all').checked == true) {\n";
//echo " inputs[i].checked = true;\n";
//echo " }\n";
//echo " else {\n";
//echo " inputs[i].checked = false;\n";
//echo " }\n";
//echo " }\n";
//echo " }\n";
//echo " }\n";
//echo "</script>\n";
//include the header
require_once "resources/header.php";
//show the content
echo "<table width='100%' border='0'>\n";
echo " <tr>\n";
echo " <td width='50%' align='left' nowrap='nowrap'>\n";
echo " <b>".$text['title-device_profiles']." (".$num_rows.")</b>\n";
echo " </td>\n";
echo " <form method='get' action=''>\n";
echo " <td width='50%' style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-device_profiles']." (".$num_rows.")</b></div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'style'=>'margin-right: 15px;','link'=>'devices.php']);
if (permission_exists('device_profile_add')) {
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'device_profile_edit.php']);
}
if (permission_exists('device_profile_add') && $device_profiles) {
echo button::create(['type'=>'button','label'=>$text['button-copy'],'icon'=>$_SESSION['theme']['button_icon_copy'],'onclick'=>"if (confirm('".$text['confirm-copy']."')) { list_action_set('copy'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
if (permission_exists('device_profile_edit') && $device_profiles) {
echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'onclick'=>"if (confirm('".$text['confirm-toggle']."')) { list_action_set('toggle'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
if (permission_exists('device_profile_delete') && $device_profiles) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
echo "<form id='form_search' class='inline' method='get'>\n";
if (permission_exists('device_profile_all')) {
if ($_GET['show'] == 'all') {
echo " <input type='hidden' name='show' value='all'>";
}
else {
echo " <input type='button' class='btn' value='".$text['button-show_all']."' onclick=\"window.location='device_profiles.php?show=all';\">\n";
echo button::create(['type'=>'button','label'=>$text['button-show_all'],'icon'=>$_SESSION['theme']['button_icon_all'],'link'=>'?show=all']);
}
}
//add buttons
if (!isset($id)) {
echo " <input type='button' class='btn' name='' alt='".$text['button-back']."' onclick='window.location=\"/app/devices/devices.php\"' value='".$text['button-back']."'>";
}
echo " <input type='text' class='txt' style='width: 150px; margin-left: 15px;' name='search' id='search' value='".escape($search)."'>\n";
echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>\n";
echo " </td>\n";
echo " </form>\n";
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'device_profiles.php','style'=>($search == '' ? 'display: none;' : null)]);
if ($paging_controls_mini != '') {
echo " <td valign='top' nowrap='nowrap' style='padding-left: 15px;'>".$paging_controls_mini."</td>\n";
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>";
}
echo " </tr>\n";
echo " <tr>\n";
echo " <td align='left' colspan='2'>\n";
echo " ".$text['description-device_profiles']."<br /><br />\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo " </form>\n";
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo "<form method='post' action=''>\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
//echo " <th style='width:30px;'>\n";
//echo " <input type='checkbox' name='checkbox_all' id='checkbox_all' value='' onclick=\"checkbox_toggle();\">\n";
//echo " </th>\n";
echo $text['description-device_profiles']."\n";
echo "<br /><br />\n";
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value=''>\n";
echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
if (permission_exists('device_profile_add') || permission_exists('device_profile_edit') || permission_exists('device_profile_delete')) {
echo " <th class='checkbox'>\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".($device_profiles ?: "style='visibility: hidden;'").">\n";
echo " </th>\n";
}
if ($_GET['show'] == "all" && permission_exists('device_profile_all')) {
echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param);
}
echo th_order_by('device_profile_name', $text['label-device_profile_name'], $order_by, $order);
echo th_order_by('device_profile_enabled', $text['label-device_profile_enabled'], $order_by, $order);
echo th_order_by('device_profile_description', $text['label-device_profile_description'], $order_by, $order);
echo " <td class='list_control_icons'>";
if (permission_exists('device_profile_add')) {
echo " <a href='device_profile_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
echo th_order_by('device_profile_enabled', $text['label-device_profile_enabled'], $order_by, $order, null, "class='center'");
echo th_order_by('device_profile_description', $text['label-device_profile_description'], $order_by, $order, null, "class='hide-xs'");
if (permission_exists('device_profile_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>&nbsp;</td>\n";
}
else {
echo "&nbsp;\n";
}
echo " </td>\n";
echo "</tr>\n";
if (is_array($device_profiles) && @sizeof($device_profiles) != 0) {
$x = 0;
foreach($device_profiles as $row) {
if (permission_exists('device_profile_edit')) {
$tr_link = "href='device_profile_edit.php?id=".escape($row['device_profile_uuid'])."'";
$list_row_url = "device_profile_edit.php?id=".urlencode($row['device_profile_uuid']);
}
echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (permission_exists('device_profile_add') || permission_exists('device_profile_edit') || permission_exists('device_profile_delete')) {
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='profiles[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='profiles[$x][uuid]' value='".escape($row['device_profile_uuid'])."' />\n";
echo " </td>\n";
}
echo "<tr ".$tr_link.">\n";
//echo " <td valign='top' class='".$row_style[$c]." tr_link_void' style='align: center; padding: 3px 3px 0px 8px;'>\n";
//echo " <input type='checkbox' name=\"device_profiles[$x][checked]\" id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('chk_all_".$x."').checked = false; }\">\n";
//echo " <input type='hidden' name=\"device_profiles[$x][device_profile_uuid]\" value='".escape($row['device_profile_uuid'])."' />\n";
//echo " </td>\n";
if ($_GET['show'] == "all" && permission_exists('device_profile_all')) {
if (strlen($_SESSION['domains'][$row['domain_uuid']]['domain_name']) > 0) {
$domain = $_SESSION['domains'][$row['domain_uuid']]['domain_name'];
@@ -247,37 +219,46 @@
else {
$domain = $text['label-global'];
}
echo " <td valign='top' class='".$row_style[$c]."'>".escape($domain)."</td>\n";
echo " <td>".escape($domain)."</td>\n";
}
echo " <td valign='top' class='".$row_style[$c]."' style=''>".escape($row['device_profile_name'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."' style=''>".escape($row['device_profile_enabled'])."&nbsp;</td>\n";
echo " <td valign='top' class='row_stylebg' style=''>".escape($row['device_profile_description'])."&nbsp;</td>\n";
echo " <td class='list_control_icons'>";
echo " <td>";
if (permission_exists('device_profile_edit')) {
echo "<a href='device_profile_edit.php?id=".escape($row['device_profile_uuid'])."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
echo " <a href='".$list_row_url."' title=\"".$text['button-edit']."\">".escape($row['device_profile_name'])."</a>\n";
}
if (permission_exists('device_profile_delete')) {
echo " <a href=\"device_profile_delete.php?id=".escape($row['device_profile_uuid'])."&amp;a=delete\" alt='delete' onclick=\"return confirm('Do you really want to delete this?')\">".$v_link_label_delete."</a>\n";
else {
echo " ".escape($row['device_profile_name'])."\n";
}
echo " </td>\n";
if (permission_exists('device_profile_edit')) {
echo " <td class='no-link center'>";
echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['device_profile_enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
}
else {
echo " <td class='center'>";
echo $text['label-'.$row['device_profile_enabled']];
}
echo " </td>\n";
echo " <td class='description overflow hide-xs'>".escape($row['device_profile_description'])."&nbsp;</td>\n";
if (permission_exists('device_profile_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>";
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
echo " </td>\n";
}
echo "</tr>\n";
$x++;
if ($c==0) { $c=1; } else { $c=0; }
} //end foreach
unset($sql, $device_profiles);
} //end if results
}
unset($device_profiles);
}
echo "</table>\n";
echo "<br />\n";
echo "<div align='center'>".$paging_controls."</div>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "<tr>\n";
echo " <td colspan='3' align='center'>\n";
echo " <br />\n";
echo " ".$paging_controls;
echo " </td>\n";
echo "</tr>\n";
echo "</table>";
echo "</form>\n";
echo "<br /><br />";
//include the footer
require_once "resources/footer.php";
?>
?>

View File

@@ -167,24 +167,13 @@
echo "</tr>\n";
echo "<tr>\n";
echo "<td class='vncellreq' valign='top' align='left' nowrap='nowrap'>\n";
echo "<td class='vncell' valign='top' align='left' nowrap='nowrap'>\n";
echo " ".$text['label-enabled']."\n";
echo "</td>\n";
echo "<td class='vtable' align='left'>\n";
echo " <select class='formfld' name='enabled'>\n";
echo " <option value=''></option>\n";
if ($enabled == "false") {
echo " <option value='false' selected='selected'>".$text['label-false']."</option>\n";
}
else {
echo " <option value='false'>".$text['label-false']."</option>\n";
}
if ($enabled == "true") {
echo " <option value='true' selected='selected'>".$text['label-true']."</option>\n";
}
else {
echo " <option value='true'>".$text['label-true']."</option>\n";
}
echo " <option value='true'>".$text['label-true']."</option>\n";
echo " <option value='false' ".($enabled == 'false' ? "selected='selected'" : null).">".$text['label-false']."</option>\n";
echo " </select>\n";
echo "<br />\n";
echo $text['description-enabled']."\n";

View File

@@ -27,9 +27,10 @@
//includes
require_once "root.php";
require_once "resources/require.php";
require_once "resources/check_auth.php";
require_once "resources/paging.php";
//check permissions
require_once "resources/check_auth.php";
if (permission_exists('device_vendor_view')) {
//access granted
}
@@ -42,25 +43,52 @@
$language = new text;
$text = $language->get();
//get posted data
if (is_array($_POST['vendors'])) {
$action = $_POST['action'];
$search = $_POST['search'];
$vendors = $_POST['vendors'];
}
//toggle the device vendors
if (permission_exists('device_vendor_edit')) {
if ($action == 'toggle' && is_array($vendors) && @sizeof($vendors) != 0) {
//toggle
$obj = new device;
$obj->toggle_vendors($vendors);
//redirect
header('Location: device_vendors.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//delete the device vendors
if (permission_exists('device_vendor_delete')) {
if ($action == 'delete' && is_array($vendors) && @sizeof($vendors) != 0) {
//delete
$obj = new device;
$obj->delete_vendors($vendors);
//redirect
header('Location: device_vendors.php'.($search != '' ? '?search='.urlencode($search) : null));
exit;
}
}
//get variables used to control the order
$order_by = $_GET["order_by"];
$order = $_GET["order"];
//add the search term
$search = $_GET["search"];
if ($search != '') {
$search = strtolower($_GET["search"]);
if (strlen($search) > 0) {
$sql_where = "where (";
$sql_where .= "name like :search ";
$sql_where .= "or enabled like :search ";
$sql_where .= "or description like :search ";
$sql_where .= "lower(name) like :search ";
$sql_where .= "or lower(enabled) like :search ";
$sql_where .= "or lower(description) like :search ";
$sql_where .= ")";
$parameters['search'] = '%'.$search.'%';
}
//additional includes
require_once "resources/header.php";
require_once "resources/paging.php";
//prepare to page the results
$sql = "select count(*) from v_device_vendors ";
$sql .= $sql_where;
@@ -69,107 +97,123 @@
//prepare to page the results
$rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50;
$param = "";
$param = "&search=".$search;
$page = $_GET['page'];
if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; }
list($paging_controls, $rows_per_page, $var3) = paging($num_rows, $param, $rows_per_page);
list($paging_controls, $rows_per_page) = paging($num_rows, $param, $rows_per_page);
list($paging_controls_mini, $rows_per_page) = paging($num_rows, $param, $rows_per_page, true);
$offset = $rows_per_page * $page;
//get the list
$sql = str_replace('count(*)', '*', $sql);
$sql .= order_by($order_by, $order);
$sql .= order_by($order_by, $order, 'name', 'asc');
$sql .= limit_offset($rows_per_page, $offset);
$database = new database;
$result = $database->select($sql, $parameters, 'all');
unset($sql, $parameters);
//alternate the row style
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style1";
//create token
$object = new token;
$token = $object->create($_SERVER['PHP_SELF']);
//include the header
require_once "resources/header.php";
//show the content
echo "<table width='100%' border='0'>\n";
echo " <tr>\n";
echo " <td width='50%' align='left' nowrap='nowrap'><b>".$text['title-device_vendors']."</b></td>\n";
echo " <form method='get' action=''>\n";
echo " <td width='50%' style='vertical-align: top; text-align: right; white-space: nowrap;'>\n";
if (permission_exists('device_vendor_restore')) {
echo " <input type='button' class='btn' alt='".$text['button-restore']."' onclick=\"document.location='device_vendor_restore.php'\" value='".$text['button-restore']."'>";
}
echo " <input type='button' class='btn' alt='".$text['button-back']."' onclick=\"document.location='devices.php'\" value='".$text['button-back']."'>";
echo " <input type='text' class='txt' style='width: 150px' name='search' id='search' value='".escape($search)."'>\n";
echo " <input type='submit' class='btn' name='submit' value='".$text['button-search']."'>\n";
echo " </td>\n";
echo " </form>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td align='left' colspan='2'>\n";
echo " ".$text['description-device_vendor']."<br /><br />\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
echo "<tr>\n";
echo th_order_by('name', $text['label-name'], $order_by, $order);
echo th_order_by('enabled', $text['label-enabled'], $order_by, $order);
echo th_order_by('description', $text['label-description'], $order_by, $order);
echo "<td class='list_control_icons'>";
echo "<div class='action_bar' id='action_bar'>\n";
echo " <div class='heading'><b>".$text['title-device_vendors']." (".$num_rows.")</b></div>\n";
echo " <div class='actions'>\n";
echo button::create(['type'=>'button','label'=>$text['button-back'],'icon'=>$_SESSION['theme']['button_icon_back'],'style'=>'margin-right: 15px;','link'=>'devices.php']);
if (permission_exists('device_vendor_add')) {
echo "<a href='device_vendor_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'device_vendor_edit.php']);
}
else {
echo "&nbsp;\n";
if (permission_exists('device_vendor_edit') && $result) {
echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'onclick'=>"if (confirm('".$text['confirm-toggle']."')) { list_action_set('toggle'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
echo "</td>\n";
echo "<tr>\n";
if (permission_exists('device_vendor_delete') && $result) {
echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'onclick'=>"if (confirm('".$text['confirm-delete']."')) { list_action_set('delete'); list_form_submit('form_list'); } else { this.blur(); return false; }"]);
}
echo "<form id='form_search' class='inline' method='get'>\n";
echo "<input type='text' class='txt list-search' name='search' id='search' value=\"".escape($search)."\" placeholder=\"".$text['label-search']."\" onkeydown='list_search_reset();'>";
echo button::create(['label'=>$text['button-search'],'icon'=>$_SESSION['theme']['button_icon_search'],'type'=>'submit','id'=>'btn_search','style'=>($search != '' ? 'display: none;' : null)]);
echo button::create(['label'=>$text['button-reset'],'icon'=>$_SESSION['theme']['button_icon_reset'],'type'=>'button','id'=>'btn_reset','link'=>'device_vendors.php','style'=>($search == '' ? 'display: none;' : null)]);
if ($paging_controls_mini != '') {
echo "<span style='margin-left: 15px;'>".$paging_controls_mini."</span>";
}
if (permission_exists('device_vendor_restore')) {
echo button::create(['type'=>'button','label'=>$text['button-restore'],'icon'=>$_SESSION['theme']['button_icon_reset'],'style'=>'margin-left: 15px;','link'=>'device_vendor_restore.php']);
}
echo " </form>\n";
echo " </div>\n";
echo " <div style='clear: both;'></div>\n";
echo "</div>\n";
echo $text['description-device_vendor']."\n";
echo "<br /><br />\n";
echo "<form id='form_list' method='post'>\n";
echo "<input type='hidden' id='action' name='action' value=''>\n";
echo "<input type='hidden' name='search' value=\"".escape($search)."\">\n";
echo "<table class='list'>\n";
echo "<tr class='list-header'>\n";
if (permission_exists('device_vendor_edit') || permission_exists('device_vendor_delete')) {
echo " <th class='checkbox'>\n";
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle();' ".($result ?: "style='visibility: hidden;'").">\n";
echo " </th>\n";
}
echo th_order_by('name', $text['label-name'], $order_by, $order);
echo th_order_by('enabled', $text['label-enabled'], $order_by, $order, null, "class='center'");
echo th_order_by('description', $text['label-description'], $order_by, $order, null, "class='hide-xs'");
if (permission_exists('device_vendor_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>&nbsp;</td>\n";
}
echo "</tr>\n";
if (is_array($result) && @sizeof($result) != 0) {
$x = 0;
foreach($result as $row) {
if (permission_exists('device_vendor_edit')) {
$tr_link = "href='device_vendor_edit.php?id=".escape($row['device_vendor_uuid'])."'";
$list_row_url = "device_vendor_edit.php?id=".urlencode($row['device_vendor_uuid']);
}
echo "<tr ".$tr_link.">\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['name'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['enabled'])."&nbsp;</td>\n";
echo " <td valign='top' class='".$row_style[$c]."'>".escape($row['description'])."&nbsp;</td>\n";
echo " <td class='list_control_icons'>";
echo "<tr class='list-row' href='".$list_row_url."'>\n";
if (permission_exists('device_vendor_edit') || permission_exists('device_vendor_delete')) {
echo " <td class='checkbox'>\n";
echo " <input type='checkbox' name='vendors[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
echo " <input type='hidden' name='vendors[$x][uuid]' value='".escape($row['device_vendor_uuid'])."' />\n";
echo " </td>\n";
}
echo " <td><a href='".$list_row_url."'>".escape($row['name'])."</a>&nbsp;</td>\n";
if (permission_exists('device_vendor_edit')) {
echo "<a href='device_vendor_edit.php?id=".escape($row['device_vendor_uuid'])."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
echo " <td class='no-link center'>";
echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
}
if (permission_exists('device_vendor_delete')) {
echo "<a href='device_vendor_delete.php?id=".escape($row['device_vendor_uuid'])."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
else {
echo " <td class='center'>";
echo $text['label-'.$row['enabled']];
}
echo " <td class='description overflow hide-xs'>".escape($row['description'])."&nbsp;</td>\n";
if (permission_exists('device_vendor_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') {
echo " <td class='action-button'>";
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]);
echo " </td>\n";
}
echo " </td>\n";
echo "</tr>\n";
if ($c==0) { $c=1; } else { $c=0; }
$x++;
}
}
unset($result, $row);
unset($result);
echo "<tr>\n";
echo "<td colspan='4' align='left'>\n";
echo " <table width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='33.3%' nowrap='nowrap'>&nbsp;</td>\n";
echo " <td width='33.3%' align='center' nowrap='nowrap'>$paging_controls</td>\n";
echo " <td class='list_control_icons'>";
if (permission_exists('device_vendor_add')) {
echo "<a href='device_vendor_edit.php' alt='".$text['button-add']."'>$v_link_label_add</a>";
}
else {
echo "&nbsp;";
}
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>";
echo "<br /><br />";
echo "</table>\n";
echo "<br />\n";
echo "<div align='center'>".$paging_controls."</div>\n";
echo "<input type='hidden' name='".$token['name']."' value='".$token['hash']."'>\n";
echo "</form>\n";
//include the footer
require_once "resources/footer.php";
?>
?>

View File

@@ -49,13 +49,6 @@ include "root.php";
//assign private variables
$this->app_name = 'devices';
$this->app_uuid = '4efa1a1a-32e7-bf83-534b-6c8299958a8e';
$this->permission_prefix = 'device_';
$this->list_page = 'devices.php';
$this->table = 'devices';
$this->uuid_prefix = 'device_';
$this->toggle_field = 'device_enabled';
$this->toggle_values = ['true','false'];
}
public function __destruct() {
@@ -285,6 +278,13 @@ include "root.php";
* delete records
*/
public function delete($records) {
//assign private variables
$this->permission_prefix = 'device_';
$this->list_page = 'devices.php';
$this->table = 'devices';
$this->uuid_prefix = 'device_';
if (permission_exists($this->permission_prefix.'delete')) {
//add multi-lingual support
@@ -349,10 +349,147 @@ include "root.php";
}
}
public function delete_vendors($records) {
//assign private variables
$this->permission_prefix = 'device_vendor_';
$this->list_page = 'device_vendors.php';
$this->tables[] = 'device_vendors';
$this->tables[] = 'device_vendor_functions';
$this->tables[] = 'device_vendor_function_groups';
$this->uuid_prefix = 'device_vendor_';
if (permission_exists($this->permission_prefix.'delete')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page);
exit;
}
//delete multiple records
if (is_array($records) && @sizeof($records) != 0) {
//build the delete array
foreach ($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
foreach ($this->tables as $table) {
$array[$table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
}
}
}
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('device_vendor_function_delete', 'temp');
$p->add('device_vendor_function_group_delete', 'temp');
//execute delete
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('device_vendor_function_delete', 'temp');
$p->delete('device_vendor_function_group_delete', 'temp');
//set message
message::add($text['message-delete']);
}
unset($records);
}
}
}
public function delete_profiles($records) {
//assign private variables
$this->permission_prefix = 'device_profile_';
$this->list_page = 'device_profiles.php';
$this->tables[] = 'device_profiles';
$this->tables[] = 'device_profile_keys';
$this->tables[] = 'device_profile_settings';
$this->uuid_prefix = 'device_profile_';
if (permission_exists($this->permission_prefix.'delete')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page);
exit;
}
//delete multiple records
if (is_array($records) && @sizeof($records) != 0) {
//build the delete array
foreach ($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
foreach ($this->tables as $table) {
$array[$table][$x][$this->uuid_prefix.'uuid'] = $record['uuid'];
}
}
}
//delete the checked rows
if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('device_profile_key_delete', 'temp');
$p->add('device_profile_setting_delete', 'temp');
//execute delete
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->delete($array);
unset($array);
//revoke temporary permissions
$p->delete('device_profile_key_delete', 'temp');
$p->delete('device_profile_setting_delete', 'temp');
//set message
message::add($text['message-delete']);
}
unset($records);
}
}
}
/**
* toggle records
*/
public function toggle($records) {
//assign private variables
$this->permission_prefix = 'device_';
$this->list_page = 'devices.php';
$this->table = 'devices';
$this->uuid_prefix = 'device_';
$this->toggle_field = 'device_enabled';
$this->toggle_values = ['true','false'];
if (permission_exists($this->permission_prefix.'edit')) {
//add multi-lingual support
@@ -423,6 +560,295 @@ include "root.php";
}
}
}
public function toggle_vendors($records) {
//assign private variables
$this->permission_prefix = 'device_vendor_';
$this->list_page = 'device_vendors.php';
$this->table = 'device_vendors';
$this->uuid_prefix = 'device_vendor_';
$this->toggle_field = 'enabled';
$this->toggle_values = ['true','false'];
if (permission_exists($this->permission_prefix.'edit')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page);
exit;
}
//toggle the checked records
if (is_array($records) && @sizeof($records) != 0) {
//get current toggle state
foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
}
}
if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
$sql .= "where ( ".implode(' or ', $record_uuids)." ) ";
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
$states[$row['uuid']] = $row['toggle'];
}
}
unset($sql, $parameters, $rows, $row);
}
//build update array
$x = 0;
foreach($states as $uuid => $state) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
$x++;
}
//save the changes
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//set message
message::add($text['message-toggle']);
}
unset($records, $states);
}
}
}
public function toggle_profiles($records) {
//assign private variables
$this->permission_prefix = 'device_profile_';
$this->list_page = 'device_profiles.php';
$this->table = 'device_profiles';
$this->uuid_prefix = 'device_profile_';
$this->toggle_field = 'device_profile_enabled';
$this->toggle_values = ['true','false'];
if (permission_exists($this->permission_prefix.'edit')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page);
exit;
}
//toggle the checked records
if (is_array($records) && @sizeof($records) != 0) {
//get current toggle state
foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
}
}
if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select ".$this->uuid_prefix."uuid as uuid, ".$this->toggle_field." as toggle from v_".$this->table." ";
$sql .= "where ( ".implode(' or ', $record_uuids)." ) ";
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
foreach ($rows as $row) {
$states[$row['uuid']] = $row['toggle'];
}
}
unset($sql, $parameters, $rows, $row);
}
//build update array
$x = 0;
foreach($states as $uuid => $state) {
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $uuid;
$array[$this->table][$x][$this->toggle_field] = $state == $this->toggle_values[0] ? $this->toggle_values[1] : $this->toggle_values[0];
$x++;
}
//save the changes
if (is_array($array) && @sizeof($array) != 0) {
//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//set message
message::add($text['message-toggle']);
}
unset($records, $states);
}
}
}
/**
* copy records
*/
public function copy_profiles($records) {
//assign private variables
$this->permission_prefix = 'device_profile_';
$this->list_page = 'device_profiles.php';
$this->table = 'device_profiles';
$this->uuid_prefix = 'device_profile_';
if (permission_exists($this->permission_prefix.'add')) {
//add multi-lingual support
$language = new text;
$text = $language->get();
//validate the token
$token = new token;
if (!$token->validate($_SERVER['PHP_SELF'])) {
message::add($text['message-invalid_token'],'negative');
header('Location: '.$this->list_page);
exit;
}
//copy the checked records
if (is_array($records) && @sizeof($records) != 0) {
//get checked records
foreach($records as $x => $record) {
if ($record['checked'] == 'true' && is_uuid($record['uuid'])) {
$record_uuids[] = $this->uuid_prefix."uuid = '".$record['uuid']."'";
}
}
//create insert array from existing data
if (is_array($record_uuids) && @sizeof($record_uuids) != 0) {
$sql = "select * from v_".$this->table." ";
$sql .= "where (domain_uuid = :domain_uuid or domain_uuid is null) ";
$sql .= "and ( ".implode(' or ', $record_uuids)." ) ";
$parameters['domain_uuid'] = $_SESSION['domain_uuid'];
$database = new database;
$rows = $database->select($sql, $parameters, 'all');
if (is_array($rows) && @sizeof($rows) != 0) {
$y = $z = 0;
foreach ($rows as $x => $row) {
$primary_uuid = uuid();
//copy data
$array[$this->table][$x] = $row;
//overwrite
$array[$this->table][$x][$this->uuid_prefix.'uuid'] = $primary_uuid;
$array[$this->table][$x]['device_profile_description'] = trim($row['device_profile_description'].' ('.$text['label-copy'].')');
//keys sub table
$sql_2 = "select * from v_device_profile_keys ";
$sql_2 .= "where device_profile_uuid = :device_profile_uuid ";
$sql_2 .= "order by ";
$sql_2 .= "case profile_key_category ";
$sql_2 .= "when 'line' then 1 ";
$sql_2 .= "when 'memort' then 2 ";
$sql_2 .= "when 'programmable' then 3 ";
$sql_2 .= "when 'expansion' then 4 ";
$sql_2 .= "else 100 end, ";
$sql_2 .= "profile_key_id asc ";
$parameters_2['device_profile_uuid'] = $row['device_profile_uuid'];
$database = new database;
$rows_2 = $database->select($sql_2, $parameters_2, 'all');
if (is_array($rows_2) && @sizeof($rows_2) != 0) {
foreach ($rows_2 as $row_2) {
//copy data
$array['device_profile_keys'][$y] = $row_2;
//overwrite
$array['device_profile_keys'][$y]['device_profile_key_uuid'] = uuid();
$array['device_profile_keys'][$y]['device_profile_uuid'] = $primary_uuid;
//increment
$y++;
}
}
unset($sql_2, $parameters_2, $rows_2, $row_2);
//settings sub table
$sql_3 = "select * from v_device_profile_settings where device_profile_uuid = :device_profile_uuid";
$parameters_3['device_profile_uuid'] = $row['device_profile_uuid'];
$database = new database;
$rows_3 = $database->select($sql_3, $parameters_3, 'all');
if (is_array($rows_3) && @sizeof($rows_3) != 0) {
foreach ($rows_3 as $row_3) {
//copy data
$array['device_profile_settings'][$z] = $row_3;
//overwrite
$array['device_profile_settings'][$z]['device_profile_setting_uuid'] = uuid();
$array['device_profile_settings'][$z]['device_profile_uuid'] = $primary_uuid;
//increment
$z++;
}
}
unset($sql_3, $parameters_3, $rows_3, $row_3);
}
}
unset($sql, $parameters, $rows, $row);
}
//save the changes and set the message
if (is_array($array) && @sizeof($array) != 0) {
//grant temporary permissions
$p = new permissions;
$p->add('device_profile_key_add', 'temp');
$p->add('device_profile_setting_add', 'temp');
//save the array
$database = new database;
$database->app_name = $this->app_name;
$database->app_uuid = $this->app_uuid;
$database->save($array);
unset($array);
//revoke temporary permissions
$p->delete('device_profile_key_add', 'temp');
$p->delete('device_profile_setting_add', 'temp');
//set message
message::add($text['message-copy']);
}
unset($records);
}
}
} //method
} //class