| 1 | #!/usr/bin/perl |
1 | #!/usr/local/bin/perl |
| 2 | |
2 | |
| 3 | ## This file is profExportClasslistDatabase.pl |
3 | ## This file is profExportClasslistDatabase.pl |
| 4 | ## |
4 | ## |
| 5 | |
5 | |
| 6 | #################################################################### |
6 | #################################################################### |
| 7 | # Copyright @ 1995-2000 University of Rochester |
7 | # Copyright @ 1995-2000 University of Rochester |
| 8 | # All Rights Reserved |
8 | # All Rights Reserved |
| 9 | #################################################################### |
9 | #################################################################### |
| 10 | |
10 | |
| 11 | use lib '/ww/webwork/development/'; # mainWeBWorKDirectory; |
11 | use lib '/ww/webwork/gage_system/webwork/system/lib/'; # mainWeBWorKDirectory |
| 12 | use CGI qw(:standard); |
12 | use CGI qw(:standard); |
| 13 | use Global; |
13 | use Global; |
| 14 | use Auth; |
14 | use Auth; |
| 15 | use strict; |
15 | use strict; |
| 16 | use GDBM_File; |
16 | use GDBM_File; |
| … | |
… | |
| 124 | } |
124 | } |
| 125 | |
125 | |
| 126 | my %loginName_StudentID_Hash = %{getLoginName_StudentID_Hash()}; |
126 | my %loginName_StudentID_Hash = %{getLoginName_StudentID_Hash()}; |
| 127 | my %studentID_LoginName_Hash =%{getStudentID_LoginName_Hash()}; |
127 | my %studentID_LoginName_Hash =%{getStudentID_LoginName_Hash()}; |
| 128 | |
128 | |
| 129 | my $WW_DB_exists = 0; |
129 | # my $WW_DB_exists = 0; |
| 130 | $WW_DB_exists = 1 if ( -e "${databaseDirectory}$Global::database" ); |
130 | # $WW_DB_exists = 1 if ( -e "${databaseDirectory}$Global::database" ); |
| 131 | |
131 | |
| 132 | my %loginName_StudentID_Hash_from_WW_DB =(); |
132 | # my %loginName_StudentID_Hash_from_WW_DB =(); |
| 133 | my %studentID_LoginName_Hash_from_WW_DB =(); |
133 | # my %studentID_LoginName_Hash_from_WW_DB =(); |
| 134 | |
134 | |
| 135 | if ($WW_DB_exists) { |
135 | # if ($WW_DB_exists) { |
| 136 | %loginName_StudentID_Hash_from_WW_DB =%{getLoginName_StudentID_Hash_from_WW_DB()}; |
136 | # %loginName_StudentID_Hash_from_WW_DB =%{getLoginName_StudentID_Hash_from_WW_DB()}; |
| 137 | %studentID_LoginName_Hash_from_WW_DB = reverse %loginName_StudentID_Hash_from_WW_DB; |
137 | # %studentID_LoginName_Hash_from_WW_DB = reverse %loginName_StudentID_Hash_from_WW_DB; |
| 138 | } |
138 | # } |
| 139 | |
139 | |
| 140 | my $errors =''; |
140 | my $errors =''; |
| 141 | my %new_good_classlist_students =(); ## students in new classlist without conflicts |
141 | my %new_good_classlist_students =(); ## students in new classlist without conflicts |
| 142 | my %new_bad_classlist_students =(); ## students in new classlist with conflicts |
142 | my %new_bad_classlist_students =(); ## students in new classlist with conflicts |
| 143 | |
143 | |
| … | |
… | |
| 163 | $errors .= "$firstName $lastName, $login_name, $studentID <BR>\n "; |
163 | $errors .= "$firstName $lastName, $login_name, $studentID <BR>\n "; |
| 164 | $new_bad_classlist_students{$login_name} =1; |
164 | $new_bad_classlist_students{$login_name} =1; |
| 165 | next; |
165 | next; |
| 166 | } |
166 | } |
| 167 | |
167 | |
| 168 | if (($WW_DB_exists) and (defined $loginName_StudentID_Hash_from_WW_DB{$login_name}) |
|
|
| 169 | and ($loginName_StudentID_Hash_from_WW_DB{$login_name} ne $studentID)) { |
|
|
| 170 | $errors .= "$firstName $lastName, $login_name, $studentID <BR>\n "; |
|
|
| 171 | $new_bad_classlist_students{$login_name} =1; |
|
|
| 172 | next; |
|
|
| 173 | } |
|
|
| 174 | |
168 | |
| 175 | if (($WW_DB_exists) and (defined $studentID_LoginName_Hash_from_WW_DB{$studentID}) |
169 | |
| 176 | and ($studentID_LoginName_Hash_from_WW_DB{$studentID} ne $login_name)) { |
|
|
| 177 | $errors .= "$firstName $lastName, $login_name, $studentID <BR>\n "; |
|
|
| 178 | $new_bad_classlist_students{$login_name} =1; |
|
|
| 179 | next; |
|
|
| 180 | } |
|
|
| 181 | |
|
|
| 182 | ## OK, the student record has no conflicts |
170 | ## OK, the student record has no conflicts |
| 183 | |
171 | |
| 184 | $new_good_classlist_students{$login_name} =1; |
172 | $new_good_classlist_students{$login_name} =1; |
| 185 | |
173 | |
| 186 | ## Handle students already in classlist DB |
174 | ## Handle students already in classlist DB |
| … | |
… | |
| 195 | &CL_putStudentEmailAddress ($email_address, $login_name) if $update_email_address; |
183 | &CL_putStudentEmailAddress ($email_address, $login_name) if $update_email_address; |
| 196 | $Global::over_ride_CLBD_lock = 1; |
184 | $Global::over_ride_CLBD_lock = 1; |
| 197 | &saveCLRecord($login_name); |
185 | &saveCLRecord($login_name); |
| 198 | $Global::over_ride_CLBD_lock = 0; |
186 | $Global::over_ride_CLBD_lock = 0; |
| 199 | |
187 | |
| 200 | if (($WW_DB_exists) and (defined $loginName_StudentID_Hash_from_WW_DB{$login_name})) { |
188 | |
| 201 | my %setNumberHash=&getAllSetNumbersForStudentLoginHash($login_name); |
|
|
| 202 | my @PSVNs = values %setNumberHash; |
|
|
| 203 | my $psvn; |
|
|
| 204 | foreach $psvn (@PSVNs) { |
|
|
| 205 | attachProbSetRecord($psvn); |
|
|
| 206 | putStudentLastName( $lastName ,$psvn) if $update_lastName; |
|
|
| 207 | putStudentFirstName( $firstName ,$psvn) if $update_firstName; |
|
|
| 208 | putStudentStatus( $status ,$psvn) if $update_status; |
|
|
| 209 | putClassSection( $section ,$psvn) if $update_section; |
|
|
| 210 | putClassRecitation( $recitation ,$psvn) if $update_recitation; |
|
|
| 211 | putStudentEmailAddress( $email_address,$psvn) if $update_email_address; |
|
|
| 212 | detachProbSetRecord($psvn); |
|
|
| 213 | } |
|
|
| 214 | } |
189 | } |
| 215 | } |
|
|
| 216 | else { ## Handle new students |
190 | else { ## Handle new students |
| 217 | &CL_putStudentID ($studentID, $login_name); |
191 | &CL_putStudentID ($studentID, $login_name); |
| 218 | &CL_putStudentLastName ($lastName, $login_name); |
192 | &CL_putStudentLastName ($lastName, $login_name); |
| 219 | &CL_putStudentFirstName ($firstName, $login_name); |
193 | &CL_putStudentFirstName ($firstName, $login_name); |
| 220 | &CL_putStudentStatus ($status, $login_name); |
194 | &CL_putStudentStatus ($status, $login_name); |
| 221 | &CL_putComment ($comment, $login_name); |
195 | &CL_putComment ($comment, $login_name); |
| … | |
… | |
| 223 | &CL_putClassRecitation ($recitation,$login_name); |
197 | &CL_putClassRecitation ($recitation,$login_name); |
| 224 | &CL_putStudentEmailAddress ($email_address, $login_name); |
198 | &CL_putStudentEmailAddress ($email_address, $login_name); |
| 225 | $Global::over_ride_CLBD_lock = 1; |
199 | $Global::over_ride_CLBD_lock = 1; |
| 226 | &saveCLRecord($login_name); |
200 | &saveCLRecord($login_name); |
| 227 | $Global::over_ride_CLBD_lock = 0; |
201 | $Global::over_ride_CLBD_lock = 0; |
| 228 | |
|
|
| 229 | if (($WW_DB_exists) and (defined $loginName_StudentID_Hash_from_WW_DB{$login_name})) { |
|
|
| 230 | my %setNumberHash=&getAllSetNumbersForStudentLoginHash($login_name); |
|
|
| 231 | my @PSVNs = values %setNumberHash; |
|
|
| 232 | my $psvn; |
|
|
| 233 | foreach $psvn (@PSVNs) { |
|
|
| 234 | attachProbSetRecord($psvn); |
|
|
| 235 | putStudentLastName( $lastName ,$psvn); |
|
|
| 236 | putStudentFirstName( $firstName,$psvn); |
|
|
| 237 | putStudentStatus( $status ,$psvn); |
|
|
| 238 | putClassSection( $section ,$psvn); |
|
|
| 239 | putClassRecitation( $recitation ,$psvn); |
|
|
| 240 | putStudentEmailAddress( $email_address ,$psvn); |
|
|
| 241 | detachProbSetRecord($psvn); |
|
|
| 242 | } |
|
|
| 243 | } |
202 | } |
| 244 | } |
|
|
| 245 | |
|
|
| 246 | } |
203 | } |
| 247 | |
204 | |
| 248 | ## Now we take care of students who are in the current classlist database but are not in |
205 | ## Now we take care of students who are in the current classlist database but are not in |
| 249 | ## the classlist file. |
206 | ## the classlist file. |
| 250 | |
207 | |
| … | |
… | |
| 308 | wwerror ($0, "Permissions set incorrectly on $permissionsFile or its directory. |
265 | wwerror ($0, "Permissions set incorrectly on $permissionsFile or its directory. |
| 309 | Cannot access file to both read and write."); |
266 | Cannot access file to both read and write."); |
| 310 | } |
267 | } |
| 311 | |
268 | |
| 312 | my $login_name; |
269 | my $login_name; |
| 313 | |
270 | |
| 314 | my @classList = @{getAllLoginNames()}; |
271 | my @classList = @{getAllLoginNames()}; |
| 315 | |
272 | |
| 316 | $msg .= "\n<BR><BR> Modifying the password file :\n $passwordFile <BR>\n "; |
273 | $msg .= "\n<BR><BR> Modifying the password file :\n $passwordFile <BR>\n "; |
| 317 | |
274 | |
| 318 | foreach $login_name (@classList) { ## read through classlist database and create |
275 | foreach $login_name (@classList) { ## read through classlist database and create |
| … | |
… | |
| 386 | |
343 | |
| 387 | |
344 | |
| 388 | sub uploadSuccess { |
345 | sub uploadSuccess { |
| 389 | my ($msg) = @_; |
346 | my ($msg) = @_; |
| 390 | print"content-type: text/html\n\n<H2>Success, the classlist database has been updated. </H2>\n"; |
347 | print"content-type: text/html\n\n<H2>Success, the classlist database has been updated. </H2>\n"; |
| 391 | print $msg; |
348 | print $msg; |
| 392 | print &htmlBOTTOM("profImportClasslistDatabase.pl", \%inputs); |
349 | print &htmlBOTTOM("profImportClasslistDatabase.pl", \%inputs); |
| 393 | } |
350 | } |
| 394 | |
351 | |
| 395 | sub backup { |
352 | sub backup { |
| 396 | ## takes as a parameter the full path name |
353 | ## takes as a parameter the full path name |