[LON-CAPA-cvs] cvs: loncom /interface londropadd.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Thu, 13 May 2004 21:03:17 -0000
This is a MIME encoded message
--matthew1084482197
Content-Type: text/plain
matthew Thu May 13 17:03:17 2004 EDT
Modified files:
/loncom/interface londropadd.pm
Log:
Bug 2976: Add start and end dates to view and drop classlist pages.
Required modifying the inputs to &show_class_list. Dates are formatted
with lonlocal::locallocaltime or Excel, as the need arises. Now
depend on lonstathelpers for the excel time handling routine.
Cleaned up some bad html on the classlist view page. Modified the input
parameters for the classlist view page to use form.output instead of the
much overused form.state. All of this is not as nice as it should be but
I don't have time to eviscerate it properly.
--matthew1084482197
Content-Type: text/plain
Content-Disposition: attachment; filename="matthew-20040513170317.txt"
Index: loncom/interface/londropadd.pm
diff -u loncom/interface/londropadd.pm:1.109 loncom/interface/londropadd.pm:1.110
--- loncom/interface/londropadd.pm:1.109 Wed May 12 16:04:57 2004
+++ loncom/interface/londropadd.pm Thu May 13 17:03:16 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Handler to drop and add students in courses
#
-# $Id: londropadd.pm,v 1.109 2004/05/12 20:04:57 matthew Exp $
+# $Id: londropadd.pm,v 1.110 2004/05/13 21:03:16 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,6 +37,7 @@
use Apache::lonhtmlcommon();
use Apache::Constants qw(:common :http REDIRECT);
use Spreadsheet::WriteExcel;
+use Apache::lonstathelpers();
use Apache::lonlocal;
###############################################################
@@ -1115,21 +1116,28 @@
#
# List course personnel
my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
+ #
+ if (! defined($ENV{'form.output'}) ||
+ $ENV{'form.output'} !~ /^(csv|excel|html)$/ ) {
+ $ENV{'form.output'} = 'html';
+ }
+ #
$r->print('<br /><table border="2">');
- foreach (sort keys %coursepersonnel) {
- $r->print('<tr><td>'.$_.'</td><td>');
- foreach (split(/\,/,$coursepersonnel{$_})) {
- my ($puname,$pudom)=split(/\:/,$_);
+ foreach my $role (sort keys %coursepersonnel) {
+ next if ($role =~ /^\s*$/);
+ $r->print('<tr><td>'.$role.'</td><td>');
+ foreach my $user (split(',',$coursepersonnel{$role})) {
+ my ($puname,$pudom)=split(':',$user);
$r->print(' '.&Apache::loncommon::aboutmewrapper(
- &Apache::loncommon::plainname($puname,
- $pudom),$puname,$pudom));
+ &Apache::loncommon::plainname($puname,
+ $pudom),
+ $puname,$pudom));
}
$r->print('</td></tr>');
}
$r->print('</table>');
#
# Interface output
- my $CCL=&mt('Current Class List');
$r->print('<input type="hidden" name="action" value="'.
$ENV{'form.action'}.'" />');
$r->print("<p>\n");
@@ -1137,14 +1145,10 @@
my %lt=&Apache::lonlocal::texthash('csv' => "CSV",
'excel' => "Excel",
'html' => 'HTML');
- $r->print('<font size="+1">');
- my $output_selector = '<select size="1" name="state" >';
- if ($ENV{'form.state'} !~ /^(csv|excel|html)$/ ) {
- $ENV{'form.state'} = 'html';
- }
+ my $output_selector = '<select size="1" name="output" >';
foreach my $outputformat ('html','csv','excel') {
my $option = '<option value="'.$outputformat.'" ';
- if ($outputformat eq $ENV{'form.state'}) {
+ if ($outputformat eq $ENV{'form.output'}) {
$option .= 'selected ';
}
$option .='>'.$lt{$outputformat}.'</option>';
@@ -1156,7 +1160,6 @@
$r->print(&mt('Student Status: [_1]',$status_select)."\n");
$r->print('<input type="submit" value="'.&mt('Update Display').'" />'.
"\n</p>\n");
-
#
# Print the classlist
$r->print('<h2>'.&mt('Current Class List').'</h2>');
@@ -1166,13 +1169,12 @@
} else {
# Print out the available choices
if ($ENV{'form.action'} eq 'modifystudent') {
- &show_class_list($r,'view','modify','modifystudent',
- $ENV{'form.Status'},$classlist,$keylist);
- } elsif (! defined($mode) || $mode eq '') {
- &show_class_list($r,'view','aboutme','classlist',
+ &show_class_list($r,'view','modify',
$ENV{'form.Status'},$classlist,$keylist);
- } elsif ($mode eq 'csv' || $mode eq 'excel') {
- &show_class_list($r,$mode,'nolink','csv',
+ } else {
+ &Apache::lonnet::logthis('showing class list '.$ENV{'form.output'});
+
+ &show_class_list($r,$ENV{'form.output'},'aboutme',
$ENV{'form.Status'},$classlist,$keylist);
}
}
@@ -1180,7 +1182,7 @@
# =================================================== Show student list to drop
sub show_class_list {
- my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_;
+ my ($r,$mode,$linkto,$statusmode,$classlist,$keylist)=@_;
my $cid=$ENV{'request.course.id'};
#
# Variables for excel output
@@ -1190,7 +1192,7 @@
my ($CSVfile,$CSVfilename);
#
my $sortby = $ENV{'form.sortby'};
- if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
+ if ($sortby !~ /^(username|domain|section|fullname|id|start|end)$/) {
$sortby = 'username';
}
# Print out header
@@ -1199,17 +1201,19 @@
<input type="hidden" name="state" value="$ENV{'form.state'}" />
<input type="hidden" name="sortby" value="$sortby" />
END
- if ($mode eq 'view') {
+ if ($mode eq 'html' || $mode eq 'view') {
if ($linkto eq 'aboutme') {
$r->print(&mt('Select a user name to view the users personal page.'));
} elsif ($linkto eq 'modify') {
$r->print(&mt('Select a user name to modify the students information'));
}
my %lt=&Apache::lonlocal::texthash(
- 'usrn' => "username",
- 'dom' => "domain",
- 'sn' => "student name",
- 'sec' => "section",
+ 'usrn' => "username",
+ 'dom' => "domain",
+ 'sn' => "student name",
+ 'sec' => "section",
+ 'start' => "start date",
+ 'end' => "end date",
);
$r->print(<<END);
<input type="hidden" name="sname" value="" />
@@ -1227,6 +1231,10 @@
<a href="javascript:document.studentform.sortby.value='fullname';document.studentform.submit();">$lt{'sn'}</a>
</th><th>
<a href="javascript:document.studentform.sortby.value='section';document.studentform.submit();">$lt{'sec'}</a>
+ </th><th>
+ <a href="javascript:document.studentform.sortby.value='start';document.studentform.submit();">$lt{'start'}</a>
+ </th><th>
+ <a href="javascript:document.studentform.sortby.value='end';document.studentform.submit();">$lt{'end'}</a>
</th>
</tr>
END
@@ -1252,12 +1260,12 @@
print $CSVfile '"'.join('","',map {
&Apache::loncommon::csv_translate(&mt($_))
} ("username","domain","ID","student name",
- "section","status")).'"'."\n";
+ "section","start date","end date","status")).'"'."\n";
} else {
print $CSVfile '"'.join('","',map {
&Apache::loncommon::csv_translate(&mt($_))
} ("username","domain","ID","student name",
- "section")).'"'."\n";
+ "section","start date","end date")).'"'."\n";
}
} elsif ($mode eq 'excel') {
# Create the excel spreadsheet
@@ -1276,7 +1284,9 @@
$excel_sheet->write($row++,0,$description,$format->{'h1'});
#
$excel_sheet->write($row++,0,["username","domain","ID",
- "student name","section","status"],$format->{'bold'});
+ "student name","section",
+ "start date","end date","status"],
+ $format->{'bold'});
}
#
# Sort the students
@@ -1297,14 +1307,19 @@
} (keys(%$classlist));
my $studentcount = 0;
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'}];
+ my $sdata = $classlist->{$student};
+ my $username = $sdata->[$index{'username'}];
+ my $domain = $sdata->[$index{'domain'}];
+ my $section = $sdata->[$index{'section'}];
+ my $name = $sdata->[$index{'fullname'}];
+ my $id = $sdata->[$index{'id'}];
+ my $status = $sdata->[$index{'status'}];
+ my $start = $sdata->[$index{'start'}];
+ my $end = $sdata->[$index{'end'}];
next if (($statusmode ne 'Any') && ($status ne $statusmode));
- if ($mode eq 'view') {
+ if ($mode eq 'view' || $mode eq 'html') {
+ $start = &Apache::lonlocal::locallocaltime($start);
+ $end = &Apache::lonlocal::locallocaltime($end);
$r->print("<tr>\n <td>".(++$studentcount)."</td><td>\n ");
if ($linkto eq 'nothing') {
$r->print($username);
@@ -1327,13 +1342,17 @@
<td>$id</td>
<td>$name</td>
<td>$section</td>
+ <td>$start</td>
+ <td>$end</td>
</tr>
END
} elsif ($mode eq 'csv') {
next if (! defined($CSVfile));
# no need to bother with $linkto
+ $start = &Apache::lonlocal::locallocaltime($start);
+ $end = &Apache::lonlocal::locallocaltime($end);
my @line = ();
- foreach ($username,$domain,$id,$name,$section) {
+ foreach ($username,$domain,$id,$name,$section,$start,$end) {
push @line,&Apache::loncommon::csv_translate($_);
}
if ($statusmode eq 'Any') {
@@ -1341,11 +1360,19 @@
}
print $CSVfile '"'.join('","',@line).'"'."\n";
} elsif ($mode eq 'excel') {
- $excel_sheet->write($row++,0,[$username,$domain,$id,
- $name,$section,$status]);
+ $excel_sheet->write($row,0,[$username,$domain,$id,
+ $name,$section]);
+ my $col = 5;
+ foreach my $time ($start,$end) {
+ $excel_sheet->write($row,$col++,
+ &Apache::lonstathelpers::calc_serial($time),
+ $format->{'date'});
+ }
+ $excel_sheet->write($row,$col++,$status);
+ $row++;
}
}
- if ($mode eq 'view') {
+ if ($mode eq 'view' || $mode eq 'html') {
$r->print('</table><br>');
} elsif ($mode eq 'excel') {
$excel_workbook->close();
@@ -1692,7 +1719,7 @@
['sortby']);
}
my $sortby = $ENV{'form.sortby'};
- if ($sortby !~ /^(username|domain|section|fullname|id)$/) {
+ if ($sortby !~ /^(username|domain|section|fullname|id|start|end)$/) {
$sortby = 'username';
}
#
@@ -1716,13 +1743,14 @@
<input type="hidden" name="phase" value="four">
END
+my %lt=&Apache::lonlocal::texthash('usrn' => "username",
+ 'dom' => "domain",
+ 'sn' => "student name",
+ 'sec' => "section",
+ 'start' => "start date",
+ 'end' => "end date",
+ );
if ($nosort) {
- my %lt=&Apache::lonlocal::texthash(
- 'usrn' => "username",
- 'dom' => "domain",
- 'sn' => "student name",
- 'sec' => "section",
- );
$r->print(<<END);
<table border=2>
<tr>
@@ -1732,16 +1760,12 @@
<th>ID</th>
<th>$lt{'sn'}</th>
<th>$lt{'sec'}</th>
+ <th>$lt{'start'}</th>
+ <th>$lt{'end'}</th>
</tr>
END
} else {
- my %lt=&Apache::lonlocal::texthash(
- 'usrn' => "username",
- 'dom' => "domain",
- 'sn' => "student name",
- 'sec' => "section",
- );
$r->print(<<END);
<table border=2>
<tr><th> </th>
@@ -1755,6 +1779,10 @@
<a href="/adm/dropadd?action=$action&sortby=fullname">$lt{'sn'}</a>
</th><th>
<a href="/adm/dropadd?action=$action&sortby=section">$lt{'sec'}</a>
+ </th><th>
+ <a href="/adm/dropadd?action=$action&sortby=start">$lt{'start'}</a>
+ </th><th>
+ <a href="/adm/dropadd?action=$action&sortby=end">$lt{'end'}</a>
</th>
</tr>
END
@@ -1778,12 +1806,25 @@
} (keys(%$classlist));
foreach my $student (@Sorted_Students) {
my $error;
- 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'}];
+ my $sdata = $classlist->{$student};
+ my $username = $sdata->[$index{'username'}];
+ my $domain = $sdata->[$index{'domain'}];
+ my $section = $sdata->[$index{'section'}];
+ my $name = $sdata->[$index{'fullname'}];
+ my $id = $sdata->[$index{'id'}];
+ my $start = $sdata->[$index{'start'}];
+ my $end = $sdata->[$index{'end'}];
+ if (! defined($start) || $start == 0) {
+ $start = &mt('none');
+ } else {
+ $start = &Apache::lonlocal::locallocaltime($start);
+ }
+ if (! defined($end) || $end == 0) {
+ $end = &mt('none');
+ } else {
+ $end = &Apache::lonlocal::locallocaltime($end);
+ }
+ my $status = $sdata->[$index{'status'}];
next if ($status ne 'Active');
#
$r->print(<<"END");
@@ -1794,6 +1835,8 @@
<td>$id</td>
<td>$name</td>
<td>$section</td>
+ <td>$start</td>
+ <td>$end</td>
</tr>
END
}
--matthew1084482197--