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

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 18 Apr 2002 20:16:44 -0000


matthew		Thu Apr 18 16:16:44 2002 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
  Log:
  Changes made to javascript in the hopes of being able to later move them
  to loncommon.pm so that londropadd.pm can also use them.
  
  
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.29 loncom/interface/loncreateuser.pm:1.30
--- loncom/interface/loncreateuser.pm:1.29	Thu Apr  4 16:46:44 2002
+++ loncom/interface/loncreateuser.pm	Thu Apr 18 16:16:43 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.29 2002/04/04 21:46:44 matthew Exp $
+# $Id: loncreateuser.pm,v 1.30 2002/04/18 20:16:43 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -47,7 +47,7 @@
 # 11/12,11/13,11/15 Scott Harrison
 # 02/11/02 Matthew Hall
 #
-# $Id: loncreateuser.pm,v 1.29 2002/04/04 21:46:44 matthew Exp $
+# $Id: loncreateuser.pm,v 1.30 2002/04/18 20:16:43 matthew Exp $
 ###
 
 package Apache::loncreateuser;
@@ -70,109 +70,106 @@
     $krbdefdom=~tr/a-z/A-Z/;
     $authformnop=(<<END);
 <p>
-<input type="radio" name="login" value="" checked="checked"
-onClick="clicknop(this.form);">
+<input type="radio" name="login" value="nochange" checked="checked"
+       onclick="changed_radio('nochange',document.cu);">
 Do not change login data
 </p>
 END
     $authformkrb=(<<END);
 <p>
-<input type=radio name=login value=krb onClick="clickkrb(this.form);">
+<input type="radio" name="login" value="krb" 
+       onclick="changed_radio('krb',document.cu);">
 Kerberos authenticated with domain
-<input type=text size=10 name=krbdom onChange="setkrb(this.form);">
+<input type="text" size="10" name="krbarg" 
+       onclick="changed_text('krb',document.cu);"
+       onchange="changed_text('krb',document.cu);">
 </p>
 END
     $authformint=(<<END);
 <p>
-<input type=radio name=login value=int onClick="clickint(this.form);"> 
+<input type="radio" name="login" value="int" 
+       onclick="changed_radio('int',document.cu);"> 
 Internally authenticated (with initial password 
-<input type=text size=10 name=intpwd onChange="setint(this.form);">)
+<input type="text" size="10" name="intarg" 
+       onclick="changed_text('int',document.cu);"
+       onchange="changed_text('int',document.cu);">
 </p>
 END
     $authformfsys=(<<END);
 <p>
-<input type=radio name=login value=fsys onClick="clickfsys(this.form);"> 
+<input type="radio" name="login" value="fsys" 
+       onclick="changed_radio('fsys',document.cu);"> 
 Filesystem authenticated (with initial password 
-<input type=text size=10 name=fsyspwd onChange="setfsys(this.form);">)
+<input type="text" size="10" name="fsysarg"
+       onclick="changed_text('fsys',document.cu);"
+       onchange="changed_text('fsys',document.cu);">
 </p>
 END
     $authformloc=(<<END);
 <p>
-<input type=radio name=login value=loc onClick="clickloc(this.form);" />
+<input type="radio" name="login" value="loc"
+       onclick="changed_radio('loc',document.cu);"> 
 Local Authentication with argument
-<input type=text size=10 name=locarg onChange="setloc(this.form);" />
+<input type="text" size="10" name="locarg" 
+       onclick="changed_text('loc',document.cu);"
+       onchange="changed_text('loc',document.cu);">
 </p>
 END
     $loginscript=(<<ENDLOGINSCRIPT);
 <script>
-function setkrb(vf) {
-    if (vf.krbdom.value!='') {
-       vf.login[0].checked=true;
-       vf.krbdom.value=vf.krbdom.value.toUpperCase();
-       vf.intpwd.value='';
-       vf.fsyspwd.value='';
-       vf.locarg.value='';
-   }
-}
-
-function setint(vf) {
-    if (vf.intpwd.value!='') {
-       vf.login[1].checked=true;
-       vf.krbdom.value='';
-       vf.fsyspwd.value='';
-       vf.locarg.value='';
-   }
-}
-
-function setfsys(vf) {
-    if (vf.fsyspwd.value!='') {
-       vf.login[2].checked=true;
-       vf.krbdom.value='';
-       vf.intpwd.value='';
-       vf.locarg.value='';
-   }
-}
 
-function setloc(vf) {
-    if (vf.locarg.value!='') {
-       vf.login[3].checked=true;
-       vf.krbdom.value='';
-       vf.intpwd.value='';
-       vf.fsyspwd.value='';
-   }
-}
-
-function clicknop(vf) {
-    vf.krbdom.value='';
-    vf.intpwd.value='';
-    vf.fsyspwd.value='';
-    vf.locarg.value='';
+var authvalues = new Object();
+authvalues.names = new Array('krbarg','intarg','fsysarg','locarg');
+authvalues.defaults = new Array('MSU.EDU','','','');
+
+function changed_radio(choice,currentform) {
+    var choicearg = choice + 'arg';
+    if (currentform.elements[choicearg].value == '') {
+        clear(currentform,authvalues.names);
+        for (var i=0; i<authvalues.names.length; i++) {
+            if (authvalues.names[i] == choicearg) {
+                currentform.elements[choicearg].value = authvalues.defaults[i];
+            }
+        }
+    }
 }
 
-function clickkrb(vf) {
-    vf.krbdom.value='$krbdefdom';
-    vf.intpwd.value='';
-    vf.fsyspwd.value='';
-    vf.locarg.value='';
+function changed_text(choice,currentform) {
+    var choicearg = choice + 'arg';
+    if (currentform.elements[choicearg].value !='') {
+        // clear the other values
+        var keep = currentform.elements[choicearg].value;
+        clear(currentform,authvalues.names);
+        currentform.elements[choicearg].value = keep;
+        // validate our value
+        if (choice == 'krb') {
+            currentform.elements[choicearg].value = keep.toUpperCase();
+        }
+        // check the appropriate checkbox
+        set_checked('login',choice,currentform);
+    } 
 }
 
-function clickint(vf) {
-    vf.krbdom.value='';
-    vf.fsyspwd.value='';
-    vf.locarg.value='';
+function clear(currentform,names) {
+    for (var i=0; i< currentform.elements.length; i++) {
+        for (var j = 0; j< names.length; j++) {
+            if (currentform.elements[i].name == names[j]) {
+                currentform.elements[i].value = '';
+            }
+        }
+    }
 }
 
-function clickfsys(vf) {
-    vf.krbdom.value='';
-    vf.intpwd.value='';
-    vf.locarg.value='';
+function set_checked(name,choice,currentform) {
+    for (var i=0; i< currentform.elements.length; i++) {
+        if (currentform.elements[i].name == name) {
+            if (currentform.elements[i].value == choice) {
+                currentform.elements[i].checked =true;
+            }
+        }
+    }
 }
 
-function clickloc(vf) {
-    vf.krbdom.value='';
-    vf.intpwd.value='';
-    vf.fsyspwd.value='';
-}
 </script>
 ENDLOGINSCRIPT
     $generalrule=<<END;
@@ -626,17 +623,20 @@
     my $genpwd='';
     if ($ENV{'form.login'} eq 'krb') {
 	$amode='krb4';
-	$genpwd=$ENV{'form.krbdom'};
+	$genpwd=$ENV{'form.krbarg'};
     } elsif ($ENV{'form.login'} eq 'int') {
 	$amode='internal';
-	$genpwd=$ENV{'form.intpwd'};
+	$genpwd=$ENV{'form.intarg'};
     } elsif ($ENV{'form.login'} eq 'fsys') {
 	$amode='unix';
-	$genpwd=$ENV{'form.fsyspwd'};
+	$genpwd=$ENV{'form.fsysarg'};
     } elsif ($ENV{'form.login'} eq 'loc') {
 	$amode='localauth';
 	$genpwd=$ENV{'form.locarg'};
 	$genpwd=" " if (!$genpwd);
+    } else {
+	    $r->print($error.'Invalid login mode or password'.$end);    
+	    return;
     }
     if ($ENV{'form.makeuser'}) {
         # Create a new user