| 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/Utils/CourseManagement.pm,v 1.8 2004/05/13 21:14:56 sh002i Exp $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/Utils/CourseManagement.pm,v 1.9 2004/05/17 16:41:07 jj 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. |
| … | |
… | |
| 26 | use strict; |
26 | use strict; |
| 27 | use warnings; |
27 | use warnings; |
| 28 | use Carp; |
28 | use Carp; |
| 29 | use DBI; |
29 | use DBI; |
| 30 | use File::Path qw(rmtree); |
30 | use File::Path qw(rmtree); |
|
|
31 | use WeBWorK::CourseEnvironment; |
| 31 | use WeBWorK::Utils qw(dequote runtime_use undefstr readDirectory); |
32 | use WeBWorK::Utils qw(dequote runtime_use undefstr readDirectory); |
| 32 | |
33 | |
| 33 | our @EXPORT = (); |
34 | our @EXPORT = (); |
| 34 | our @EXPORT_OK = qw( |
35 | our @EXPORT_OK = qw( |
| 35 | addCourse |
36 | addCourse |
| … | |
… | |
| 55 | |
56 | |
| 56 | =over |
57 | =over |
| 57 | |
58 | |
| 58 | =item addCourse(%options) |
59 | =item addCourse(%options) |
| 59 | |
60 | |
| 60 | Options must contain: |
61 | %options must contain: |
| 61 | |
62 | |
| 62 | courseID => $courseID, |
63 | courseID => $courseID, |
| 63 | ce => $ce, |
64 | ce => $ce, |
| 64 | courseOptions => $courseOptions, |
65 | courseOptions => $courseOptions, |
| 65 | dbOptions => $dbOptions, |
66 | dbOptions => $dbOptions, |
| 66 | users => $users |
67 | users => $users |
|
|
68 | |
|
|
69 | %options may contain: |
|
|
70 | |
|
|
71 | templatesFrom => $templatesCourseID, |
| 67 | |
72 | |
| 68 | Create a new course named $courseID. |
73 | Create a new course named $courseID. |
| 69 | |
74 | |
| 70 | $ce is a WeBWorK::CourseEnvironment object that describes the new course's |
75 | $ce is a WeBWorK::CourseEnvironment object that describes the new course's |
| 71 | environment. |
76 | environment. |
| … | |
… | |
| 106 | |
111 | |
| 107 | $users = [ $User, $Password, $PermissionLevel ] |
112 | $users = [ $User, $Password, $PermissionLevel ] |
| 108 | |
113 | |
| 109 | These users are added to the course. |
114 | These users are added to the course. |
| 110 | |
115 | |
|
|
116 | $templatesCourseID indicates the ID of a course from which the contents of the |
|
|
117 | templates directory will be copied to the new course. |
|
|
118 | |
| 111 | =cut |
119 | =cut |
| 112 | |
120 | |
| 113 | sub addCourse { |
121 | sub addCourse { |
| 114 | my (%options) = @_; |
122 | my (%options) = @_; |
| 115 | |
123 | |
| … | |
… | |
| 190 | my $courseEnvFile = $ce->{courseFiles}->{environment}; |
198 | my $courseEnvFile = $ce->{courseFiles}->{environment}; |
| 191 | open my $fh, ">", $courseEnvFile |
199 | open my $fh, ">", $courseEnvFile |
| 192 | or die "failed to open $courseEnvFile for writing.\n"; |
200 | or die "failed to open $courseEnvFile for writing.\n"; |
| 193 | writeCourseConf($fh, $ce, %courseOptions); |
201 | writeCourseConf($fh, $ce, %courseOptions); |
| 194 | close $fh; |
202 | close $fh; |
|
|
203 | |
|
|
204 | ##### step 5: copy templates ##### |
|
|
205 | |
|
|
206 | if (exists $options{templatesFrom}) { |
|
|
207 | my $sourceCourse = $options{templatesFrom}; |
|
|
208 | my $sourceCE = new WeBWorK::CourseEnvironment( |
|
|
209 | $ce->{webworkDirs}->{root}, |
|
|
210 | $ce->{webworkURLs}->{root}, |
|
|
211 | $ce->{pg}->{directories}->{root}, |
|
|
212 | $sourceCourse, |
|
|
213 | ); |
|
|
214 | my $sourceDir = $sourceCE->{courseDirs}->{templates}; |
|
|
215 | |
|
|
216 | if (-d $sourceDir) { |
|
|
217 | my $destDir = $ce->{courseDirs}->{templates}; |
|
|
218 | my $errno = system "/bin/cp -r $sourceDir/* $destDir"; |
|
|
219 | if ($errno) { |
|
|
220 | warn "Failed to copy templates from course '$sourceCourse' (errno=$errno): $!\n"; |
|
|
221 | } |
|
|
222 | } else { |
|
|
223 | warn "Failed to copy templates from course '$sourceCourse': templates directory '$sourceDir' does not exist.\n"; |
|
|
224 | } |
|
|
225 | } |
|
|
226 | |
| 195 | } |
227 | } |
| 196 | |
228 | |
| 197 | =item renameCourse($webworkRoot, $oldCourseID, $newCourseID) |
229 | =item renameCourse($webworkRoot, $oldCourseID, $newCourseID) |
| 198 | |
230 | |
| 199 | Rename the course named $oldCourseID to $newCourseID. |
231 | Rename the course named $oldCourseID to $newCourseID. |