#!/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
#
#################################################################
sub weeksago($$$ ) {
my ($y,$m,$d) = @_ ;
$y -= 1900 ;
$m-- ;
my $_now = time() ;
my $_then = $_now ;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime($_then);
if(($y > $year) or
(($y == $year) and ($m > $mon)) or
(($y == $year) and ($m == $mon) and ($d > $mday))) {
return 0 ;
}
while(1) {
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime($_then);
if(($y == $year) and ($m == $mon) and ($d == $mday)) {
return int(( $_now - $_then)/(3600*24*7)) ;
}
$_then -= 3600*24 ;
} ;
}
&P4CGI::SET_HELP_TARGET("userList") ;
# Get user data
my %userData = &P4CGI::p4users() ;
my $WARNING_LEVEL = &P4CGI::UNUSEDUSRWL() ;
$WARNING_LEVEL = 10 unless $WARNING_LEVEL =~ /^\d+$/ ;
my $usertable = "" ;
# Get groups
my @groups ;
&P4CGI::p4call(\@groups, "groups" );
if(@groups > 0) {
my $g = @groups == 1?"group":"groups" ;
my $n = @groups ;
# $usertable .= "$n $g
" ;
$usertable .= &P4CGI::start_framedTable("$n $g") ;
$usertable .= &P4CGI::start_table() ;
$usertable .= &P4CGI::table_header("Group name");
foreach (@groups) {
$usertable .= &P4CGI::table_row(&P4CGI::ahref(-url => "groupView.cgi",
"GROUP=$_",
"HELP=View group info",
$_)) ;
}
$usertable .= &P4CGI::end_table() ;
$usertable .= &P4CGI::end_framedTable() ;
}
my $emailall ;
$usertable .= join("\n",(&P4CGI::start_framedTable(scalar(keys %userData)." users:"),
&P4CGI::start_table("cellpadding=1"),
&P4CGI::table_header("User",
"Name and e-mail",
"Last access"))) ;
my $u ;
foreach $u (sort { uc($a) cmp uc($b) } (keys %userData))
{
my %udata = %{$userData{$u}} ;
my ($user,$email,$name,$lastaccess) = ($u,
$udata{"Email"},
$udata{"FullName"},
$udata{"Access"}) ;
$user = &P4CGI::ahref(-url => "userView.cgi",
"USER=$user",
"HELP=View user info",
$user) ;
$email =~ /\w+\@\w+/ and do {
if(defined $emailall) {
$emailall .= ",$email" ;
} else {
$emailall = "mailto:$email" ;
} ;
$email = &P4CGI::ahref(-url => "mailto:$email",
"HELP=Send email",
$email) ;
} ;
my $weeksOld = "" ;
if($lastaccess =~ /(\d\d\d\d)\/(\d\d)\/(\d\d)/) {
$weeksOld = weeksago($1,$2,$3) ;
if($weeksOld >= $WARNING_LEVEL) {
$weeksOld = "Not used for $weeksOld weeks!" ;
}
else {
$weeksOld = "" ;
}
}
$usertable .= &P4CGI::table_row($user,
"$name $email",
$lastaccess,
$weeksOld) ;
}
$usertable .= &P4CGI::end_table().&P4CGI::end_framedTable() ;
my @legend ;
push @legend ,&P4CGI::buttonCell("$emailall",
"Send email to all users",
"Email all users") ;
print
&P4CGI::start_page("List users and groups",
@legend),
$usertable,
&P4CGI::end_page() ;
#
# That's all folks
#