Diff for /loncom/interface/lonuserutils.pm between versions 1.174 and 1.198

version 1.174, 2016/07/24 14:34:59 version 1.198, 2019/05/06 18:25:58
Line 30 Line 30
   
 package Apache::lonuserutils;  package Apache::lonuserutils;
   
   =pod
   
   =head1 NAME
   
   Apache::lonuserutils.pm
   
   =head1 SYNOPSIS
   
       Utilities for management of users and custom roles
   
       Provides subroutines called by loncreateuser.pm
   
   =head1 OVERVIEW
   
   =cut
   
 use strict;  use strict;
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon();  use Apache::loncommon();
Line 422  sub javascript_validations { Line 438  sub javascript_validations {
             } elsif ($context eq 'domain') {              } elsif ($context eq 'domain') {
                 $setsection_call = 'setCourse()';                  $setsection_call = 'setCourse()';
                 $setsections_js = &dc_setcourse_js($param{'formname'},$mode,                  $setsections_js = &dc_setcourse_js($param{'formname'},$mode,
                                                    $context,$showcredits);                                                     $context,$showcredits,$domain);
             }              }
             $finish = "  var checkSec = $setsection_call\n".              $finish = "  var checkSec = $setsection_call\n".
                       "  if (checkSec == 'ok') {\n".                        "  if (checkSec == 'ok') {\n".
Line 515  END Line 531  END
 /* regexp here to check for non \d \. in credits */  /* regexp here to check for non \d \. in credits */
 END  END
     } else {      } else {
           my ($numrules,$intargjs) =
               &passwd_validation_js('vf.elements[current.argfield].value',$domain);
         $auth_checks .= (<<END);          $auth_checks .= (<<END);
     foundatype=1;      foundatype=1;
     if (current.argfield == null || current.argfield == '') {      if (current.argfield == null || current.argfield == '') {
           // The login radiobutton checked does not have an associated textbox
       } else if (vf.elements[current.argfield].value == '') {
         var alertmsg = '';          var alertmsg = '';
         switch (current.radiovalue) {          switch (current.radiovalue) {
             case 'krb':              case 'krb':
                 alertmsg = '$alert{'krb'}';                  alertmsg = '$alert{'krb'}';
                 break;                  break;
             case 'loc':              case 'loc':
             case 'fsys':              case 'int':
                 alertmsg = '$alert{'ipass'}';                  alertmsg = '$alert{'ipass'}';
                 break;                  break;
             case 'fsys':              case 'fsys':
                 alertmsg = '';                  alertmsg = '$alert{'ipass'}';
                 break;                  break;
               case 'lti':
             default:              default:
                 alertmsg = '';                  alertmsg = '';
         }          }
Line 537  END Line 558  END
             alert(alertmsg);              alert(alertmsg);
             return;              return;
         }          }
       } else if (current.radiovalue == 'int') {
           if ($numrules > 0) {
   $intargjs
           }
     }      }
 END  END
     }      }
