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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1059 - (download) (as text) (annotate)
Sat Jun 7 04:30:31 2003 UTC (9 years, 11 months ago) by gage
File size: 4872 byte(s)
Restoring header #!/usr/local/bin/webwork-perl line
--Mike

    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 
   17 my $cgi = new CGI;
   18 my %inputs = $cgi->Vars();
   19 
   20 # get information from CGI inputs  (see also below for additional information)
   21 
   22 my $Course      = $inputs{'course'};
   23 my $User      = $inputs{'user'};
   24 my $Session_key   = $inputs{'key'};
   25 
   26 # verify that information has been received
   27   unless($Course && $User && $Session_key) {
   28     &wwerror("$0","The script did not receive the proper input data.","","");
   29     }
   30 
   31 # establish environment for this script
   32 
   33 &Global::getCourseEnvironment($inputs{'course'});
   34 
   35 
   36 my $scriptsDirectory  = getWebworkScriptDirectory;
   37 my $databaseDirectory     = getCourseDatabaseDirectory;
   38 my $templateDirectory       = getCourseTemplateDirectory;
   39 my $cgiURL          = getWebworkCgiURL;
   40 
   41 # File names
   42 
   43 require "${scriptsDirectory}$Global::HTMLglue_pl";
   44 require "${scriptsDirectory}$Global::classlist_DBglue_pl";
   45 require "${scriptsDirectory}$Global::FILE_pl";;
   46 
   47 # log access
   48   &Global::log_info('', query_string);
   49 
   50 
   51 my $permissionsFile = &Global::getCoursePermissionsFile($inputs{'course'});
   52 my $permissions = &get_permissions($inputs{'user'}, $permissionsFile);
   53 my $keyFile = &Global::getCourseKeyFile($inputs{'course'});
   54 
   55 #verify session key
   56 &verify_key($inputs{'user'}, $inputs{'key'}, $keyFile, $inputs{'course'});
   57 
   58 # verify permissions are correct
   59 if ($permissions != $Global::instructor_permissions ) {
   60   print "permissions = $permissions instructor_permissions = $Global::instructor_permissions\n";
   61   print &html_NO_PERMISSION;
   62   exit(0);
   63 }
   64 # get the rest of the information from the submitted form
   65 
   66 my $outFileName = $inputs{'savefilename'};
   67 my $overWrite = $inputs{'overWrite'};
   68 my $backUp = $inputs{'backUp'};
   69 
   70 $overWrite = 0 unless defined $overWrite;
   71 $backUp = 0 unless defined $backUp;
   72 
   73 my $CL_status = get_CL_database_status();
   74 wwerror('Classlist Database is unlocked', 'You must go back and lock the classlist database
   75 before you can export it to an ascii file.') unless $CL_status eq 'locked';
   76 
   77 if ($outFileName =~ /([^\/\\]+)$/) {
   78   $outFileName = $1;
   79   $outFileName =~ s/^\.+//;
   80 }
   81 else {
   82   wwerror($0, "The fileName $outFileName is invalid. Go back and type in another file name.");
   83 }
   84 
   85 $outFileName =~  s|\..*||;      ## remove extension
   86 $outFileName = "${outFileName}\.lst";      ## make sure filename has .lst extension
   87 my $fullPathName = "${templateDirectory}$outFileName";
   88 if ((-e "$fullPathName") and (not $overWrite)) {
   89   &overWriteError();
   90     exit;
   91 }
   92 
   93 if ((-e "$fullPathName") and  $backUp)  {&backupFile("$fullPathName");}   ##make up to three backups
   94 
   95 my ($studentID, $lastName, $firstName, $status, $comment,  $section, $recitation, $email_address, $login_name);
   96 my @login_names = @{&getAllLoginNamesSortedBySectionThenByName()};
   97 
   98 open(OUTFILE,">$fullPathName") or wwerror("$0","Can't open $fullPathName for writing.");
   99 
  100 foreach $login_name (@login_names) {
  101 
  102   attachCLRecord($login_name);
  103 
  104   $studentID =     &CL_getStudentID           ($login_name);
  105   $lastName =      &CL_getStudentLastName     ($login_name);
  106   $firstName =     &CL_getStudentFirstName    ($login_name);
  107   $status =        &CL_getStudentStatus       ($login_name);
  108   $comment =       &CL_getComment             ($login_name);
  109   $section =       &CL_getClassSection        ($login_name);
  110   $recitation =    &CL_getClassRecitation     ($login_name);
  111   $email_address = &CL_getStudentEmailAddress ($login_name);
  112 
  113 
  114     print OUTFILE "$studentID\, $lastName\, $firstName\, $status\, $comment\, $section\, $recitation\,  $email_address\, $login_name \n";
  115 
  116 
  117 }
  118 
  119 close(OUTFILE);
  120 
  121 &columnPrint("$fullPathName","$fullPathName");
  122 chmod($Global::classlist_file_permission, "$fullPathName") or
  123   &wwerror("$0","Can't do chmod($Global::classlist_file_permission, $fullPathName)");
  124 chown(-1,$Global::numericalGroupID,"$fullPathName") or
  125   &wwerror("$0","Can't do chown(-1,$Global::numericalGroupID,$fullPathName)");
  126 
  127 uploadSuccess("$fullPathName");
  128 exit;
  129 
  130 sub uploadSuccess {
  131   my ($savedFile) = @_;
  132   print"content-type: text/html\n\n<H2>Success, file saved. </H2>\n";
  133   print "The classlist database has been exported to the file:<BR>$savedFile";
  134 
  135   print &htmlBOTTOM("profExportClasslistDatabase.pl", \%inputs);
  136 }
  137 
  138 
  139 sub overWriteError {
  140     print"content-type: text/html\n\n<H2>No changes made:  You are not in overwrite mode</H2>\n";
  141     print "The file $fullPathName already exists.  If you want to overwrite this file,
  142     use your browser's Back Button to return to the previous page and check the overwrite check box.
  143     Or you can go back and type in a different filename.";
  144 }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9