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

www lon-capa-cvs@mail.lon-capa.org
Wed, 23 Apr 2003 01:55:52 -0000


www		Tue Apr 22 21:55:52 2003 EDT

  Modified files:              
    /loncom/interface	lonmanagekeys.pm 
  Log:
  Continued work on key access.
  
  
Index: loncom/interface/lonmanagekeys.pm
diff -u loncom/interface/lonmanagekeys.pm:1.2 loncom/interface/lonmanagekeys.pm:1.3
--- loncom/interface/lonmanagekeys.pm:1.2	Tue Apr 22 17:00:42 2003
+++ loncom/interface/lonmanagekeys.pm	Tue Apr 22 21:55:52 2003
@@ -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.3 2003/04/23 01:55:52 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -122,14 +122,28 @@
     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 ($num) { return 'No number of keys given.'; }
+    unless (($num=~/^\d+$/) && ($num>0)) { 
+	return 'Invalid number of keys given.'; 
+    }
+    return 'Generated '.&Apache::lonnet::generate_access_keys
+    ($num,$cenv{'domain'},$cenv{'number'},$comments).' access keys.';
+}
+
 ###################################################################
 ###################################################################
 sub handler {
@@ -151,37 +165,47 @@
         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('<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("\n");
-	} else {
+	    $r->print(
+	    '<input type="hidden" name="cid" value="'.$ENV{'form.cid'}.'" />');
+# --- Actions
+	    if ($ENV{'form.toggle'}) {
+		$r->print(&togglekeyaccess(%cenv).'<br />');
+		%cenv=&Apache::lonnet::coursedescription($ENV{'form.cid'});
+	    }
+	    if ($ENV{'form.genkeys'}) {
+		$r->print(
+	      &genkeys($ENV{'form.num'},$ENV{'form.comments'},%cenv).'<br />');
+	    }
+# --- 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" />')
+		} else {
+		    $r->print('Access to this course is open, no access keys. <input type="submit" name="toggle" value="Control Access" />');
+	    }
+	    $r->print(<<ENDKEYGEN);
+<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
 	    $r->print('</form></body></html>');
 	}
     } else {