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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Mon, 30 Jul 2007 00:31:28 -0000


This is a MIME encoded message

--raeburn1185755488
Content-Type: text/plain

raeburn		Sun Jul 29 20:31:28 2007 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm loncommon.pm 
  Log:
  - moved a couple of javascript functions  - setSearch() and validateEntry() - from loncreateuser::print_username_entry_form() to loncommon::user_picker() to keep functionality together.
  
  - loncreateuser now performs 'is contained in' type searches by username for domain or course.   
  
  
--raeburn1185755488
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20070729203128.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.161 loncom/interface/loncreateuser.pm:1.162
--- loncom/interface/loncreateuser.pm:1.161	Sun Jul 29 00:32:44 2007
+++ loncom/interface/loncreateuser.pm	Sun Jul 29 20:31:27 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.161 2007/07/29 04:32:44 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.162 2007/07/30 00:31:27 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -200,111 +200,13 @@
         $formtoset = 'docustom';
         $env{'form.rolename'} = $env{'form.startrolename'};
     }
-    my ($newuserscript,$newuservalidate);
-
-    if ($forcenewuser) {
-        $newuserscript = <<"ENDSCRIPT";
-
-function setSearch() {
-    var createnew = 0;
-    for (var i=0; i<document.crtuser.forcenew.length; i++) {
-        if (document.crtuser.forcenew[i].checked) {
-            if (document.crtuser.forcenew[i].value == 1) {
-                createnew = 1;
-            }
-        }
-    } 
-    if (createnew == 1) {
-        for (var i=0; i<document.crtuser.srchby.length; i++) {
-            if (document.crtuser.srchby.options[i].value == 'uname') {
-                document.crtuser.srchby.selectedIndex = i;
-            }
-        }
-        for (var i=0; i<document.crtuser.srchin.length; i++) {
-            if (document.crtuser.srchin.options[i].value == 'dom') {
-                document.crtuser.srchin.selectedIndex = i;
-            }
-        }
-        for (var i=0; i<document.crtuser.srchtype.length; i++) {
-            if (document.crtuser.srchtype.options[i].value == 'exact') {
-                document.crtuser.srchtype.selectedIndex = i;
-            }
-        }
-        for (var i=0; i<document.crtuser.srchdomain.length; i++) {
-            if (document.crtuser.srchdomain.options[i].value == '$env{'request.role.domain'}') {
-                document.crtuser.srchdomain.selectedIndex = i;
-            }
-        }
-    }
-}
-ENDSCRIPT
-        $newuservalidate = <<"ENDBLOCK";
-    setSearch();
-ENDBLOCK
-    }
-    my $validatescript = <<"ENDSCRIPT";
-
-function validateEntry() {
-    var checkok = 1;
-    var srchin = document.crtuser.srchin.options[document.crtuser.srchin.selectedIndex].value;
-    var srchtype = document.crtuser.srchtype.options[document.crtuser.srchtype.selectedIndex].value;
-    var srchby = document.crtuser.srchby.options[document.crtuser.srchby.selectedIndex].value;
-    var srchdomain = document.crtuser.srchdomain.options[document.crtuser.srchdomain.selectedIndex].value;
-    var srchterm =  document.crtuser.srchterm.value;
-    var msg = "";
-
-    if (srchterm == "") {
-        checkok = 0;
-        msg += "You must include some text to search for.\\n";
-    }
-
-    $newuservalidate
-
-    if (srchtype== 'contains') {
-        if (srchterm.length < 3) {
-            checkok = 0;
-            msg += "The text you are searching for must contain at least three characters when using a 'contained in' type search.\\n";   
-        }
-    }
-    if (srchin == 'instd') {
-        if (srchdomain == '') {
-            checkok = 0;
-            msg += "You must choose a domain when using an institutional directory search.\\n"; 
-        }
-    }
-    if (srchin == 'dom') {
-        if (srchdomain == '') {
-            checkok = 0;
-            msg += "You must choose a domain when using a domain search.\\n";
-        }
-    }
-    if (srchby == 'lastfirst') {
-        if (srchterm.indexOf(",") == -1) {
-            checkok = 0;
-            msg += "When using searching by last,first you must include a comma as separator between last name and first name.\\n";
-        }
-        if (srchterm.indexOf(",") == srchterm.length -1) { 
-            checkok = 0;
-            msg += "When searching by last,first you must include at least one character in the first name.\\n";
-        }
-    }
-    if (checkok == 0) {
-        alert("The following need to be corrected before the search can be run:\\n"+msg);
-        return;
-    }
-    if (checkok == 1) {
-        document.crtuser.submit();
-    }
-}
-
-ENDSCRIPT
 
     my ($jsback,$elements) = &crumb_utilities();
 
     my $jscript = &Apache::loncommon::studentbrowser_javascript()."\n".
         '<script type"text/javascript">'."\n".
         &Apache::lonhtmlcommon::set_form_elements($elements->{$formtoset}).
