Parent Directory
|
Revision Log
Revision 10 - (view) (download) (as text)
| 1 : | sam | 10 | #!/usr/local/bin/perl |
| 2 : | sam | 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 : | gage | 8 | use lib '.'; use webworkInit; # WeBWorKInitLine |
| 15 : | sam | 2 | 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 : | |||
| 170 : | ## sort the files | ||
| 171 : | |||
| 172 : | my @setHeadFiles = grep /header.*\.pg$/i, @allFiles; #get all files containing 'set' that end in .pg | ||
| 173 : | @sortedNames = sort @setHeadFiles; | ||
| 174 : | |||
| 175 : | ## print list of files | ||
| 176 : | $fileName = ''; | ||
| 177 : | |||
| 178 : | ($ind,$label,$date,@stat) = ('', '', '', ()); | ||
| 179 : | %labels = (); | ||
| 180 : | for $ind (@sortedNames) { | ||
| 181 : | $fileName = "${templateDirectory}$ind"; | ||
| 182 : | if (-e $fileName) { | ||
| 183 : | @stat = stat($fileName); | ||
| 184 : | $date = $stat[9]; | ||
| 185 : | $date = formatDateAndTime($date); | ||
| 186 : | $date =~ s|\s*at.*||; | ||
| 187 : | $label = " Last Changed $date"; | ||
| 188 : | } | ||
| 189 : | $labels{$ind} = "$ind $label"; | ||
| 190 : | } | ||
| 191 : | |||
| 192 : | print heading('editSetHead', "3. Simple editing of $Course Set Header files"), | ||
| 193 : | $cgi->startform(-action=>"${cgiURL}profEditCourseFiles.pl"), | ||
| 194 : | $cgi->submit(-value=>'Edit Set Header File'), "\n", | ||
| 195 : | $cgi->popup_menu(-name=>'filename', -values=>\@sortedNames, -labels=>\%labels, -default=>$sortedNames[0]), " (Must contain the word header in the name)\n", | ||
| 196 : | hiddens('user', 'key', 'course'), | ||
| 197 : | $cgi->hidden(-name=>'ext', -value=>'pg'), "\n", | ||
| 198 : | $cgi->endform(), "\n", | ||
| 199 : | $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."; | ||
| 200 : | |||
| 201 : | |||
| 202 : | if ( -e "${databaseDirectory}$Global::database" ) { | ||
| 203 : | print heading('DestroyRebuild', "4. Destroy and Rebuild Problem Sets for $Course."), | ||
| 204 : | $cgi->p, "Select the set(s) to destroy and rebuild. Note that | ||
| 205 : | by selecting multiple sets, you can destroy and rebuild multiple sets at one time. Note that | ||
| 206 : | destroying sets removes all associated data (and .sco files) from the database. | ||
| 207 : | The reconstructed sets will have problem with different psvn's and seeds and all scoring | ||
| 208 : | information will be removed from the webwork-database and .sco files.<b> Be very careful.</b> | ||
| 209 : | if you want to save the current scoring information for a set to be | ||
| 210 : | destroyed and rebuilt, score the set before deleting it (go to the scoring page) and/or move | ||
| 211 : | the .sco files out of the DATA directory. <b> Be very careful and think before you click.</b>", | ||
| 212 : | $cgi->p, $cgi->p, "Select the set(s) to destroy and rebuild:", | ||
| 213 : | $cgi->startform(-action=>"${cgiURL}profBuildProblemSet.pl"); | ||
| 214 : | |||
| 215 : | my %availableSets = &getAllProbSetNumbersHash; | ||
| 216 : | my @sortedSetNames = &sortSetNamesByDueDate(\%availableSets); | ||
| 217 : | |||
| 218 : | # enter the available set names | ||
| 219 : | for $ind (@sortedSetNames) { | ||
| 220 : | $labels{$ind} = "Set $ind"; | ||
| 221 : | } | ||
| 222 : | |||
| 223 : | print $cgi->popup_menu(-name=>'setNo', -size=>4, -multiple=>undef, -values=>\@sortedSetNames, -labels=>\%labels), "\n", | ||
| 224 : | $cgi->br, $cgi->radio_group(-name=>'outputFormat', -values=>['no_students','all_students'], -default=>'no_students', -linebreak=>'true', -labels=>\%formatLabels), | ||
| 225 : | $cgi->p, $cgi->submit(-value=>'Destroy and Rebuild'), "\n", | ||
| 226 : | $cgi->radio_group(-name=>'confirm', -values=>['0', '1'], -default=>'0', -labels=>{'0'=>'Off', '1'=>'Destroy and Rebuild enabled'}), "\n", | ||
| 227 : | hiddens('user', 'key', 'course'), | ||
| 228 : | $cgi->hidden(-name=>'page', -value=>'destroy'), "\n", | ||
| 229 : | $cgi->hidden(-name=>'download', -value=>0), "\n", | ||
| 230 : | $cgi->hidden(-name=>'fileName', -value=>''), "\n", | ||
| 231 : | $cgi->endform(), "\n", | ||
| 232 : | $cgi->p; | ||
| 233 : | |||
| 234 : | } ## end of long if which began on line 202. Clean up this code next time. | ||
| 235 : | |||
| 236 : | # print &sessionKeyInputs(\%inputs); Don't use this. It's duplicating the course, user and key which have already been put in. | ||
| 237 : | |||
| 238 : | print &htmlBOTTOM("profBuildProblemSetPage.pl", \%inputs, 'profBuildProblemSetPageHelp.html'); | ||
| 239 : | |||
| 240 : | # begin Timing code | ||
| 241 : | my $endTime = new Benchmark; | ||
| 242 : | &Global::logTimingInfo($beginTime,$endTime,"profBuildProblemSetPage.pl",$inputs{'course'},$inputs{'user'}); | ||
| 243 : | # end Timing code | ||
| 244 : | exit; | ||
| 245 : | |||
| 246 : | ################################################################################ | ||
| 247 : | # | ||
| 248 : | # HELPFUL METHODS | ||
| 249 : | # | ||
| 250 : | ################################################################################ | ||
| 251 : | |||
| 252 : | #returns the horizontal line, blue square, and heading for each option | ||
| 253 : | #in the list, eliminating the need to repeat this code each time it is needed | ||
| 254 : | #this does NOT PRINT the info, so that it can be incorporated into other text | ||
| 255 : | sub heading { | ||
| 256 : | my $link = shift; #name for internal link (used for shortcuts on some pages) | ||
| 257 : | my $text = shift; #text used as the main heading | ||
| 258 : | |||
| 259 : | return "\n", | ||
| 260 : | $cgi->p, "\n", | ||
| 261 : | $cgi->a({-name=>$link},''), "\n", | ||
| 262 : | $cgi->hr({ -noshade=>undef }), "\n", | ||
| 263 : | $cgi->h4({ -align=>'LEFT' }, | ||
| 264 : | "\n" . $cgi->img({-src=>"$Global::bluesquareImgUrl", -border=>1, -alt=>'' }) . "\n" . | ||
| 265 : | $text ), "\n"; | ||
| 266 : | } | ||
| 267 : | |||
| 268 : | #prints hidden form fields for each of given cgi parameters | ||
| 269 : | #if a given parameter does not exist, a note is placed in the html to that affect | ||
| 270 : | #this does NOT PRINT the info, so that it can be incorporated into other text | ||
| 271 : | sub hiddens { | ||
| 272 : | my @params = @_; | ||
| 273 : | my $out; | ||
| 274 : | |||
| 275 : | foreach my $param (@params) { | ||
| 276 : | if (exists $inputs{$param}) { | ||
| 277 : | $out .= $cgi->hidden(-name=>"$param", -value=>"$inputs{$param}") . "\n"; | ||
| 278 : | } else { | ||
| 279 : | $out .= $cgi->p . "\nExpected cgi parameter $param does not exist or is empty"; | ||
| 280 : | } | ||
| 281 : | } | ||
| 282 : | $out; | ||
| 283 : | } |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |