version 1.2, 2003/04/22 21:00:42
|
version 1.10, 2003/05/02 16:58:56
|
Line 54 ENDHEAD
|
Line 54 ENDHEAD
|
|
|
# =================================================== Show student list to drop |
# =================================================== Show student list to drop |
sub show_key_list { |
sub show_key_list { |
my ($r,$mode,$linkto,$action,$statusmode,$classlist,$keylist)=@_; |
my ($r,$comment,$newonly,$checkonly,%cenv)=@_; |
|
$comment=~s/\W/\./g; |
|
my %accesskeys=&Apache::lonnet::dump |
|
('accesskeys',$cenv{'domain'},$cenv{'num'}); |
|
$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) { |
|
if ($_=~/^error\:/) { |
|
$r->print('<tr><td>No keys have been generated yet.</td></tr>'); |
|
} elsif ($accesskeys{$_}=~/$comment/) { |
|
my ($checkout,$com)=split(/\s*\#\s*/,$accesskeys{$_}); |
|
unless ($checkout) { |
|
if ($checkonly) { next; } |
|
} else { |
|
if ($newonly) { next; } |
|
} |
|
$r->print("\n<tr><td><tt>".$_.'</tt></td><td>'.($checkout? |
|
$checkout:'-').'</td><td>'. |
|
join('<br />',split(/\s*\;\s*/,$com)). |
|
'</td><td><input type="text" size="40" name="com_'.$_. |
|
'" value="" /></td></tr>'); |
|
} |
|
} |
|
$r->print('</table>'); |
|
$r->print('<input type="submit" name="addcom" value="Add Above Comments to Keys" /><hr />'); |
|
return ''; |
|
# |
|
# Junk below |
|
# |
|
my ($mode,$linkto,$action,$statusmode,$classlist,$keylist); |
# |
# |
# Just junk so that this compiles |
# Just junk so that this compiles |
# |
# |
Line 122 sub togglekeyaccess {
|
Line 168 sub togglekeyaccess {
|
my %cenv=@_; |
my %cenv=@_; |
unless ($cenv{'domain'}) { return; } |
unless ($cenv{'domain'}) { return; } |
if ($cenv{'keyaccess'} eq 'yes') { |
if ($cenv{'keyaccess'} eq 'yes') { |
|
return 'Removing key access: '. |
&Apache::lonnet::del('environment',['keyaccess'], |
&Apache::lonnet::del('environment',['keyaccess'], |
$cenv{'domain'},$cenv{'num'}); |
$cenv{'domain'},$cenv{'num'}); |
} else { |
} else { |
|
return 'Establishing key access: '. |
&Apache::lonnet::put('environment',{'keyaccess' => 'yes'}, |
&Apache::lonnet::put('environment',{'keyaccess' => 'yes'}, |
$cenv{'domain'},$cenv{'num'}); |
$cenv{'domain'},$cenv{'num'}); |
} |
} |
} |
} |
|
|
|
# --------------------------------------------------------------- Generate Keys |
|
|
|
sub genkeys { |
|
my ($num,$comments,%cenv)=@_; |
|
unless ($comments) { $comments=''; } |
|
$comments=~s/\#/ /g; |
|
$comments=~s/\;/ /g; |
|
unless ($num) { return 'No number of keys given.'; } |
|
unless (($num=~/^\d+$/) && ($num>0)) { |
|
return 'Invalid number of keys given.'; |
|
} |
|
my $batchnumber='BATCH_'.time().'_'.$$; |
|
return 'Generated '.&Apache::lonnet::generate_access_keys |
|
($num,$cenv{'domain'},$cenv{'num'},$batchnumber.'; '.$comments).' of '. |
|
$num.' access keys (Batch Number: '.$batchnumber.')',$batchnumber; |
|
} |
|
|
|
# ---------------------------------------------------------------- Add comments |
|
|
|
sub addcom { |
|
my %cenv=@_; |
|
my %newcomment=(); |
|
undef %newcomment; |
|
foreach (keys %ENV) { |
|
if ($_=~/^form\.com\_(.+)$/) { |
|
my $key=$1; |
|
my $comment=$ENV{$_}; |
|
$comment=~s/^\s+//gs; |
|
if ($comment) { |
|
&Apache::lonnet::comment_access_key |
|
($key,$cenv{'domain'},$cenv{'num'},$comment); |
|
} |
|
} |
|
} |
|
return ''; |
|
} |
################################################################### |
################################################################### |
################################################################### |
################################################################### |
sub handler { |
sub handler { |
Line 151 sub handler {
|
Line 235 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'}); |
# Only output the header information if they did not request csv format |
|
# |
|
if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) { |
if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) { |
|
# |
|
# CSV Output |
|
# |
$r->content_type('text/csv'); |
$r->content_type('text/csv'); |
|
# |
|
# Do CSV |
|
# |
} else { |
} else { |
# Start page |
# |
|
# Normal web stuff |
|
# |
$r->content_type('text/html'); |
$r->content_type('text/html'); |
$r->send_http_header; |
$r->send_http_header; |
$r->print(&header()); |
$r->print(&header()); |
} |
|
$r->print('<input type="hidden" name="cid" value="'.$ENV{'form.cid'}. |
|
'" />'); |
|
my %cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'}); |
|
if ($ENV{'form.toggle'}) { |
|
&togglekeyaccess(%cenv); |
|
%cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'}); |
|
} |
|
if ($cenv{'keyaccess'} eq 'yes') { |
|
$r->print('Access to this course is key controlled. <input type="submit" name="toggle" value="Open Access" />') |
|
} else { |
|
$r->print('Access to this course is open, no access keys. <input type="submit" name="toggle" value="Control Access" />'); |
|
} |
|
$r->print('<hr />'); |
|
# |
|
# do stuff here. |
|
# |
|
|
|
if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) { |
$r->print( |
$r->print("\n"); |
'<input type="hidden" name="cid" value="'.$ENV{'form.cid'}.'" />'); |
} else { |
# --- Actions |
|
if ($ENV{'form.toggle'}) { |
|
$r->print(&togglekeyaccess(%cenv).'<br />'); |
|
%cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'}); |
|
} |
|
my $batchnumber=''; |
|
if ($ENV{'form.genkeys'}) { |
|
(my $msg,$batchnumber)= |
|
&genkeys($ENV{'form.num'},$ENV{'form.comments'},%cenv); |
|
$r->print($msg.'<br />'); |
|
} |
|
if ($ENV{'form.listkeys'}) { |
|
&show_key_list($r,$ENV{'form.listcom'}, |
|
$ENV{'form.newonly'},$ENV{'form.checkonly'},%cenv); |
|
} |
|
if ($ENV{'form.addcom'}) { |
|
&addcom(%cenv); |
|
} |
|
# --- Menu |
|
$r->print('<h3>Key Access</h3>'); |
|
if ($cenv{'keyaccess'} eq 'yes') { |
|
$r->print('Access to this course is key controlled.<br /><input type="submit" name="toggle" value="Open Access" />') |
|
} else { |
|
$r->print('Access to this course is open, no access keys.<br /><input type="submit" name="toggle" value="Control Access" />'); |
|
} |
|
$r->print(<<ENDKEYMENU); |
|
<hr /><h3>Generate New Keys</h3> |
|
Number of keys to be generated: <input type="text" name="num" size="6" /><br /> |
|
Comments/Remarks/Notes: <input type="text" name="comments" size="30" /><br /> |
|
<input type="submit" name="genkeys" value="Generate Keys" /> |
|
<hr /><h3>List Keys</h3> |
|
Comments/Remarks/Notes/User/Batch Number: |
|
<input type="text" name="listcom" size="30" value="$batchnumber" /><br /> |
|
<input type="checkbox" name="newonly" /> Unused keys only<br /> |
|
<input type="checkbox" name="checkonly" /> Used keys only<br /> |
|
<input type="submit" name="listkeys" value="List Keys" /> |
|
ENDKEYMENU |
$r->print('</form></body></html>'); |
$r->print('</form></body></html>'); |
} |
} |
} else { |
} else { |