--- loncom/interface/lonmanagekeys.pm 2003/04/22 21:00:42 1.2 +++ loncom/interface/lonmanagekeys.pm 2003/05/02 16:58:56 1.10 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to manage course access keys # -# $Id: lonmanagekeys.pm,v 1.2 2003/04/22 21:00:42 www Exp $ +# $Id: lonmanagekeys.pm,v 1.10 2003/05/02 16:58:56 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -54,7 +54,53 @@ ENDHEAD # =================================================== Show student list to drop 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(< + function copyallcom(tf) { + for (i=0; i +

List of Keys/Enter New Comments

+ + + +ENDTABLEHEADER + foreach (keys %accesskeys) { + if ($_=~/^error\:/) { + $r->print(''); + } elsif ($accesskeys{$_}=~/$comment/) { + my ($checkout,$com)=split(/\s*\#\s*/,$accesskeys{$_}); + unless ($checkout) { + if ($checkonly) { next; } + } else { + if ($newonly) { next; } + } + $r->print("\n'); + } + } + $r->print('
KeyChecked OutComments/Remarks/NotesEnter Additional Comments/Remarks/Notes
+ + +
No keys have been generated yet.
".$_.''.($checkout? + $checkout:'-').''. + join('
',split(/\s*\;\s*/,$com)). + '
'); + $r->print('
'); + return ''; +# +# Junk below +# + my ($mode,$linkto,$action,$statusmode,$classlist,$keylist); # # Just junk so that this compiles # @@ -122,14 +168,52 @@ sub togglekeyaccess { my %cenv=@_; unless ($cenv{'domain'}) { return; } if ($cenv{'keyaccess'} eq 'yes') { + return 'Removing key access: '. &Apache::lonnet::del('environment',['keyaccess'], $cenv{'domain'},$cenv{'num'}); } else { + return 'Establishing key access: '. &Apache::lonnet::put('environment',{'keyaccess' => 'yes'}, $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 { @@ -151,37 +235,62 @@ sub handler { return HTTP_NOT_ACCEPTABLE; } if ($ENV{'form.cid'}) { - # - # Only output the header information if they did not request csv format - # + my %cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'}); if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) { +# +# CSV Output +# $r->content_type('text/csv'); +# +# Do CSV +# } else { - # Start page +# +# Normal web stuff +# $r->content_type('text/html'); $r->send_http_header; $r->print(&header()); - } - $r->print(''); - 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. ') - } else { - $r->print('Access to this course is open, no access keys. '); - } - $r->print('
'); -# -# do stuff here. -# - if (exists($ENV{'form.state'}) && ($ENV{'form.state'} eq 'csv')) { - $r->print("\n"); - } else { + $r->print( + ''); +# --- Actions + if ($ENV{'form.toggle'}) { + $r->print(&togglekeyaccess(%cenv).'
'); + %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.'
'); + } + 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('

Key Access

'); + if ($cenv{'keyaccess'} eq 'yes') { + $r->print('Access to this course is key controlled.
') + } else { + $r->print('Access to this course is open, no access keys.
'); + } + $r->print(<

Generate New Keys

+Number of keys to be generated:
+Comments/Remarks/Notes:
+ +

List Keys

+Comments/Remarks/Notes/User/Batch Number: +
+ Unused keys only
+ Used keys only
+ +ENDKEYMENU $r->print(''); } } else {