[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 2254 Revision 3054
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.14 2004/06/02 18:21:38 gage Exp $ 4# $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v 1.31 2004/10/10 21:04:47 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.
31use WeBWorK::CourseEnvironment; 31use WeBWorK::CourseEnvironment;
32use WeBWorK::Utils qw(cryptPassword writeLog); 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
36# put the following database layouts at the top of the list, in this order
37our @DB_LAYOUT_ORDER = qw/sql_single gdbm sql/;
38
39our %DB_LAYOUT_DESCRIPTIONS = (
40 gdbm => "Deprecated. Uses GDBM databases to record WeBWorK data. Use this layout if the course must be used with WeBWorK 1.x.",
41 sql => "Deprecated. Uses a separate SQL database to record WeBWorK data for each course.",
42 sql_single => "Uses a single SQL database to record WeBWorK data for all courses using this layout. This is the recommended layout for new courses.",
43);
44
36sub pre_header_initialize { 45sub pre_header_initialize {
37 my ($self) = @_; 46 my ($self) = @_;
38 my $r = $self->r; 47 my $r = $self->r;
39 my $ce = $r->ce; 48 my $ce = $r->ce;
40 my $db = $r->db; 49 my $db = $r->db;
45 # check permissions 54 # check permissions
46 unless ($authz->hasPermissions($user, "create_and_delete_courses")) { 55 unless ($authz->hasPermissions($user, "create_and_delete_courses")) {
47 $self->addmessage( CGI::div({class=>'ResultsWithError'},"$user is not authorized to create or delete courses") ); 56 $self->addmessage( CGI::div({class=>'ResultsWithError'},"$user is not authorized to create or delete courses") );
48 return; 57 return;
49 } 58 }
59
60 # get result and send to message
61 my $status_message = $r->param("status_message");
62 $self->addmessage(CGI::p("$status_message")) if $status_message;
50 63
64 ## if the user is asking for the downloaded database...
51 if (defined $r->param("download_exported_database")) { 65 #if (defined $r->param("download_exported_database")) {
66 # my $courseID = $r->param("export_courseID");
67 # my $random_chars = $r->param("download_exported_database");
68 #
69 # die "courseID not specified" unless defined $courseID;
70 # die "invalid file specification" unless $random_chars =~ m/^\w+$/;
71 #
72 # my $tempdir = $ce->{webworkDirs}->{tmp};
73 # my $export_file = "$tempdir/db_export_$random_chars";
74 #
75 # $self->reply_with_file("application/xml", $export_file, "${courseID}_database.xml", 0);
76 #
77 # return "";
78 #}
79 #
80 ## otherwise...
81
82 my @errors;
83 my $method_to_call;
84
85 my $subDisplay = $r->param("subDisplay");
86 if (defined $subDisplay) {
87
88 if ($subDisplay eq "add_course") {
89 if (defined $r->param("add_course")) {
90 @errors = $self->add_course_validate;
91 if (@errors) {
92 $method_to_call = "add_course_form";
93 } else {
94 $method_to_call = "do_add_course";
95 }
96 } else {
97 $method_to_call = "add_course_form";
98 }
99 }
100
101 elsif ($subDisplay eq "delete_course") {
102 if (defined $r->param("delete_course")) {
103 # validate or confirm
104 @errors = $self->delete_course_validate;
105 if (@errors) {
106 $method_to_call = "delete_course_form";
107 } else {
108 $method_to_call = "delete_course_confirm";
109 }
110 } elsif (defined $r->param("confirm_delete_course")) {
111 # validate and delete
112 @errors = $self->delete_course_validate;
113 if (@errors) {
114 $method_to_call = "delete_course_form";
115 } else {
116 $method_to_call = "do_delete_course";
117 }
118 } else {
119 # form only
120 $method_to_call = "delete_course_form";
121 }
122 }
123
124 elsif ($subDisplay eq "export_database") {
125 if (defined $r->param("export_database")) {
126 @errors = $self->export_database_validate;
127 if (@errors) {
128 $method_to_call = "export_database_form";
129 } else {
130 # we have to do something special here, since we're sending
131 # the database as we export it. $method_to_call still gets
132 # set here, but it gets caught by header() and content()
133 # below instead of by body().
134 $method_to_call = "do_export_database";
135 }
136 } else {
137 $method_to_call = "export_database_form";
138 }
139 }
140
141 elsif ($subDisplay eq "import_database") {
142 if (defined $r->param("import_database")) {
143 @errors = $self->import_database_validate;
144 if (@errors) {
145 $method_to_call = "import_database_form";
146 } else {
147 $method_to_call = "do_import_database";
148 }
149 } else {
150 $method_to_call = "import_database_form";
151 }
152 }
153
154 else {
155 @errors = "Unrecognized sub-display @{[ CGI::b($subDisplay) ]}.";
156 }
157
158 }
159
160 $self->{errors} = \@errors;
161 $self->{method_to_call} = $method_to_call;
162}
163
164sub header {
165 my ($self) = @_;
166 my $method_to_call = $self->{method_to_call};
167 if (defined $method_to_call and $method_to_call eq "do_export_database") {
168 my $r = $self->r;
52 my $courseID = $r->param("export_courseID"); 169 my $courseID = $r->param("export_courseID");
53 my $random_chars = $r->param("download_exported_database"); 170 $r->content_type("application/octet-stream");
54 171 $r->header_out("Content-Disposition" => "attachment; filename=\"${courseID}_database.xml\"");
55 die "courseID not specified" unless defined $courseID; 172 $r->send_http_header;
56 die "invalid file specification" unless $random_chars =~ m/^\w+$/; 173 } else {
57 174 $self->SUPER::header;
58 my $tempdir = $ce->{webworkDirs}->{tmp}; 175 }
59 my $export_file = "$tempdir/db_export_$random_chars"; 176}
60 177
61 $self->reply_with_file("text/xml", $export_file, "${courseID}_database.xml", 0); 178# sends:
179#
180# HTTP/1.1 200 OK
181# Date: Fri, 09 Jul 2004 19:05:55 GMT
182# Server: Apache/1.3.27 (Unix) mod_perl/1.27
183# Content-Disposition: attachment; filename="mth143_database.xml"
184# Connection: close
185# Content-Type: application/octet-stream
186
187sub content {
188 my ($self) = @_;
189 my $method_to_call = $self->{method_to_call};
190 if (defined $method_to_call and $method_to_call eq "do_export_database") {
191 $self->do_export_database;
192 } else {
193 $self->SUPER::content;
62 } 194 }
63} 195}
64 196
65sub body { 197sub body {
66 my ($self) = @_; 198 my ($self) = @_;
68 my $ce = $r->ce; 200 my $ce = $r->ce;
69 my $db = $r->db; 201 my $db = $r->db;
70 my $authz = $r->authz; 202 my $authz = $r->authz;
71 my $urlpath = $r->urlpath; 203 my $urlpath = $r->urlpath;
72 204
73 my $user = $r->param('user'); 205 my $user = $r->param('user');
74 206
75 # check permissions 207 # check permissions
76 unless ($authz->hasPermissions($user, "create_and_delete_courses")) { 208 unless ($authz->hasPermissions($user, "create_and_delete_courses")) {
77 return ""; 209 return "";
78 } 210 }
79 211
80 print CGI::p({style=>"text-align: center"}, 212 print CGI::p({style=>"text-align: center"},
81 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"add_course"})}, "Add Course"), 213 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"add_course"})}, "Add Course"),
82 #" | ",
83 #CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"rename_course"})}, "Rename Course"),
84 " | ", 214 " | ",
85 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"delete_course"})}, "Delete Course"), 215 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"delete_course"})}, "Delete Course"),
86 " | ", 216 " | ",
87 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"export_database"})}, "Export Database"), 217 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"export_database"})}, "Export Database"),
88 " | ", 218 " | ",
89 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"import_database"})}, "Import Database"), 219 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"import_database"})}, "Import Database"),
90 ); 220 );
91 221
92 print CGI::hr(); 222 print CGI::hr();
93 223
94 my $subDisplay = $r->param("subDisplay"); 224 my @errors = @{$self->{errors}};
95 if (defined $subDisplay) { 225 my $method_to_call = $self->{method_to_call};
96 226
97 if ($subDisplay eq "add_course") {
98 if (defined $r->param("add_course")) {
99 my @errors = $self->add_course_validate;
100 if (@errors) { 227 if (@errors) {
101 print CGI::div({class=>"ResultsWithError"},
102 CGI::p("Please correct the following errors and try again:"),
103 CGI::ul(CGI::li(\@errors)),
104 );
105 $self->add_course_form;
106 } else {
107 $self->do_add_course;
108 }
109 } else {
110 $self->add_course_form;
111 }
112 }
113
114 elsif ($subDisplay eq "delete_course") {
115 if (defined $r->param("delete_course")) {
116 # validate or confirm
117 my @errors = $self->delete_course_validate;
118 if (@errors) {
119 print CGI::div({class=>"ResultsWithError"},
120 CGI::p("Please correct the following errors and try again:"),
121 CGI::ul(CGI::li(\@errors)),
122 );
123 $self->delete_course_form;
124 } else {
125 $self->delete_course_confirm;
126 }
127 } elsif (defined $r->param("confirm_delete_course")) {
128 # validate and delete
129 my @errors = $self->delete_course_validate;
130 if (@errors) {
131 print CGI::div({class=>"ResultsWithError"},
132 CGI::p("Please correct the following errors and try again:"),
133 CGI::ul(CGI::li(\@errors)),
134 );
135 $self->delete_course_form;
136 } else {
137 $self->do_delete_course;
138 }
139 } else {
140 # form only
141 $self->delete_course_form;
142 }
143 }
144
145 elsif ($subDisplay eq "export_database") {
146 if (defined $r->param("export_database")) {
147 my @errors = $self->export_database_validate;
148 if (@errors) {
149 print CGI::div({class=>"ResultsWithError"},
150 CGI::p("Please correct the following errors and try again:"),
151 CGI::ul(CGI::li(\@errors)),
152 );
153 $self->export_database_form;
154 } else {
155 $self->do_export_database;
156 }
157 } else {
158 $self->export_database_form;
159 }
160 }
161
162 elsif ($subDisplay eq "import_database") {
163 if (defined $r->param("import_database")) {
164 my @errors = $self->import_database_validate;
165 if (@errors) {
166 print CGI::div({class=>"ResultsWithError"},
167 CGI::p("Please correct the following errors and try again:"),
168 CGI::ul(CGI::li(\@errors)),
169 );
170 $self->import_database_form;
171 } else {
172 $self->do_import_database;
173 }
174 } else {
175 $self->import_database_form;
176 }
177 }
178
179 else {
180 print CGI::div({class=>"ResultsWithError"}, 228 print CGI::div({class=>"ResultsWithError"},
181 "Unrecognized sub-display @{[ CGI::b($subDisplay) ]}."); 229 CGI::p("Please correct the following errors and try again:"),
230 CGI::ul(CGI::li(\@errors)),
231 );
182 } 232 }
183 233
234 if (defined $method_to_call and $method_to_call ne "") {
235 $self->$method_to_call;
184 } 236 }
185 237
186 return ""; 238 return "";
187} 239}
188 240
195 #my $db = $r->db; 247 #my $db = $r->db;
196 #my $authz = $r->authz; 248 #my $authz = $r->authz;
197 #my $urlpath = $r->urlpath; 249 #my $urlpath = $r->urlpath;
198 250
199 my $add_courseID = $r->param("add_courseID") || ""; 251 my $add_courseID = $r->param("add_courseID") || "";
252 my $add_courseTitle = $r->param("add_courseTitle") || "";
253 my $add_courseInstitution = $r->param("add_courseInstitution") || "";
254
255 my $add_admin_users = $r->param("add_admin_users") || "";
256
257 my $add_initial_userID = $r->param("add_initial_userID") || "";
258 my $add_initial_password = $r->param("add_initial_password") || "";
259 my $add_initial_confirmPassword = $r->param("add_initial_confirmPassword") || "";
260 my $add_initial_firstName = $r->param("add_initial_firstName") || "";
261 my $add_initial_lastName = $r->param("add_initial_lastName") || "";
262 my $add_initial_email = $r->param("add_initial_email") || "";
263
264 my $add_templates_course = $r->param("add_templates_course") || "";
265
200 my $add_dbLayout = $r->param("add_dbLayout") || ""; 266 my $add_dbLayout = $r->param("add_dbLayout") || "";
201 my $add_sql_host = $r->param("add_sql_host") || ""; 267 my $add_sql_host = $r->param("add_sql_host") || "";
202 my $add_sql_port = $r->param("add_sql_port") || ""; 268 my $add_sql_port = $r->param("add_sql_port") || "";
203 my $add_sql_username = $r->param("add_sql_username") || ""; 269 my $add_sql_username = $r->param("add_sql_username") || "";
204 my $add_sql_password = $r->param("add_sql_password") || ""; 270 my $add_sql_password = $r->param("add_sql_password") || "";
205 my $add_sql_database = $r->param("add_sql_database") || ""; 271 my $add_sql_database = $r->param("add_sql_database") || "";
206 my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; 272 my $add_sql_wwhost = $r->param("add_sql_wwhost") || "";
207 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; 273 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_person = $r->param("add_contact_person") || "";
214 my $add_contact_institution = $r->param("add_contact_institution") || "";
215 my $add_course_title = $r->param("add_course_title") || "";
216 my $add_contact_email = $r->param("add_contact_email") || "";
217 my $add_admin_userID = $r->param("add_admin_userID") || $r->param("user") || "";
218 my $add_admin_password = $r->param("add_admin_password") || "";
219 274
220 my @dbLayouts = sort keys %{ $ce->{dbLayouts} }; 275 my @dbLayouts = do {
276 my @ordered_layouts;
277 foreach my $layout (@DB_LAYOUT_ORDER) {
278 if (exists $ce->{dbLayouts}->{$layout}) {
279 push @ordered_layouts, $layout;
280 }
281 }
282
283 my %ordered_layouts; @ordered_layouts{@ordered_layouts} = ();
284 my @other_layouts;
285 foreach my $layout (keys %{ $ce->{dbLayouts} }) {
286 unless (exists $ordered_layouts{$layout}) {
287 push @other_layouts, $layout;
288 }
289 }
290
291 (@ordered_layouts, @other_layouts);
292 };
221 293
222 my $ce2 = WeBWorK::CourseEnvironment->new( 294 my $ce2 = WeBWorK::CourseEnvironment->new(
223 $ce->{webworkDirs}->{root}, 295 $ce->{webworkDirs}->{root},
224 $ce->{webworkURLs}->{root}, 296 $ce->{webworkURLs}->{root},
225 $ce->{pg}->{directories}->{root}, 297 $ce->{pg}->{directories}->{root},
243 } 315 }
244 $source; 316 $source;
245 }; 317 };
246 318
247 my @existingCourses = listCourses($ce); 319 my @existingCourses = listCourses($ce);
320 @existingCourses = sort @existingCourses;
248 321
249 print CGI::h2("Add Course"); 322 print CGI::h2("Add Course");
250 323
251 print CGI::start_form("POST", $r->uri); 324 print CGI::start_form("POST", $r->uri);
252 print $self->hidden_authen_fields; 325 print $self->hidden_authen_fields;
253 print $self->hidden_fields("subDisplay"); 326 print $self->hidden_fields("subDisplay");
254 327
255 print CGI::p("Specify a name for the new course."); 328 print CGI::p("Specify an ID, title, and institution for the new course. The course ID may contain only letters, numbers, hyphens, and underscores.");
256 329
257 print CGI::table({class=>"FormLayout"}, 330 print CGI::table({class=>"FormLayout"},
258 CGI::Tr( 331 CGI::Tr(
259 CGI::th({class=>"LeftHeader"}, "Course ID:"), 332 CGI::th({class=>"LeftHeader"}, "Course ID:"),
260 CGI::td(CGI::textfield("add_courseID", $add_courseID, 25)), 333 CGI::td(CGI::textfield("add_courseID", $add_courseID, 25)),
261 CGI::th({class=>"LeftHeader"}, "Course Title"),
262 CGI::td(CGI::textfield("add_course_title", $add_course_title, 25)),
263 ), 334 ),
264 );
265
266 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.");
267
268 print CGI::table({class=>"FormLayout"},
269 CGI::Tr( 335 CGI::Tr(
336 CGI::th({class=>"LeftHeader"}, "Course Title:"),
337 CGI::td(CGI::textfield("add_courseTitle", $add_courseTitle, 25)),
338 ),
339 CGI::Tr(
270 CGI::th({class=>"CenterHeader"}, "Instructor ID"), 340 CGI::th({class=>"LeftHeader"}, "Institution:"),
341 CGI::td(CGI::textfield("add_courseInstitution", $add_courseInstitution, 25)),
342 ),
343 );
344
345 print CGI::p("To add the WeBWorK administrators to the new course (as instructors) check the box below.");
346
347 print CGI::p(CGI::checkbox("add_admin_users", $add_admin_users, "on", "Add WeBWorK administrators to new course"));
348
349 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.");
350
351 print CGI::table({class=>"FormLayout"}, CGI::Tr(
352 CGI::td(
353 CGI::table({class=>"FormLayout"},
354 CGI::Tr(
355 CGI::th({class=>"LeftHeader"}, "User ID:"),
356 CGI::td(CGI::textfield("add_initial_userID", $add_initial_userID, 25)),
357 ),
358 CGI::Tr(
271 CGI::th({class=>"CenterHeader"}, "Instructor Password"), 359 CGI::th({class=>"LeftHeader"}, "Password:"),
360 CGI::td(CGI::password_field("add_initial_password", $add_initial_password, 25)),
361 ),
362 CGI::Tr(
272 CGI::th({class=>"CenterHeader"}, "Confirm Instructor Password"), 363 CGI::th({class=>"LeftHeader"}, "Confirm Password:"),
364 CGI::td(CGI::password_field("add_initial_confirmPassword", $add_initial_confirmPassword, 25)),
365 ),
366 ),
367 ),
368 CGI::td(
369 CGI::table({class=>"FormLayout"},
370 CGI::Tr(
371 CGI::th({class=>"LeftHeader"}, "First Name:"),
372 CGI::td(CGI::textfield("add_initial_firstName", $add_initial_firstName, 25)),
373 ),
374 CGI::Tr(
375 CGI::th({class=>"LeftHeader"}, "Last Name:"),
376 CGI::td(CGI::textfield("add_initial_lastName", $add_initial_lastName, 25)),
377 ),
378 CGI::Tr(
379 CGI::th({class=>"LeftHeader"}, "Email Address:"),
380 CGI::td(CGI::textfield("add_initial_email", $add_initial_email, 25)),
381 ),
382 ),
273 383
274
275 ), 384 ),
276 CGI::Tr(
277 CGI::td(CGI::textfield("add_initial_userID", $add_initial_userID || "professor", 25)),
278 CGI::td(CGI::password_field("add_initial_password", $add_initial_password, 25)),
279 CGI::td(CGI::password_field("add_initial_password_confirm", $add_initial_password_confirm, 25)),
280
281 ),
282
283 CGI::Tr(
284 CGI::th({class=>"CenterHeader"}, "Contact name"),
285 CGI::th({class=>"CenterHeader"}, "Contact institution"),
286 CGI::th({class=>"CenterHeader"}, "Contact e-mail"),
287 ),
288 CGI::Tr(
289 CGI::td(CGI::textfield("add_contact_person", $add_contact_person, 35)),
290 CGI::td(CGI::textfield("add_contact_institution", $add_contact_institution, 35)),
291 CGI::td(CGI::textfield("add_contact_email", $add_contact_email, 35)),
292 ),
293 CGI::Tr(
294 CGI::th({class=>"CenterHeader"}, "Administrator ID"),
295 CGI::th({class=>"CenterHeader"}, "Administrator Password"),
296 CGI::th({class=>"CenterHeader"}, "Feedback e-mail"),
297
298 ),
299 CGI::Tr(
300 CGI::td(CGI::textfield("add_admin_userID", $add_admin_userID, 25)),
301 CGI::td(CGI::password_field("add_admin_password", $add_admin_password, 25)),
302 CGI::td(CGI::textfield("add_feedback_email", $add_feedback_email, 25)),
303 ),
304 ); 385 ));
305 386
306 print CGI::p("Select an existing course from which to copy templates:"); 387 print CGI::p("To copy problem templates from an existing course, select the course below.");
307 388
308 print CGI::table({class=>"FormLayout"}, 389 print CGI::table({class=>"FormLayout"},
309 CGI::Tr( 390 CGI::Tr(
310 CGI::th({class=>"LeftHeader"}, "Copy templates from:"), 391 CGI::th({class=>"LeftHeader"}, "Copy templates from:"),
311 CGI::td( 392 CGI::td(
320 401
321 ), 402 ),
322 ), 403 ),
323 ); 404 );
324 405
325 print CGI::p("Select a database layout below. Some database layouts require additional information."); 406 print CGI::p("Select a database layout below.");
326
327 #print CGI::start_Tr();
328 #print CGI::th({class=>"LeftHeader"}, "Database Layout:");
329 #print CGI::start_td();
330 407
331 foreach my $dbLayout (@dbLayouts) { 408 foreach my $dbLayout (@dbLayouts) {
332 print CGI::start_table({class=>"FormLayout"}); 409 print CGI::start_table({class=>"FormLayout"});
410
411 my $dbLayoutLabel = (defined $DB_LAYOUT_DESCRIPTIONS{$dbLayout})
412 ? "$dbLayout - $DB_LAYOUT_DESCRIPTIONS{$dbLayout}"
413 : $dbLayout;
333 414
334 # we generate singleton radio button tags ourselves because it's too much of a pain to do it with CGI.pm 415 # we generate singleton radio button tags ourselves because it's too much of a pain to do it with CGI.pm
335 print CGI::Tr( 416 print CGI::Tr(
336 CGI::td({style=>"text-align: right"}, 417 CGI::td({style=>"text-align: right"},
337 '<input type="radio" name="add_dbLayout" value="' . $dbLayout . '"' 418 '<input type="radio" name="add_dbLayout" value="' . $dbLayout . '"'
338 . ($add_dbLayout eq $dbLayout ? " checked" : "") . ' />', 419 . ($add_dbLayout eq $dbLayout ? " checked" : "") . ' />',
339 ), 420 ),
340 CGI::td($dbLayout), 421 CGI::td($dbLayoutLabel),
341 ); 422 );
342 423
343 print CGI::start_Tr(); 424 print CGI::start_Tr();
344 print CGI::td(); # for indentation :( 425 print CGI::td(); # for indentation :(
345 print CGI::start_td(); 426 print CGI::start_td();
346 427
347 if ($dbLayout eq "sql") { 428 if ($dbLayout eq "sql") {
348
349 print CGI::start_table({class=>"FormLayout"}); 429 print CGI::start_table({class=>"FormLayout"});
350 print CGI::Tr(CGI::td({colspan=>2}, 430 print CGI::Tr(CGI::td({colspan=>2},
351 "The SQL Admin is a user in the SQL database with sufficient permissions to create a new database." 431 "Enter the user ID and password for an SQL account with sufficient permissions to create a new database."
352 ) 432 )
353 ); 433 );
354 print CGI::Tr( 434 print CGI::Tr(
355 CGI::th({class=>"LeftHeader"}, "SQL Admin Username:"), 435 CGI::th({class=>"LeftHeader"}, "SQL Admin Username:"),
356 CGI::td(CGI::textfield("add_sql_username", $add_sql_username, 25)), 436 CGI::td(CGI::textfield("add_sql_username", $add_sql_username, 25)),
358 print CGI::Tr( 438 print CGI::Tr(
359 CGI::th({class=>"LeftHeader"}, "SQL Admin Password:"), 439 CGI::th({class=>"LeftHeader"}, "SQL Admin Password:"),
360 CGI::td(CGI::password_field("add_sql_password", $add_sql_password, 25)), 440 CGI::td(CGI::password_field("add_sql_password", $add_sql_password, 25)),
361 ); 441 );
362 442
363 print CGI::Tr(CGI::td({colspan=>2}, CGI::hr(), 443 print CGI::Tr(CGI::td({colspan=>2},
364 "The optionial SQL settings you enter below must match the settings in the DBI source", 444 "The optionial SQL settings you enter below must match the settings in the DBI source"
365 " specification ", CGI::tt($dbi_source), ". Replace ", CGI::tt("COURSENAME"), 445 . " specification " . CGI::tt($dbi_source) . ". Replace " . CGI::tt("COURSENAME")
366 " with the course name you entered above." 446 . " with the course name you entered above."
367 ) 447 )
368 ); 448 );
369 print CGI::Tr( 449 print CGI::Tr(
370 CGI::th({class=>"LeftHeader"}, "SQL Server Host:"), 450 CGI::th({class=>"LeftHeader"}, "SQL Server Host:"),
371 CGI::td( 451 CGI::td(
412 print CGI::end_td(); 492 print CGI::end_td();
413 print CGI::end_Tr(); 493 print CGI::end_Tr();
414 print CGI::end_table(); 494 print CGI::end_table();
415 } 495 }
416 496
417
418
419
420
421
422
423 print CGI::p({style=>"text-align: center"}, CGI::submit("add_course", "Add Course")); 497 print CGI::p({style=>"text-align: center"}, CGI::submit("add_course", "Add Course"));
424 498
425 print CGI::end_form(); 499 print CGI::end_form();
426} 500}
427 501
432 #my $db = $r->db; 506 #my $db = $r->db;
433 #my $authz = $r->authz; 507 #my $authz = $r->authz;
434 #my $urlpath = $r->urlpath; 508 #my $urlpath = $r->urlpath;
435 509
436 my $add_courseID = $r->param("add_courseID") || ""; 510 my $add_courseID = $r->param("add_courseID") || "";
511 my $add_courseTitle = $r->param("add_courseTitle") || "";
512 my $add_courseInstitution = $r->param("add_courseInstitution") || "";
513
514 my $add_admin_users = $r->param("add_admin_users") || "";
515
516 my $add_initial_userID = $r->param("add_initial_userID") || "";
517 my $add_initial_password = $r->param("add_initial_password") || "";
518 my $add_initial_confirmPassword = $r->param("add_initial_confirmPassword") || "";
519 my $add_initial_firstName = $r->param("add_initial_firstName") || "";
520 my $add_initial_lastName = $r->param("add_initial_lastName") || "";
521 my $add_initial_email = $r->param("add_initial_email") || "";
522
523 my $add_templates_course = $r->param("add_templates_course") || "";
524
437 my $add_dbLayout = $r->param("add_dbLayout") || ""; 525 my $add_dbLayout = $r->param("add_dbLayout") || "";
438 my $add_sql_host = $r->param("add_sql_host") || ""; 526 my $add_sql_host = $r->param("add_sql_host") || "";
439 my $add_sql_port = $r->param("add_sql_port") || ""; 527 my $add_sql_port = $r->param("add_sql_port") || "";
440 my $add_sql_username = $r->param("add_sql_username") || ""; 528 my $add_sql_username = $r->param("add_sql_username") || "";
441 my $add_sql_password = $r->param("add_sql_password") || ""; 529 my $add_sql_password = $r->param("add_sql_password") || "";
442 my $add_sql_database = $r->param("add_sql_database") || ""; 530 my $add_sql_database = $r->param("add_sql_database") || "";
443 my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; 531 my $add_sql_wwhost = $r->param("add_sql_wwhost") || "";
444 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; 532 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || "";
445 my $add_initial_userID = $r->param("add_initial_userID") || ""; 533
446 my $add_initial_password = $r->param("add_initial_password") || "";
447 my $add_initial_password_confirm = $r->param("add_initial_password_confirm") || "";
448 my $add_templates_course = $r->param("add_templates_course") || "";
449 my $add_contact_person = $r->param("add_contact_person") || "";
450 my $add_contact_institution = $r->param("add_contact_institution") || "";
451 my $add_contact_email = $r->param("add_contact_email") || "";
452 my $add_course_title = $r->param("add_course_title") || "";
453 my $add_admin_userID = $r->param("add_admin_userID") || "";
454 my $add_admin_password = $r->param("add_admin_password") || "";
455
456 my @errors; 534 my @errors;
457 535
458 if ($add_courseID eq "") { 536 if ($add_courseID eq "") {
459 push @errors, "You must specify a course name."; 537 push @errors, "You must specify a course ID.";
460 } 538 }
461 if ($add_contact_institution eq "") { 539 unless ($add_courseID =~ /^[\w-]*$/) { # regex copied from CourseAdministration.pm
462 push @errors, "You must specify a contact institution." ; 540 push @errors, "Course ID may only contain letters, numbers, hyphens, and underscores.";
463 } 541 }
464 if ($add_contact_person eq "") { 542 if (grep { $add_courseID eq $_ } listCourses($ce)) {
465 push @errors, "You must specify a contact person."; 543 push @errors, "A course with ID $add_courseID already exists.";
466 } 544 }
467 if ($add_contact_email eq "") {
468 push @errors, "You must specify an email address for the contact person." ;
469 }
470 if ($add_initial_password ne $add_initial_password_confirm) {
471 push @errors, "The instructor's passwords don't match";
472 }
473 if ($add_course_title eq "") { 545 if ($add_courseTitle eq "") {
546 push @errors, "You must specify a course title.";
547 }
548 if ($add_courseInstitution eq "") {
474 push @errors, "You must specify a title for the course."; 549 push @errors, "You must specify an institution for this course.";
550 }
551
552 if ($add_initial_userID ne "") {
553 if ($add_initial_password eq "") {
554 push @errors, "You must specify a password for the initial instructor.";
555 }
556 if ($add_initial_confirmPassword eq "") {
557 push @errors, "You must confirm the password for the initial instructor.";
558 }
559 if ($add_initial_password ne $add_initial_confirmPassword) {
560 push @errors, "The password and password confirmation for the instructor must match.";
561 }
562 if ($add_initial_firstName eq "") {
563 push @errors, "You must specify a first name for the initial instructor.";
564 }
565 if ($add_initial_lastName eq "") {
566 push @errors, "You must specify a last name for the initial instructor.";
567 }
568 if ($add_initial_email eq "") {
569 push @errors, "You must specify an email address for the initial instructor.";
570 }
475 } 571 }
476 572
477 if ($add_dbLayout eq "") { 573 if ($add_dbLayout eq "") {
478 push @errors, "You must select a database layout."; 574 push @errors, "You must select a database layout.";
479 } else { 575 } else {
480 if (exists $ce->{dbLayouts}->{$add_dbLayout}) { 576 if (exists $ce->{dbLayouts}->{$add_dbLayout}) {
481 if ($add_dbLayout eq "sql") { 577 if ($add_dbLayout eq "sql") {
482 push @errors, "You must specify the SQL admin username." if $add_sql_username eq ""; 578 push @errors, "You must specify the SQL admin username." if $add_sql_username eq "";
483 #push @errors, "You must specify the SQL admin password." if $add_sql_password eq "";
484 #push @errors, "You must specify the SQL database name." if $add_sql_database eq "";
485 push @errors, "You must specify the WeBWorK host." if $add_sql_wwhost eq ""; 579 push @errors, "You must specify the WeBWorK host." if $add_sql_wwhost eq "";
486 } elsif ($add_dbLayout eq "gdbm") { 580 } elsif ($add_dbLayout eq "gdbm") {
487 push @errors, "You must specify the GDBM global user ID." if $add_gdbm_globalUserID eq ""; 581 push @errors, "You must specify the GDBM global user ID." if $add_gdbm_globalUserID eq "";
488 } 582 }
489 } else { 583 } else {
490 push @errors, "The database layout $add_dbLayout doesn't exist."; 584 push @errors, "The database layout $add_dbLayout doesn't exist.";
491 } 585 }
492 } 586 }
493 587
494 if ($add_initial_userID ne "") {
495 push @errors, "You must specify a professor password." if $add_initial_password eq "";
496 }
497 if ($add_admin_userID ne "") {
498 push @errors, "You must specify an admin password for $add_admin_userID." if $add_admin_password eq "";
499 }
500
501
502 return @errors; 588 return @errors;
503} 589}
504 590
505sub do_add_course { 591sub do_add_course {
506 my ($self) = @_; 592 my ($self) = @_;
508 my $ce = $r->ce; 594 my $ce = $r->ce;
509 my $db = $r->db; 595 my $db = $r->db;
510 #my $authz = $r->authz; 596 #my $authz = $r->authz;
511 my $urlpath = $r->urlpath; 597 my $urlpath = $r->urlpath;
512 598
513 my $add_courseID = $r->param("add_courseID") || ""; 599 my $add_courseID = $r->param("add_courseID") || "";
600 my $add_courseTitle = $r->param("add_courseTitle") || "";
601 my $add_courseInstitution = $r->param("add_courseInstitution") || "";
602
603 my $add_admin_users = $r->param("add_admin_users") || "";
604
605 my $add_initial_userID = $r->param("add_initial_userID") || "";
606 my $add_initial_password = $r->param("add_initial_password") || "";
607 my $add_initial_confirmPassword = $r->param("add_initial_confirmPassword") || "";
608 my $add_initial_firstName = $r->param("add_initial_firstName") || "";
609 my $add_initial_lastName = $r->param("add_initial_lastName") || "";
610 my $add_initial_email = $r->param("add_initial_email") || "";
611
612 my $add_templates_course = $r->param("add_templates_course") || "";
613
514 my $add_dbLayout = $r->param("add_dbLayout") || ""; 614 my $add_dbLayout = $r->param("add_dbLayout") || "";
515 my $add_sql_host = $r->param("add_sql_host") || ""; 615 my $add_sql_host = $r->param("add_sql_host") || "";
516 my $add_sql_port = $r->param("add_sql_port") || ""; 616 my $add_sql_port = $r->param("add_sql_port") || "";
517 my $add_sql_username = $r->param("add_sql_username") || ""; 617 my $add_sql_username = $r->param("add_sql_username") || "";
518 my $add_sql_password = $r->param("add_sql_password") || ""; 618 my $add_sql_password = $r->param("add_sql_password") || "";
519 my $add_sql_database = $r->param("add_sql_database") || ""; 619 my $add_sql_database = $r->param("add_sql_database") || "";
520 my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; 620 my $add_sql_wwhost = $r->param("add_sql_wwhost") || "";
521 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; 621 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || "";
522 my $add_initial_userID = $r->param("add_initial_userID") || "";
523 my $add_initial_password = $r->param("add_initial_password") || "";
524 my $add_templates_course = $r->param("add_templates_course") || "";
525 my $add_contact_person = $r->param("add_contact_person") || "";
526 my $add_contact_institution = $r->param("add_contact_institution") || "";
527 my $add_contact_email = $r->param("add_contact_email") || "";
528 my $add_course_title = $r->param("add_course_title") || "";
529 my $add_admin_userID = $r->param("add_admin_userID") || $r->param("user") || "";
530 my $add_admin_password = $r->param("add_admin_password") || "";
531 622
532 my $ce2 = WeBWorK::CourseEnvironment->new( 623 my $ce2 = WeBWorK::CourseEnvironment->new(
533 $ce->{webworkDirs}->{root}, 624 $ce->{webworkDirs}->{root},
534 $ce->{webworkURLs}->{root}, 625 $ce->{webworkURLs}->{root},
535 $ce->{pg}->{directories}->{root}, 626 $ce->{pg}->{directories}->{root},
536 $add_courseID, 627 $add_courseID,
537 ); 628 );
538 629
539 my %courseOptions = ( dbLayoutName => $add_dbLayout ); 630 my %courseOptions = ( dbLayoutName => $add_dbLayout );
631
632 if ($add_initial_email ne "") {
633 $courseOptions{allowedRecipients} = [ $add_initial_email ];
634 # don't set feedbackRecipients -- this just gets in the way of the more
635 # intelligent "receive_recipients" method.
636 #$courseOptions{feedbackRecipients} = [ $add_initial_email ];
637 }
638
540 if ($add_dbLayout eq "gdbm") { 639 if ($add_dbLayout eq "gdbm") {
541 $courseOptions{globalUserID} = $add_gdbm_globalUserID if $add_gdbm_globalUserID ne ""; 640 $courseOptions{globalUserID} = $add_gdbm_globalUserID if $add_gdbm_globalUserID ne "";
542 } 641 }
543 642
544 my %dbOptions; 643 my %dbOptions;
548 $dbOptions{username} = $add_sql_username; 647 $dbOptions{username} = $add_sql_username;
549 $dbOptions{password} = $add_sql_password; 648 $dbOptions{password} = $add_sql_password;
550 $dbOptions{database} = $add_sql_database || "webwork_$add_courseID"; 649 $dbOptions{database} = $add_sql_database || "webwork_$add_courseID";
551 $dbOptions{wwhost} = $add_sql_wwhost; 650 $dbOptions{wwhost} = $add_sql_wwhost;
552 } 651 }
553 # add professor and administor if defined. 652
554 my @users; 653 my @users;
654
655 # copy users from current (admin) course if desired
656 if ($add_admin_users ne "") {
657 foreach my $userID ($db->listUsers) {
658 if ($userID eq $add_initial_userID) {
659 $self->addbadmessage( "User '$userID' will not be copied from admin course as it is the initial instructor.");
660 next;
661 }
662 my $User = $db->getUser($userID);
663 my $Password = $db->getPassword($userID);
664 my $PermissionLevel = $db->getPermissionLevel($userID);
665 push @users, [ $User, $Password, $PermissionLevel ];
666 }
667 }
668
669 # add initial instructor if desired
555 if ($add_initial_userID ne "") { 670 if ($add_initial_userID ne "") {
556 my $User = $db->newUser( 671 my $User = $db->newUser(
557 user_id => $add_initial_userID, 672 user_id => $add_initial_userID,
673 first_name => $add_initial_firstName,
674 last_name => $add_initial_lastName,
675 student_id => $add_initial_userID,
676 email_address => $add_initial_email,
558 status => "C", 677 status => "C",
559 ); 678 );
560 my $Password = $db->newPassword( 679 my $Password = $db->newPassword(
561 user_id => $add_initial_userID, 680 user_id => $add_initial_userID,
562 password => cryptPassword($add_initial_password), 681 password => cryptPassword($add_initial_password),
563 ); 682 );
564 my $PermissionLevel = $db->newPermissionLevel( 683 my $PermissionLevel = $db->newPermissionLevel(
565 user_id => $add_initial_userID, 684 user_id => $add_initial_userID,
566 permission => "10", 685 permission => "10",
567 ); 686 );
568 push @users, [ $User, $Password, $PermissionLevel ]; 687 push @users, [ $User, $Password, $PermissionLevel ];
569 } 688 }
570 if ($add_admin_userID ne "") { 689
571 my $User = $db->newUser( 690 push @{$courseOptions{PRINT_FILE_NAMES_FOR}}, map { $_->[0]->user_id } @users;
572 user_id => $add_admin_userID, 691
573 status => "C",
574 );
575 my $Password = $db->newPassword(
576 user_id => $add_admin_userID,
577 password => cryptPassword($add_admin_password),
578 );
579 my $PermissionLevel = $db->newPermissionLevel(
580 user_id => $add_admin_userID,
581 permission => "10",
582 );
583 push @users, [ $User, $Password, $PermissionLevel ];
584 }
585 my %optional_arguments; 692 my %optional_arguments;
586 if ($add_templates_course ne "") { 693 if ($add_templates_course ne "") {
587 $optional_arguments{templatesFrom} = $add_templates_course; 694 $optional_arguments{templatesFrom} = $add_templates_course;
588 } 695 }
589 696
595 dbOptions => \%dbOptions, 702 dbOptions => \%dbOptions,
596 users => \@users, 703 users => \@users,
597 %optional_arguments, 704 %optional_arguments,
598 ); 705 );
599 }; 706 };
600
601 if ($@) { 707 if ($@) {
602 my $error = $@; 708 my $error = $@;
603 print CGI::div({class=>"ResultsWithError"}, 709 print CGI::div({class=>"ResultsWithError"},
604 CGI::p("An error occured while creating the course $add_courseID:"), 710 CGI::p("An error occured while creating the course $add_courseID:"),
605 CGI::tt(CGI::escapeHTML($error)), 711 CGI::tt(CGI::escapeHTML($error)),
614 dbOptions => \%dbOptions, 720 dbOptions => \%dbOptions,
615 ); 721 );
616 } 722 }
617 } 723 }
618 } else { 724 } else {
725 #log the action
619 writeLog($ce, "hosted_courses", join("\t", 726 writeLog($ce, "hosted_courses", join("\t",
620 "\tAdded", 727 "\tAdded",
621 $add_contact_institution, 728 $add_courseInstitution,
622 $add_course_title, 729 $add_courseTitle,
623 $add_courseID, 730 $add_courseID,
624 $add_contact_person, 731 $add_initial_firstName,
732 $add_initial_lastName,
625 $add_contact_email, 733 $add_initial_email,
626 )); 734 ));
735 # add contact to admin course as student?
736 # FIXME -- should we do this?
627 print CGI::div({class=>"ResultsWithoutError"}, 737 print CGI::div({class=>"ResultsWithoutError"},
628 CGI::p("Successfully created the course $add_courseID"), 738 CGI::p("Successfully created the course $add_courseID"),
629 ); 739 );
630 my $newCoursePath = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSets", 740 my $newCoursePath = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSets",
631 courseID => $add_courseID); 741 courseID => $add_courseID);
632 my $newCourseURL = $self->systemLink($newCoursePath, authen => 0); 742 my $newCourseURL = $self->systemLink($newCoursePath, authen => 0);
633 print CGI::div({style=>"text-align: center"}, 743 print CGI::div({style=>"text-align: center"},
634 CGI::a({href=>$newCourseURL}, "Log into $add_courseID"), 744 CGI::a({href=>$newCourseURL}, "Log into $add_courseID"),
635 ); 745 );
636 } 746 }
747
748
637} 749}
638 750
639################################################################################ 751################################################################################
640 752
641sub delete_course_form { 753sub delete_course_form {
695 "If the course's database layout (indicated in parentheses above) is " 807 "If the course's database layout (indicated in parentheses above) is "
696 . CGI::b("sql") . ", supply the SQL connections information requested below." 808 . CGI::b("sql") . ", supply the SQL connections information requested below."
697 ); 809 );
698 810
699 print CGI::start_table({class=>"FormLayout"}); 811 print CGI::start_table({class=>"FormLayout"});
812 print CGI::Tr(CGI::td({colspan=>2},
813 "Enter the user ID and password for an SQL account with sufficient permissions to delete an existing database."
814 )
815 );
816 print CGI::Tr(
817 CGI::th({class=>"LeftHeader"}, "SQL Admin Username:"),
818 CGI::td(CGI::textfield("delete_sql_username", $delete_sql_username, 25)),
819 );
820 print CGI::Tr(
821 CGI::th({class=>"LeftHeader"}, "SQL Admin Password:"),
822 CGI::td(CGI::password_field("delete_sql_password", $delete_sql_password, 25)),
823 );
824
825 #print CGI::Tr(CGI::td({colspan=>2},
826 # "The optionial SQL settings you enter below must match the settings in the DBI source"
827 # . " specification " . CGI::tt($dbi_source) . ". Replace " . CGI::tt("COURSENAME")
828 # . " with the course name you entered above."
829 # )
830 #);
700 print CGI::Tr( 831 print CGI::Tr(
701 CGI::th({class=>"LeftHeader"}, "SQL Server Host:"), 832 CGI::th({class=>"LeftHeader"}, "SQL Server Host:"),
702 CGI::td( 833 CGI::td(
703 CGI::textfield("delete_sql_host", $delete_sql_host, 25), 834 CGI::textfield("delete_sql_host", $delete_sql_host, 25),
704 CGI::br(), 835 CGI::br(),
711 CGI::textfield("delete_sql_port", $delete_sql_port, 25), 842 CGI::textfield("delete_sql_port", $delete_sql_port, 25),
712 CGI::br(), 843 CGI::br(),
713 CGI::small("Leave blank to use the default port."), 844 CGI::small("Leave blank to use the default port."),
714 ), 845 ),
715 ); 846 );
716 print CGI::Tr( 847
717 CGI::th({class=>"LeftHeader"}, "SQL Admin Username:"),
718 CGI::td(CGI::textfield("delete_sql_username", $delete_sql_username, 25)),
719 );
720 print CGI::Tr(
721 CGI::th({class=>"LeftHeader"}, "SQL Admin Password:"),
722 CGI::td(CGI::password_field("delete_sql_password", $delete_sql_password, 25)),
723 );
724 print CGI::Tr( 848 print CGI::Tr(
725 CGI::th({class=>"LeftHeader"}, "SQL Database Name:"), 849 CGI::th({class=>"LeftHeader"}, "SQL Database Name:"),
726 CGI::td( 850 CGI::td(
727 CGI::textfield("delete_sql_database", $delete_sql_database, 25), 851 CGI::textfield("delete_sql_database", $delete_sql_database, 25),
728 CGI::br(), 852 CGI::br(),
880 CGI::p("An error occured while deleting the course $delete_courseID:"), 1004 CGI::p("An error occured while deleting the course $delete_courseID:"),
881 CGI::tt(CGI::escapeHTML($error)), 1005 CGI::tt(CGI::escapeHTML($error)),
882 ); 1006 );
883 } else { 1007 } else {
884 print CGI::div({class=>"ResultsWithoutError"}, 1008 print CGI::div({class=>"ResultsWithoutError"},
885 CGI::p("Possibly deleted the course $delete_courseID. (We need better error checking in deleteCourse().)"), 1009 CGI::p("Successfully deleted the course $delete_courseID."),
886 ); 1010 );
887 writeLog($ce, "hosted_courses", join("\t", 1011 writeLog($ce, "hosted_courses", join("\t",
888 "\tDeleted", 1012 "\tDeleted",
889 "", 1013 "",
890 "", 1014 "",
931 $courseLabels{$courseID} = "$courseID (" . $tempCE->{dbLayoutName} . ")"; 1055 $courseLabels{$courseID} = "$courseID (" . $tempCE->{dbLayoutName} . ")";
932 } 1056 }
933 1057
934 print CGI::h2("Export Database"); 1058 print CGI::h2("Export Database");
935 1059
936 print CGI::start_form("POST", $r->uri); 1060 print CGI::start_form("GET", $r->uri);
937 print $self->hidden_authen_fields; 1061 print $self->hidden_authen_fields;
938 print $self->hidden_fields("subDisplay"); 1062 print $self->hidden_fields("subDisplay");
939 1063
940 print CGI::p("Select a course to export the course's database."); 1064 print CGI::p("Select a course to export the course's database. Please note
1065 that exporting can take a very long time for a large course. If you have
1066 shell access to the WeBWorK server, you may use the ", CGI::code("wwdb"), "
1067 utility instead.");
941 1068
942 print CGI::table({class=>"FormLayout"}, 1069 print CGI::table({class=>"FormLayout"},
943 CGI::Tr( 1070 CGI::Tr(
944 CGI::th({class=>"LeftHeader"}, "Course Name:"), 1071 CGI::th({class=>"LeftHeader"}, "Course Name:"),
945 CGI::td( 1072 CGI::td(
1013 $export_courseID, 1140 $export_courseID,
1014 ); 1141 );
1015 1142
1016 my $db2 = new WeBWorK::DB($ce2->{dbLayout}); 1143 my $db2 = new WeBWorK::DB($ce2->{dbLayout});
1017 1144
1018 my ($fh, $export_file) = tempfile("db_export_XXXXXX", DIR => $ce->{webworkDirs}->{tmp}); 1145 #my ($fh, $export_file) = tempfile("db_export_XXXXXX", DIR => $ce->{webworkDirs}->{tmp});
1019 my ($random_chars) = $export_file =~ m/db_export_(\w+)$/; 1146 #my ($random_chars) = $export_file =~ m/db_export_(\w+)$/;
1020 1147
1021 my @errors; 1148 my @errors;
1022 1149
1023 eval { 1150 eval {
1024 @errors = dbExport( 1151 @errors = dbExport(
1025 db => $db2, 1152 db => $db2,
1026 xml => $fh, 1153 #xml => $fh,
1154 xml => *STDOUT,
1027 tables => \@export_tables, 1155 tables => \@export_tables,
1028 ); 1156 );
1029 }; 1157 };
1030 1158
1031 push @errors, "Fatal exception: $@" if $@; 1159 #push @errors, "Fatal exception: $@" if $@;
1032 1160 #
1033 if (@errors) { 1161 #if (@errors) {
1034 print CGI::div({class=>"ResultsWithError"}, 1162 # print CGI::div({class=>"ResultsWithError"},
1035 CGI::p("An error occured while exporting the database of course $export_courseID:"), 1163 # CGI::p("An error occured while exporting the database of course $export_courseID:"),
1036 CGI::ul(CGI::li(\@errors)), 1164 # CGI::ul(CGI::li(\@errors)),
1037 ); 1165 # );
1038 } else { 1166 #} else {
1039 print CGI::div({class=>"ResultsWithoutError"}, 1167 # print CGI::div({class=>"ResultsWithoutError"},
1040 CGI::p("Export succeeded."), 1168 # CGI::p("Export succeeded."),
1041 ); 1169 # );
1042 1170 #
1043 print CGI::div({style=>"text-align: center"}, 1171 # print CGI::div({style=>"text-align: center"},
1044 CGI::a({href=>$self->systemLink($urlpath, params=>{download_exported_database=>$random_chars, export_courseID=>undef})}, "Download Exported Database"), 1172 # CGI::a({href=>$self->systemLink($urlpath, params=>{download_exported_database=>$random_chars, export_courseID=>undef})}, "Download Exported Database"),
1045 ); 1173 # );
1046 } 1174 #}
1047} 1175}
1048 1176
1049################################################################################ 1177################################################################################
1050 1178
1051sub import_database_form { 1179sub import_database_form {

Legend:
Removed from v.2254  
changed lines
  Added in v.3054

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9