Diff for /loncom/interface/lonuserutils.pm between versions 1.175 and 1.180

version 1.175, 2016/10/04 21:02:16 version 1.180, 2017/01/02 19:44:07
Line 2563  $verify_action_js Line 2563  $verify_action_js
   
 function username_display_launch(username,domain) {  function username_display_launch(username,domain) {
     var target;      var target;
     for (var i=0; i<document.$formname.usernamelink.length; i++) {      if (!document.$formname.usernamelink.length) {
         if (document.$formname.usernamelink[i].checked) {          target = document.$formname.usernamelink.value;
             target = document.$formname.usernamelink[i].value;      } else {
           for (var i=0; i<document.$formname.usernamelink.length; i++) {
               if (document.$formname.usernamelink[i].checked) {
                  target = document.$formname.usernamelink[i].value;
               }
         }          }
     }      }
     if (target == 'modify') {      if ((target == 'modify') || (target == 'activity')) {
           var nextaction = 'singleuser';
           if (target == 'activity') {
               nextaction = 'accesslogs';
           }
         if (document.$formname.userwin.checked == true) {          if (document.$formname.userwin.checked == true) {
             var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&action=singleuser&srchin=dom&srchby=uname&srchtype=exact&popup=1';              var url = '/adm/createuser?srchterm='+username+'&srchdomain='+domain+'&phase=get_user_info&srchin=dom&srchby=uname&srchtype=exact&popup=1&action='+nextaction;
             var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';              var options = 'height=600,width=800,resizable=yes,scrollbars=yes,location=no,menubar=no,toolbar=no';
             modifywin = window.open(url,'',options,1);              modifywin = window.open(url,'',options,1);
             modifywin.focus();              modifywin.focus();
Line 2579  function username_display_launch(usernam Line 2587  function username_display_launch(usernam
             document.$formname.srchterm.value=username;              document.$formname.srchterm.value=username;
             document.$formname.srchdomain.value=domain;              document.$formname.srchdomain.value=domain;
             document.$formname.phase.value='get_user_info';              document.$formname.phase.value='get_user_info';
             document.$formname.action.value = 'singleuser';              document.$formname.action.value = nextaction;
             document.$formname.submit();              document.$formname.submit();
         }          }
     }      }
Line 2625  END Line 2633  END
                        'owin'       => "Open in a new window",                         'owin'       => "Open in a new window",
                        'modify'     => "Modify a user's information",                         'modify'     => "Modify a user's information",
                        'track'      => "View a user's recent activity",                         'track'      => "View a user's recent activity",
                          'activity'   => "View a user's access log", 
                       );                        );
     my %lt = (%coltxt,%acttxt);      my %lt = (%coltxt,%acttxt);
     my $rolefilter = $env{'form.showrole'};      my $rolefilter = $env{'form.showrole'};
Line 2715  END Line 2724  END
             if ($permission->{'cusr'}) {              if ($permission->{'cusr'}) {
                 unshift (@linkdests,'modify');                  unshift (@linkdests,'modify');
             }              }
             if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||              if ($context eq 'course') {
                 &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.                  if (&Apache::lonnet::allowed('vsa', $env{'request.course.id'}) ||
                                          $env{'request.course.sec'})) {                      &Apache::lonnet::allowed('vsa', $env{'request.course.id'}.'/'.
                 push(@linkdests,'track');                                               $env{'request.course.sec'})) {
                       push(@linkdests,'track');
                   }
               } elsif ($context eq 'domain') {
                   if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
                       push(@linkdests,'activity');
                   }
             }              }
   
             $output .= '<td>';              $output .= '<td>';
             my $usernamelink = $env{'form.usernamelink'};              my $usernamelink = $env{'form.usernamelink'};
             if ($usernamelink eq '') {              if ($usernamelink eq '') {
Line 2989  END Line 3003  END
             } (keys(%$userlist));              } (keys(%$userlist));
     }      }
     my $rowcount = 0;      my $rowcount = 0;
       my $disabled;
       if ($mode eq 'autoenroll') {
           unless ($permission->{'cusr'}) {
               $disabled = ' disabled="disabled"';
           }
       }
     foreach my $user (@sorted_users) {      foreach my $user (@sorted_users) {
         my %in;          my %in;
         my $sdata = $userlist->{$user};          my $sdata = $userlist->{$user};
Line 3025  END Line 3045  END
             if ($mode eq 'autoenroll') {              if ($mode eq 'autoenroll') {
                 my $cellentry;                  my $cellentry;
                 if ($in{'type'} eq 'auto') {                  if ($in{'type'} eq 'auto') {
                     $cellentry = '<b>'.&mt('auto').'</b>&nbsp;<label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;'.&mt('Change').'</label>';                      $cellentry = '<b>'.&mt('auto').'</b>&nbsp;<label><input type="checkbox" name="chgauto" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' />&nbsp;'.&mt('Change').'</label>';
                     $autocount ++;                      $autocount ++;
                 } else {                  } else {
                     $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><span class="LC_nobreak"><label><input type="checkbox" name="chgmanual" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;'.&mt('Change').'</label></span></td></tr><tr><td><span class="LC_nobreak">';                      $cellentry = '<table border="0" cellspacing="0"><tr><td rowspan="2"><b>'.&mt('manual').'</b></td><td><span class="LC_nobreak"><label><input type="checkbox" name="chgmanual" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' />&nbsp;'.&mt('Change').'</label></span></td></tr><tr><td><span class="LC_nobreak">';
                     $manualcount ++;                      $manualcount ++;
                     if ($in{'lockedtype'}) {                      if ($in{'lockedtype'}) {
                         $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;'.&mt('Unlock').'</label>';                          $cellentry .= '<label><input type="checkbox" name="unlockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' />&nbsp;'.&mt('Unlock').'</label>';
                         $unlockcount ++;                          $unlockcount ++;
                     } else {                      } else {
                         $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'" />&nbsp;'.&mt('Lock').'</label>';                          $cellentry .= '<label><input type="checkbox" name="lockchg" value="'.$in{'username'}.':'.$in{'domain'}.'"'.$disabled.' />&nbsp;'.&mt('Lock').'</label>';
                         $lockcount ++;                          $lockcount ++;
                     }                      }
                     $cellentry .= '</span></td></tr></table>';                      $cellentry .= '</span></td></tr></table>';
Line 5412  sub set_login { Line 5432  sub set_login {
 }  }
   
 sub course_sections {  sub course_sections {
     my ($sections_count,$role,$current_sec) = @_;      my ($sections_count,$role,$current_sec,$disabled) = @_;
     my $output = '';      my $output = '';
     my @sections = (sort {$a <=> $b} keys(%{$sections_count}));      my @sections = (sort {$a <=> $b} keys(%{$sections_count}));
     my $numsec = scalar(@sections);      my $numsec = scalar(@sections);
     my $is_selected = ' selected="selected"';      my $is_selected = ' selected="selected"';
     if ($numsec <= 1) {      if ($numsec <= 1) {
         $output = '<select name="currsec_'.$role.'" >'."\n".          $output = '<select name="currsec_'.$role.'"'.$disabled.'>'."\n".
                   '  <option value="">'.&mt('Select').'</option>'."\n";                    '  <option value="">'.&mt('Select').'</option>'."\n";
         if ($current_sec eq 'none') {          if ($current_sec eq 'none') {
             $output .=                     $output .=       
Line 5441  sub course_sections { Line 5461  sub course_sections {
         my $multiple = 4;          my $multiple = 4;
         if (scalar(@sections) < 4) { $multiple = scalar(@sections); }          if (scalar(@sections) < 4) { $multiple = scalar(@sections); }
         if ($role eq 'st') {          if ($role eq 'st') {
             $output .= '>'."\n".              $output .= $disabled.'>'."\n".
                        '  <option value="">'.&mt('Select').'</option>'."\n";                         '  <option value="">'.&mt('Select').'</option>'."\n";
             if ($current_sec eq 'none') {              if ($current_sec eq 'none') {
                 $output .=                   $output .= 
Line 5451  sub course_sections { Line 5471  sub course_sections {
                        '  <option value="">'.&mt('No section')."</option>\n";                         '  <option value="">'.&mt('No section')."</option>\n";
             }              }
         } else {          } else {
             $output .= 'multiple="multiple" size="'.$multiple.'">'."\n";              $output .= 'multiple="multiple" size="'.$multiple.'"'.$disabled.'>'."\n";
         }          }
         foreach my $sec (@sections) {          foreach my $sec (@sections) {
             if ($current_sec eq $sec) {              if ($current_sec eq $sec) {
Line 5668  sub can_create_user { Line 5688  sub can_create_user {
     my $cancreate = 1;      my $cancreate = 1;
     if (&Apache::lonnet::allowed('mau',$dom)) {      if (&Apache::lonnet::allowed('mau',$dom)) {
         return $cancreate;          return $cancreate;
       } elsif ($context eq 'domain') {
           $cancreate = 0;
           return $cancreate;
     }      }
     if (ref($domconf{'usercreation'}) eq 'HASH') {      if (ref($domconf{'usercreation'}) eq 'HASH') {
         if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {          if (ref($domconf{'usercreation'}{'cancreate'}) eq 'HASH') {
Line 5868  sub get_permission { Line 5891  sub get_permission {
                 }                  }
             }              }
         }          }
           if ($env{'request.course.id'}) {
               my $user = $env{'user.name'}.':'.$env{'user.domain'};
               if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
                                     $user)) {
                   $permission{'owner'} = 1;
               } elsif (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.co-owners'} ne '')) {
                   if (grep(/^\Q$user\E$/,split(/,/,$env{'course.'.$env{'request.course.id'}.'.internal.co-owners'}))) {
                       $permission{'co-owner'} = 1;
                   }
               }
           }
     } elsif ($context eq 'author') {      } elsif ($context eq 'author') {
         $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});          $permission{'cusr'} = &authorpriv($env{'user.name'},$env{'request.role.domain'});
         $permission{'view'} = $permission{'cusr'};          $permission{'view'} = $permission{'cusr'};
Line 5887  sub get_permission { Line 5921  sub get_permission {
         if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {          if (&Apache::lonnet::allowed('ccr',$env{'request.role.domain'})) {
             $permission{'custom'} = 1;              $permission{'custom'} = 1;
         }          }
         $permission{'view'} = $permission{'cusr'};          if (&Apache::lonnet::allowed('vac',$env{'request.role.domain'})) {
               $permission{'activity'} = 1;
           }
           if (&Apache::lonnet::allowed('vur',$env{'request.role.domain'})) {
               $permission{'view'} = 1;
           }
           if (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'})) {
               $permission{'owner'} = 1;
           }
     }      }
     my $allowed = 0;      my $allowed = 0;
     foreach my $perm (values(%permission)) {      foreach my $perm (values(%permission)) {
Line 6383  END Line 6425  END
 }  }
   
 sub custom_role_table {  sub custom_role_table {
     my ($crstype,$full,$levels,$levelscurrent,$prefix) = @_;      my ($crstype,$full,$levels,$levelscurrent,$prefix,$add_class,$id) = @_;
     return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&      return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
                    (ref($levelscurrent) eq 'HASH'));                     (ref($levelscurrent) eq 'HASH'));
     my %lt=&Apache::lonlocal::texthash (      my %lt=&Apache::lonlocal::texthash (
Line 6397  sub custom_role_table { Line 6439  sub custom_role_table {
                system => '_s',                 system => '_s',
              );               );
   
     my $output=&Apache::loncommon::start_data_table().      my $output=&Apache::loncommon::start_data_table($add_class,$id).
                &Apache::loncommon::start_data_table_header_row().                 &Apache::loncommon::start_data_table_header_row().
                '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.                 '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
                '</th><th>'.$lt{'ssl'}.'</th>'.                 '</th><th>'.$lt{'ssl'}.'</th>'.
Line 6654  sub custom_role_update { Line 6696  sub custom_role_update {
     return %privs;      return %privs;
 }  }
   
   sub adhoc_status_types {
       my ($cdom,$context,$role,$selectedref,$othertitle,$usertypes,$types,$disabled) = @_;
       my $output = &Apache::loncommon::start_data_table();
       my $numinrow = 3;
       my $rem;
       if (ref($types) eq 'ARRAY') {
           for (my $i=0; $i<@{$types}; $i++) {
               if (defined($usertypes->{$types->[$i]})) {
                   my $rem = $i%($numinrow);
                   if ($rem == 0) {
                       if ($i > 0) {
                           $output .= &Apache::loncommon::end_data_table_row();
                       }
                       $output .= &Apache::loncommon::start_data_table_row();
                   }
                   my $check;
                   if (ref($selectedref) eq 'ARRAY') {
                       if (grep(/^\Q$types->[$i]\E$/,@{$selectedref})) {
                           $check = ' checked="checked"';
                       }
                   }
                   $output .= '<td>'.
                              '<span class="LC_nobreak"><label>'.
                              '<input type="checkbox" name="'.$context.$role.'_status" '.
                              'value="'.$types->[$i].'"'.$check.$disabled.' />'.
                              $usertypes->{$types->[$i]}.'</label></span></td>';
               }
           }
           $rem = @{$types}%($numinrow);
       }
       my $colsleft = $numinrow - $rem;
       if (($rem == 0) && (@{$types} > 0)) {
           $output .= &Apache::loncommon::start_data_table_row();
       }
       if ($colsleft > 1) {
           $output .= '<td colspan="'.$colsleft.'">';
       } else {
           $output .= '<td>';
       }
       my $defcheck;
       if (ref($selectedref) eq 'ARRAY') {
           if (grep(/^default$/,@{$selectedref})) {
               $defcheck = ' checked="checked"';
           }
       }
       $output .= '<span class="LC_nobreak"><label>'.
                  '<input type="checkbox" name="'.$context.$role.'_status"'.
                  'value="default"'.$defcheck.$disabled.' />'.
                  $othertitle.'</label></span></td>'.
                  &Apache::loncommon::end_data_table_row().
                  &Apache::loncommon::end_data_table();
       return $output;
   }
   
   sub adhoc_staff {
       my ($access,$context,$role,$selectedref,$adhocref,$disabled) = @_;
       my $output;
       if (ref($adhocref) eq 'HASH') {
           my %by_fullname;
           my $numinrow = 4;
           my $rem;
           my @personnel = keys(%{$adhocref});
           if (@personnel) {
               foreach my $person (@personnel) {
                   my ($uname,$udom) = split(/:/,$person);
                   my $fullname = &Apache::loncommon::plainname($uname,$udom,'lastname');
                   $by_fullname{$fullname} = $person;
               }
               my @sorted = sort(keys(%by_fullname));
               my $count = scalar(@sorted);
               $output = &Apache::loncommon::start_data_table();
               for (my $i=0; $i<$count; $i++) {
                   my $rem = $i%($numinrow);
                   if ($rem == 0) {
                       if ($i > 0) {
                           $output .= &Apache::loncommon::end_data_table_row();
                       }
                       $output .= &Apache::loncommon::start_data_table_row();
                   }
                   my $check;
                   my $user = $by_fullname{$sorted[$i]};
                   if (ref($selectedref) eq 'ARRAY') {
                       if (grep(/^\Q$user\E$/,@{$selectedref})) {
                           $check = ' checked="checked"';
                       }
                   }
                   if ($i == $count-1) {
                       my $colsleft = $numinrow - $rem;
                       if ($colsleft > 1) {
                           $output .= '<td colspan="'.$colsleft.'">';
                       } else {
                           $output .= '<td>';
                       }
                   } else {
                       $output .= '<td>';
                   }
                   $output .= '<span class="LC_nobreak"><label>'.
                              '<input type="checkbox" name="'.$context.$role.'_staff_'.$access.'" '.
                              'value="'.$user.'"'.$check.$disabled.' />'.$sorted[$i].
                              '</label></span></td>';
                   if ($i == $count-1) {
                       $output .= &Apache::loncommon::end_data_table_row();
                   }
               }
               $output .= &Apache::loncommon::end_data_table();
           }
       }
       return $output;
   }
   
   
 1;  1;
   

Removed from v.1.175  
changed lines
  Added in v.1.180


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>