[LON-CAPA-cvs] cvs: loncom /interface lonmanagekeys.pm

www lon-capa-cvs@mail.lon-capa.org
Wed, 23 Apr 2003 20:29:17 -0000


www		Wed Apr 23 16:29:17 2003 EDT

  Modified files:              
    /loncom/interface	lonmanagekeys.pm 
  Log:
  Access keys (saving my work)
  
  
Index: loncom/interface/lonmanagekeys.pm
diff -u loncom/interface/lonmanagekeys.pm:1.4 loncom/interface/lonmanagekeys.pm:1.5
--- loncom/interface/lonmanagekeys.pm:1.4	Wed Apr 23 09:11:45 2003
+++ loncom/interface/lonmanagekeys.pm	Wed Apr 23 16:29:17 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to manage course access keys 
 #
-# $Id: lonmanagekeys.pm,v 1.4 2003/04/23 13:11:45 www Exp $
+# $Id: lonmanagekeys.pm,v 1.5 2003/04/23 20:29:17 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -136,13 +136,17 @@
 
 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'},$comments).' of '.$num.
-    ' access keys.';
+    ($num,$cenv{'domain'},$cenv{'num'},$batchnumber.'; '.$comments).' of '.
+    $num.' access keys (Batch Number: '.$batchnumber.')',$batchnumber;
 }
 
 ###################################################################
@@ -190,23 +194,32 @@
 		$r->print(&togglekeyaccess(%cenv).'<br />');
 		%cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'});
 	    }
+            my $batchnumber='';
 	    if ($ENV{'form.genkeys'}) {
-		$r->print(
-	      &genkeys($ENV{'form.num'},$ENV{'form.comments'},%cenv).'<br />');
+		(my $msg,$batchnumber)=
+		    &genkeys($ENV{'form.num'},$ENV{'form.comments'},%cenv);
+                $r->print($msg.'<br />');
 	    }
+            if ($ENV{'form.listkeys'}) {
+		&show_key_list($ENV{'form.listcom'},%cenv);
+            }
 # --- Menu
 	    $r->print('<h3>Key Access</h3>');
 	    if ($cenv{'keyaccess'} eq 'yes') {
-		$r->print('Access to this course is key controlled. <input type="submit" name="toggle" value="Open Access" />')
+		$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. <input type="submit" name="toggle" value="Control Access" />');
+		    $r->print('Access to this course is open, no access keys.<br /><input type="submit" name="toggle" value="Control Access" />');
 	    }
-	    $r->print(<<ENDKEYGEN);
+	    $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" />
-ENDKEYGEN
+<hr /><h3>List Keys</h3>
+Comments/Remarks/Notes/Batch Number:
+<input type="text" name="listcom" size="30" value="$batchnumber" /><br />
+<input type="submit" name="listkeys" value="List Keys" />
+ENDKEYMENU
 	    $r->print('</form></body></html>');
 	}
     } else {