[system] / trunk / webwork-modperl / lib / WeBWorK / ContentGenerator / CourseAdmin.pm Repository:
ViewVC logotype

Diff of /trunk/webwork-modperl/lib/WeBWorK/ContentGenerator/CourseAdmin.pm

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

Revision 2377 Revision 2378
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.18 2004/06/16 01:58:03 gage Exp $ 4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v 1.19 2004/06/23 19:19:32 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.
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_courseTitle = $r->param("add_courseTitle") || "";
201 my $add_courseInstitution = $r->param("add_courseInstitution") || "";
202
203 my $add_admin_users = $r->param("add_admin_users") || "";
204
205 my $add_initial_userID = $r->param("add_initial_userID") || "";
206 my $add_initial_password = $r->param("add_initial_password") || "";
207 my $add_initial_confirmPassword = $r->param("add_initial_confirmPassword") || "";
208 my $add_initial_firstName = $r->param("add_initial_firstName") || "";
209 my $add_initial_lastName = $r->param("add_initial_lastName") || "";
210 my $add_initial_email = $r->param("add_initial_email") || "";
211
212 my $add_templates_course = $r->param("add_templates_course") || "";
213
200 my $add_dbLayout = $r->param("add_dbLayout") || ""; 214 my $add_dbLayout = $r->param("add_dbLayout") || "";
201 my $add_sql_host = $r->param("add_sql_host") || ""; 215 my $add_sql_host = $r->param("add_sql_host") || "";
202 my $add_sql_port = $r->param("add_sql_port") || ""; 216 my $add_sql_port = $r->param("add_sql_port") || "";
203 my $add_sql_username = $r->param("add_sql_username") || ""; 217 my $add_sql_username = $r->param("add_sql_username") || "";
204 my $add_sql_password = $r->param("add_sql_password") || ""; 218 my $add_sql_password = $r->param("add_sql_password") || "";
205 my $add_sql_database = $r->param("add_sql_database") || ""; 219 my $add_sql_database = $r->param("add_sql_database") || "";
206 my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; 220 my $add_sql_wwhost = $r->param("add_sql_wwhost") || "";
207 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; 221 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || "";
208 my $add_initial_userID = $r->param("add_initial_userID") || "";
209 my $add_initial_password = $r->param("add_initial_password") || "";
210 my $add_initial_password_confirm = $r->param("add_initial_password_confirm") || "";
211 my $add_feedback_email = $r->param("add_feedback_email") || "";
212 my $add_templates_course = $r->param("add_templates_course") || "";
213 my $add_contact_first_name = $r->param("add_contact_first_name") || "";
214 my $add_contact_last_name = $r->param("add_contact_last_name") || "";
215 my $add_contact_institution = $r->param("add_contact_institution") || "";
216 my $add_course_title = $r->param("add_course_title") || "";
217 my $add_contact_email = $r->param("add_contact_email") || "";
218 my $add_admin_userID = $r->param("add_admin_userID") || $r->param("user") || "";
219 my $add_admin_password = $r->param("add_admin_password") || "";
220 222
221 my @dbLayouts = sort keys %{ $ce->{dbLayouts} }; 223 my @dbLayouts = sort keys %{ $ce->{dbLayouts} };
222 224
223 my $ce2 = WeBWorK::CourseEnvironment->new( 225 my $ce2 = WeBWorK::CourseEnvironment->new(
224 $ce->{webworkDirs}->{root}, 226 $ce->{webworkDirs}->{root},
243 ($source) = keys %sources; 245 ($source) = keys %sources;
244 } 246 }
245 $source; 247 $source;
246 }; 248 };
247 249
248 my @existingCourses = listCourses($ce); 250 my @existingCourses = listCourses($ce);
249 @existingCourses = sort @existingCourses; 251 @existingCourses = sort @existingCourses;
250 252
251 print CGI::h2("Add Course"); 253 print CGI::h2("Add Course");
252 254
253 print CGI::start_form("POST", $r->uri); 255 print CGI::start_form("POST", $r->uri);
254 print $self->hidden_authen_fields; 256 print $self->hidden_authen_fields;
255 print $self->hidden_fields("subDisplay"); 257 print $self->hidden_fields("subDisplay");
256 258
257 print CGI::p("Specify a name for the new course."); 259 print CGI::p("Specify an ID, title, and institution for the new course. The course ID may contain only letters, numbers, hyphens, and underscores.");
258 260
259 print CGI::table({class=>"FormLayout"}, 261 print CGI::table({class=>"FormLayout"},
260 CGI::Tr( 262 CGI::Tr(
261 CGI::th({class=>"LeftHeader"}, "Course ID:"), 263 CGI::th({class=>"LeftHeader"}, "Course ID:"),
262 CGI::td(CGI::textfield("add_courseID", $add_courseID, 25)), 264 CGI::td(CGI::textfield("add_courseID", $add_courseID, 25)),
263 CGI::th({class=>"LeftHeader"}, "Course Title"),
264 CGI::td(CGI::textfield("add_course_title", $add_course_title, 25)),
265 ), 265 ),
266 );
267
268 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.");
269
270 print CGI::table({class=>"FormLayout"},
271 CGI::Tr( 266 CGI::Tr(
267 CGI::th({class=>"LeftHeader"}, "Course Title:"),
268 CGI::td(CGI::textfield("add_courseTitle", $add_courseTitle, 25)),
269 ),
270 CGI::Tr(
272 CGI::th({class=>"CenterHeader"}, "Instructor ID"), 271 CGI::th({class=>"LeftHeader"}, "Institution:"),
272 CGI::td(CGI::textfield("add_courseInstitution", $add_courseInstitution, 25)),
273 ),
274 );
275
276 print CGI::p("To add the WeBWorK administrators to the new course (as instructors) check the box below.");
277
278 print CGI::p(CGI::checkbox("add_admin_users", $add_admin_users, "on", "Add WeBWorK administrators to new course"));
279
280 print CGI::p("To add an additional instructor to the new course, specify user information below. The user ID may contain only numbers, letters, hyphens, and underscores.");
281
282 print CGI::table({class=>"FormLayout"}, CGI::Tr(
283 CGI::td(
284 CGI::table({class=>"FormLayout"},
285 CGI::Tr(
286 CGI::th({class=>"LeftHeader"}, "User ID:"),
287 CGI::td(CGI::textfield("add_initial_userID", $add_initial_userID, 25)),
288 ),
289 CGI::Tr(
273 CGI::th({class=>"CenterHeader"}, "Instructor Password"), 290 CGI::th({class=>"LeftHeader"}, "Password:"),
291 CGI::td(CGI::password_field("add_initial_password", $add_initial_password, 25)),
292 ),
293 CGI::Tr(
274 CGI::th({class=>"CenterHeader"}, "Confirm Instructor Password"), 294 CGI::th({class=>"LeftHeader"}, "Confirm Password:"),
295 CGI::td(CGI::password_field("add_initial_confirmPassword", $add_initial_confirmPassword, 25)),
296 ),
297 ),
298 ),
299 CGI::td(
300 CGI::table({class=>"FormLayout"},
301 CGI::Tr(
302 CGI::th({class=>"LeftHeader"}, "First Name:"),
303 CGI::td(CGI::textfield("add_initial_firstName", $add_initial_firstName, 25)),
304 ),
305 CGI::Tr(
306 CGI::th({class=>"LeftHeader"}, "Last Name:"),
307 CGI::td(CGI::textfield("add_initial_lastName", $add_initial_lastName, 25)),
308 ),
309 CGI::Tr(
310 CGI::th({class=>"LeftHeader"}, "Email Address:"),
311 CGI::td(CGI::textfield("add_initial_email", $add_initial_email, 25)),
312 ),
313 ),
275 314
276
277 ), 315 ),
278 CGI::Tr(
279 CGI::td(CGI::textfield("add_initial_userID", $add_initial_userID || "professor", 25)),
280 CGI::td(CGI::password_field("add_initial_password", $add_initial_password, 25)),
281 CGI::td(CGI::password_field("add_initial_password_confirm", $add_initial_password_confirm, 25)),
282
283 ),
284
285 CGI::Tr(
286 CGI::th({class=>"CenterHeader"}, "First name"),
287 CGI::th({class=>"CenterHeader"}, "Last name"),
288 CGI::th({class=>"CenterHeader"}, " "),
289 ),
290 CGI::Tr(
291 CGI::td(CGI::textfield("add_contact_first_name", $add_contact_first_name, 20)),
292 CGI::td(CGI::textfield("add_contact_last_name", $add_contact_last_name, 20)),
293 CGI::th({class=>"CenterHeader"}, " "),
294 ),
295 CGI::Tr(
296 CGI::th({class=>"CenterHeader"}, "Contact institution"),
297 CGI::th({class=>"CenterHeader"}, "Contact e-mail"),
298 CGI::th({class=>"CenterHeader"}, " "),
299 ),
300 CGI::Tr(
301 CGI::td(CGI::textfield("add_contact_institution", $add_contact_institution, 35)),
302 CGI::td(CGI::textfield("add_contact_email", $add_contact_email, 35)),
303 CGI::th({class=>"CenterHeader"}, " "),
304 ),
305 CGI::Tr(
306 CGI::th({class=>"CenterHeader"}, "Administrator ID"),
307 CGI::th({class=>"CenterHeader"}, "Administrator Password"),
308 CGI::th({class=>"CenterHeader"}, "Feedback e-mail"),
309
310 ),
311 CGI::Tr(
312 CGI::td(CGI::textfield("add_admin_userID", $add_admin_userID, 25)),
313 CGI::td(CGI::password_field("add_admin_password", $add_admin_password, 25)),
314 CGI::td(CGI::textfield("add_feedback_email", $add_feedback_email, 25)),
315
316 ),
317 ); 316 ));
318 317
319 print CGI::p("Select an existing course from which to copy templates:"); 318 print CGI::p("To copy problem templates from an existing course, select the course below.");
320 319
321 print CGI::table({class=>"FormLayout"}, 320 print CGI::table({class=>"FormLayout"},
322 CGI::Tr( 321 CGI::Tr(
323 CGI::th({class=>"LeftHeader"}, "Copy templates from:"), 322 CGI::th({class=>"LeftHeader"}, "Copy templates from:"),
324 CGI::td( 323 CGI::td(
333 332
334 ), 333 ),
335 ), 334 ),
336 ); 335 );
337 336
338 print CGI::p("Select a database layout below. Some database layouts require additional information."); 337 print CGI::p("Select a database layout below.");
339
340 #print CGI::start_Tr();
341 #print CGI::th({class=>"LeftHeader"}, "Database Layout:");
342 #print CGI::start_td();
343 338
344 foreach my $dbLayout (@dbLayouts) { 339 foreach my $dbLayout (@dbLayouts) {
345 print CGI::start_table({class=>"FormLayout"}); 340 print CGI::start_table({class=>"FormLayout"});
346 341
347 # we generate singleton radio button tags ourselves because it's too much of a pain to do it with CGI.pm 342 # we generate singleton radio button tags ourselves because it's too much of a pain to do it with CGI.pm
356 print CGI::start_Tr(); 351 print CGI::start_Tr();
357 print CGI::td(); # for indentation :( 352 print CGI::td(); # for indentation :(
358 print CGI::start_td(); 353 print CGI::start_td();
359 354
360 if ($dbLayout eq "sql") { 355 if ($dbLayout eq "sql") {
361
362 print CGI::start_table({class=>"FormLayout"}); 356 print CGI::start_table({class=>"FormLayout"});
363 print CGI::Tr(CGI::td({colspan=>2}, 357 print CGI::Tr(CGI::td({colspan=>2},
364 "The SQL Admin is a user in the SQL database with sufficient permissions to create a new database." 358 "Enter the user ID and password for an SQL account with sufficient permissions to create a new database."
365 ) 359 )
366 ); 360 );
367 print CGI::Tr( 361 print CGI::Tr(
368 CGI::th({class=>"LeftHeader"}, "SQL Admin Username:"), 362 CGI::th({class=>"LeftHeader"}, "SQL Admin Username:"),
369 CGI::td(CGI::textfield("add_sql_username", $add_sql_username, 25)), 363 CGI::td(CGI::textfield("add_sql_username", $add_sql_username, 25)),
371 print CGI::Tr( 365 print CGI::Tr(
372 CGI::th({class=>"LeftHeader"}, "SQL Admin Password:"), 366 CGI::th({class=>"LeftHeader"}, "SQL Admin Password:"),
373 CGI::td(CGI::password_field("add_sql_password", $add_sql_password, 25)), 367 CGI::td(CGI::password_field("add_sql_password", $add_sql_password, 25)),
374 ); 368 );
375 369
376 print CGI::Tr(CGI::td({colspan=>2}, CGI::hr(), 370 print CGI::Tr(CGI::td({colspan=>2},
377 "The optionial SQL settings you enter below must match the settings in the DBI source", 371 "The optionial SQL settings you enter below must match the settings in the DBI source"
378 " specification ", CGI::tt($dbi_source), ". Replace ", CGI::tt("COURSENAME"), 372 . " specification " . CGI::tt($dbi_source) . ". Replace " . CGI::tt("COURSENAME")
379 " with the course name you entered above." 373 . " with the course name you entered above."
380 ) 374 )
381 ); 375 );
382 print CGI::Tr( 376 print CGI::Tr(
383 CGI::th({class=>"LeftHeader"}, "SQL Server Host:"), 377 CGI::th({class=>"LeftHeader"}, "SQL Server Host:"),
384 CGI::td( 378 CGI::td(
425 print CGI::end_td(); 419 print CGI::end_td();
426 print CGI::end_Tr(); 420 print CGI::end_Tr();
427 print CGI::end_table(); 421 print CGI::end_table();
428 } 422 }
429 423
430
431
432
433
434
435
436 print CGI::p({style=>"text-align: center"}, CGI::submit("add_course", "Add Course")); 424 print CGI::p({style=>"text-align: center"}, CGI::submit("add_course", "Add Course"));
437 425
438 print CGI::end_form(); 426 print CGI::end_form();
439} 427}
440 428
445 #my $db = $r->db; 433 #my $db = $r->db;
446 #my $authz = $r->authz; 434 #my $authz = $r->authz;
447 #my $urlpath = $r->urlpath; 435 #my $urlpath = $r->urlpath;
448 436
449 my $add_courseID = $r->param("add_courseID") || ""; 437 my $add_courseID = $r->param("add_courseID") || "";
438 my $add_courseTitle = $r->param("add_courseTitle") || "";
439 my $add_courseInstitution = $r->param("add_courseInstitution") || "";
440
441 my $add_admin_users = $r->param("add_admin_users") || "";
442
443 my $add_initial_userID = $r->param("add_initial_userID") || "";
444 my $add_initial_password = $r->param("add_initial_password") || "";
445 my $add_initial_confirmPassword = $r->param("add_initial_confirmPassword") || "";
446 my $add_initial_firstName = $r->param("add_initial_firstName") || "";
447 my $add_initial_lastName = $r->param("add_initial_lastName") || "";
448 my $add_initial_email = $r->param("add_initial_email") || "";
449
450 my $add_templates_course = $r->param("add_templates_course") || "";
451
450 my $add_dbLayout = $r->param("add_dbLayout") || ""; 452 my $add_dbLayout = $r->param("add_dbLayout") || "";
451 my $add_sql_host = $r->param("add_sql_host") || ""; 453 my $add_sql_host = $r->param("add_sql_host") || "";
452 my $add_sql_port = $r->param("add_sql_port") || ""; 454 my $add_sql_port = $r->param("add_sql_port") || "";
453 my $add_sql_username = $r->param("add_sql_username") || ""; 455 my $add_sql_username = $r->param("add_sql_username") || "";
454 my $add_sql_password = $r->param("add_sql_password") || ""; 456 my $add_sql_password = $r->param("add_sql_password") || "";
455 my $add_sql_database = $r->param("add_sql_database") || ""; 457 my $add_sql_database = $r->param("add_sql_database") || "";
456 my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; 458 my $add_sql_wwhost = $r->param("add_sql_wwhost") || "";
457 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; 459 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || "";
458 my $add_initial_userID = $r->param("add_initial_userID") || ""; 460
459 my $add_initial_password = $r->param("add_initial_password") || "";
460 my $add_initial_password_confirm = $r->param("add_initial_password_confirm") || "";
461 my $add_templates_course = $r->param("add_templates_course") || "";
462 my $add_contact_first_name = $r->param("add_contact_first_name") || "";
463 my $add_contact_last_name = $r->param("add_contact_last_name") || "";
464 my $add_contact_institution = $r->param("add_contact_institution") || "";
465 my $add_contact_email = $r->param("add_contact_email") || "";
466 my $add_course_title = $r->param("add_course_title") || "";
467 my $add_admin_userID = $r->param("add_admin_userID") || "";
468 my $add_admin_password = $r->param("add_admin_password") || "";
469
470 my @errors; 461 my @errors;
471 462
472 if ($add_courseID eq "") { 463 if ($add_courseID eq "") {
473 push @errors, "You must specify a course name."; 464 push @errors, "You must specify a course ID.";
474 } 465 }
475 if (grep { $add_courseID eq $_ } listCourses($ce)) { 466 if (grep { $add_courseID eq $_ } listCourses($ce)) {
476 push @errors, "A course named $add_courseID already exists." ; 467 push @errors, "A course with ID $add_courseID already exists.";
477 } 468 }
478 if ($add_contact_institution eq "") {
479 push @errors, "You must specify a contact institution." ;
480 }
481 if ($add_contact_last_name eq "") {
482 push @errors, "You must specify a contact person.";
483 }
484 if ($add_contact_email eq "") {
485 push @errors, "You must specify an email address for the contact person." ;
486 }
487 if ($add_initial_password ne $add_initial_password_confirm) {
488 push @errors, "The instructor's passwords don't match";
489 }
490 if ($add_course_title eq "") { 469 if ($add_courseTitle eq "") {
470 push @errors, "You must specify a course title.";
471 }
472 if ($add_courseInstitution eq "") {
491 push @errors, "You must specify a title for the course."; 473 push @errors, "You must specify an institution for this course.";
474 }
475
476 if ($add_initial_userID ne "") {
477 if ($add_initial_password eq "") {
478 push @errors, "You must specify a password for the initial instructor.";
479 }
480 if ($add_initial_confirmPassword eq "") {
481 push @errors, "You must confirm the password for the initial instructor.";
482 }
483 if ($add_initial_password ne $add_initial_confirmPassword) {
484 push @errors, "The password and password confirmation for the instructor must match.";
485 }
486 if ($add_initial_firstName eq "") {
487 push @errors, "You must specify a first name for the initial instructor.";
488 }
489 if ($add_initial_lastName eq "") {
490 push @errors, "You must specify a last name for the initial instructor.";
491 }
492 if ($add_initial_email eq "") {
493 push @errors, "You must specify an email address for the initial instructor.";
494 }
492 } 495 }
493 496
494 if ($add_dbLayout eq "") { 497 if ($add_dbLayout eq "") {
495 push @errors, "You must select a database layout."; 498 push @errors, "You must select a database layout.";
496 } else { 499 } else {
497 if (exists $ce->{dbLayouts}->{$add_dbLayout}) { 500 if (exists $ce->{dbLayouts}->{$add_dbLayout}) {
498 if ($add_dbLayout eq "sql") { 501 if ($add_dbLayout eq "sql") {
499 push @errors, "You must specify the SQL admin username." if $add_sql_username eq ""; 502 push @errors, "You must specify the SQL admin username." if $add_sql_username eq "";
500 #push @errors, "You must specify the SQL admin password." if $add_sql_password eq "";
501 #push @errors, "You must specify the SQL database name." if $add_sql_database eq "";
502 push @errors, "You must specify the WeBWorK host." if $add_sql_wwhost eq ""; 503 push @errors, "You must specify the WeBWorK host." if $add_sql_wwhost eq "";
503 } elsif ($add_dbLayout eq "gdbm") { 504 } elsif ($add_dbLayout eq "gdbm") {
504 push @errors, "You must specify the GDBM global user ID." if $add_gdbm_globalUserID eq ""; 505 push @errors, "You must specify the GDBM global user ID." if $add_gdbm_globalUserID eq "";
505 } 506 }
506 } else { 507 } else {
507 push @errors, "The database layout $add_dbLayout doesn't exist."; 508 push @errors, "The database layout $add_dbLayout doesn't exist.";
508 } 509 }
509 } 510 }
510 511
511 if ($add_initial_userID ne "") {
512 push @errors, "You must specify a professor password." if $add_initial_password eq "";
513 }
514 if ($add_admin_userID ne "") {
515 push @errors, "You must specify an admin password for $add_admin_userID." if $add_admin_password eq "";
516 }
517
518 return @errors; 512 return @errors;
519} 513}
520 514
521sub do_add_course { 515sub do_add_course {
522 my ($self) = @_; 516 my ($self) = @_;
524 my $ce = $r->ce; 518 my $ce = $r->ce;
525 my $db = $r->db; 519 my $db = $r->db;
526 #my $authz = $r->authz; 520 #my $authz = $r->authz;
527 my $urlpath = $r->urlpath; 521 my $urlpath = $r->urlpath;
528 522
529 my $add_courseID = $r->param("add_courseID") || ""; 523 my $add_courseID = $r->param("add_courseID") || "";
524 my $add_courseTitle = $r->param("add_courseTitle") || "";
525 my $add_courseInstitution = $r->param("add_courseInstitution") || "";
526
527 my $add_admin_users = $r->param("add_admin_users") || "";
528
529 my $add_initial_userID = $r->param("add_initial_userID") || "";
530 my $add_initial_password = $r->param("add_initial_password") || "";
531 my $add_initial_confirmPassword = $r->param("add_initial_confirmPassword") || "";
532 my $add_initial_firstName = $r->param("add_initial_firstName") || "";
533 my $add_initial_lastName = $r->param("add_initial_lastName") || "";
534 my $add_initial_email = $r->param("add_initial_email") || "";
535
536 my $add_templates_course = $r->param("add_templates_course") || "";
537
530 my $add_dbLayout = $r->param("add_dbLayout") || ""; 538 my $add_dbLayout = $r->param("add_dbLayout") || "";
531 my $add_sql_host = $r->param("add_sql_host") || ""; 539 my $add_sql_host = $r->param("add_sql_host") || "";
532 my $add_sql_port = $r->param("add_sql_port") || ""; 540 my $add_sql_port = $r->param("add_sql_port") || "";
533 my $add_sql_username = $r->param("add_sql_username") || ""; 541 my $add_sql_username = $r->param("add_sql_username") || "";
534 my $add_sql_password = $r->param("add_sql_password") || ""; 542 my $add_sql_password = $r->param("add_sql_password") || "";
535 my $add_sql_database = $r->param("add_sql_database") || ""; 543 my $add_sql_database = $r->param("add_sql_database") || "";
536 my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; 544 my $add_sql_wwhost = $r->param("add_sql_wwhost") || "";
537 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; 545 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || "";
538 my $add_initial_userID = $r->param("add_initial_userID") || "";
539 my $add_initial_password = $r->param("add_initial_password") || "";
540 my $add_templates_course = $r->param("add_templates_course") || "";
541 my $add_contact_first_name = $r->param("add_contact_first_name") || "";
542 my $add_contact_last_name = $r->param("add_contact_last_name") || "";
543 my $add_contact_institution = $r->param("add_contact_institution") || "";
544 my $add_contact_email = $r->param("add_contact_email") || "";
545 my $add_course_title = $r->param("add_course_title") || "";
546 my $add_admin_userID = $r->param("add_admin_userID") || $r->param("user") || "";
547 my $add_admin_password = $r->param("add_admin_password") || "";
548 546
549 my $ce2 = WeBWorK::CourseEnvironment->new( 547 my $ce2 = WeBWorK::CourseEnvironment->new(
550 $ce->{webworkDirs}->{root}, 548 $ce->{webworkDirs}->{root},
551 $ce->{webworkURLs}->{root}, 549 $ce->{webworkURLs}->{root},
552 $ce->{pg}->{directories}->{root}, 550 $ce->{pg}->{directories}->{root},
565 $dbOptions{username} = $add_sql_username; 563 $dbOptions{username} = $add_sql_username;
566 $dbOptions{password} = $add_sql_password; 564 $dbOptions{password} = $add_sql_password;
567 $dbOptions{database} = $add_sql_database || "webwork_$add_courseID"; 565 $dbOptions{database} = $add_sql_database || "webwork_$add_courseID";
568 $dbOptions{wwhost} = $add_sql_wwhost; 566 $dbOptions{wwhost} = $add_sql_wwhost;
569 } 567 }
570 # add professor and administor if defined. 568
571 my @users; 569 my @users;
570
571 # copy users from current (admin) course if desired
572 if ($add_admin_users ne "") {
573 foreach my $userID ($db->listUsers) {
574 my $User = $db->getUser($userID);
575 my $Password = $db->getPassword($userID);
576 my $PermissionLevel = $db->getPermissionLevel($userID);
577 push @users, [ $User, $Password, $PermissionLevel ];
578 }
579 }
580
581 # add initial instructor if desired
572 if ($add_initial_userID ne "") { 582 if ($add_initial_userID ne "") {
573 my $User = $db->newUser( 583 my $User = $db->newUser(
574 user_id => $add_initial_userID, 584 user_id => $add_initial_userID,
575 last_name => $add_contact_last_name,
576 first_name => $add_contact_first_name, 585 first_name => $add_initial_firstName,
586 last_name => $add_initial_lastName,
577 student_id => $add_initial_userID, 587 student_id => $add_initial_userID,
578 status => "C", 588 status => "C",
579 ); 589 );
580# $User->last_name( $add_contact_last_name );
581# $User->first_name( $add_contact_first_name );
582# $User->student_id( $add_initial_userID );
583 my $Password = $db->newPassword( 590 my $Password = $db->newPassword(
584 user_id => $add_initial_userID, 591 user_id => $add_initial_userID,
585 password => cryptPassword($add_initial_password), 592 password => cryptPassword($add_initial_password),
586 ); 593 );
587 my $PermissionLevel = $db->newPermissionLevel( 594 my $PermissionLevel = $db->newPermissionLevel(
588 user_id => $add_initial_userID, 595 user_id => $add_initial_userID,
589 permission => "10", 596 permission => "10",
590 ); 597 );
591 push @users, [ $User, $Password, $PermissionLevel ]; 598 push @users, [ $User, $Password, $PermissionLevel ];
592 } 599 }
593 if ($add_admin_userID ne "") { 600
594 my $User = $db->newUser(
595 user_id => $add_admin_userID,
596 last_name => " Administrator",
597 first_name => "Sir",
598 student_id => $add_admin_userID,
599 status => "C",
600 );
601 my $Password = $db->newPassword(
602 user_id => $add_admin_userID,
603 password => cryptPassword($add_admin_password),
604 );
605 my $PermissionLevel = $db->newPermissionLevel(
606 user_id => $add_admin_userID,
607 permission => "10",
608 );
609 push @users, [ $User, $Password, $PermissionLevel ];
610 }
611 my %optional_arguments; 601 my %optional_arguments;
612 if ($add_templates_course ne "") { 602 if ($add_templates_course ne "") {
613 $optional_arguments{templatesFrom} = $add_templates_course; 603 $optional_arguments{templatesFrom} = $add_templates_course;
614 } 604 }
615 605
621 dbOptions => \%dbOptions, 611 dbOptions => \%dbOptions,
622 users => \@users, 612 users => \@users,
623 %optional_arguments, 613 %optional_arguments,
624 ); 614 );
625 }; 615 };
626
627 if ($@) { 616 if ($@) {
628 my $error = $@; 617 my $error = $@;
629 print CGI::div({class=>"ResultsWithError"}, 618 print CGI::div({class=>"ResultsWithError"},
630 CGI::p("An error occured while creating the course $add_courseID:"), 619 CGI::p("An error occured while creating the course $add_courseID:"),
631 CGI::tt(CGI::escapeHTML($error)), 620 CGI::tt(CGI::escapeHTML($error)),
643 } 632 }
644 } else { 633 } else {
645 #log the action 634 #log the action
646 writeLog($ce, "hosted_courses", join("\t", 635 writeLog($ce, "hosted_courses", join("\t",
647 "\tAdded", 636 "\tAdded",
648 $add_contact_institution, 637 $add_courseInstitution,
649 $add_course_title, 638 $add_courseTitle,
650 $add_courseID, 639 $add_courseID,
651 $add_contact_first_name, 640 $add_initial_firstName,
652 $add_contact_last_name, 641 $add_initial_lastName,
653 $add_contact_email, 642 $add_initial_email,
654 )); 643 ));
655 # add contact to admin course as student? 644 # add contact to admin course as student?
656 # FIXME -- should we do this? 645 # FIXME -- should we do this?
657 print CGI::div({class=>"ResultsWithoutError"}, 646 print CGI::div({class=>"ResultsWithoutError"},
658 CGI::p("Successfully created the course $add_courseID"), 647 CGI::p("Successfully created the course $add_courseID"),
912 CGI::p("An error occured while deleting the course $delete_courseID:"), 901 CGI::p("An error occured while deleting the course $delete_courseID:"),
913 CGI::tt(CGI::escapeHTML($error)), 902 CGI::tt(CGI::escapeHTML($error)),
914 ); 903 );
915 } else { 904 } else {
916 print CGI::div({class=>"ResultsWithoutError"}, 905 print CGI::div({class=>"ResultsWithoutError"},
917 CGI::p("Possibly deleted the course $delete_courseID. (We need better error checking in deleteCourse().)"), 906 CGI::p("Successfully deleted the course $delete_courseID."),
918 ); 907 );
919 writeLog($ce, "hosted_courses", join("\t", 908 writeLog($ce, "hosted_courses", join("\t",
920 "\tDeleted", 909 "\tDeleted",
921 "", 910 "",
922 "", 911 "",

Legend:
Removed from v.2377  
changed lines
  Added in v.2378

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9