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

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Tue, 03 Jun 2008 01:13:27 -0000


This is a MIME encoded message

--raeburn1212455607
Content-Type: text/plain

raeburn		Mon Jun  2 21:13:27 2008 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
  Log:
  Bug 5558.
  Replace single textbox for entry of user types allowed to selfenroll, with combination of radiobuttons (Y/N for * - allusers, all domains), select boxes for domains, and checkboxes for institutional user types within each domain.
  
  
--raeburn1212455607
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080602211327.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.240 loncom/interface/loncreateuser.pm:1.241
--- loncom/interface/loncreateuser.pm:1.240	Thu May 29 00:10:50 2008
+++ loncom/interface/loncreateuser.pm	Mon Jun  2 21:13:27 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.240 2008/05/29 04:10:50 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.241 2008/06/03 01:13:27 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2981,7 +2981,7 @@
         if (!exists($env{'form.state'})) {
             $r->print(&Apache::lonhtmlcommon::breadcrumbs('Configure Self-enrollment',
                                                           'Course_Self_Enrollment'));
-
+            $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
             &print_selfenroll_menu($r,$context,$permission);
         } elsif ($env{'form.state'} eq 'done') {
             &Apache::lonhtmlcommon::add_breadcrumb
@@ -2989,7 +2989,8 @@
               text=>"Result"});
             $r->print(&Apache::lonhtmlcommon::breadcrumbs('Self-enrollment result',
                                                           'Course_Self_Enrollment'));
