diff --git a/app/devices/devices.php b/app/devices/devices.php index 0cdcd0ee61..af2fb3015b 100644 --- a/app/devices/devices.php +++ b/app/devices/devices.php @@ -48,18 +48,6 @@ $database = database::new(); $settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid, 'user_uuid' => $user_uuid]); -//set all permissions - $has_device_import = permission_exists('device_import'); - $has_device_edit = permission_exists('device_edit'); - $has_device_all = permission_exists('device_all'); - $has_device_delete = permission_exists('device_delete'); - $has_device_domain_all = permission_exists('device_domain_all'); - $has_device_export = permission_exists('device_export'); - $has_device_vendor_view = permission_exists('device_vendor_view'); - $has_device_profile_view = permission_exists('device_profile_view'); - $has_device_add = permission_exists('device_add'); - $has_show_all = &$has_device_domain_all; - //add multi-lingual support $language = new text; $text = $language->get(); @@ -78,13 +66,13 @@ if (!empty($action) && !empty($devices) && is_array($devices) && @sizeof($devices) != 0) { switch ($action) { case 'toggle': - if ($has_device_edit) { + if (permission_exists('device_edit')) { $obj = new device; $obj->toggle($devices); } break; case 'delete': - if ($has_device_delete) { + if (permission_exists('device_delete')) { $obj = new device; $obj->delete($devices); } @@ -105,7 +93,7 @@ //get total devices count from the database $sql = "select count(*) from v_devices "; $sql .= "where domain_uuid = :domain_uuid "; - if (!$has_device_all && !$has_device_domain_all) { + if (!permission_exists('device_all') && !permission_exists('device_domain_all')) { $sql .= "and device_user_uuid = :user_uuid "; $parameters['user_uuid'] = $user_uuid; } @@ -113,12 +101,6 @@ $total_devices = $database->select($sql, $parameters, 'column'); unset($sql, $parameters); -//update the has_device_add permission if the total device count is greater then set limit - $device_limit = $settings->get('limit', 'devices', null); - if ($has_device_add && $device_limit !== null) { - $has_device_add = $total_devices > $device_limit; - } - //get the domains if user has permission for show all $domains = []; if ($has_device_domain_all) { @@ -142,7 +124,7 @@ //prepare to page the results $sql = "select count(*) from v_devices as d "; - if (isset($_GET['show']) && $_GET['show'] == "all" && $has_device_all) { + if (isset($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { if (!empty($search)) { $sql .= "where "; } @@ -150,7 +132,7 @@ else { $sql .= "where ("; $sql .= " d.domain_uuid = :domain_uuid "; - if ($has_device_all) { + if (permission_exists('device_all')) { $sql .= " or d.domain_uuid is null "; } $sql .= ") "; @@ -205,7 +187,7 @@ $param = "&search=".$search; $param .= "&fields=".$fields; } - if (!empty($_GET['show']) && $_GET['show'] == "all" && $has_device_all) { + if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { $param .= "&show=all"; } $page = $_GET['page'] ?? 0; @@ -218,7 +200,7 @@ $sql .= "to_char(timezone(:time_zone, d.device_provisioned_date), 'DD Mon YYYY') as provisioned_date_formatted, \n"; $sql .= "to_char(timezone(:time_zone, d.device_provisioned_date), 'HH12:MI:SS am') as provisioned_time_formatted \n"; $sql .= "from v_devices as d, v_devices as d2 "; - if (isset($_GET['show']) && $_GET['show'] == "all" && $has_device_all) { + if (isset($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { $sql .= ", v_domains as d3 "; } $sql .= "where ( "; @@ -228,19 +210,19 @@ $sql .= " d.device_uuid = d2.device_uuid "; $sql .= " ) "; $sql .= ") "; - if (isset($_GET['show']) && $_GET['show'] == "all" && $has_device_all) { + if (isset($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { $sql .= " and d.domain_uuid = d3.domain_uuid "; } else { $sql .= "and ("; $sql .= " d.domain_uuid = :domain_uuid "; - if ($has_device_all) { + if (permission_exists('device_all')) { $sql .= " or d.domain_uuid is null "; } $sql .= ") "; $parameters['domain_uuid'] = $domain_uuid; } - if (!$has_device_all && !$has_device_domain_all) { + if (!permission_exists('device_all') && !permission_exists('device_domain_all')) { $sql .= "and d.device_user_uuid = :user_uuid "; $parameters['user_uuid'] = $user_uuid; } @@ -314,33 +296,33 @@ echo "
\n"; echo "
".$text['header-devices']."
".number_format($num_rows)."
\n"; echo "
\n"; - if ($has_device_import) { + if (permission_exists('device_import')) { echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>$settings->get('theme', 'button_icon_import'),'link'=>'device_imports.php']); } - if ($has_device_export) { + if (permission_exists('device_export')) { echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>$settings->get('theme', 'button_icon_export'),'link'=>'device_download.php']); } - if ($has_device_vendor_view) { + if (permission_exists('device_vendor_view')) { echo button::create(['type'=>'button','label'=>$text['button-vendors'],'icon'=>'fax','link'=>'device_vendors.php']); } - if ($has_device_profile_view) { + if (permission_exists('device_profile_view')) { echo button::create(['type'=>'button','label'=>$text['button-profiles'],'icon'=>'clone','link'=>'device_profiles.php']); } - $margin_left = $has_device_import || $has_device_export || $has_device_vendor_view || $has_device_profile_view ? "margin-left: 15px;" : null; - if ($has_device_add) { + $margin_left = permission_exists('device_import') || permission_exists('device_export') || permission_exists('device_vendor_view') || permission_exists('device_profile_view') ? "margin-left: 15px;" : null; + if (permission_exists('device_add') && (empty($_SESSION['limit']['devices']['numeric']) || ($total_devices < $_SESSION['limit']['devices']['numeric']))) { echo button::create(['type'=>'button','label'=>$text['button-add'],'icon'=>$settings->get('theme', 'button_icon_add'),'id'=>'btn_add','style'=>$margin_left,'link'=>'device_edit.php']); unset($margin_left); } - if ($has_device_edit && $devices) { + if (permission_exists('device_edit') && $devices) { echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$settings->get('theme', 'button_icon_toggle'),'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display: none; '.($margin_left ?? null),'onclick'=>"modal_open('modal-toggle','btn_toggle');"]); unset($margin_left); } - if ($has_device_delete && $devices) { + if (permission_exists('device_delete') && $devices) { echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$settings->get('theme', 'button_icon_delete'),'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; '.($margin_left ?? null),'onclick'=>"modal_open('modal-delete','btn_delete');"]); unset($margin_left); } echo "
\n"; - if ($has_device_edit && $devices) { + if (permission_exists('device_edit') && $devices) { echo modal::create(['id'=>'modal-toggle','type'=>'toggle','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_toggle','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('toggle'); list_form_submit('form_list');"])]); } - if ($has_device_delete && $devices) { + if (permission_exists('device_delete') && $devices) { echo modal::create(['id'=>'modal-delete','type'=>'delete','actions'=>button::create(['type'=>'button','label'=>$text['button-continue'],'icon'=>'check','id'=>'btn_delete','style'=>'float: right; margin-left: 15px;','collapse'=>'never','onclick'=>"modal_close(); list_action_set('delete'); list_form_submit('form_list');"])]); } @@ -387,12 +369,12 @@ echo "
\n"; echo "\n"; echo "\n"; - if ($has_device_edit || $has_device_delete) { + if (permission_exists('device_edit') || permission_exists('device_delete')) { echo " \n"; } - if (!empty($_GET['show']) && $_GET['show'] == "all" && $has_device_all) { + if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, null, null, $param); } echo th_order_by('device_address', $text['label-device_address'], $order_by, $order, null, null, $param ?? null); @@ -406,7 +388,7 @@ echo th_order_by('device_enabled', $text['label-device_enabled'], $order_by, $order, null, "class='center'", $param ?? null); echo th_order_by('device_provisioned_date', $text['label-device_status'], $order_by, $order, null, null, $param ?? null); echo th_order_by('device_description', $text['label-device_description'], $order_by, $order, null, "class='hide-sm-dn'", $param ?? null); - if ($has_device_edit && $settings->get('theme', 'list_row_edit_button', 'false') === 'true') { + if (permission_exists('device_edit') && $settings->get('theme', 'list_row_edit_button', false)) { echo " \n"; } echo "\n"; @@ -422,7 +404,7 @@ } } - if ($has_device_edit) { + if (permission_exists('device_edit')) { $list_row_url = "device_edit.php?id=".urlencode($row['device_uuid']); } @@ -437,17 +419,17 @@ } echo "\n"; - if ($has_device_edit || $has_device_delete) { + if (permission_exists('device_edit') || permission_exists('device_delete')) { echo " \n"; } - if (!empty($_GET['show']) && $_GET['show'] == "all" && $has_device_all) { + if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { echo " \n"; } echo " \n"; echo " \n"; if ($device_alternate) { @@ -463,7 +445,7 @@ echo " \n"; echo " \n"; echo " \n"; - if ($has_device_edit) { + if (permission_exists('device_edit')) { echo " \n"; echo " \n"; echo " \n"; - if ($has_device_edit && $settings->get('theme', 'list_row_edit_button', false)) { + if (permission_exists('device_edit') && $settings->get('theme', 'list_row_edit_button', false)) { echo " \n";
\n"; echo " \n"; echo "  
\n"; echo " \n"; echo " \n"; echo " ".escape($domains[$row['domain_uuid']]).""; - echo $has_device_edit ? "".escape(format_device_address($row['device_address']))."" : escape(format_device_address($row['device_address'])); + echo permission_exists('device_edit') ? "".escape(format_device_address($row['device_address']))."" : escape(format_device_address($row['device_address'])); echo " ".escape($row['device_label'])." ".escape($row['device_vendor'])." ".escape($row['device_template'])." ".escape($device_profile_name)." ".escape($row['device_description'])." "; echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$settings->get('theme','button_icon_edit'),'link'=>$list_row_url]); echo "