userList.cgi #5

  • //
  • guest/
  • fredric_fredricson/
  • P4DB/
  • main/
  • userList.cgi
  • View
  • Commits
  • Open Download .zip Download (3 KB)
#!/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 .=  "<B>$n $g</B><br>" ;
    $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 = "<b>Not used for $weeksOld weeks!</b>" ;
	}
	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
#
# Change User Description Committed
#5 4998 Fredric Fredricson P4DB: cleaned up some code.
Added p4users(), p4client() and p4user2name() to P4CGI.pm and modified
all cgi:s to use these,
#4 4046 Fredric Fredricson P4DB: First submit for 3.1.
* Removed frame-stuff and some related files
* Added new page header
* Started update of documentation
* Changed a lot of CGI:s to conform to new "look and feel"
Still a lot to do:
- clean up stuff (especially the javascript)
- Fix the file list to use new annotate-command
- Clean up and document css-file
- and more.......
#3 2875 Fredric Fredricson P4DB 3.0 first beta...
#2 1920 Fredric Fredricson P4DB: Mainly some user interface fixes:
* Added a small arrow that points to selection in list of options
* Added tooltip help
* Added user prefereces to turn the above off (or on)
* Some other user interface fixes
And fixed a bug in jobList.cgi and some minor bugs in label and branch
viewers.
#1 1638 Fredric Fredricson P4DB: Added all (I think) files for P4DB