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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Fri, 21 Dec 2007 16:23:55 -0000


This is a MIME encoded message

--raeburn1198254235
Content-Type: text/plain

raeburn		Fri Dec 21 11:23:55 2007 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
  Log:
  - Generation of interface for addition of new roles for a single user:
  - Author roles moved to subroutine: &new_coauthor_roles()
  - Domain roles moved to subroutine: &new_domain_roles()
  - Display of interface for adding new course roles only shown if adding "singleuser"; not show when adding "singlestudent"
  - "Modify User" button in "singleuser" context; "Enroll student" button in "singlestudent" context.
  
  
--raeburn1198254235
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20071221112355.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.217 loncom/interface/loncreateuser.pm:1.218
--- loncom/interface/loncreateuser.pm:1.217	Fri Dec 21 10:33:32 2007
+++ loncom/interface/loncreateuser.pm	Fri Dec 21 11:23:54 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.217 2007/12/21 15:33:32 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.218 2007/12/21 16:23:54 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -809,141 +809,44 @@
             &display_existing_roles($r,$ccuname,$ccdomain,\%inccourses);
         }
     } ## End of new user/old user logic
-    my $addrolesdisplay = 0;
-    $r->print('<h3>'.&mt('Add Roles').'</h3>');
-#
-# Co-Author
-# 
-    if (&Apache::lonuserutils::authorpriv($env{'user.name'},
-                                          $env{'request.role.domain'}) &&
-        ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
-        # No sense in assigning co-author role to yourself
-        $addrolesdisplay = 1;
-	my $cuname=$env{'user.name'};
-        my $cudom=$env{'request.role.domain'};
-	   my %lt=&Apache::lonlocal::texthash(
-		    'cs'   => "Construction Space",
-                    'act'  => "Activate",                    
-                    'rol'  => "Role",
-                    'ext'  => "Extent",
-                    'sta'  => "Start",
-                    'end'  => "End",
-                    'cau'  => "Co-Author",
-                    'caa'  => "Assistant Co-Author",
-                    'ssd'  => "Set Start Date",
-                    'sed'  => "Set End Date"
-				       );
-       $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n". 
-           &Apache::loncommon::start_data_table()."\n".
-           &Apache::loncommon::start_data_table_header_row()."\n".
-           '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
-           '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
-           '<th>'.$lt{'end'}.'</th>'."\n".
-           &Apache::loncommon::end_data_table_header_row()."\n".
-           &Apache::loncommon::start_data_table_row()."\n".
-           '<td>
-            <input type=checkbox name="act_'.$cudom.'_'.$cuname.'_ca" />
-           </td>
-           <td>'.$lt{'cau'}.'</td>
-           <td>'.$cudom.'_'.$cuname.'</td>
-           <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
-             <a href=
-"javascript:pjump('."'date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
-<td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
-<a href=
-"javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
-          &Apache::loncommon::end_data_table_row()."\n".
-          &Apache::loncommon::start_data_table_row()."\n".
-'<td><input type=checkbox name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
-<td>'.$lt{'caa'}.'</td>
-<td>'.$cudom.'_'.$cuname.'</td>
-<td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
-<a href=
-"javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
-<td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
-<a href=
-"javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
-         &Apache::loncommon::end_data_table_row()."\n".
-         &Apache::loncommon::end_data_table());
-    } elsif ($env{'request.role'} =~ /^au\./) {
-        if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
-                                                $env{'request.role.domain'}))) {
-            $r->print('<span class="LC_error">'.
-                      &mt('You do not have privileges to assign co-author roles.').
-                      '</span>');
-        } elsif (($env{'user.name'} eq $ccuname) && 
-             ($env{'user.domain'} eq $ccdomain)) {
-           $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
-        }
-    }
-#
-# Domain level
-#
-    my $num_domain_level = 0;
-    my $domaintext = 
-    '<h4>'.&mt('Domain Level').'</h4>'.
-    &Apache::loncommon::start_data_table().
-    &Apache::loncommon::start_data_table_header_row().
-    '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
-    &mt('Extent').'</th>'.
-    '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
-    &Apache::loncommon::end_data_table_header_row();
-    foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
-        foreach my $role ('dc','li','dg','au','sc') {
-            if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
-               my $plrole=&Apache::lonnet::plaintext($role);
-	       my %lt=&Apache::lonlocal::texthash(
-                    'ssd'  => "Set Start Date",
-                    'sed'  => "Set End Date"
-				       );
-               $num_domain_level ++;
-               $domaintext .= 
-&Apache::loncommon::start_data_table_row().
-'<td><input type=checkbox name="act_'.$thisdomain.'_'.$role.'" /></td>
-<td>'.$plrole.'</td>
-<td>'.$thisdomain.'</td>
-<td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
-<a href=
-"javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
-<td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
-<a href=
-"javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
-&Apache::loncommon::end_data_table_row();
-            }
-        } 
-    }
-    $domaintext.= &Apache::loncommon::end_data_table();
-    if ($num_domain_level > 0) {
-        $r->print($domaintext);
-        $addrolesdisplay = 1;
-    }
-#
-# Course level
-#
 
