--- loncom/interface/lonmanagekeys.pm 2003/09/23 00:26:10 1.13 +++ loncom/interface/lonmanagekeys.pm 2014/12/11 01:48:54 1.27 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Handler to manage course access keys # -# $Id: lonmanagekeys.pm,v 1.13 2003/09/23 00:26:10 www Exp $ +# $Id: lonmanagekeys.pm,v 1.27 2014/12/11 01:48:54 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,7 +31,7 @@ package Apache::lonmanagekeys; use strict; -use Apache::lonnet(); +use Apache::lonnet; use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::Constants qw(:common :http REDIRECT); @@ -41,13 +41,15 @@ use Apache::lonlocal; ############################################################### ############################################################### sub header { - my $bodytag=&Apache::loncommon::bodytag('Access Key Management'); + # Breadcrumbs + my $brcrum = [{'href' => '/adm/managekeys', + 'text' => 'Access Key Management'}]; + + my $start_page=&Apache::loncommon::start_page('Access Key Management', + undef, + {'bread_crumbs' => $brcrum,}); return(<<ENDHEAD); -<html> -<head> -<title>LON-CAPA Access Key Management</title> -</head> -$bodytag +$start_page <form method="post" enctype="multipart/form-data" action="/adm/managekeys" name="keyform"> ENDHEAD @@ -76,11 +78,11 @@ sub show_key_list { <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);" /> +<input type="button" value="Copy to All" onclick="copyallcom(this.form);" /> </th></tr> ENDTABLEHEADER } - foreach (keys %accesskeys) { + foreach (keys(%accesskeys)) { if ($_=~/^error\:/) { $r->print('<tr><td>No keys have been generated yet.</td></tr>'); } elsif ($accesskeys{$_}=~/$comment/) { @@ -157,10 +159,10 @@ sub addcom { my %cenv=@_; my %newcomment=(); undef %newcomment; - foreach (keys %ENV) { + foreach (keys(%env)) { if ($_=~/^form\.com\_(.+)$/) { my $key=$1; - my $comment=$ENV{$_}; + my $comment=$env{$_}; $comment=~s/^\s+//gs; if ($comment) { &Apache::lonnet::comment_access_key @@ -181,18 +183,28 @@ sub handler { } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['state','cid']); - if (($ENV{'form.domain'}) && ($ENV{'form.course'})) { - $ENV{'form.cid'}=$ENV{'form.domain'}.'_'.$ENV{'form.course'}; + if (($env{'form.domain'}) && ($env{'form.course'})) { + $env{'form.cid'}=$env{'form.domain'}.'_'.$env{'form.course'}; } - unless (&Apache::lonnet::allowed('mky',$ENV{'request.role.domain'})) { - $ENV{'user.error.msg'}= + unless (&Apache::lonnet::allowed('mky',$env{'request.role.domain'})) { + $env{'user.error.msg'}= "/adm/managekeys:mky:0:0:Cannot manage access keys"; return HTTP_NOT_ACCEPTABLE; } - if ($ENV{'form.cid'}) { - my %cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'}); - if ($ENV{'form.listkeyscsv'}) { + if ($env{'form.cid'}) { + my %cenv=&Apache::lonnet::coursedescription($env{'form.cid'}); + 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(/:/,$cenv{'keyauth'}); + $keytype='auth'; + } else { + $keytype='course'; + } + if ($env{'form.listkeyscsv'}) { # # CSV Output # @@ -201,8 +213,8 @@ sub handler { # # Do CSV # - &show_key_list($r,1,$ENV{'form.listcom'}, - $ENV{'form.newonly'},$ENV{'form.checkonly'},%cenv); + &show_key_list($r,1,$env{'form.listcom'}, + $env{'form.newonly'},$env{'form.checkonly'},%cenv); } else { # @@ -213,32 +225,38 @@ sub handler { $r->print(&header()); $r->print( - '<input type="hidden" name="cid" value="'.$ENV{'form.cid'}.'" />'); + '<input type="hidden" name="cid" value="'.$env{'form.cid'}.'" />'); # --- Actions - if ($ENV{'form.toggle'}) { + if ($env{'form.toggle'}) { $r->print(&togglekeyaccess(%cenv).'<br />'); - %cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'}); + %cenv=&Apache::lonnet::coursedescription($env{'form.cid'}, + {'freshen_cache'=> 1}); } my $batchnumber=''; - if ($ENV{'form.genkeys'}) { + if ($env{'form.genkeys'}) { (my $msg,$batchnumber)= - &genkeys($ENV{'form.num'},$ENV{'form.comments'},%cenv); + &genkeys($env{'form.num'},$env{'form.comments'},%cenv); $r->print($msg.'<br />'); } - if ($ENV{'form.listkeys'}) { - &show_key_list($r,0,$ENV{'form.listcom'}, - $ENV{'form.newonly'},$ENV{'form.checkonly'},%cenv); + if ($env{'form.listkeys'}) { + &show_key_list($r,0,$env{'form.listcom'}, + $env{'form.newonly'},$env{'form.checkonly'},%cenv); } - if ($ENV{'form.addcom'}) { + if ($env{'form.addcom'}) { &addcom(%cenv); } # --- Menu - $r->print('<h3>'.&mt('Key Access').'</h3>'); - if ($cenv{'keyaccess'} eq 'yes') { - $r->print(&mt('Access to this course is key controlled.'). + if ($keytype eq 'course') { + $r->print('<h3>'.&mt('Key Access').'</h3>'); + 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 { $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); <hr /><h3>Generate New Keys</h3> @@ -248,26 +266,35 @@ Comments/Remarks/Notes: <input type="tex <hr /><h3>List Keys</h3> Comments/Remarks/Notes/User/Batch Number Filter: <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 /> +<label><input type="checkbox" name="newonly" /> Unused keys only</label><br /> +<label><input type="checkbox" name="checkonly" /> Used keys only</label><br /> <input type="submit" name="listkeys" value="List Keys/Add Comments" /> <input type="submit" name="listkeyscsv" value="CSV List of Keys" /> ENDKEYMENU - $r->print('</form></body></html>'); + $r->print('</form>'.&Apache::loncommon::end_page()); } } else { # Start page no course id &Apache::loncommon::content_type($r,'text/html'); $r->send_http_header; $r->print(&header().&Apache::loncommon::coursebrowser_javascript()); - $r->print( - &mt('Course ID').': <input input type="text" size="25" name="course" value="" />'); - $r->print(&mt('Domain').': '.&Apache::loncommon::select_dom_form( - $ENV{'request.role.domain'},'domain')); - $r->print(&Apache::loncommon::selectcourse_link( - 'keyform','course','domain')); - $r->print('<br /><input type="submit" value="'.&mt('Manage Access Keys').'" />'); - $r->print('</form></body></html>'); + $r->print('<br />'); + $r->print(&Apache::lonhtmlcommon::start_pick_box() + .&Apache::lonhtmlcommon::row_title(&mt('Course ID of Key Authority')) + .'<input input type="text" size="25" name="course" value="" />' + .' '.&Apache::loncommon::selectcourse_link( + 'keyform','course','domain', + undef,undef,undef,'Course') + .&Apache::lonhtmlcommon::row_closure() + .&Apache::lonhtmlcommon::row_title(&mt('Domain')) + .&Apache::loncommon::select_dom_form($env{'request.role.domain'},'domain') + .&Apache::lonhtmlcommon::row_closure(1) + .&Apache::lonhtmlcommon::end_pick_box() + ); + $r->print('<input type="submit" value="'.&mt('Next').'" />' + .'</form>' + .&Apache::loncommon::end_page() + ); } return OK; }