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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 150 - (download) (as text) (annotate)
Fri Aug 17 21:36:27 2001 UTC (18 years, 6 months ago) by sh002i
File size: 12021 byte(s)
added recursiveFindFiles subroutine, used it to replace `find` call for
set header file editing form.

    1 #!/usr/local/bin/webwork-perl
    2 
    3 
    4 
    5 ## This file is profBuildProblemSetPage.pl
    6 ## It provides access to utilities for building problem sets
    7 ##
    8 
    9 ####################################################################
   10 # Copyright @ 1995-1998 University of Rochester
   11 # All Rights Reserved
   12 ####################################################################
   13 
   14 use lib '.'; use webworkInit; # WeBWorKInitLine
   15 use CGI qw(:standard);
   16 use Global;
   17 use Auth;
   18 use strict;
   19 
   20 # begin Timing code
   21 use Benchmark;
   22 my $beginTime = new Benchmark;
   23 # end Timing code
   24 
   25 my $cgi = new CGI;
   26 my %inputs = $cgi->Vars();
   27 
   28 # get information from CGI inputs  (see also below for additional information)
   29 
   30 my $Course    = $inputs{'course'};
   31 my $User    = $inputs{'user'};
   32 my $Session_key   = $inputs{'key'};
   33 
   34 # verify that information has been received
   35 unless($Course && $User && $Session_key) {
   36   &wwerror("$0","The script did not receive the proper input data.","","");
   37 }
   38 
   39 # establish environment for this script
   40 
   41 &Global::getCourseEnvironment($inputs{'course'});
   42 
   43 
   44 my $cgiURL        = getWebworkCgiURL;
   45 my $courseScriptsDirectory  = getCourseScriptsDirectory;
   46 my $databaseDirectory     = getCourseDatabaseDirectory;
   47 my $htmlURL           = getCourseHtmlURL;
   48 my $scriptDirectory       = getWebworkScriptDirectory;
   49 my $templateDirectory     = getCourseTemplateDirectory;
   50 my $dat       = getDat;
   51 my $dd        = getDirDelim;
   52 
   53 require "${scriptDirectory}$Global::DBglue_pl";
   54 require "${scriptDirectory}$Global::FILE_pl";
   55 require "${scriptDirectory}$Global::HTMLglue_pl";
   56 
   57 # log access
   58 &Global::log_info('', query_string);
   59 
   60 
   61 my $permissionsFile = &Global::getCoursePermissionsFile($inputs{'course'});
   62 my $permissions = &get_permissions($inputs{'user'}, $permissionsFile);
   63 my $keyFile = &Global::getCourseKeyFile($inputs{'course'});
   64 # my $defaultClasslistFile = getCourseClasslistFile($Course);
   65 
   66 #verify session key
   67   &verify_key($inputs{'user'}, $inputs{'key'}, $keyFile, $inputs{'course'});
   68 
   69 # verify permissions are correct
   70   if ($permissions != $Global::instructor_permissions ) {
   71     print "permissions = $permissions instructor_permissions = $Global::instructor_permissions\n";
   72     print &html_NO_PERMISSION;
   73     exit(0);
   74     }
   75 # get the rest of the information from the submitted form
   76   # nothing further to get in this case
   77 
   78 # print HTML text
   79 print &htmlTOP("Build Problem Set Utilities");
   80 
   81 # print navigation button
   82 print $cgi->a( { -href=>"${cgiURL}login.pl?user=$User&key=$Session_key&course=$Course" },
   83 
   84                         $cgi->img({ #  -name=>'upImg',  # name is not an attribute of img
   85                                           -src=>"${Global::upImgUrl}",
   86                                           -align=>'right',
   87                                           -border=>'1',
   88                                           -alt=>'[Up]'
   89                                         })
   90                         ),
   91         $cgi->p;
   92 
   93 print "\n",
   94         $cgi->hr, $cgi->br,
   95         "\n\n", $cgi->h3({ -align=>'left' }, "WeBWorK Housekeeping Utilities for $Course"), "\n",
   96         $cgi->p,
   97   "From this page, you can build a problem set, edit a set definition or header file, or
   98   destroy and rebuild sets in one operation";
   99 
  100 # build problem sets
  101 print heading('Build', "1. Build Problem Sets for $Course"),
  102   $cgi->p,  "Select the Set Definition file(s) to be used to build the set(s).  Note that
  103       by selecting multiple Set Definition files, you can build multiple sets at one time.  If you want to
  104       see lists of actions for individual students, select the appropriate button.  Note that some of these
  105       selections may return a lot of data.",
  106   $cgi->p,  "Building a set which already exists will not change any data for students already  in the set.  It
  107       will however add all new students to the set.\n",
  108   $cgi->startform(-action=>"${cgiURL}profBuildProblemSet.pl");
  109 
  110  ## find the available set definition files
  111 
  112   opendir SETDEFDIR, $templateDirectory or wweror($0,"Can't open directory $templateDirectory","","");
  113     my @allFiles = grep !/^\./, readdir SETDEFDIR;
  114   closedir  SETDEFDIR;
  115 
  116   ## sort the files
  117 
  118   my @setDefFiles = grep /\.def$/, @allFiles;
  119   my @sortedNames = sort @setDefFiles;
  120 
  121   ## print list of files
  122   my  $fileName;
  123 
  124   my ($ind,$label,$date,@stat);
  125   my %labels;
  126   for $ind (@sortedNames) {
  127     $fileName = "${templateDirectory}$ind";
  128       if (-e $fileName) {
  129         @stat = stat($fileName);
  130         $date = $stat[9];
  131         $date = formatDateAndTime($date);
  132         $date =~ s|\s*at.*||;
  133         $label = "  Last Changed $date";
  134       }
  135     $labels{$ind} = "$ind $label";
  136   }
  137 
  138 print $cgi->popup_menu(-name=>'setDefinition', -size=>4, -multiple=>undef, -values=>\@sortedNames, -labels=>\%labels), "\n";
  139 
  140 my %formatLabels = ();
  141 %formatLabels = ('no_students'=>'Don\'t list actions for individual students', 'new_students'=>'List actions only for new students', 'all_students'=>'List actions for all students');
  142 
  143 print $cgi->br, $cgi->radio_group(-name=>'outputFormat', -values=>['no_students','new_students','all_students'], -default=>'no_students', -linebreak=>'true', -labels=>\%formatLabels),
  144   $cgi->submit(-value=>'Build Problem Set(s)'), "\n",
  145   hiddens('user', 'key', 'course'),
  146   $cgi->hidden(-name=>'page', -value=>'build'), "\n",
  147   $cgi->hidden(-name=>'download', -value=>0), "\n",
  148   $cgi->hidden(-name=>'fileName', -value=>'blah'), "\n",
  149   $cgi->endform(), "\n",
  150   $cgi->p;
  151 
  152 #edit set definition files
  153 print heading('editSetDef', "2. Simple editing of $Course Set Definition files"),
  154   $cgi->startform(-action=>"${cgiURL}profEditCourseFiles.pl"),
  155   $cgi->submit(-value=>'Edit Set Definition File'), "\n", #join (",<BR>", @sortedNames), %labels,
  156   $cgi->popup_menu(-name=>'filename', -values=>\@sortedNames, -labels=>\%labels, -default=>$sortedNames[0]), "\n",
  157   hiddens('user', 'key', 'course'),
  158   $cgi->hidden(-name=>'ext', -value=>'def'), "\n",
  159   $cgi->endform(), "\n",
  160   $cgi->p, "This lets you edit set definition files which are used to build problem sets (by detailing due dates, problem filenames, etc).";
  161 
  162 #edit set header files
  163 
  164 ## find the available set header files
  165 ## reuses most of the variable from the above set definition file search
  166   #opendir SETHEADDIR, $templateDirectory or wweror($0,"Can't open directory $templateDirectory","","");
  167   # @allFiles = grep !/^\./, readdir SETHEADDIR;
  168   #closedir  SETHEADDIR;
  169   #my @setHeadFiles = grep /header.*\.pg$/i, @allFiles; #get all files containing 'header' that end in .pg
  170 
  171   # i should fix this so that it doesn't use find!
  172   #my @setHeadFiles = `find $templateDirectory`;
  173   #for (my $i = 0; $i < @setHeadFiles; $i++) {
  174   # $setHeadFiles[$i] =~ s/$templateDirectory//;
  175   # chomp $setHeadFiles[$i];
  176   #}
  177 
  178   my @setHeaderFiles = grep /header.*\.pg$/i, recursiveFindFiles($templateDirectory);
  179   map s|$templateDirectory/?||, @setHeaderFiles;
  180   @sortedNames = sort @setHeaderFiles;
  181 
  182   ## print list of files
  183   $fileName = '';
  184 
  185   ($ind,$label,$date,@stat) = ('', '', '', ());
  186   %labels = ();
  187   for $ind (@sortedNames) {
  188     $fileName = "${templateDirectory}$ind";
  189       if (-e $fileName) {
  190         @stat = stat($fileName);
  191         $date = $stat[9];
  192         $date = formatDateAndTime($date);
  193         $date =~ s|\s*at.*||;
  194         $label = "  Last Changed $date";
  195       }
  196     $labels{$ind} = "$ind $label";
  197   }
  198 
  199 print heading('editSetHead', "3. Simple editing of $Course Set Header files"),
  200   $cgi->startform(-action=>"${cgiURL}profEditCourseFiles.pl"),
  201   $cgi->submit(-value=>'Edit Set Header File'), "\n",
  202   $cgi->popup_menu(-name=>'filename', -values=>\@sortedNames, -labels=>\%labels, -default=>$sortedNames[0]), " (Must contain the word Header in the name)\n",
  203   hiddens('user', 'key', 'course'),
  204   $cgi->hidden(-name=>'ext', -value=>'pg'), "\n",
  205   $cgi->endform(), "\n",
  206   $cgi->p, "This lets you edit set header files which tend to come in two forms: screen set headers which are used for the opening page before viewing problems and paper set headers which are printed right before the problems in a paper copy of a problem set.";
  207 
  208 
  209 if ( -e "${databaseDirectory}$Global::database" ) {
  210   print heading('DestroyRebuild', "4. Destroy and Rebuild Problem Sets for $Course."),
  211     $cgi->p,  "Select the set(s) to destroy and rebuild.  Note that
  212         by selecting multiple sets, you can destroy and rebuild multiple sets at one time.  Note that
  213         destroying sets removes all associated data (and .sco files) from the database.
  214         The reconstructed sets will have problem with different psvn's and seeds and all scoring
  215         information will be removed from the webwork-database and .sco files.<b> Be very careful.</b>
  216         if you want to save the current scoring information for a set to be
  217         destroyed and rebuilt, score the set before deleting it (go to the scoring page) and/or move
  218         the .sco files out of the DATA directory. <b> Be very careful and think before you click.</b>",
  219     $cgi->p, $cgi->p, "Select the set(s) to destroy and rebuild:",
  220     $cgi->startform(-action=>"${cgiURL}profBuildProblemSet.pl");
  221 
  222     my %availableSets = &getAllProbSetNumbersHash;
  223     my @sortedSetNames = &sortSetNamesByDueDate(\%availableSets);
  224 
  225     # enter the available set names
  226     for $ind (@sortedSetNames) {
  227       $labels{$ind} = "Set $ind";
  228     }
  229 
  230 print $cgi->popup_menu(-name=>'setNo', -size=>4, -multiple=>undef, -values=>\@sortedSetNames, -labels=>\%labels), "\n",
  231   $cgi->br, $cgi->radio_group(-name=>'outputFormat', -values=>['no_students','all_students'], -default=>'no_students', -linebreak=>'true', -labels=>\%formatLabels),
  232   $cgi->p, $cgi->submit(-value=>'Destroy and Rebuild'), "\n",
  233   $cgi->radio_group(-name=>'confirm', -values=>['0', '1'], -default=>'0', -labels=>{'0'=>'Off', '1'=>'Destroy and Rebuild enabled'}), "\n",
  234   hiddens('user', 'key', 'course'),
  235   $cgi->hidden(-name=>'page', -value=>'destroy'), "\n",
  236   $cgi->hidden(-name=>'download', -value=>0), "\n",
  237   $cgi->hidden(-name=>'fileName', -value=>''), "\n",
  238   $cgi->endform(), "\n",
  239   $cgi->p;
  240 
  241 }  ## end of long if which began on line 202.  Clean up this code next time.
  242 
  243 # print &sessionKeyInputs(\%inputs);  Don't use this.  It's duplicating the course, user and key which have already been   put in.
  244 
  245 print &htmlBOTTOM("profBuildProblemSetPage.pl", \%inputs, 'profBuildProblemSetPageHelp.html');
  246 
  247 # begin Timing code
  248 my $endTime = new Benchmark;
  249 &Global::logTimingInfo($beginTime,$endTime,"profBuildProblemSetPage.pl",$inputs{'course'},$inputs{'user'});
  250 # end Timing code
  251 exit;
  252 
  253 ################################################################################
  254 #
  255 # HELPFUL METHODS
  256 #
  257 ################################################################################
  258 
  259 #returns the horizontal line, blue square, and heading for each option
  260 #in the list, eliminating the need to repeat this code each time it is needed
  261 #this does NOT PRINT the info, so that it can be incorporated into other text
  262 sub heading {
  263         my $link = shift; #name for internal link (used for shortcuts on some pages)
  264         my $text = shift; #text used as the main heading
  265 
  266         return "\n",
  267                  $cgi->p, "\n",
  268                  $cgi->a({-name=>$link},''), "\n",
  269                  $cgi->hr({ -noshade=>undef }), "\n",
  270                  $cgi->h4({ -align=>'LEFT' },
  271                                 "\n" . $cgi->img({-src=>"$Global::bluesquareImgUrl", -border=>1, -alt=>'' }) . "\n" .
  272                                 $text ), "\n";
  273 }
  274 
  275 #prints hidden form fields for each of given cgi parameters
  276 #if a given parameter does not exist, a note is placed in the html to that affect
  277 #this does NOT PRINT the info, so that it can be incorporated into other text
  278 sub hiddens {
  279   my @params = @_;
  280   my $out;
  281 
  282   foreach my $param (@params) {
  283     if (exists $inputs{$param}) {
  284       $out .= $cgi->hidden(-name=>"$param", -value=>"$inputs{$param}") . "\n";
  285     } else {
  286       $out .= $cgi->p . "\nExpected cgi parameter $param does not exist or is empty";
  287     }
  288   }
  289   $out;
  290 }
  291 
  292 sub recursiveFindFiles
  293 {
  294   my $dir = shift;
  295   $dir .= '/' unless $dir =~ m|/$|;
  296   opendir DIR, $dir;
  297   my @items = readdir DIR;
  298   closedir DIR;
  299   my @result;
  300   foreach (@items) {
  301     /^\./ and next;
  302     -f "$dir$_" and push @result, "$dir$_";
  303     -d "$dir$_" and push @result, recursiveFindFiles("$dir$_");
  304   }
  305   return @result;
  306 }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9