Fix the device ADD button.
Also, permission_exists function uses the permission::new() method and this made it efficient enough to continue to use the permission_exists function.
This commit is contained in:
parent
075cc4824a
commit
2cd94a93a5
|
|
@ -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 "<div class='action_bar' id='action_bar'>\n";
|
||||
echo " <div class='heading'><b>".$text['header-devices']."</b><div class='count'>".number_format($num_rows)."</div></div>\n";
|
||||
echo " <div class='actions'>\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 "<form id='form_search' class='inline' method='get'>\n";
|
||||
if ($has_device_all) {
|
||||
if (permission_exists('device_all')) {
|
||||
if (!empty($_GET['show']) && $_GET['show'] == 'all') {
|
||||
echo " <input type='hidden' name='show' value='all'>";
|
||||
}
|
||||
|
|
@ -369,10 +351,10 @@
|
|||
echo " <div style='clear: both;'></div>\n";
|
||||
echo "</div>\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 "<div class='card'>\n";
|
||||
echo "<table class='list'>\n";
|
||||
echo "<tr class='list-header'>\n";
|
||||
if ($has_device_edit || $has_device_delete) {
|
||||
if (permission_exists('device_edit') || permission_exists('device_delete')) {
|
||||
echo " <th class='checkbox'>\n";
|
||||
echo " <input type='checkbox' id='checkbox_all' name='checkbox_all' onclick='list_all_toggle(); checkbox_on_change(this);' ".(empty($devices) ? "style='visibility: hidden;'" : null).">\n";
|
||||
echo " </th>\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 " <td class='action-button'> </td>\n";
|
||||
}
|
||||
echo "</tr>\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 "<tr class='list-row' href='".$list_row_url."'>\n";
|
||||
if ($has_device_edit || $has_device_delete) {
|
||||
if (permission_exists('device_edit') || permission_exists('device_delete')) {
|
||||
echo " <td class='checkbox'>\n";
|
||||
echo " <input type='checkbox' name='devices[$x][checked]' id='checkbox_".$x."' value='true' onclick=\"checkbox_on_change(this); if (!this.checked) { document.getElementById('checkbox_all').checked = false; }\">\n";
|
||||
echo " <input type='hidden' name='devices[$x][uuid]' value='".escape($row['device_uuid'])."' />\n";
|
||||
echo " </td>\n";
|
||||
}
|
||||
if (!empty($_GET['show']) && $_GET['show'] == "all" && $has_device_all) {
|
||||
if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) {
|
||||
echo " <td>".escape($domains[$row['domain_uuid']])."</td>\n";
|
||||
}
|
||||
echo " <td class='no-wrap'>";
|
||||
echo $has_device_edit ? "<a href='".$list_row_url."'>".escape(format_device_address($row['device_address']))."</a>" : escape(format_device_address($row['device_address']));
|
||||
echo permission_exists('device_edit') ? "<a href='".$list_row_url."'>".escape(format_device_address($row['device_address']))."</a>" : escape(format_device_address($row['device_address']));
|
||||
echo " </td>\n";
|
||||
echo " <td>".escape($row['device_label'])." </td>\n";
|
||||
if ($device_alternate) {
|
||||
|
|
@ -463,7 +445,7 @@
|
|||
echo " <td>".escape($row['device_vendor'])." </td>\n";
|
||||
echo " <td>".escape($row['device_template'])." </td>\n";
|
||||
echo " <td>".escape($device_profile_name)." </td>\n";
|
||||
if ($has_device_edit) {
|
||||
if (permission_exists('device_edit')) {
|
||||
echo " <td class='no-link center'>";
|
||||
echo button::create(['type'=>'submit','class'=>'link','label'=>$text['label-'.$row['device_enabled']],'title'=>$text['button-toggle'],'onclick'=>"list_self_check('checkbox_".$x."'); list_action_set('toggle'); list_form_submit('form_list')"]);
|
||||
}
|
||||
|
|
@ -474,7 +456,7 @@
|
|||
echo " </td>\n";
|
||||
echo " <td class='no-link'><a title='".escape($row['device_provisioned_agent'])."' href='javascript:void(0)'>".escape($row['provisioned_date_formatted'])." ".escape($row['provisioned_time_formatted'])."</a> ".escape($device_provisioned_method)." <a href='".escape($device_provisioned_method)."://".escape($row['device_provisioned_ip'])."' target='_blank'>".escape($row['device_provisioned_ip'])."</a> </td>\n";
|
||||
echo " <td class='description overflow hide-sm-dn'>".escape($row['device_description'])." </td>\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 " <td class='action-button'>";
|
||||
echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$settings->get('theme','button_icon_edit'),'link'=>$list_row_url]);
|
||||
echo " </td>\n";
|
||||
|
|
|
|||
Loading…
Reference in New Issue