Parent Directory
|
Revision Log
nothing should change
1 #!/usr/local/bin/perl 2 3 ## This file is profSortScoringFiles.pl 4 ## It provides access to utilities for downloading scoring files 5 ## 6 7 #################################################################### 8 # Copyright @ 1995-1998 University of Rochester 9 # All Rights Reserved 10 #################################################################### 11 12 use lib '.'; use webworkInit; # WeBWorKInitLine 13 use CGI qw(:standard); 14 use Global; 15 use Auth; 16 use strict; 17 18 # begin Timing code 19 use Benchmark; 20 my $beginTime = new Benchmark; 21 # end Timing code 22 23 &CGI::ReadParse; 24 my %inputs =%main::in; 25 26 # get information from CGI inputs (see also below for additional information) 27 28 my $Course = $inputs{'course'}; 29 my $User = $inputs{'user'}; 30 my $Session_key = $inputs{'key'}; 31 32 my @array = %inputs; 33 # print "inputs are @array"; 34 35 # verify that information has been received 36 unless($Course && $User && $Session_key) { 37 &wwerror("$0","The script did not receive the proper input data.","",""); 38 } 39 40 41 # establish environment for this script 42 43 &Global::getCourseEnvironment($inputs{'course'}); 44 45 my $cgiURL = getWebworkCgiURL; 46 my $databaseDirectory = getCourseDatabaseDirectory; 47 my $htmlURL = getCourseHtmlURL; 48 my $scriptDirectory = getWebworkScriptDirectory; 49 my $scoringDirectory = getCourseScoringDirectory; 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 require "${scriptDirectory}$Global::SCRtools_pl"; 57 58 # log access 59 &Global::log_info('', query_string); 60 61 62 my $permissionsFile = &Global::getCoursePermissionsFile($inputs{'course'}); 63 my $permissions = &get_permissions($inputs{'user'}, $permissionsFile); 64 my $keyFile = &Global::getCourseKeyFile($inputs{'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 77 78 my $totalsFile = $inputs{'totalsFile'}; 79 my $scrFiles = $inputs{'scrFiles'}; 80 my $fulFiles = $inputs{'fulFiles'}; 81 my $fileName = $inputs{'fileName'}; 82 my $action = $inputs{'action'}; 83 my $sortOrder = $inputs{'sortOrder'}; 84 85 ## define values even if check boxes not checked 86 $totalsFile = 0 unless defined $totalsFile; 87 $scrFiles = 0 unless defined $scrFiles; 88 $fulFiles = 0 unless defined $fulFiles; 89 90 ## if totals file is the only one selected, sort it immediately 91 92 OPTIONSWITCH: { 93 if ($totalsFile == 1 and $scrFiles == 0 and $fulFiles == 0 and $action eq '') { 94 $fileName = "${scoringDirectory}${Course}_totals.csv"; 95 unless (-r $fileName) { 96 &wwerror("$0","The file $fileName is not readable by the webserver","",""); 97 } 98 &sortScoringFile($fileName, $sortOrder); 99 last OPTIONSWITCH; 100 } 101 if ($scrFiles > 0 or $fulFiles > 0 and $action eq '') { 102 &selectFilesForm(); 103 last OPTIONSWITCH; 104 } 105 if ($action eq 'sort') { 106 &sortScoringFile("${scoringDirectory}$fileName", $sortOrder); 107 last OPTIONSWITCH; 108 } 109 if ($totalsFile == 0 and $scrFiles == 0 and $fulFiles == 0 and $action eq '') { 110 &wwerror("$0","You must check at least one check box","",""); 111 last OPTIONSWITCH; 112 } 113 } 114 115 # begin Timing code 116 my $endTime = new Benchmark; 117 &Global::logTimingInfo($beginTime,$endTime,"profScoring.pl",$inputs{'course'},$inputs{'user'}); 118 # end Timing code 119 120 exit; 121 122 ## subroutines 123 124 125 sub selectFilesForm { 126 127 # print HTML text 128 print &htmlTOP("Select Scoring File for sorting"); 129 130 # print navigation buttons 131 print qq! 132 <A HREF="${cgiURL}profLogin.pl?user=$inputs{'user'}&key=$inputs{'key'}&course=$inputs{'course'}"> 133 <IMG SRC="${Global::upImgUrl}" align="right" BORDER=1 ALT="[Up]"></A><p> 134 !; 135 136 print <<EOF; 137 <h3 align="left">Sort scoring files for $Course</h3> <p> 138 EOF 139 140 141 print <<EOF; 142 <P> 143 <HR NOSHADE> 144 <H4 ALIGN=LEFT> 145 Select files: 146 </H4> 147 148 <FORM METHOD = "POST" ACTION= "${cgiURL}profSortScoringFiles.pl"> 149 <INPUT TYPE="SUBMIT" VALUE="Sort"> 150 151 EOF 152 153 ## find the available files 154 155 opendir SCORINGDIR, $scoringDirectory or wwerror("$0","Can't open directory $scoringDirectory","",""); 156 my @allFiles = grep !/^\./, readdir SCORINGDIR; 157 closedir SCORINGDIR; 158 159 ## sort the files 160 161 my @totalsFiles = grep /${Course}_totals\.csv$/,@allFiles; 162 my @scrFiles = grep /scr\.csv$/,@allFiles; 163 my @fulFiles = grep /ful\.csv$/,@allFiles; 164 my @sortedNames = (); 165 166 if ($totalsFile) { 167 @totalsFiles = sort @totalsFiles; 168 @sortedNames = (@sortedNames,@totalsFiles); 169 } 170 if ($scrFiles) { 171 @scrFiles = sort @scrFiles; 172 @sortedNames = (@sortedNames, @scrFiles); 173 } 174 if ($fulFiles) { 175 @fulFiles = sort @fulFiles; 176 @sortedNames = (@sortedNames, @fulFiles); 177 } 178 179 ## print list of files 180 181 print qq! <SELECT Name="fileName" >\n!; 182 my ($ind); 183 for $ind (@sortedNames) { 184 print "<OPTION VALUE = \"$ind\">$ind\n"; 185 } 186 print qq!</SELECT>\n!; 187 188 ## resume printing the rest of the form 189 190 print <<EOF; 191 <INPUT TYPE="HIDDEN" NAME="user" VALUE="$inputs{'user'}"> 192 <INPUT TYPE="HIDDEN" NAME="key" VALUE="$inputs{'key'}"> 193 <INPUT TYPE="HIDDEN" NAME="course" VALUE="$inputs{'course'}"> 194 <INPUT TYPE="HIDDEN" NAME="action" VALUE='sort'> 195 <INPUT TYPE="HIDDEN" NAME="sortOrder" VALUE="$inputs{'sortOrder'}"> 196 </FORM> 197 EOF 198 print &htmlBOTTOM("profFormEditScoringFiles.pl", \%inputs); 199 } 200 201 202 203 sub selectionError { 204 print"content-type:\n\n<H2>Error: You must make a selection!</H2>\n"; 205 print "<FORM METHOD=POST ACTION=\"${cgiURL}profSortFiles.pl\"><P>"; 206 print &sessionKeyInputs(\%inputs); 207 print <<"ENDOFHTML"; 208 <INPUT TYPE=SUBMIT VALUE="Return to Sort Scoring Files Page"> 209 </FORM> 210 ENDOFHTML 211 print &htmlBOTTOM("profSortFiles.pl", \%inputs); 212 } 213 214 sub sortScoringFile { 215 my ($fulFileName, $sortOrder) = @_; 216 my $shortFileName = $fulFileName; 217 if ($shortFileName =~ m|$dd|) { 218 $shortFileName =~ m|$dd([^$dd]*)$|; ## extract filename from full path name 219 $shortFileName = $1; 220 } 221 $shortFileName =~ s|\..*||; ## remove extension 222 my %assocArray = &dat2aa("$shortFileName"); 223 &backup("$shortFileName"); ##make up to three backups 224 &aa2dat(\%assocArray,"$shortFileName", $sortOrder); ##sort 225 &sortSuccess($fulFileName); 226 227 } 228 229 230 sub sortSuccess { 231 my ($savedFile) = @_; 232 print"content-type:\n\n<H2>Success, file sorted. </H2>\n"; 233 print "Your file:<BR>$savedFile <BR>has been successfully sorted. The original file 234 has been saved to a backup file."; 235 236 print "<FORM METHOD=POST ACTION=\"${cgiURL}profScoring.pl\"><P>"; 237 print &sessionKeyInputs(\%inputs); 238 print <<"ENDOFHTML"; 239 <INPUT TYPE=SUBMIT VALUE="Return to Scoring Page"> 240 </FORM> 241 ENDOFHTML 242 print &htmlBOTTOM("profSortScoringFiles.pl", \%inputs); 243 }
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |