Rev 196 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/perl# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";close STDERR;open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";#warn "Redirecting errors to ${error_log_path}vorc_error.log";#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }use strict;use cPanelUserConfig;use CGI qw/param cookie header start_html url/;use HTML::Tiny;use tableViewer;use RollerCon;our $h = HTML::Tiny->new( mode => 'html' );my $cookie_string = authenticate (RollerCon::LEAD) || die;our ($EML, $PWD, $LVL) = split /&/, $cookie_string;our $RCAUTH_cookie = CGI::Cookie->new (-name=>'RCAUTH', -value=>"$cookie_string", -expires=>"+30m");my $pageTitle = "User Report";our $DBTABLE = 'v_official';my %COLUMNS = (# colname => [qw(DisplayName N type status)], status -> static | default | <blank>RCid => [qw(ID 5 number )],derby_name => [qw(DerbyName 10 text default )],email => [qw(Email 15 text default )],real_name => [qw(FullName 20 text default )],pronouns => [qw(Pronouns 25 text default )],tshirt => [qw(TShirtSize 30 select default )],phone => [qw(Phone 35 text )],access => [qw(vOrcAccess 40 select )],MVPid => [qw(MVPPass 42 select )],department => [qw(Department 45 select default )],emt_verified => [qw(EMTVerified 46 select )],added => [qw(Added 50 date )],last_login => [qw(LastLogin 55 date )]);my $defaultWhere;if ($LVL < 4 and $ORCUSER->{department}->{VCI} < 2) {$defaultWhere = join " or ", map { 'department like "%'.$_.'%"' } grep { $ORCUSER->{department}->{$_} >= 2 } keys %{$ORCUSER->{department}};$defaultWhere = "($defaultWhere)";}my $ROLE = getAccessLevels;my $DepartmentNames = getDepartments ();# If we need to modify line item values, create a subroutine named "modify_$columnname"# It will receive a hashref to the object lineitem# You can also create specific "filter_column" subroutines...sub modify_department {my $li = shift // "";if ($li->{"department"}) {my $Ds = convertDepartments $li->{"department"};return join $h->br, map { ($Ds->{$_} == 0 and ($ORCUSER->{department}->{$_} > 1 or $LVL > 4)) ? $h->a ({ onClick=>"event.stopPropagation(); window.open('activate_user.pl?RCid=$li->{RCid}&department=$_','Activating User','resizable,height=260,width=370');" }, "$DepartmentNames->{$_} - $ROLE->{$Ds->{$_}}") : "$DepartmentNames->{$_} - $ROLE->{$Ds->{$_}}" } sort keys %{$Ds};} else {return "";}}sub modify_access {my $li = shift // "";my @levels = ($li->{"access"});if ($li->{"department"}) {push @levels, values %{convertDepartments $li->{"department"}};}return $ROLE->{ max @levels };}sub modify_emt_verified {my $li = shift // "";return "" unless exists convertDepartments($li->{"department"})->{EMT};return $li->{"emt_verified"} ? "True" : "False";}# If we need to modify how a filter works, create a subroutine named "filter_$columnname"# It will receive two fields, the field name and the current filter value (if any)sub filter_department {my $colName = shift;my $filter = shift // "";if ($filter) {if ($filter eq "-blank-") {return "($colName = '' or isNull($colName) = 1)";}no strict;if ($filtered_by_access ne "") {return "$colName like \"%$filter-$filtered_by_access%\"";} else {return "$colName like \"%$filter%\"";}} else {my @options = ();my $tmpFormValue = param ("filter-".$colName);push @options, "-blank-" unless $LVL < 4;push @options, ($LVL < 4 and $ORCUSER->{department}->{VCI} < 2) ? grep { $ORCUSER->{department}->{$_} >= 2 } sort keys %{$ORCUSER->{department}} : sort keys %{$DepartmentNames};@options = map { $tmpFormValue eq $_ ?( $h->option ({ selected=>[], value=>$_ }, $_ eq "-blank-" ? $_ : $DepartmentNames->{$_}) ) :( $h->option ({ value=>$_ }, $_ eq "-blank-" ? $_ : $DepartmentNames->{$_}) ) } @options;unshift @options, $tmpFormValue eq "" ? "<option selected></option>" : "<option></option>";my $autoload = param ("autoload") // 1;return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);}}our $filtered_by_access = "";sub filter_access {my $colName = shift;my $filter = shift // "";if ($filter ne "") {$filtered_by_access = $filter;return $filter eq "-1" ? "$colName = $filter" : "($colName = $filter or department like '%$filter%')";} else {my @options = (-1, 0, 1, 2, 3, 4, 5);my $tmpFormValue = param ("filter-".$colName);@options = map { $tmpFormValue eq $_ ?( $h->option ({ selected=>[], value=>$_ }, $ROLE->{$_}) ) :( $h->option ({ value=>$_ }, $ROLE->{$_}) ) } @options;unshift @options, $tmpFormValue eq "" ? "<option selected></option>" : "<option></option>";my $autoload = param ("autoload") // 1;return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);}}sub filter_MVPid {my $colName = shift;my $filter = shift // "";if ($filter) {return $filter =~ /^R-/ ? "$colName = '$filter'" : $filter eq "pass" ? "isnull($colName) = 0" : "isnull($colName) = 1";} else {my @options = ("", "pass", "no pass");my $tmpFormValue = param ("filter-".$colName);@options = map { $tmpFormValue eq $_ ?( $h->option ({ selected=>[] }, $_) ) :( $h->option ( $_) ) } @options;my $autoload = param ("autoload") // 1;return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);}}sub filter_emt_verified {my $colName = shift;my $filter = shift // "";if ($filter ne "") {return join " and ", "department like '%EMT%'", $filter eq "True" ? "$colName = 1" : "$colName = 0";} else {my @options = ("", "True", "False");my $tmpFormValue = param ("filter-".$colName);@options = map { $tmpFormValue eq $_ ?( $h->option ({ selected=>[] }, $_) ) :( $h->option ( $_) ) } @options;my $autoload = param ("autoload") // 1;return $autoload ? $h->select ({ name=>"filter-".$colName, onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-".$colName }, [$h->option (), @options]);}}# Uncomment and update if we want to enable clicking on a row to open a new page.#sub addRowClick {my $t = shift;return "location.href='view_user.pl?RCid=$t->{RCid}'";}# Call the function to print the table view page (with available options)printTablePage ({ Title => $pageTitle,Table => $DBTABLE,Columns => \%COLUMNS,RCAuth => $RCAUTH_cookie,Where => $defaultWhere,DisplayYearSelect => 0,});