| 1 | ################################################################################ |
1 | ################################################################################ |
| 2 | # WeBWorK Online Homework Delivery System |
2 | # WeBWorK Online Homework Delivery System |
| 3 | # Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/ |
3 | # Copyright © 2000-2006 The WeBWorK Project, http://openwebwork.sf.net/ |
| 4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v 1.45 2006/06/10 14:18:56 gage Exp $ |
4 | # $CVSHeader: webwork-modperl/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v 1.46 2006/06/15 14:48:19 gage 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. |
| … | |
… | |
| 1800 | -size => 10, |
1800 | -size => 10, |
| 1801 | -multiple => 0, |
1801 | -multiple => 0, |
| 1802 | -labels => \%courseLabels, |
1802 | -labels => \%courseLabels, |
| 1803 | ), |
1803 | ), |
| 1804 | ), |
1804 | ), |
|
|
1805 | |
|
|
1806 | ), |
|
|
1807 | CGI::Tr( |
|
|
1808 | CGI::th({class=>"LeftHeader"}, "Delete course:"), |
|
|
1809 | CGI::td({-style=>'color:red'}, CGI::checkbox({ |
|
|
1810 | -name=>'delete_course', |
|
|
1811 | -checked=>0, |
|
|
1812 | -value => 1, |
|
|
1813 | -label =>'Delete course after archiving. Caution there is no undo!', |
|
|
1814 | }, |
|
|
1815 | ), |
| 1805 | ), |
1816 | ), |
|
|
1817 | ) |
| 1806 | ); |
1818 | ); |
| 1807 | |
1819 | |
| 1808 | print CGI::p( |
1820 | print CGI::p( |
| 1809 | "Currently the archive facility is only available for mysql databases. |
1821 | "Currently the archive facility is only available for mysql databases. |
| 1810 | It depends on the mysqldump application." |
1822 | It depends on the mysqldump application." |
| … | |
… | |
| 1867 | |
1879 | |
| 1868 | my $archive_courseID = $r->param("archive_courseID") || ""; |
1880 | my $archive_courseID = $r->param("archive_courseID") || ""; |
| 1869 | my $archive_sql_host = $r->param("archive_sql_host") || ""; |
1881 | my $archive_sql_host = $r->param("archive_sql_host") || ""; |
| 1870 | my $archive_sql_port = $r->param("archive_sql_port") || ""; |
1882 | my $archive_sql_port = $r->param("archive_sql_port") || ""; |
| 1871 | my $archive_sql_database = $r->param("archive_sql_database") || ""; |
1883 | my $archive_sql_database = $r->param("archive_sql_database") || ""; |
| 1872 | |
1884 | my $delete_course_flag = $r->param("delete_course") || ""; |
| 1873 | my $ce2 = WeBWorK::CourseEnvironment->new( |
1885 | my $ce2 = WeBWorK::CourseEnvironment->new( |
| 1874 | $ce->{webworkDirs}->{root}, |
1886 | $ce->{webworkDirs}->{root}, |
| 1875 | $ce->{webworkURLs}->{root}, |
1887 | $ce->{webworkURLs}->{root}, |
| 1876 | $ce->{pg}->{directories}->{root}, |
1888 | $ce->{pg}->{directories}->{root}, |
| 1877 | $archive_courseID, |
1889 | $archive_courseID, |
| 1878 | ); |
1890 | ); |
| 1879 | |
1891 | |
| 1880 | if ($ce2->{dbLayoutName} eq "sql") { |
1892 | if ($ce2->{dbLayoutName} ) { |
| 1881 | print CGI::p("Are you sure you want to archive the course " . CGI::b($archive_courseID) |
1893 | print CGI::p("Are you sure you want to archive the course " . CGI::b($archive_courseID) |
| 1882 | . "? "); |
1894 | . "? "); |
|
|
1895 | print(CGI::p({-style=>'color:red; font-weight:bold'}, "Are you sure that you want to delete the course ". |
|
|
1896 | CGI::b($archive_courseID). " after archiving? This cannot be undone!")) if $delete_course_flag; |
| 1883 | |
1897 | |
| 1884 | print CGI::table({class=>"FormLayout"}, |
1898 | |
| 1885 | CGI::Tr( |
|
|
| 1886 | CGI::th({class=>"LeftHeader"}, "SQL Server Host:"), |
|
|
| 1887 | CGI::td($archive_sql_host || "system default"), |
|
|
| 1888 | ), |
|
|
| 1889 | CGI::Tr( |
|
|
| 1890 | CGI::th({class=>"LeftHeader"}, "SQL Server Port:"), |
|
|
| 1891 | CGI::td($archive_sql_port || "system default"), |
|
|
| 1892 | ), |
|
|
| 1893 | CGI::Tr( |
|
|
| 1894 | CGI::th({class=>"LeftHeader"}, "SQL Database Name:"), |
|
|
| 1895 | CGI::td($archive_sql_database || "webwork_$archive_courseID"), |
|
|
| 1896 | ), |
|
|
| 1897 | ); |
|
|
| 1898 | } else { |
|
|
| 1899 | print CGI::p("Are you sure you want to archive the course " . CGI::b($archive_courseID) |
|
|
| 1900 | . "? All course files and data will be destroyed. There is no undo available."); |
|
|
| 1901 | } |
1899 | } |
| 1902 | |
1900 | |
| 1903 | print CGI::start_form("POST", $r->uri); |
1901 | print CGI::start_form("POST", $r->uri); |
| 1904 | print $self->hidden_authen_fields; |
1902 | print $self->hidden_authen_fields; |
| 1905 | print $self->hidden_fields("subDisplay"); |
1903 | print $self->hidden_fields("subDisplay"); |
| 1906 | print $self->hidden_fields(qw/archive_courseID archive_sql_host archive_sql_port archive_sql_username archive_sql_password archive_sql_database/); |
1904 | print $self->hidden_fields(qw/archive_courseID archive_sql_host archive_sql_port archive_sql_username archive_sql_password archive_sql_database delete_course/); |
| 1907 | |
1905 | |
| 1908 | print CGI::p({style=>"text-align: center"}, |
1906 | print CGI::p({style=>"text-align: center"}, |
| 1909 | CGI::submit("decline_archive_course", "Don't archive"), |
1907 | CGI::submit("decline_archive_course", "Don't archive"), |
| 1910 | " ", |
1908 | " ", |
| 1911 | CGI::submit("confirm_archive_course", "archive"), |
1909 | CGI::submit("confirm_archive_course", "archive"), |
| … | |
… | |
| 1916 | |
1914 | |
| 1917 | sub do_archive_course { |
1915 | sub do_archive_course { |
| 1918 | my ($self) = @_; |
1916 | my ($self) = @_; |
| 1919 | my $r = $self->r; |
1917 | my $r = $self->r; |
| 1920 | my $ce = $r->ce; |
1918 | my $ce = $r->ce; |
| 1921 | #my $db = $r->db; |
1919 | my $db = $r->db; |
| 1922 | #my $authz = $r->authz; |
1920 | #my $authz = $r->authz; |
| 1923 | #my $urlpath = $r->urlpath; |
1921 | #my $urlpath = $r->urlpath; |
| 1924 | |
1922 | |
| 1925 | my $archive_courseID = $r->param("archive_courseID") || ""; |
1923 | my $archive_courseID = $r->param("archive_courseID") || ""; |
| 1926 | my $archive_sql_host = $r->param("archive_sql_host") || ""; |
1924 | my $archive_sql_host = $r->param("archive_sql_host") || ""; |
| 1927 | my $archive_sql_port = $r->param("archive_sql_port") || ""; |
1925 | my $archive_sql_port = $r->param("archive_sql_port") || ""; |
| 1928 | my $archive_sql_username = $r->param("archive_sql_username") || ""; |
1926 | my $archive_sql_username = $r->param("archive_sql_username") || ""; |
| 1929 | my $archive_sql_password = $r->param("archive_sql_password") || ""; |
1927 | my $archive_sql_password = $r->param("archive_sql_password") || ""; |
| 1930 | my $archive_sql_database = $r->param("archive_sql_database") || ""; |
1928 | my $archive_sql_database = $r->param("archive_sql_database") || ""; |
|
|
1929 | my $delete_course_flag = $r->param("delete_course") || ""; |
| 1931 | |
1930 | |
| 1932 | my $ce2 = WeBWorK::CourseEnvironment->new( |
1931 | my $ce2 = WeBWorK::CourseEnvironment->new( |
| 1933 | $ce->{webworkDirs}->{root}, |
1932 | $ce->{webworkDirs}->{root}, |
| 1934 | $ce->{webworkURLs}->{root}, |
1933 | $ce->{webworkURLs}->{root}, |
| 1935 | $ce->{pg}->{directories}->{root}, |
1934 | $ce->{pg}->{directories}->{root}, |
| … | |
… | |
| 1967 | "\tarchived", |
1966 | "\tarchived", |
| 1968 | "", |
1967 | "", |
| 1969 | "", |
1968 | "", |
| 1970 | $archive_courseID, |
1969 | $archive_courseID, |
| 1971 | )); |
1970 | )); |
|
|
1971 | |
|
|
1972 | if ($delete_course_flag) { |
|
|
1973 | eval { |
|
|
1974 | deleteCourse( |
|
|
1975 | courseID => $archive_courseID, |
|
|
1976 | ce => $ce2, |
|
|
1977 | dbOptions => \%dbOptions, |
|
|
1978 | ); |
|
|
1979 | }; |
|
|
1980 | |
|
|
1981 | if ($@) { |
|
|
1982 | my $error = $@; |
|
|
1983 | print CGI::div({class=>"ResultsWithError"}, |
|
|
1984 | CGI::p("An error occured while deleting the course $archive_courseID:"), |
|
|
1985 | CGI::tt(CGI::escapeHTML($error)), |
|
|
1986 | ); |
|
|
1987 | } else { |
|
|
1988 | # mark the contact person in the admin course as dropped. |
|
|
1989 | # find the contact person for the course by searching the admin classlist. |
|
|
1990 | my @contacts = grep /_$archive_courseID$/, $db->listUsers; |
|
|
1991 | die "Incorrect number of contacts for the course $archive_courseID". join(" ", @contacts) if @contacts !=1; |
|
|
1992 | #warn "contacts", join(" ", @contacts); |
|
|
1993 | #my $composite_id = "${add_initial_userID}_${add_courseID}"; |
|
|
1994 | my $composite_id = $contacts[0]; |
|
|
1995 | |
|
|
1996 | # mark the contact person as dropped. |
|
|
1997 | my $User = $db->getUser($composite_id); |
|
|
1998 | my $status_name = 'Drop'; |
|
|
1999 | my $status_value = ($ce->status_name_to_abbrevs($status_name))[0]; |
|
|
2000 | $User->status($status_value); |
|
|
2001 | $db->putUser($User); |
|
|
2002 | |
|
|
2003 | print CGI::div({class=>"ResultsWithoutError"}, |
|
|
2004 | CGI::p("Successfully deleted the course $archive_courseID."), |
|
|
2005 | ); |
|
|
2006 | } |
|
|
2007 | |
|
|
2008 | |
|
|
2009 | } |
|
|
2010 | |
| 1972 | # print CGI::start_form("POST", $r->uri); |
2011 | # print CGI::start_form("POST", $r->uri); |
| 1973 | # print $self->hidden_authen_fields; |
2012 | # print $self->hidden_authen_fields; |
| 1974 | # print $self->hidden_fields("subDisplay"); |
2013 | # print $self->hidden_fields("subDisplay"); |
| 1975 | # |
2014 | # |
| 1976 | # print CGI::p({style=>"text-align: center"}, CGI::submit("decline_archive_course", "OK"),); |
2015 | # print CGI::p({style=>"text-align: center"}, CGI::submit("decline_archive_course", "OK"),); |