[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 2479
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.23 2004/07/10 16:06:59 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.
45 # check permissions 45 # check permissions
46 unless ($authz->hasPermissions($user, "create_and_delete_courses")) { 46 unless ($authz->hasPermissions($user, "create_and_delete_courses")) {
47 $self->addmessage( CGI::div({class=>'ResultsWithError'},"$user is not authorized to create or delete courses") ); 47 $self->addmessage( CGI::div({class=>'ResultsWithError'},"$user is not authorized to create or delete courses") );
48 return; 48 return;
49 } 49 }
50 50
51 ## if the user is asking for the downloaded database...
51 if (defined $r->param("download_exported_database")) { 52 #if (defined $r->param("download_exported_database")) {
53 # my $courseID = $r->param("export_courseID");
54 # my $random_chars = $r->param("download_exported_database");
55 #
56 # die "courseID not specified" unless defined $courseID;
57 # die "invalid file specification" unless $random_chars =~ m/^\w+$/;
58 #
59 # my $tempdir = $ce->{webworkDirs}->{tmp};
60 # my $export_file = "$tempdir/db_export_$random_chars";
61 #
62 # $self->reply_with_file("application/xml", $export_file, "${courseID}_database.xml", 0);
63 #
64 # return "";
65 #}
66 #
67 ## otherwise...
68
69 my @errors;
70 my $method_to_call;
71
72 my $subDisplay = $r->param("subDisplay");
73 if (defined $subDisplay) {
74
75 if ($subDisplay eq "add_course") {
76 if (defined $r->param("add_course")) {
77 @errors = $self->add_course_validate;
78 if (@errors) {
79 $method_to_call = "add_course_form";
80 } else {
81 $method_to_call = "do_add_course";
82 }
83 } else {
84 $method_to_call = "add_course_form";
85 }
86 }
87
88 elsif ($subDisplay eq "delete_course") {
89 if (defined $r->param("delete_course")) {
90 # validate or confirm
91 @errors = $self->delete_course_validate;
92 if (@errors) {
93 $method_to_call = "delete_course_form";
94 } else {
95 $method_to_call = "delete_course_confirm";
96 }
97 } elsif (defined $r->param("confirm_delete_course")) {
98 # validate and delete
99 @errors = $self->delete_course_validate;
100 if (@errors) {
101 $method_to_call = "delete_course_form";
102 } else {
103 $method_to_call = "do_delete_course";
104 }
105 } else {
106 # form only
107 $method_to_call = "delete_course_form";
108 }
109 }
110
111 elsif ($subDisplay eq "export_database") {
112 if (defined $r->param("export_database")) {
113 @errors = $self->export_database_validate;
114 if (@errors) {
115 $method_to_call = "export_database_form";
116 } else {
117 # we have to do something special here, since we're sending
118 # the database as we export it. $method_to_call still gets
119 # set here, but it gets caught by header() and content()
120 # below instead of by body().
121 $method_to_call = "do_export_database";
122 }
123 } else {
124 $method_to_call = "export_database_form";
125 }
126 }
127
128 elsif ($subDisplay eq "import_database") {
129 if (defined $r->param("import_database")) {
130 @errors = $self->import_database_validate;
131 if (@errors) {
132 $method_to_call = "import_database_form";
133 } else {
134 $method_to_call = "do_import_database";
135 }
136 } else {
137 $method_to_call = "import_database_form";
138 }
139 }
140
141 else {
142 @errors = "Unrecognized sub-display @{[ CGI::b($subDisplay) ]}.";
143 }
144
145 }
146
147 $self->{errors} = \@errors;
148 $self->{method_to_call} = $method_to_call;
149}
150
151sub header {
152 my ($self) = @_;
153 my $method_to_call = $self->{method_to_call};
154 if (defined $method_to_call and $method_to_call eq "do_export_database") {
155 my $r = $self->r;
52 my $courseID = $r->param("export_courseID"); 156 my $courseID = $r->param("export_courseID");
53 my $random_chars = $r->param("download_exported_database"); 157 $r->content_type("application/octet-stream");
54 158 $r->header_out("Content-Disposition" => "attachment; filename=\"${courseID}_database.xml\"");
55 die "courseID not specified" unless defined $courseID; 159 $r->send_http_header;
56 die "invalid file specification" unless $random_chars =~ m/^\w+$/; 160 } else {
57 161 $self->SUPER::header;
58 my $tempdir = $ce->{webworkDirs}->{tmp}; 162 }
59 my $export_file = "$tempdir/db_export_$random_chars"; 163}
60 164
61 $self->reply_with_file("text/xml", $export_file, "${courseID}_database.xml", 0); 165# sends:
166#
167# HTTP/1.1 200 OK
168# Date: Fri, 09 Jul 2004 19:05:55 GMT
169# Server: Apache/1.3.27 (Unix) mod_perl/1.27
170# Content-Disposition: attachment; filename="mth143_database.xml"
171# Connection: close
172# Content-Type: application/octet-stream
173
174sub content {
175 my ($self) = @_;
176 my $method_to_call = $self->{method_to_call};
177 if (defined $method_to_call and $method_to_call eq "do_export_database") {
178 print "<!-- Ϸĩ½ōú -->\n";
179 print "<!-- Those were some high-bit characters to convince Safari that we really do want this saved as a file. -->\n";
180 $self->do_export_database;
181 } else {
182 $self->SUPER::content;
62 } 183 }
63} 184}
64 185
65sub body { 186sub body {
66 my ($self) = @_; 187 my ($self) = @_;
68 my $ce = $r->ce; 189 my $ce = $r->ce;
69 my $db = $r->db; 190 my $db = $r->db;
70 my $authz = $r->authz; 191 my $authz = $r->authz;
71 my $urlpath = $r->urlpath; 192 my $urlpath = $r->urlpath;
72 193
73 my $user = $r->param('user'); 194 my $user = $r->param('user');
74 195
75 # check permissions 196 # check permissions
76 unless ($authz->hasPermissions($user, "create_and_delete_courses")) { 197 unless ($authz->hasPermissions($user, "create_and_delete_courses")) {
77 return ""; 198 return "";
78 } 199 }
79 200
80 print CGI::p({style=>"text-align: center"}, 201 print CGI::p({style=>"text-align: center"},
81 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"add_course"})}, "Add Course"), 202 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 " | ", 203 " | ",
85 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"delete_course"})}, "Delete Course"), 204 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"delete_course"})}, "Delete Course"),
86 " | ", 205 " | ",
87 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"export_database"})}, "Export Database"), 206 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"export_database"})}, "Export Database"),
88 " | ", 207 " | ",
89 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"import_database"})}, "Import Database"), 208 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"import_database"})}, "Import Database"),
90 ); 209 );
91 210
92 print CGI::hr(); 211 print CGI::hr();
93 212
94 my $subDisplay = $r->param("subDisplay"); 213 my @errors = @{$self->{errors}};
95 if (defined $subDisplay) { 214 my $method_to_call = $self->{method_to_call};
96 215
97 if ($subDisplay eq "add_course") {
98 if (defined $r->param("add_course")) {
99 my @errors = $self->add_course_validate;
100 if (@errors) { 216 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"}, 217 print CGI::div({class=>"ResultsWithError"},
181 "Unrecognized sub-display @{[ CGI::b($subDisplay) ]}."); 218 CGI::p("Please correct the following errors and try again:"),
219 CGI::ul(CGI::li(\@errors)),
220 );
182 } 221 }
183 222
223 if (defined $method_to_call and $method_to_call ne "") {
224 $self->$method_to_call;
184 } 225 }
185 226
186 return ""; 227 return "";
187} 228}
188 229
195 #my $db = $r->db; 236 #my $db = $r->db;
196 #my $authz = $r->authz; 237 #my $authz = $r->authz;
197 #my $urlpath = $r->urlpath; 238 #my $urlpath = $r->urlpath;
198 239
199 my $add_courseID = $r->param("add_courseID") || ""; 240 my $add_courseID = $r->param("add_courseID") || "";
241 my $add_courseTitle = $r->param("add_courseTitle") || "";
242 my $add_courseInstitution = $r->param("add_courseInstitution") || "";
243
244 my $add_admin_users = $r->param("add_admin_users") || "";
245
246 my $add_initial_userID = $r->param("add_initial_userID") || "";
247 my $add_initial_password = $r->param("add_initial_password") || "";
248 my $add_initial_confirmPassword = $r->param("add_initial_confirmPassword") || "";
249 my $add_initial_firstName = $r->param("add_initial_firstName") || "";
250 my $add_initial_lastName = $r->param("add_initial_lastName") || "";
251 my $add_initial_email = $r->param("add_initial_email") || "";
252
253 my $add_templates_course = $r->param("add_templates_course") || "";
254
200 my $add_dbLayout = $r->param("add_dbLayout") || ""; 255 my $add_dbLayout = $r->param("add_dbLayout") || "";
201 my $add_sql_host = $r->param("add_sql_host") || ""; 256 my $add_sql_host = $r->param("add_sql_host") || "";
202 my $add_sql_port = $r->param("add_sql_port") || ""; 257 my $add_sql_port = $r->param("add_sql_port") || "";
203 my $add_sql_username = $r->param("add_sql_username") || ""; 258 my $add_sql_username = $r->param("add_sql_username") || "";
204 my $add_sql_password = $r->param("add_sql_password") || ""; 259 my $add_sql_password = $r->param("add_sql_password") || "";
205 my $add_sql_database = $r->param("add_sql_database") || ""; 260 my $add_sql_database = $r->param("add_sql_database") || "";
206 my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; 261 my $add_sql_wwhost = $r->param("add_sql_wwhost") || "";
207 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; 262 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 263
220 my @dbLayouts = sort keys %{ $ce->{dbLayouts} }; 264 my @dbLayouts = sort keys %{ $ce->{dbLayouts} };
221 265
222 my $ce2 = WeBWorK::CourseEnvironment->new( 266 my $ce2 = WeBWorK::CourseEnvironment->new(
223 $ce->{webworkDirs}->{root}, 267 $ce->{webworkDirs}->{root},
243 } 287 }
244 $source; 288 $source;
245 }; 289 };
246 290
247 my @existingCourses = listCourses($ce); 291 my @existingCourses = listCourses($ce);
292 @existingCourses = sort @existingCourses;
248 293
249 print CGI::h2("Add Course"); 294 print CGI::h2("Add Course");
250 295
251 print CGI::start_form("POST", $r->uri); 296 print CGI::start_form("POST", $r->uri);
252 print $self->hidden_authen_fields; 297 print $self->hidden_authen_fields;
253 print $self->hidden_fields("subDisplay"); 298 print $self->hidden_fields("subDisplay");
254 299
255 print CGI::p("Specify a name for the new course."); 300 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 301
257 print CGI::table({class=>"FormLayout"}, 302 print CGI::table({class=>"FormLayout"},
258 CGI::Tr( 303 CGI::Tr(
259 CGI::th({class=>"LeftHeader"}, "Course ID:"), 304 CGI::th({class=>"LeftHeader"}, "Course ID:"),
260 CGI::td(CGI::textfield("add_courseID", $add_courseID, 25)), 305 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 ), 306 ),
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( 307 CGI::Tr(
308 CGI::th({class=>"LeftHeader"}, "Course Title:"),
309 CGI::td(CGI::textfield("add_courseTitle", $add_courseTitle, 25)),
310 ),
311 CGI::Tr(
270 CGI::th({class=>"CenterHeader"}, "Instructor ID"), 312 CGI::th({class=>"LeftHeader"}, "Institution:"),
313 CGI::td(CGI::textfield("add_courseInstitution", $add_courseInstitution, 25)),
314 ),
315 );
316
317 print CGI::p("To add the WeBWorK administrators to the new course (as instructors) check the box below.");
318
319 print CGI::p(CGI::checkbox("add_admin_users", $add_admin_users, "on", "Add WeBWorK administrators to new course"));
320
321 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.");
322
323 print CGI::table({class=>"FormLayout"}, CGI::Tr(
324 CGI::td(
325 CGI::table({class=>"FormLayout"},
326 CGI::Tr(
327 CGI::th({class=>"LeftHeader"}, "User ID:"),
328 CGI::td(CGI::textfield("add_initial_userID", $add_initial_userID, 25)),
329 ),
330 CGI::Tr(
271 CGI::th({class=>"CenterHeader"}, "Instructor Password"), 331 CGI::th({class=>"LeftHeader"}, "Password:"),
332 CGI::td(CGI::password_field("add_initial_password", $add_initial_password, 25)),
333 ),
334 CGI::Tr(
272 CGI::th({class=>"CenterHeader"}, "Confirm Instructor Password"), 335 CGI::th({class=>"LeftHeader"}, "Confirm Password:"),
336 CGI::td(CGI::password_field("add_initial_confirmPassword", $add_initial_confirmPassword, 25)),
337 ),
338 ),
339 ),
340 CGI::td(
341 CGI::table({class=>"FormLayout"},
342 CGI::Tr(
343 CGI::th({class=>"LeftHeader"}, "First Name:"),
344 CGI::td(CGI::textfield("add_initial_firstName", $add_initial_firstName, 25)),
345 ),
346 CGI::Tr(
347 CGI::th({class=>"LeftHeader"}, "Last Name:"),
348 CGI::td(CGI::textfield("add_initial_lastName", $add_initial_lastName, 25)),
349 ),
350 CGI::Tr(
351 CGI::th({class=>"LeftHeader"}, "Email Address:"),
352 CGI::td(CGI::textfield("add_initial_email", $add_initial_email, 25)),
353 ),
354 ),
273 355
274
275 ), 356 ),
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 ); 357 ));
305 358
306 print CGI::p("Select an existing course from which to copy templates:"); 359 print CGI::p("To copy problem templates from an existing course, select the course below.");
307 360
308 print CGI::table({class=>"FormLayout"}, 361 print CGI::table({class=>"FormLayout"},
309 CGI::Tr( 362 CGI::Tr(
310 CGI::th({class=>"LeftHeader"}, "Copy templates from:"), 363 CGI::th({class=>"LeftHeader"}, "Copy templates from:"),
311 CGI::td( 364 CGI::td(
320 373
321 ), 374 ),
322 ), 375 ),
323 ); 376 );
324 377
325 print CGI::p("Select a database layout below. Some database layouts require additional information."); 378 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 379
331 foreach my $dbLayout (@dbLayouts) { 380 foreach my $dbLayout (@dbLayouts) {
332 print CGI::start_table({class=>"FormLayout"}); 381 print CGI::start_table({class=>"FormLayout"});
333 382
334 # we generate singleton radio button tags ourselves because it's too much of a pain to do it with CGI.pm 383 # we generate singleton radio button tags ourselves because it's too much of a pain to do it with CGI.pm
343 print CGI::start_Tr(); 392 print CGI::start_Tr();
344 print CGI::td(); # for indentation :( 393 print CGI::td(); # for indentation :(
345 print CGI::start_td(); 394 print CGI::start_td();
346 395
347 if ($dbLayout eq "sql") { 396 if ($dbLayout eq "sql") {
348
349 print CGI::start_table({class=>"FormLayout"}); 397 print CGI::start_table({class=>"FormLayout"});
350 print CGI::Tr(CGI::td({colspan=>2}, 398 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." 399 "Enter the user ID and password for an SQL account with sufficient permissions to create a new database."
352 ) 400 )
353 ); 401 );
354 print CGI::Tr( 402 print CGI::Tr(
355 CGI::th({class=>"LeftHeader"}, "SQL Admin Username:"), 403 CGI::th({class=>"LeftHeader"}, "SQL Admin Username:"),
356 CGI::td(CGI::textfield("add_sql_username", $add_sql_username, 25)), 404 CGI::td(CGI::textfield("add_sql_username", $add_sql_username, 25)),
358 print CGI::Tr( 406 print CGI::Tr(
359 CGI::th({class=>"LeftHeader"}, "SQL Admin Password:"), 407 CGI::th({class=>"LeftHeader"}, "SQL Admin Password:"),
360 CGI::td(CGI::password_field("add_sql_password", $add_sql_password, 25)), 408 CGI::td(CGI::password_field("add_sql_password", $add_sql_password, 25)),
361 ); 409 );
362 410
363 print CGI::Tr(CGI::td({colspan=>2}, CGI::hr(), 411 print CGI::Tr(CGI::td({colspan=>2},
364 "The optionial SQL settings you enter below must match the settings in the DBI source", 412 "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"), 413 . " specification " . CGI::tt($dbi_source) . ". Replace " . CGI::tt("COURSENAME")
366 " with the course name you entered above." 414 . " with the course name you entered above."
367 ) 415 )
368 ); 416 );
369 print CGI::Tr( 417 print CGI::Tr(
370 CGI::th({class=>"LeftHeader"}, "SQL Server Host:"), 418 CGI::th({class=>"LeftHeader"}, "SQL Server Host:"),
371 CGI::td( 419 CGI::td(
412 print CGI::end_td(); 460 print CGI::end_td();
413 print CGI::end_Tr(); 461 print CGI::end_Tr();
414 print CGI::end_table(); 462 print CGI::end_table();
415 } 463 }
416 464
417
418
419
420
421
422
423 print CGI::p({style=>"text-align: center"}, CGI::submit("add_course", "Add Course")); 465 print CGI::p({style=>"text-align: center"}, CGI::submit("add_course", "Add Course"));
424 466
425 print CGI::end_form(); 467 print CGI::end_form();
426} 468}
427 469
432 #my $db = $r->db; 474 #my $db = $r->db;
433 #my $authz = $r->authz; 475 #my $authz = $r->authz;
434 #my $urlpath = $r->urlpath; 476 #my $urlpath = $r->urlpath;
435 477
436 my $add_courseID = $r->param("add_courseID") || ""; 478 my $add_courseID = $r->param("add_courseID") || "";
479 my $add_courseTitle = $r->param("add_courseTitle") || "";
480 my $add_courseInstitution = $r->param("add_courseInstitution") || "";
481
482 my $add_admin_users = $r->param("add_admin_users") || "";
483
484 my $add_initial_userID = $r->param("add_initial_userID") || "";
485 my $add_initial_password = $r->param("add_initial_password") || "";
486 my $add_initial_confirmPassword = $r->param("add_initial_confirmPassword") || "";
487 my $add_initial_firstName = $r->param("add_initial_firstName") || "";
488 my $add_initial_lastName = $r->param("add_initial_lastName") || "";
489 my $add_initial_email = $r->param("add_initial_email") || "";
490
491 my $add_templates_course = $r->param("add_templates_course") || "";
492
437 my $add_dbLayout = $r->param("add_dbLayout") || ""; 493 my $add_dbLayout = $r->param("add_dbLayout") || "";
438 my $add_sql_host = $r->param("add_sql_host") || ""; 494 my $add_sql_host = $r->param("add_sql_host") || "";
439 my $add_sql_port = $r->param("add_sql_port") || ""; 495 my $add_sql_port = $r->param("add_sql_port") || "";
440 my $add_sql_username = $r->param("add_sql_username") || ""; 496 my $add_sql_username = $r->param("add_sql_username") || "";
441 my $add_sql_password = $r->param("add_sql_password") || ""; 497 my $add_sql_password = $r->param("add_sql_password") || "";
442 my $add_sql_database = $r->param("add_sql_database") || ""; 498 my $add_sql_database = $r->param("add_sql_database") || "";
443 my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; 499 my $add_sql_wwhost = $r->param("add_sql_wwhost") || "";
444 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; 500 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || "";
445 my $add_initial_userID = $r->param("add_initial_userID") || ""; 501
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; 502 my @errors;
457 503
458 if ($add_courseID eq "") { 504 if ($add_courseID eq "") {
459 push @errors, "You must specify a course name."; 505 push @errors, "You must specify a course ID.";
460 } 506 }
461 if ($add_contact_institution eq "") { 507 if (grep { $add_courseID eq $_ } listCourses($ce)) {
462 push @errors, "You must specify a contact institution." ; 508 push @errors, "A course with ID $add_courseID already exists.";
463 } 509 }
464 if ($add_contact_person eq "") {
465 push @errors, "You must specify a contact person.";
466 }
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 "") { 510 if ($add_courseTitle eq "") {
511 push @errors, "You must specify a course title.";
512 }
513 if ($add_courseInstitution eq "") {
474 push @errors, "You must specify a title for the course."; 514 push @errors, "You must specify an institution for this course.";
515 }
516
517 if ($add_initial_userID ne "") {
518 if ($add_initial_password eq "") {
519 push @errors, "You must specify a password for the initial instructor.";
520 }
521 if ($add_initial_confirmPassword eq "") {
522 push @errors, "You must confirm the password for the initial instructor.";
523 }
524 if ($add_initial_password ne $add_initial_confirmPassword) {
525 push @errors, "The password and password confirmation for the instructor must match.";
526 }
527 if ($add_initial_firstName eq "") {
528 push @errors, "You must specify a first name for the initial instructor.";
529 }
530 if ($add_initial_lastName eq "") {
531 push @errors, "You must specify a last name for the initial instructor.";
532 }
533 if ($add_initial_email eq "") {
534 push @errors, "You must specify an email address for the initial instructor.";
535 }
475 } 536 }
476 537
477 if ($add_dbLayout eq "") { 538 if ($add_dbLayout eq "") {
478 push @errors, "You must select a database layout."; 539 push @errors, "You must select a database layout.";
479 } else { 540 } else {
480 if (exists $ce->{dbLayouts}->{$add_dbLayout}) { 541 if (exists $ce->{dbLayouts}->{$add_dbLayout}) {
481 if ($add_dbLayout eq "sql") { 542 if ($add_dbLayout eq "sql") {
482 push @errors, "You must specify the SQL admin username." if $add_sql_username eq ""; 543 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 ""; 544 push @errors, "You must specify the WeBWorK host." if $add_sql_wwhost eq "";
486 } elsif ($add_dbLayout eq "gdbm") { 545 } elsif ($add_dbLayout eq "gdbm") {
487 push @errors, "You must specify the GDBM global user ID." if $add_gdbm_globalUserID eq ""; 546 push @errors, "You must specify the GDBM global user ID." if $add_gdbm_globalUserID eq "";
488 } 547 }
489 } else { 548 } else {
490 push @errors, "The database layout $add_dbLayout doesn't exist."; 549 push @errors, "The database layout $add_dbLayout doesn't exist.";
491 } 550 }
492 } 551 }
493 552
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; 553 return @errors;
503} 554}
504 555
505sub do_add_course { 556sub do_add_course {
506 my ($self) = @_; 557 my ($self) = @_;
508 my $ce = $r->ce; 559 my $ce = $r->ce;
509 my $db = $r->db; 560 my $db = $r->db;
510 #my $authz = $r->authz; 561 #my $authz = $r->authz;
511 my $urlpath = $r->urlpath; 562 my $urlpath = $r->urlpath;
512 563
513 my $add_courseID = $r->param("add_courseID") || ""; 564 my $add_courseID = $r->param("add_courseID") || "";
565 my $add_courseTitle = $r->param("add_courseTitle") || "";
566 my $add_courseInstitution = $r->param("add_courseInstitution") || "";
567
568 my $add_admin_users = $r->param("add_admin_users") || "";
569
570 my $add_initial_userID = $r->param("add_initial_userID") || "";
571 my $add_initial_password = $r->param("add_initial_password") || "";
572 my $add_initial_confirmPassword = $r->param("add_initial_confirmPassword") || "";
573 my $add_initial_firstName = $r->param("add_initial_firstName") || "";
574 my $add_initial_lastName = $r->param("add_initial_lastName") || "";
575 my $add_initial_email = $r->param("add_initial_email") || "";
576
577 my $add_templates_course = $r->param("add_templates_course") || "";
578
514 my $add_dbLayout = $r->param("add_dbLayout") || ""; 579 my $add_dbLayout = $r->param("add_dbLayout") || "";
515 my $add_sql_host = $r->param("add_sql_host") || ""; 580 my $add_sql_host = $r->param("add_sql_host") || "";
516 my $add_sql_port = $r->param("add_sql_port") || ""; 581 my $add_sql_port = $r->param("add_sql_port") || "";
517 my $add_sql_username = $r->param("add_sql_username") || ""; 582 my $add_sql_username = $r->param("add_sql_username") || "";
518 my $add_sql_password = $r->param("add_sql_password") || ""; 583 my $add_sql_password = $r->param("add_sql_password") || "";
519 my $add_sql_database = $r->param("add_sql_database") || ""; 584 my $add_sql_database = $r->param("add_sql_database") || "";
520 my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; 585 my $add_sql_wwhost = $r->param("add_sql_wwhost") || "";
521 my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; 586 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 587
532 my $ce2 = WeBWorK::CourseEnvironment->new( 588 my $ce2 = WeBWorK::CourseEnvironment->new(
533 $ce->{webworkDirs}->{root}, 589 $ce->{webworkDirs}->{root},
534 $ce->{webworkURLs}->{root}, 590 $ce->{webworkURLs}->{root},
535 $ce->{pg}->{directories}->{root}, 591 $ce->{pg}->{directories}->{root},
536 $add_courseID, 592 $add_courseID,
537 ); 593 );
538 594
539 my %courseOptions = ( dbLayoutName => $add_dbLayout ); 595 my %courseOptions = ( dbLayoutName => $add_dbLayout );
596
597 if ($add_initial_email ne "") {
598 $courseOptions{allowedRecipients} = [ $add_initial_email ];
599 $courseOptions{feedbackRecipients} = [ $add_initial_email ];
600 }
601
540 if ($add_dbLayout eq "gdbm") { 602 if ($add_dbLayout eq "gdbm") {
541 $courseOptions{globalUserID} = $add_gdbm_globalUserID if $add_gdbm_globalUserID ne ""; 603 $courseOptions{globalUserID} = $add_gdbm_globalUserID if $add_gdbm_globalUserID ne "";
542 } 604 }
543 605
544 my %dbOptions; 606 my %dbOptions;
548 $dbOptions{username} = $add_sql_username; 610 $dbOptions{username} = $add_sql_username;
549 $dbOptions{password} = $add_sql_password; 611 $dbOptions{password} = $add_sql_password;
550 $dbOptions{database} = $add_sql_database || "webwork_$add_courseID"; 612 $dbOptions{database} = $add_sql_database || "webwork_$add_courseID";
551 $dbOptions{wwhost} = $add_sql_wwhost; 613 $dbOptions{wwhost} = $add_sql_wwhost;
552 } 614 }
553 # add professor and administor if defined. 615
554 my @users; 616 my @users;
617
618 # copy users from current (admin) course if desired
619 if ($add_admin_users ne "") {
620 foreach my $userID ($db->listUsers) {
621 my $User = $db->getUser($userID);
622 my $Password = $db->getPassword($userID);
623 my $PermissionLevel = $db->getPermissionLevel($userID);
624 push @users, [ $User, $Password, $PermissionLevel ];
625 }
626 }
627
628 # add initial instructor if desired
555 if ($add_initial_userID ne "") { 629 if ($add_initial_userID ne "") {
556 my $User = $db->newUser( 630 my $User = $db->newUser(
557 user_id => $add_initial_userID, 631 user_id => $add_initial_userID,
632 first_name => $add_initial_firstName,
633 last_name => $add_initial_lastName,
634 student_id => $add_initial_userID,
635 email_address => $add_initial_email,
558 status => "C", 636 status => "C",
559 ); 637 );
560 my $Password = $db->newPassword( 638 my $Password = $db->newPassword(
561 user_id => $add_initial_userID, 639 user_id => $add_initial_userID,
562 password => cryptPassword($add_initial_password), 640 password => cryptPassword($add_initial_password),
563 ); 641 );
564 my $PermissionLevel = $db->newPermissionLevel( 642 my $PermissionLevel = $db->newPermissionLevel(
565 user_id => $add_initial_userID, 643 user_id => $add_initial_userID,
566 permission => "10", 644 permission => "10",
567 ); 645 );
568 push @users, [ $User, $Password, $PermissionLevel ]; 646 push @users, [ $User, $Password, $PermissionLevel ];
569 } 647 }
570 if ($add_admin_userID ne "") { 648
571 my $User = $db->newUser( 649 push @{$courseOptions{PRINT_FILE_NAMES_FOR}}, map { $_->[0]->email_address } @users;
572 user_id => $add_admin_userID, 650
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; 651 my %optional_arguments;
586 if ($add_templates_course ne "") { 652 if ($add_templates_course ne "") {
587 $optional_arguments{templatesFrom} = $add_templates_course; 653 $optional_arguments{templatesFrom} = $add_templates_course;
588 } 654 }
589 655
595 dbOptions => \%dbOptions, 661 dbOptions => \%dbOptions,
596 users => \@users, 662 users => \@users,
597 %optional_arguments, 663 %optional_arguments,
598 ); 664 );
599 }; 665 };
600
601 if ($@) { 666 if ($@) {
602 my $error = $@; 667 my $error = $@;
603 print CGI::div({class=>"ResultsWithError"}, 668 print CGI::div({class=>"ResultsWithError"},
604 CGI::p("An error occured while creating the course $add_courseID:"), 669 CGI::p("An error occured while creating the course $add_courseID:"),
605 CGI::tt(CGI::escapeHTML($error)), 670 CGI::tt(CGI::escapeHTML($error)),
614 dbOptions => \%dbOptions, 679 dbOptions => \%dbOptions,
615 ); 680 );
616 } 681 }
617 } 682 }
618 } else { 683 } else {
684 #log the action
619 writeLog($ce, "hosted_courses", join("\t", 685 writeLog($ce, "hosted_courses", join("\t",
620 "\tAdded", 686 "\tAdded",
621 $add_contact_institution, 687 $add_courseInstitution,
622 $add_course_title, 688 $add_courseTitle,
623 $add_courseID, 689 $add_courseID,
624 $add_contact_person, 690 $add_initial_firstName,
691 $add_initial_lastName,
625 $add_contact_email, 692 $add_initial_email,
626 )); 693 ));
694 # add contact to admin course as student?
695 # FIXME -- should we do this?
627 print CGI::div({class=>"ResultsWithoutError"}, 696 print CGI::div({class=>"ResultsWithoutError"},
628 CGI::p("Successfully created the course $add_courseID"), 697 CGI::p("Successfully created the course $add_courseID"),
629 ); 698 );
630 my $newCoursePath = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSets", 699 my $newCoursePath = $urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSets",
631 courseID => $add_courseID); 700 courseID => $add_courseID);
632 my $newCourseURL = $self->systemLink($newCoursePath, authen => 0); 701 my $newCourseURL = $self->systemLink($newCoursePath, authen => 0);
633 print CGI::div({style=>"text-align: center"}, 702 print CGI::div({style=>"text-align: center"},
634 CGI::a({href=>$newCourseURL}, "Log into $add_courseID"), 703 CGI::a({href=>$newCourseURL}, "Log into $add_courseID"),
635 ); 704 );
636 } 705 }
706
707
637} 708}
638 709
639################################################################################ 710################################################################################
640 711
641sub delete_course_form { 712sub delete_course_form {
880 CGI::p("An error occured while deleting the course $delete_courseID:"), 951 CGI::p("An error occured while deleting the course $delete_courseID:"),
881 CGI::tt(CGI::escapeHTML($error)), 952 CGI::tt(CGI::escapeHTML($error)),
882 ); 953 );
883 } else { 954 } else {
884 print CGI::div({class=>"ResultsWithoutError"}, 955 print CGI::div({class=>"ResultsWithoutError"},
885 CGI::p("Possibly deleted the course $delete_courseID. (We need better error checking in deleteCourse().)"), 956 CGI::p("Successfully deleted the course $delete_courseID."),
886 ); 957 );
887 writeLog($ce, "hosted_courses", join("\t", 958 writeLog($ce, "hosted_courses", join("\t",
888 "\tDeleted", 959 "\tDeleted",
889 "", 960 "",
890 "", 961 "",
931 $courseLabels{$courseID} = "$courseID (" . $tempCE->{dbLayoutName} . ")"; 1002 $courseLabels{$courseID} = "$courseID (" . $tempCE->{dbLayoutName} . ")";
932 } 1003 }
933 1004
934 print CGI::h2("Export Database"); 1005 print CGI::h2("Export Database");
935 1006
936 print CGI::start_form("POST", $r->uri); 1007 print CGI::start_form("GET", $r->uri);
937 print $self->hidden_authen_fields; 1008 print $self->hidden_authen_fields;
938 print $self->hidden_fields("subDisplay"); 1009 print $self->hidden_fields("subDisplay");
939 1010
940 print CGI::p("Select a course to export the course's database."); 1011 print CGI::p("Select a course to export the course's database.");
941 1012
1013 $export_courseID, 1084 $export_courseID,
1014 ); 1085 );
1015 1086
1016 my $db2 = new WeBWorK::DB($ce2->{dbLayout}); 1087 my $db2 = new WeBWorK::DB($ce2->{dbLayout});
1017 1088
1018 my ($fh, $export_file) = tempfile("db_export_XXXXXX", DIR => $ce->{webworkDirs}->{tmp}); 1089 #my ($fh, $export_file) = tempfile("db_export_XXXXXX", DIR => $ce->{webworkDirs}->{tmp});
1019 my ($random_chars) = $export_file =~ m/db_export_(\w+)$/; 1090 #my ($random_chars) = $export_file =~ m/db_export_(\w+)$/;
1020 1091
1021 my @errors; 1092 my @errors;
1022 1093
1023 eval { 1094 eval {
1024 @errors = dbExport( 1095 @errors = dbExport(
1025 db => $db2, 1096 db => $db2,
1026 xml => $fh, 1097 #xml => $fh,
1098 xml => *STDOUT,
1027 tables => \@export_tables, 1099 tables => \@export_tables,
1028 ); 1100 );
1029 }; 1101 };
1030 1102
1031 push @errors, "Fatal exception: $@" if $@; 1103 #push @errors, "Fatal exception: $@" if $@;
1032 1104 #
1033 if (@errors) { 1105 #if (@errors) {
1034 print CGI::div({class=>"ResultsWithError"}, 1106 # print CGI::div({class=>"ResultsWithError"},
1035 CGI::p("An error occured while exporting the database of course $export_courseID:"), 1107 # CGI::p("An error occured while exporting the database of course $export_courseID:"),
1036 CGI::ul(CGI::li(\@errors)), 1108 # CGI::ul(CGI::li(\@errors)),
1037 ); 1109 # );
1038 } else { 1110 #} else {
1039 print CGI::div({class=>"ResultsWithoutError"}, 1111 # print CGI::div({class=>"ResultsWithoutError"},
1040 CGI::p("Export succeeded."), 1112 # CGI::p("Export succeeded."),
1041 ); 1113 # );
1042 1114 #
1043 print CGI::div({style=>"text-align: center"}, 1115 # 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"), 1116 # CGI::a({href=>$self->systemLink($urlpath, params=>{download_exported_database=>$random_chars, export_courseID=>undef})}, "Download Exported Database"),
1045 ); 1117 # );
1046 } 1118 #}
1047} 1119}
1048 1120
1049################################################################################ 1121################################################################################
1050 1122
1051sub import_database_form { 1123sub import_database_form {

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

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9