version 1.9, 2003/05/02 15:26:36
|
version 1.15, 2004/05/09 00:45:01
|
Line 36 use Apache::loncommon();
|
Line 36 use Apache::loncommon();
|
use Apache::lonhtmlcommon(); |
use Apache::lonhtmlcommon(); |
use Apache::Constants qw(:common :http REDIRECT); |
use Apache::Constants qw(:common :http REDIRECT); |
use Spreadsheet::WriteExcel; |
use Spreadsheet::WriteExcel; |
|
use Apache::lonlocal; |
|
|
############################################################### |
############################################################### |
############################################################### |
############################################################### |
Line 54 ENDHEAD
|
Line 55 ENDHEAD
|
|
|
# =================================================== Show student list to drop |
# =================================================== Show student list to drop |
sub show_key_list { |
sub show_key_list { |
my ($r,$comment,$newonly,$checkonly,%cenv)=@_; |
my ($r,$csvlist,$comment,$newonly,$checkonly,%cenv)=@_; |
$comment=~s/\W/\./g; |
$comment=~s/\W/\./g; |
my %accesskeys=&Apache::lonnet::dump |
my %accesskeys=&Apache::lonnet::dump |
('accesskeys',$cenv{'domain'},$cenv{'num'}); |
('accesskeys',$cenv{'domain'},$cenv{'num'}); |
$r->print('<h3>List of Keys/Enter New Comments</h3><table border="2"><tr><th>Key</th><th>Checked Out</th><th>Comments/Remarks/Notes</th><th>Enter Additional Comments/Remarks/Notes</th></tr>'); |
unless ($csvlist) { |
|
$r->print(<<ENDTABLEHEADER); |
|
<script> |
|
function copyallcom(tf) { |
|
for (i=0; i<tf.elements.length; i++) { |
|
if (tf.elements[i].name.indexOf('com_')==0) { |
|
tf.elements[i].value+=tf.copyall.value; |
|
} |
|
} |
|
|
|
} |
|
</script> |
|
<h3>List of Keys/Enter New Comments</h3> |
|
<table border="2"><tr><th>Key</th><th>Checked Out</th> |
|
<th>Comments/Remarks/Notes</th> |
|
<th>Enter Additional Comments/Remarks/Notes<br /> |
|
<input type="text" size="40" name="copyall" /> |
|
<input type="button" value="Copy to All" onClick="copyallcom(this.form);" /> |
|
</th></tr> |
|
ENDTABLEHEADER |
|
} |
foreach (keys %accesskeys) { |
foreach (keys %accesskeys) { |
if ($_=~/^error\:/) { |
if ($_=~/^error\:/) { |
$r->print('<tr><td>No keys have been generated yet.</td></tr>'); |
$r->print('<tr><td>No keys have been generated yet.</td></tr>'); |
Line 69 sub show_key_list {
|
Line 90 sub show_key_list {
|
} else { |
} else { |
if ($newonly) { next; } |
if ($newonly) { next; } |
} |
} |
$r->print("\n<tr><td><tt>".$_.'</tt></td><td>'.($checkout? |
unless ($csvlist) { |
|
$r->print("\n<tr><td><tt>".$_.'</tt></td><td>'.($checkout? |
$checkout:'-').'</td><td>'. |
$checkout:'-').'</td><td>'. |
join('<br />',split(/\s*\;\s*/,$com)). |
join('<br />',split(/\s*\;\s*/,$com)). |
'</td><td><input type="text" size="40" name="com_'.$_. |
'</td><td><input type="text" size="40" name="com_'.$_. |
'" /></td></tr>'); |
'" value="" /></td></tr>'); |
|
} else { |
|
my @line = (); |
|
push @line,&Apache::loncommon::csv_translate($_); |
|
push @line,&Apache::loncommon::csv_translate($checkout); |
|
foreach (split(/\s*\;\s*/,$com)) { |
|
push @line,&Apache::loncommon::csv_translate($_); |
|
} |
|
my $tmp = $"; |
|
$" = '","'; |
|
$r->print("\"@line\"\n"); |
|
$" = $tmp; |
|
} |
} |
} |
} |
} |
$r->print('</table>'); |
unless ($csvlist) { |
$r->print('<input type="submit" name="addcom" value="Add Above Comments to Keys" /><hr />'); |
$r->print('</table>'); |
return ''; |
$r->print('<input type="submit" name="addcom" value="Add Above Comments to Keys" /><hr />'); |
# |
|
# Junk below |
|
# |
|
my ($mode,$linkto,$action,$statusmode,$classlist,$keylist); |
|
# |
|
# Just junk so that this compiles |
|
# |
|
my ($username,$domain,$id,$name,$section,$status,@Sorted_Students); |
|
# |
|
# |
|
# |
|
my $cid=$ENV{'form.cid'}; |
|
# |
|
# Variables for excel output |
|
my ($excel_workbook, $excel_sheet, $excel_filename,$row); |
|
# |
|
|
|
# Print out header |
|
if ($mode eq 'view') { |
|
} elsif ($mode eq 'excel') { |
|
# Create the excel spreadsheet |
|
$excel_filename = '/prtspool/'. |
|
$ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'. |
|
time.'_'.rand(1000000000).'.xls'; |
|
$excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'. |
|
$excel_filename); |
|
$excel_workbook->set_tempdir('/home/httpd/perl/tmp'); |
|
$excel_sheet = $excel_workbook->addworksheet('classlist'); |
|
# |
|
my $description = 'Classlist for '. |
|
$ENV{'course.'.$ENV{'request.course.id'}.'.description'}; |
|
$excel_sheet->write($row++,0,$description); |
|
# |
|
$excel_sheet->write($row++,0,["username","domain","ID", |
|
"student name","section","status"]); |
|
} |
|
foreach my $student (@Sorted_Students) { |
|
if ($mode eq 'view') { |
|
} elsif ($mode eq 'csv') { |
|
# no need to bother with $linkto |
|
my @line = (); |
|
foreach ($username,$domain,$id,$name,$section) { |
|
push @line,&Apache::loncommon::csv_translate($_); |
|
} |
|
if ($statusmode eq 'Any') { |
|
push @line,&Apache::loncommon::csv_translate($status); |
|
} |
|
my $tmp = $"; |
|
$" = '","'; |
|
$r->print("\"@line\"\n"); |
|
$" = $tmp; |
|
} elsif ($mode eq 'excel') { |
|
$excel_sheet->write($row++,0,[$username,$domain,$id, |
|
$name,$section,$status]); |
|
} |
|
} |
|
if ($mode eq 'view') { |
|
} elsif ($mode eq 'excel') { |
|
$excel_workbook->close(); |
|
$r->print('<p><a href="'.$excel_filename.'">'. |
|
'Your Excel spreadsheet</a> is ready for download.</p>'."\n"); |
|
} |
} |
|
return ''; |
} |
} |
|
|
|
|
Line 201 sub addcom {
|
Line 175 sub addcom {
|
sub handler { |
sub handler { |
my $r=shift; |
my $r=shift; |
if ($r->header_only) { |
if ($r->header_only) { |
$r->content_type('text/html'); |
&Apache::loncommon::content_type($r,'text/html'); |
$r->send_http_header; |
$r->send_http_header; |
return OK; |
return OK; |
} |
} |
Line 217 sub handler {
|
Line 191 sub handler {
|
return HTTP_NOT_ACCEPTABLE; |
return HTTP_NOT_ACCEPTABLE; |
} |
} |
if ($ENV{'form.cid'}) { |
if ($ENV{'form.cid'}) { |
my %cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'}); |
my %cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'}); |
if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) { |
my $keytype=''; |
|
if ($cenv{'url'} eq '/res/') { |
|
($cenv{'domain'},$cenv{'num'})=split(/\_/,$ENV{'form.cid'}); |
|
$keytype='auth'; |
|
} elsif ($cenv{'keyauth'}) { |
|
($cenv{'num'},$cenv{'domain'})=split(/\W/,$cenv{'keyauth'}); |
|
$keytype='auth'; |
|
} else { |
|
$keytype='course'; |
|
} |
|
if ($ENV{'form.listkeyscsv'}) { |
# |
# |
# CSV Output |
# CSV Output |
# |
# |
$r->content_type('text/csv'); |
$r->content_type('text/csv'); |
|
$r->send_http_header; |
# |
# |
# Do CSV |
# Do CSV |
# |
# |
|
&show_key_list($r,1,$ENV{'form.listcom'}, |
|
$ENV{'form.newonly'},$ENV{'form.checkonly'},%cenv); |
|
|
} else { |
} else { |
# |
# |
# Normal web stuff |
# Normal web stuff |
# |
# |
$r->content_type('text/html'); |
&Apache::loncommon::content_type($r,'text/html'); |
$r->send_http_header; |
$r->send_http_header; |
$r->print(&header()); |
$r->print(&header()); |
|
|
Line 248 sub handler {
|
Line 236 sub handler {
|
$r->print($msg.'<br />'); |
$r->print($msg.'<br />'); |
} |
} |
if ($ENV{'form.listkeys'}) { |
if ($ENV{'form.listkeys'}) { |
&show_key_list($r,$ENV{'form.listcom'}, |
&show_key_list($r,0,$ENV{'form.listcom'}, |
$ENV{'form.newonly'},$ENV{'form.checkonly'},%cenv); |
$ENV{'form.newonly'},$ENV{'form.checkonly'},%cenv); |
} |
} |
if ($ENV{'form.addcom'}) { |
if ($ENV{'form.addcom'}) { |
&addcom(%cenv); |
&addcom(%cenv); |
} |
} |
# --- Menu |
# --- Menu |
$r->print('<h3>Key Access</h3>'); |
if ($keytype eq 'course') { |
if ($cenv{'keyaccess'} eq 'yes') { |
$r->print('<h3>'.&mt('Key Access').'</h3>'); |
$r->print('Access to this course is key controlled.<br /><input type="submit" name="toggle" value="Open Access" />') |
if ($cenv{'keyaccess'} eq 'yes') { |
|
$r->print(&mt('Access to this course is key controlled.'). |
|
'<br /><input type="submit" name="toggle" value="'.&mt('Open Access').'" />') |
} else { |
} else { |
$r->print('Access to this course is open, no access keys.<br /><input type="submit" name="toggle" value="Control Access" />'); |
$r->print(&mt('Access to this course is open, no access keys').'<br /><input type="submit" name="toggle" value="'.&mt('Control Access').'" />'); |
|
} |
|
} else { |
|
$r->print('<h3>'.&mt('Key Authority'). |
|
' <tt>'.$cenv{'num'}.'@'.$cenv{'domain'}.'</tt></h3>'); |
} |
} |
$r->print(<<ENDKEYMENU); |
$r->print(<<ENDKEYMENU); |
<hr /><h3>Generate New Keys</h3> |
<hr /><h3>Generate New Keys</h3> |
Line 267 Number of keys to be generated: <input t
|
Line 261 Number of keys to be generated: <input t
|
Comments/Remarks/Notes: <input type="text" name="comments" size="30" /><br /> |
Comments/Remarks/Notes: <input type="text" name="comments" size="30" /><br /> |
<input type="submit" name="genkeys" value="Generate Keys" /> |
<input type="submit" name="genkeys" value="Generate Keys" /> |
<hr /><h3>List Keys</h3> |
<hr /><h3>List Keys</h3> |
Comments/Remarks/Notes/User/Batch Number: |
Comments/Remarks/Notes/User/Batch Number Filter: |
<input type="text" name="listcom" size="30" value="$batchnumber" /><br /> |
<input type="text" name="listcom" size="30" value="$batchnumber" /><br /> |
<input type="checkbox" name="newonly" /> Unused keys only<br /> |
<input type="checkbox" name="newonly" /> Unused keys only<br /> |
<input type="checkbox" name="checkonly" /> Used keys only<br /> |
<input type="checkbox" name="checkonly" /> Used keys only<br /> |
<input type="submit" name="listkeys" value="List Keys" /> |
<input type="submit" name="listkeys" value="List Keys/Add Comments" /> |
|
<input type="submit" name="listkeyscsv" value="CSV List of Keys" /> |
ENDKEYMENU |
ENDKEYMENU |
$r->print('</form></body></html>'); |
$r->print('</form></body></html>'); |
} |
} |
} else { |
} else { |
# Start page no course id |
# Start page no course id |
$r->content_type('text/html'); |
&Apache::loncommon::content_type($r,'text/html'); |
$r->send_http_header; |
$r->send_http_header; |
$r->print(&header().&Apache::loncommon::coursebrowser_javascript()); |
$r->print(&header().&Apache::loncommon::coursebrowser_javascript()); |
$r->print( |
$r->print( |
'Course ID: <input input type="text" size="25" name="course" value="" />'); |
&mt('Course ID of Key Authority').': <input input type="text" size="25" name="course" value="" />'); |
$r->print('Domain: '.&Apache::loncommon::select_dom_form( |
$r->print(&mt('Domain').': '.&Apache::loncommon::select_dom_form( |
$ENV{'request.role.domain'},'domain')); |
$ENV{'request.role.domain'},'domain')); |
$r->print(&Apache::loncommon::selectcourse_link( |
$r->print(&Apache::loncommon::selectcourse_link( |
'keyform','course','domain')); |
'keyform','course','domain')); |
$r->print('<br /><input type="submit" value="Manage Access Keys" />'); |
$r->print('<br /><input type="submit" value="'.&mt('Manage Access Keys').'" />'); |
$r->print('</form></body></html>'); |
$r->print('</form></body></html>'); |
} |
} |
return OK; |
return OK; |