-        $newuserscript.$validatescript.'</script>'."\n";
+        '</script>'."\n";
 
     my %loaditems = (
                 'onload' => "javascript:setFormElements(document.$formtoset)",
@@ -516,8 +418,6 @@
     $loginscript  = &Apache::loncommon::authform_header(%param);
     $authformkrb  = &Apache::loncommon::authform_kerberos(%param);
 
-    $ccuname =&LONCAPA::clean_username($ccuname);
-    $ccdomain=&LONCAPA::clean_domain($ccdomain);
     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
     my $dc_setcourse_code = '';
     my $nondc_setsection_code = '';                                        
@@ -768,12 +668,12 @@
                          srchby => 'uname',
                          srchtype => 'exact',
                        };
-        if ((exists($env{'form.seluname'})) && (exists($env{'form.seludom'}))) {
+        if ($env{'form.phase'} eq 'userpicked') {
             $instsrch->{'srchterm'} = $env{'form.seluname'};
             $instsrch->{'srchdomain'} = $env{'form.seludom'};
         } else {
-            $instsrch->{'srchterm'} = $env{'form.srchterm'};
-            $instsrch->{'srchdomain'} = $env{'form.srchdomain'},
+            $instsrch->{'srchterm'} = $ccuname;
+            $instsrch->{'srchdomain'} = $ccdomain,
         }
         if (($instsrch->{'srchterm'} ne '') && ($instsrch->{'srchdomain'} ne '')) {
             $newuser = $instsrch->{'srchterm'}.':'.$instsrch->{'srchdomain'};
@@ -784,7 +684,7 @@
                 %dirsrch_results = &Apache::lonnet::inst_directory_query($instsrch);
                 if (ref($dirsrch_results{$newuser}) eq 'HASH') { 
                     %inst_results = %{$dirsrch_results{$newuser}};
-                } 
+                }
             }
         }
         my $home_server_list=
