| 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.23 2004/07/10 16:06:59 sh002i Exp $ |
4 | # $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v 1.24 2004/07/10 16:28:56 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. |
| … | |
… | |
| 30 | use File::Temp qw/tempfile/; |
30 | use File::Temp qw/tempfile/; |
| 31 | use WeBWorK::CourseEnvironment; |
31 | use WeBWorK::CourseEnvironment; |
| 32 | use WeBWorK::Utils qw(cryptPassword writeLog); |
32 | use WeBWorK::Utils qw(cryptPassword writeLog); |
| 33 | use WeBWorK::Utils::CourseManagement qw(addCourse deleteCourse listCourses); |
33 | use WeBWorK::Utils::CourseManagement qw(addCourse deleteCourse listCourses); |
| 34 | use WeBWorK::Utils::DBImportExport qw(dbExport dbImport); |
34 | use WeBWorK::Utils::DBImportExport qw(dbExport dbImport); |
|
|
35 | |
|
|
36 | # put the following database layouts at the top of the list, in this order |
|
|
37 | our @DB_LAYOUT_ORDER = qw/sql_single gdbm sql/; |
|
|
38 | |
|
|
39 | our %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 | ); |
| 35 | |
44 | |
| 36 | sub pre_header_initialize { |
45 | sub 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; |
| … | |
… | |
| 259 | my $add_sql_password = $r->param("add_sql_password") || ""; |
268 | my $add_sql_password = $r->param("add_sql_password") || ""; |
| 260 | my $add_sql_database = $r->param("add_sql_database") || ""; |
269 | my $add_sql_database = $r->param("add_sql_database") || ""; |
| 261 | my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; |
270 | my $add_sql_wwhost = $r->param("add_sql_wwhost") || ""; |
| 262 | my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; |
271 | my $add_gdbm_globalUserID = $r->param("add_gdbm_globalUserID") || ""; |
| 263 | |
272 | |
| 264 | my @dbLayouts = sort keys %{ $ce->{dbLayouts} }; |
273 | my @dbLayouts = do { |
|
|
274 | my @ordered_layouts; |
|
|
275 | foreach my $layout (@DB_LAYOUT_ORDER) { |
|
|
276 | if (exists $ce->{dbLayouts}->{$layout}) { |
|
|
277 | push @ordered_layouts, $layout; |
|
|
278 | } |
|
|
279 | } |
|
|
280 | |
|
|
281 | my %ordered_layouts; @ordered_layouts{@ordered_layouts} = (); |
|
|
282 | my @other_layouts; |
|
|
283 | foreach my $layout (keys %{ $ce->{dbLayouts} }) { |
|
|
284 | unless (exists $ordered_layouts{$layout}) { |
|
|
285 | push @other_layouts, $layout; |
|
|
286 | } |
|
|
287 | } |
|
|
288 | |
|
|
289 | (@ordered_layouts, @other_layouts); |
|
|
290 | }; |
| 265 | |
291 | |
| 266 | my $ce2 = WeBWorK::CourseEnvironment->new( |
292 | my $ce2 = WeBWorK::CourseEnvironment->new( |
| 267 | $ce->{webworkDirs}->{root}, |
293 | $ce->{webworkDirs}->{root}, |
| 268 | $ce->{webworkURLs}->{root}, |
294 | $ce->{webworkURLs}->{root}, |
| 269 | $ce->{pg}->{directories}->{root}, |
295 | $ce->{pg}->{directories}->{root}, |
| … | |
… | |
| 378 | print CGI::p("Select a database layout below."); |
404 | print CGI::p("Select a database layout below."); |
| 379 | |
405 | |
| 380 | foreach my $dbLayout (@dbLayouts) { |
406 | foreach my $dbLayout (@dbLayouts) { |
| 381 | print CGI::start_table({class=>"FormLayout"}); |
407 | print CGI::start_table({class=>"FormLayout"}); |
| 382 | |
408 | |
|
|
409 | my $dbLayoutLabel = (defined $DB_LAYOUT_DESCRIPTIONS{$dbLayout}) |
|
|
410 | ? "$dbLayout - $DB_LAYOUT_DESCRIPTIONS{$dbLayout}" |
|
|
411 | : $dbLayout; |
|
|
412 | |
| 383 | # we generate singleton radio button tags ourselves because it's too much of a pain to do it with CGI.pm |
413 | # we generate singleton radio button tags ourselves because it's too much of a pain to do it with CGI.pm |
| 384 | print CGI::Tr( |
414 | print CGI::Tr( |
| 385 | CGI::td({style=>"text-align: right"}, |
415 | CGI::td({style=>"text-align: right"}, |
| 386 | '<input type="radio" name="add_dbLayout" value="' . $dbLayout . '"' |
416 | '<input type="radio" name="add_dbLayout" value="' . $dbLayout . '"' |
| 387 | . ($add_dbLayout eq $dbLayout ? " checked" : "") . ' />', |
417 | . ($add_dbLayout eq $dbLayout ? " checked" : "") . ' />', |
| 388 | ), |
418 | ), |
| 389 | CGI::td($dbLayout), |
419 | CGI::td($dbLayoutLabel), |
| 390 | ); |
420 | ); |
| 391 | |
421 | |
| 392 | print CGI::start_Tr(); |
422 | print CGI::start_Tr(); |
| 393 | print CGI::td(); # for indentation :( |
423 | print CGI::td(); # for indentation :( |
| 394 | print CGI::start_td(); |
424 | print CGI::start_td(); |
| … | |
… | |
| 765 | print CGI::p( |
795 | print CGI::p( |
| 766 | "If the course's database layout (indicated in parentheses above) is " |
796 | "If the course's database layout (indicated in parentheses above) is " |
| 767 | . CGI::b("sql") . ", supply the SQL connections information requested below." |
797 | . CGI::b("sql") . ", supply the SQL connections information requested below." |
| 768 | ); |
798 | ); |
| 769 | |
799 | |
| 770 | print CGI::start_table({class=>"FormLayout"}); |
800 | print CGI::start_table({class=>"FormLayout"}); |
|
|
801 | print CGI::Tr(CGI::td({colspan=>2}, |
|
|
802 | "Enter the user ID and password for an SQL account with sufficient permissions to delete an existing database." |
|
|
803 | ) |
|
|
804 | ); |
| 771 | print CGI::Tr( |
805 | print CGI::Tr( |
| 772 | CGI::th({class=>"LeftHeader"}, "SQL Server Host:"), |
|
|
| 773 | CGI::td( |
|
|
| 774 | CGI::textfield("delete_sql_host", $delete_sql_host, 25), |
|
|
| 775 | CGI::br(), |
|
|
| 776 | CGI::small("Leave blank to use the default host."), |
|
|
| 777 | ), |
|
|
| 778 | ); |
|
|
| 779 | print CGI::Tr( |
|
|
| 780 | CGI::th({class=>"LeftHeader"}, "SQL Server Port:"), |
|
|
| 781 | CGI::td( |
|
|
| 782 | CGI::textfield("delete_sql_port", $delete_sql_port, 25), |
|
|
| 783 | CGI::br(), |
|
|
| 784 | CGI::small("Leave blank to use the default port."), |
|
|
| 785 | ), |
|
|
| 786 | ); |
|
|
| 787 | print CGI::Tr( |
|
|
| 788 | CGI::th({class=>"LeftHeader"}, "SQL Admin Username:"), |
806 | CGI::th({class=>"LeftHeader"}, "SQL Admin Username:"), |
| 789 | CGI::td(CGI::textfield("delete_sql_username", $delete_sql_username, 25)), |
807 | CGI::td(CGI::textfield("delete_sql_username", $delete_sql_username, 25)), |
| 790 | ); |
808 | ); |
| 791 | print CGI::Tr( |
809 | print CGI::Tr( |
| 792 | CGI::th({class=>"LeftHeader"}, "SQL Admin Password:"), |
810 | CGI::th({class=>"LeftHeader"}, "SQL Admin Password:"), |
| 793 | CGI::td(CGI::password_field("delete_sql_password", $delete_sql_password, 25)), |
811 | CGI::td(CGI::password_field("delete_sql_password", $delete_sql_password, 25)), |
| 794 | ); |
812 | ); |
|
|
813 | |
|
|
814 | #print CGI::Tr(CGI::td({colspan=>2}, |
|
|
815 | # "The optionial SQL settings you enter below must match the settings in the DBI source" |
|
|
816 | # . " specification " . CGI::tt($dbi_source) . ". Replace " . CGI::tt("COURSENAME") |
|
|
817 | # . " with the course name you entered above." |
|
|
818 | # ) |
|
|
819 | #); |
| 795 | print CGI::Tr( |
820 | print CGI::Tr( |
|
|
821 | CGI::th({class=>"LeftHeader"}, "SQL Server Host:"), |
|
|
822 | CGI::td( |
|
|
823 | CGI::textfield("delete_sql_host", $delete_sql_host, 25), |
|
|
824 | CGI::br(), |
|
|
825 | CGI::small("Leave blank to use the default host."), |
|
|
826 | ), |
|
|
827 | ); |
|
|
828 | print CGI::Tr( |
|
|
829 | CGI::th({class=>"LeftHeader"}, "SQL Server Port:"), |
|
|
830 | CGI::td( |
|
|
831 | CGI::textfield("delete_sql_port", $delete_sql_port, 25), |
|
|
832 | CGI::br(), |
|
|
833 | CGI::small("Leave blank to use the default port."), |
|
|
834 | ), |
|
|
835 | ); |
|
|
836 | |
|
|
837 | print CGI::Tr( |
| 796 | CGI::th({class=>"LeftHeader"}, "SQL Database Name:"), |
838 | CGI::th({class=>"LeftHeader"}, "SQL Database Name:"), |
| 797 | CGI::td( |
839 | CGI::td( |
| 798 | CGI::textfield("delete_sql_database", $delete_sql_database, 25), |
840 | CGI::textfield("delete_sql_database", $delete_sql_database, 25), |
| 799 | CGI::br(), |
841 | CGI::br(), |
| 800 | CGI::small("Leave blank to use the name ", CGI::tt("webwork_COURSENAME"), "."), |
842 | CGI::small("Leave blank to use the name ", CGI::tt("webwork_COURSENAME"), "."), |
| 801 | ), |
843 | ), |
| 802 | ); |
844 | ); |
| 803 | print CGI::end_table(); |
845 | print CGI::end_table(); |
| 804 | |
846 | |
| 805 | print CGI::p({style=>"text-align: center"}, CGI::submit("delete_course", "Delete Course")); |
847 | print CGI::p({style=>"text-align: center"}, CGI::submit("delete_course", "Delete Course")); |
| 806 | |
848 | |
| 807 | print CGI::end_form(); |
849 | print CGI::end_form(); |
| 808 | } |
850 | } |