[system] / branches / rel-2-4-patches / webwork-modperl / lib / WeBWorK / ContentGenerator / CourseAdmin.pm Repository:
ViewVC logotype

Diff of /branches/rel-2-4-patches/webwork-modperl/lib/WeBWorK/ContentGenerator/CourseAdmin.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2241 Revision 2242
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 3# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v 1.12 2004/05/22 01:08:09 sh002i Exp $ 4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v 1.13 2004/05/23 23:59:41 sh002i Exp $
5# 5#
6# This program is free software; you can redistribute it and/or modify it under 6# This program is free software; you can redistribute it and/or modify it under
7# the terms of either: (a) the GNU General Public License as published by the 7# the terms of either: (a) the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any later 8# Free Software Foundation; either version 2, or (at your option) any later
9# version, or (b) the "Artistic License" which comes with this package. 9# version, or (b) the "Artistic License" which comes with this package.
27use warnings; 27use warnings;
28use CGI::Pretty qw(); 28use CGI::Pretty qw();
29use Data::Dumper; 29use Data::Dumper;
30use File::Temp qw/tempfile/; 30use File::Temp qw/tempfile/;
31use WeBWorK::CourseEnvironment; 31use WeBWorK::CourseEnvironment;
32use WeBWorK::Utils qw(cryptPassword); 32use WeBWorK::Utils qw(cryptPassword writeLog);
33use WeBWorK::Utils::CourseManagement qw(addCourse deleteCourse listCourses); 33use WeBWorK::Utils::CourseManagement qw(addCourse deleteCourse listCourses);
34use WeBWorK::Utils::DBImportExport qw(dbExport dbImport); 34use WeBWorK::Utils::DBImportExport qw(dbExport dbImport);
35 35
36sub pre_header_initialize { 36sub pre_header_initialize {
37 my ($self) = @_; 37 my ($self) = @_;
194 my $ce = $r->ce; 194 my $ce = $r->ce;
195 #my $db = $r->db; 195 #my $db = $r->db;
196 #my $authz = $r->authz; 196 #my $authz = $r->authz;
197 #my $urlpath = $r->urlpath; 197 #my $urlpath = $r->urlpath;
198 198
199 my $add_courseID = $r->param("add_courseID") || ""; 199 my $add_courseID = $r->param("add_courseID") || "";
200 my $add_dbLayout = $r->param("add_dbLayout") || ""; 200 my $add_dbLayout = $r->param("add_dbLayout") || "";
201 my $add_sql_host = $r->param("add_sql_host") || ""; 201 my $add_sql_host = $r->param("add_sql_host") || "";
202 my $add_sql_port = $r->param("add_sql_port") || ""; 202 my $add_sql_port = $r->param("add_sql_port") || "";
203 my $add_sql_username = $r->param("add_sql_username") || ""; 203 my $add_sql_username = $r->param("add_sql_username") || "";
204 my $add_sql_password = $r->param("add_sql_password") || ""; 204 my $add_sql_password = $r->param("add_sql_password") || "";
205 my $add_sql_database = $r->param("add_sql_database") || ""; 205 my $add_sql_database = $r->param("add_sql_database") || "";
206 my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; 206 my $add_sql_wwhost = $r->param("add_sql_wwhost") || "";
207 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; 207 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || "";
208 my $add_initial_userID = $r->param("add_initial_userID") || ""; 208 my $add_initial_userID = $r->param("add_initial_userID") || "";
209 my $add_initial_password = $r->param("add_initial_password") || ""; 209 my $add_initial_password = $r->param("add_initial_password") || "";
210 my $add_feedback_email = $r->param("add_feedback_email") || "";
210 my $add_templates_course = $r->param("add_templates_course") || ""; 211 my $add_templates_course = $r->param("add_templates_course") || "";
212 my $add_contact_person = $r->param("add_contact_person") || "";
213 my $add_contact_institution = $r->param("add_contact_institution") || "";
214 my $add_course_title = $r->param("add_course_title") || "";
215 my $add_contact_email = $r->param("add_contact_email") || "";
216 my $add_admin_userID = $r->param("add_admin_userID") || $r->param("user") || "";
217 my $add_admin_password = $r->param("add_admin_password") || "";
211 218
212 my @dbLayouts = sort keys %{ $ce->{dbLayouts} }; 219 my @dbLayouts = sort keys %{ $ce->{dbLayouts} };
213 220
214 my $ce2 = WeBWorK::CourseEnvironment->new( 221 my $ce2 = WeBWorK::CourseEnvironment->new(
215 $ce->{webworkDirs}->{root}, 222 $ce->{webworkDirs}->{root},
246 253
247 print CGI::p("Specify a name for the new course."); 254 print CGI::p("Specify a name for the new course.");
248 255
249 print CGI::table({class=>"FormLayout"}, 256 print CGI::table({class=>"FormLayout"},
250 CGI::Tr( 257 CGI::Tr(
251 CGI::th({class=>"LeftHeader"}, "Course Name:"), 258 CGI::th({class=>"LeftHeader"}, "Course ID:"),
252 CGI::td(CGI::textfield("add_courseID", $add_courseID, 25)), 259 CGI::td(CGI::textfield("add_courseID", $add_courseID, 25)),
260 CGI::th({class=>"LeftHeader"}, "Course Title"),
261 CGI::td(CGI::textfield("add_course_title", $add_course_title, 25)),
253 ), 262 ),
254 ); 263 );
255 264
265 print CGI::p("To add an initial user to the new course, enter a user ID and password below. If you do not do so, you will not be able to log into the course.");
266
267 print CGI::table({class=>"FormLayout"},
268 CGI::Tr(
269 CGI::th({class=>"CenterHeader"}, "Professor User ID"),
270 CGI::th({class=>"CenterHeader"}, "Professor Password"),
271 CGI::th({class=>"CenterHeader"}, "Feedback email"),
272
273 ),
274 CGI::Tr(
275 CGI::td(CGI::textfield("add_initial_userID", $add_initial_userID || "professor", 25)),
276 CGI::td(CGI::password_field("add_initial_password", $add_initial_password, 25)),
277 CGI::td(CGI::textfield("add_feedback_email", $add_feedback_email, 25)),
278 ),
279
280 CGI::Tr(
281 CGI::th({class=>"CenterHeader"}, "Contact name"),
282 CGI::th({class=>"CenterHeader"}, "Contact institution"),
283 CGI::th({class=>"CenterHeader"}, "Contact e-mail"),
284 ),
285 CGI::Tr(
286 CGI::td(CGI::textfield("add_contact_person", $add_contact_person, 35)),
287 CGI::td(CGI::textfield("add_contact_institution", $add_contact_institution, 35)),
288 CGI::td(CGI::textfield("add_contact_email", $add_contact_email, 35)),
289 ),
290 CGI::Tr(
291 CGI::th({class=>"CenterHeader"}, "Administrator User ID"),
292 CGI::th({class=>"CenterHeader"}, "Administrator Password"),
293 CGI::th({class=>"CenterHeader"}, " "),
294
295 ),
296 CGI::Tr(
297 CGI::td(CGI::textfield("add_admin_userID", $add_admin_userID, 25)),
298 CGI::td(CGI::password_field("add_admin_password", $add_admin_password, 25)),
299 CGI::td(' '),
300 ),
301 );
256 print CGI::p("Select a database layout below. Some database layouts require additional information."); 302 print CGI::p("Select a database layout below. Some database layouts require additional information.");
257 303
258 #print CGI::start_Tr(); 304 #print CGI::start_Tr();
259 #print CGI::th({class=>"LeftHeader"}, "Database Layout:"); 305 #print CGI::th({class=>"LeftHeader"}, "Database Layout:");
260 #print CGI::start_td(); 306 #print CGI::start_td();
336 print CGI::end_Tr(); 382 print CGI::end_Tr();
337 print CGI::end_table(); 383 print CGI::end_table();
338 } 384 }
339 385
340 386
341 print CGI::p("To add an initial user to the new course, enter a user ID and password below. If you do not do so, you will not be able to log into the course.");
342 387
343 print CGI::table({class=>"FormLayout"},
344 CGI::Tr(
345 CGI::th({class=>"LeftHeader"}, "Professor User ID:"),
346 CGI::td(CGI::textfield("add_initial_userID", $add_initial_userID || "professor", 25)),
347 ),
348 CGI::Tr(
349 CGI::th({class=>"LeftHeader"}, "Professor Password:"),
350 CGI::td(CGI::password_field("add_initial_password", $add_initial_password, 25)),
351 ),
352 );
353 388
389
354 print CGI::p("Select an existing course from which to copy templates:"); 390 print CGI::p("Select an existing course from which to copy templates:");
355 391
356 print CGI::table({class=>"FormLayout"}, 392 print CGI::table({class=>"FormLayout"},
357 CGI::Tr( 393 CGI::Tr(
358 CGI::th({class=>"LeftHeader"}, "Copy templates from:"), 394 CGI::th({class=>"LeftHeader"}, "Copy templates from:"),
393 my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; 429 my $add_sql_wwhost = $r->param("add_sql_wwhost") || "";
394 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; 430 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || "";
395 my $add_initial_userID = $r->param("add_initial_userID") || ""; 431 my $add_initial_userID = $r->param("add_initial_userID") || "";
396 my $add_initial_password = $r->param("add_initial_password") || ""; 432 my $add_initial_password = $r->param("add_initial_password") || "";
397 my $add_templates_course = $r->param("add_templates_course") || ""; 433 my $add_templates_course = $r->param("add_templates_course") || "";
398 434 my $add_contact_person = $r->param("add_contact_person") || "";
435 my $add_contact_institution = $r->param("add_contact_institution") || "";
436 my $add_contact_email = $r->param("add_contact_email") || "";
437 my $add_course_title = $r->param("add_course_title") || "";
438 my $add_admin_userID = $r->param("add_admin_userID") || "";
439 my $add_admin_password = $r->param("add_admin_password") || "";
440
399 my @errors; 441 my @errors;
400 442
401 if ($add_courseID eq "") { 443 if ($add_courseID eq "") {
402 push @errors, "You must specify a course name."; 444 push @errors, "You must specify a course name.";
403 } 445 }
446 if ($add_contact_institution eq "") {
447 push @errors, "You must specify a contact institution." ;
448 }
449 if ($add_contact_person eq "") {
450 push @errors, "You must specify a contact person.";
451 }
452 if ($add_contact_email eq "") {
453 push @errors, "You must specify an email address for the contact person." ;
454 }
455 if ($add_course_title eq "") {
456 push @errors, "You must specify a title for the course.";
457 }
458
404 459
405 if ($add_dbLayout eq "") { 460 if ($add_dbLayout eq "") {
406 push @errors, "You must select a database layout."; 461 push @errors, "You must select a database layout.";
407 } else { 462 } else {
408 if (exists $ce->{dbLayouts}->{$add_dbLayout}) { 463 if (exists $ce->{dbLayouts}->{$add_dbLayout}) {
420 } 475 }
421 476
422 if ($add_initial_userID ne "") { 477 if ($add_initial_userID ne "") {
423 push @errors, "You must specify a professor password." if $add_initial_password eq ""; 478 push @errors, "You must specify a professor password." if $add_initial_password eq "";
424 } 479 }
480 if ($add_admin_userID ne "") {
481 push @errors, "You must specify an admin password for $add_admin_userID." if $add_admin_password eq "";
482 }
483
425 484
426 return @errors; 485 return @errors;
427} 486}
428 487
429sub do_add_course { 488sub do_add_course {
444 my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; 503 my $add_sql_wwhost = $r->param("add_sql_wwhost") || "";
445 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; 504 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || "";
446 my $add_initial_userID = $r->param("add_initial_userID") || ""; 505 my $add_initial_userID = $r->param("add_initial_userID") || "";
447 my $add_initial_password = $r->param("add_initial_password") || ""; 506 my $add_initial_password = $r->param("add_initial_password") || "";
448 my $add_templates_course = $r->param("add_templates_course") || ""; 507 my $add_templates_course = $r->param("add_templates_course") || "";
449 508 my $add_contact_person = $r->param("add_contact_person") || "";
509 my $add_contact_institution = $r->param("add_contact_institution") || "";
510 my $add_contact_email = $r->param("add_contact_email") || "";
511 my $add_course_title = $r->param("add_course_title") || "";
512 my $add_admin_userID = $r->param("add_admin_userID") || $r->param("user") || "";
513 my $add_admin_password = $r->param("add_admin_password") || "";
514
450 my $ce2 = WeBWorK::CourseEnvironment->new( 515 my $ce2 = WeBWorK::CourseEnvironment->new(
451 $ce->{webworkDirs}->{root}, 516 $ce->{webworkDirs}->{root},
452 $ce->{webworkURLs}->{root}, 517 $ce->{webworkURLs}->{root},
453 $ce->{pg}->{directories}->{root}, 518 $ce->{pg}->{directories}->{root},
454 $add_courseID, 519 $add_courseID,
466 $dbOptions{username} = $add_sql_username; 531 $dbOptions{username} = $add_sql_username;
467 $dbOptions{password} = $add_sql_password; 532 $dbOptions{password} = $add_sql_password;
468 $dbOptions{database} = $add_sql_database || "webwork_$add_courseID"; 533 $dbOptions{database} = $add_sql_database || "webwork_$add_courseID";
469 $dbOptions{wwhost} = $add_sql_wwhost; 534 $dbOptions{wwhost} = $add_sql_wwhost;
470 } 535 }
471 536 # add professor and administor if defined.
472 my @users; 537 my @users;
473 if ($add_initial_userID ne "") { 538 if ($add_initial_userID ne "") {
474 my $User = $db->newUser( 539 my $User = $db->newUser(
475 user_id => $add_initial_userID, 540 user_id => $add_initial_userID,
476 status => "C", 541 status => "C",
483 user_id => $add_initial_userID, 548 user_id => $add_initial_userID,
484 permission => "10", 549 permission => "10",
485 ); 550 );
486 push @users, [ $User, $Password, $PermissionLevel ]; 551 push @users, [ $User, $Password, $PermissionLevel ];
487 } 552 }
488 553 if ($add_admin_userID ne "") {
554 my $User = $db->newUser(
555 user_id => $add_admin_userID,
556 status => "C",
557 );
558 my $Password = $db->newPassword(
559 user_id => $add_admin_userID,
560 password => cryptPassword($add_admin_password),
561 );
562 my $PermissionLevel = $db->newPermissionLevel(
563 user_id => $add_admin_userID,
564 permission => "10",
565 );
566 push @users, [ $User, $Password, $PermissionLevel ];
567 }
489 my %optional_arguments; 568 my %optional_arguments;
490 if ($add_templates_course ne "") { 569 if ($add_templates_course ne "") {
491 $optional_arguments{templatesFrom} = $add_templates_course; 570 $optional_arguments{templatesFrom} = $add_templates_course;
492 } 571 }
493 572
507 print CGI::div({class=>"ResultsWithError"}, 586 print CGI::div({class=>"ResultsWithError"},
508 CGI::p("An error occured while creating the course $add_courseID:"), 587 CGI::p("An error occured while creating the course $add_courseID:"),
509 CGI::tt(CGI::escapeHTML($error)), 588 CGI::tt(CGI::escapeHTML($error)),
510 ); 589 );
511 } else { 590 } else {
591 writeLog($ce, "hosted_courses", join("\t",
592 "\tAdded",
593 $add_contact_institution,
594 $add_course_title,
595 $add_courseID,
596 $add_contact_person,
597 $add_contact_email,
598 ));
512 print CGI::div({class=>"ResultsWithoutError"}, 599 print CGI::div({class=>"ResultsWithoutError"},
513 CGI::p("Successfully created the course $add_courseID"), 600 CGI::p("Successfully created the course $add_courseID"),
514 ); 601 );
515 my $newCoursePath = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSets", 602 my $newCoursePath = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSets",
516 courseID => $add_courseID); 603 courseID => $add_courseID);
767 ); 854 );
768 } else { 855 } else {
769 print CGI::div({class=>"ResultsWithoutError"}, 856 print CGI::div({class=>"ResultsWithoutError"},
770 CGI::p("Possibly deleted the course $delete_courseID. (We need better error checking in deleteCourse().)"), 857 CGI::p("Possibly deleted the course $delete_courseID. (We need better error checking in deleteCourse().)"),
771 ); 858 );
772 859 writeLog($ce, "hosted_courses", join("\t",
860 "\tDeleted",
861 "",
862 "",
863 $delete_courseID,
864 ));
773 print CGI::start_form("POST", $r->uri); 865 print CGI::start_form("POST", $r->uri);
774 print $self->hidden_authen_fields; 866 print $self->hidden_authen_fields;
775 print $self->hidden_fields("subDisplay"); 867 print $self->hidden_fields("subDisplay");
776 868
777 print CGI::p({style=>"text-align: center"}, CGI::submit("decline_delete_course", "OK"),); 869 print CGI::p({style=>"text-align: center"}, CGI::submit("decline_delete_course", "OK"),);

Legend:
Removed from v.2241  
changed lines
  Added in v.2242

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9