@@ -2236,11 +2136,13 @@
            if ($env{'form.phase'} eq 'get_user_info') {
                my ($state,$response,$forcenewuser,$results) = 
                    &user_search_result($srch);
+               print STDERR "Got $state,$response,$forcenewuser\n";
                if ($state eq 'select') {
                    &print_user_selection_page($r,$response,$srch,$results);
                } elsif ($state eq 'modify') {
                    my ($ccuname,$ccdomain);
-                   if ($srch->{'srchby'} eq 'uname') {
+                   if (($srch->{'srchby'} eq 'uname') && 
+                       ($srch->{'srchtype'} eq 'exact')) {
                        $ccuname = $srch->{'srchterm'};
                        $ccdomain= $srch->{'srchdomain'};
                    } else {
@@ -2336,18 +2238,37 @@
                 }
             } else {
                 if ($srch->{'srchin'} eq 'dom') {
-                    my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
-                    if ($uhome eq 'no_host') {
+                    if ($srch->{'srchtype'} eq 'exact') {
+                        my $uhome=&Apache::lonnet::homeserver($srch->{'srchterm'},$srch->{'srchdomain'});
+                        if ($uhome eq 'no_host') {
+                            ($state,$response,$forcenewuser) =
+                                &build_search_response($srch,%srch_results);
+                        } else {
+                            $state = 'modify';
+                        }
+                    } else {
+                        %srch_results = &Apache::lonnet::usersearch($srch);
                         ($state,$response,$forcenewuser) =
                             &build_search_response($srch,%srch_results);
-                    } else {
-                        $state = 'modify';
                     }
                 } else {
                     my %courseusers = &get_courseusers();
-                    if (exists($courseusers{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
-                        $state = 'modify';
+                    if ($srch->{'srchtype'} eq 'exact') {
+                        if (exists($courseusers{$srch->{'srchterm'}.':'.$srch->{'srchdomain'}})) {
+                            $state = 'modify';
+                        } else {
+                            ($state,$response,$forcenewuser) =
+                                &build_search_response($srch,%srch_results);
+                        }
                     } else {
+                        foreach my $user (keys(%courseusers)) {
+                            my ($cuname,$cudomain) = split(/:/,$user);
+                            if ($cudomain eq $srch->{'srchdomain'}) {
+                                if ($cuname =~ /\Q$srch->{'srchterm'}\E/i) {
+                                    $srch_results{$user} = '';
+                                }
+                            }
+                        }
                         ($state,$response,$forcenewuser) =
                             &build_search_response($srch,%srch_results);
                     }
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.555 loncom/interface/loncommon.pm:1.556
--- loncom/interface/loncommon.pm:1.555	Sat Jul 28 17:38:29 2007
+++ loncom/interface/loncommon.pm	Sun Jul 29 20:31:28 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.555 2007/07/28 21:38:29 raeburn Exp $
+# $Id: loncommon.pm,v 1.556 2007/07/30 00:31:28 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5617,7 +5617,106 @@
     }
     $srchtypesel .= "\n  </select>\n";
 
+    my ($newuserscript,$newuservalidate);
+
+    if ($forcenewuser) {
+        $newuserscript = <<"ENDSCRIPT";
+
+function setSearch() {
+    var createnew = 0;
+    for (var i=0; i<document.crtuser.forcenew.length; i++) {
+        if (document.crtuser.forcenew[i].checked) {
+            if (document.crtuser.forcenew[i].value == 1) {
+                createnew = 1;
+            }
+        }
+    }
+    if (createnew == 1) {
+        for (var i=0; i<document.crtuser.srchby.length; i++) {
+            if (document.crtuser.srchby.options[i].value == 'uname') {
+                document.crtuser.srchby.selectedIndex = i;
+            }
+        }
+        for (var i=0; i<document.crtuser.srchin.length; i++) {
+            if (document.crtuser.srchin.options[i].value == 'dom') {
+                document.crtuser.srchin.selectedIndex = i;
+            }
+        }
+        for (var i=0; i<document.crtuser.srchtype.length; i++) {
+            if (document.crtuser.srchtype.options[i].value == 'exact') {
+                document.crtuser.srchtype.selectedIndex = i;
+            }
+        }
+        for (var i=0; i<document.crtuser.srchdomain.length; i++) {
+            if (document.crtuser.srchdomain.options[i].value == '$env{'request.role.domain'}') {
+                document.crtuser.srchdomain.selectedIndex = i;
+            }
+        }
+    }
+}
+ENDSCRIPT
+        $newuservalidate = <<"ENDBLOCK";
+setSearch();
+ENDBLOCK
+    }
+
     my $output = <<"END_BLOCK";
+<script type="text/javascript">
+function validateEntry() {
+    $newuservalidate
+    var checkok = 1;
+    var srchin = document.crtuser.srchin.options[document.crtuser.srchin.selectedIndex].value;
+    var srchtype = document.crtuser.srchtype.options[document.crtuser.srchtype.selectedIndex].value;
+    var srchby = document.crtuser.srchby.options[document.crtuser.srchby.selectedIndex].value;
+    var srchdomain = document.crtuser.srchdomain.options[document.crtuser.srchdomain.selectedIndex].value;
+    var srchterm =  document.crtuser.srchterm.value;
+    var msg = "";
+
+    if (srchterm == "") {
+        checkok = 0;
+        msg += "You must include some text to search for.\\n";
+    }
+
+    if (srchtype== 'contains') {
+        if (srchterm.length < 3) {
+            checkok = 0;
+            msg += "The text you are searching for must contain at least three characters when using a 'contained in' type search.\\n";
+        }
+    }
+    if (srchin == 'instd') {
+        if (srchdomain == '') {
+            checkok = 0;
+            msg += "You must choose a domain when using an institutional directory search.\\n";
+        }
+    }
+    if (srchin == 'dom') {
+        if (srchdomain == '') {
+            checkok = 0;
+            msg += "You must choose a domain when using a domain search.\\n";
+        }
+    }
+    if (srchby == 'lastfirst') {
+        if (srchterm.indexOf(",") == -1) {
+            checkok = 0;
+            msg += "When using searching by last,first you must include a comma as separator between last name and first name.\\n";
+        }
+        if (srchterm.indexOf(",") == srchterm.length -1) {
+            checkok = 0;
+            msg += "When searching by last,first you must include at least one character in the first name.\\n";
+        }
+    }
+    if (checkok == 0) {
+        alert("The following need to be corrected before the search can be run:\\n"+msg);
+        return;
+    }
+    if (checkok == 1) {
+        document.crtuser.submit();
+    }
+}
+
+$newuserscript
+
+</script>
 <table>
 <tr>
  <td align="right">$lt{'usr'}:</td><td><input type="text" size="15" name="srchterm" value="$srchterm" /></td>
@@ -5646,6 +5745,8 @@
     return $output;
 }
 
+
+
 =pod
 
 =back

--raeburn1185755488--