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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Fri, 21 Dec 2007 14:05:41 -0000


This is a MIME encoded message

--raeburn1198245941
Content-Type: text/plain

raeburn		Fri Dec 21 09:05:41 2007 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm lonuserutils.pm 
  Log:
  loncreateuser.pm 
  &print_username_entry_form() simplify actions to take depending on $env{'form.action'}
  Pass appropriate $operation arg to &print_user_selection_page() if in "single student" mode instead of "single user"
  Add breadcrumbs and emove duplicate defintion of "action" form element in single student mode 
  Include $usertype (official or nonofficial), if available, in call to lonuserutils::can_create_user()
  
  lonuserutils.pm
  &check_usertype() determine usertype for "username is"-type searches for supplied username.
  
  
--raeburn1198245941
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071221090541.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.213 loncom/interface/loncreateuser.pm:1.214
--- loncom/interface/loncreateuser.pm:1.213	Fri Dec 21 07:41:25 2007
+++ loncom/interface/loncreateuser.pm	Fri Dec 21 09:05:40 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.213 2007/12/21 12:41:25 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.214 2007/12/21 14:05:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -223,15 +223,15 @@
     my $start_page =
 	&Apache::loncommon::start_page('User Management',
 				       $jscript,{'add_entries' => \%loaditems,});
-    if ($env{'form.action'} eq 'singleuser') {
+    if ($env{'form.action'} eq 'custom') {
         &Apache::lonhtmlcommon::add_breadcrumb
           ({href=>"javascript:backPage(document.crtuser)",
-            text=>"Single user search",
-            faq=>282,bug=>'Instructor Interface',});
-    } elsif ($env{'form.action'} eq 'custom') {
+            text=>"Pick custom role",});
+    } else {
         &Apache::lonhtmlcommon::add_breadcrumb
           ({href=>"javascript:backPage(document.crtuser)",
-            text=>"Pick custom role",});
+            text=>"Single user search",
+            faq=>282,bug=>'Instructor Interface',});
     }
     my $crumbs = &Apache::lonhtmlcommon::breadcrumbs('User Management');
     my %existingroles=&Apache::lonuserutils::my_custom_roles();
@@ -245,7 +245,8 @@
                     'ecrp' => "Edit Custom Role Privileges",
                     'nr'   => "Name of Role",
                     'cre'  => "Custom Role Editor",
-                    'mod'  => "to edit user information or add/modify roles",
+                    'mod'  => "to modify user information or add/modify roles",
+                    'enrl' => "to enroll one student",
 				       );
     my $help = &Apache::loncommon::help_open_menu(undef,undef,282,'Instructor Interface');
     my $helpsiur=&Apache::loncommon::help_open_topic('Course_Change_Privileges');
@@ -256,12 +257,7 @@
         $sellink = "$lt{'or'} ".$sellink;
     } 
     $r->print($start_page."\n".$crumbs);
