diff --git a/app/devices/app_languages.php b/app/devices/app_languages.php index 76a0a1b4a8..d2b852e729 100644 --- a/app/devices/app_languages.php +++ b/app/devices/app_languages.php @@ -7054,4 +7054,30 @@ $text['label-column_name']['zh-cn'] = "列名"; $text['label-column_name']['ja-jp'] = "列名"; $text['label-column_name']['ko-kr'] = "열 이름"; +$text['label-required']['en-us'] = "Required"; +$text['label-required']['en-gb'] = "Required"; +$text['label-required']['ar-eg'] = "مطلوب"; +$text['label-required']['de-at'] = "Erforderlich"; +$text['label-required']['de-ch'] = "Erforderlich"; +$text['label-required']['de-de'] = "Erforderlich"; +$text['label-required']['el-gr'] = "Απαιτείται"; +$text['label-required']['es-cl'] = "Requerido"; +$text['label-required']['es-mx'] = "Requerido"; +$text['label-required']['fr-ca'] = "Requis"; +$text['label-required']['fr-fr'] = "Requis"; +$text['label-required']['he-il'] = "נדרש"; +$text['label-required']['it-it'] = "Necessario"; +$text['label-required']['nl-nl'] = "Vereist"; +$text['label-required']['pl-pl'] = "Wymagany"; +$text['label-required']['pt-br'] = "Obrigatório"; +$text['label-required']['pt-pt'] = "Obrigatório"; +$text['label-required']['ro-ro'] = "Necesar"; +$text['label-required']['ru-ru'] = "Необходимый"; +$text['label-required']['sv-se'] = "Krav"; +$text['label-required']['uk-ua'] = "вимагається"; +$text['label-required']['tr-tr'] = "Gerekli"; +$text['label-required']['zh-cn'] = "必需的"; +$text['label-required']['ja-jp'] = "必要"; +$text['label-required']['ko-kr'] = "필수의"; + ?> diff --git a/app/devices/device_download.php b/app/devices/device_download.php index f0fdda687a..a0933f480c 100644 --- a/app/devices/device_download.php +++ b/app/devices/device_download.php @@ -37,22 +37,56 @@ exit; } +//set the current domain and user information + $domain_name = $_SESSION['domain_name'] ?? ''; + $domain_uuid = $_SESSION['domain_uuid'] ?? ''; + $user_uuid = $_SESSION['user_uuid'] ?? ''; + $user_name = $_SESSION['username'] ?? ''; + +//create database connection and settings object + $database = database::new(); + $settings = new settings(['database' => $database, 'domain_uuid' => $domain_uuid, 'user_uuid' => $user_uuid]); + //add multi-lingual support $language = new text; $text = $language->get(); +//define label + $label_required = $text['label-required']; + //define the functions function array2csv(array &$array) { if (count($array) == 0) { return null; } - ob_start(); - $df = fopen("php://output", 'w'); - fputcsv($df, array_keys(reset($array))); - foreach ($array as $row) { - fputcsv($df, $row); + + //get all headers as first device may not have all columns + $headers = []; + foreach ($array as $device) { + //get the column headers for this device + $columns = array_keys($device); + //check if there are more column headers than previous devices + if (count($columns) > count($headers)) { + //use the device with all columns + $headers = $columns; + } } - fclose($df); + + //find and remove the "|2" that denotes a duplicate header + foreach ($headers as &$header) { + $pos = strpos($header, '|'); + if ($pos !== false) { + $header = substr($header, 0, $pos); + } + } + + ob_start(); + $file_pointer = fopen("php://output", 'w'); + fputcsv($file_pointer, $headers); + foreach ($array as $row) { + fputcsv($file_pointer, $row); + } + fclose($file_pointer); return ob_get_clean(); } @@ -139,30 +173,41 @@ //iterate columns if (is_array($column_group) && @sizeof($column_group) != 0) { + //device_uuid must be exported + $column_group['devices']['device_uuid'] = 'device_uuid'; + $column_names = implode(", ", $column_group['devices']); $sql = "select ".$column_names." from v_devices "; - $sql .= " where domain_uuid = :domain_uuid "; + $sql .= "where domain_uuid = :domain_uuid "; $parameters['domain_uuid'] = $domain_uuid; - $database = new database; $devices = $database->select($sql, $parameters, 'all'); unset($sql, $parameters, $column_names); foreach($column_group as $table_name => $columns) { if ($table_name !== 'devices') { + //device_uuid must be included in child table to match export row + $columns['device_uuid'] = 'device_uuid'; $column_names = implode(", ", $columns); $sql = "select ".$column_names." from v_".$table_name." "; $sql .= " where domain_uuid = :domain_uuid "; $parameters['domain_uuid'] = $domain_uuid; - $database = new database; - $$table_name = $database->select($sql, $parameters, 'all'); + $child_table_result = $database->select($sql, $parameters, 'all'); $x = 0; foreach($devices as $device) { - foreach($$table_name as $row) { + $header_match_count = 1; + //find the matching device within the linked table + foreach($child_table_result as $row) { if ($device['device_uuid'] == $row['device_uuid']) { foreach($row as $key => $value) { - $devices[$x][$key] = $value; + //check for multi-line devices + if ($key != 'device_uuid' && array_key_exists($key, $devices[$x])) { + //create a new key so that we don't overwrite data + $devices[$x][$key . '|' . $header_match_count] = $value; + } else { + $devices[$x][$key] = $value; + } } - break; + $header_match_count++; } } $x++; @@ -221,9 +266,18 @@ $list_row_onclick = "if (!this.checked) { document.getElementById('checkbox_all').checked = false; }"; echo "\n"; echo " \n"; - echo " \n"; + //device_uuid must be selected on devices to avoid duplication on import + if ($table_name == 'devices' && $column_name == 'device_uuid') { + echo " \n"; + } else { + echo " \n"; + } echo " \n"; - echo " ".$column_name.""; + if ($table_name == 'devices' && $column_name == 'device_uuid') { + echo " ".$column_name.""; + } else { + echo " ".$column_name.""; + } echo ""; $x++; } @@ -232,7 +286,7 @@ echo "\n"; } } - + //test the validation //echo " \n"; //echo " \n"; @@ -244,4 +298,4 @@ //include the footer require_once "resources/footer.php"; -?> \ No newline at end of file +?> diff --git a/app/devices/device_imports.php b/app/devices/device_imports.php index f76de89c0a..a6d4337737 100644 --- a/app/devices/device_imports.php +++ b/app/devices/device_imports.php @@ -520,6 +520,7 @@ echo " \n"; echo "
\n"; echo $text['description-import_delimiter']."\n"; diff --git a/app/devices/devices.php b/app/devices/devices.php index 894378d934..2d298c6bb1 100644 --- a/app/devices/devices.php +++ b/app/devices/devices.php @@ -38,6 +38,28 @@ exit; } +//set the current domain and user information + $domain_name = $_SESSION['domain_name'] ?? ''; + $domain_uuid = $_SESSION['domain_uuid'] ?? ''; + $user_uuid = $_SESSION['user_uuid'] ?? ''; + $user_name = $_SESSION['username'] ?? ''; + +//create database connection and settings object + $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(); @@ -56,13 +78,13 @@ if (!empty($action) && !empty($devices) && is_array($devices) && @sizeof($devices) != 0) { switch ($action) { case 'toggle': - if (permission_exists('device_edit')) { + if ($has_device_edit) { $obj = new device; $obj->toggle($devices); } break; case 'delete': - if (permission_exists('device_delete')) { + if ($has_device_delete) { $obj = new device; $obj->delete($devices); } @@ -78,36 +100,46 @@ $order = $_GET["order"] ?? ''; //set the time zone - if (isset($_SESSION['domain']['time_zone']['name'])) { - $time_zone = $_SESSION['domain']['time_zone']['name']; - } - else { - $time_zone = date_default_timezone_get(); - } + $time_zone = $settings->get('domain', 'time_zone', date_default_timezone_get()); //get total devices count from the database $sql = "select count(*) from v_devices "; $sql .= "where domain_uuid = :domain_uuid "; - if (!permission_exists('device_all') && !permission_exists('device_domain_all')) { + if (!$has_device_all && !$has_device_domain_all) { $sql .= "and device_user_uuid = :user_uuid "; - $parameters['user_uuid'] = $_SESSION['user_uuid']; + $parameters['user_uuid'] = $user_uuid; } - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $database = new database; + $parameters['domain_uuid'] = $domain_uuid; $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) { + $rows = $database->select("select domain_uuid, domain_name from v_domains where domain_enabled = 'true'"); + if (!empty($rows)) { + foreach ($rows as $row) { + $domains[$row['domain_uuid']] = $row['domain_name']; + } + } + } + //get the devices profiles $sql = "select * from v_device_profiles "; $sql .= "where domain_uuid = :domain_uuid "; - $parameters['domain_uuid'] = $_SESSION['domain_uuid']; - $database = new database; + $parameters['domain_uuid'] = $domain_uuid; $device_profiles = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //prepare to page the results $sql = "select count(*) from v_devices as d "; - if (isset($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { + if (isset($_GET['show']) && $_GET['show'] == "all" && $has_device_all) { if (!empty($search)) { $sql .= "where "; } @@ -115,7 +147,7 @@ else { $sql .= "where ("; $sql .= " d.domain_uuid = :domain_uuid "; - if (permission_exists('device_all')) { + if ($has_device_all) { $sql .= " or d.domain_uuid is null "; } $sql .= ") "; @@ -160,18 +192,17 @@ $sql .= ") "; $parameters['search'] = '%'.strtolower($search).'%'; } - $database = new database; $num_rows = $database->select($sql, $parameters ?? null, 'column'); unset($sql, $parameters); //prepare to page the results - $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; + $rows_per_page = intval($settings->get('domain', 'paging', 50)); $param = ''; if ($search) { $param = "&search=".$search; $param .= "&fields=".$fields; } - if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { + if (!empty($_GET['show']) && $_GET['show'] == "all" && $has_device_all) { $param .= "&show=all"; } $page = $_GET['page'] ?? 0; @@ -182,9 +213,9 @@ //get the list $sql = "select d.*, d2.device_label as alternate_label, "; $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 .= "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" && permission_exists('device_all')) { + if (isset($_GET['show']) && $_GET['show'] == "all" && $has_device_all) { $sql .= ", v_domains as d3 "; } $sql .= "where ( "; @@ -194,21 +225,21 @@ $sql .= " d.device_uuid = d2.device_uuid "; $sql .= " ) "; $sql .= ") "; - if (isset($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { + if (isset($_GET['show']) && $_GET['show'] == "all" && $has_device_all) { $sql .= " and d.domain_uuid = d3.domain_uuid "; } else { $sql .= "and ("; $sql .= " d.domain_uuid = :domain_uuid "; - if (permission_exists('device_all')) { + if ($has_device_all) { $sql .= " or d.domain_uuid is null "; } $sql .= ") "; $parameters['domain_uuid'] = $domain_uuid; } - if (!permission_exists('device_all') && !permission_exists('device_domain_all')) { + if (!$has_device_all && !$has_device_domain_all) { $sql .= "and d.device_user_uuid = :user_uuid "; - $parameters['user_uuid'] = $_SESSION['user_uuid']; + $parameters['user_uuid'] = $user_uuid; } if (!empty($search)) { $sql .= "and ("; @@ -254,7 +285,6 @@ } $sql .= limit_offset($rows_per_page, $offset); $parameters['time_zone'] = $time_zone; - $database = new database; $devices = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); @@ -281,38 +311,38 @@ echo "
\n"; echo "
".$text['header-devices']." (".$num_rows.")
\n"; echo "
\n"; - if (permission_exists('device_import')) { - echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>$_SESSION['theme']['button_icon_import'],'link'=>'device_imports.php']); + if ($has_device_import) { + echo button::create(['type'=>'button','label'=>$text['button-import'],'icon'=>$settings->get('theme', 'button_icon_import'),'link'=>'device_imports.php']); } - if (permission_exists('device_export')) { - echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>$_SESSION['theme']['button_icon_export'],'link'=>'device_download.php']); + if ($has_device_export) { + echo button::create(['type'=>'button','label'=>$text['button-export'],'icon'=>$settings->get('theme', 'button_icon_export'),'link'=>'device_download.php']); } - if (permission_exists('device_vendor_view')) { + if ($has_device_vendor_view) { echo button::create(['type'=>'button','label'=>$text['button-vendors'],'icon'=>'fax','link'=>'device_vendors.php']); } - if (permission_exists('device_profile_view')) { + if ($has_device_profile_view) { echo button::create(['type'=>'button','label'=>$text['button-profiles'],'icon'=>'clone','link'=>'device_profiles.php']); } - $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'=>$_SESSION['theme']['button_icon_add'],'id'=>'btn_add','style'=>$margin_left,'link'=>'device_edit.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) { + 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 (permission_exists('device_edit') && $devices) { - echo button::create(['type'=>'button','label'=>$text['button-toggle'],'icon'=>$_SESSION['theme']['button_icon_toggle'],'id'=>'btn_toggle','name'=>'btn_toggle','style'=>'display: none; '.($margin_left ?? null),'onclick'=>"modal_open('modal-toggle','btn_toggle');"]); + if ($has_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 (permission_exists('device_delete') && $devices) { - echo button::create(['type'=>'button','label'=>$text['button-delete'],'icon'=>$_SESSION['theme']['button_icon_delete'],'id'=>'btn_delete','name'=>'btn_delete','style'=>'display: none; '.($margin_left ?? null),'onclick'=>"modal_open('modal-delete','btn_delete');"]); + if ($has_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 (permission_exists('device_edit') && $devices) { + if ($has_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 (permission_exists('device_delete') && $devices) { + if ($has_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');"])]); } @@ -353,12 +383,12 @@ echo "\n"; echo "\n"; - if (permission_exists('device_edit') || permission_exists('device_delete')) { + if ($has_device_edit || $has_device_delete) { echo " \n"; } - if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { + if (!empty($_GET['show']) && $_GET['show'] == "all" && $has_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); @@ -372,7 +402,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 (permission_exists('device_edit') && !empty($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + if ($has_device_edit && $settings->get('theme', 'list_row_edit_button', 'false') === 'true') { echo " \n"; } echo "\n"; @@ -388,7 +418,7 @@ } } - if (permission_exists('device_edit')) { + if ($has_device_edit) { $list_row_url = "device_edit.php?id=".urlencode($row['device_uuid']); } @@ -403,17 +433,17 @@ } echo "\n"; - if (permission_exists('device_edit') || permission_exists('device_delete')) { + if ($has_device_edit || $has_device_delete) { echo " \n"; } - if (!empty($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { - echo " \n"; + if (!empty($_GET['show']) && $_GET['show'] == "all" && $has_device_all) { + echo " \n"; } echo " \n"; echo " \n"; if ($device_alternate) { @@ -429,7 +459,7 @@ echo " \n"; echo " \n"; echo " \n"; - if (permission_exists('device_edit')) { + if ($has_device_edit) { echo " \n"; echo " \n"; echo " \n"; - if (permission_exists('device_edit') && !empty($_SESSION['theme']['list_row_edit_button']['boolean']) && $_SESSION['theme']['list_row_edit_button']['boolean'] == 'true') { + if ($has_device_edit && $settings->get('theme', 'list_row_edit_button', 'false') === 'true') { echo " \n"; } echo "\n"; @@ -462,4 +492,4 @@ //include the footer require_once "resources/footer.php"; -?> \ No newline at end of file +?>
\n"; echo " \n"; echo "  
\n"; echo " \n"; echo " \n"; echo " ".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."".escape($domains[$row['domain_uuid']]).""; - echo permission_exists('device_edit') ? "".escape(format_device_address($row['device_address']))."" : escape(format_device_address($row['device_address'])); + echo $has_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'=>$_SESSION['theme']['button_icon_edit'],'link'=>$list_row_url]); + echo button::create(['type'=>'button','title'=>$text['button-edit'],'icon'=>$settings->get('theme','button_icon_edit'),'link'=>$list_row_url]); echo "