--- loncom/interface/Attic/londropadd.pm 2002/04/15 23:37:37 1.24
+++ loncom/interface/Attic/londropadd.pm 2002/10/15 14:41:31 1.56
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.24 2002/04/15 23:37:37 albertel Exp $
+# $Id: londropadd.pm,v 1.56 2002/10/15 14:41:31 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,167 +31,223 @@
#
# (TeX Content Handler
#
-# YEAR=2000
-# 05/29/00,05/30,10/11 Gerd Kortemeyer)
-#
-# 10/11,10/12,10/16 Gerd Kortemeyer)
-#
-# 11/20,11/21,11/22,11/23,11/24,11/25,11/27,11/28,
-# 12/08,12/12 Gerd Kortemeyer)
-#
-# 12/26,12/27,12/28,
-# YEAR=2001
-# 01/01/01,01/15,02/10,02/13,02/14,02/22 Gerd Kortemeyer
-# 8/6 Scott Harrison
-# Guy Albertelli
-# 9/25 Gerd Kortemeyer
-# 12/19 Guy Albertelli
-# YEAR=2002
-# 1/4 Gerd Kortemeyer
+###############################################################
+###############################################################
package Apache::londropadd;
use strict;
use Apache::lonnet();
use Apache::loncommon();
+use Apache::lonhtmlcommon();
use Apache::Constants qw(:common :http REDIRECT);
-# ================================================================ Print header
-
+###############################################################
+###############################################################
sub header {
- my $r=shift;
- $r->print(<
-LON-CAPA Student Drop/Add
+LON-CAPA Enrollment Manager
-
-
-Drop/Add Students
-
+END
my $cid=$ENV{'request.course.id'};
- my $classlst=&Apache::lonnet::reply
- ('dump:'.$ENV{'course.'.$cid.'.domain'}.':'.
- $ENV{'course.'.$cid.'.num'}.':classlist',
- $ENV{'course.'.$cid.'.home'});
- my %currentlist=();
- my $now=time;
- unless ($classlst=~/^error\:/) {
- foreach (split(/\&/,$classlst)) {
- my ($name,$value)=split(/\=/,$_);
- my ($end,$start)=split(/\:/,
- &Apache::lonnet::unescape($value));
- my $active=1;
- if (($end) && ($now>$end)) { $active=0; }
- if ($active) {
- $currentlist{&Apache::lonnet::unescape($name)}=1;
- }
- }
-# ----------------------------------------------------------- Print out choices
- &show_drop_list($r,%currentlist);
- } else {
- $r->print(
- 'Could not access classlist: '.$classlst.
- '
');
- }
+ my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
+ if (! defined($classlist)) {
+ $r->print("There are no students currently enrolled.\n");
+ } else {
+ # Print out the available choices
+ if ($ENV{'form.action'} eq 'modifystudent') {
+ &show_class_list($r,'view','modify','modifystudent',
+ 'Active',$classlist,$keylist);
+ } else {
+ &show_class_list($r,'view','aboutme','classlist',
+ 'Active',$classlist,$keylist);
+ }
+ }
+}
+
+# ============================================== view classlist
+sub print_csv_classlist {
+ my $r=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,'csv','nolink','csv',
+ 'Active',$classlist,$keylist);
+ }
}
# =================================================== Show student list to drop
+sub show_class_list {
+ my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
+ my $cid=$ENV{'request.course.id'};
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['sortby']);
+ 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(<
+
+
+
+ username
+ |
+ domain
+ |
+ ID
+ |
+ student name
+ |
+ section
+ |
+
+END
+ } elsif ($mode eq 'csv') {
+ $r->print('"'.join('","',("username","domain","ID","student name",
+ "section")).'"'."\n");
+ }
+ #
+ # Sort the students
+ my %index;
+ my $i;
+ foreach (@$keylist) {
+ $index{$_} = $i++;
+ }
+ my $index = $index{$sortby};
+ my $second = $index{'username'};
+ my $third = $index{'domain'};
+ my @Sorted_Students = sort {
+ lc($classlist->{$a}->[$index]) cmp lc($classlist->{$b}->[$index])
+ ||
+ lc($classlist->{$a}->[$second]) cmp lc($classlist->{$b}->[$second])
+ ||
+ lc($classlist->{$a}->[$third]) cmp lc($classlist->{$b}->[$third])
+ } (keys(%$classlist));
+ foreach my $student (@Sorted_Students) {
+ my $username = $classlist->{$student}->[$index{'username'}];
+ my $domain = $classlist->{$student}->[$index{'domain'}];
+ my $section = $classlist->{$student}->[$index{'section'}];
+ my $name = $classlist->{$student}->[$index{'fullname'}];
+ my $id = $classlist->{$student}->[$index{'id'}];
+ my $status = $classlist->{$student}->[$index{'status'}];
+ next if (($statusmode ne 'any') && ($status ne $statusmode));
+ if ($mode eq 'view') {
+ $r->print("\n \n ");
+ if ($linkto eq 'nothing') {
+ $r->print($username);
+ } elsif ($linkto eq 'aboutme') {
+ $r->print(&Apache::loncommon::aboutmewrapper($username,
+ $username,
+ $domain));
+ } elsif ($linkto eq 'modify') {
+ $r->print(''.
+ $username."\n");
+ }
+ $r->print(<<"END");
+ |
+ $domain |
+ $id |
+ $name |
+ $section |
+
+END
+ } elsif ($mode eq 'csv') {
+ # no need to bother with $linkto
+ my @line = ();
+ foreach ($username,$domain,$id,$name,$section) {
+ push @line,&Apache::loncommon::csv_translate($_);
+ }
+ my $tmp = $";
+ $" = '","';
+ $r->print("\"@line\"\n");
+ $" = $tmp;
+ }
+ }
+ $r->print('
') if ($mode eq 'view');
+}
+
+
+#
+# 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','sortby']);
+ 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.