diff --git a/app/devices/device_profile_edit.php b/app/devices/device_profile_edit.php index fc5c19d409..587d71e73c 100644 --- a/app/devices/device_profile_edit.php +++ b/app/devices/device_profile_edit.php @@ -663,24 +663,13 @@ } echo "\n"; - echo "\n"; + echo "\n"; echo " ".$text['label-device_profile_enabled']."\n"; echo "\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-device_profile_enabled']."\n"; diff --git a/app/devices/device_profiles.php b/app/devices/device_profiles.php index dfe49b25d1..20f51cd1ae 100644 --- a/app/devices/device_profiles.php +++ b/app/devices/device_profiles.php @@ -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 "\n"; +//include the header + require_once "resources/header.php"; //show the content - echo "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; + echo ""; + 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 " \n"; + echo "".$paging_controls_mini.""; } - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['title-device_profiles']." (".$num_rows.")\n"; - echo "
\n"; - + echo "
\n"; + echo "
".$text['title-device_profiles']." (".$num_rows.")
\n"; + echo "
\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 "\n"; if (permission_exists('device_profile_all')) { if ($_GET['show'] == 'all') { echo " "; } else { - echo " \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 " "; - } - echo " \n"; - echo " \n"; - echo "
".$paging_controls_mini."
\n"; - echo " ".$text['description-device_profiles']."

\n"; - echo "
\n"; + echo " \n"; + echo " \n"; + echo "
\n"; + echo "\n"; - echo "
\n"; - echo "\n"; - echo "\n"; - //echo " \n"; + echo $text['description-device_profiles']."\n"; + echo "

\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + + echo "
\n"; - //echo " \n"; - //echo "
\n"; + echo "\n"; + if (permission_exists('device_profile_add') || permission_exists('device_profile_edit') || permission_exists('device_profile_delete')) { + echo " \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 " \n"; } - else { - echo " \n"; - } - echo " \n"; echo "\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 "\n"; + if (permission_exists('device_profile_add') || permission_exists('device_profile_edit') || permission_exists('device_profile_delete')) { + echo " \n"; } - echo "\n"; - //echo " \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 " \n"; + echo " \n"; } - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; + if (permission_exists('device_profile_edit')) { + echo " \n"; + echo " \n"; + if (permission_exists('device_profile_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo " \n"; + } echo "\n"; $x++; - if ($c==0) { $c=1; } else { $c=0; } - } //end foreach - unset($sql, $device_profiles); - } //end if results + } + unset($device_profiles); + } + + echo "
\n"; + echo " \n"; + echo " "; - if (permission_exists('device_profile_add')) { - echo " $v_link_label_add"; + 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 "  
\n"; + echo " \n"; + echo " \n"; + echo "
".escape($domain)."".escape($domain)."".escape($row['device_profile_name'])." ".escape($row['device_profile_enabled'])." ".escape($row['device_profile_description'])." "; + echo " "; if (permission_exists('device_profile_edit')) { - echo "$v_link_label_edit"; + echo " ".escape($row['device_profile_name'])."\n"; } - if (permission_exists('device_profile_delete')) { - echo " ".$v_link_label_delete."\n"; + else { + echo " ".escape($row['device_profile_name'])."\n"; } echo " "; + echo $text['label-'.$row['device_profile_enabled']]; + } + echo " ".escape($row['device_profile_description'])." "; + echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); + echo "
\n"; + echo "
\n"; + echo "
".$paging_controls."
\n"; + + echo "\n"; - echo "\n"; - echo " \n"; - echo "
\n"; - echo " ".$paging_controls; - echo " \n"; - echo "\n"; - echo ""; echo "
\n"; - echo "

"; //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file diff --git a/app/devices/device_vendor_edit.php b/app/devices/device_vendor_edit.php index 7163b5ca2b..9544f582e2 100644 --- a/app/devices/device_vendor_edit.php +++ b/app/devices/device_vendor_edit.php @@ -167,24 +167,13 @@ echo "\n"; echo "\n"; - echo "\n"; + echo "\n"; echo " ".$text['label-enabled']."\n"; echo "\n"; echo "\n"; echo " \n"; echo "
\n"; echo $text['description-enabled']."\n"; diff --git a/app/devices/device_vendors.php b/app/devices/device_vendors.php index ddf665d2f7..5a6fca83f6 100644 --- a/app/devices/device_vendors.php +++ b/app/devices/device_vendors.php @@ -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 "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
".$text['title-device_vendors']."
\n"; - if (permission_exists('device_vendor_restore')) { - echo " "; - } - echo " "; - echo " \n"; - echo " \n"; - echo "
\n"; - echo " ".$text['description-device_vendor']."

\n"; - echo "
\n"; - - echo "\n"; - echo "\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 "\n"; - echo "\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 "\n"; + echo ""; + 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 "".$paging_controls_mini.""; + } + 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 " \n"; + echo " \n"; + echo "
\n"; + echo "\n"; + + echo $text['description-device_vendor']."\n"; + echo "

\n"; + + echo "\n"; + echo "\n"; + echo "\n"; + + + echo "
"; + echo "
\n"; + echo "
".$text['title-device_vendors']." (".$num_rows.")
\n"; + echo "
\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 "$v_link_label_add"; + echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$_SESSION['theme']['button_icon_add'],'link'=>'device_vendor_edit.php']); } - else { - echo " \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 "
\n"; + echo "\n"; + if (permission_exists('device_vendor_edit') || permission_exists('device_vendor_delete')) { + echo " \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 " \n"; + } + echo "\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 "\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; + if (permission_exists('device_vendor_edit') || permission_exists('device_vendor_delete')) { + echo " \n"; + } + echo " \n"; if (permission_exists('device_vendor_edit')) { - echo "$v_link_label_edit"; + echo " \n"; + if (permission_exists('device_vendor_edit') && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + echo " \n"; } - echo " \n"; echo "\n"; - if ($c==0) { $c=1; } else { $c=0; } + $x++; } } - unset($result, $row); + unset($result); - echo "\n"; - echo "\n"; - echo "\n"; - echo "
\n"; + echo " \n"; + echo "  
".escape($row['name'])." ".escape($row['enabled'])." ".escape($row['description'])." "; + echo "
\n"; + echo " \n"; + echo " \n"; + echo " ".escape($row['name'])." "; + echo $text['label-'.$row['enabled']]; + } + echo " ".escape($row['description'])." "; + echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); + echo "
\n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo " \n"; - echo "
 $paging_controls"; - if (permission_exists('device_vendor_add')) { - echo "$v_link_label_add"; - } - else { - echo " "; - } - echo "
\n"; - echo "
"; - echo "

"; + echo "\n"; + echo "
\n"; + echo "
".$paging_controls."
\n"; + + echo "\n"; + + echo "\n"; //include the footer require_once "resources/footer.php"; -?> +?> \ No newline at end of file diff --git a/app/devices/resources/classes/device.php b/app/devices/resources/classes/device.php index f76fcbedc0..0382c8d47f 100644 --- a/app/devices/resources/classes/device.php +++ b/app/devices/resources/classes/device.php @@ -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