Line 625  END Line 650  END
                  $section_checks.$authheader;                   $section_checks.$authheader;
     return $result;      return $result;
 }  }
   
   sub passwd_validation_js {
       my ($currpasswdval,$domain) = @_;
       my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
       my ($min,$max,@chars,$numrules,$intargjs,%alert);
       $numrules = 0;
       if (ref($passwdconf{'chars'}) eq 'ARRAY') {
           if ($passwdconf{'min'} =~ /^\d+$/) {
               $min = $passwdconf{'min'};
               $numrules ++;
           }
           if ($passwdconf{'max'} =~ /^\d+$/) {
               $max = $passwdconf{'max'};
               $numrules ++;
           }
           @chars = @{$passwdconf{'chars'}};
           if (@chars) {
               $numrules ++;
           }
       } else {
           $min = 7;
           $numrules ++;
       }
       if (($min ne '') || ($max ne '') || (@chars > 0)) {
           my $alertmsg = &mt('Initial password did not satisfy requirement(s):').'\n\n';
           if ($min) {
               $alert{'min'} = &mt('minimum [quant,_1,character]',$min).'\n';
           }
           if ($max) {
               $alert{'max'} = &mt('maximum [quant,_1,character]',$max).'\n';
           }
           my (@charalerts,@charrules);
           if (@chars) {
               if (grep(/^uc$/,@chars)) {
                   push(@charalerts,&mt('contain at least one upper case letter'));
                   push(@charrules,'uc');
               }
               if (grep(/^lc$/,@chars)) {
                   push(@charalerts,&mt('contain at least one lower case letter'));
                   push(@charrules,'lc');
               }
               if (grep(/^num$/,@chars)) {
                   push(@charalerts,&mt('contain at least one number'));
                   push(@charrules,'num');
               }
               if (grep(/^spec$/,@chars)) {
                   push(@charalerts,&mt('contain at least one non-alphanumeric'));
                   push(@charrules,'spec');
               }
           }
           $intargjs = qq|            var rulesmsg = '';\n|.
                       qq|            var currpwval = $currpasswdval;\n|;
               if ($min) {
                   $intargjs .= qq|
               if (currpwval.length < $min) {
                   rulesmsg += ' - $alert{min}';
               }
   |;
               }
               if ($max) {
                   $intargjs .= qq|
               if (currpwval.length > $max) {
                   rulesmsg += ' - $alert{max}';
               }
   |;
               }
               if (@chars > 0) {
                   my $charrulestr = '"'.join('","',@charrules).'"';
                   my $charalertstr = '"'.join('","',@charalerts).'"';
                   $intargjs .= qq|            var brokerules = new Array();\n|.
                                qq|            var charrules = new Array($charrulestr);\n|.
                                qq|            var charalerts = new Array($charalertstr);\n|;
                   my %rules;
                   map { $rules{$_} = 1; } @chars;
                   if ($rules{'uc'}) {
                       $intargjs .= qq|
               var ucRegExp = /[A-Z]/;
               if (!ucRegExp.test(currpwval)) {
                   brokerules.push('uc');
               }
   |;
                   }
                   if ($rules{'lc'}) {
                       $intargjs .= qq|
               var lcRegExp = /[a-z]/;
               if (!lcRegExp.test(currpwval)) {
                   brokerules.push('lc');
               }
   |;
                   }
                   if ($rules{'num'}) {
                        $intargjs .= qq|
               var numRegExp = /[0-9]/;
               if (!numRegExp.test(currpwval)) {
                   brokerules.push('num');
               }
   |;
                   }
                   if ($rules{'spec'}) {
                        $intargjs .= q|
               var specRegExp = /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{\|}~]/;
               if (!specRegExp.test(currpwval)) {
                   brokerules.push('spec');
               }
   |;
                   }
                   $intargjs .= qq|
               if (brokerules.length > 0) {
                   for (var i=0; i<brokerules.length; i++) {
                       for (var j=0; j<charrules.length; j++) {
                           if (brokerules[i] == charrules[j]) {
                               rulesmsg += ' - '+charalerts[j]+'\\n';
                               break;
                           }
                       }
                   }
               }
   |;
               }
               $intargjs .= qq|
               if (rulesmsg != '') {
                   rulesmsg = '$alertmsg'+rulesmsg;
                   alert(rulesmsg);
                   return false;
               }
   |;
       }
       return ($numrules,$intargjs);
   }
   
 ###############################################################  ###############################################################
 ###############################################################  ###############################################################
 sub upload_manager_javascript_forward_associate {  sub upload_manager_javascript_forward_associate {
Line 882  sub print_upload_manager_footer { Line 1037  sub print_upload_manager_footer {
     my $krbform = &Apache::loncommon::authform_kerberos(%param);      my $krbform = &Apache::loncommon::authform_kerberos(%param);
     my $intform = &Apache::loncommon::authform_internal(%param);      my $intform = &Apache::loncommon::authform_internal(%param);
     my $locform = &Apache::loncommon::authform_local(%param);      my $locform = &Apache::loncommon::authform_local(%param);
       my $ltiform = &Apache::loncommon::authform_lti(%param);
     my $date_table = &date_setting_table(undef,undef,$context,undef,      my $date_table = &date_setting_table(undef,undef,$context,undef,
                                          $formname,$permission,$crstype);                                           $formname,$permission,$crstype);
   
Line 910  sub print_upload_manager_footer { Line 1066  sub print_upload_manager_footer {
             &Apache::loncommon::help_open_topic('Auth_Options').              &Apache::loncommon::help_open_topic('Auth_Options').
             "</p>\n";              "</p>\n";
     }      }
     $Str .= &set_login($defdom,$krbform,$intform,$locform);      $Str .= &set_login($defdom,$krbform,$intform,$locform,$ltiform);
   
     my ($home_server_pick,$numlib) =      my ($home_server_pick,$numlib) =
         &Apache::loncommon::home_server_form_item($defdom,'lcserver',          &Apache::loncommon::home_server_form_item($defdom,'lcserver',
Line 927  sub print_upload_manager_footer { Line 1083  sub print_upload_manager_footer {
                 &Apache::lonhtmlcommon::row_closure();                  &Apache::lonhtmlcommon::row_closure();
     }      }
   
       my ($trusted,$untrusted);
       if ($context eq 'course') {
           ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
       } elsif ($context eq 'author') {
           ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
       }
     $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))      $Str .= &Apache::lonhtmlcommon::row_title(&mt('Default domain'))
            .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1)             .&Apache::loncommon::select_dom_form($defdom,'defaultdomain',undef,1,undef,$trusted,$untrusted)
            .&Apache::lonhtmlcommon::row_closure();             .&Apache::lonhtmlcommon::row_closure();
   
     $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))      $Str .= &Apache::lonhtmlcommon::row_title(&mt('Starting and Ending Dates'))
Line 1105  sub print_upload_manager_form { Line 1267  sub print_upload_manager_form {
     if (!$env{'form.datatoken'}) {      if (!$env{'form.datatoken'}) {
         $datatoken=&Apache::loncommon::upfile_store($r);          $datatoken=&Apache::loncommon::upfile_store($r);
     } else {      } else {
         $datatoken=$env{'form.datatoken'};          $datatoken=&Apache::loncommon::valid_datatoken($env{'form.datatoken'});
         &Apache::loncommon::load_tmp_file($r);          if ($datatoken ne '') {
               &Apache::loncommon::load_tmp_file($r,$datatoken);
           }
       }
       if ($datatoken eq '') {
           $r->print('<p class="LC_error">'.&mt('Error').': '.
                     &mt('Invalid datatoken').'</p>');
           return 'missingdata';
     }      }
     my @records=&Apache::loncommon::upfile_record_sep();      my @records=&Apache::loncommon::upfile_record_sep();
     if($env{'form.noFirstLine'}){      if($env{'form.noFirstLine'}){
Line 1190  sub print_upload_manager_form { Line 1359  sub print_upload_manager_form {
     }      }
     &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,      &print_upload_manager_footer($r,$i,$keyfields,$defdom,$today,$halfyear,
                                  $context,$permission,$crstype,$showcredits);                                   $context,$permission,$crstype,$showcredits);
       return 'ok';
 }  }
   
 sub setup_date_selectors {  sub setup_date_selectors {
Line 1531  sub curr_role_permissions { Line 1701  sub curr_role_permissions {
 # ======================================================= Existing Custom Roles  # ======================================================= Existing Custom Roles
   
 sub my_custom_roles {  sub my_custom_roles {
     my ($crstype) = @_;      my ($crstype,$udom,$uname) = @_;
     my %returnhash=();      my %returnhash=();
     my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});      my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
     my %rolehash=&Apache::lonnet::dump('roles');      my %rolehash=&Apache::lonnet::dump('roles',$udom,$uname);
     foreach my $key (keys(%rolehash)) {      foreach my $key (keys(%rolehash)) {
         if ($key=~/^rolesdef\_(\w+)$/) {          if ($key=~/^rolesdef\_(\w+)$/) {
             if ($crstype eq 'Community') {              if ($crstype eq 'Community') {
Line 2291  sub courses_selector { Line 2461  sub courses_selector {
             my $allidlist = $idlist{$codetitles[0]};              my $allidlist = $idlist{$codetitles[0]};
             $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);              $jscript .= &Apache::courseclassifier::courseset_js_start($formname,$longtitles_str,$allidlist);
             $jscript .= $scripttext;              $jscript .= $scripttext;
             $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,@codetitles);              $jscript .= &Apache::courseclassifier::javascript_code_selections($formname,\@codetitles);
         }          }
     }      }
     my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);      my $cb_jscript = &Apache::loncommon::coursebrowser_javascript($cdom);
Line 2320  function setCourseCat(formname) { Line 2490  function setCourseCat(formname) {
     }      }
     courseSet('$codetitles[1]');      courseSet('$codetitles[1]');
     for (var j=0; j<formname.Department.length; j++) {      for (var j=0; j<formname.Department.length; j++) {
         if (formname.Department.options[j].value == "$env{'form.Department'}") {            formname.Department.options[j].selected = true;          if (formname.Department.options[j].value == "$env{'form.Department'}") {
               formname.Department.options[j].selected = true;
         }          }
     }      }
     if (formname.Department.options[formname.Department.selectedIndex].value == -1) {      if (formname.Department.options[formname.Department.selectedIndex].value == -1) {
Line 2547  $verify_action_js Line 2718  $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 2563  function username_display_launch(usernam Line 2742  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 2609  END Line 2788  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 2699  END Line 2879  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 2727  END Line 2912  END
                .'<input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}                 .'<input type="checkbox" name="userwin" value="1"'.$checkwin.' />'.$lt{'owin'}
                .'</label></span></td></tr></table></fieldset></div>';                 .'</label></span></td></tr></table></fieldset></div>';
         }          }
         $output .= "\n".'<br clear="all" />'."\n".          $output .= "\n".'<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
                   &Apache::loncommon::start_data_table().                    &Apache::loncommon::start_data_table().
                   &Apache::loncommon::start_data_table_header_row();                    &Apache::loncommon::start_data_table_header_row();
         if ($mode eq 'autoenroll') {          if ($mode eq 'autoenroll') {
Line 2973  END Line 3158  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 3009  END Line 3200  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 3065  END Line 3256  END
                         }                          }
                         if ($showcheckbox) {                          if ($showcheckbox) {
                             $r->print('<td><input type="checkbox" name="'.                              $r->print('<td><input type="checkbox" name="'.
                                       'actionlist" value="'.&HTML::Entities::encode($checkval,'&<>"').'" /></td>');                                        'actionlist" value="'.
                                         &HTML::Entities::encode($checkval,'&<>"').'" />');
                               foreach my $item ('start','end') {
                                   $r->print('<input type="hidden" name="'.
                                             &HTML::Entities::encode($checkval.'_'.$item,'&<>"').'"'.
                                             ' value="'.$sdata->[$index{$item}].'" />');
                               }
                               $r->print('</td>');
                         } else {                          } else {
                             $r->print('<td>&nbsp;</td>');                              $r->print('<td>&nbsp;</td>');
                         }                          }
Line 3079  END Line 3277  END
             foreach my $item (@cols) {              foreach my $item (@cols) {
                 if ($item eq 'username') {                  if ($item eq 'username') {
                     $r->print('<td>'.&print_username_link($mode,\%in).'</td>');                      $r->print('<td>'.&print_username_link($mode,\%in).'</td>');
                 } elsif (($item eq 'start' || $item eq 'end') && ($actionselect)) {  
                     $r->print('<td>'.$in{$item}.'<input type="hidden" name="'.&HTML::Entities::encode($checkval.'_'.$item.'" value="'.$sdata->[$index{$item}],'&<>"').'" /></td>'."\n");  
                 } elsif ($item eq 'status') {                  } elsif ($item eq 'status') {
                     my $showitem = $in{$item};                      my $showitem = $in{$item};
                     if (defined($ltstatus{$in{$item}})) {                      if (defined($ltstatus{$in{$item}})) {
Line 4055  sub print_first_users_upload_form { Line 4251  sub print_first_users_upload_form {
            .&Apache::lonhtmlcommon::end_pick_box();             .&Apache::lonhtmlcommon::end_pick_box();
   
     $str .= '<p>'      $str .= '<p>'
            .'<input type="submit" name="fileupload" value="'.&mt('Next').'"'             .'<input type="button" name="fileupload" value="'.&mt('Next').'"'
            .' onclick="javascript:checkUpload(this.form);" />'             .' onclick="javascript:checkUpload(this.form);" />'
            .'</p>';             .'</p>';
   
Line 4066  sub print_first_users_upload_form { Line 4262  sub print_first_users_upload_form {
 # ================================================= Drop/Add from uploaded file  # ================================================= Drop/Add from uploaded file
 sub upfile_drop_add {  sub upfile_drop_add {
     my ($r,$context,$permission,$showcredits) = @_;      my ($r,$context,$permission,$showcredits) = @_;
     &Apache::loncommon::load_tmp_file($r);      my $datatoken = &Apache::loncommon::valid_datatoken($env{'form.datatoken'});
       if ($datatoken ne '') {
           &Apache::loncommon::load_tmp_file($r,$datatoken);
       }
     my @userdata=&Apache::loncommon::upfile_record_sep();      my @userdata=&Apache::loncommon::upfile_record_sep();
     if($env{'form.noFirstLine'}){shift(@userdata);}      if($env{'form.noFirstLine'}){shift(@userdata);}
     my @keyfields = split(/\,/,$env{'form.keyfields'});      my @keyfields = split(/\,/,$env{'form.keyfields'});
Line 4080  sub upfile_drop_add { Line 4279  sub upfile_drop_add {
             $fields{$env{'form.f'.$i}}=$keyfields[$i];              $fields{$env{'form.f'.$i}}=$keyfields[$i];
         }          }
     }      }
     if ($env{'form.fullup'} ne 'yes') {  
         $r->print('<form name="studentform" method="post" action="/adm/createuser">'."\n".  
                   '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />');  
     }  
     #      #
     # Store the field choices away      # Store the field choices away
     my @storefields = qw/username names fname mname lname gen id       my @storefields = qw/username names fname mname lname gen id 
Line 4097  sub upfile_drop_add { Line 4292  sub upfile_drop_add {
         $fieldstype{$field.'_choice'} = 'scalar';          $fieldstype{$field.'_choice'} = 'scalar';
     }      }
     &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);      &Apache::loncommon::store_course_settings('enrollment_upload',\%fieldstype);
     my ($cid,$crstype,$setting);      my ($cid,$crstype,$setting,$crsdom);
     if ($context eq 'domain') {      if ($context eq 'domain') {
         $setting = $env{'form.roleaction'};          $setting = $env{'form.roleaction'};
     }      }
     if ($env{'request.course.id'} ne '') {      if ($env{'request.course.id'} ne '') {
         $cid = $env{'request.course.id'};          $cid = $env{'request.course.id'};
         $crstype = &Apache::loncommon::course_type();          $crstype = &Apache::loncommon::course_type();
           $crsdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
     } elsif ($setting eq 'course') {      } elsif ($setting eq 'course') {
         if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {          if (&Apache::lonnet::is_course($env{'form.dcdomain'},$env{'form.dccourse'})) {
             $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};              $cid = $env{'form.dcdomain'}.'_'.$env{'form.dccourse'};
             $crstype = &Apache::loncommon::course_type($cid);              $crstype = &Apache::loncommon::course_type($cid);
               $crsdom = $env{'form.dcdomain'};
         }          }
     }      }
     my ($startdate,$enddate) = &get_dates_from_form();      my ($startdate,$enddate) = &get_dates_from_form();
Line 4118  sub upfile_drop_add { Line 4315  sub upfile_drop_add {
     my $defdom=$env{'request.role.domain'};      my $defdom=$env{'request.role.domain'};
     my $domain;      my $domain;
     if ($env{'form.defaultdomain'} ne '') {      if ($env{'form.defaultdomain'} ne '') {
         $domain = $env{'form.defaultdomain'};          if (($context eq 'course') || ($setting eq 'course')) {
               if ($env{'form.defaultdomain'} eq $crsdom) {
                   $domain = $env{'form.defaultdomain'};
               } else {
                   if (&Apache::lonnet::will_trust('enroll',$crsdom,$env{'form.defaultdomain'})) {
                       $domain = $env{'form.defaultdomain'};
                   } else {
                       $r->print('<span class="LC_error">'.&mt('Error').': '.
                                 &mt('Enrollment of users not permitted for specified default domain: [_1].',
                                     &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
                       return 'untrusted';
                   }
               }
           } elsif ($context eq 'author') {
               if ($env{'form.defaultdomain'} eq $defdom) {
                   $domain = $env{'form.defaultdomain'}; 
               } else {
                   if ((&Apache::lonnet::will_trust('othcoau',$defdom,$env{'form.defaultdomain'})) &&
                       (&Apache::lonnet::will_trust('coaurem',$env{'form.defaultdomain'},$defdom))) {
                       $domain = $env{'form.defaultdomain'};
                   } else {
                       $r->print('<span class="LC_error">'.&mt('Error').': '.
                                 &mt('Addition of users not permitted for specified default domain: [_1].',
                                     &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
                       return 'untrusted';
                   }
               }
           } elsif (($context eq 'domain') && ($setting eq 'domain')) {
               if ($env{'form.defaultdomain'} eq $defdom) {
                   $domain = $env{'form.defaultdomain'};
               } else {
                   if (&Apache::lonnet::will_trust('domroles',$defdom,$env{'form.defaultdomain'})) {
                       $domain = $env{'form.defaultdomain'};
                   } else {
                       $r->print('<span class="LC_error">'.&mt('Error').': '.
                                 &mt('Addition of users not permitted for specified default domain: [_1].',
                                     &Apache::lonnet::domain($env{'form.defaultdomain'},'description')).'</span>');
                       return 'untrusted';
                   }
               }
           }
     } else {      } else {
         $domain = $defdom;          $domain = $defdom;
     }      }
Line 4128  sub upfile_drop_add { Line 4365  sub upfile_drop_add {
     } else {      } else {
         my %home_servers = &Apache::lonnet::get_servers($defdom,'library');          my %home_servers = &Apache::lonnet::get_servers($defdom,'library');
         if (! exists($home_servers{$desiredhost})) {          if (! exists($home_servers{$desiredhost})) {
             $r->print('<span class="LC_error">'.&mt('Error').              $r->print('<p class="LC_error">'.&mt('Error').': '.
                       &mt('Invalid home server specified').'</span>');                        &mt('Invalid home server specified').'</p>');
             $r->print(&Apache::loncommon::end_page());              return 'invalidhome';
             return;  
         }          }
     }      }
     # Determine authentication mechanism      # Determine authentication mechanism
Line 4155  sub upfile_drop_add { Line 4391  sub upfile_drop_add {
         if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {          if ((defined($env{'form.locarg'})) && ($env{'form.locarg'})) {
             $genpwd=$env{'form.locarg'};              $genpwd=$env{'form.locarg'};
         }          }
       } elsif ($env{'form.login'} eq 'lti') {
           $amode='lti';
     }      }
     if ($amode =~ /^krb/) {      if ($amode =~ /^krb/) {
         if (! defined($genpwd) || $genpwd eq '') {          if (! defined($genpwd) || $genpwd eq '') {
Line 4231  sub upfile_drop_add { Line 4469  sub upfile_drop_add {
             }              }
         }          }
     }      }
       if ($datatoken eq '') {
           $r->print('<p class="LC_error">'.&mt('Error').': '.
                     &mt('Invalid datatoken').'</p>');
           return 'missingdata';
       }
     if ( $domain eq &LONCAPA::clean_domain($domain)      if ( $domain eq &LONCAPA::clean_domain($domain)
         && ($amode ne '')) {          && ($amode ne '')) {
         #######################################          #######################################
Line 4302  sub upfile_drop_add { Line 4545  sub upfile_drop_add {
         # Get new users list          # Get new users list
         my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname);          my (%existinguser,%userinfo,%disallow,%rulematch,%inst_results,%alerts,%checkuname);
         my $counter = -1;          my $counter = -1;
           my (%willtrust,%trustchecked);
         foreach my $line (@userdata) {          foreach my $line (@userdata) {
             $counter ++;              $counter ++;
             my @secs;              my @secs;
Line 4349  sub upfile_drop_add { Line 4593  sub upfile_drop_add {
                                 '"<b>'.$entries{$fields{'domain'}}.'</b>"',                                  '"<b>'.$entries{$fields{'domain'}}.'</b>"',
                                 $fname,$mname,$lname,$gen);                                  $fname,$mname,$lname,$gen);
                         next;                          next;
                       } elsif ($entries{$fields{'domain'}} ne $domain) {
                           my $possdom = $entries{$fields{'domain'}};
                           if ($context eq 'course' || $setting eq 'course') {
                               unless ($trustchecked{$possdom}) {
                                   $willtrust{$possdom} = &Apache::lonnet::will_trust('enroll',$domain,$possdom);
                                   $trustchecked{$possdom} = 1;
                               }
                           } elsif ($context eq 'author') {
                               unless ($trustchecked{$possdom}) {
                                   $willtrust{$possdom} = &Apache::lonnet::will_trust('othcoau',$domain,$possdom);
                               }
                               if ($willtrust{$possdom}) {
                                   $willtrust{$possdom} = &Apache::lonnet::will_trust('coaurem',$possdom,$domain); 
                               }
                           }
                           unless ($willtrust{$possdom}) {
                               $disallow{$counter} =
                                   &mt('Unacceptable domain [_1] for user [_2] [_3] [_4] [_5]',
                                       '"<b>'.$possdom.'</b>"',
                                       $fname,$mname,$lname,$gen);
                               next;
                           }
                     }                      }
                     my $username = $entries{$fields{'username'}};                      my $username = $entries{$fields{'username'}};
                     my $userdomain = $entries{$fields{'domain'}};                      my $userdomain = $entries{$fields{'domain'}};
Line 4501  sub upfile_drop_add { Line 4767  sub upfile_drop_add {
                                 &mt('The user does not already exist, and you may not create a new user in a different domain.');                                  &mt('The user does not already exist, and you may not create a new user in a different domain.');
                             next;                              next;
                         } else {                          } else {
                             unless ($password || $env{'form.login'} eq 'loc') {                              unless (($password ne '') || ($env{'form.login'} eq 'loc') || ($env{'form.login'} eq 'lti')) {
                                 $disallow{$counter} =                                  $disallow{$counter} =
                                     &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',                                      &mt('[_1]: This is a new user but no default password was provided, and the authentication type requires one.',
                                         '<b>'.$username.'</b>');                                          '<b>'.$username.'</b>');
Line 4783  sub upfile_drop_add { Line 5049  sub upfile_drop_add {
                   "</p>\n");                    "</p>\n");
         if ($counts{'role'} > 0) {          if ($counts{'role'} > 0) {
             $r->print("<p>\n".              $r->print("<p>\n".
                       &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.&mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.')."</p>\n");                        &mt('Roles added for [quant,_1,user].',$counts{'role'}).' '.
                         &mt('If a user is currently logged-in to LON-CAPA, any new roles which are active will be available when the user next logs in.').
                         "</p>\n");
         } else {          } else {
             $r->print('<p>'.&mt('No roles added').'</p>');              $r->print('<p>'.&mt('No roles added').'</p>');
         }          }
Line 4801  sub upfile_drop_add { Line 5069  sub upfile_drop_add {
             #  Get current classlist              #  Get current classlist
             my $classlist = &Apache::loncoursedata::get_classlist();              my $classlist = &Apache::loncoursedata::get_classlist();
             if (! defined($classlist)) {              if (! defined($classlist)) {
                 $r->print('<form name="studentform" method="post" action="/adm/createuser">'.                  $r->print('<p class="LC_info">'.
                           '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.                            &mt('There are no students with current/future access to the course.').
                           '<p class="LC_info">'.&mt('There are no students with current/future access to the course.').'</p>'.                            '</p>'."\n");
                           '</form>'."\n");  
             } elsif (ref($classlist) eq 'HASH') {              } elsif (ref($classlist) eq 'HASH') {
                 # Remove the students we just added from the list of students.                  # Remove the students we just added from the list of students.
                 foreach my $line (@userdata) {                  foreach my $line (@userdata) {
Line 4820  sub upfile_drop_add { Line 5087  sub upfile_drop_add {
             }              }
         }          }
     } # end of unless      } # end of unless
     if ($env{'form.fullup'} ne 'yes') {      return 'ok';
         $r->print('</form>');  
     }  
 }  }
   
 sub print_namespacing_alerts {  sub print_namespacing_alerts {
Line 5368  END Line 5633  END
 }  }
   
 sub set_login {  sub set_login {
     my ($dom,$authformkrb,$authformint,$authformloc) = @_;      my ($dom,$authformkrb,$authformint,$authformloc,$authformlti) = @_;
     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);      my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
     my $response;      my $response;
     my ($authnum,%can_assign) =      my ($authnum,%can_assign) =
Line 5390  sub set_login { Line 5655  sub set_login {
                          '<td>'.$authformloc.'</td>'.                           '<td>'.$authformloc.'</td>'.
                          &Apache::loncommon::end_data_table_row()."\n";                           &Apache::loncommon::end_data_table_row()."\n";
         }          }
           if ($can_assign{'lti'}) {
               $response .= &Apache::loncommon::start_data_table_row().
                            '<td>'.$authformlti.'</td>'.
                            &Apache::loncommon::end_data_table_row()."\n";
           }
         $response .= &Apache::loncommon::end_data_table();          $response .= &Apache::loncommon::end_data_table();
     }      }
     return $response;      return $response;
 }  }
   
 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 5425  sub course_sections { Line 5695  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 5435  sub course_sections { Line 5705  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 5652  sub can_create_user { Line 5922  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 5731  sub can_modify_userinfo { Line 6004  sub can_modify_userinfo {
     return %canmodify;      return %canmodify;
 }  }
   
   sub can_change_internalpass {
       my ($uname,$udom,$crstype,$permission) = @_;
       my $canchange;
       if (&Apache::lonnet::allowed('mau',$udom)) {
           $canchange = 1;
       } elsif ((ref($permission) eq 'HASH') && ($permission->{'mip'}) &&
                ($udom eq $env{'request.role.domain'})) {
           unless ($env{'course.'.$env{'request.course.id'}.'.internal.nopasswdchg'}) {
               my ($cnum,$cdom) = &get_course_identity();
               if ((&Apache::lonnet::is_course_owner($cdom,$cnum)) && ($udom eq $env{'user.domain'})) {
                   my $noupdate;
                   my %owned = &Apache::lonnet::courseiddump($cdom,'.',1,'.',
                                                             $env{'user.name'}.':'.$env{'user.domain'},
                                                             undef,undef,undef,'.');
                   my %roleshash = &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                                                                 ['active','future']);
                   foreach my $key (keys(%roleshash)) {
                       my ($name,$domain,$role) = split(/:/,$key);
                       if ($role eq 'st') {
                           next if (($name eq $cnum) && ($domain eq $cdom));
                           if ($owned{$domain.'_'.$name}) {
                               if (ref($owned{$domain.'_'.$name}) eq 'HASH') {
                                   if ($owned{$domain.'_'.$name}{'nopasswdchg'}) {
                                       $noupdate = 1;
                                       last;
                                   }
                               }
                           } else {
                               $noupdate = 1;
                               last;
                           }
                       } else {
                           $noupdate = 1;
                           last;
                       }
                   }
                   unless ($noupdate) {
                       $canchange = 1;
                   }
               }
           }
       }
       return $canchange;
   }
   
 sub check_usertype {  sub check_usertype {
     my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;      my ($dom,$uname,$rules,$curr_rules,$got_rules) = @_;
     my $usertype;      my $usertype;
Line 5794  sub roles_by_context { Line 6112  sub roles_by_context {
     } elsif ($context eq 'author') {      } elsif ($context eq 'author') {
         @allroles = ('ca','aa');          @allroles = ('ca','aa');
     } elsif ($context eq 'domain') {      } elsif ($context eq 'domain') {
         @allroles = ('li','ad','dg','sc','au','dc');          @allroles = ('li','ad','dg','dh','da','sc','au','dc');
     }      }
     return @allroles;      return @allroles;
 }  }
Line 5852  sub get_permission { Line 6170  sub get_permission {
                 }                  }
             }              }
         }          }
           if ($env{'request.course.id'}) {
               my $user;
               if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
                   $user = $env{'user.name'}.':'.$env{'user.domain'};
               }
               if (($user ne '') && ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} eq
                                     $user)) {
                   $permission{'owner'} = 1;
                   if (&Apache::lonnet::allowed('mip',$env{'request.course.id'})) {
                       $permission{'mip'} = 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 5871  sub get_permission { Line 6206  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 5924  sub get_course_identity { Line 6267  sub get_course_identity {
 }  }
   
 sub dc_setcourse_js {  sub dc_setcourse_js {
     my ($formname,$mode,$context,$showcredits) = @_;      my ($formname,$mode,$context,$showcredits,$domain) = @_;
     my ($dc_setcourse_code,$authen_check);      my ($dc_setcourse_code,$authen_check);
     my $cctext = &Apache::lonnet::plaintext('cc');      my $cctext = &Apache::lonnet::plaintext('cc');
     my $cotext = &Apache::lonnet::plaintext('co');      my $cotext = &Apache::lonnet::plaintext('co');
Line 5933  sub dc_setcourse_js { Line 6276  sub dc_setcourse_js {
     if ($mode eq 'upload') {      if ($mode eq 'upload') {
         $role = 'courserole';          $role = 'courserole';
     } else {      } else {
         $authen_check = &verify_authen($formname,$context);          $authen_check = &verify_authen($formname,$context,$domain);
     }      }
     $dc_setcourse_code = (<<"SCRIPTTOP");      $dc_setcourse_code = (<<"SCRIPTTOP");
 $authen_check  $authen_check
Line 6077  ENDSCRIPT Line 6420  ENDSCRIPT
 }  }
   
 sub verify_authen {  sub verify_authen {
     my ($formname,$context) = @_;      my ($formname,$context,$domain) = @_;
     my %alerts = &authcheck_alerts();      my %alerts = &authcheck_alerts();
     my $finish = "return 'ok';";      my $finish = "return 'ok';";
     if ($context eq 'author') {      if ($context eq 'author') {
         $finish = "document.$formname.submit();";          $finish = "document.$formname.submit();";
     }      }
       my ($numrules,$intargjs) =
           &passwd_validation_js('argpicked',$domain);
     my $outcome = <<"ENDSCRIPT";      my $outcome = <<"ENDSCRIPT";
   
 function auth_check() {  function auth_check() {
Line 6116  function auth_check() { Line 6461  function auth_check() {
                 break;                  break;
             case 'int':              case 'int':
                 alertmsg = '$alerts{'ipass'}';                  alertmsg = '$alerts{'ipass'}';
                   break;
             case 'fsys':              case 'fsys':
                 alertmsg = '$alerts{'ipass'}';                  alertmsg = '$alerts{'ipass'}';
                 break;                  break;
Line 6129  function auth_check() { Line 6475  function auth_check() {
             alert(alertmsg);              alert(alertmsg);
             return;              return;
         }          }
       } else if (logintype == 'int') {
           var numrules = $numrules;
           if (numrules > 0) {
   $intargjs
           }
     }      }
     $finish      $finish
 }  }
Line 6307  sub selfenrollment_administration { Line 6658  sub selfenrollment_administration {
     return (\@in_course,\@in_domain);      return (\@in_course,\@in_domain);
 }  }
   
   sub custom_role_header {
       my ($context,$crstype,$templaterolerefs,$prefix) = @_;
       my %lt = &Apache::lonlocal::texthash(
                    sele => 'Select a Template',
       );
       my ($context_code,$button_code);
       if ($context eq 'domain') {
           $context_code = &custom_coursetype_switch($crstype,$prefix);
       }
       if (ref($templaterolerefs) eq 'ARRAY') {
           foreach my $role (@{$templaterolerefs}) {
               my $display = 'inline';
               if (($context eq 'domain') && ($role eq 'co')) {
                   $display = 'none';
               }
               $button_code .= &make_button_code($role,$crstype,$display,$prefix).' ';
           }
       }
       return <<"END";
   <div class="LC_left_float">
   <fieldset>
   <legend>$lt{'sele'}</legend>
   $button_code
   </fieldset></div>
   $context_code
   <br clear="all" />
   END
   }
   
   sub custom_coursetype_switch {
       my ($crstype,$prefix) = @_;
       my ($checkedcourse,$checkedcommunity);
       if ($crstype eq 'Community') {
           $checkedcommunity = ' checked="checked"';
       } else {
           $checkedcourse = ' checked="checked"';
       }
       my %lt = &Apache::lonlocal::texthash(
           cont => 'Context',
           cour => 'Course',
           comm => 'Community',
       );
       return <<"END";
   <div class="LC_left_float">
   <fieldset>
   <legend>$lt{'cont'}</legend>
   <label>
   <input type="radio" name="${prefix}_custrolecrstype" value="Course"$checkedcourse onclick="javascript:customSwitchType('$prefix');" />
   $lt{'cour'}
   </label>&nbsp;&nbsp;
   <label>
   <input type="radio" name="${prefix}_custrolecrstype" value="Community"$checkedcommunity onclick="javascript:customSwitchType('$prefix');" />
   $lt{'comm'}
   </label>
   </fieldset>
   </div>
   END
   }
   
   sub custom_role_table {
       my ($crstype,$full,$levels,$levelscurrent,$prefix,$add_class,$id) = @_;
       return unless ((ref($full) eq 'HASH') && (ref($levels) eq 'HASH') &&
                      (ref($levelscurrent) eq 'HASH'));
       my %lt=&Apache::lonlocal::texthash (
                       'prv'  => "Privilege",
                       'crl'  => "Course Level",
                       'dml'  => "Domain Level",
                       'ssl'  => "System Level");
       my %cr = (
                  course => '_c',
                  domain => '_d',
                  system => '_s',
                );
   
       my $output=&Apache::loncommon::start_data_table($add_class,$id).
                  &Apache::loncommon::start_data_table_header_row().
                  '<th>'.$lt{'prv'}.'</th><th>'.$lt{'crl'}.'</th><th>'.$lt{'dml'}.
                  '</th><th>'.$lt{'ssl'}.'</th>'.
                  &Apache::loncommon::end_data_table_header_row();
       foreach my $priv (sort(keys(%{$full}))) {
           my $privtext = &Apache::lonnet::plaintext($priv,$crstype);
           $output .= &Apache::loncommon::start_data_table_row().
                     '<td><span id="'.$prefix.$priv.'">'.$privtext.'</span></td>';
           foreach my $type ('course','domain','system') {
               if (($type eq 'system') && ($priv eq 'bre') && ($crstype eq 'Community')) {
                   $output .= '<td>&nbsp;</td>';
               } else {
                   $output .= '<td>'.
                     ($levels->{$type}{$priv}?'<input type="checkbox" id="'.$prefix.$priv.$cr{$type}.'"'.
                     ' name="'.$prefix.$priv.$cr{$type}.'"'.
                     ($levelscurrent->{$type}{$priv}?' checked="checked"':'').' />':'&nbsp;').
                     '</td>';
               }
           }
           $output .= &Apache::loncommon::end_data_table_row();
       }
       $output .= &Apache::loncommon::end_data_table();
       return $output;
   }
   
   sub custom_role_privs {
       my ($privs,$full,$levels,$levelscurrent)= @_;
       return unless ((ref($privs) eq 'HASH') && (ref($full) eq 'HASH') &&
                      (ref($levels) eq 'HASH') && (ref($levelscurrent) eq 'HASH'));
       my %cr = (
                  course => 'cr:c',
                  domain => 'cr:d',
                  system => 'cr:s',
                );
       foreach my $type ('course','domain','system') {
           foreach my $item (split(/\:/,$Apache::lonnet::pr{$cr{$type}})) {
               my ($priv,$restrict)=split(/\&/,$item);
               if (!$restrict) { $restrict='F'; }
               $levels->{$type}->{$priv}=$restrict;
               if ($privs->{$type}=~/\:$priv/) {
                   $levelscurrent->{$type}->{$priv}=1;
               }
               $full->{$priv}=1;
           }
       }
       return;
   }
   
   sub custom_template_roles {
       my ($context,$crstype) = @_;
       my @template_roles = ("in","ta","ep");
       if (($context eq 'domain') || ($context eq 'domprefs')) {
           push(@template_roles,"ad");
       }
       push(@template_roles,"st");
       if ($context eq 'domain') {
           unshift(@template_roles,('co','cc'));
       } else {
           if ($crstype eq 'Community') {
               unshift(@template_roles,'co');
           } else {
               unshift(@template_roles,'cc');
           }
       }
       return @template_roles;
   }
   
   sub custom_roledefs_js {
       my ($context,$crstype,$formname,$full,$templaterolesref,$jsback) = @_;
       my $button_code = "\n";
       my $head_script = "\n";
       my (%roletitlestr,$rolenamestr);
       my %role_titles = (
                           Course    => [],
                           Community => [],
                         );
       $head_script .= '<script type="text/javascript">'."\n"
                      .'// <![CDATA['."\n";
       if (ref($templaterolesref) eq 'ARRAY') {
           if ($context eq 'domain') {
               $rolenamestr = join("','",@{$templaterolesref});
           }
           foreach my $role (@{$templaterolesref}) {
               $head_script .= &make_script_template($role,$crstype,$formname);
               if ($context eq 'domain') {
                   foreach my $type ('Course','Community') {
                       push(@{$role_titles{$type}},&Apache::lonnet::plaintext($role,$type));
                   }
               }
           }
       }
       if ($context eq 'domain') {
           foreach my $type ('Course','Community') {
               $roletitlestr{$type} = join("','",@{$role_titles{$type}});
           }
           my %pt = (
               Community => {
                              cst => &mt('Grant/revoke role of Member'),
                              mdc => &mt('Edit community contents'),
                              pch => &mt('Post discussion on community resources'),
                              pfo => &mt('Print for other users and entire community'),
                            },
               Course    => {
                              cst => &mt('Grant/revoke role of Student'),
                              mdc => &mt('Edit course contents'),
                              pch => &mt('Post discussion on course resources'),
                              pfo => &mt('Print for other users and entire course'),
                            },
           );
           $head_script .= <<"ENDJS";
   function customSwitchType(prefix) {
       var privnames = new Array('cst','mdc','pch','pfo');
       var privtxtcrs = new Array('$pt{Course}{cst}','$pt{Course}{mdc}','$pt{Course}{pch}','$pt{Course}{pfo}');
       var privtxtcom = new Array('$pt{Community}{cst}','$pt{Community}{mdc}','$pt{Community}{pch}','$pt{Community}{pfo}');
       var rolenames = new Array('$rolenamestr');
       var rolescrs = new Array('$roletitlestr{Course}');
       var rolescom = new Array('$roletitlestr{Community}');
       var radio = prefix+'_custrolecrstype';
       if (document.$formname.elements[radio].length > 1) {
           for (var i=0; i<document.$formname.elements[radio].length; i++) {
               if (document.$formname.elements[radio][i].checked) {
                   if ((document.getElementById(prefix+'bre_s')) && (document.getElementById(prefix+'bro_s'))) {
                       if (document.$formname.elements[radio][i].value == 'Community') {
                           if (document.getElementById(prefix+'bre_s').checked) {
                               document.getElementById(prefix+'bro_s').checked = true;
                               document.getElementById(prefix+'bre_s').checked = false;
   
                           }
                           document.getElementById(prefix+'bre_s').style.visibility = 'hidden';
                       } else {
                           document.getElementById(prefix+'bre_s').style.visibility = 'visible';
                           if (document.getElementById(prefix+'bro_s').checked) {
                               document.getElementById(prefix+'bre_s').checked = true;
                               document.getElementById(prefix+'bro_s').checked = false;
                           }
                       }
                   }
                   for (var j=0; j<privnames.length; j++) {
                       if (document.getElementById(prefix+privnames[j])) {
                           if (document.getElementById(prefix+privnames[j])) {
                               if (document.$formname.elements[radio][i].value == 'Course') {
                                   document.getElementById(prefix+privnames[j]).innerHTML = privtxtcrs[j];
                               } else {
                                   document.getElementById(prefix+privnames[j]).innerHTML = privtxtcom[j];
                               }
                           }
                       }
                   }
                   for (var j=0; j<rolenames.length; j++) {
                       if (document.getElementById(prefix+rolenames[j])) {
                           if (document.getElementById(prefix+rolenames[j])) {
                               if (document.$formname.elements[radio][i].value == 'Course') {
                                   document.getElementById(prefix+rolenames[j]).value = rolescrs[j];
                                   if (rolenames[j] == 'cc') {
                                       document.getElementById(prefix+rolenames[j]).style.display = 'inline';
                                   }
                                   if (rolenames[j] == 'co') {
                                       document.getElementById(prefix+rolenames[j]).style.display = 'none';
                                   }
                               } else {
                                   document.getElementById(prefix+rolenames[j]).value = rolescom[j];
                                   if (rolenames[j] == 'cc') {
                                       document.getElementById(prefix+rolenames[j]).style.display = 'none';
                                   }
                                   if (rolenames[j] == 'co') {
                                       document.getElementById(prefix+rolenames[j]).style.display = 'inline';
                                   }
                               }
                           }
                       }
                   }
               }
           }
       }
       return;
   }
   ENDJS
       }
       $head_script .= "\n".$jsback."\n"
                      .'// ]]>'."\n"
                      .'</script>'."\n";
       return $head_script;
   }
   
   # --------------------------------------------------------
   sub make_script_template {
       my ($role,$crstype,$formname) = @_;
       my $return_script = 'function set_'.$role.'(prefix) {'."\n";
       my (%full_by_level,%role_priv);
       foreach my $level ('c','d','s') {
           foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
               next if (($level eq 's') && ($crstype eq 'Community') && ($item eq 'bre&S'));
               my ($priv,$restrict)=split(/\&/,$item);
               $full_by_level{$level}{$priv}=1;
           }
           $role_priv{$level} = {};
           my @temp = split(/:/,$Apache::lonnet::pr{$role.':'.$level});
           foreach my $priv (@temp) {
               my ($priv_item, $dummy) = split(/\&/,$priv);
               $role_priv{$level}{$priv_item} = 1;
           }
       }
       my %to_check = (
                         c => ['c','d','s'],
                         d => ['d','s'],
                         s => ['s'],
                      );
       foreach my $level ('c','d','s') {
           if (ref($full_by_level{$level}) eq 'HASH') {
               foreach my $priv (keys(%{$full_by_level{$level}})) {
                   my $value = 'false';
                   if (ref($to_check{$level}) eq 'ARRAY') {
                       foreach my $lett (@{$to_check{$level}}) {
                           if (exists($role_priv{$lett}{$priv})) {
                               $value = 'true';
                               last;
                           }
                       }
                       $return_script .= "document.$formname.elements[prefix+'".$priv."_".$level."'].checked = $value;\n";
                   }
               }
           }
       }
       $return_script .= '}'."\n";
       return ($return_script);
   }
   # ----------------------------------------------------------
   sub make_button_code {
       my ($role,$crstype,$display,$prefix) = @_;
       my $label = &Apache::lonnet::plaintext($role,$crstype);
       my $button_code = '<input type="button" onclick="set_'.$role."('$prefix'".')" '.
                         'id="'.$prefix.$role.'" value="'.$label.'" '.
                         'style="display:'.$display.'" />';
       return ($button_code);
   }
   
   sub custom_role_update {
       my ($rolename,$prefix) = @_;
   # ------------------------------------------------------- What can be assigned?
       my %privs = (
                         c => '',
                         d => '',
                         s => '',
                       );
       foreach my $level (keys(%privs)) {
           foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:'.$level})) {
               my ($priv,$restrict)=split(/\&/,$item);
               if (!$restrict) { $restrict=''; }
               if ($env{'form.'.$prefix.$priv.'_'.$level}) {
                   $privs{$level} .=':'.$item;
               }
           }
       }
       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.174  
changed lines
  Added in v.1.198


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.