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

version 1.180, 2017/01/02 19:44:07 version 1.194, 2018/03/23 01:01:21
Line 546  END Line 546  END
             case 'fsys':              case 'fsys':
                 alertmsg = '';                  alertmsg = '';
                 break;                  break;
               case 'lti':
             default:              default:
                 alertmsg = '';                  alertmsg = '';
         }          }
Line 898  sub print_upload_manager_footer { Line 899  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 926  sub print_upload_manager_footer { Line 928  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 943  sub print_upload_manager_footer { Line 945  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 1121  sub print_upload_manager_form { Line 1129  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 1206  sub print_upload_manager_form { Line 1221  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 2307  sub courses_selector { Line 2323  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 2336  function setCourseCat(formname) { Line 2352  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 2757  END Line 2774  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 3101  END Line 3118  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 3115  END Line 3139  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 4102  sub print_first_users_upload_form { Line 4124  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 4116  sub upfile_drop_add { Line 4141  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 4133  sub upfile_drop_add { Line 4154  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 4154  sub upfile_drop_add { Line 4177  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 4164  sub upfile_drop_add { Line 4227  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 4191  sub upfile_drop_add { Line 4253  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 4267  sub upfile_drop_add { Line 4331  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 4338  sub upfile_drop_add { Line 4407  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 4385  sub upfile_drop_add { Line 4455  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 4537  sub upfile_drop_add { Line 4629  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 4819  sub upfile_drop_add { Line 4911  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 4837  sub upfile_drop_add { Line 4931  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 4856  sub upfile_drop_add { Line 4949  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 5404  END Line 5495  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 5426  sub set_login { Line 5517  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;
Line 5833  sub roles_by_context { Line 5929  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','dh','sc','au','dc');          @allroles = ('li','ad','dg','dh','da','sc','au','dc');
     }      }
     return @allroles;      return @allroles;
 }  }

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


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