#!/usr/bin/perl # # $Id: sadmin.pl,v 1.12 2006/11/28 21:07:48 psims Exp $ # # Source File: sadmin.pl #use strict; use warnings; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); #warningsToBrowser(1); #fatalsToBrowser(1); # Get config require 'sitecfg.pl'; require 'testlib.pl'; &app_initialize; print "Content-Type: text/html\n\n"; #print $logroot; my $tid = $FORM{'tid'}; if (&get_session($tid)) { &LanguageSupportInit(); unless ($SESSION{'clid'}) { warn "ERROR: Empty Client ID in Session data for Session ID $FORM{'tid'} " ; #&show_illegal_access_warning("user"); exit(); } if ($SESSION{'clid'} ne 'std') { &get_client_profile($SESSION{'clid'}); unless (%CLIENT) { warn "ERROR: Invalid Client ID $SESSION{'clid'} in Session ID $FORM{'tid'} " ; #&show_illegal_access_warning("user"); exit(); } if ($SESSION{'uac'} eq 'admin' || $SESSION{'uac'} eq 'madmin') { $FORM{'pageid'} = "Group"; $FORM{'PAGEID'} = "GROUP"; $mainttmplt = "frgrpadmin"; } else { &get_candidate_profile($SESSION{'clid'}, $SESSION{'uid'}); unless (%CANDIDATE) { warn "ERROR: Invalid Candidate ID $SESSION{'uid'} for Client $SESSION{'clid'} in Session ID $FORM{'tid'} " ; #&show_illegal_access_warning("user"); exit(); } $FORM{'pageid'} = "Gradebook"; $FORM{'PAGEID'} = "GRADEBOOK"; $mainttmplt = "frgradebooks"; } } my @tempacl = &popEmlAcl($SESSION{'clid'}); foreach (@tempacl) { $CLIENT{'emlaclstr'} .= "$_,"; } $CLIENT{'emlaclstr'} =~ s/@//g; $CLIENT{'emlaclstr'} =~ s/,$//g; if ($FORM{'idx'} eq '1') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/I"); if ($SESSION{'uac'} eq 'admin' || $SESSION{'uac'} eq 'gadmin' || $SESSION{'uac'} eq 'madmin') { &show_template("sadminidx"); } else { &show_template("cndidx"); } } elsif ($FORM{'dtl'} eq '0') { print "\n$xlatphrase[539]$xlatphrase[540]\n"; } elsif ($FORM{'dtl'} eq '1') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/CM"); if ($SESSION{'uac'} eq 'gadmin') { &show_admin_request("maintclient"); } else { $FORM{'dbop'} = 'ccupd'; &show_admin_request("cdef"); } } elsif ($FORM{'dtl'} eq '12') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/TR"); &show_admin_request("treplicaframe"); } elsif ($FORM{'dtl'} eq '13') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/TO"); &show_admin_request("tocrinpframe"); } elsif ($FORM{'dtl'} eq '2') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/TM"); $TEST{'id'} = $FORM{'tstid'}; &show_admin_request("tdefframe"); } elsif ($FORM{'dtl'} eq '21') { if ($SESSION{'uac'} eq 'cnd') { $CANDIDATE{'ownedtests'} = &get_group_tests($SESSION{'clid'}, $SESSION{'uid'}, 0); } &show_admin_request("mainttest"); } elsif ($FORM{'dtl'} eq '99') { &show_template("selectpg"); } elsif ($FORM{'dtl'} eq '3') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/R"); &show_admin_request("maintreport"); } elsif ($FORM{'dtl'} eq '4') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/DL"); &show_admin_downloads; } elsif ($FORM{'dtl'} eq '5') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/DB"); &show_admin_request("maintdb"); } elsif ($FORM{'dtl'} eq '6') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/CF"); # set FORM.colors $trash = join( $pathsep, $dataroot, "config.$SESSION{'clid'}"); $omsg = ""; open( CFGFILE, "<$trash" ) or $omsg="not found"; if ($omsg eq 'not found') { $trash = join( $pathsep, $dataroot, "config.std"); open( CFGFILE, "<$trash" ) or return; } @cfgentries = ; close CFGFILE; $langdef = "enu"; $FORM{'colors'} = ""; for (0 .. $#cfgentries) { chop ($cfgentries[$_]); ($entrykey,$entryvalue) = split(/=/, $cfgentries[$_]); if ($entrykey eq 'DEFAULTLANG') { $langdef = $entryvalue; $langselfr = ($langdef eq 'fr') ? " SELECTED" : ""; $langselsp = ($langdef eq 'sp') ? " SELECTED" : ""; $langseldeu = ($langdef eq 'deu') ? " SELECTED" : ""; $langselenu = ($langdef eq 'enu') ? " SELECTED" : ""; $langselena = ($langdef eq 'ena') ? " SELECTED" : ""; $langseleuv = ($langdef eq 'euv') ? " SELECTED" : ""; $langselcyr = ($langdef eq 'cyr') ? " SELECTED" : ""; $langselmy = ($langdef eq 'my') ? " SELECTED" : ""; $langselkor = ($langdef eq 'kor') ? " SELECTED" : ""; $langselafr = ($langdef eq 'afr') ? " SELECTED" : ""; $langselhin = ($langdef eq 'hin') ? " SELECTED" : ""; $colortag = " $xlatphrase[541]\ \; $LANGUAGE_ID{'enu'} $LANGUAGE_ID{'ena'} $LANGUAGE_ID{'euv'} Fráncáís ($LANGUAGE_ID{'fr'}) Dëutsch ($LANGUAGE_ID{'deu'}) Español ($LANGUAGE_ID{'sp'}) Cyrillic ($LANGUAGE_ID{'cyr'}) Malay ($LANGUAGE_ID{'my'}) Korean ($LANGUAGE_ID{'kor'}) Afrikaans ($LANGUAGE_ID{'afr'}) Hindi ($LANGUAGE_ID{'hin'}) \n"; $FORM{'language'} = join('', $colortag, $FORM{'language'}); } elsif ($entrykey eq 'IP_ACCESS_FILTER') { $FORM{'language'} = " $xlatphrase[385]\ \; \n"; } else { if ($entrykey eq 'BACKGROUND') { $colortag = " $entrykey:\ \; \n"; } else { if (($entrykey =~ /COLOR/) || ($entrykey =~ 'LINK') || ($entrykey =~ 'ALINK') || ($entrykey =~ 'VLINK') || ($entrykey eq 'TEXT') ) { $gotfocus = "onFocus=\"return tGotFocus(this)\""; } else { $gotfocus = ""; } $colortag = " $entrykey:\ \; \n"; } $FORM{'colors'} = join('', $FORM{'colors'}, $colortag); } } &show_admin_request("maintcfg"); } elsif ($FORM{'dtl'} eq '7') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/GP"); &show_admin_request($mainttmplt); } elsif ($FORM{'dtl'} eq '8') { #Begin filtering $filterbydate = $FORM{'filterbydate'}; $day_filter = $FORM{'day_filter'}; $date_filter = $FORM{'date_filter'}; $cnd1_filter = $FORM{'cnd1'}; $cnd2_filter = $FORM{'cnd2'}; $cnd3_filter = $FORM{'cnd3'}; $cnd4_filter = $FORM{'cnd4'}; #End filtering &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/CC"); &show_admin_request("maintcnd"); } elsif ($FORM{'dtl'} eq '9') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/RG"); &show_admin_request("regcnd"); } elsif ($FORM{'dtl'} eq '10') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/IM"); &show_admin_request("upimport"); } elsif ($FORM{'dtl'} eq '11') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "SA/LC"); &show_admin_request("frlicadmin"); } elsif ($FORM{'dbop'} ne '') { &show_dbop_response; } else { #&show_illegal_access_warning("else1"); } } else { &logger::logerr("Unable to get session with &get_session($FORM{'tid'})"); &show_illegal_access_warning("else2"); } sub show_license_request { } sub show_admin_downloads { @dlrecs = &get_data("downloads.dat"); $bFirst=1; if ($#dlrecs eq 0) { $download = "No downloads are currently available.\n"; $SYSTEM{'downloadcount'} = 1; } else { $downloadcount=0; foreach $dlrec (@dlrecs) { $msg = ""; if ($bFirst) { $bFirst = 0; } else { chop ($dlrec); @flds = split(/&/, $dlrec); $dlfile = join($pathsep, $pubroot, "downloads/$flds[2]"); open (TMPFILE, "<$dlfile") or $msg="nya"; if ($msg eq 'nya') { $download = "$flds[1] (Coming Soon)\n"; } else { binmode(TMPFILE); $fsize = (stat(TMPFILE))[7]; close TMPFILE; $download = "$flds[1] ($fsize bytes)\n"; } $downloadcount++; $downloads = join('', $downloads , $download); } } if ($downloadcount == 0) { $downloadcount = 1;} if ($downloadcount > 10) { $downloadcount = 10;}; $SYSTEM{'downloadcount'} = $downloadcount; } $SYSTEM{'downloads'} = $downloads; @dlrecs = (); $downloads = ""; $download = ""; &show_template("download"); } #sub show_admin_request { ##moved to smilib # my ($key) = @_; # &get_template($key); # @lines = &get_template($key); # foreach $line (@lines) { # $line = &xlatline($line); # } #} sub show_dbop_response { if ($FORM{'dbop'} eq 'tnew') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "Define New Test"); $FORM{'newtest'} = "Y"; @lines = &get_template("tdefframe"); &print_response; } elsif ($FORM{'dbop'} eq'tdel') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "Delete Test $FORM{'tstid'}"); @trecs = &get_test_list($SESSION{'clid'}); foreach $trec (@trecs) { chop ($trec); ($id, $trash) = split(/\&/, $trec); if ($FORM{'tstid'} ne $id) { push @newtests, $trec; } } @trecs = @newtests; &save_test_list($SESSION{'clid'}); $showmessage = "Test $FORM{'tstid'} has been deleted."; &show_message_with_close($showmessage); } elsif ($FORM{'dbop'} eq 'tupd') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "Edit Test $FORM{'tstid'}"); $TEST{'new'} = "N"; &get_test_profile($SESSION{'clid'}, $FORM{'tstid'}); @lines = &get_template("tdefframe"); &print_response; } elsif ($FORM{'dbop'} eq 'cnew') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "New Client"); $FORM{'newclient'} = "Y"; @lines = &get_template("cdef"); &print_response; } elsif ($FORM{'dbop'} eq 'cdel') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "Delete Client $FORM{'clid'}"); &open_results; &client_delete_response; &close_results; $FORM{'dtl'} eq 8; } elsif ($FORM{'dbop'} eq 'cupd') { &log_entry($SESSION{'clid'}, $SESSION{'uid'}, "2", "Edit Client $FORM{'clid'}"); &get_client_profile($FORM{'clid'}); @lines = &get_template("cdef"); &print_response; } } sub print_response { foreach $line (@lines) { $srch = "<%=CLIENT.REPORTING%>"; if ( $line =~ /$srch/i) { &client_reporting_options($CLIENT{'clid'}); } else { $line = &xlatline($line); } } } sub client_reporting_options { # @rrecs = &get_test_list($_[0]); } sub client_delete_response { &get_client_profile($FORM{'clid'}); print "Deleting $FORM{'clid'} $CLIENT{'clnmc'} ...\n"; # open preservation file $archivefile = join($pathsep, $dataroot, "$FORM{'clid'}.dat"); $archivefile =~ s/$docroot/$archiveroot/g; open (ARCHFILE, ">$archivefile"); # delete client profile @crecs = &get_data("clients.dat"); $trash = join($pathsep, $dataroot, "clients.dat"); open (TMPFILE, ">$trash"); foreach $crec (@crecs) { chop ($crec); ($id, $trash) = split(/&/, $crec); if ($id eq $CLIENT{'clid'}) { print ARCHFILE "$crec\n"; print "client profile $id archived $! ...\n"; } else { print TMPFILE "$crec\n"; } } close TMPFILE; # delete administrative logins @crecs = &get_data("admin.dat"); $trash = join($pathsep, $dataroot, "admin.dat"); open (TMPFILE, ">$trash"); foreach $crec (@crecs) { chop ($crec); ($id, $pwd, $pv, $clid) = split(/&/, $crec); if ($clid eq $CLIENT{'clid'}) { print ARCHFILE "$crec\n"; print "admin login $id archived $! ...\n"; } else { print TMPFILE "$crec\n"; } } close TMPFILE; close ARCHFILE; $chmodok = chmod 0666, $archivefile; # delete logos $ulinkdir = join($pathsep, $pubroot, "graphic"); opendir (GDIR, $ulinkdir); @dots = readdir(GDIR); closedir GDIR; $rmmask = "$CLIENT{'clid'}."; foreach $rmfile (@dots) { if ($rmfile =~ /$rmmask/ ) { $ulinkfile = join($pathsep, $pubroot, "graphic", $rmfile); $archivefile = $ulinkfile; $archivefile =~ s/$docroot/$archiveroot/g; rename $ulinkfile, $archivefile; print "$ulinkfile archived $! ...\n"; } } @dots = (); # delete cnd file $tofile = join($pathsep, $dataroot, "cnd.$CLIENT{'clid'}"); $archivefile = $tofile; $archivefile =~ s/$docroot/$archiveroot/g; rename $tofile, $archivefile; print "$tofile archived $! ...\n"; # delete reports file $tofile = join($pathsep, $dataroot, "reports.$CLIENT{'clid'}"); $archivefile = $tofile; $archivefile =~ s/$docroot/$archiveroot/g; rename $tofile, $archivefile; print "$tofile archived $! ...\n"; # delete tests file $tofile = join($pathsep, $dataroot, "tests.$CLIENT{'clid'}"); $archivefile = $tofile; $archivefile =~ s/$docroot/$archiveroot/g; rename $tofile, $archivefile; print "$tofile archived $! ...\n"; # delete test graphic files opendir (GDIR, $testgraphic); @dots = readdir(GDIR); closedir GDIR; $rmmask = "$CLIENT{'clid'}."; foreach $rmfile (@dots) { if ($rmfile =~ /$rmmask/ ) { $ulinkfile = join($pathsep, $testgraphic, $rmfile); $archivefile = $ulinkfile; $archivefile =~ s/$docroot/$archiveroot/g; rename $ulinkfile, $archivefile; print "$ulinkfile archived $! ...\n"; } } @dots = (); # delete test questions files opendir (GDIR, $questionroot); @dots = readdir(GDIR); closedir GDIR; $rmmask = ".$CLIENT{'clid'}"; foreach $rmfile (@dots) { if ($rmfile =~ /$rmmask/ ) { $ulinkfile = join($pathsep, $questionroot, $rmfile); $archivefile = $ulinkfile; $archivefile =~ s/$docroot/$archiveroot/g; rename $ulinkfile, $archivefile; print "$ulinkfile archived $! ...\n"; } } @dots = (); # delete index page $tofile = join($pathsep, $pubroot, "$CLIENT{'clid'}", "index.htm"); $cnt = unlink $tofile; print "$tofile deleted $! ...\n"; } sub open_results { print " "; } sub close_results { print "HERE\n\n"; }