#!/usr/bin/perl -w
# -*- perl -*-
use P4CGI ;
use strict ;
#
#################################################################
#  CONFIGURATION INFORMATION 
#  All config info should be in P4CGI.pm
#
#################################################################
#
#  P4 list all users
#  List p4 users
#
#################################################################

# Get users
my @users ;
&P4CGI::p4call(\@users, "users" );

my $emailall ;
my $usertable ;
$usertable  =  &P4CGI::start_table("cellpadding=1") ;
$usertable .=  &P4CGI::table_row("-type","th",
				 "-align","left",
				 "User","Name","e-mail address","Last access");

my $userinfo ;
foreach $userinfo (sort { uc($a) cmp uc($b) } @users)
{
    $userinfo =~ /(\w+)\s+\<(.*)\>\s+\((.*)\) accessed (\S+)/ and do {
	my ($user,$email,$name,$lastaccess) = ($1,$2,$3,$4) ;
	$user = &P4CGI::ahref(-url => &P4CGI::LU_URL(),
			      "USER=$user",
			      $user) ;
	$email =~ /\w+\@\w+/ and do {
	    if(defined $emailall) {
		$emailall .= ",$email" ;
	    } else {
		$emailall .= "mailto:$email" ;
	    } ;
	    $email = &P4CGI::ahref(-url => "mailto:$email",
				    $email) ;
	} ;
	$usertable .= &P4CGI::table_row($user,
					$name,
					$email,
					$lastaccess) ;	
    }
}
$usertable .= &P4CGI::end_table() ;

print "",
    &P4CGI::start_page("P4 users",
		       &P4CGI::ul_list("<b>user</b> -- see more info",
				       "<b>e-mail address</b> -- e-mail user",
				       &P4CGI::ahref(-url => $emailall,
						     "<b>Mail all users</b>"))),
    "<B>",
    scalar(@users),
    " users:<br></B>",
    $usertable,
    &P4CGI::end_page() ;

#
# That's it folks
#