<?php
# ---------------------------------------------------------------------
# truc is a tool for requirement and use case tracking
# Copyright (C) 2006 ASDIS - http://sf.net/projects/truc
#
# (rth) Initial truc version based on rth
#       Copyright (C) 2005 George Holbrook - rth@lists.sourceforge.net
#
# This program is distributed under the terms and conditions of the GPL
# See the README and LICENSE files for details
#----------------------------------------------------------------------
define('NO_FOLDER_VIEW',true);
include"./api/include_api.php";
auth_authenticate_user();

$page                   = basename(__FILE__);
$delete_page			= 'delete_page.php';
$redirect_url			= $page;

$s_project_properties   = session_get_project_properties();
$project_name           = $s_project_properties['project_name'];
$project_id 			= $s_project_properties['project_id'];

$s_user_properties		= session_get_user_properties();
$user_id				= $s_user_properties['user_id'];
$row_style              = '';

$s_user_manage_display_options	= session_set_display_options("user_manage", $_POST);
$order_by						= $s_user_manage_display_options['order_by'];
$order_dir						= $s_user_manage_display_options['order_dir'];
$page_number					= $s_user_manage_display_options['page_number'];

html_window_title();
html_print_body();
html_page_title($project_name ." - ". lang_get('user_manage_page') );
html_page_header( $db, $project_name );
html_print_menu();
admin_user_print( $page, $project_id, $user_id );

print"<br>\n";

print"<div align=center>\n";

print"<form method=post action='$page'>\n";
print"<table class=hide80>\n";
print"<tr>\n";
print"<td>\n";
$users	= user_get_all($order_by, $order_dir, $page_number);
print"</td>\n";
print"</tr>\n";
print"</table>\n";
print"</form>\n";

print"<table class=width80 rules=cols>\n";

print"<tr>\n";
html_tbl_print_header( lang_get('id'),			USER_ID,	$order_by, $order_dir, $page );
html_tbl_print_header( lang_get('username'),	USER_UNAME,	$order_by, $order_dir, $page );
html_tbl_print_header( lang_get('first_name'),	USER_FNAME,	$order_by, $order_dir, $page );
html_tbl_print_header( lang_get('last_name'),	USER_LNAME, $order_by, $order_dir, $page );
html_tbl_print_header( lang_get('email'),		USER_EMAIL, $order_by, $order_dir, $page );
if( user_has_rights( $project_id, $user_id, ADMIN ) ) {
	html_tbl_print_header( lang_get('edit') );
	html_tbl_print_header( lang_get('delete') );
}
print"</tr>\n";

foreach($users as $user_row) {

	$row_user_id	= util_pad_id($user_row[USER_ID]);
	$row_username	= $user_row[USER_UNAME];
	$row_first_name	= $user_row[USER_FNAME];
	$row_last_name	= $user_row[USER_LNAME];
	$row_user_email	= $user_row[USER_EMAIL];

	$row_style = html_tbl_alternate_bgcolor($row_style);
	print"<tr class='$row_style'>\n";
	print"<td>$row_user_id</td>\n";
	print"<td>$row_username</td>\n";
	print"<td>$row_first_name</td>\n";
	print"<td>$row_last_name</td>\n";
	print"<td>$row_user_email</td>\n";

	if ( user_has_rights($project_id, $user_id, ADMIN) ) {
		print"<td>\n";
		print"<a href='user_edit_account_page.php?user_id=$row_user_id'>Edit</a>";
		print"</td>\n";

		print"<td>\n";
			print"<form method=post action='$delete_page'>\n";
			print"<input type='submit' name='delete_project' value='". lang_get( 'delete' ) ."' class='page-numbers'>\n";
			print"<input type='hidden' name='r_page' value='$redirect_url'>\n";
			print"<input type='hidden' name='f' value='delete_user'>\n";
			print"<input type='hidden' name='id' value='".$user_row[USER_ID]."'>\n";
			print"<input type='hidden' name='msg' value='". DEL_USER ."'>\n";
			print"</form>\n";
		print"</td>\n";
	}

	print"</tr>\n";
}

print"</table>\n";
print"</div>\n";
html_print_footer();
?>