--- loncom/interface/Attic/londropadd.pm 2001/02/14 22:51:48 1.12
+++ loncom/interface/Attic/londropadd.pm 2003/11/06 20:04:06 1.88
@@ -1,322 +1,403 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# (Handler to set parameters for assessments
+# $Id: londropadd.pm,v 1.88 2003/11/06 20:04:06 matthew Exp $
#
-# (Handler to resolve ambiguous file locations
+# Copyright Michigan State University Board of Trustees
#
-# (TeX Content Handler
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
+#
+# LON-CAPA is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# LON-CAPA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
+# /home/httpd/html/adm/gpl.txt
#
-# 10/11,10/12,10/16 Gerd Kortemeyer)
+# http://www.lon-capa.org/
#
-# 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28,
-# 12/08,12/12 Gerd Kortemeyer)
+# (Handler to set parameters for assessments
+#
+# (Handler to resolve ambiguous file locations
+#
+# (TeX Content Handler
#
-# 12/26,12/27,12/28,
-# 01/01/01,01/15,02/10,02/13,02/14 Gerd Kortemeyer
+###############################################################
+##############################################################
package Apache::londropadd;
use strict;
-use Apache::lonnet;
+use Apache::lonnet();
+use Apache::loncommon();
+use Apache::lonhtmlcommon();
use Apache::Constants qw(:common :http REDIRECT);
+use Spreadsheet::WriteExcel;
+use Apache::lonlocal;
-# ================================================================ Print header
-
+###############################################################
+###############################################################
sub header {
- my $r=shift;
- $r->print(<
-LON-CAPA Student Drop/Add
+$title
-
-
-
Full update
(also print list of users not enrolled anymore)
-
-Note: for large courses, this operation might be time consuming.
+
ID/Student Number
+
+Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
+(only do if you know what you are doing)
+
+Note: for large courses, this operation may be time consuming.
ENDPICK
}
-# ======================================================= Enroll single student
+# ======================================================= Menu Phase Two Upload
+sub print_upload_manager_form {
+ my $r=shift;
+ my $firstLine;
+ my $datatoken;
+ if (!$ENV{'form.datatoken'}) {
+ $datatoken=&Apache::loncommon::upfile_store($r);
+ } else {
+ $datatoken=$ENV{'form.datatoken'};
+ &Apache::loncommon::load_tmp_file($r);
+ }
+ my @records=&Apache::loncommon::upfile_record_sep();
+ if($ENV{'form.noFirstLine'}){$firstLine=shift(@records);}
+ my $total=$#records;
+ my $distotal=$total+1;
+ my $today=time;
+ my $halfyear=$today+15552000;
+ my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+ my ($krbdef,$krbdefdom) =
+ &Apache::loncommon::get_kerberos_defaults($defdom);
+ &print_upload_manager_header($r,$datatoken,$distotal,$krbdefdom);
+ my $i;
+ my $keyfields;
+ if ($total>=0) {
+ my @d=(['username','Username'],
+ ['names','Last Name, First Names'],
+ ['fname','First Name'],
+ ['mname','Middle Names/Initials'],
+ ['lname','Last Name'],
+ ['gen','Generation'],
+ ['id','ID/Student Number'],
+ ['sec','Group/Section'],
+ ['ipwd','Initial Password'],
+ ['email','EMail Address']);
+ if ($ENV{'form.upfile_associate'} eq 'reverse') {
+ &Apache::loncommon::csv_print_samples($r,\@records);
+ $i=&Apache::loncommon::csv_print_select_table($r,\@records,\@d);
+ foreach (@d) { $keyfields.=$_->[0].','; }
+ chop($keyfields);
+ } else {
+ unshift(@d,['none','']);
+ $i=&Apache::loncommon::csv_samples_select_table($r,\@records,\@d);
+ my %sone=&Apache::loncommon::record_sep($records[0]);
+ $keyfields=join(',',sort(keys(%sone)));
+ }
+ }
+ &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear);
+}
+# ======================================================= Enroll single student
sub enroll_single_student {
my $r=shift;
+ # Remove non alphanumeric values from section
+ $ENV{'form.csec'}=~s/\W//g;
+ #
+ # We do the dates first because the action of making them the defaul
+ # in the course is entirely seperate from the action of enrolling the
+ # student. Also, a failure in setting the dates as default is not fatal
+ # to the process of enrolling / modifying a student.
+ my ($startdate,$enddate) = &get_dates_from_form();
+ if ($ENV{'form.makedatesdefault'}) {
+ $r->print(&make_dates_default($startdate,$enddate));
+ }
+
$r->print('
");
+ #
+ my $username = $ENV{'form.cuname'};
+ my $domain = $ENV{'form.cudomain'};
+ my $home = &Apache::lonnet::homeserver($username,$domain);
+ # $new_user flags whether we are creating a new user or using an old one
+ my $new_user = 1;
+ if ($home ne 'no_host') {
+ $new_user = 0;
+ }
+ #
+ my $user_data_html = '';
+ my $javascript_validations = '';
+ if ($new_user) {
+ my $defdom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
+ # Set up authentication forms
+ my ($krbdef,$krbdefdom) =
+ &Apache::loncommon::get_kerberos_defaults($domain);
+ $javascript_validations=&javascript_validations($krbdefdom);
+ my %param = ( formname => 'document.studentform',
+ kerb_def_dom => $krbdefdom,
+ kerb_def_auth => $krbdef
+ );
+ my $krbform = &Apache::loncommon::authform_kerberos(%param);
+ my $intform = &Apache::loncommon::authform_internal(%param);
+ my $locform = &Apache::loncommon::authform_local(%param);
+ #
+ # Set up domain selection form
+ my $homeserver_form = '';
+ my %servers = &Apache::loncommon::get_library_servers($domain);
+ $homeserver_form = '\n";
+ #
+ #
+ $user_data_html = <User Data for $username\@$domain
+
+
First Name:
+
+
Middle Name:
+
+
Last Name:
+
+
Generation:
+
+
Home Server:
+
$homeserver_form
+
+
Password
+Please select an authentication mechanism
+
+
+$krbform
+
+$intform
+
+$locform
+
+END
+ } else {
+ # User already exists. Do not worry about authentication
+ my %uenv = &Apache::lonnet::dump('environment',$domain,$username);
+ $javascript_validations = &javascript_validations_without_auth();
+ $user_data_html = <User Data for $username\@$domain
+
+
+
First Name:
+
+
+
+
Middle Name:
+
+
+
+
Last Name:
+
+
+
+
Generation:
+
+
+
+
+END
+ }
+ my $date_table = &date_setting_table();
+ # Print it all out
+ $r->print(<
+
+
+
+
+
+$user_data_html
+
+
Course Data
+
+
Group/Section:
+
+$date_table
+
+
ID/Student Number
+
+ID/Student Number:
+
+
+Disable ID/Student Number Safeguard and Force Change of Conflicting IDs
+(only do if you know what you are doing)
+
+
+
+END
+ return;
+}
+
+# ========================================================= Menu Phase Two Drop
+sub print_drop_menu {
+ my $r=shift;
+ $r->print("
Drop Students
");
+ my $cid=$ENV{'request.course.id'};
+ my ($classlist,$keylist) = &Apache::loncoursedata::get_classlist();
+ if (! defined($classlist)) {
+ $r->print("There are no students currently enrolled.\n");
+ return;
}
- if (vf.login[1].checked) {
- foundatype=1;
- if ((vf.intpwd.value=='') && (foundpwd==0)) {
- alert('You need to specify the initial password');
- return;
- }
+ # Print out the available choices
+ &show_drop_list($r,$classlist,$keylist);
+ return;
+}
+
+# ============================================== view classlist
+sub print_html_classlist {
+ my $r=shift;
+ if (! exists($ENV{'form.sortby'})) {
+ $ENV{'form.sortby'} = 'username';
}
- if (foundatype==0) {
- alert('You need to set the login type');
- return;
+ if ($ENV{'form.Status'} !~ /^(Any|Expired|Active)$/) {
+ $ENV{'form.Status'} = 'Active';
}
- if (foundname==0) { message='No first and last name specified. '; }
- if (foundid==0) { message+='No ID or student number field specified. '; }
- if (foundsec==0) { message+='No section or group field specified. '; }
- if (vf.startdate.value=='') {
- message+='No starting date set. ';
- }
- if (vf.enddate.value=='') {
- message+='No ending date set. ';
- }
- if ((vf.enddate.value!='') && (vf.startdate.value!='')) {
- if (Math.round(vf.enddate.value)print(<
+
+
+Current Class List
+
+END
+ if ($ENV{'form.action'} ne 'modifystudent') {
+ $r->print(<
+CSV format
+
+Excel format
+
+
+Student Status:
+END
}
- if (message!='') {
- message+='Continue enrollment?';
- if (confirm(message)) {
- pclose();
- vf.submit();
- }
+ $r->print($status_select."
\n");
+ my $cid=$ENV{'request.course.id'};
+ my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+ if (! defined($classlist)) {
+ $r->print("There are no students currently enrolled.\n");
} else {
- pclose();
- vf.submit();
- }
+ # Print out the available choices
+ if ($ENV{'form.action'} eq 'modifystudent') {
+ &show_class_list($r,'view','modify','modifystudent',
+ $ENV{'form.Status'},$classlist,$keylist);
+ } else {
+ &show_class_list($r,'view','aboutme','classlist',
+ $ENV{'form.Status'},$classlist,$keylist);
+ }
+ }
}
-function setkrb(vf) {
- if (vf.krbdom.value!='') {
- vf.login[0].checked=true;
- vf.krbdom.value=vf.krbdom.value.toUpperCase();
- vf.intpwd.value='';
- }
+# ============================================== view classlist
+sub print_formatted_classlist {
+ my $r=shift;
+ my $mode = shift;
+ my $cid=$ENV{'request.course.id'};
+ my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+ if (! defined($classlist)) {
+ $r->print("There are no students currently enrolled.\n");
+ } else {
+ &show_class_list($r,$mode,'nolink','csv',
+ $ENV{'form.Status'},$classlist,$keylist);
+ }
}
-function setint(vf) {
- if (vf.intpwd.value!='') {
- vf.login[1].checked=true;
- vf.krbdom.value='';
- }
-}
+# =================================================== Show student list to drop
+sub show_class_list {
+ my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
+ my $cid=$ENV{'request.course.id'};
+ #
+ # Variables for excel output
+ my ($excel_workbook, $excel_sheet, $excel_filename,$row);
+ #
+ my $sortby = $ENV{'form.sortby'};
+ if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
+ $sortby = 'username';
+ }
+ # Print out header
+ if ($mode eq 'view') {
+ if ($linkto eq 'aboutme') {
+ $r->print('Select a user name to view the users personal page.');
+ } elsif ($linkto eq 'modify') {
+ $r->print('Select a user name to modify the students information');
+ }
+ $r->print(<
+
+
+
'."\n");
+ }
}
-function clickint(vf) {
- vf.krbdom.value='';
-}
- function pclose() {
- parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
- "height=350,width=350,scrollbars=no,menubar=no");
- parmwin.close();
+#
+# print out form for modification of a single students data
+#
+sub print_modify_student_form {
+ my $r = shift();
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['sdom','sname']);
+ my $sname = $ENV{'form.sname'};
+ my $sdom = $ENV{'form.sdom'};
+ my $sortby = $ENV{'form.sortby'};
+ # determine the students name information
+ my %info=&Apache::lonnet::get('environment',
+ ['firstname','middlename',
+ 'lastname','generation','id'],
+ $sdom, $sname);
+ my ($tmp) = keys(%info);
+ if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
+ $r->print('Error'.
+ '
'.
+ 'Unable to retrieve environment data for '.$sname.
+ 'in domain '.$sdom.'
'.
+ 'Please contact your LON-CAPA administrator '.
+ 'regarding this situation.