-    if ($env{'form.action'} eq 'singleuser') {
-        $r->print("
-<h3>$lt{'srch'} $sellink $lt{'mod'}$helpsiur</h3>
-$response");
-        $r->print(&entry_form($defdom,$srch,$forcenewuser,$context));
-    } elsif ($env{'form.action'} eq 'custom') {
+    if ($env{'form.action'} eq 'custom') {
         if (&Apache::lonnet::allowed('mcr','/')) {
             $r->print(<<ENDCUSTOM);
 <form action="/adm/createuser" method="post" name="docustom">
@@ -289,15 +285,25 @@
 }
 
 sub entry_form {
-    my ($dom,$srch,$forcenewuser,$context) = @_;
+    my ($dom,$srch,$forcenewuser,$context,$responsemsg) = @_;
     my %domconf = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
-    my $cancreate = &Apache::lonuserutils::can_create_user($dom,$context);
-    if (!$cancreate) {
-        $forcenewuser = '';
+    my $usertype;
+    if (ref($srch) eq 'HASH') {
+        if (($srch->{'srchin'} eq 'dom') &&
+            ($srch->{'srchby'} eq 'uname') &&
+            ($srch->{'srchtype'} eq 'exact') &&
+            ($srch->{'srchdomain'} ne '') &&
+            ($srch->{'srchterm'} ne '')) {
+            my ($rules,$ruleorder) =
+                &Apache::lonnet::inst_userrules($srch->{'srchdomain'},'username');
+            $usertype = &Apache::lonuserutils::check_usertype($srch->{'srchdomain'},$srch->{'srchterm'},$rules);
+        }
     }
+    my $cancreate =
+        &Apache::lonuserutils::can_create_user($dom,$context,$usertype);
     my $userpicker = 
        &Apache::loncommon::user_picker($dom,$srch,$forcenewuser,
-                                       'document.crtuser');
+                                       'document.crtuser',$cancreate,$usertype);
     my $srchbutton = &mt('Search');
     my $output = <<"ENDBLOCK";
 <form action="/adm/createuser" method="post" name="crtuser">
@@ -327,6 +333,7 @@
 <input type="hidden" name="forcenewuser" value="1" />
 <input type="hidden" name="origform" value="crtusername" />
 <h3>$lt{crnu}$helpcrt</h3>
+$responsemsg
 <table>
  <tr>
   <td>$lt{'usr'}:</td>
@@ -404,8 +411,8 @@
                                        'firstname'      => "first name",
                                        'permanentemail' => "permanent e-mail",
                                       );
+    $r->print(&Apache::loncommon::start_page('User Management',$jscript));
     if ($operation eq 'createuser') {
-        $r->print(&Apache::loncommon::start_page('User Management',$jscript));
         &Apache::lonhtmlcommon::add_breadcrumb
             ({href=>"javascript:backPage(document.usersrchform,'','')",
               text=>"Create/modify user",
@@ -417,9 +424,17 @@
         $r->print("<b>$lt{'usrch'}</b><br />");
         $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
         $r->print('<h3>'.$lt{'usel'}.'</h3>');
-    } else {
+    } elsif ($operation eq 'enrollstudent') {
+        &Apache::lonhtmlcommon::add_breadcrumb
+            ({href=>"javascript:backPage(document.usersrchform,'','')",
+              text=>"Create/modify student",
+              faq=>282,bug=>'Instructor Interface',},
+             {href=>"javascript:backPage(document.usersrchform,'get_user_info','select')",
+              text=>"Select Student",
+              faq=>282,bug=>'Instructor Interface',});
+        $r->print(&Apache::lonhtmlcommon::breadcrumbs('User Management'));
         $r->print($jscript."<b>$lt{'stusrch'}</b><br />");
-        $r->print(&Apache::londropadd::single_user_entry_form($srch->{'srchdomain'},$srch));
+        $r->print(&entry_form($srch->{'srchdomain'},$srch,undef,$context));
         $r->print('</form><h3>'.$lt{'stusel'}.'</h3>');
     }
     $r->print('<form name="usersrchform" method="post">'.
@@ -465,14 +480,8 @@
               ' <input type="hidden" name="seludom" value="" />'."\n".
               ' <input type="hidden" name="currstate" value="select" />'."\n".
               ' <input type="hidden" name="phase" value="get_user_info" />'."\n".
-              ' <input type="hidden" name="action" value="singleuser" />'."\n");
-    $r->print($response);
-    if ($operation eq 'createuser') {
-        $r->print('</form>'.&Apache::loncommon::end_page());
-    } else {
-        $r->print('<input type="hidden" name="action" value="enrollstudent" />'."\n".
-                  '<input type="hidden" name="state" value="gotusername" />'."\n");
-    }
+              ' <input type="hidden" name="action" value="'.$env{'form.action'}.'" />'."\n");
+    $r->print($response.'</form>'.&Apache::loncommon::end_page());
 }
 
 sub print_user_query_page {
@@ -2754,8 +2763,14 @@
                     $currstate = $env{'form.currstate'};
                 }
                 if ($currstate eq 'select') {
+                    my $operation; 
+                    if ($env{'form.action'} eq 'singleuser') {
+                        $operation = 'createuser';
+                    } elsif ($env{'form.action'} eq 'singlestudent') {
+                        $operation = 'enrollstudent';
+                    }
                     &print_user_selection_page($r,$response,$srch,$results,
-                                               'createuser',\@search,$context);
+                                               $operation,\@search,$context);
                 } elsif ($currstate eq 'modify') {
                     my ($ccuname,$ccdomain);
                     if (($srch->{'srchby'} eq 'uname') && 
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.17 loncom/interface/lonuserutils.pm:1.18
--- loncom/interface/lonuserutils.pm:1.17	Fri Dec 21 07:41:25 2007
+++ loncom/interface/lonuserutils.pm	Fri Dec 21 09:05:40 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.17 2007/12/21 12:41:25 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.18 2007/12/21 14:05:40 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -3810,6 +3810,27 @@
     return $cancreate;
 }
 
+sub check_usertype {
+    my ($dom,$uname,$rules) = @_;
+    my $usertype;
+    if (ref($rules) eq 'HASH') {
+        my @user_rules = keys(%{$rules});
+        if (@user_rules > 0) {
+            my %rule_check = &Apache::lonnet::inst_rulecheck($dom,$uname,undef,'username',\@user_rules);
+            if (keys(%rule_check) > 0) {
+                $usertype = 'unofficial';
+                foreach my $item (keys(%rule_check)) {
+                    if ($rule_check{$item}) {
+                        $usertype = 'official';
+                        last;
+                    }
+                }
+            }
+        }
+    }
+    return $usertype;
+}
+
 sub roles_by_context {
     my ($context,$custom) = @_;
     my @allroles;

--raeburn1198245941--