You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

493 lines
15 KiB

#!/usr/bin/perl
#
# $Id: sadmin.pl,v 1.12 2006/11/28 21:07:48 psims Exp $
#
# Source File: sadmin.pl
4 months ago
#use strict;
use warnings;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
#warningsToBrowser(1);
#fatalsToBrowser(1);
# Get config
4 months ago
require 'sitecfg.pl';
require 'testlib.pl';
&app_initialize;
print "Content-Type: text/html\n\n";
4 months ago
#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();
}
4 months ago
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'} " ;
4 months ago
#&show_illegal_access_warning("user");
exit();
4 months ago
}
$FORM{'pageid'} = "Gradebook";
$FORM{'PAGEID'} = "GRADEBOOK";
$mainttmplt = "frgradebooks";
}
4 months ago
}
4 months ago
my @tempacl = &popEmlAcl($SESSION{'clid'});
foreach (@tempacl) {
$CLIENT{'emlaclstr'} .= "$_,";
}
$CLIENT{'emlaclstr'} =~ s/@//g;
$CLIENT{'emlaclstr'} =~ s/,$//g;
4 months ago
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 "<HTML>\n$xlatphrase[539]<BR>$xlatphrase[540]</HTML>\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 = <CFGFILE>;
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 = "<TR>
<TD align=right>
$xlatphrase[541]\&nbsp\;
</TD>
<TD align=left>
<SELECT NAME=\"CDEFAULTLANG\" onChange=\"reset_autotimer()\">
<OPTION VALUE=\"enu\"$langselenu>$LANGUAGE_ID{'enu'}
<OPTION VALUE=\"ena\"$langselena>$LANGUAGE_ID{'ena'}
<OPTION VALUE=\"euv\"$langseleuv>$LANGUAGE_ID{'euv'}
<OPTION VALUE=\"fr\"$langselfr>Frncs ($LANGUAGE_ID{'fr'})
<OPTION VALUE=\"deu\"$langseldeu>Dutsch ($LANGUAGE_ID{'deu'})
<OPTION VALUE=\"sp\"$langselsp>Espaol ($LANGUAGE_ID{'sp'})
<OPTION VALUE=\"cyr\"$langselcyr>Cyrillic ($LANGUAGE_ID{'cyr'})
<OPTION VALUE=\"my\"$langselmy>Malay ($LANGUAGE_ID{'my'})
<OPTION VALUE=\"kor\"$langselkor>Korean ($LANGUAGE_ID{'kor'})
<OPTION VALUE=\"afr\"$langselafr>Afrikaans ($LANGUAGE_ID{'afr'})
<OPTION VALUE=\"hin\"$langselafr>Hindi ($LANGUAGE_ID{'hin'})
</SELECT>
</TD>
</TR>\n";
4 months ago
$FORM{'language'} = join('', $colortag, $FORM{'language'});
} elsif ($entrykey eq 'IP_ACCESS_FILTER') {
$FORM{'language'} = " <TR>
<TD align=right width=50\%>
$xlatphrase[385]\&nbsp\;
</TD>
<TD align=left width=50\%>
<INPUT TYPE=TEXT NAME=\"C$entrykey\" VALUE=\"$entryvalue\" onChange=\"reset_autotimer()\">
</TD>
</TR>\n";
4 months ago
} else {
if ($entrykey eq 'BACKGROUND') {
$colortag = " <TR>
<TD align=right><font size=1>$entrykey:\&nbsp\;</font></TD>
<TD align=left><INPUT TYPE=FILE NAME=\"C$entrykey\" VALUE=\"$entryvalue\" onChange=\"reset_autotimer()\"></TD>
</TR>\n";
4 months ago
} else {
if (($entrykey =~ /COLOR/)
|| ($entrykey =~ 'LINK')
|| ($entrykey =~ 'ALINK')
|| ($entrykey =~ 'VLINK')
|| ($entrykey eq 'TEXT') ) {
$gotfocus = "onFocus=\"return tGotFocus(this)\"";
} else {
$gotfocus = "";
}
$colortag = " <TR>
<TD align=right nowrap><font size=1>$entrykey:\&nbsp\;</font></TD>
<TD align=left><INPUT TYPE=TEXT NAME=\"C$entrykey\" SIZE=8 MAXLENGTH=7 VALUE=\"$entryvalue\" $gotfocus onChange=\"reset_autotimer()\"></TD>
</TR>\n";
}
4 months ago
$FORM{'colors'} = join('', $FORM{'colors'}, $colortag);
}
}
4 months ago
&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 {
4 months ago
&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 = "<OPTION VALUE=\"nya\">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 = "<OPTION VALUE=\"nya\">$flds[1] (Coming Soon)\n";
} else {
binmode(TMPFILE);
$fsize = (stat(TMPFILE))[7];
close TMPFILE;
$download = "<OPTION VALUE=\"$flds[2]\">$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'} ...<BR>\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 $! ...<BR>\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 $! ...<BR>\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 $! ...<BR>\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 $! ...<BR>\n";
# delete reports file
$tofile = join($pathsep, $dataroot, "reports.$CLIENT{'clid'}");
$archivefile = $tofile;
$archivefile =~ s/$docroot/$archiveroot/g;
rename $tofile, $archivefile;
print "$tofile archived $! ...<BR>\n";
# delete tests file
$tofile = join($pathsep, $dataroot, "tests.$CLIENT{'clid'}");
$archivefile = $tofile;
$archivefile =~ s/$docroot/$archiveroot/g;
rename $tofile, $archivefile;
print "$tofile archived $! ...<BR>\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 $! ...<BR>\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 $! ...<BR>\n";
}
}
@dots = ();
# delete index page
$tofile = join($pathsep, $pubroot, "$CLIENT{'clid'}", "index.htm");
$cnt = unlink $tofile;
print "$tofile deleted $! ...<BR>\n";
}
sub open_results {
print "<HTML>
<HEAD>
<SCRIPT language=\"JavaScript\">
<!--
function right(e) {
if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) {
alert(\"<%=PHRASE.473%>\");
return false;
} else {
if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) {
alert(\"<%=PHRASE.473%>\");
return false;
}
}
return true;
}
document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=right;
window.onmouseup=right;
// -->
</SCRIPT>
</HEAD>
<BODY BACKGROUND=\"$SYSTEM{'BACKGROUND'}\" BGCOLOR==\"$SYSTEM{'BGCOLOR'}\"
TEXT=\"$SYSTEM{'TEXT'}\" LINK=\"$SYSTEM{'LINK'}\"
VLINK=\"$SYSTEM{'VLINK'}\" ALINK=\"$SYSTEM{'ALINK'}\">
";
}
sub close_results {
4 months ago
print "<DIV>HERE</DIV></BODY>\n</HTML>\n";
}