-            &update_selfenroll_config($r,$context);
+            $r->print('<h3>'.&mt('Self-enrollment with a student role').'</h3>'."\n");
+            &update_selfenroll_config($r,$context,$permission);
         }
         $r->print(&Apache::loncommon::end_page());
     } elsif ($env{'form.action'} eq 'changelogs') {
@@ -3178,8 +3179,10 @@
                  $setsec_js."\n".
                  '</script>'."\n".
                  '<h3>'.$lt->{'selfenroll'}.'</h3>'."\n".
-                 '<form name="'.$formname.'" method="post">'."\n".
+                 '<form name="'.$formname.'" method="post" action="/adm/createuser">'."\n".
                  &Apache::lonhtmlcommon::start_pick_box();
+    my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+    my $cnum = $env{'course.'.$env{'request.course.id'},'.num'};
     if (ref($row) eq 'ARRAY') {
         foreach my $item (@{$row}) {
             my $title = $item; 
@@ -3191,7 +3194,68 @@
                              'LC_selfenroll_pick_box_title','LC_oddrow_value')."\n";
             if ($item eq 'types') {
                 my $curr_types = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_types'};
-                $output .= '<input type="text" name="selfenroll_types" value="'.$curr_types.'" size="50" />';
+                my $showdomdesc = 1;
+                my $includeempty = 1;
+                my $num = 0;
+                $output .= &Apache::loncommon::start_data_table().
+                           &Apache::loncommon::start_data_table_row()
+                           .'<td colspan="2"><span class="LC_nobreak"><label>'
+                           .&mt('Any user in any domain:')
+                           .'&nbsp;<input type="radio" name="selfenroll_all" value="1" ';
+                if ($curr_types eq '*') {
+                    $output .= ' checked="checked" '; 
+                }
+                $output .= '/>'.&mt('Yes').'</label>&nbsp;&nbsp;<input type="radio" name="selfenroll_all" value="0" ';
+                if ($curr_types ne '*') {
+                    $output .= ' checked="checked" ';
+                }
+                $output .= '/>'.&mt('No').'</label></td>'
+                           .&Apache::loncommon::end_data_table_row();
+                my %currdoms;
+                if (($curr_types eq '') && ($env{'form.selfenroll_newdom'} eq '')) {
+                    $output .= &new_selfenroll_dom_row($cdom,'0');
+                } elsif ($curr_types ne '*') {
+                    my @entries = split(/;/,$curr_types);
+                    if (@entries > 0) {
+                        foreach my $entry (@entries) {
+                            my ($currdom,$typestr) = split(/:/,$entry);
+                            $currdoms{$currdom} = 1;
+                            my $domdesc = &Apache::lonnet::domain($currdom);
+                            my @currinsttypes = split(/,/,$typestr);
+                            $output .= &Apache::loncommon::start_data_table_row()
+                                       .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'<b>'
+                                       .'&nbsp;'.$domdesc.' ('.$currdom.')'
+                                       .'</b><input type="hidden" name="selfenroll_dom_'.$num
+                                       .'" value="'.$currdom.'" /></span><br />'
+                                       .'<span class="LC_nobreak"><label><input type="checkbox" '
+                                       .'name="selfenroll_delete" value="'.$num.'" />'
+                                       .&mt('Delete').'</label></span></td>';
+                            $output .= '<td valign="top">'.&mt('User types:').'<br />'
+                                       .&selfenroll_inst_types($num,$currdom,\@currinsttypes).'</td>'
+                                       .&Apache::loncommon::end_data_table_row();
+                            $num ++;
+                        }
+                    }
+                }
+                if ($env{'form.selfenroll_newdom'} ne '') {
+                    if (!defined($currdoms{$env{'form.selfenroll_newdom'}})) {
+                        $output .= &new_selfenroll_dom_row($env{'form.selfenroll_newdom'},$num); 
+                        $num ++;
+                    }
+                }
+                my $add_domtitle = &mt('Additional domain:');
+                if ($curr_types eq '*') { 
+                    $add_domtitle = &mt('Specific Domain:');
+                } elsif ($curr_types eq '') {
+                    $add_domtitle = &mt('Other domain:');
+                }
+                $output .= &Apache::loncommon::start_data_table_row()
+                           .'<td colspan="2"><span class="LC_nobreak">'.$add_domtitle.'</span><br />'
+                           .&Apache::loncommon::select_dom_form('','selfenroll_newdom',
+                                                                $includeempty,$showdomdesc)
+                           .'<input type="hidden" name="selfenroll_types_total" value="'.$num.'" />'
+                           .'</td>'.&Apache::loncommon::end_data_table_row()
+                           .&Apache::loncommon::end_data_table();
             } elsif ($item eq 'registered') {
                 my ($regon,$regoff);
                 if ($env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_registered'}) {
@@ -3240,8 +3304,6 @@
                 $output .= &selfenroll_date_forms($startform,$endform);
             } elsif ($item eq 'section') {
                 my $currsec = $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_section'}; 
-                my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-                my $cnum = $env{'course.'.$env{'request.course.id'},'.num'};
                 my %sections_count = &Apache::loncommon::get_sections($cdom,$cnum);
                 my $newsecval;
                 if ($currsec ne 'none' && $currsec ne '') {
@@ -3265,12 +3327,72 @@
         }
     }
     $output .= &Apache::lonhtmlcommon::end_pick_box().
-               '<br /><input type="button" name="selfenrollconf" value="'.
-               &mt('Save changes').'" onclick="setSections(this.form);" /></form>';
+               '<br /><input type="button" name="selfenrollconf" value="'
+               .&mt('Save changes').'" onclick="setSections(this.form);" />'
+               .'<input type="hidden" name="action" value="selfenroll" /></form>';
     $r->print($output);
     return;
 }
 
+sub new_selfenroll_dom_row {
+    my ($newdom,$num) = @_;
+    my $domdesc = &Apache::lonnet::domain($newdom);
+    my $output;
+    if ($domdesc ne '') {
+        $output .= &Apache::loncommon::start_data_table_row()
+                   .'<td valign="top"><span class="LC_nobreak">'.&mt('Domain:').'&nbsp;<b>'.$domdesc
+                   .' ('.$newdom.')</b><input type="hidden" name="selfenroll_dom_'.$num
+                   .'" value="'.$newdom.'" /></span></td>';
+        my @currinsttypes;
+        $output .= '<td>'.&mt('User types:').'<br />'
+                   .&selfenroll_inst_types($num,$newdom,\@currinsttypes).'</td>'
+                   .&Apache::loncommon::end_data_table_row();
+    }
+    return $output;
+}
+
+sub selfenroll_inst_types {
+    my ($num,$currdom,$currinsttypes) = @_;
+    my $output;
+    my $numinrow = 4;
+    my $count = 0;
+    my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($currdom);
+    if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
+        $output .= '<table><tr>';
+        foreach my $type (@{$types}) {
+            if (($count > 0) && ($count%$numinrow == 0)) {
+                $output .= '</tr><tr>';
+            }
+            if (defined($usertypes->{$type})) {
+                $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="'.
+                           $type.'" ';
+                if (ref($currinsttypes) eq 'ARRAY') {
+                    if (@{$currinsttypes} > 0) {
+                        if (grep(/^\Q$type\E$/,@{$currinsttypes})) {
+                            $output .= 'checked="checked"';
+                        }
+                    }
+                }
+                $output .= ' name="selfenroll_types_'.$num.'" />'.$usertypes->{$type}.'</label></span></td>';
+            }
+            $count ++;
+        }
+        if (($count > 0) && ($count%$numinrow == 0)) {
+            $output .= '</tr><tr>';
+        }
+        $output .= '<td><span class="LC_nobreak"><label><input type = "checkbox" value="other" ';
+        if (ref($currinsttypes) eq 'ARRAY') {
+            if (@{$currinsttypes} > 0) {
+                if (grep(/^other$/,@{$currinsttypes})) {
+                    $output .= 'checked="checked" ';
+                }
+            }
+        }
+        $output .= ' name="selfenroll_types_'.$num.'" />'.$othertitle.'</label></span></td></tr></table>';
+    }
+    return $output;
+}
+
 sub selfenroll_date_forms {
     my ($startform,$endform) = @_;
     my $output .= &Apache::lonhtmlcommon::start_pick_box()."\n".
@@ -4138,13 +4260,13 @@
 }
 
 sub update_selfenroll_config {
-    my ($r,$context) = @_;
+    my ($r,$context,$permission) = @_;
     my ($row,$lt) = &get_selfenroll_titles();
-    my $groupslist = &Apache::lonuserutils::get_groupslist();
+    my %curr_groups = &Apache::longroup::coursegroups();
     my (%changes,%warning);
     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
-    $r->print('<h3>'.$lt->{'selfenroll'}.'</h3>'."\n");
+    my $curr_types;
     if (ref($row) eq 'ARRAY') {
         foreach my $item (@{$row}) {
             if ($item eq 'enroll_dates') {
@@ -4165,13 +4287,47 @@
                         $changes{'internal.selfenroll_'.$type.'_access'} = $newdate{$type};
                     }
                 }
+            } elsif ($item eq 'types') {
+                $curr_types =
+                    $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
+                if ($env{'form.selfenroll_all'}) {
+                    if ($curr_types ne '*') {
+                        $changes{'internal.selfenroll_types'} = '*';
+                    } else {
+                        next;
+                    }
+                } elsif ($curr_types eq '') {
+                    my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_0');
+                    if (@types > 0) {
+                        $changes{'internal.selfenroll_types'} = $env{'form.selfenroll_dom_0'}.':'.join(',',@types);
+                    }
+                } else {
+                    my @entries = split(/;/,$curr_types);
+                    my $num = 0;
+                    my @latesttypes;
+                    my @deletedoms = &Apache::loncommon::get_env_multiple('form.selfenroll_delete');
+                    my $newnum = 0;
+                    for (my $j=0; $j<$env{'form.selfenroll_types_total'}; $j++) {
+                        if (!grep(/^$j$/,@deletedoms)) {
+                            my @types = &Apache::loncommon::get_env_multiple('form.selfenroll_types_'.$j);
+                            @types = sort(@types);
+                            my $typestr = join(',',@types);
+                            $latesttypes[$newnum] = $env{'form.selfenroll_dom_'.$j}.':'.$typestr;
+                            $newnum ++;
+                        }
+                    }
+                    my $selfenroll_types = join(';',@latesttypes);
+                    if ($selfenroll_types ne $curr_types) {
+                        $changes{'internal.selfenroll_types'} = $selfenroll_types;
+                    }
+                }
             } else {
                 my $curr_val = 
                     $env{'course.'.$env{'request.course.id'}.'.internal.selfenroll_'.$item};
                 my $newval = $env{'form.selfenroll_'.$item};
                 if ($item eq 'section') {
                     $newval = $env{'form.sections'};
-                    if (grep(/^\Q$newval\E$/,keys(%{$groupslist}))) {
+                    if (defined($curr_groups{$newval})) {
                         $newval = $curr_val;
                         $warning{$item} = &mt('Section for self-enrolled users unchanged as the proposed section is a group').'<br />'.&mt('Group names and section names must be distinct');
                     } elsif ($newval eq 'all') {
@@ -4185,7 +4341,7 @@
                 if ($newval ne $curr_val) {
                     $changes{'internal.selfenroll_'.$item} = $newval;
                 }
-            } 
+            }
         }
         if (keys(%warning) > 0) {
             foreach my $item (@{$row}) {
@@ -4239,8 +4395,15 @@
                         }
                     } else {
                         if (exists($changes{'internal.selfenroll_'.$item})) {
-                            $r->print('<li>'.&mt('[_1] set to "[_2]".',$title,
-                                      $changes{'internal.selfenroll_'.$item}).'</li>'."\n");
+                            my $newval = $changes{'internal.selfenroll_'.$item};
+                            if ($item eq 'types') {
+                                if ($newval eq '') {
+                                    $newval = &mt('None');
+                                } elsif ($newval eq '*') {
+                                    $newval = &mt('Any user in any domain');
+                                }
+                            }
+                            $r->print('<li>'.&mt('[_1] set to "[_2]".',$title,$newval).'</li>'."\n");
                         }
                     }
                 }
@@ -4259,18 +4422,20 @@
     } else {
         $r->print(&mt('No changes were needed to the existing self-enrollment settings in this course.'));
     }
+    if ($env{'form.selfenroll_newdom'} ne '') {
+        &print_selfenroll_menu($r,$context,$permission);
+    }
     return;
 }
 
 sub get_selfenroll_titles {
     my @row = ('types','registered','enroll_dates','access_dates','section');
     my %lt = &Apache::lonlocal::texthash (
-                selfenroll   => 'Self-enrollment with a student role',
                 types        => 'Users allowed to self-enroll in this course',
                 registered   => 'Restrict self-enrollment to registered students?',
                 enroll_dates => 'Dates self-enrollment available',
                 access_dates => 'Access dates for self-enrolled users',
-                section      => 'Section',
+                section      => 'Section assigned to self-enrolled users',
              );
     return (\@row,\%lt);
 }

--raeburn1212455607--