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

raeburn raeburn@source.lon-capa.org
Thu, 10 Sep 2009 23:04:52 -0000


This is a MIME encoded message

--raeburn1252623892
Content-Type: text/plain

raeburn		Thu Sep 10 23:04:52 2009 EDT

  Modified files:              
    /loncom/interface	loncreateuser.pm 
  Log:
  - Storage of course request settings for users in other domains now conforms
     to the format $dom1:$option=$num,$dom2:$option=$num where =$num contains
     optional  limit for requests/user.
  - Consistent use of upper case when reporting results of changes to course 
     request options (for "external" users).
  - "blank for unlimited" shown in request setting tables for numerical limit 
     option.
  - Coding style - removed trailing spaces from a few lines.
  
  
--raeburn1252623892
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20090910230452.txt"

Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.313 loncom/interface/loncreateuser.pm:1.314
--- loncom/interface/loncreateuser.pm:1.313	Sat Sep  5 20:17:35 2009
+++ loncom/interface/loncreateuser.pm	Thu Sep 10 23:04:52 2009
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.313 2009/09/05 20:17:35 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.314 2009/09/10 23:04:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -261,20 +261,20 @@
         }
         if ($context eq 'requestcourses') {
             if ($userenv{$context.'.'.$item} eq '') {
-                $custom_access = &mt('Currently from default setting.'); 
+                $custom_access = &mt('Currently from default setting.');
             } else {
                 $custom_access = &mt('Currently from custom setting.');
             }
         } else {
             if ($userenv{$context.'.'.$item} eq '') {
-                $custom_access = 
+                $custom_access =
                     &mt('Availability determined currently from default setting.');
                 if (!$curr_access) {
                     $tool_off = 'checked="checked" ';
                     $tool_on = '';
                 }
             } else {
-                $custom_access = 
+                $custom_access =
                     &mt('Availability determined currently from custom setting.');
                 if ($userenv{$context.'.'.$item} == 0) {
                     $tool_off = 'checked="checked" ';
@@ -294,7 +294,11 @@
             }
             if ($curroption =~ /^autolimit=(\d*)$/) {
                 $currlimit = $1;
-                $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit); 
+                if ($currlimit eq '') {
+                    $currdisp = &mt('Yes, automatic creation');
+                } else {
+                    $currdisp = &mt('Yes, up to [quant,_1,request]/user',$currlimit);
+                }
             } else {
                 $currdisp = $reqdisplay{$curroption};
             }
@@ -328,16 +332,19 @@
                 if ($option eq 'autolimit') {
                     $custdisp .= '<input type="text" name="crsreq_'.
                                  $item.'_limit" size="1" '.
-                                 'value="'.$currlimit.'" />';
+                                 'value="'.$currlimit.'" /></span><br />'.
+                                 $reqtitles{'unlimited'};
+                 } else {
+                     $custdisp .= '</span>';
                  }
-                 $custdisp .= '</span></td></tr>';
+                 $custdisp .= '</td></tr>';
             }
             $custdisp .= '</table>';
             $custradio = '</span></td><td>'.&mt('Custom setting').'<br />'.$custdisp;
         } else {
             $currdisp = ($curr_access?&mt('Yes'):&mt('No'));
             $custdisp = '<span class="LC_nobreak"><label>'.
-                        '<input type="radio" name="'.$context.'_'.$item.'"'. 
+                        '<input type="radio" name="'.$context.'_'.$item.'"'.
                         ' value="1"'. $tool_on.'/>'.&mt('On').'</label>&nbsp;<label>'.
                         '<input type="radio" name="'.$context.'_'.$item.'" value="0" '.
                         $tool_off.'/>'.&mt('Off').'</label></span>';
@@ -380,22 +387,27 @@
         my ($curroption,$currlimit,$tooloff);
         if ($userenv{'reqcrsotherdom.'.$item} ne '') {
             my @curr = split(',',$userenv{'reqcrsotherdom.'.$item});
-            if (grep(/^\Q$cdom\E:($optregex)=?(\d*)$/,@curr)) {
-                $curroption = $1;
-                $currlimit = $2;
-                if (!$curroption) {
-                    $curroption = 'norequest';
+            foreach my $req (@curr) {
+                if ($req =~ /^\Q$cdom\E\:($optregex)=?(\d*)$/) {
+                    $curroption = $1;
+                    $currlimit = $2;
+                    last;
                 }
             }
+            if (!$curroption) {
+                $curroption = 'norequest';
+                $tooloff = ' checked="checked"';
+            }
         } else {
             $curroption = 'norequest';
             $tooloff = ' checked="checked"';
         }
         $output.= &Apache::loncommon::start_data_table_row()."\n".
-                  '  <td><span class="LC_nobreak">'.$lt{$item}.': '.
+                  '  <td><span class="LC_nobreak">'.$lt{$item}.': </span></td><td>'.
+                  '<table><tr><td valign="top">'."\n".
                   '<label><input type="radio" name="reqcrsotherdom_'.$item.
-                  '" value="0"'.$tooloff.' />'.$reqtitles{'norequest'}.
-                  '</label>&nbsp;';
+                  '" value=""'.$tooloff.' />'.$reqtitles{'norequest'}.
+                  '</label></td>';
         foreach my $option (@options) {
             if ($option eq 'validate') {
                 my $canvalidate = 0;
@@ -410,18 +422,21 @@
             if ($option eq $curroption) {
                 $checked = ' checked="checked"';
             }
-            $output .= '<span class="LC_nobreak"><label>'.
+            $output .= '<td valign="top"><span class="LC_nobreak"><label>'.
                        '<input type="radio" name="reqcrsotherdom_'.$item.
                        '" value="'.$option.'"'.$checked.' />'.
-                       $reqtitles{$option}.'</label>&nbsp;';
+                       $reqtitles{$option}.'</label>';
             if ($option eq 'autolimit') {
-                $output .= '<input type="text" name="reqcrsotherdom_'.
+                $output .= '&nbsp;<input type="text" name="reqcrsotherdom_'.
                            $item.'_limit" size="1" '.
-                           'value="'.$currlimit.'" />';
+                           'value="'.$currlimit.'" /></span>'.
+                           '<br />'.$reqtitles{'unlimited'};
+            } else {
+                $output .= '</span>';
             }
-            $output .= '&nbsp;'
+            $output .= '</td>';
         }
-        $output .= '</span></td>'."\n".
+        $output .= '</td></tr></table></td>'."\n".
                    &Apache::loncommon::end_data_table_row()."\n";
     }
     return $output;
@@ -436,6 +451,7 @@
                                    approval   => 'Approval by Dom. Coord.',
                                    validate   => 'With validation',
                                    autolimit  => 'Numerical limit',
+                                   unlimited  => '(blank for unlimited)',
                  );
     return %titles;
 }
@@ -636,6 +652,7 @@
     return <<END;
 <script type="text/javascript" language="Javascript">
 // <![CDATA[
+
     function pclose() {
         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms",
                  "height=350,width=350,scrollbars=no,menubar=no");
@@ -747,13 +764,13 @@
         my ($uname,$udom) = split(/:/,$user);
         my $onclick;
         if ($context eq 'requestcrs') {
-            $onclick = 
+            $onclick =
                 'onclick="javascript:gochoose('."'$uname','$udom',".
                                                "'$srch_results->{$user}->{firstname}',".
                                                "'$srch_results->{$user}->{lastname}',".
                                                "'$srch_results->{$user}->{permanentemail}'".');"';
         } else {
-            $onclick = 
+            $onclick =
                 ' onclick="javascript:pickuser('."'".$uname."'".','."'".$udom."'".');"';
         }
         $r->print(&Apache::loncommon::start_data_table_row().
@@ -964,7 +981,6 @@
             &personal_data_display($ccuname,$ccdomain,$newuser,$context,
                                    $inst_results{$ccuname.':'.$ccdomain});
         $r->print($personal_table);
-#FIXME
         my ($home_server_pick,$numlib) = 
             &Apache::loncommon::home_server_form_item($ccdomain,'hserver',
                                                       'default','hide');
@@ -1076,7 +1092,7 @@
         if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
             $r->print('<h3>'.&mt('User Can Request Creation of Courses in this Domain?').'</h3>'.
                       &Apache::loncommon::start_data_table());
-            if ($env{'request.role.domain'} eq $ccdomain) { 
+            if ($env{'request.role.domain'} eq $ccdomain) {
                 $r->print(&build_tools_display($ccuname,$ccdomain,'requestcourses'));
             } else {
                 $r->print(&coursereq_externaluser($ccuname,$ccdomain,
@@ -2453,8 +2469,7 @@
                           \%userenv,\%changeHash,\%changed,\%newaccess,\%newaccesstext);
         } else {
             &tool_changes('reqcrsotherdom',\@requestcourses,\%oldaccess,\%oldaccesstext,
-                          \%userenv,
-                                  \%changeHash,\%changed,\%newaccess,\%newaccesstext);
+                          \%userenv,\%changeHash,\%changed,\%newaccess,\%newaccesstext);
         }
         if ($env{'form.cfirstname'}  ne $userenv{'firstname'}  ||
             $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
@@ -2818,14 +2833,24 @@
         my %reqdisplay = &courserequest_display();
         my $cdom = $env{'request.role.domain'};
         foreach my $tool (@{$usertools}) {
-            $oldaccesstext->{$tool} = &mt('no');
+            $oldaccesstext->{$tool} = &mt('No');
+            $newaccesstext->{$tool} = $oldaccesstext->{$tool};
             $changeHash->{$context.'.'.$tool} = $userenv->{$context.'.'.$tool};
+            my $newop;
+            if ($env{'form.'.$context.'_'.$tool}) {
+                $newop = $env{'form.'.$context.'_'.$tool};
+                if ($newop eq 'autolimit') {
+                    my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
+                    $limit =~ s/\D+//g;
+                    $newop .= '='.$limit;
+                }
+            }
             if ($userenv->{$context.'.'.$tool} eq '') {
-                if ($env{'form.'.$context.'_'.$tool}) {
-                    $changed->{$tool}=&tool_admin($tool,$cdom,
+                if ($newop) {
+                    $changed->{$tool}=&tool_admin($tool,$cdom.':'.$newop,
                                                   $changeHash,$context);
                     if ($changed->{$tool}) {
-                        $newaccesstext->{$tool} = &mt('yes');
+                        $newaccesstext->{$tool} = &mt('Yes');
                     } else {
                         $newaccesstext->{$tool} = $oldaccesstext->{$tool};
                     }
@@ -2834,35 +2859,32 @@
                 my @curr = split(',',$userenv->{$context.'.'.$tool});
                 my @new;
                 my $changedoms;
-                my $newop = $env{'form.'.$context.'_'.$tool};
-                if ($newop eq 'autolimit') {
-                    $newop .= '=';
-                    unless ($env{'form.'.$context.'_'.$tool.'_limit'} =~ /\D/) {
-                        $newop .= $env{'form.'.$context.'_'.$tool.'_limit'};
-                    }
-                }  
-                if (grep(/^\Q$cdom:($optregex\=?\d*)\E$/,@curr)) {
-                    $oldaccesstext->{$tool} = &mt('yes');
-                    my $oldop = $1;
-                    if ($oldop ne $newop) {
-                        $changedoms = 1;
-                        foreach my $dom (@curr) {
-                            unless ($dom eq $cdom) {
-                                push(@new,$dom);
+                foreach my $req (@curr) {
+                    if ($req =~ /^\Q$cdom\E\:($optregex\=?\d*)$/) {
+                        $oldaccesstext->{$tool} = &mt('Yes');
+                        my $oldop = $1;
+                        if ($oldop ne $newop) {
+                            $changedoms = 1;
+                            foreach my $item (@curr) {
+                                my ($reqdom,$option) = split(':',$item);
+                                unless ($reqdom eq $cdom) {
+                                    push(@new,$item);
+                                }
                             }
+                            if ($newop) {
+                                push(@new,$cdom.':'.$newop);
+                            }
+                            @new = sort(@new);
                         }
-                        if ($newop) {
-                            push(@new,$cdom.':'.$newop);
-                        }
-                        @new = sort(@new);
+                        last;
                     }
-                } elsif ($env{'form.'.$context.'_'.$tool}) {
+                }
+                if ((!$changedoms) && ($newop)) {
                     $changedoms = 1;
                     @new = sort(@curr,$cdom.':'.$newop);
                 }
-                $newaccesstext->{$tool} = $oldaccesstext->{$tool};
                 if ($changedoms) {
-                    my $newdomstr; 
+                    my $newdomstr;
                     if (@new) {
                         $newdomstr = join(',',@new);
                     }
@@ -2871,12 +2893,14 @@
                     if ($changed->{$tool}) {
                         if ($env{'form.'.$context.'_'.$tool}) {
                             if ($env{'form.'.$context.'_'.$tool} eq 'autolimit') {
-                                if ($env{'form.'.$context.'_'.$tool.'_limit'} =~ /\D/) {
-                                    $newaccesstext->{$tool} = &mt('Yes, processed automatically');
+                                my $limit = $env{'form.'.$context.'_'.$tool.'_limit'};
+                                $limit =~ s/\D+//g;
+                                if ($limit) {
+                                    $newaccesstext->{$tool} = &mt('Yes, up to limit of [quant,_1,request] per user.',$limit);
                                 } else {
-                                    $newaccesstext->{$tool} = &mt('Yes, up to limit of [quant,_1,request] per user).',$env{'form.'.$context.'_'.$tool.'_limit'});
+                                    $newaccesstext->{$tool} = &mt('Yes, processed automatically');
                                 }
-                            } else {  
+                            } else {
                                 $newaccesstext->{$tool} = $reqdisplay{$env{'form.'.$context.'_'.$tool}};
                             }
                         } else {
@@ -2895,7 +2919,7 @@
             if ($newval eq 'autolimit') {
                 $newval .= '='.$env{'form.crsreq_'.$tool.'_limit'};
             }
-        } else {  
+        } else {
             $newval = $env{'form.'.$context.'_'.$tool};
         }
         if ($userenv->{$context.'.'.$tool} ne '') {
@@ -5572,7 +5596,7 @@
                     my $helplink = ' href="javascript:helpMenu('."'display'".')"';
                     $response .= '<br /><br />';
                     if ($context eq 'requestcrs') {
-                        $response .= &mt("You are not authorized to defined new users in the new course's domain - [_1].",$targetdom);
+                        $response .= &mt("You are not authorized to define new users in the new course's domain - [_1].",$targetdom);
                     } else {
                         $response .= &mt("You are not authorized to create new users in your current role's domain - [_1].",$targetdom);
                     }

--raeburn1252623892--