[system] / trunk / webwork / system / cgi / cgi-scripts / profImportClasslistDatabase.pl Repository:
ViewVC logotype

View of /trunk/webwork/system/cgi/cgi-scripts/profImportClasslistDatabase.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1216 - (download) (as text) (annotate)
Thu Jun 19 16:28:18 2003 UTC (9 years, 11 months ago) by apizer
File size: 22832 byte(s)
Change classlist importation so that (1) prof's can not be droped or removed
and (2) students with existing sets can only be removed with conformation.

Arnie

    1 #!/usr/local/bin/webwork-perl
    2 
    3 ## This file is profExportClasslistDatabase.pl
    4 ##
    5 
    6 ####################################################################
    7 # Copyright @ 1995-2000 University of Rochester
    8 # All Rights Reserved
    9 ####################################################################
   10 
   11 use lib '.'; use webworkInit; # WeBWorKInitLine
   12 use CGI qw(:standard);
   13 use Global;
   14 use Auth;
   15 use strict;
   16 use GDBM_File;
   17 
   18 my $cgi = new CGI;
   19 my %inputs = $cgi->Vars();
   20 
   21 # get information from CGI inputs  (see also below for additional information)
   22 
   23 my $Course      = $inputs{'course'};
   24 my $User      = $inputs{'user'};
   25 my $Session_key   = $inputs{'key'};
   26 
   27 # verify that information has been received
   28   unless($Course && $User && $Session_key) {
   29     &wwerror("$0","The script did not receive the proper input data.","","");
   30     }
   31 
   32 # establish environment for this script
   33 
   34 &Global::getCourseEnvironment($Course);
   35 
   36 
   37 my $scriptsDirectory    = getWebworkScriptDirectory;
   38 my $databaseDirectory   = getCourseDatabaseDirectory;
   39 my $templateDirectory   = getCourseTemplateDirectory;
   40 my $cgiURL          = getWebworkCgiURL;
   41 my $CL_Database       = $Global::CL_Database;
   42 my $path_to_CL_DB     = "${databaseDirectory}$CL_Database";
   43 # File names
   44 
   45 require "${scriptsDirectory}$Global::HTMLglue_pl";
   46 require "${scriptsDirectory}$Global::DBglue_pl";
   47 require "${scriptsDirectory}$Global::classlist_DBglue_pl";
   48 require "${scriptsDirectory}$Global::FILE_pl";;
   49 my $DELIM = $Global::delim;
   50 
   51 # log access
   52   &Global::log_info('', query_string);
   53 
   54 my $passwordFile = &Global::getCoursePasswordFile($Course);
   55 my $permissionsFile = &Global::getCoursePermissionsFile($Course);
   56 my $permissions = &get_permissions($inputs{'user'}, $permissionsFile);
   57 my $keyFile = &Global::getCourseKeyFile($Course);
   58 
   59 #verify session key
   60 &verify_key($inputs{'user'}, $inputs{'key'}, $keyFile, $Course);
   61 
   62 # verify permissions are correct
   63 if ($permissions != $Global::instructor_permissions ) {
   64   print "permissions = $permissions instructor_permissions = $Global::instructor_permissions\n";
   65   print &html_NO_PERMISSION;
   66   exit(0);
   67 }
   68 # get the rest of the information from the submitted form
   69 
   70 my $classlistFilename   = $inputs{'classList'};
   71 my $update_firstName    = $inputs{'update_firstName'};
   72 my $update_lastName     = $inputs{'update_lastName'};
   73 my $update_status     = $inputs{'update_status'};
   74 my $update_comment      = $inputs{'update_comment'};
   75 my $update_section      = $inputs{'update_section'};
   76 my $update_recitation   = $inputs{'update_recitation'};
   77 my $update_email_address  = $inputs{'update_email_address'};
   78 my $update_drop       = $inputs{'update_drop'};  ## either 'drop', 'leave', or 'remove'
   79 
   80 $update_firstName   = 0 unless defined  $update_firstName;
   81 $update_lastName    = 0 unless defined  $update_lastName;
   82 $update_status      = 0 unless defined  $update_status;
   83 $update_comment     = 0 unless defined  $update_comment;
   84 $update_section     = 0 unless defined  $update_section;
   85 $update_recitation    = 0 unless defined  $update_recitation;
   86 $update_email_address = 0 unless defined  $update_email_address;
   87 
   88 my $second_pass = 0;
   89 
   90 #  $second_pass is 1 if we are removing all records for some students who have existing sets.
   91 $second_pass = 1 if (defined $inputs{'action'} and $inputs{'action'} =~ /Remove/);
   92 lock_CL_database() if $second_pass;  ## the first pass unlocked the database
   93 
   94 my $CL_status = get_CL_database_status();
   95 wwerror('Classlist Database is unlocked', 'You must go back and lock the classlist database
   96   before you can import it from an ascii file.') unless $CL_status eq 'locked';
   97 
   98 wwerror('No classlist file selected', 'You must go back and select a classlist file.')
   99   unless $classlistFilename =~ /\w/;
  100 
  101 my $msg1 = updateClasslistDB($classlistFilename);
  102 
  103 my $msg2 = initial_passwords();
  104 
  105 my $msg3 = "$msg1" . "$msg2";
  106 
  107 uploadSuccess("$msg3");
  108 
  109 exit;  ## end of main script
  110 
  111 sub updateClasslistDB { ## builds the classlist DB and returns a message
  112 
  113   my ($classlistFilename) = @_;
  114 
  115   #get data from class list.
  116   my $fileName="${templateDirectory}$classlistFilename";  ## e.g. fileName=m161.lst
  117 
  118   my $message = "\nGetting classlist file from: $fileName <BR>\n";
  119   checkClasslistFile($Global::noOfFieldsInClasslist,$fileName);
  120   open(FILE, "$fileName") || wwerror($0, "Can't open $fileName");
  121   my @classList=<FILE>;
  122   close(FILE);
  123 
  124   ###################################
  125   #  Before updating the database we back it up
  126   ###################################
  127   if (( -e "$path_to_CL_DB" ) and (!$second_pass)){
  128     $message .= "Backing up current classlist database to: ${path_to_CL_DB}_bak1 <BR>\n";
  129     &backup($path_to_CL_DB);
  130   }
  131 
  132   my %loginName_StudentID_Hash = %{getLoginName_StudentID_Hash()};
  133   my %studentID_LoginName_Hash =%{getStudentID_LoginName_Hash()};
  134 
  135 # my $WW_DB_exists = 0;
  136 # $WW_DB_exists = 1 if ( -e "${databaseDirectory}$Global::database" );
  137 
  138 # my %loginName_StudentID_Hash_from_WW_DB =();
  139 # my %studentID_LoginName_Hash_from_WW_DB =();
  140 
  141 # if ($WW_DB_exists) {
  142 #   %loginName_StudentID_Hash_from_WW_DB =%{getLoginName_StudentID_Hash_from_WW_DB()};
  143 #   %studentID_LoginName_Hash_from_WW_DB = reverse %loginName_StudentID_Hash_from_WW_DB;
  144 # }
  145 
  146   my $errors ='';
  147   my $drop_profs = '';                    ## profs who will not be dropped
  148   my $remove_profs = '';                  ## profs who will not be removed
  149   my $remove_students_with_sets = '';     ## students for whom sets exits who will not
  150                                           ##   not be removed on first pass
  151   my %new_good_classlist_students =();    ## students in new classlist without conflicts
  152   my %new_bad_classlist_students =();   ## students in new classlist with conflicts
  153 
  154 
  155   foreach (@classList)     {          ## read through classlist and create
  156                         ## class list database
  157     unless ($_ =~ /\S/)  {next;}      ## skip blank lines
  158     chomp;
  159     my @classListRecord=&getRecord($_);
  160     my ($studentID, $lastName, $firstName, $status, $comment,  $section, $recitation, $email_address, $login_name)
  161         =  @classListRecord;
  162 
  163     ## First we get a list of any conflicts with current students
  164     if ((defined $loginName_StudentID_Hash{$login_name})
  165       and ($loginName_StudentID_Hash{$login_name} ne $studentID)) {
  166       $errors .= "$firstName $lastName, $login_name, $studentID <BR>\n ";
  167       $new_bad_classlist_students{$login_name} =1;
  168       next;
  169     }
  170 
  171     if ((defined $studentID_LoginName_Hash{$studentID})
  172       and ($studentID_LoginName_Hash{$studentID} ne $login_name)) {
  173       $errors .= "$firstName $lastName, $login_name, $studentID <BR>\n ";
  174       $new_bad_classlist_students{$login_name} =1;
  175       next;
  176     }
  177 
  178 
  179 
  180     ## OK, the student record has no conflicts
  181 
  182     $new_good_classlist_students{$login_name} =1;
  183 
  184     ## Handle students already in classlist DB
  185     if (defined $loginName_StudentID_Hash{$login_name}) {
  186       &attachCLRecord($login_name);
  187       &CL_putStudentLastName     ($lastName, $login_name)       if $update_lastName;
  188       &CL_putStudentFirstName    ($firstName, $login_name)      if $update_firstName;
  189       &CL_putComment             ($comment, $login_name)        if $update_comment;
  190       &CL_putClassSection        ($section,$login_name)         if $update_section;
  191       &CL_putClassRecitation     ($recitation,$login_name)      if $update_recitation;
  192       &CL_putStudentEmailAddress ($email_address, $login_name)  if $update_email_address;
  193 
  194       ## test for dropping a professor
  195       my $studentPermissions = &get_permissions($login_name, $permissionsFile);
  196       my $orgStudentStatus = &CL_getStudentStatus($login_name);
  197       if ($update_status and
  198         defined $studentPermissions and
  199         $studentPermissions == $Global::instructor_permissions and
  200         &dropStatus($status) !=  &dropStatus($orgStudentStatus) and
  201         &dropStatus($status)
  202       )
  203         {$drop_profs .= "$firstName $lastName, $login_name, $studentID <BR>\n ";}
  204       elsif ($update_status)
  205         {&CL_putStudentStatus       ($status, $login_name);}
  206 
  207       $Global::over_ride_CLBD_lock = 1;
  208       &saveCLRecord($login_name);
  209       $Global::over_ride_CLBD_lock = 0;
  210 
  211 
  212     }
  213     else {        ## Handle new students
  214       &CL_putStudentID           ($studentID, $login_name);
  215       &CL_putStudentLastName     ($lastName, $login_name);
  216       &CL_putStudentFirstName    ($firstName, $login_name);
  217       &CL_putStudentStatus       ($status, $login_name);
  218       &CL_putComment             ($comment, $login_name);
  219       &CL_putClassSection        ($section,$login_name);
  220       &CL_putClassRecitation     ($recitation,$login_name);
  221       &CL_putStudentEmailAddress ($email_address, $login_name);
  222       $Global::over_ride_CLBD_lock = 1;
  223       &saveCLRecord($login_name);
  224       $Global::over_ride_CLBD_lock = 0;
  225     }
  226   }
  227 
  228   ## Now we take care of students who are in the current classlist database but are not in
  229   ## the classlist file.
  230 
  231   my %drop_list =();
  232   my $login_name;
  233   %loginName_StudentID_Hash = %{getLoginName_StudentID_Hash()};
  234   foreach $login_name (keys %loginName_StudentID_Hash) {
  235     $drop_list{$login_name} = 1 unless (
  236       (defined ($new_good_classlist_students{$login_name})) or (defined ($new_bad_classlist_students{$login_name}))
  237     );
  238   }
  239   if  ($update_drop eq 'drop')  {
  240     my $status = 'D';
  241     $status = $Global::statusDrop[0] if defined $Global::statusDrop[0];
  242     foreach $login_name (keys %drop_list) {
  243       &attachCLRecord($login_name);
  244 
  245       ## test for dropping a professor. If not a prof, drop them.
  246       my $studentPermissions = &get_permissions($login_name, $permissionsFile);
  247       my $orgStudentStatus = &CL_getStudentStatus($login_name);
  248       if (defined $studentPermissions and
  249         $studentPermissions == $Global::instructor_permissions and
  250         !&dropStatus($orgStudentStatus)
  251       ) {
  252         my $lastName = &CL_getStudentLastName($login_name);
  253         my $firstName = &CL_getStudentFirstName($login_name);
  254         my $studentID = &CL_getStudentID($login_name);
  255         $drop_profs .= "$firstName $lastName, $login_name, $studentID <BR>\n ";
  256       }
  257       else  {&CL_putStudentStatus($status, $login_name);}
  258 
  259       $Global::over_ride_CLBD_lock = 1;
  260       &saveCLRecord($login_name);
  261       $Global::over_ride_CLBD_lock = 0;
  262     }
  263   }
  264   elsif ($update_drop eq 'remove') {
  265     $remove_profs = '';
  266     $remove_students_with_sets = '';
  267     foreach $login_name (keys %drop_list) {
  268       &attachCLRecord($login_name);
  269 
  270       ## test for removing a professor.
  271       my $studentPermissions = &get_permissions($login_name, $permissionsFile);
  272       my $orgStudentStatus = &CL_getStudentStatus($login_name);
  273       if (defined $studentPermissions and
  274         $studentPermissions == $Global::instructor_permissions and
  275         !&dropStatus($orgStudentStatus)
  276       ) {
  277         my $lastName = &CL_getStudentLastName($login_name);
  278         my $firstName = &CL_getStudentFirstName($login_name);
  279         my $studentID = &CL_getStudentID($login_name);
  280         $remove_profs .= "$firstName $lastName, $login_name, $studentID <BR>\n ";
  281       }
  282 
  283       ## test for removing a students with existing problem sets.
  284       elsif (check_Record($login_name)) {
  285         my $lastName = &CL_getStudentLastName($login_name);
  286         my $firstName = &CL_getStudentFirstName($login_name);
  287         my $studentID = &CL_getStudentID($login_name);
  288         $remove_students_with_sets .= "$firstName $lastName, $login_name, $studentID <BR>\n ";
  289         if ($second_pass) {
  290           removeRecord($login_name);
  291           $Global::over_ride_CLBD_lock = 1;
  292           deleteClassListRecord($login_name);
  293           $Global::over_ride_CLBD_lock = 0;
  294         }
  295       }
  296       else  {
  297         $Global::over_ride_CLBD_lock = 1;
  298         deleteClassListRecord($login_name);
  299         $Global::over_ride_CLBD_lock = 0;
  300       }
  301     }
  302   }
  303   else {  ## if this case $update_drop eq 'leave' and we do nothing
  304   }
  305 
  306   unlock_CL_database();
  307 
  308   if (($remove_profs) and (!$second_pass)){
  309     $message .= "<BR>The following professors <FONT COLOR='#ff00aa'><b>HAVE NOT BEEN REMOVED</b></FONT>.
  310     If you really want to remove a professor, do this from the Edit Class Roster page where there are more
  311     options and safe guards.
  312     <BR><BR>";
  313     $message .= "\n $remove_profs<BR>";
  314   }
  315   if (($drop_profs) and (!$second_pass)) {
  316     $message .= "<BR>The following professors <FONT COLOR='#ff00aa'><b>HAVE NOT BEEN DROPPED</b></FONT>.
  317     If you really want to drop a professor, do this from the Edit Class Roster page where there are more
  318     options and safe guards.
  319     <BR><BR>";
  320     $message .= "\n $drop_profs<BR>";
  321   }
  322   if ($remove_students_with_sets) {
  323     if (!$second_pass) {
  324       $message .= "<BR>The following students <FONT COLOR='#ff00aa'><b>HAVE NOT BEEN REMOVED</b></FONT>.
  325       There are existing sets for these students.  If you choose to remove all records for these students,
  326       all this data will be destroyed.  This action can not be undone.  Generally it is preferable to change
  327       their \"Enrollment Status\" to \"D\" (for Drop) rather than to totally remove all records.    To change
  328       their \"Enrollment Status\" to \"D\", use your brower's back button and select \"Change student's
  329       status to 'drop' in the classlist database\". If you want details on which sets exist for which
  330       students, go to the Edit Class Roster page, select the student and then click \"Remove THIS RECORD\".
  331       You will see a list of existing sets and then be given the oportunity to remove them if you wish.<P>
  332       <FONT COLOR='#ff00aa'><b>If you really want to remove all records for these students,
  333       click on 'Remove all records'.</b></FONT><BR><BR>";
  334     }
  335     else {
  336       $message .= "<BR>The following students <FONT COLOR='#ff00aa'><b>HAVE BEEN REMOVED</b></FONT>.
  337       All records for these students have been deleted.<BR><BR>";
  338     }
  339     $message .= "\n $remove_students_with_sets<BR>";
  340     $message .= &remove_students_form() unless $second_pass;
  341 
  342   }
  343   if ($errors) {
  344     $message .= "<BR>The following students <FONT COLOR='#ff00aa'><b>HAVE NOT BEEN ENTERED IN THE
  345     CLASSLIST DATABASE</b></FONT>
  346     because of a conflict with entries in the WeBWorK problem set database or the classlist database.
  347     These students have a studentID or a loginName that conflicts with a current student.
  348     Enter this information again from the Add Student(s) Page to get a more detailed error message
  349     and instructions on how to correct the problem.<BR><BR>";
  350     $message .= "\n $errors<BR>";
  351 
  352 
  353   }
  354   $message;
  355 }
  356 
  357 sub initial_passwords {
  358   my %studentsinclass=();
  359   my @classListRecord=();
  360   my $msg ='';
  361 
  362   # Check that the files exist:
  363   #    The permissions file must exist and have both read and write privilages.
  364   #    The password file must exist and have both read and write privilages.
  365 
  366 
  367   unless ( -r $passwordFile and -w $passwordFile) {
  368     wwerror ($0, "Permissions set incorrectly on $passwordFile or its directory.
  369        Cannot access file to both read and write.");
  370   }
  371 
  372   unless ( -r $permissionsFile and -w $permissionsFile) {
  373     wwerror ($0, "Permissions set incorrectly on $permissionsFile or its directory.
  374        Cannot access file to both read and write.");
  375   }
  376 
  377   my $login_name;
  378 
  379   my @classList = @{getAllLoginNames()};
  380 
  381   $msg .= "\n<BR><BR> Modifying the password file: $passwordFile <BR>\n ";
  382 
  383   foreach $login_name (@classList)   {      ## read through classlist database and create
  384                           ## passwords for all active students
  385                           ## except if passwords already exist for student
  386     attachCLRecord($login_name);
  387 
  388     my $status    = CL_getStudentStatus($login_name);
  389     my $studentID = CL_getStudentID($login_name);
  390 
  391     $studentsinclass{$login_name}++ unless(&dropStatus($status));
  392 
  393     if(&dropStatus($status)) {
  394       $msg .= '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'."$login_name not added because status is $status <BR>\n ";
  395     }
  396     elsif (&get_password($login_name, $passwordFile)) {
  397       $msg .= '&nbsp;&nbsp;&nbsp;'."$login_name not added because password already exists <BR>\n ";
  398     }
  399     else {
  400       &new_password($login_name, $studentID, $passwordFile);
  401       &put_permissions(0,$login_name,$permissionsFile);
  402       $msg .= "added: $login_name, $studentID <BR>\n ";
  403     }
  404   }
  405 
  406   my @pwStudents = &get_keys_from_db($passwordFile);
  407   my ($ans,$student);
  408 
  409 
  410   $msg .= "\n<BR<BR><BR> The following login's (if any) in the password and permissions databases are either\n ";
  411   $msg .= "(1) not listed  in the new class list database file \n";
  412   $msg .= "or (2) have DROP status in the new class list database file.\n";
  413   $msg .= "They will all be removed from the password and permissions databases.<BR><BR>\n ";
  414 
  415   foreach $student (@pwStudents) {
  416     next if defined($studentsinclass{$student});
  417 
  418     &delete_password($student,$passwordFile);
  419     &delete_permissions($student,$permissionsFile);
  420     $msg .= "$student<BR>\n ";
  421   }
  422 
  423 $msg = '';  ## returning too much info so don't return this
  424 $msg;
  425 }
  426 
  427 
  428 sub uploadSuccess {
  429   my ($msg) = @_;
  430   print"content-type: text/html\n\n<H2>The classlist database has been updated. </H2>\n";
  431   print $msg;
  432   print &htmlBOTTOM("profImportClasslistDatabase.pl", \%inputs);
  433 }
  434 
  435 sub backup  {
  436   ## takes as a parameter the full path name
  437   ## makes upto two backups of the file with _bak1, or _bak2
  438   ## appended to filename where _bak1 is the most recent backup
  439   use File::Copy;
  440   my $fileName =$_[0];
  441 
  442   if (-e "${fileName}_bak1") {
  443     rename("${fileName}_bak1","${fileName}_bak2") or
  444       &wwerror("$0","can't rename ${fileName}_bak1");
  445   }
  446 
  447   if (-e "${fileName}") {
  448     copy("${fileName}","${fileName}_bak1") or
  449       &wwerror("$0","can't copy ${fileName}");
  450   }
  451 }
  452 
  453 sub check_Record {
  454   my $studentLogin = shift @_;
  455 
  456   my $setsExist = 0;
  457 
  458   # check to see if there is data for this student in the WW DB
  459   if ( -e "${databaseDirectory}$Global::database" ){
  460     $setsExist = &setsExistForStudentLogin($studentLogin);
  461   }
  462   return $setsExist;
  463 }
  464 
  465 sub removeRecordWarningPage {
  466   my ($inputref, $studentLogin, $setsExist, $SetNumberKeysref)  = @_;
  467 
  468   my @SetNumberKeys = @$SetNumberKeysref;
  469   my %inputs = %$inputref;
  470 
  471   attachCLRecord($studentLogin);
  472   my $studentLastName = CL_getStudentLastName($studentLogin);
  473   my $studentFirstName  = CL_getStudentFirstName($studentLogin);
  474   my $studentID   = CL_getStudentID($studentLogin);
  475 
  476    my $studentPermissions = &get_permissions($studentLogin, $permissionsFile);
  477   my $word = 'informational';
  478 
  479   if ($setsExist or (defined $studentPermissions and $studentPermissions == $Global::instructor_permissions))
  480     {$word = "<FONT COLOR='#ff00aa'>WARNING</font>";}
  481   # print HTML text
  482   print &htmlTOP("Data for the classlist record for $studentLogin");
  483 
  484   print qq!<h3 align="left">WeBWorK $word message concerning user $studentLogin
  485   ($studentFirstName $studentLastName $studentID)</h3>\n!;
  486 
  487   print qq!You have requested to remove the the classlist records and all associated data for the above user. <BR><BR>
  488 
  489   <P><FONT COLOR='#ff00aa'><B>NO CHANGES HAVE BEEN MADE YET. </B></font> <P>!;
  490 
  491   if ($User eq $studentLogin) {
  492     print qq!<FONT COLOR='#ff00aa'><B>YOU ARE TRYING TO REMOVE YOURSELF FROM THE COURSE. </B></font>\n
  493     If you do this, you will immediately be locked out of the course.  You will no longer be able to\n
  494     login and/or administer the course.  Removing yourself is something you almost never want to do.\n
  495     Use your browser's "Back" button to cancel this action.<P>\n!;
  496   }
  497   elsif (defined $studentPermissions and $studentPermissions == $Global::instructor_permissions){
  498     print qq!<FONT COLOR='#ff00aa'><B>YOU ARE TRYING TO REMOVE A PROFESSOR FROM THE COURSE. </B></font>\n
  499     If you do this, $studentFirstName $studentLastName will imediately be locked out of the course.
  500     He or she will no longer be able to login and/or administer the course.
  501     Use your browser's "Back" button to cancel this action.<P>\n!;
  502   }
  503 
  504   if ($setsExist) {
  505     print qq! Data exists in the WeBWorK databases for following sets for user <b>$studentLogin</b><BR>\n!;
  506     foreach my $set (@SetNumberKeys) {
  507       print "<BR> Set $set\n";
  508     }
  509     print "<BR> <BR>If you choose to remove all records for <b>$studentLogin</b>, all this data will be destroyed.  This action can not be undone.<BR>\n";
  510   }
  511 
  512   print qq! <BR><BR>Generally if the user <b>$studentLogin</b> is a real user, it is preferable to change his or her "Enrollment Status"\n
  513   to "D" (for Drop) rather than to totally remove all records.  That way records are not destroyed\n
  514   and also the student can be reactivated simply by changing his or her "Enrollment Status" back to "C" (for Current).\n!;
  515 
  516   print qq! <BR><BR>If you have scored any of the above sets, scores for user <b>$studentLogin</b> will be contained in the
  517   ${Course}_totals.csv file (and the other scoring files).  These scores will not be removed.\n!;
  518 
  519   print qq! <BR><BR>If you want to change the "Enrollment Status" for $studentLogin to "D" (for Drop), use your browser's "Back" button.<BR>\n!;
  520 
  521 
  522   print qq!<FORM ACTION="${cgiURL}profEditClasslistDB.pl" METHOD=POST>\n!;
  523   print &sessionKeyInputs(\%inputs);
  524   print qq!<INPUT TYPE='HIDDEN' NAME='studentLogin' VALUE="$studentLogin">\n
  525   <INPUT TYPE="HIDDEN" NAME="save" VALUE="ON">\n
  526   <INPUT TYPE="HIDDEN" NAME="firsttime" VALUE= 1>\n
  527   If you really want to remove all records for <b>$studentLogin</b>, click on\n
  528   <INPUT TYPE="SUBMIT" NAME = "action" VALUE="DO IT"> \n
  529   but think before you click since this data, once removed, can not be recovered.\n
  530   </FORM>!;
  531 
  532 print &htmlBOTTOM('profEditClasslistDB.pl', \%inputs);
  533 
  534 } #end of removeRecordWarningPage
  535 
  536 
  537 sub removeRecord {
  538   my $studentLogin = shift @_;
  539 
  540   my $setsExist = 0;
  541   my @SetNumberKeys = ();
  542   my %setNumberHash = ();
  543 
  544   # check to see if there is data for this student in the WW DB
  545 
  546   if ( -e "${databaseDirectory}$Global::database" ){
  547     $setsExist = &setsExistForStudentLogin($studentLogin);
  548     if ($setsExist) {
  549       %setNumberHash=&getAllSetNumbersForStudentLoginHash($studentLogin);
  550       @SetNumberKeys =  keys(%setNumberHash);
  551     }
  552   }
  553 
  554   ## Now remove all that data in the WeBWorK database, the .sco files,
  555   ## dvipng images, and any LaTeX2HTML images
  556   my ($setName, $psvn);
  557 
  558   if ($setsExist) {
  559     foreach $setName (@SetNumberKeys) {
  560       $psvn = $setNumberHash{$setName};
  561       &attachProbSetRecord($psvn);
  562       &deleteProbSetRecord($psvn);
  563       # remove .sco file if it exists
  564       system ("rm ${databaseDirectory}S${setName}-${psvn}.sco") if (-e "${databaseDirectory}S${setName}-${psvn}.sco");
  565       # remove any l2h files
  566       my $l2hDir = getCoursel2hDirectory();
  567       my $tempDir = convertPath("${l2hDir}set${setName}/*-$psvn");
  568       system ("rm -rf $tempDir");
  569       # remove any dvipng images -- reuse the variable names
  570       $l2hDir = getCourseTempDirectory();
  571       $tempDir = convertPath("${l2hDir}png/${setName}/$psvn");
  572       system ("rm -rf $tempDir");
  573     }
  574   }
  575 
  576   ## Next remove password and permission data
  577 
  578   delete_password($studentLogin,$passwordFile);
  579   delete_permissions($studentLogin,$permissionsFile);
  580 }
  581 
  582 sub remove_students_form {
  583   my $form = '';
  584   $form .= $cgi->startform(-action=>"${cgiURL}profImportClasslistDatabase.pl")."\n";
  585   $form .= $cgi->hidden(-name=>'classList', -value=>"$inputs{'classList'}")."\n";
  586   $form .= $cgi->hidden(-name=>'course', -value=>"$inputs{'course'}")."\n";
  587   $form .= $cgi->hidden(-name=>'user', -value=>"$inputs{'user'}")."\n";
  588   $form .= $cgi->hidden(-name=>'key', -value=>"$inputs{'key'}")."\n";
  589   $form .= $cgi->hidden(-name=>'update_drop', -value=>'remove')."\n";
  590   $form .= $cgi->submit(-name=>'action', -value=>'Remove all records')."\n";
  591   $form .= $cgi->endform()."\n";
  592   return $form;
  593 }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9