Portions created by the Initial Developer are Copyright (C) 2008-2018 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; require_once "resources/paging.php"; //check permissions if (permission_exists("user_view") || if_group("superadmin")) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //include the header require_once "resources/header.php"; $document['title'] = $text['title-user_manager']; //set the variables $order_by = check_str($_GET["order_by"]); $order = check_str($_GET["order"]); $search = check_str($_REQUEST["search"]); //get the list of superadmins $superadmins = superadmin_list($db); //get the user group(s) from the database $sql = "select "; $sql .= " ug.*, g.domain_uuid as group_domain_uuid "; $sql .= "from "; $sql .= " v_user_groups as ug, "; $sql .= " v_groups as g "; $sql .= "where "; $sql .= " ug.group_uuid = g.group_uuid "; if (!(permission_exists('user_all') && $_GET['show'] == 'all')) { $sql .= " and ("; $sql .= " g.domain_uuid = '".$domain_uuid."' "; $sql .= " or g.domain_uuid is null "; $sql .= " ) "; $sql .= " and ug.domain_uuid = '".$domain_uuid."' "; } $sql .= "order by "; $sql .= " g.domain_uuid desc, "; $sql .= " g.group_name asc "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(PDO::FETCH_NAMED); if (is_array($result)) { foreach($result as $row) { $user_groups[$row['user_uuid']][] = $row['group_name'].(($row['group_domain_uuid'] != '') ? "@".$_SESSION['domains'][$row['group_domain_uuid']]['domain_name'] : null); } } unset ($sql, $prep_statement); //get the user count from the database $sql = "select count(*) as num_rows from v_users where 1 = 1 "; if (!(permission_exists('user_all') && $_GET['show'] == 'all')) { $sql .= "and domain_uuid = '".$_SESSION['domain_uuid']."' "; } $prep_statement = $db->prepare($sql); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); $total_users = $row['num_rows']; } unset($prep_statement, $row); //get the users from the database (reuse $sql from above) if (strlen($search) > 0) { $search = strtolower($search); $sql .= "and lower(username) = '".$search."' "; } if (strlen($order_by) > 0) { $sql .= "order by ".$order_by." ".$order." "; } $prep_statement = $db->prepare($sql); if ($prep_statement) { $prep_statement->execute(); $row = $prep_statement->fetch(PDO::FETCH_ASSOC); if ($row['num_rows'] > 0) { $num_rows = $row['num_rows']; } else { $num_rows = '0'; } } unset ($prep_statement, $result, $sql); $rows_per_page = ($_SESSION['domain']['paging']['numeric'] != '') ? $_SESSION['domain']['paging']['numeric'] : 50; $param = "search=".escape($search); if (permission_exists('user_all') && $_GET['show'] == 'all') { $param .= "&show=all"; } $page = $_GET['page']; if (strlen($page) == 0) { $page = 0; $_GET['page'] = 0; } list($paging_controls, $rows_per_page, $var_3) = paging($num_rows, $param, $rows_per_page); $offset = $rows_per_page * $page; $sql = "select * from v_contacts as c "; $sql .= "right join v_users u on u.contact_uuid = c.contact_uuid "; $sql .= "inner join v_domains as d on d.domain_uuid = u.domain_uuid "; $sql .= "where 1 = 1 "; if (!(permission_exists('user_all') && $_GET['show'] == 'all')) { $sql .= "and u.domain_uuid = '".$_SESSION['domain_uuid']."' "; } if (strlen($search) > 0) { $sql .= "and lower(u.username) like '%".$search."%' "; } if (strlen($order_by)> 0) { $sql .= "order by ".$order_by." ".$order." "; } else { $sql .= "order by u.username asc "; } $sql .= " limit ".$rows_per_page." offset ".$offset." "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $users = $prep_statement->fetchAll(PDO::FETCH_NAMED); unset ($prep_statement, $sql); //page title and description echo "\n"; echo ""; echo "\n"; echo "\n"; echo ""; echo "\n"; echo ""; echo "\n"; echo "\n"; echo "\n"; //alternate the row style $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; //show the users echo "
".$text['header-user_manager']." (".$num_rows.")"; if (permission_exists('user_all')) { if ($_GET['show'] == 'all') { echo "\n"; echo ""; } else { echo "\n"; } } if (permission_exists('user_import')) { echo "\n"; } echo ""; echo ""; echo "
\n"; echo $text['description-user_manager']."\n"; echo "
\n"; echo "
\n"; echo "
\n"; echo "\n"; if (permission_exists('user_all') && $_GET['show'] == 'all') { echo th_order_by('domain_name', $text['label-domain'], $order_by, $order, '', '', $param); } echo th_order_by('username', $text['label-username'], $order_by, $order); echo "\n"; echo "\n"; echo "\n"; echo th_order_by('user_enabled', $text['label-enabled'], $order_by, $order, '', '', $param); echo "\n"; echo "\n"; if (is_array($users)) { foreach($users as $row) { if (if_superadmin($superadmins, $row['user_uuid']) && !if_group("superadmin")) { //hide } else { $tr_link = (permission_exists('user_edit')) ? "href='user_edit.php?id=".escape($row['user_uuid'])."'" : null; echo "\n"; if (permission_exists('user_all') && $_GET['show'] == 'all') { echo " \n"; } echo " \n"; echo " \n"; echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; if ($c==0) { $c=1; } else { $c=0; } } } //end foreach unset($sql, $users); } //end if results echo "\n"; echo "
".$text['label-groups']."".$text['label-organization']."".$text['label-name'].""; if (permission_exists('user_add')) { if ($_SESSION['limit']['users']['numeric'] == '' || ($_SESSION['limit']['users']['numeric'] != '' && $total_users < $_SESSION['limit']['users']['numeric'])) { echo "".$v_link_label_add.""; } } echo "
".escape($row['domain_name']).""; if (permission_exists('user_edit')) { echo "".escape($row['username']).""; } else { echo escape($row['username']); } echo " "; if (sizeof($user_groups[$row['user_uuid']]) > 0) { echo escape(implode(', ', $user_groups[$row['user_uuid']])); } echo " ".$row['contact_organization']."  ".$row['contact_name_given']." ".$row['contact_name_family']."  "; if ($row['user_enabled'] == 'true') { echo $text['option-true']; } else { echo $text['option-false']; } echo " 
\n"; echo "
\n"; echo $paging_controls."\n"; echo "

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