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

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

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

Revision 4087 Revision 4127
1################################################################################ 1################################################################################
2# WeBWorK Online Homework Delivery System 2# WeBWorK Online Homework Delivery System
3# Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/ 3# Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v 1.43 2006/01/25 23:13:52 sh002i Exp $ 4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v 1.44 2006/05/18 19:52:12 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.
410 410
411 print CGI::p("To add the WeBWorK administrators to the new course (as instructors) check the box below."); 411 print CGI::p("To add the WeBWorK administrators to the new course (as instructors) check the box below.");
412 my $checked = ($add_admin_users) ?"checked": ""; # workaround because CGI::checkbox seems to have a bug -- it won't default to checked. 412 my $checked = ($add_admin_users) ?"checked": ""; # workaround because CGI::checkbox seems to have a bug -- it won't default to checked.
413 print CGI::p(CGI::input({-type=>'checkbox', -name=>"add_admin_users", $checked=>'' }, "Add WeBWorK administrators to new course")); 413 print CGI::p(CGI::input({-type=>'checkbox', -name=>"add_admin_users", $checked=>'' }, "Add WeBWorK administrators to new course"));
414 414
415 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."); 415 print CGI::p("To add an additional instructor to the new course, specify user information below. The user ID may contain only
416 numbers, letters, hyphens, periods (dots), commas,and underscores.\n");
416 417
417 print CGI::table({class=>"FormLayout"}, CGI::Tr( 418 print CGI::table({class=>"FormLayout"}, CGI::Tr(
418 CGI::td( 419 CGI::td(
419 CGI::table({class=>"FormLayout"}, 420 CGI::table({class=>"FormLayout"},
420 CGI::Tr( 421 CGI::Tr(
587sub do_add_course { 588sub do_add_course {
588 my ($self) = @_; 589 my ($self) = @_;
589 my $r = $self->r; 590 my $r = $self->r;
590 my $ce = $r->ce; 591 my $ce = $r->ce;
591 my $db = $r->db; 592 my $db = $r->db;
592 #my $authz = $r->authz; 593 my $authz = $r->authz;
593 my $urlpath = $r->urlpath; 594 my $urlpath = $r->urlpath;
594 595
595 my $add_courseID = $r->param("add_courseID") || ""; 596 my $add_courseID = $r->param("add_courseID") || "";
596 my $add_courseTitle = $r->param("add_courseTitle") || ""; 597 my $add_courseTitle = $r->param("add_courseTitle") || "";
597 my $add_courseInstitution = $r->param("add_courseInstitution") || ""; 598 my $add_courseInstitution = $r->param("add_courseInstitution") || "";
656 next; 657 next;
657 } 658 }
658 my $User = $db->getUser($userID); 659 my $User = $db->getUser($userID);
659 my $Password = $db->getPassword($userID); 660 my $Password = $db->getPassword($userID);
660 my $PermissionLevel = $db->getPermissionLevel($userID); 661 my $PermissionLevel = $db->getPermissionLevel($userID);
661 push @users, [ $User, $Password, $PermissionLevel ]; 662 push @users, [ $User, $Password, $PermissionLevel ]
663 if $authz->hasPermissions($userID,"create_and_delete_courses");
664 #only transfer the "instructors" in the admin course classlist.
662 } 665 }
663 } 666 }
664 667
665 # add initial instructor if desired 668 # add initial instructor if desired
666 if ($add_initial_userID ne "") { 669 if ($add_initial_userID ne "") {
728 $add_initial_lastName, 731 $add_initial_lastName,
729 $add_initial_email, 732 $add_initial_email,
730 )); 733 ));
731 # add contact to admin course as student? 734 # add contact to admin course as student?
732 # FIXME -- should we do this? 735 # FIXME -- should we do this?
736 if ($add_initial_userID ne "") {
737 my $composite_id = "${add_initial_userID}_${add_courseID}"; # student id includes school name and contact
738 my $User = $db->newUser(
739 user_id => $composite_id, # student id includes school name and contact
740 first_name => $add_initial_firstName,
741 last_name => $add_initial_lastName,
742 student_id => $add_initial_userID,
743 email_address => $add_initial_email,
744 status => "C",
745 );
746 my $Password = $db->newPassword(
747 user_id => $composite_id,
748 password => cryptPassword($add_initial_password),
749 );
750 my $PermissionLevel = $db->newPermissionLevel(
751 user_id => $composite_id,
752 permission => "0",
753 );
754 # add contact to admin course as student
755 # or if this contact and course already exist in a dropped status
756 # change the student's status to enrolled
757 if (my $oldUser = $db->getUser($composite_id) ) {
758 warn "Replacing old data for $composite_id status: ". $oldUser->status;
759 $db->deleteUser($composite_id);
760 }
761 eval { $db->addUser($User) }; warn $@ if $@;
762 eval { $db->addPassword($Password) }; warn $@ if $@;
763 eval { $db->addPermissionLevel($PermissionLevel) }; warn $@ if $@;
764 }
733 print CGI::div({class=>"ResultsWithoutError"}, 765 print CGI::div({class=>"ResultsWithoutError"},
734 CGI::p("Successfully created the course $add_courseID"), 766 CGI::p("Successfully created the course $add_courseID"),
735 ); 767 );
736 my $newCoursePath = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSets", 768 my $newCoursePath = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSets",
737 courseID => $add_courseID); 769 courseID => $add_courseID);
1207 1239
1208sub do_delete_course { 1240sub do_delete_course {
1209 my ($self) = @_; 1241 my ($self) = @_;
1210 my $r = $self->r; 1242 my $r = $self->r;
1211 my $ce = $r->ce; 1243 my $ce = $r->ce;
1212 #my $db = $r->db; 1244 my $db = $r->db;
1213 #my $authz = $r->authz; 1245 #my $authz = $r->authz;
1214 #my $urlpath = $r->urlpath; 1246 #my $urlpath = $r->urlpath;
1215 1247
1216 my $delete_courseID = $r->param("delete_courseID") || ""; 1248 my $delete_courseID = $r->param("delete_courseID") || "";
1217 my $delete_sql_host = $r->param("delete_sql_host") || ""; 1249 my $delete_sql_host = $r->param("delete_sql_host") || "";
1249 print CGI::div({class=>"ResultsWithError"}, 1281 print CGI::div({class=>"ResultsWithError"},
1250 CGI::p("An error occured while deleting the course $delete_courseID:"), 1282 CGI::p("An error occured while deleting the course $delete_courseID:"),
1251 CGI::tt(CGI::escapeHTML($error)), 1283 CGI::tt(CGI::escapeHTML($error)),
1252 ); 1284 );
1253 } else { 1285 } else {
1286 # mark the contact person in the admin course as dropped.
1287 # find the contact person for the course by searching the admin classlist.
1288 my @contacts = grep /_$delete_courseID$/, $db->listUsers;
1289 die "Incorrect number of contacts for the course $delete_courseID". join(" ", @contacts) if @contacts !=1;
1290 #warn "contacts", join(" ", @contacts);
1291 #my $composite_id = "${add_initial_userID}_${add_courseID}";
1292 my $composite_id = $contacts[0];
1293
1294 # mark the contact person as dropped.
1295 my $User = $db->getUser($composite_id);
1296 my $status_name = 'Drop';
1297 my $status_value = ($ce->status_name_to_abbrevs($status_name))[0];
1298 $User->status($status_value);
1299 $db->putUser($User);
1300
1254 print CGI::div({class=>"ResultsWithoutError"}, 1301 print CGI::div({class=>"ResultsWithoutError"},
1255 CGI::p("Successfully deleted the course $delete_courseID."), 1302 CGI::p("Successfully deleted the course $delete_courseID."),
1256 ); 1303 );
1257 writeLog($ce, "hosted_courses", join("\t", 1304 writeLog($ce, "hosted_courses", join("\t",
1258 "\tDeleted", 1305 "\tDeleted",

Legend:
Removed from v.4087  
changed lines
  Added in v.4127

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9