[system] / trunk / webwork2 / lib / WeBWorK / ContentGenerator / CourseAdmin.pm Repository:
ViewVC logotype

Diff of /trunk/webwork2/lib/WeBWorK/ContentGenerator/CourseAdmin.pm

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

Revision 3284 Revision 3973
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-2006 The WeBWorK Project, http://openwebwork.sf.net/
4# $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v 1.34 2005/05/20 16:28:25 gage Exp $ 4# $CVSHeader: webwork2/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v 1.42 2005/11/07 21:20:57 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.
23 23
24=cut 24=cut
25 25
26use strict; 26use strict;
27use warnings; 27use warnings;
28use CGI::Pretty qw(); 28use CGI qw();
29use Data::Dumper; 29use Data::Dumper;
30use File::Temp qw/tempfile/; 30use File::Temp qw/tempfile/;
31use WeBWorK::CourseEnvironment; 31use WeBWorK::CourseEnvironment;
32use IO::File; 32use IO::File;
33use WeBWorK::Utils qw(cryptPassword writeLog listFilesRecursive); 33use WeBWorK::Utils qw(cryptPassword writeLog listFilesRecursive);
34use WeBWorK::Utils::CourseManagement qw(addCourse renameCourse deleteCourse listCourses); 34use WeBWorK::Utils::CourseManagement qw(addCourse renameCourse deleteCourse listCourses archiveCourse);
35use WeBWorK::Utils::DBImportExport qw(dbExport dbImport); 35use WeBWorK::Utils::DBImportExport qw(dbExport dbImport);
36 36
37# put the following database layouts at the top of the list, in this order 37# put the following database layouts at the top of the list, in this order
38our @DB_LAYOUT_ORDER = qw/sql_single gdbm sql/; 38our @DB_LAYOUT_ORDER = qw/sql_single gdbm sql/;
39 39
40our %DB_LAYOUT_DESCRIPTIONS = ( 40our %DB_LAYOUT_DESCRIPTIONS = (
41 gdbm => "Deprecated. Uses GDBM databases to record WeBWorK data. Use this layout if the course must be used with WeBWorK 1.x.", 41 gdbm => CGI::i("Deprecated. Uses GDBM databases to record WeBWorK data. Use this layout if the course must be used with WeBWorK 1.x."),
42 sql => "Deprecated. Uses a separate SQL database to record WeBWorK data for each course.", 42 sql => CGI::i("Deprecated. Uses a separate SQL database to record WeBWorK data for each course."),
43 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 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.",
44); 44);
45 45
46sub pre_header_initialize { 46sub pre_header_initialize {
47 my ($self) = @_; 47 my ($self) = @_;
163 } else { 163 } else {
164 $method_to_call = "import_database_form"; 164 $method_to_call = "import_database_form";
165 } 165 }
166 } 166 }
167 167
168 elsif ($subDisplay eq "archive_course") {
169 if (defined $r->param("archive_course")) {
170 # validate or confirm
171 @errors = $self->archive_course_validate;
172 if (@errors) {
173 $method_to_call = "archive_course_form";
174 } else {
175 $method_to_call = "archive_course_confirm";
176 }
177 } elsif (defined $r->param("confirm_archive_course")) {
178 # validate and archive
179 @errors = $self->archive_course_validate;
180 if (@errors) {
181 $method_to_call = "archive_course_form";
182 } else {
183 $method_to_call = "do_archive_course";
184 }
185 } else {
186 # form only
187 $method_to_call = "archive_course_form";
188 }
189 }
190
168 else { 191 else {
169 @errors = "Unrecognized sub-display @{[ CGI::b($subDisplay) ]}."; 192 @errors = "Unrecognized sub-display @{[ CGI::b($subDisplay) ]}.";
170 } 193 }
171 194
172 } 195 }
236 file manager.").CGI::hr(); 259 file manager.").CGI::hr();
237 }; 260 };
238 261
239 262
240 print CGI::p({style=>"text-align: center"}, 263 print CGI::p({style=>"text-align: center"},
241 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"add_course"})}, "Add Course"), 264 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"add_course",add_admin_users=>1,
265 add_dbLayout=>'sql_single',
266 add_templates_course => $ce->{siteDefaults}->{default_templates_course} ||""}
267 )},
268 "Add Course"
269 ),
242 " | ", 270 " | ",
243 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"rename_course"})}, "Rename Course"), 271 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"rename_course"})}, "Rename Course"),
244 " | ", 272 " | ",
245 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"delete_course"})}, "Delete Course"), 273 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"delete_course"})}, "Delete Course"),
246 " | ", 274 " | ",
247 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"export_database"})}, "Export Database"), 275 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"export_database"})}, "Export Database"),
248 " | ", 276 " | ",
249 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"import_database"})}, "Import Database"), 277 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"import_database"})}, "Import Database"),
278 " | ",
279 CGI::a({href=>$self->systemLink($urlpath, params=>{subDisplay=>"archive_course"})}, "Archive Course"),
250 CGI::hr(), 280 CGI::hr(),
251 $methodMessage, 281 $methodMessage,
252 282
253 ); 283 );
254 284
267 ); 297 );
268 } 298 }
269 299
270 if (defined $method_to_call and $method_to_call ne "") { 300 if (defined $method_to_call and $method_to_call ne "") {
271 $self->$method_to_call; 301 $self->$method_to_call;
302 } else {
303
304 print CGI::h2("Courses");
305
306 print CGI::start_ol();
307
308 my @courseIDs = listCourses($ce);
309 foreach my $courseID (sort {lc($a) cmp lc($b) } @courseIDs) {
310 next if $courseID eq "admin"; # done already above
311 my $urlpath = $r->urlpath->newFromModule("WeBWorK::ContentGenerator::ProblemSets", courseID => $courseID);
312 my $tempCE = WeBWorK::CourseEnvironment->new(
313 $ce->{webworkDirs}->{root},
314 $ce->{webworkURLs}->{root},
315 $ce->{pg}->{directories}->{root},
316 $courseID,
317 );
318 print CGI::li(CGI::a({href=>$self->systemLink($urlpath, authen => 0)}, $courseID),
319 CGI::code(
320 $tempCE->{dbLayoutName},
321 ),
322 (-r $tempCE->{courseFiles}->{environment}) ? "" : CGI::i(", missing course.conf"),
323
324 );
325
272 } 326 }
273 327
328 print CGI::end_ol();
329 }
274 return ""; 330 return "";
275} 331}
276 332
277################################################################################ 333################################################################################
278 334
351 } 407 }
352 $source; 408 $source;
353 }; 409 };
354 410
355 my @existingCourses = listCourses($ce); 411 my @existingCourses = listCourses($ce);
356 @existingCourses = sort @existingCourses; 412 @existingCourses = sort { lc($a) cmp lc ($b) } @existingCourses; #make sort case insensitive
357 413
358 print CGI::h2("Add Course"); 414 print CGI::h2("Add Course");
359 415
360 print CGI::start_form("POST", $r->uri); 416 print CGI::start_form("POST", $r->uri);
361 print $self->hidden_authen_fields; 417 print $self->hidden_authen_fields;
377 CGI::td(CGI::textfield("add_courseInstitution", $add_courseInstitution, 25)), 433 CGI::td(CGI::textfield("add_courseInstitution", $add_courseInstitution, 25)),
378 ), 434 ),
379 ); 435 );
380 436
381 print CGI::p("To add the WeBWorK administrators to the new course (as instructors) check the box below."); 437 print CGI::p("To add the WeBWorK administrators to the new course (as instructors) check the box below.");
382 438 my $checked = ($add_admin_users) ?"checked": ""; # workaround because CGI::checkbox seems to have a bug -- it won't default to checked.
383 print CGI::p(CGI::checkbox("add_admin_users", $add_admin_users, "on", "Add WeBWorK administrators to new course")); 439 print CGI::p(CGI::input({-type=>'checkbox', -name=>"add_admin_users", $checked=>'' }, "Add WeBWorK administrators to new course"));
384 440
385 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."); 441 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.");
386 442
387 print CGI::table({class=>"FormLayout"}, CGI::Tr( 443 print CGI::table({class=>"FormLayout"}, CGI::Tr(
388 CGI::td( 444 CGI::td(
459 515
460 print CGI::start_Tr(); 516 print CGI::start_Tr();
461 print CGI::td(); # for indentation :( 517 print CGI::td(); # for indentation :(
462 print CGI::start_td(); 518 print CGI::start_td();
463 519
520
464 if ($dbLayout eq "sql") { 521 if ($dbLayout eq "sql") {
522
523 print CGI::p({style=>'font-style:italic'},"The following information is only required for the deprecated sql database format:");
465 print CGI::start_table({class=>"FormLayout"}); 524 print CGI::start_table({class=>"FormLayout"});
466 print CGI::Tr(CGI::td({colspan=>2}, 525 print CGI::Tr(CGI::td({colspan=>2},
467 "Enter the user ID and password for an SQL account with sufficient permissions to create a new database." 526 "Enter the user ID and password for an SQL account with sufficient permissions to create a new database."
468 ) 527 )
469 ); 528 );
515 CGI::small("If the SQL server does not run on the same host as WeBWorK, enter the host name of the WeBWorK server as seen by the SQL server."), 574 CGI::small("If the SQL server does not run on the same host as WeBWorK, enter the host name of the WeBWorK server as seen by the SQL server."),
516 ), 575 ),
517 ); 576 );
518 print CGI::end_table(); 577 print CGI::end_table();
519 } elsif ($dbLayout eq "gdbm") { 578 } elsif ($dbLayout eq "gdbm") {
579 print CGI::p({style=>"font-style: italic"},"The following information is only required for the deprecated gdbm database format:");
520 print CGI::start_table({class=>"FormLayout"}); 580 print CGI::start_table({class=>"FormLayout"});
521 print CGI::Tr( 581 print CGI::Tr(
522 CGI::th({class=>"LeftHeader"}, "GDBM Global User ID:"), 582 CGI::th({class=>"LeftHeader"}, "GDBM Global User ID:"),
523 CGI::td(CGI::textfield("add_gdbm_globalUserID", $add_gdbm_globalUserID || "global_user", 25)), 583 CGI::td(CGI::textfield("add_gdbm_globalUserID", $add_gdbm_globalUserID || "global_user", 25)),
524 ); 584 );
804 my $rename_sql_oldDatabase = $r->param("rename_sql_oldDatabase") || ""; 864 my $rename_sql_oldDatabase = $r->param("rename_sql_oldDatabase") || "";
805 my $rename_sql_newDatabase = $r->param("rename_sql_newDatabase") || ""; 865 my $rename_sql_newDatabase = $r->param("rename_sql_newDatabase") || "";
806 my $rename_sql_wwhost = $r->param("rename_sql_wwhost") || ""; 866 my $rename_sql_wwhost = $r->param("rename_sql_wwhost") || "";
807 867
808 my @courseIDs = listCourses($ce); 868 my @courseIDs = listCourses($ce);
809 @courseIDs = sort @courseIDs; 869 @courseIDs = sort {lc($a) cmp lc ($b) } @courseIDs;
810 870
811 my %courseLabels; # records... heh. 871 my %courseLabels; # records... heh.
812 foreach my $courseID (@courseIDs) { 872 foreach my $courseID (@courseIDs) {
813 my $tempCE = WeBWorK::CourseEnvironment->new( 873 my $tempCE = WeBWorK::CourseEnvironment->new(
814 $ce->{webworkDirs}->{root}, 874 $ce->{webworkDirs}->{root},
1050 my $delete_sql_username = $r->param("delete_sql_username") || ""; 1110 my $delete_sql_username = $r->param("delete_sql_username") || "";
1051 my $delete_sql_password = $r->param("delete_sql_password") || ""; 1111 my $delete_sql_password = $r->param("delete_sql_password") || "";
1052 my $delete_sql_database = $r->param("delete_sql_database") || ""; 1112 my $delete_sql_database = $r->param("delete_sql_database") || "";
1053 1113
1054 my @courseIDs = listCourses($ce); 1114 my @courseIDs = listCourses($ce);
1055 @courseIDs = sort @courseIDs; 1115 @courseIDs = sort {lc($a) cmp lc ($b) } @courseIDs; #make sort case insensitive
1056 1116
1057 my %courseLabels; # records... heh. 1117 my %courseLabels; # records... heh.
1058 foreach my $courseID (@courseIDs) { 1118 foreach my $courseID (@courseIDs) {
1059 my $tempCE = WeBWorK::CourseEnvironment->new( 1119 my $tempCE = WeBWorK::CourseEnvironment->new(
1060 $ce->{webworkDirs}->{root}, 1120 $ce->{webworkDirs}->{root},
1326 my @export_tables = $r->param("export_tables"); 1386 my @export_tables = $r->param("export_tables");
1327 1387
1328 @export_tables = @tables unless @export_tables; 1388 @export_tables = @tables unless @export_tables;
1329 1389
1330 my @courseIDs = listCourses($ce); 1390 my @courseIDs = listCourses($ce);
1331 @courseIDs = sort @courseIDs; 1391 @courseIDs = sort {lc($a) cmp lc ($b) } @courseIDs; #make sort case insensitive
1332 1392
1333 my %courseLabels; # records... heh. 1393 my %courseLabels; # records... heh.
1334 foreach my $courseID (@courseIDs) { 1394 foreach my $courseID (@courseIDs) {
1335 my $tempCE = WeBWorK::CourseEnvironment->new( 1395 my $tempCE = WeBWorK::CourseEnvironment->new(
1336 $ce->{webworkDirs}->{root}, 1396 $ce->{webworkDirs}->{root},
1510 my $import_conflict = $r->param("import_conflict") || "skip"; 1570 my $import_conflict = $r->param("import_conflict") || "skip";
1511 1571
1512 @import_tables = @tables unless @import_tables; 1572 @import_tables = @tables unless @import_tables;
1513 1573
1514 my @courseIDs = listCourses($ce); 1574 my @courseIDs = listCourses($ce);
1515 @courseIDs = sort @courseIDs; 1575 @courseIDs = sort {lc($a) cmp lc ($b) } @courseIDs; #make sort case insensitive
1516 1576
1517 1577
1518 my %courseLabels; # records... heh. 1578 my %courseLabels; # records... heh.
1519 foreach my $courseID (@courseIDs) { 1579 foreach my $courseID (@courseIDs) {
1520 my $tempCE = WeBWorK::CourseEnvironment->new( 1580 my $tempCE = WeBWorK::CourseEnvironment->new(
1708 print CGI::div({class=>"ResultsWithoutError"}, 1768 print CGI::div({class=>"ResultsWithoutError"},
1709 CGI::p("Import succeeded."), 1769 CGI::p("Import succeeded."),
1710 ); 1770 );
1711 } 1771 }
1712} 1772}
1773##########################################################################
1774sub archive_course_form {
1775 my ($self) = @_;
1776 my $r = $self->r;
1777 my $ce = $r->ce;
1778 #my $db = $r->db;
1779 #my $authz = $r->authz;
1780 #my $urlpath = $r->urlpath;
1781
1782 my $archive_courseID = $r->param("archive_courseID") || "";
1783 my $archive_sql_host = $r->param("archive_sql_host") || "";
1784 my $archive_sql_port = $r->param("archive_sql_port") || "";
1785 my $archive_sql_username = $r->param("archive_sql_username") || "";
1786 my $archive_sql_password = $r->param("archive_sql_password") || "";
1787 my $archive_sql_database = $r->param("archive_sql_database") || "";
1788
1789 my @courseIDs = listCourses($ce);
1790 @courseIDs = sort {lc($a) cmp lc ($b) } @courseIDs; #make sort case insensitive
1791
1792 my %courseLabels; # records... heh.
1793 foreach my $courseID (@courseIDs) {
1794 my $tempCE = WeBWorK::CourseEnvironment->new(
1795 $ce->{webworkDirs}->{root},
1796 $ce->{webworkURLs}->{root},
1797 $ce->{pg}->{directories}->{root},
1798 $courseID,
1799 );
1800 $courseLabels{$courseID} = "$courseID (" . $tempCE->{dbLayoutName} . ")";
1801 }
1802
1803 print CGI::h2("archive Course");
1804
1805 print CGI::start_form("POST", $r->uri);
1806 print $self->hidden_authen_fields;
1807 print $self->hidden_fields("subDisplay");
1808
1809 print CGI::p("Select a course to archive.");
1810
1811 print CGI::table({class=>"FormLayout"},
1812 CGI::Tr(
1813 CGI::th({class=>"LeftHeader"}, "Course Name:"),
1814 CGI::td(
1815 CGI::scrolling_list(
1816 -name => "archive_courseID",
1817 -values => \@courseIDs,
1818 -default => $archive_courseID,
1819 -size => 10,
1820 -multiple => 0,
1821 -labels => \%courseLabels,
1822 ),
1823 ),
1824 ),
1825 );
1826
1827 print CGI::p(
1828 "Currently the archive facility is only available for mysql databases.
1829 It depends on the mysqldump application."
1830 );
1831# print CGI::p(
1832# "If the course's database layout (indicated in parentheses above) is "
1833# . CGI::b("sql") . ", supply the SQL connections information requested below."
1834# );
1835
1836# print CGI::start_table({class=>"FormLayout"});
1837# print CGI::Tr(CGI::td({colspan=>2},
1838# "Enter the user ID and password for an SQL account with sufficient permissions to archive an existing database."
1839# )
1840# );
1841# print CGI::Tr(
1842# CGI::th({class=>"LeftHeader"}, "SQL Admin Username:"),
1843# CGI::td(CGI::textfield("archive_sql_username", $archive_sql_username, 25)),
1844# );
1845# print CGI::Tr(
1846# CGI::th({class=>"LeftHeader"}, "SQL Admin Password:"),
1847# CGI::td(CGI::password_field("archive_sql_password", $archive_sql_password, 25)),
1848# );
1849#
1850# #print CGI::Tr(CGI::td({colspan=>2},
1851# # "The optionial SQL settings you enter below must match the settings in the DBI source"
1852# # . " specification " . CGI::tt($dbi_source) . ". Replace " . CGI::tt("COURSENAME")
1853# # . " with the course name you entered above."
1854# # )
1855# #);
1856# print CGI::Tr(
1857# CGI::th({class=>"LeftHeader"}, "SQL Server Host:"),
1858# CGI::td(
1859# CGI::textfield("archive_sql_host", $archive_sql_host, 25),
1860# CGI::br(),
1861# CGI::small("Leave blank to use the default host."),
1862# ),
1863# );
1864# print CGI::Tr(
1865# CGI::th({class=>"LeftHeader"}, "SQL Server Port:"),
1866# CGI::td(
1867# CGI::textfield("archive_sql_port", $archive_sql_port, 25),
1868# CGI::br(),
1869# CGI::small("Leave blank to use the default port."),
1870# ),
1871# );
1872#
1873# print CGI::Tr(
1874# CGI::th({class=>"LeftHeader"}, "SQL Database Name:"),
1875# CGI::td(
1876# CGI::textfield("archive_sql_database", $archive_sql_database, 25),
1877# CGI::br(),
1878# CGI::small("Leave blank to use the name ", CGI::tt("webwork_COURSENAME"), "."),
1879# ),
1880# );
1881# print CGI::end_table();
1882
1883 print CGI::p({style=>"text-align: center"}, CGI::submit("archive_course", "archive Course"));
1884
1885 print CGI::end_form();
1886}
1713 1887
1888sub archive_course_validate {
1889 my ($self) = @_;
1890 my $r = $self->r;
1891 my $ce = $r->ce;
1892 #my $db = $r->db;
1893 #my $authz = $r->authz;
1894 my $urlpath = $r->urlpath;
1895
1896 my $archive_courseID = $r->param("archive_courseID") || "";
1897 my $archive_sql_host = $r->param("archive_sql_host") || "";
1898 my $archive_sql_port = $r->param("archive_sql_port") || "";
1899 my $archive_sql_username = $r->param("archive_sql_username") || "";
1900 my $archive_sql_password = $r->param("archive_sql_password") || "";
1901 my $archive_sql_database = $r->param("archive_sql_database") || "";
1902
1903 my @errors;
1904
1905 if ($archive_courseID eq "") {
1906 push @errors, "You must specify a course name.";
1907 } elsif ($archive_courseID eq $urlpath->arg("courseID")) {
1908 push @errors, "You cannot archive the course you are currently using.";
1909 }
1910
1911 my $ce2 = WeBWorK::CourseEnvironment->new(
1912 $ce->{webworkDirs}->{root},
1913 $ce->{webworkURLs}->{root},
1914 $ce->{pg}->{directories}->{root},
1915 $archive_courseID,
1916 );
1917
1918 if ($ce2->{dbLayoutName} eq "sql") {
1919 push @errors, "You must specify the SQL admin username." if $archive_sql_username eq "";
1920 #push @errors, "You must specify the SQL admin password." if $archive_sql_password eq "";
1921 #push @errors, "You must specify the SQL database name." if $archive_sql_database eq "";
1922 }
1923
1924 return @errors;
1925}
1926
1927sub archive_course_confirm {
1928 my ($self) = @_;
1929 my $r = $self->r;
1930 my $ce = $r->ce;
1931 #my $db = $r->db;
1932 #my $authz = $r->authz;
1933 #my $urlpath = $r->urlpath;
1934
1935 print CGI::h2("archive Course");
1936
1937 my $archive_courseID = $r->param("archive_courseID") || "";
1938 my $archive_sql_host = $r->param("archive_sql_host") || "";
1939 my $archive_sql_port = $r->param("archive_sql_port") || "";
1940 my $archive_sql_database = $r->param("archive_sql_database") || "";
1941
1942 my $ce2 = WeBWorK::CourseEnvironment->new(
1943 $ce->{webworkDirs}->{root},
1944 $ce->{webworkURLs}->{root},
1945 $ce->{pg}->{directories}->{root},
1946 $archive_courseID,
1947 );
1948
1949 if ($ce2->{dbLayoutName} eq "sql") {
1950 print CGI::p("Are you sure you want to archive the course " . CGI::b($archive_courseID)
1951 . "? ");
1952
1953 print CGI::table({class=>"FormLayout"},
1954 CGI::Tr(
1955 CGI::th({class=>"LeftHeader"}, "SQL Server Host:"),
1956 CGI::td($archive_sql_host || "system default"),
1957 ),
1958 CGI::Tr(
1959 CGI::th({class=>"LeftHeader"}, "SQL Server Port:"),
1960 CGI::td($archive_sql_port || "system default"),
1961 ),
1962 CGI::Tr(
1963 CGI::th({class=>"LeftHeader"}, "SQL Database Name:"),
1964 CGI::td($archive_sql_database || "webwork_$archive_courseID"),
1965 ),
1966 );
1967 } else {
1968 print CGI::p("Are you sure you want to archive the course " . CGI::b($archive_courseID)
1969 . "? All course files and data will be destroyed. There is no undo available.");
1970 }
1971
1972 print CGI::start_form("POST", $r->uri);
1973 print $self->hidden_authen_fields;
1974 print $self->hidden_fields("subDisplay");
1975 print $self->hidden_fields(qw/archive_courseID archive_sql_host archive_sql_port archive_sql_username archive_sql_password archive_sql_database/);
1976
1977 print CGI::p({style=>"text-align: center"},
1978 CGI::submit("decline_archive_course", "Don't archive"),
1979 " ",
1980 CGI::submit("confirm_archive_course", "archive"),
1981 );
1982
1983 print CGI::end_form();
1984}
1985
1986sub do_archive_course {
1987 my ($self) = @_;
1988 my $r = $self->r;
1989 my $ce = $r->ce;
1990 #my $db = $r->db;
1991 #my $authz = $r->authz;
1992 #my $urlpath = $r->urlpath;
1993
1994 my $archive_courseID = $r->param("archive_courseID") || "";
1995 my $archive_sql_host = $r->param("archive_sql_host") || "";
1996 my $archive_sql_port = $r->param("archive_sql_port") || "";
1997 my $archive_sql_username = $r->param("archive_sql_username") || "";
1998 my $archive_sql_password = $r->param("archive_sql_password") || "";
1999 my $archive_sql_database = $r->param("archive_sql_database") || "";
2000
2001 my $ce2 = WeBWorK::CourseEnvironment->new(
2002 $ce->{webworkDirs}->{root},
2003 $ce->{webworkURLs}->{root},
2004 $ce->{pg}->{directories}->{root},
2005 $archive_courseID,
2006 );
2007
2008 my %dbOptions;
2009 if ($ce2->{dbLayoutName} eq "sql") {
2010 $dbOptions{host} = $archive_sql_host if $archive_sql_host ne "";
2011 $dbOptions{port} = $archive_sql_port if $archive_sql_port ne "";
2012 $dbOptions{username} = $archive_sql_username;
2013 $dbOptions{password} = $archive_sql_password;
2014 $dbOptions{database} = $archive_sql_database || "webwork_$archive_courseID";
2015 }
2016
2017 eval {
2018 archiveCourse(
2019 courseID => $archive_courseID,
2020 ce => $ce2,
2021 dbOptions => \%dbOptions,
2022 );
2023 };
2024
2025 if ($@) {
2026 my $error = $@;
2027 print CGI::div({class=>"ResultsWithError"},
2028 CGI::p("An error occured while archiving the course $archive_courseID:"),
2029 CGI::tt(CGI::escapeHTML($error)),
2030 );
2031 } else {
2032 print CGI::div({class=>"ResultsWithoutError"},
2033 CGI::p("Successfully archived the course $archive_courseID"),
2034 );
2035 writeLog($ce, "hosted_courses", join("\t",
2036 "\tarchived",
2037 "",
2038 "",
2039 $archive_courseID,
2040 ));
2041 print CGI::start_form("POST", $r->uri);
2042 print $self->hidden_authen_fields;
2043 print $self->hidden_fields("subDisplay");
2044
2045 print CGI::p({style=>"text-align: center"}, CGI::submit("decline_archive_course", "OK"),);
2046
2047 print CGI::end_form();
2048 }
2049}
2050
2051################################################################################
17141; 20521;

Legend:
Removed from v.3284  
changed lines
  Added in v.3973

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9