[LON-CAPA-cvs] cvs: loncom /interface londropadd.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Wed, 18 Sep 2002 14:17:47 -0000
This is a MIME encoded message
--matthew1032358667
Content-Type: text/plain
matthew Wed Sep 18 10:17:47 2002 EDT
Modified files:
/loncom/interface londropadd.pm
Log:
Rewrote &get_current_classlist to call routines in loncoursedata.
Renamed &menu_phase_two_drop to &print_drop_menu and modified to use new
data from &get_current_classlist.
Modified &print_html_classlist and &print_csv_classlist to deal with new
&get_current_classlist.
Rewrote &show_classlist to take data from &get_current_classlist.
Not all of the error detecting code is reimplemented yet.
Modifying a single students status is not working yet.
Sorting of students by various fields (table headings) needs to be implemented.
--matthew1032358667
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20020918101747.txt"
Index: loncom/interface/londropadd.pm
diff -u loncom/interface/londropadd.pm:1.50 loncom/interface/londropadd.pm:1.51
--- loncom/interface/londropadd.pm:1.50 Tue Sep 17 11:52:44 2002
+++ loncom/interface/londropadd.pm Wed Sep 18 10:17:47 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.50 2002/09/17 15:52:44 matthew Exp $
+# $Id: londropadd.pm,v 1.51 2002/09/18 14:17:47 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -728,48 +728,33 @@
# =================================================== get the current classlist
sub get_current_classlist {
- my ($domain,$identifier) = @_;
- # domain is the domain the class is being run in
- # identifier is the internal, unique identifier for the class.
- my %currentlist=();
- my $now=time;
- my %results=&Apache::lonnet::dump('classlist',$domain,$identifier);
- my ($tmp) = keys(%results);
- if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
- foreach my $student (keys(%results)) {
- # Extract the start and end dates
- my ($end,$start)=split(/\:/,$results{$student});
- # If the class isn't over, put it in the list
- unless (($end) && ($now>$end)) {
- $currentlist{$student}=1;
- }
- }
- return (undef,%currentlist);
- } else {
- $tmp =~ s/^error://;
- return ($tmp,undef);
- }
+ my $r = shift;
+ # Call DownloadClasslist
+ my $cid = $ENV{'request.course.id'};
+ my $c = $r->connection;
+ my $classlisthash = &Apache::loncoursedata::DownloadClasslist
+ ($cid,'Not downloaded',$c);
+ # Call ProcessClasslist
+ my %cache;
+ my @students = &Apache::loncoursedata::ProcessClasslist(\%cache,
+ $classlisthash,
+ $cid,$c);
+ return (\@students,\%cache);
}
# ========================================================= Menu Phase Two Drop
-sub menu_phase_two_drop {
+sub print_drop_menu {
my $r=shift;
$r->print("<h3>Drop Students</h3>");
my $cid=$ENV{'request.course.id'};
- my ($error,%currentlist)=&get_current_classlist
- ($ENV{'course.'.$cid.'.domain'},$ENV{'course.'.$cid.'.num'});
- if (defined($error)) {
- if ($error =~ /^No such file or directory/) {
- $r->print("There are no students currently enrolled.\n");
- } else {
- $r->print("<pre>ERROR:$error</pre>");
- }
- } elsif (!defined(%currentlist)) {
+ my ($student_array,$student_data)=&get_current_classlist($r);
+ if (! scalar(@$student_array)) {
$r->print("There are no students currently enrolled.\n");
- } else {
- # Print out the available choices
- &show_drop_list($r,%currentlist);
+ return;
}
+ # Print out the available choices
+ &show_drop_list($student_array,$student_data,$r);
+ return;
}
# ============================================== view classlist
@@ -782,22 +767,15 @@
</p>
END
my $cid=$ENV{'request.course.id'};
- my ($error,%currentlist)=&get_current_classlist
- ($ENV{'course.'.$cid.'.domain'},$ENV{'course.'.$cid.'.num'});
- if (defined($error)) {
- if ($error =~ /^No such file or directory/) {
- $r->print("There are no students currently enrolled.\n");
- } else {
- $r->print("<pre>ERROR:$error</pre>");
- }
- } elsif (!defined(%currentlist)) {
+ my ($student_array,$student_data)=&get_current_classlist($r);
+ if (! scalar(@$student_array)) {
$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',%currentlist);
+ &show_class_list($r,'view','modify',$student_array,$student_data);
} else {
- &show_class_list($r,'view','aboutme',%currentlist);
+ &show_class_list($r,'view','aboutme',$student_array,$student_data);
}
}
}
@@ -806,24 +784,17 @@
sub print_csv_classlist {
my $r=shift;
my $cid=$ENV{'request.course.id'};
- my ($error,%currentlist)=&get_current_classlist
- ($ENV{'course.'.$cid.'.domain'},$ENV{'course.'.$cid.'.num'});
- if (defined($error)) {
- if ($error =~ /^No such file or directory/) {
- $r->print("There are no students currently enrolled.\n");
- } else {
- $r->print("<pre>ERROR:$error</pre>");
- }
- } elsif (!defined(%currentlist)) {
+ my ($student_array,$student_data)=&get_current_classlist($r);
+ if (! scalar(@$student_array)) {
$r->print("There are no students currently enrolled.\n");
} else {
- &show_class_list($r,'csv','nolink',%currentlist);
+ &show_class_list($r,'csv','nolink',$student_array,$student_data);
}
}
# =================================================== Show student list to drop
sub show_class_list {
- my ($r,$mode,$linkto,%currentlist)=@_;
+ my ($r,$mode,$linkto,$students,$student_data)=@_;
my $cid=$ENV{'request.course.id'};
# Print out header
if ($mode eq 'view') {
@@ -836,66 +807,51 @@
<p>
<table border=2>
<tr><th>username</th><th>domain</th><th>ID</th>
- <th>student name</th><th>generation</th><th>section</th></tr>
+ <th>student name</th><th>section</th></tr>
END
} elsif ($mode eq 'csv') {
- $r->print('"'.join('","',("username","domain","ID","last name",
- "first name","middle name","generation",
+ $r->print('"'.join('","',("username","domain","ID","student name",
"section")).'"'."\n");
}
- foreach (sort keys %currentlist) {
- my ($sname,$sdom)=split(/\:/,$_);
- my %reply=&Apache::lonnet::idrget($sdom,$sname);
- my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
- my %info=&Apache::lonnet::get('environment',
- ['firstname','middlename',
- 'lastname','generation'],
- $sdom, $sname);
- my ($tmp) = keys(%info);
- if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
- if ($mode eq 'view') {
- $r->print('<tr><td colspan="6"><font color="red">'.
- 'Internal error: unable to get environment '.
- 'for '.$sname.' in domain '.$sdom.'</font></td></tr>');
- } else {
- $r->print('"Internal error: unable to get environment for '.
- $sname.' in domain '.$sdom.'"');
+ foreach my $student (@$students) {
+ my $username = $student_data->{$student.':username'};
+ my $domain = $student_data->{$student.':domain'};
+ my $section = $student_data->{$student.':section'};
+ my $name = $student_data->{$student.':fullname'};
+ my $status = $student_data->{$student.':Status'};
+ my $id = $student_data->{$student.':id'};
+ next if ($status ne 'Active');
+ if ($mode eq 'view') {
+ $r->print("<tr>\n <td>\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('<a href="/adm/dropadd?action=modifystudent'.
+ '&state=selected'.'&sname='.$username.
+ '&sdom='.$domain.'">'.$username."</a>\n");
}
- } else {
- if ($mode eq 'view') {
- $r->print("<tr>\n <td>\n ");
- if ($linkto eq 'nothing') {
- $r->print($sname);
- } elsif ($linkto eq 'aboutme') {
- $r->print(&Apache::loncommon::aboutmewrapper($sname,$sname,
- $sdom));
- } elsif ($linkto eq 'modify') {
- $r->print('<a href="/adm/dropadd?action=modifystudent'.
- '&state=selected'.'&sname='.$sname.
- '&sdom='.$sdom.'">'.$sname."</a>\n");
- }
- $r->print(<<"END");
+ $r->print(<<"END");
</td>
- <td>$sdom</td>
- <td>$reply{$sname}</td>
- <td>$info{'lastname'}, $info{'firstname'} $info{'middlename'}</td>
- <td>$info{'generation'}</td>
- <td>$ssec</td>
+ <td>$domain</td>
+ <td>$id</td>
+ <td>$name</td>
+ <td>$section</td>
</tr>
END
- } elsif ($mode eq 'csv') {
- # no need to bother with $linkto
- my @line = ();
- foreach ($sname,$sdom,$reply{$sname},
- $info{'lastname'},$info{'firstname'},
- $info{'middlename'},$info{'generation'},$ssec) {
- push @line,&Apache::loncommon::csv_translate($_);
- }
- my $tmp = $";
- $" = '","';
- $r->print("\"@line\"\n");
- $" = $tmp;
+ } 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('</table><br>') if ($mode eq 'view');
@@ -1063,20 +1019,18 @@
# =================================================== Show student list to drop
sub show_drop_list {
- my ($r,%currentlist)=@_;
+ my ($students,$student_data,$r)=@_;
my $cid=$ENV{'request.course.id'};
$r->print(<<'END');
<input type="hidden" name="action" value="drop" />
<input type="hidden" name="state" value="done" />
<script>
-function checkAll(field)
-{
+function checkAll(field) {
for (i = 0; i < field.length; i++)
field[i].checked = true ;
}
-function uncheckAll(field)
-{
+function uncheckAll(field) {
for (i = 0; i < field.length; i++)
field[i].checked = false ;
}
@@ -1085,35 +1039,27 @@
<input type="hidden" name="phase" value="four">
<table border=2>
<tr><th> </th><th>username</th><th>domain</th>
-<th>ID</th><th>student name</th><th>generation</th>
-<th>section</th></tr>
+ <th>ID</th><th>student name</th><th>section</th></tr>
END
- foreach (sort keys %currentlist) {
- my ($sname,$sdom)=split(/\:/,$_);
- my %reply=&Apache::lonnet::idrget($sdom,$sname);
- my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
- my %info=&Apache::lonnet::get('environment',
- ['firstname','middlename',
- 'lastname','generation'],
- $sdom, $sname);
- my ($tmp) = keys(%info);
- if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
- $r->print('<tr><td colspan="7"><font color="red">'.
- 'Internal error: unable to get environment '.
- 'for '.$sname.' in domain '.$sdom.'</font></td></tr>');
- } else {
- $r->print(<<"END");
+ foreach my $student (@$students) {
+ my $username = $student_data->{$student.':username'};
+ my $domain = $student_data->{$student.':domain'};
+ my $section = $student_data->{$student.':section'};
+ my $name = $student_data->{$student.':fullname'};
+ my $status = $student_data->{$student.':Status'};
+ my $id = $student_data->{$student.':id'};
+ next if ($status ne 'Active');
+ #
+ $r->print(<<"END");
<tr>
- <td><input type="checkbox" name="droplist" value="$_"></td>
- <td>$sname</td>
- <td>$sdom</td>
- <td>$reply{$sname}</td>
- <td>$info{'lastname'}, $info{'firstname'} $info{'middlename'}</td>
- <td>$info{'generation'}</td>
- <td>$ssec</td>
+ <td><input type="checkbox" name="droplist" value="$student"></td>
+ <td>$username</td>
+ <td>$domain</td>
+ <td>$id</td>
+ <td>$name</td>
+ <td>$section</td>
</tr>
END
- }
}
$r->print('</table><br>');
$r->print(<<"END");
@@ -1122,6 +1068,7 @@
<input type="button" value="uncheck all" onclick="javascript:uncheckAll(document.studentform.droplist)">
<p><input type=submit value="Drop Students"></p>
END
+ return;
}
#
@@ -1302,9 +1249,7 @@
if ($ENV{'form.fullup'} eq 'yes') {
$r->print('<h3>Dropping Students</h3>');
# Get current classlist
- my ($error,%currentlist)=&get_current_classlist
- ($ENV{'course.'.$cid.'.domain'},
- $ENV{'course.'.$cid.'.num'});
+ my ($error,%currentlist)=&get_current_classlist($r);
if (defined($error)) {
$r->print('<pre>ERROR:$error</pre>');
}
@@ -1470,7 +1415,7 @@
}
} elsif ($ENV{'form.action'} eq 'drop') {
if (! exists($ENV{'form.state'})) {
- &menu_phase_two_drop($r);
+ &print_drop_menu($r);
} elsif ($ENV{'form.state'} eq 'done') {
&drop_student_list($r);
} else {
--matthew1032358667--