Copyright (C) 2008-2015 All Rights Reserved. Contributor(s): Mark J Crane */ //includes require_once "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; //check permissions if (permission_exists('device_view')) { //access granted } else { echo "access denied"; exit; } //additional includes require_once "resources/header.php"; require_once "resources/paging.php"; //add multi-lingual support $language = new text; $text = $language->get(); //get the http values and set them as variables $search = $_GET["search"]; $order_by = $_GET["order_by"]; $order = $_GET["order"]; //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')) { $sql .= "and device_user_uuid = :user_uuid "; $parameters['user_uuid'] = $_SESSION['user_uuid']; } $parameters['domain_uuid'] = $_SESSION['domain_uuid']; $database = new database; $total_devices = $database->select($sql, $parameters, 'column'); unset($sql, $parameters); //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; $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 (strlen($search) > 0) { $sql .= "where "; } } else { $sql .= "where ("; $sql .= " d.domain_uuid = :domain_uuid "; if (permission_exists('device_all')) { $sql .= " or d.domain_uuid is null "; } $sql .= ") "; if (strlen($search) > 0) { $sql .= "and "; } $parameters['domain_uuid'] = $domain_uuid; } if (strlen($search) > 0) { $sql .= "("; $sql .= " lower(d.device_mac_address) like :search "; $sql .= " or lower(d.device_label) like :search "; $sql .= " or lower(d.device_vendor) like :search "; $sql .= " or lower(d.device_enabled) like :search "; $sql .= " or lower(d.device_template) like :search "; $sql .= " or lower(d.device_description) like :search "; $sql .= " or lower(d.device_provisioned_method) like :search "; $sql .= " or lower(d.device_provisioned_ip) like :search "; $sql .= ") "; $parameters['search'] = '%'.strtolower($search).'%'; } $database = new database; $num_rows = $database->select($sql, $parameters, 'column'); unset($sql, $parameters); //prepare to page the results $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; if (isset($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { $param = "&search=".$search."&show=all"; } else { $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); $offset = $rows_per_page * $page; //get the list $sql = "select d.*, d2.device_label as alternate_label "; $sql .= "from v_devices as d, v_devices as d2 "; $sql .= "where ( "; $sql .= " d.device_uuid_alternate = d2.device_uuid "; $sql .= " or d.device_uuid_alternate is null and d.device_uuid = d2.device_uuid "; $sql .= ") "; if (isset($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { //echo __line__."
\n"; } else { $sql .= "and ("; $sql .= " d.domain_uuid = :domain_uuid "; if (permission_exists('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')) { $sql .= "and d.device_user_uuid = :user_uuid "; $parameters['user_uuid'] = $_SESSION['user_uuid']; } if (strlen($search) > 0) { $sql .= "and ("; $sql .= " lower(d.device_mac_address) like :search "; $sql .= " or lower(d.device_label) like :search "; $sql .= " or lower(d.device_vendor) like :search "; $sql .= " or lower(d.device_enabled) like :search "; $sql .= " or lower(d.device_template) like :search "; $sql .= " or lower(d.device_description) like :search "; $sql .= " or lower(d.device_provisioned_method) like :search "; $sql .= " or lower(d.device_provisioned_ip) like :search "; $sql .= ") "; $parameters['search'] = '%'.strtolower($search).'%'; } if (strlen($order_by) == 0) { $sql .= "order by d.device_label, d.device_description asc "; } else { $sql .= "order by $order_by $order "; } $sql .= limit_offset($rows_per_page, $offset); $database = new database; $devices = $database->select($sql, $parameters, 'all'); unset($sql, $parameters); //alternate_found $device_alternate = false; foreach($devices as $row) { if (is_uuid($row['device_uuid_alternate'])) { $device_alternate = true; break; } } //show the content echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "
\n"; echo " ".$text['header-devices']." (".$total_devices.")\n"; echo " \n"; echo "
\n"; if (permission_exists('device_all')) { if (isset($_GET['show']) && $_GET['show'] == 'all') { echo " \n"; } else { echo " \n"; } } if (permission_exists('device_vendor_view')) { echo " \n"; } if (permission_exists('device_profile_view')) { echo " \n"; } if (permission_exists('device_import')) { echo " \n"; } if (permission_exists('device_export')) { echo " \n"; } echo " \n"; echo " \n"; echo "
\n"; echo "
\n"; echo " ".$text['description-devices']; echo "
\n"; echo "
\n"; $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; echo "\n"; echo "\n"; if (isset($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, $param); } echo th_order_by('device_mac_address', $text['label-device_mac_address'], $order_by, $order); echo th_order_by('device_label', $text['label-device_label'], $order_by, $order); if ($device_alternate) { echo th_order_by('device_template', $text['label-device_uuid_alternate'], $order_by, $order); } echo th_order_by('device_vendor', $text['label-device_vendor'], $order_by, $order); echo th_order_by('device_template', $text['label-device_template'], $order_by, $order); echo "\n"; echo th_order_by('device_enabled', $text['label-device_enabled'], $order_by, $order); echo th_order_by('device_status', $text['label-device_status'], $order_by, $order); echo th_order_by('device_description', $text['label-device_description'], $order_by, $order); echo "\n"; echo "\n"; if (is_array($devices) && @sizeof($devices) != 0) { foreach($devices as $row) { $device_profile_name = ''; foreach($device_profiles as $profile) { if ($profile['device_profile_uuid'] == $row['device_profile_uuid']) { $device_profile_name = $profile['device_profile_name']; } } $tr_link = (permission_exists('device_edit')) ? "href='device_edit.php?id=".escape($row['device_uuid'])."'" : null; echo "\n"; if (isset($_GET['show']) && $_GET['show'] == "all" && permission_exists('device_all')) { echo " \n"; } echo " \n"; echo " \n"; if ($device_alternate) { echo " \n"; } echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; if ($c==0) { $c=1; } else { $c=0; } } } unset($devices, $row); echo "\n"; echo "
". $text['label-device_profiles']."\n"; if (permission_exists('device_add')) { if ($_SESSION['limit']['devices']['numeric'] == '' || ($_SESSION['limit']['devices']['numeric'] != '' && $total_devices < $_SESSION['limit']['devices']['numeric'])) { echo " ".$v_link_label_add."\n"; } } else { echo "  \n"; } echo "
".escape($_SESSION['domains'][$row['domain_uuid']]['domain_name'])."\n"; echo (permission_exists('device_edit')) ? "".format_mac(escape($row['device_mac_address']))."" : format_mac(escape($row['device_mac_address'])); echo " ".escape($row['device_label'])." \n"; if (strlen($row['device_uuid_alternate']) > 0) { echo " ".escape($row['alternate_label'])."\n"; } echo " ".escape($row['device_vendor'])." ".escape($row['device_template'])." ".escape($device_profile_name)." ".$text['label-'.escape($row['device_enabled'])]." ".escape($row['device_provisioned_date'])." - ".escape($row['device_provisioned_method'])." - ".escape($row['device_provisioned_ip'])." ".escape($row['device_description'])." \n"; if (permission_exists('device_edit')) { echo "$v_link_label_edit\n"; } if (permission_exists('device_delete')) { echo "$v_link_label_delete\n"; } echo "
\n"; echo "
\n"; echo $paging_controls."\n"; echo "

\n"; //include the footer require_once "resources/footer.php"; ?>