-    if ($env{'request.role'} =~ m{^dc\./($match_domain)/$}) {
-        $r->print(&course_level_dc($1,'Course'));
-        $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()" />'."\n");
-    } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/$}) {
-        if ($addrolesdisplay) {
-            $r->print('<br /><input type="button" value="'.&mt('Modify User').'"');
-            if ($newuser) {
-                $r->print(' onClick="verify_message(this.form)" \>'."\n");
+    if ($env{'form.action'} eq 'singlestudent') {
+        $r->print('<br /><input type="button" value="'.&mt('Enroll Student').'" onClick="setSections(this.form)" />'."\n");
+    } else {
+        $r->print('<h3>'.&mt('Add Roles').'</h3>');
+        my $addrolesdisplay = 0;
+        if ($context eq 'domain' || $context eq 'author') {
+            $addrolesdisplay = &new_coauthor_roles($r,$ccuname,$ccdomain);
+        }
+        if ($context eq 'domain') {
+            my $add_domainroles = &new_domain_roles($r);
+            if (!$addrolesdisplay) {
+                $addrolesdisplay = $add_domainroles;
+            }
+            $r->print(&course_level_dc($env{'request.role.domain'},'Course'));
+            $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setCourse()" />'."\n");
+        } elsif ($context eq 'author') {
+            if ($addrolesdisplay) {
+                $r->print('<br /><input type="button" value="'.&mt('Modify User').'"');
+                if ($newuser) {
+                    $r->print(' onClick="verify_message(this.form)" \>'."\n");
+                } else {
+                    $r->print('onClick="this.form.submit()" \>'."\n");
+                }
             } else {
-                $r->print('onClick="this.form.submit()" \>'."\n"); 
+                $r->print('<br /><a href="javascript:backPage(document.cu)">'.
+                          &mt('Back to previous page').'</a>');
             }
         } else {
-            $r->print('<br /><a href="javascript:backPage(document.cu)">'.
-                      &mt('Back to previous page').'</a>');
+            $r->print(&course_level_table(%inccourses));
+            $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections(this.form)" />'."\n");
         }
-    } else {
-        $r->print(&course_level_table(%inccourses));
-        $r->print('<br /><input type="button" value="'.&mt('Modify User').'" onClick="setSections(this.form)" />'."\n");
     }
     $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','userrole','ccdomain','prevphase','currstate','ccuname','ccdomain']));
     $r->print('<input type="hidden" name="currstate" value="" />');
     $r->print('<input type="hidden" name="prevphase" value="'.$env{'form.phase'}.'" />');
     $r->print("</form>".&Apache::loncommon::end_page());
+    return;
 }
 
 sub singleuser_breadcrumb {
@@ -1208,6 +1111,124 @@
     return;
 }
 
+sub new_coauthor_roles {
+    my ($r,$ccuname,$ccdomain) = @_;
+    my $addrolesdisplay = 0;
+    #
+    # Co-Author
+    #
+    if (&Apache::lonuserutils::authorpriv($env{'user.name'},
+                                          $env{'request.role.domain'}) &&
+        ($env{'user.name'} ne $ccuname || $env{'user.domain'} ne $ccdomain)) {
+        # No sense in assigning co-author role to yourself
+        $addrolesdisplay = 1;
+        my $cuname=$env{'user.name'};
+        my $cudom=$env{'request.role.domain'};
+        my %lt=&Apache::lonlocal::texthash(
+                    'cs'   => "Construction Space",
+                    'act'  => "Activate",
+                    'rol'  => "Role",
+                    'ext'  => "Extent",
+                    'sta'  => "Start",
+                    'end'  => "End",
+                    'cau'  => "Co-Author",
+                    'caa'  => "Assistant Co-Author",
+                    'ssd'  => "Set Start Date",
+                    'sed'  => "Set End Date"
+                                       );
+        $r->print('<h4>'.$lt{'cs'}.'</h4>'."\n".
+                  &Apache::loncommon::start_data_table()."\n".
+                  &Apache::loncommon::start_data_table_header_row()."\n".
+                  '<th>'.$lt{'act'}.'</th><th>'.$lt{'rol'}.'</th>'.
+                  '<th>'.$lt{'ext'}.'</th><th>'.$lt{'sta'}.'</th>'.
+                  '<th>'.$lt{'end'}.'</th>'."\n".
+                  &Apache::loncommon::end_data_table_header_row()."\n".
+                  &Apache::loncommon::start_data_table_row().'
+           <td>
+            <input type=checkbox name="act_'.$cudom.'_'.$cuname.'_ca" />
+           </td>
+           <td>'.$lt{'cau'}.'</td>
+           <td>'.$cudom.'_'.$cuname.'</td>
+           <td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_ca" value="" />
+             <a href=
+"javascript:pjump('."'date_start','Start Date Co-Author',document.cu.start_$cudom\_$cuname\_ca.value,'start_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
+<td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_ca" value="" />
+<a href=
+"javascript:pjump('."'date_end','End Date Co-Author',document.cu.end_$cudom\_$cuname\_ca.value,'end_$cudom\_$cuname\_ca','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
+              &Apache::loncommon::end_data_table_row()."\n".
+              &Apache::loncommon::start_data_table_row()."\n".
+'<td><input type=checkbox name="act_'.$cudom.'_'.$cuname.'_aa" /></td>
+<td>'.$lt{'caa'}.'</td>
+<td>'.$cudom.'_'.$cuname.'</td>
+<td><input type="hidden" name="start_'.$cudom.'_'.$cuname.'_aa" value="" />
+<a href=
+"javascript:pjump('."'date_start','Start Date Assistant Co-Author',document.cu.start_$cudom\_$cuname\_aa.value,'start_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
+<td><input type="hidden" name="end_'.$cudom.'_'.$cuname.'_aa" value="" />
+<a href=
+"javascript:pjump('."'date_end','End Date Assistant Co-Author',document.cu.end_$cudom\_$cuname\_aa.value,'end_$cudom\_$cuname\_aa','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'."\n".
+             &Apache::loncommon::end_data_table_row()."\n".
+             &Apache::loncommon::end_data_table());
+    } elsif ($env{'request.role'} =~ /^au\./) {
+        if (!(&Apache::lonuserutils::authorpriv($env{'user.name'},
+                                                $env{'request.role.domain'}))) {
+            $r->print('<span class="LC_error">'.
+                      &mt('You do not have privileges to assign co-author roles.').
+                      '</span>');
+        } elsif (($env{'user.name'} eq $ccuname) &&
+             ($env{'user.domain'} eq $ccdomain)) {
+            $r->print(&mt('Assigning yourself a co-author or assistant co-author role in your own author area in Construction Space is not permitted'));
+        }
+    }
+    return $addrolesdisplay;;
+}
+
+sub new_domain_roles {
+    my ($r) = @_;
+    my $addrolesdisplay = 0;
+    #
+    # Domain level
+    #
+    my $num_domain_level = 0;
+    my $domaintext =
+    '<h4>'.&mt('Domain Level').'</h4>'.
+    &Apache::loncommon::start_data_table().
+    &Apache::loncommon::start_data_table_header_row().
+    '<th>'.&mt('Activate').'</th><th>'.&mt('Role').'</th><th>'.
+    &mt('Extent').'</th>'.
+    '<th>'.&mt('Start').'</th><th>'.&mt('End').'</th>'.
+    &Apache::loncommon::end_data_table_header_row();
+    foreach my $thisdomain (sort(&Apache::lonnet::all_domains())) {
+        foreach my $role ('dc','li','dg','au','sc') {
+            if (&Apache::lonnet::allowed('c'.$role,$thisdomain)) {
+               my $plrole=&Apache::lonnet::plaintext($role);
+               my %lt=&Apache::lonlocal::texthash(
+                    'ssd'  => "Set Start Date",
+                    'sed'  => "Set End Date"
+                                       );
+               $num_domain_level ++;
+               $domaintext .=
+&Apache::loncommon::start_data_table_row().
+'<td><input type=checkbox name="act_'.$thisdomain.'_'.$role.'" /></td>
+<td>'.$plrole.'</td>
+<td>'.$thisdomain.'</td>
+<td><input type="hidden" name="start_'.$thisdomain.'_'.$role.'" value="" />
+<a href=
+"javascript:pjump('."'date_start','Start Date $plrole',document.cu.start_$thisdomain\_$role.value,'start_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'ssd'}.'</a></td>
+<td><input type="hidden" name="end_'.$thisdomain.'_'.$role.'" value="" />
+<a href=
+"javascript:pjump('."'date_end','End Date $plrole',document.cu.end_$thisdomain\_$role.value,'end_$thisdomain\_$role','cu.pres','dateset'".')">'.$lt{'sed'}.'</a></td>'.
+&Apache::loncommon::end_data_table_row();
+            }
+        }
+    }
+    $domaintext.= &Apache::loncommon::end_data_table();
+    if ($num_domain_level > 0) {
+        $r->print($domaintext);
+        $addrolesdisplay = 1;
+    }
+    return $addrolesdisplay;
+}
+
 sub user_authentication {
     my ($ccuname,$ccdomain,$krbdefdom,$abv_auth) = @_;
     my $currentauth=&Apache::lonnet::queryauthenticate($ccuname,$ccdomain);

--raeburn1198254235--