Diff for /loncom/interface/domainprefs.pm between versions 1.324 and 1.369

version 1.324, 2018/01/01 01:29:38 version 1.369, 2020/02/05 23:46:01
Line 104  $datatable  - HTML containing form eleme Line 104  $datatable  - HTML containing form eleme
   
 In the case of course requests, radio buttons are displayed for each institutional  In the case of course requests, radio buttons are displayed for each institutional
 affiliate type (and also default, and _LC_adv) for each of the course types   affiliate type (and also default, and _LC_adv) for each of the course types 
 (official, unofficial, community, textbook, and placement).    (official, unofficial, community, textbook, placement, and lti).  
 In each case the radio buttons allow the selection of one of four values:    In each case the radio buttons allow the selection of one of four values:  
   
 0, approval, validate, autolimit=N (where N is blank, or a positive integer).  0, approval, validate, autolimit=N (where N is blank, or a positive integer).
Line 219  sub handler { Line 219  sub handler {
                 'serverstatuses','requestcourses','helpsettings',                  'serverstatuses','requestcourses','helpsettings',
                 'coursedefaults','usersessions','loadbalancing',                  'coursedefaults','usersessions','loadbalancing',
                 'requestauthor','selfenrollment','inststatus',                  'requestauthor','selfenrollment','inststatus',
                 'ltitools','ssl','trust','lti'],$dom);                  'ltitools','ssl','trust','lti','privacy','passwords'],$dom);
     my %encconfig =      my %encconfig =
         &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);          &Apache::lonnet::get_dom('encconfig',['ltitools','lti'],$dom);
     if (ref($domconfig{'ltitools'}) eq 'HASH') {      if (ref($domconfig{'ltitools'}) eq 'HASH') {
Line 246  sub handler { Line 246  sub handler {
             }              }
         }          }
     }      }
     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',      my @prefs_order = ('rolecolors','login','defaults','passwords','quotas','autoenroll',
                        'autoupdate','autocreate','directorysrch','contacts',                         'autoupdate','autocreate','directorysrch','contacts','privacy',
                        'usercreation','selfcreation','usermodification','scantron',                         'usercreation','selfcreation','usermodification','scantron',
                        'requestcourses','requestauthor','coursecategories',                         'requestcourses','requestauthor','coursecategories',
                        'serverstatuses','helpsettings','coursedefaults',                         'serverstatuses','helpsettings','coursedefaults',
Line 291  sub handler { Line 291  sub handler {
                       help => 'Domain_Configuration_LangTZAuth',                        help => 'Domain_Configuration_LangTZAuth',
                       header => [{col1 => 'Setting',                        header => [{col1 => 'Setting',
                                   col2 => 'Value'},                                    col2 => 'Value'},
                                  {col1 => 'Internal Authentication',  
                                   col2 => 'Value'},  
                                  {col1 => 'Institutional user types',                                   {col1 => 'Institutional user types',
                                   col2 => 'Name displayed'}],                                    col2 => 'Name displayed'}],
                       print => \&print_defaults,                        print => \&print_defaults,
                       modify => \&modify_defaults,                        modify => \&modify_defaults,
                     },                      },
           'passwords' =>
                       { text => 'Passwords (Internal authentication)',
                         help => 'Domain_Configuration_Passwords',
                         header => [{col1 => 'Resetting Forgotten Password',
                                     col2 => 'Settings'},
                                    {col1 => 'Encryption of Stored Passwords (Internal Auth)',
                                     col2 => 'Settings'},
                                    {col1 => 'Rules for LON-CAPA Passwords',
                                     col2 => 'Settings'},
                                    {col1 => 'Course Owner Changing Student Passwords',
                                     col2 => 'Settings'}],
                         print => \&print_passwords,
                         modify => \&modify_passwords,
                       },
         'quotas' =>           'quotas' => 
                     { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',                      { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
                       help => 'Domain_Configuration_Quotas',                        help => 'Domain_Configuration_Quotas',
Line 352  sub handler { Line 364  sub handler {
                                 col2 => 'Value',},                                  col2 => 'Value',},
                                {col1 => 'Recipient(s) for notifications',                                 {col1 => 'Recipient(s) for notifications',
                                 col2 => 'Value',},                                  col2 => 'Value',},
                                  {col1 => 'Nightly status check e-mail',
                                   col2 => 'Settings',},
                                {col1 => 'Ask helpdesk form settings',                                 {col1 => 'Ask helpdesk form settings',
                                 col2 => 'Value',},],                                  col2 => 'Value',},],
                     print => \&print_contacts,                      print => \&print_contacts,
Line 392  sub handler { Line 406  sub handler {
                     modify => \&modify_usermodification,                      modify => \&modify_usermodification,
                   },                    },
         'scantron' =>          'scantron' =>
                   { text => 'Bubblesheet format file',                    { text => 'Bubblesheet format',
                     help => 'Domain_Configuration_Scantron_Format',                      help => 'Domain_Configuration_Scantron_Format',
                     header => [ {col1 => 'Item',                      header => [ {col1 => 'Bubblesheet format file',
                                  col2 => '',                                   col2 => ''},
                               }],                                  {col1 => 'Bubblesheet data upload formats',
                                    col2 => 'Settings'}],
                     print => \&print_scantron,                      print => \&print_scantron,
                     modify => \&modify_scantron,                      modify => \&modify_scantron,
                   },                    },
Line 482  sub handler { Line 497  sub handler {
                   modify => \&modify_selfenrollment,                    modify => \&modify_selfenrollment,
                  },                   },
         'privacy' =>           'privacy' => 
                  {text   => 'User Privacy',                   {text   => 'Availability of User Information',
                   help   => 'Domain_Configuration_User_Privacy',                    help   => 'Domain_Configuration_User_Privacy',
                   header => [{col1 => 'Setting',                    header => [{col1 => 'Role assigned in different domain',
                               col2 => 'Value',}],                                col2 => 'Approval options'},
                                {col1 => 'Role assigned in different domain to user of type',
                                 col2 => 'User information available in that domain'},
                                {col1 => "Role assigned in user's domain",
                                 col2 => 'Information viewable by privileged user'},
                                {col1 => "Role assigned in user's domain",
                                 col2 => 'Information viewable by unprivileged user'}],
                   print => \&print_privacy,                    print => \&print_privacy,
                   modify => \&modify_privacy,                    modify => \&modify_privacy,
                  },                   },
Line 625  END Line 646  END
         if (grep(/^contacts$/,@actions)) {          if (grep(/^contacts$/,@actions)) {
             $js .= &contacts_javascript();              $js .= &contacts_javascript();
         }          }
           if (grep(/^scantron$/,@actions)) {
               $js .= &scantron_javascript();
           }
         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);          &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
     } else {      } else {
 # check if domconfig user exists for the domain.  # check if domconfig user exists for the domain.
Line 753  sub process_changes { Line 777  sub process_changes {
         $output = &modify_trust($dom,$lastactref,%domconfig);          $output = &modify_trust($dom,$lastactref,%domconfig);
     } elsif ($action eq 'lti') {      } elsif ($action eq 'lti') {
         $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);          $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
       } elsif ($action eq 'privacy') {
           $output = &modify_privacy($dom,%domconfig);
       } elsif ($action eq 'passwords') {
           $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
     }      }
     return $output;      return $output;
 }  }
Line 765  sub print_config_box { Line 793  sub print_config_box {
         $output = &coursecategories_javascript($settings);          $output = &coursecategories_javascript($settings);
     } elsif ($action eq 'defaults') {      } elsif ($action eq 'defaults') {
         $output = &defaults_javascript($settings);           $output = &defaults_javascript($settings); 
       } elsif ($action eq 'passwords') {
           $output = &passwords_javascript();
     } elsif ($action eq 'helpsettings') {      } elsif ($action eq 'helpsettings') {
         my (%privs,%levelscurrent);          my (%privs,%levelscurrent);
         my %full=();          my %full=();
Line 781  sub print_config_box { Line 811  sub print_config_box {
         $output =          $output =
             &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,               &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full, 
                                                       \@templateroles);                                                        \@templateroles);
       } elsif ($action eq 'ltitools') {
           $output .= &ltitools_javascript($settings);
       } elsif ($action eq 'lti') {
           $output .= &lti_javascript($settings);
     }      }
     $output .=      $output .=
          '<table class="LC_nested_outer">           '<table class="LC_nested_outer">
Line 797  sub print_config_box { Line 831  sub print_config_box {
     if ($numheaders > 1) {      if ($numheaders > 1) {
         my $colspan = '';          my $colspan = '';
         my $rightcolspan = '';          my $rightcolspan = '';
           my $leftnobr = '';
         if (($action eq 'rolecolors') || ($action eq 'defaults') ||          if (($action eq 'rolecolors') || ($action eq 'defaults') ||
             ($action eq 'directorysrch') ||              ($action eq 'directorysrch') ||
             (($action eq 'login') && ($numheaders < 4))) {              (($action eq 'login') && ($numheaders < 4))) {
Line 805  sub print_config_box { Line 840  sub print_config_box {
         if ($action eq 'usersessions') {          if ($action eq 'usersessions') {
             $rightcolspan = ' colspan="3"';               $rightcolspan = ' colspan="3"'; 
         }          }
           if ($action eq 'passwords') {
               $leftnobr = ' LC_nobreak';
           }
         $output .= '          $output .= '
           <tr>            <tr>
            <td>             <td>
             <table class="LC_nested">              <table class="LC_nested">
              <tr class="LC_info_row">               <tr class="LC_info_row">
               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>                <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
               <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>                <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
              </tr>';               </tr>';
         $rowtotal ++;          $rowtotal ++;
Line 818  sub print_config_box { Line 856  sub print_config_box {
             ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||              ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
             ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||              ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
             ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||              ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
             ($action eq 'contacts')) {              ($action eq 'contacts') || ($action eq 'privacy')) {
             $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);              $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
           } elsif ($action eq 'passwords') {
               $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'coursecategories') {          } elsif ($action eq 'coursecategories') {
             $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);              $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
           } elsif ($action eq 'scantron') {
               $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'login') {          } elsif ($action eq 'login') {
             if ($numheaders == 4) {              if ($numheaders == 4) {
                 $colspan = ' colspan="2"';                  $colspan = ' colspan="2"';
Line 849  sub print_config_box { Line 891  sub print_config_box {
         if (($action eq 'autoupdate') || ($action eq 'usercreation') ||          if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
             ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||              ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
             ($action eq 'usersessions') || ($action eq 'coursecategories') ||               ($action eq 'usersessions') || ($action eq 'coursecategories') || 
             ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults')) {              ($action eq 'trust') || ($action eq 'contacts') ||
               ($action eq 'privacy') || ($action eq 'passwords')) {
               my $leftnobr = ' LC_nobreak';
             if ($action eq 'coursecategories') {              if ($action eq 'coursecategories') {
                 $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);                  $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
                 $colspan = ' colspan="2"';                  $colspan = ' colspan="2"';
             } elsif ($action eq 'trust') {              } elsif ($action eq 'trust') {
                 $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);                  $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
               } elsif ($action eq 'passwords') {
                   $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
             } else {              } else {
                 $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);                  $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
             }              }
Line 900  sub print_config_box { Line 946  sub print_config_box {
              </tr>'."\n";               </tr>'."\n";
                 if ($action eq 'coursecategories') {                  if ($action eq 'coursecategories') {
                     $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);                      $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
                   } elsif (($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'passwords')) {
                       if ($action eq 'passwords') {
                           $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
                       } else {
                           $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
                       }
                       $output .= '
                </tr>
               </table>
              </td>
             </tr>
             <tr>
              <td>
               <table class="LC_nested">
                <tr class="LC_info_row">
                 <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
                 <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
                       if ($action eq 'passwords') {
                           $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
                       } else {
                           $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                       }
                       $output .= '
               </table>
             </td>
            </tr>
            <tr>';
                 } else {                  } else {
                     $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);                      $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
                 }                  }
Line 909  sub print_config_box { Line 982  sub print_config_box {
                  ($action eq 'defaults') || ($action eq 'directorysrch') ||                   ($action eq 'defaults') || ($action eq 'directorysrch') ||
                  ($action eq 'helpsettings')) {                   ($action eq 'helpsettings')) {
             $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);              $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
           } elsif ($action eq 'scantron') {
               $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'ssl') {          } elsif ($action eq 'ssl') {
             $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'              $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
             </table>              </table>
Line 1090  sub print_config_box { Line 1165  sub print_config_box {
                  ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||                    ($action eq 'serverstatuses') || ($action eq 'loadbalancing') || 
                  ($action eq 'ltitools') || ($action eq 'lti')) {                   ($action eq 'ltitools') || ($action eq 'lti')) {
             $output .= $item->{'print'}->($dom,$settings,\$rowtotal);              $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
         } elsif ($action eq 'scantron') {  
             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);  
         }          }
     }      }
     $output .= '      $output .= '
Line 1436  sub print_login { Line 1509  sub print_login {
             } else {              } else {
                 $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';                  $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
             }              }
             $datatable .= '</td><td><input type="textbox" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';              $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
         }          }
         $datatable .= '</table></td></tr>';          $datatable .= '</table></td></tr>';
     }      }
Line 1596  sub display_color_options { Line 1669  sub display_color_options {
     my $datatable = '<tr'.$css_class.'>'.      my $datatable = '<tr'.$css_class.'>'.
         '<td>'.$choices->{'font'}.'</td>';          '<td>'.$choices->{'font'}.'</td>';
     if (!$is_custom->{'font'}) {      if (!$is_custom->{'font'}) {
         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';          $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
     } else {      } else {
         $datatable .= '<td>&nbsp;</td>';          $datatable .= '<td>&nbsp;</td>';
     }      }
Line 1605  sub display_color_options { Line 1678  sub display_color_options {
     $datatable .= '<td><span class="LC_nobreak">'.      $datatable .= '<td><span class="LC_nobreak">'.
                   '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.                    '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
                   ' value="'.$current_color.'" />&nbsp;'.                    ' value="'.$current_color.'" />&nbsp;'.
                   '&nbsp;</td></tr>';                    '&nbsp;</span></td></tr>';
     unless ($role eq 'login') {       unless ($role eq 'login') { 
         $datatable .= '<tr'.$css_class.'>'.          $datatable .= '<tr'.$css_class.'>'.
                       '<td>'.$choices->{'fontmenu'}.'</td>';                        '<td>'.$choices->{'fontmenu'}.'</td>';
         if (!$is_custom->{'fontmenu'}) {          if (!$is_custom->{'fontmenu'}) {
             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';              $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
         } else {          } else {
             $datatable .= '<td>&nbsp;</td>';              $datatable .= '<td>&nbsp;</td>';
         }          }
Line 1620  sub display_color_options { Line 1693  sub display_color_options {
                       '<input class="colorchooser" type="text" size="10" name="'                        '<input class="colorchooser" type="text" size="10" name="'
       .$role.'_fontmenu"'.        .$role.'_fontmenu"'.
                       ' value="'.$current_color.'" />&nbsp;'.                        ' value="'.$current_color.'" />&nbsp;'.
                       '&nbsp;</td></tr>';                        '&nbsp;</span></td></tr>';
     }      }
     my $switchserver = &check_switchserver($dom,$confname);      my $switchserver = &check_switchserver($dom,$confname);
     foreach my $img (@{$images}) {      foreach my $img (@{$images}) {
Line 1738  sub display_color_options { Line 1811  sub display_color_options {
     my $bgs_def;      my $bgs_def;
     foreach my $item (@{$bgs}) {      foreach my $item (@{$bgs}) {
         if (!$is_custom->{$item}) {          if (!$is_custom->{$item}) {
             $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span>&nbsp;<span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span><br />'.$defaults->{'bgs'}{$item}.'</td>';              $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span>&nbsp;<span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span><br />'.$defaults->{'bgs'}{$item}.'</td>';
         }          }
     }      }
     if ($bgs_def) {      if ($bgs_def) {
Line 1766  sub display_color_options { Line 1839  sub display_color_options {
     my $links_def;      my $links_def;
     foreach my $item (@{$links}) {      foreach my $item (@{$links}) {
         if (!$is_custom->{$item}) {          if (!$is_custom->{$item}) {
             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';              $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
         }          }
     }      }
     if ($links_def) {      if ($links_def) {
Line 1852  sub image_changes { Line 1925  sub image_changes {
     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;      my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
     my $output;      my $output;
     if ($img eq 'login') {      if ($img eq 'login') {
             # suppress image for Log-in header          $output = '</td><td>'.$logincolors; # suppress image for Log-in header
     } elsif (!$is_custom) {      } elsif (!$is_custom) {
         if ($img ne 'domlogo') {          if ($img ne 'domlogo') {
             $output .= &mt('Default image:').'<br />';              $output = &mt('Default image:').'<br />';
         } else {          } else {
             $output .= &mt('Default in use:').'<br />';              $output = &mt('Default in use:').'<br />';
         }          }
     }      }
     if ($img eq 'login') { # suppress image for Log-in header      if ($img ne 'login') {
         $output .= '<td>'.$logincolors;  
     } else {  
         if ($img_import) {          if ($img_import) {
             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';              $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
         }          }
Line 1893  sub print_quotas { Line 1964  sub print_quotas {
     my $typecount = 0;      my $typecount = 0;
     my ($css_class,%titles);      my ($css_class,%titles);
     if ($context eq 'requestcourses') {      if ($context eq 'requestcourses') {
         @usertools = ('official','unofficial','community','textbook','placement');          @usertools = ('official','unofficial','community','textbook','placement','lti');
         @options =('norequest','approval','validate','autolimit');          @options =('norequest','approval','validate','autolimit');
         %validations = &Apache::lonnet::auto_courserequest_checks($dom);          %validations = &Apache::lonnet::auto_courserequest_checks($dom);
         %titles = &courserequest_titles();          %titles = &courserequest_titles();
Line 2357  sub print_studentcode { Line 2428  sub print_studentcode {
     my ($settings,$rowtotal) = @_;      my ($settings,$rowtotal) = @_;
     my $rownum = 0;       my $rownum = 0; 
     my ($output,%current);      my ($output,%current);
     my @crstypes = ('official','unofficial','community','textbook','placement');      my @crstypes = ('official','unofficial','community','textbook','placement','lti');
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
         if (ref($settings->{'uniquecode'}) eq 'HASH') {          if (ref($settings->{'uniquecode'}) eq 'HASH') {
             foreach my $type (@crstypes) {              foreach my $type (@crstypes) {
Line 2484  sub print_textbookcourses { Line 2555  sub print_textbookcourses {
         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';          $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
     }      }
     $datatable .= '</select>&nbsp;'."\n".      $datatable .= '</select>&nbsp;'."\n".
                   '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</td>'."\n".                    '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
                   '<td colspan="2">'.                    '<td colspan="2">'.
                   '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".                    '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
                   ('&nbsp;'x2).                    ('&nbsp;'x2).
Line 2501  sub print_textbookcourses { Line 2572  sub print_textbookcourses {
         } else {          } else {
             $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';              $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
         }          }
           $datatable .= '</span>'."\n";
     }      }
     $datatable .= '</span>'."\n".      $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.
                   '<span class="LC_nobreak">'.&mt('LON-CAPA course:').'&nbsp;'.  
                   &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').                    &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
                   '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.                    '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
                   &Apache::loncommon::selectcourse_link                    &Apache::loncommon::selectcourse_link
                       ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course');                        ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
                   '</span></td>'."\n".                    '</span></td>'."\n".
                   '</tr>'."\n";                    '</tr>'."\n";
     $itemcount ++;      $itemcount ++;
Line 2806  ENDSCRIPT Line 2877  ENDSCRIPT
 }  }
   
 sub lti_toggle_js {  sub lti_toggle_js {
       my %lcauthparmtext = &Apache::lonlocal::texthash (
                               localauth => 'Local auth argument',
                               krb       => 'Kerberos domain',
                            );
     return <<"ENDSCRIPT";      return <<"ENDSCRIPT";
 <script type="text/javascript">  <script type="text/javascript">
 // <![CDATA[  // <![CDATA[
   
 function toggleLTI(form,setting,item) {  function toggleLTI(form,setting,item) {
     if ((setting == 'user') || (setting == 'crs')) {      if (setting == 'requser') {
           var fieldsets = document.getElementsByClassName('ltioption_'+item);
           if (fieldsets.length) {
               var radioname = 'lti_'+setting+'_'+item;
               var num = form.elements[radioname].length;
               if (num) {
                   var setvis = '';
                   for (var i=0; i<num; i++) {
                       if (form.elements[radioname][i].checked) {
                           if (form.elements[radioname][i].value == '1') {
                              setvis = 1;
                              break;
                           }
                       }
                   }
                   for (var j=0; j<fieldsets.length; j++) {
                       if (setvis) {
                           fieldsets[j].style.display = 'block';
                       } else {
                           fieldsets[j].style.display = 'none';
                       }
                   }
               }
           }
       } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
         var radioname = '';          var radioname = '';
         var divid = '';          var divid = '';
         if (setting == 'user') {          if (setting == 'user') {
             radioname = 'lti_mapuser_'+item;              radioname = 'lti_mapuser_'+item;
             divid = 'lti_userfield_'+item;              divid = 'lti_userfield_'+item;
         } else {          } else if (setting == 'crs') {
             radioname = 'lti_mapcrs_'+item;              radioname = 'lti_mapcrs_'+item;
             divid = 'lti_crsfield_'+item;              divid = 'lti_crsfield_'+item;
           } else if (setting == 'callback') {
               radioname = 'lti_callback_'+item;
               divid = 'lti_callbackfield_'+item;
           } else {
               radioname = 'lti_passback_'+item;
               divid =  'lti_passback_'+item;
         }          }
         var num = form.elements[radioname].length;          var num = form.elements[radioname].length;
         if (num) {          if (num) {
             var setvis = '';              var setvis = '';
             for (var i=0; i<num; i++) {              for (var i=0; i<num; i++) {
                if (form.elements[radioname][i].checked) {                 if (form.elements[radioname][i].checked) {
                    if (form.elements[radioname][i].value == 'other') {                     if ((setting == 'passback') || (setting == 'callback')) {
                        if (document.getElementById(divid)) {                         if (form.elements[radioname][i].value == '1') {
                            document.getElementById(divid).style.display = 'inline-block';                             if (document.getElementById(divid)) {
                                  document.getElementById(divid).style.display = 'inline-block';
                              }
                              setvis = 1;
                              break;
                          }
                      } else {
                          if (form.elements[radioname][i].value == 'other') {
                              if (document.getElementById(divid)) {
                                  document.getElementById(divid).style.display = 'inline-block';
                              }
                              setvis = 1;
                              break;
                        }                         }
                        setvis = 1;  
                        break;  
                    }                     }
                }                  } 
             }              }
Line 2883  function toggleLTI(form,setting,item) { Line 2998  function toggleLTI(form,setting,item) {
                 }                  }
             }              }
         }          }
       } else if (setting == 'lcauth') {
           var numauth = form.elements['lti_lcauth_'+item].length;
           if (numauth) {
               for (var i=0; i<numauth; i++) {
                   if (form.elements['lti_lcauth_'+item][i].checked) {
                       if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
                           if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
                               document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
                           } else {
                               document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
                               if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
                                   if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
                                       document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
                                   } else {
                                       document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
                                   }
                               }
                           }
                       }
                   }
               }
           }
       } else if (setting == 'lcmenu') {
           var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
           var divid = 'lti_menufield_'+item;
           var setvis = '';
           for (var i=0; i<menus.length; i++) {
               var radioname = menus[i];  
               var num = form.elements[radioname].length;
               if (num) {
                   for (var j=0; j<num; j++) {
                       if (form.elements[radioname][j].checked) {
                           if (form.elements[radioname][j].value == '1') {
                               if (document.getElementById(divid)) {
                                   document.getElementById(divid).style.display = 'inline-block';
                               }
                               setvis = 1;
                               break;
                           }
                       }
                   }
               }
               if (setvis == 1) {
                   break;
               }
           }
           if (!setvis) {
               if (document.getElementById(divid)) {
                   document.getElementById(divid).style.display = 'none';
               }
           }
     }      }
     return;      return;
 }  }
Line 2971  sub print_autoenroll { Line 3137  sub print_autoenroll {
                   '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.                    '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
                   '<td class="LC_right_item"><span class="LC_nobreak">'.                    '<td class="LC_right_item"><span class="LC_nobreak">'.
                   '<input type="text" name="autoenroll_failsafe"'.                    '<input type="text" name="autoenroll_failsafe"'.
                   ' value="'.$failsafe.'" size="4" /></td></tr>';                    ' value="'.$failsafe.'" size="4" /></span></td></tr>';
     $$rowtotal += 4;      $$rowtotal += 4;
     return $datatable;      return $datatable;
 }  }
Line 3253  sub print_contacts { Line 3419  sub print_contacts {
     my $datatable;      my $datatable;
     my @contacts = ('adminemail','supportemail');      my @contacts = ('adminemail','supportemail');
     my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,      my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
         $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings);          $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
     if ($position eq 'top') {      if ($position eq 'top') {
         if (ref($settings) eq 'HASH') {          if (ref($settings) eq 'HASH') {
             foreach my $item (@contacts) {              foreach my $item (@contacts) {
Line 3264  sub print_contacts { Line 3430  sub print_contacts {
         }          }
     } elsif ($position eq 'middle') {      } elsif ($position eq 'middle') {
         @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',          @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
                      'updatesmail','idconflictsmail');                       'updatesmail','idconflictsmail','hostipmail');
         foreach my $type (@mailings) {          foreach my $type (@mailings) {
             $otheremails{$type} = '';              $otheremails{$type} = '';
         }          }
       } elsif ($position eq 'lower') {
           if (ref($settings) eq 'HASH') {
               if (ref($settings->{'lonstatus'}) eq 'HASH') {
                   %lonstatus = %{$settings->{'lonstatus'}};
               }
           }
     } else {      } else {
         @mailings = ('helpdeskmail','otherdomsmail');          @mailings = ('helpdeskmail','otherdomsmail');
         foreach my $type (@mailings) {          foreach my $type (@mailings) {
Line 3280  sub print_contacts { Line 3452  sub print_contacts {
         ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();          ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
     }      }
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
         unless ($position eq 'top') {          unless (($position eq 'top') || ($position eq 'lower')) {
             foreach my $type (@mailings) {              foreach my $type (@mailings) {
                 if (exists($settings->{$type})) {                  if (exists($settings->{$type})) {
                     if (ref($settings->{$type}) eq 'HASH') {                      if (ref($settings->{$type}) eq 'HASH') {
Line 3341  sub print_contacts { Line 3513  sub print_contacts {
             $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';              $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
             $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';              $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
             $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';              $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
               $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
         } elsif ($position eq 'bottom') {          } elsif ($position eq 'bottom') {
             $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';              $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
             $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';              $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
Line 3401  sub print_contacts { Line 3574  sub print_contacts {
                     if ($currfield{$field} eq 'no') {                      if ($currfield{$field} eq 'no') {
                         $display = ' style="display:none"';                          $display = ' style="display:none"';
                     }                      }
                     $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.' />'.                      $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
                                   '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.                                    '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
                                   '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';                                    '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
                 }                  }
Line 3412  sub print_contacts { Line 3585  sub print_contacts {
         $datatable .= '</td></tr>'."\n";          $datatable .= '</td></tr>'."\n";
         $rownum ++;          $rownum ++;
     }      }
     unless ($position eq 'top') {      unless (($position eq 'top') || ($position eq 'lower')) {
         foreach my $type (@mailings) {          foreach my $type (@mailings) {
             $css_class = $rownum%2?' class="LC_odd_row"':'';              $css_class = $rownum%2?' class="LC_odd_row"':'';
             $datatable .= '<tr'.$css_class.'>'.              $datatable .= '<tr'.$css_class.'>'.
Line 3446  sub print_contacts { Line 3619  sub print_contacts {
                               'value="'.$bccemails{$type}.'"  /></fieldset>'.                                'value="'.$bccemails{$type}.'"  /></fieldset>'.
                               '<fieldset><legend>'.&mt('Optional added text').'</legend>'.                                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                               &mt('Text automatically added to e-mail:').' '.                                &mt('Text automatically added to e-mail:').' '.
                               '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br >'.                                '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
                               '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.                                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                               '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.                                '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                               ('&nbsp;'x2).                                ('&nbsp;'x2).
Line 3459  sub print_contacts { Line 3632  sub print_contacts {
     }      }
     if ($position eq 'middle') {      if ($position eq 'middle') {
         my %choices;          my %choices;
         $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',          my $corelink = &core_link_msu();
                                        &Apache::loncommon::modal_link('http://loncapa.org/core.html',          $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
                                        &mt('LON-CAPA core group - MSU'),600,500));  
         $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',          $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
                                         &Apache::loncommon::modal_link('http://loncapa.org/core.html',                                          $corelink);
                                         &mt('LON-CAPA core group - MSU'),600,500));          $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
         my @toggles = ('reporterrors','reportupdates');          my @toggles = ('reporterrors','reportupdates','reportstatus');
         my %defaultchecked = ('reporterrors'  => 'on',          my %defaultchecked = ('reporterrors'  => 'on',
                               'reportupdates' => 'on');                                'reportupdates' => 'on',
                                 'reportstatus'  => 'on');
         (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,          (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
                                                    \%choices,$rownum);                                                     \%choices,$rownum);
         $datatable .= $reports;          $datatable .= $reports;
       } elsif ($position eq 'lower') {
           $css_class = $rownum%2?' class="LC_odd_row"':'';
           my ($threshold,$sysmail,%excluded,%weights);
           my ($defaults,$names) = &Apache::loncommon::lon_status_items();
           if ($lonstatus{'threshold'} =~ /^\d+$/) {
               $threshold = $lonstatus{'threshold'};
           } else {
               $threshold = $defaults->{'threshold'};
           }
           if ($lonstatus{'sysmail'} =~ /^\d+$/) {
               $sysmail = $lonstatus{'sysmail'};
           } else {
               $sysmail = $defaults->{'sysmail'};
           }
           if (ref($lonstatus{'weights'}) eq 'HASH') {
               foreach my $type ('E','W','N','U') {
                   if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
                       $weights{$type} = $lonstatus{'weights'}{$type};
                   } else {
                       $weights{$type} = $defaults->{$type};
                   }
               }
           } else {
               foreach my $type ('E','W','N','U') {
                   $weights{$type} = $defaults->{$type};
               }
           }
           if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
               if (@{$lonstatus{'excluded'}} > 0) {
                   map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
               }
           }
           $datatable .= '<tr'.$css_class.'>'.
                         '<td class="LC_left_item"><span class="LC_nobreak">'.
                         $titles->{'errorthreshold'}.
                         '</span></td><td class="LC_left_item">'.
                         '<input type="text" name="errorthreshold" value="'.
                         $threshold.'" size="5" /></td></tr>';
           $rownum ++;
           $css_class = $rownum%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'>'.
                         '<td class="LC_left_item">'.
                         '<span class="LC_nobreak">'.$titles->{'errorweights'}.
                         '</span></td><td class="LC_left_item"><table><tr>';
           foreach my $type ('E','W','N','U') {
               $datatable .= '<td>'.$names->{$type}.'<br />'.
                             '<input type="text" name="errorweights_'.$type.'" value="'.
                             $weights{$type}.'" size="5" /></td>';
           }
           $datatable .= '</tr></table></tr>';
           $rownum ++;
           $css_class = $rownum%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
                         $titles->{'errorexcluded'}.'</td>'.
                         '<td class="LC_left_item"><table>';
           my $numinrow = 4;
           my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
           for (my $i=0; $i<@ids; $i++) {
               my $rem = $i%($numinrow);
               if ($rem == 0) {
                   if ($i > 0) {
                       $datatable .= '</tr>';
                   }
                   $datatable .= '<tr>';
               }
               my $check;
               if ($excluded{$ids[$i]}) {
                   $check = ' checked="checked" ';
               }
               $datatable .= '<td class="LC_left_item">'.
                             '<span class="LC_nobreak"><label>'.
                             '<input type="checkbox" name="errorexcluded" '.
                             'value="'.$ids[$i].'"'.$check.' />'.
                             $ids[$i].'</label></span></td>';
           }
           my $colsleft = $numinrow - @ids%($numinrow);
           if ($colsleft > 1 ) {
               $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                             '&nbsp;</td>';
           } elsif ($colsleft == 1) {
               $datatable .= '<td class="LC_left_item">&nbsp;</td>';
           }
           $datatable .= '</tr></table></td></tr>';
           $rownum ++;
           $css_class = $rownum%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'>'.
                         '<td class="LC_left_item"><span class="LC_nobreak">'.
                         $titles->{'errorsysmail'}.
                         '</span></td><td class="LC_left_item">'.
                         '<input type="text" name="errorsysmail" value="'.
                         $sysmail.'" size="5" /></td></tr>';
           $rownum ++;
     } elsif ($position eq 'bottom') {      } elsif ($position eq 'bottom') {
         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);          my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
         my (@posstypes,%usertypeshash);          my (@posstypes,%usertypeshash);
Line 3544  sub print_contacts { Line 3809  sub print_contacts {
     return $datatable;      return $datatable;
 }  }
   
   sub core_link_msu {
       return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
                                             &mt('LON-CAPA core group - MSU'),600,500);
   }
   
 sub overridden_helpdesk {  sub overridden_helpdesk {
     my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,      my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
         $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;          $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
Line 3594  sub overridden_helpdesk { Line 3864  sub overridden_helpdesk {
                'value="'.$bccemails.'"  /></fieldset>'.                 'value="'.$bccemails.'"  /></fieldset>'.
                '<fieldset><legend>'.&mt('Optional added text').'</legend>'.                 '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
                &mt('Text automatically added to e-mail:').' '.                 &mt('Text automatically added to e-mail:').' '.
                '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br >'.                 '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
                '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.                 '<span class="LC_nobreak">'.&mt('Location:').'&nbsp;'.
                '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.                 '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
                ('&nbsp;'x2).                 ('&nbsp;'x2).
Line 3723  sub print_helpsettings { Line 3993  sub print_helpsettings {
             push(@jsarray,('notinc','notexc'));              push(@jsarray,('notinc','notexc'));
         }          }
         my $hiddenstr = join("','",@jsarray);          my $hiddenstr = join("','",@jsarray);
         $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);  
         my $context = 'domprefs';          my $context = 'domprefs';
         my $crstype = 'Course';          my $crstype = 'Course';
         my $prefix = 'helproles_';          my $prefix = 'helproles_';
Line 3826  sub print_helpsettings { Line 4095  sub print_helpsettings {
                                                                 \@templateroles,$newcust).                                                                  \@templateroles,$newcust).
                       &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,                        &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
                                                                \%levelscurrent,$newcust).                                                                 \%levelscurrent,$newcust).
                       '</fieldset></td></tr>';                        '</fieldset>'.
                         &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
                         '</td></tr>';
         $count ++;          $count ++;
         $$rowtotal += $count;          $$rowtotal += $count;
     }      }
Line 4115  sub print_ltitools { Line 4386  sub print_ltitools {
     my $confname = $dom.'-domainconfig';      my $confname = $dom.'-domainconfig';
     my $switchserver = &check_switchserver($dom,$confname);      my $switchserver = &check_switchserver($dom,$confname);
     my $maxnum = scalar(keys(%ordered));      my $maxnum = scalar(keys(%ordered));
     my $datatable = &ltitools_javascript($settings);      my $datatable;
     my %lt = &ltitools_names();      my %lt = &ltitools_names();
     my @courseroles = ('cc','in','ta','ep','st');      my @courseroles = ('cc','in','ta','ep','st');
     my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);      my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
Line 4216  sub print_ltitools { Line 4487  sub print_ltitools {
                               '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.                                '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
                               ('&nbsp;'x2);                                ('&nbsp;'x2);
             }              }
             $datatable .= '<br />'.              $datatable .= '</span><br />'.
                           '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.                            '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
                           '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></label></div>'.                            '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
                           '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.                            '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                           '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.                            '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
                           '</textarea></div><div style=""></div><br />';                            '</textarea></div><div style=""></div><br />';
Line 4389  sub print_ltitools { Line 4660  sub print_ltitools {
         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';          $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
     }      }
     $datatable .= '</select>&nbsp;'."\n".      $datatable .= '</select>&nbsp;'."\n".
                   '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</td>'."\n".                    '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
                   '<td colspan="2">'.                    '<td colspan="2">'.
                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.                    '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".                    '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
Line 4426  sub print_ltitools { Line 4697  sub print_ltitools {
                       '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.                        '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
                       ('&nbsp;'x2);                        ('&nbsp;'x2);
     }      }
     $datatable .= '<br />'.      $datatable .= '</span><br />'.
                   '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.                    '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
                   '<input type="text" name="ltitools_add_linktext" size="5" /></label></div>'.                    '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
                   '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.                    '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
                   '<textarea name=ltitools_add_explanation" rows="5" cols="40"></textarea>'.                    '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
                   '</div><div style=""></div><br />';                    '</div><div style=""></div><br />';
     my %units = (      my %units = (
                   'passback' => 'days',                    'passback' => 'days',
Line 4509  sub print_ltitools { Line 4780  sub print_ltitools {
                   '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.                    '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
                   &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.                    &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
                   '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.                    '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
                   '</table></fieldset></td></tr>'."\n".                    '</table></fieldset>'."\n".
                   '</td>'."\n".                    '</td>'."\n".
                   '</tr>'."\n";                    '</tr>'."\n";
     $itemcount ++;      $itemcount ++;
Line 4567  sub print_lti { Line 4838  sub print_lti {
         }          }
     }      }
     my $maxnum = scalar(keys(%ordered));      my $maxnum = scalar(keys(%ordered));
     my $datatable = &lti_javascript($settings);      my $datatable;
     my %lt = &lti_names();      my %lt = &lti_names();
     if (keys(%ordered)) {      if (keys(%ordered)) {
         my @items = sort { $a <=> $b } keys(%ordered);          my @items = sort { $a <=> $b } keys(%ordered);
         for (my $i=0; $i<@items; $i++) {          for (my $i=0; $i<@items; $i++) {
             $css_class = $itemcount%2?' class="LC_odd_row"':'';              $css_class = $itemcount%2?' class="LC_odd_row"':'';
             my $item = $ordered{$items[$i]};              my $item = $ordered{$items[$i]};
             my ($key,$secret,$lifetime,$consumer,$current);              my ($key,$secret,$lifetime,$consumer,$requser,$current);
             if (ref($settings->{$item}) eq 'HASH') {              if (ref($settings->{$item}) eq 'HASH') {
                 $key = $settings->{$item}->{'key'};                  $key = $settings->{$item}->{'key'};
                 $secret = $settings->{$item}->{'secret'};                  $secret = $settings->{$item}->{'secret'};
                 $lifetime = $settings->{$item}->{'lifetime'};                  $lifetime = $settings->{$item}->{'lifetime'};
                 $consumer = $settings->{$item}->{'consumer'};                  $consumer = $settings->{$item}->{'consumer'};
                   $requser = $settings->{$item}->{'requser'};
                 $current = $settings->{$item};                  $current = $settings->{$item};
             }              }
               my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
               my %checkedrequser = (
                                      yes => ' checked="checked"',
                                      no  => '',
                                    );
               if (!$requser) {
                   $checkedrequser{'no'} = $checkedrequser{'yes'};
                   $checkedrequser{'yes'} = '';
               }
             my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';              my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
             $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'              $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                          .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';                           .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
Line 4599  sub print_lti { Line 4880  sub print_lti {
                 '<td colspan="2">'.                  '<td colspan="2">'.
                 '<fieldset><legend>'.&mt('Required settings').'</legend>'.                  '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                 '<span class="LC_nobreak">'.$lt{'consumer'}.                  '<span class="LC_nobreak">'.$lt{'consumer'}.
                 ':<input type="text" size="20" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.                  ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
                 ('&nbsp;'x2).                  ('&nbsp;'x2).
                 '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.                  '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
                 '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.                  '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
                 ('&nbsp;'x2).                  ('&nbsp;'x2).
                 '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.                  '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
                 'value="'.$lifetime.'" size="5" /></span>'.                  'value="'.$lifetime.'" size="3" /></span>'.
                   ('&nbsp;'x2).
                    '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                    '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label>&nbsp;'."\n".
                    '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
                 '<br /><br />'.                  '<br /><br />'.
                 '<span class="LC_nobreak">'.$lt{'key'}.                  '<span class="LC_nobreak">'.$lt{'key'}.
                 ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.                  ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" /></span> '.
Line 4614  sub print_lti { Line 4899  sub print_lti {
                 '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.                  '<input type="password" size="20" name="lti_secret_'.$i.'" value="'.$secret.'" />'.
                 '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.                  '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
                 '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.                  '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
                 '</fieldset>'.&lti_options($i,$current,%lt).'</td></tr>';                  '</fieldset>'.&lti_options($i,$current,$itemcount,%lt).'</td></tr>';
             $itemcount ++;              $itemcount ++;
         }          }
     }      }
Line 4632  sub print_lti { Line 4917  sub print_lti {
         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';          $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
     }      }
     $datatable .= '</select>&nbsp;'."\n".      $datatable .= '</select>&nbsp;'."\n".
                   '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</td>'."\n".                    '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
                   '<td colspan="2">'.                    '<td colspan="2">'.
                   '<fieldset><legend>'.&mt('Required settings').'</legend>'.                    '<fieldset><legend>'.&mt('Required settings').'</legend>'.
                   '<span class="LC_nobreak">'.$lt{'consumer'}.                    '<span class="LC_nobreak">'.$lt{'consumer'}.
                   ':<input type="text" size="20" name="lti_consumer_add" value="" /></span> '."\n".                    ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
                   ('&nbsp;'x2).                    ('&nbsp;'x2).
                   '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.                    '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
                   '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".                    '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
                   ('&nbsp;'x2).                    ('&nbsp;'x2).
                   '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="lti_lifetime_add" value="300" /></span> '."\n".                    '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span> '."\n".
                     ('&nbsp;'x2).
                     '<span class="LC_nobreak">'.$lt{'requser'}.':'.
                     '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label>&nbsp;'."\n".
                     '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
                   '<br /><br />'.                    '<br /><br />'.
                   '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".                    '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" /></span> '."\n".
                   ('&nbsp;'x2).                    ('&nbsp;'x2).
                   '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.                    '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" />'.
                   '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".                    '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
                   '</fieldset>'.&lti_options('add',undef,%lt).                    '</fieldset>'.&lti_options('add',undef,$itemcount,%lt).
                   '</td>'."\n".                    '</td>'."\n".
                   '</tr>'."\n";                    '</tr>'."\n";
     $$rowtotal ++;      $$rowtotal ++;
Line 4660  sub lti_names { Line 4949  sub lti_names {
                                           'url'       => 'URL',                                            'url'       => 'URL',
                                           'key'       => 'Key',                                            'key'       => 'Key',
                                           'lifetime'  => 'Nonce lifetime (s)',                                            'lifetime'  => 'Nonce lifetime (s)',
                                           'consumer'  => 'LTI Consumer',                                             'consumer'  => 'Consumer',
                                           'secret'    => 'Secret',                                            'secret'    => 'Secret',
                                             'requser'   => "User's identity sent",
                                           'email'     => 'Email address',                                            'email'     => 'Email address',
                                           'sourcedid' => 'User ID',                                            'sourcedid' => 'User ID',
                                           'other'     => 'Other',                                            'other'     => 'Other',
                                           'passback'  => 'Can return grades to Consumer:',                                            'passback'  => 'Can return grades to Consumer:',
                                           'roster'    => 'Can retrieve roster from Consumer:',                                            'roster'    => 'Can retrieve roster from Consumer:',
                                             'topmenu'   => 'Display LON-CAPA page header',
                                             'inlinemenu'=> 'Display LON-CAPA inline menu',
                                         );                                          );
     return %lt;      return %lt;
 }  }
   
 sub lti_options {  sub lti_options {
     my ($num,$current,%lt) = @_;      my ($num,$current,$itemcount,%lt) = @_;
     my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield);      my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
     $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';      $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
     $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';      $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
     $checked{'makecrs'}{'N'} = '  checked="checked"';      $checked{'makecrs'}{'N'} = '  checked="checked"';
Line 4682  sub lti_options { Line 4974  sub lti_options {
     $checked{'selfenroll'} = {};      $checked{'selfenroll'} = {};
     $checked{'crssec'} = {};      $checked{'crssec'} = {};
     $checked{'crssecsrc'} = {};      $checked{'crssecsrc'} = {};
       $checked{'lcauth'} = {};
       $checked{'menuitem'} = {};
       if ($num eq 'add') {
           $checked{'lcauth'}{'lti'} = ' checked="checked"';
       }
     my $userfieldsty = 'none';      my $userfieldsty = 'none';
     my $crsfieldsty = 'none';      my $crsfieldsty = 'none';
     my $crssecfieldsty = 'none';      my $crssecfieldsty = 'none';
     my $secsrcfieldsty = 'none';      my $secsrcfieldsty = 'none';
       my $callbacksty = 'none';
       my $passbacksty = 'none';
       my $optionsty = 'block';
       my $lcauthparm;
       my $lcauthparmstyle = 'display:none';
       my $lcauthparmtext;
       my $menusty;
       my $numinrow = 4;
       my %menutitles = &ltimenu_titles();
   
     if (ref($current) eq 'HASH') {      if (ref($current) eq 'HASH') {
           if (!$current->{'requser'}) {
               $optionsty = 'none';
           }
         if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {          if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
             $checked{'mapuser'}{'sourcedid'} = '';              $checked{'mapuser'}{'sourcedid'} = '';
             if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {              if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
Line 4714  sub lti_options { Line 5022  sub lti_options {
                 $checked{'mapcrstype'}{$type} = ' checked="checked"';                  $checked{'mapcrstype'}{$type} = ' checked="checked"';
             }              }
         }          }
         if ($current->{'makecrs'}) {           if ($current->{'makecrs'}) {
             $checked{'makecrs'}{'Y'} = '  checked="checked"';              $checked{'makecrs'}{'Y'} = '  checked="checked"';
         }           }
         if (ref($current->{'makeuser'}) eq 'ARRAY') {          if (ref($current->{'makeuser'}) eq 'ARRAY') {
             foreach my $role (@{$current->{'makeuser'}}) {              foreach my $role (@{$current->{'makeuser'}}) {
                 $checked{'makeuser'}{$role} = ' checked="checked"';                  $checked{'makeuser'}{$role} = ' checked="checked"';
             }              }
         }          }
           if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
               $checked{'lcauth'}{$1} = ' checked="checked"';
               unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
                   $lcauthparm = $current->{'lcauthparm'};
                   $lcauthparmstyle = 'display:table-row'; 
                   if ($current->{'lcauth'} eq 'localauth') {
                       $lcauthparmtext = &mt('Local auth argument');
                   } else {
                       $lcauthparmtext = &mt('Kerberos domain');
                   }
               }
           }
         if (ref($current->{'selfenroll'}) eq 'ARRAY') {          if (ref($current->{'selfenroll'}) eq 'ARRAY') {
             foreach my $role (@{$current->{'selfenroll'}}) {              foreach my $role (@{$current->{'selfenroll'}}) {
                 $checked{'selfenroll'}{$role} = ' checked="checked"';                  $checked{'selfenroll'}{$role} = ' checked="checked"';
Line 4743  sub lti_options { Line 5063  sub lti_options {
         } else {          } else {
             $checked{'crssec'}{'N'} = ' checked="checked"';              $checked{'crssec'}{'N'} = ' checked="checked"';
         }          }
           if ($current->{'callback'} ne '') {
               $callback = $current->{'callback'};
               $checked{'callback'}{'Y'} = ' checked="checked"';
               $callbacksty = 'inline-block';
           } else {
               $checked{'callback'}{'N'} = ' checked="checked"';
           }
           if ($current->{'topmenu'}) {
               $checked{'topmenu'}{'Y'} = ' checked="checked"';
           } else {
               $checked{'topmenu'}{'N'} = ' checked="checked"';
           }
           if ($current->{'inlinemenu'}) {
               $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
           } else {
               $checked{'inlinemenu'}{'N'} = ' checked="checked"';
           }
           if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
               $menusty = 'inline-block';
               if (ref($current->{'lcmenu'}) eq 'ARRAY') {
                   foreach my $item (@{$current->{'lcmenu'}}) {
                       if (exists($menutitles{$item})) {
                           $checked{'menuitem'}{$item} = ' checked="checked"';
                       }
                   }
               }
           } else {
               $menusty = 'none';
           }
     } else {      } else {
         $checked{'makecrs'}{'N'} = ' checked="checked"';          $checked{'makecrs'}{'N'} = ' checked="checked"';
         $checked{'crssec'}{'N'} = ' checked="checked"';          $checked{'crssec'}{'N'} = ' checked="checked"';
           $checked{'callback'}{'N'} = ' checked="checked"';
           $checked{'topmenu'}{'N'} = ' checked="checked"';
           $checked{'inlinemenu'}{'Y'} = ' checked="checked"'; 
           $checked{'menuitem'}{'grades'} = ' checked="checked"';
           $menusty = 'inline-block'; 
     }      }
     my @coursetypes = ('official','unofficial','community','textbook','placement');      my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
     my %coursetypetitles = &Apache::lonlocal::texthash (      my %coursetypetitles = &Apache::lonlocal::texthash (
                                official   => 'Official',                                 official   => 'Official',
                                unofficial => 'Unofficial',                                 unofficial => 'Unofficial',
                                community  => 'Community',                                 community  => 'Community',
                                textbook   => 'Textbook',                                 textbook   => 'Textbook',
                                placement  => 'Placement Test',                                 placement  => 'Placement Test',
                                  lti        => 'LTI Provider',
     );      );
       my @authtypes = ('internal','krb4','krb5','localauth');
       my %shortauth = (
                        internal => 'int',
                        krb4 => 'krb4',
                        krb5 => 'krb5',
                        localauth  => 'loc'
                       );
       my %authnames = &authtype_names();
     my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);      my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
     my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);      my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
     my @courseroles = ('cc','in','ta','ep','st');      my @courseroles = ('cc','in','ta','ep','st');
     my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';      my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
     my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';      my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
     my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';      my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
       my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
     my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';      my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
     my $output = '<fieldset><legend>'.&mt('Mapping users').'</legend>'.      my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
       my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
       my $output = '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').':&nbsp;';                   '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').':&nbsp;';
     foreach my $option ('sourcedid','email','other') {      foreach my $option ('sourcedid','email','other') {
         $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.          $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
Line 4773  sub lti_options { Line 5139  sub lti_options {
                '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.                 '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
                '<input type="text" name="lti_customuser_'.$num.'" '.                 '<input type="text" name="lti_customuser_'.$num.'" '.
                'value="'.$userfield.'" /></div></fieldset>'.                  'value="'.$userfield.'" /></div></fieldset>'. 
                '<fieldset><legend>'.&mt('Mapping course roles').'</legend><table><tr>';                 '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
     foreach my $ltirole (@lticourseroles) {      foreach my $ltirole (@lticourseroles) {
         my ($selected,$selectnone);          my ($selected,$selectnone);
         if ($rolemaps{$ltirole} eq '') {          if ($rolemaps{$ltirole} eq '') {
Line 4797  sub lti_options { Line 5163  sub lti_options {
         $output .= '</select></td>';          $output .= '</select></td>';
     }      }
     $output .= '</tr></table></fieldset>'.      $output .= '</tr></table></fieldset>'.
                '<fieldset><legend>'.&mt('Roles which may create user accounts').'</legend>';                 '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
     foreach my $ltirole (@ltiroles) {      foreach my $ltirole (@ltiroles) {
         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.          $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
                    $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label>&nbsp;</span> ';                          $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label>&nbsp;</span> ';     
     }      }
     $output .= '</fieldset>'.      $output .= '</fieldset>'.
                '<fieldset><legend>'.&mt('Mapping courses').'</legend>'.                 '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
                  '<table>'.
                  &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
                  '</table>'.
                  '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
                  '<td class="LC_left_item">';
       foreach my $auth ('lti',@authtypes) {
           my $authtext;
           if ($auth eq 'lti') {
               $authtext = &mt('None');
           } else {
               $authtext = $authnames{$shortauth{$auth}};
           }
           $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
                      '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
                      $authtext.'</label></span> &nbsp;';
       }
       $output .= '</td></tr>'.
                  '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
                  '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
                  '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
                  '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
                  '</table></fieldset>'.
                  '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping courses').'</legend>'.
                '<div class="LC_floatleft"><span class="LC_nobreak">'.                 '<div class="LC_floatleft"><span class="LC_nobreak">'.
                &mt('Unique course identifier').':&nbsp;';                 &mt('Unique course identifier').':&nbsp;';
     foreach my $option ('course_offering_sourcedid','context_id','other') {      foreach my $option ('course_offering_sourcedid','context_id','other') {
Line 4811  sub lti_options { Line 5200  sub lti_options {
                    $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.                     $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
                    ($option eq 'other' ? '' : ('&nbsp;'x2) );                     ($option eq 'other' ? '' : ('&nbsp;'x2) );
     }      }
     $output .= '</div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'".>'.      $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
                '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.                 '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.                 '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
                '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').':&nbsp;';                 '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').':&nbsp;';
Line 4821  sub lti_options { Line 5210  sub lti_options {
                    ('&nbsp;'x2);                     ('&nbsp;'x2);
     }      }
     $output .= '</span></fieldset>'.      $output .= '</span></fieldset>'.
                '<fieldset><legend>'.&mt('Creating courses').'</legend>'.                 '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Creating courses').'</legend>'.
                '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').':&nbsp;'.                 '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').':&nbsp;'.
                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.                 '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
                $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).                 $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.                 '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
                $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.                 $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
                '</fieldset>'.                 '</fieldset>'.
                '<fieldset><legend>'.&mt('Roles which may self-enroll').'</legend>';                 '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
     foreach my $lticrsrole (@lticourseroles) {      foreach my $lticrsrole (@lticourseroles) {
         $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.          $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
                    $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label>&nbsp;</span> ';                     $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label>&nbsp;</span> ';
     }      }
     $output .= '</fieldset>'.      $output .= '</fieldset>'.
                '<fieldset><legend>'.&mt('Course options').'</legend>'.                 '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course options').'</legend>'.
                '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').':&nbsp;'.                 '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').':&nbsp;'.
                '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.                 '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
                $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.('&nbsp;'x2).                 $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.                 '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
                $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label><span></div>'.                 $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
                '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.                 '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
                '<span class="LC_nobreak">'.&mt('From').':<label>'.                 '<span class="LC_nobreak">'.&mt('From').':<label>'.
                '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.                 '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
Line 4847  sub lti_options { Line 5236  sub lti_options {
                &mt('Standard field').'</label>'.('&nbsp;'x2).                 &mt('Standard field').'</label>'.('&nbsp;'x2).
                '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.                 '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
                $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').                 $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
                '</label></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.                 '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
                '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.                 '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
                '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';                  '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
     foreach my $extra ('passback','roster') {      my ($pb1p1chk,$pb1p0chk,$onclickpb);
       foreach my $extra ('roster','passback') {
         my $checkedon = '';          my $checkedon = '';
         my $checkedoff = ' checked="checked"';          my $checkedoff = ' checked="checked"';
           if ($extra eq 'passback') {
               $pb1p1chk = ' checked="checked"';
               $pb1p0chk = '';
               $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"'; 
           } else {
               $onclickpb = ''; 
           }
         if (ref($current) eq 'HASH') {          if (ref($current) eq 'HASH') {
             if (($current->{$extra})) {              if (($current->{$extra})) {
                 $checkedon = $checkedoff;                  $checkedon = $checkedoff;
                 $checkedoff = '';                  $checkedoff = '';
                   if ($extra eq 'passback') {
                       $passbacksty = 'inline-block';
                   }
                   if ($current->{'passbackformat'} eq '1.0') {
                       $pb1p0chk =  ' checked="checked"';
                       $pb1p1chk = '';
                   }
             }              }
         }          }
         $output .= $lt{$extra}.'&nbsp;'.          $output .= $lt{$extra}.'&nbsp;'.
                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.' />'.                     '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
                    &mt('No').'</label>'.('&nbsp;'x2).                     &mt('No').'</label>'.('&nbsp;'x2).
                    '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.' />'.                     '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
                    &mt('Yes').'</label><br />';                     &mt('Yes').'</label><br />';
     }      }
     $output .= '</span></fieldset>';      $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
                  '<span class="LC_nobreak">'.&mt('Grade format').
                  '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
                  &mt('Outcomes Service (1.1)').'</label>'.('&nbsp;'x2).
                  '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
                  &mt('Outcomes Extension (1.0)').'</label></span></div>'.
                  '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                  '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback on logout').':&nbsp;'.
                  '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
                  $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                  '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
                  $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
                  '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
                  '<span class="LC_nobreak">'.&mt('Parameter').': '.
                  '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
                  '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
                  '<fieldset class="ltioption_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Course defaults (Course Coordinator can override)').'</legend>'.
                  '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.':&nbsp;'.
                  '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
                  $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                  '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
                  $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
                  '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
                  '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.':&nbsp;'.
                  '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
                  $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.('&nbsp;'x2).
                  '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
                  $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
        $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'. 
                  '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
                  '<span class="LC_nobreak">'.&mt('Menu items').':&nbsp;';
       foreach my $type ('fullname','coursetitle','role','logout','grades') {
           $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
                      $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
                      ('&nbsp;'x2);
       }
       $output .= '</span></div></fieldset>';
 #        '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';  #        '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
 #  #
 #    $output .= '</fieldset>'.  #    $output .= '</fieldset>'.
Line 4873  sub lti_options { Line 5313  sub lti_options {
     return $output;      return $output;
 }  }
   
   sub ltimenu_titles {
       return &Apache::lonlocal::texthash(
                                           fullname    => 'Full name',
                                           coursetitle => 'Course title',
                                           role        => 'Role',
                                           logout      => 'Logout',
                                           grades      => 'Grades',
       );
   }
   
 sub print_coursedefaults {  sub print_coursedefaults {
     my ($position,$dom,$settings,$rowtotal) = @_;      my ($position,$dom,$settings,$rowtotal) = @_;
     my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);      my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
Line 4890  sub print_coursedefaults { Line 5340  sub print_coursedefaults {
         mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',          mysqltables          => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
     );      );
     my %staticdefaults = (      my %staticdefaults = (
                            texengine            => 'MathJax',  
                            anonsurvey_threshold => 10,                             anonsurvey_threshold => 10,
                            uploadquota          => 500,                             uploadquota          => 500,
                            postsubmit           => 60,                             postsubmit           => 60,
Line 4904  sub print_coursedefaults { Line 5353  sub print_coursedefaults {
                             'canclone'        => 'none',                              'canclone'        => 'none',
                           );                            );
         @toggles = ('canuse_pdfforms','uselcmath','usejsme');          @toggles = ('canuse_pdfforms','uselcmath','usejsme');
         my $deftex = $staticdefaults{'texengine'};          my $deftex = $Apache::lonnet::deftex;
         if (ref($settings) eq 'HASH') {          if (ref($settings) eq 'HASH') {
             if ($settings->{'texengine'}) {              if ($settings->{'texengine'}) {
                 if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {                  if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
Line 5351  sub print_validation_rows { Line 5800  sub print_validation_rows {
                               '</label></span> ';                                '</label></span> ';
             }              }
         } elsif ($item eq 'markup') {          } elsif ($item eq 'markup') {
             $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5" wrap="soft">'.              $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
                            $currvalidation{$item}.                             $currvalidation{$item}.
                               '</textarea>';                                '</textarea>';
         }          }
Line 5373  sub print_validation_rows { Line 5822  sub print_validation_rows {
         my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',          my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
                                                        'validationdc',%currhash);                                                         'validationdc',%currhash);
         my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';          my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
         $datatable .= '</td></tr><tr'.$css_class.'><td>';          $datatable .= '<tr'.$css_class.'><td>';
         if ($numdc > 1) {          if ($numdc > 1) {
             $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');              $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
         } else {          } else {
Line 5388  sub print_validation_rows { Line 5837  sub print_validation_rows {
     return $datatable;      return $datatable;
 }  }
   
   sub print_privacy {
       my ($position,$dom,$settings,$rowtotal) = @_;
       my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
       my $itemcount = 0;
       unless ($position eq 'top') {
           @items = ('domain','author','course','community');
           %names = &Apache::lonlocal::texthash (
                        domain => 'Assigned domain role(s)',
                        author => 'Assigned co-author role(s)',
                        course => 'Assigned course role(s)',
                        community => 'Assigned community role',
                    );
           $numinrow = 4;
           ($othertitle,$usertypes,$types) =
               &Apache::loncommon::sorted_inst_types($dom);
       }
       if (($position eq 'top') || ($position eq 'middle')) {
           my (%by_ip,%by_location,@intdoms,@instdoms);
           &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
           if ($position eq 'top') {
               my %curr;
               my @options = ('none','user','domain','auto');
               my %titles = &Apache::lonlocal::texthash (
                   none   => 'Not allowed',
                   user   => 'User authorizes',
                   domain => 'DC authorizes',
                   auto   => 'Unrestricted',
                   instdom => 'Other domain shares institution/provider',
                   extdom => 'Other domain has different institution/provider',
               );
               my %names = &Apache::lonlocal::texthash (
                   domain => 'Domain role',
                   author => 'Co-author role',
                   course => 'Course role',
                   community => 'Community role',
               );
               my $primary_id = &Apache::lonnet::domain($dom,'primary');
               my $intdom = &Apache::lonnet::internet_dom($primary_id);
               foreach my $domtype ('instdom','extdom') {
                   my (%checked,$skip);
                   $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
                                 '<td class="LC_left_item">';
                   if ($domtype eq 'instdom') {
                       unless (@instdoms > 1) {
                           $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
                           $skip = 1;
                       }
                   } elsif ($domtype eq 'extdom') {
                       if (keys(%by_location) == 0) {
                           $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
                           $skip = 1;
                       }
                   }
                   unless ($skip) {
                       foreach my $roletype ('domain','author','course','community') {
                           $checked{'auto'} = ' checked="checked"';
                           if (ref($settings) eq 'HASH') {
                               if (ref($settings->{approval}) eq 'HASH') {
                                   if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
                                       if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
                                           $checked{$1} = ' checked="checked"';
                                           $checked{'auto'} = '';
                                       }
                                   }
                               }
                           }
                           $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
                           foreach my $option (@options) {
                               $datatable .= '<span class="LC_nobreak"><label>'.
                                             '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
                                             'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
                                             '</label></span>&nbsp; ';
                           }
                           $datatable .= '</fieldset>';
                       }
                   }
                   $datatable .= '</td></tr>';
                   $itemcount ++;
               }
           } elsif ($position eq 'middle') {
               if ((@instdoms > 1) || (keys(%by_location) > 0)) {
                   if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                       foreach my $item (@{$types}) {
                           $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
                                                                  $numinrow,$itemcount,'','','','','',
                                                                  '',$usertypes->{$item});
                           $itemcount ++;
                       }
                   }
                   $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
                                                          $numinrow,$itemcount,'','','','','',
                                                          '',$othertitle);
                   $itemcount ++;
               } else {
                   my (@insttypes,%insttitles);
                   if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                       @insttypes = @{$types};
                       %insttitles = %{$usertypes};
                   }
                   foreach my $item (@insttypes,'default') {
                       my $title;
                       if ($item eq 'default') {
                           $title = $othertitle;
                       } else {
                           $title = $insttitles{$item};
                       }
                       $css_class = $itemcount%2?' class="LC_odd_row"':'';
                       $datatable .= '<tr'.$css_class.'>'.
                                     '<td class="LC_left_item">'.$title.'</td>'.
                                     '<td class="LC_left_item">'.
                                     &mt('Nothing to set here, as there are no other domains').
                                     '</td></tr>';
                       $itemcount ++;
                   }
               }
           }
       } else {
           my $prefix;
           if ($position eq 'lower') {
               $prefix = 'priv';
           } else {
               $prefix = 'unpriv';
           }
           foreach my $item (@items) {
               $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
                                                      $numinrow,$itemcount,'','','','','',
                                                      '',$names{$item});
               $itemcount ++;
           }
       }
       if (ref($rowtotal)) {
           $$rowtotal += $itemcount;
       }
       return $datatable;
   }
   
   sub print_passwords {
       my ($position,$dom,$confname,$settings,$rowtotal) = @_;
       my ($datatable,$css_class);
       my $itemcount = 0;
       my %titles = &Apache::lonlocal::texthash (
           captcha        => '"Forgot Password" CAPTCHA validation',
           link           => 'Reset link expiration (hours)',
           case           => 'Case-sensitive usernames/e-mail',
           prelink        => 'Information required (form 1)',
           postlink       => 'Information required (form 2)',
           emailsrc       => 'LON-CAPA e-mail address type(s)',
           customtext     => 'Domain specific text (HTML)',
           intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
           intauth_check  => 'Check bcrypt cost if authenticated',
           intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
           permanent      => 'Permanent e-mail address',
           critical       => 'Critical notification address',
           notify         => 'Notification address',
           min            => 'Minimum password length',
           max            => 'Maximum password length',
           chars          => 'Required characters',
           expire         => 'Password expiration (days)',
           numsaved       => 'Number of previous passwords to save and disallow reuse',
       );
       if ($position eq 'top') {
           my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
           my $shownlinklife = 2;
           my $prelink = 'both';
           my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
           if (ref($settings) eq 'HASH') {
               if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
                   $shownlinklife = $settings->{resetlink};
               }
               if (ref($settings->{resetcase}) eq 'ARRAY') {
                   map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
               }
               if ($settings->{resetprelink} =~ /^(both|either)$/) {
                   $prelink = $settings->{resetprelink};
               }
               if (ref($settings->{resetpostlink}) eq 'HASH') {
                   %postlink = %{$settings->{resetpostlink}};
               }
               if (ref($settings->{resetemail}) eq 'ARRAY') {
                   map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
               }
               if ($settings->{resetremove}) {
                   $nostdtext = 1;
               }
               if ($settings->{resetcustom}) {
                   $customurl = $settings->{resetcustom};
               }
           } else {
               if (ref($types) eq 'ARRAY') {
                   foreach my $item (@{$types}) {
                       $casesens{$item} = 1;
                       $postlink{$item} = ['username','email'];
                   }
               }
               $casesens{'default'} = 1;
               $postlink{'default'} = ['username','email'];
               $prelink = 'both';
               %emailsrc = (
                             permanent => 1,
                             critical  => 1,
                             notify    => 1,
               );
           }
           $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
           $itemcount ++;
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
                         '<td class="LC_left_item">'.
                         '<input type="textbox" value="'.$shownlinklife.'" '.
                         'name="passwords_link" size="3" /></td></tr>';
           $itemcount ++;
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
                         '<td class="LC_left_item">';
           if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
               foreach my $item (@{$types}) {
                   my $checkedcase;
                   if ($casesens{$item}) {
                       $checkedcase = ' checked="checked"';
                   }
                   $datatable .= '<span class="LC_nobreak"><label>'.
                                 '<input type="checkbox" name="passwords_case_sensitive" value="'.
                                 $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
                                 '</span>&nbsp;&nbsp; ';
               }
           }
           my $checkedcase;
           if ($casesens{'default'}) {
               $checkedcase = ' checked="checked"';
           }
           $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                         'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
                         $othertitle.'</label></span></td>';
           $itemcount ++;
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           my %checkedpre = (
                                both => ' checked="checked"',
                                either => '',
                            );
           if ($prelink eq 'either') {
               $checkedpre{either} = ' checked="checked"';
               $checkedpre{both} = '';
           }
           $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
                         '<td class="LC_left_item"><span class="LC_nobreak">'.
                         '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
                         &mt('Both username and e-mail address').'</label></span>&nbsp;&nbsp; '.
                         '<span class="LC_nobreak"><label>'.
                         '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
                         &mt('Either username or e-mail address').'</label></span></td></tr>';
           $itemcount ++;
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
                         '<td class="LC_left_item">';
           my %postlinked;
           if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
               foreach my $item (@{$types}) {
                   undef(%postlinked);
                   $datatable .= '<fieldset style="display: inline-block;">'.
                                 '<legend>'.$usertypes->{$item}.'</legend>';
                   if (ref($postlink{$item}) eq 'ARRAY') {
                       map { $postlinked{$_} = 1; } (@{$postlink{$item}});
                   }
                   foreach my $field ('email','username') {
                       my $checked;
                       if ($postlinked{$field}) {
                           $checked = ' checked="checked"';
                       }
                       $datatable .= '<span class="LC_nobreak"><label>'.
                                     '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
                                     $field.'"'.$checked.' />'.$field.'</label>'.
                                     '<span>&nbsp;&nbsp; ';
                   }
                   $datatable .= '</fieldset>';
               }
           }
           if (ref($postlink{'default'}) eq 'ARRAY') {
               map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
           }
           $datatable .= '<fieldset style="display: inline-block;">'.
                         '<legend>'.$othertitle.'</legend>';
           foreach my $field ('email','username') {
               my $checked;
               if ($postlinked{$field}) {
                   $checked = ' checked="checked"';
               }
               $datatable .= '<span class="LC_nobreak"><label>'.
                             '<input type="checkbox" name="passwords_postlink_default" value="'.
                             $field.'"'.$checked.' />'.$field.'</label>'.
                             '<span>&nbsp;&nbsp; ';
           }
           $datatable .= '</fieldset></td></tr>';
           $itemcount ++;
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
                         '<td class="LC_left_item">';
           foreach my $type ('permanent','critical','notify') {
               my $checkedemail;
               if ($emailsrc{$type}) {
                   $checkedemail = ' checked="checked"';
               }
               $datatable .= '<span class="LC_nobreak"><label>'.
                             '<input type="checkbox" name="passwords_emailsrc" value="'.
                             $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
                             '<span>&nbsp;&nbsp; ';
           }
           $datatable .= '</td></tr>';
           $itemcount ++;
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           my $switchserver = &check_switchserver($dom,$confname);
           my ($showstd,$noshowstd);
           if ($nostdtext) {
               $noshowstd = ' checked="checked"';
           } else {
               $showstd = ' checked="checked"';
           }
           $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
                         '<td class="LC_left_item"><span class="LC_nobreak">'.
                         &mt('Retain standard text:').
                         '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
                         &mt('Yes').'</label>'.'&nbsp;'.
                         '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
                         &mt('No').'</label></span><br />'.
                         '<span class="LC_fontsize_small">'.
                         &mt('(If you use the same account ...  reset a password from this page.)').'</span><br /><br />'.
                         &mt('Include custom text:');
           if ($customurl) {
               my $link =  &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
                                                          undef,undef,undef,undef,'background-color:#ffffff');
               $datatable .= '<span class="LC_nobreak">&nbsp;'.$link.
                             '<label><input type="checkbox" name="passwords_custom_del"'.
                             ' value="1" />'.&mt('Delete?').'</label></span>'.
                             ' <span class="LC_nobreak">&nbsp;'.&mt('Replace:').'</span>';
           }
           if ($switchserver) {
               $datatable .= '<span class="LC_nobreak">&nbsp;'.&mt('Upload to library server: [_1]',$switchserver).'</span>';
           } else {
               $datatable .='<span class="LC_nobreak">&nbsp;'.
                            '<input type="file" name="passwords_customfile" /></span>';
           }
           $datatable .= '</td></tr>';
       } elsif ($position eq 'middle') {
           my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
           my @items = ('intauth_cost','intauth_check','intauth_switch');
           my %defaults;
           if (ref($domconf{'defaults'}) eq 'HASH') {
               %defaults = %{$domconf{'defaults'}};
               if ($defaults{'intauth_cost'} !~ /^\d+$/) {
                   $defaults{'intauth_cost'} = 10;
               }
               if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
                   $defaults{'intauth_check'} = 0;
               }
               if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
                   $defaults{'intauth_switch'} = 0;
               }
           } else {
               %defaults = (
                             'intauth_cost'   => 10,
                             'intauth_check'  => 0,
                             'intauth_switch' => 0,
                           );
           }
           foreach my $item (@items) {
               if ($itemcount%2) {
                   $css_class = '';
               } else {
                   $css_class = ' class="LC_odd_row" ';
               }
               $datatable .= '<tr'.$css_class.'>'.
                             '<td><span class="LC_nobreak">'.$titles{$item}.
                             '</span></td><td class="LC_left_item" colspan="3">';
               if ($item eq 'intauth_switch') {
                   my @options = (0,1,2);
                   my %optiondesc = &Apache::lonlocal::texthash (
                                      0 => 'No',
                                      1 => 'Yes',
                                      2 => 'Yes, and copy existing passwd file to passwd.bak file',
                                    );
                   $datatable .= '<table width="100%">';
                   foreach my $option (@options) {
                       my $checked = ' ';
                       if ($defaults{$item} eq $option) {
                           $checked = ' checked="checked"';
                       }
                       $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                                     '<label><input type="radio" name="'.$item.
                                     '" value="'.$option.'"'.$checked.' />'.
                                     $optiondesc{$option}.'</label></span></td></tr>';
                   }
                   $datatable .= '</table>';
               } elsif ($item eq 'intauth_check') {
                   my @options = (0,1,2);
                   my %optiondesc = &Apache::lonlocal::texthash (
                                      0 => 'No',
                                      1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                                      2 => 'Yes, disallow login if stored cost is less than domain default',
                                    );
                   $datatable .= '<table width="100%">';
                   foreach my $option (@options) {
                       my $checked = ' ';
                       my $onclick;
                       if ($defaults{$item} eq $option) {
                           $checked = ' checked="checked"';
                       }
                       if ($option == 2) {
                           $onclick = ' onclick="javascript:warnIntAuth(this);"';
                       }
                       $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
                                     '<label><input type="radio" name="'.$item.
                                     '" value="'.$option.'"'.$checked.$onclick.' />'.
                                     $optiondesc{$option}.'</label></span></td></tr>';
                   }
                   $datatable .= '</table>';
               } else {
                   $datatable .= '<input type="text" name="'.$item.'" value="'.
                                 $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
               }
               $datatable .= '</td></tr>';
               $itemcount ++;
           }
       } elsif ($position eq 'lower') {
           my ($min,$max,%chars,$expire,$numsaved);
           $min = $Apache::lonnet::passwdmin;
           if (ref($settings) eq 'HASH') {
               if ($settings->{min}) {
                   $min = $settings->{min};
               }
               if ($settings->{max}) {
                   $max = $settings->{max};
               }
               if (ref($settings->{chars}) eq 'ARRAY') {
                   map { $chars{$_} = 1; } (@{$settings->{chars}});
               }
               if ($settings->{expire}) {
                   $expire = $settings->{expire};
               }
               if ($settings->{numsaved}) {
                   $numsaved = $settings->{numsaved};
               }
           }
           my %rulenames = &Apache::lonlocal::texthash(
                                                        uc => 'At least one upper case letter',
                                                        lc => 'At least one lower case letter',
                                                        num => 'At least one number',
                                                        spec => 'At least one non-alphanumeric',
                                                      );
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
                         '<td class="LC_left_item"><span class="LC_nobreak">'.
                         '<input type="text" name="passwords_min" value="'.$min.'" size="3" '.
                         'onblur="javascript:warnIntPass(this);" />'.
                         '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
                         '</span></td></tr>';
           $itemcount ++;
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
                         '<td class="LC_left_item"><span class="LC_nobreak">'.
                         '<input type="text" name="passwords_max" value="'.$max.'" size="3" '.
                         'onblur="javascript:warnIntPass(this);" />'.
                         '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
                         '</span></td></tr>';
           $itemcount ++;
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
                         '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
                         '</span></td>';
           my $numinrow = 2;
           my @possrules = ('uc','lc','num','spec');
           $datatable .= '<td class="LC_left_item"><table>';
           for (my $i=0; $i<@possrules; $i++) {
               my ($rem,$checked);
               if ($chars{$possrules[$i]}) {
                   $checked = ' checked="checked"';
               }
               $rem = $i%($numinrow);
               if ($rem == 0) {
                   if ($i > 0) {
                       $datatable .= '</tr>';
                   }
                   $datatable .= '<tr>';
               }
               $datatable .= '<td><span class="LC_nobreak"><label>'.
                             '<input type="checkbox" name="passwords_chars" value="'.$possrules[$i].'"'.$checked.' />'.
                             $rulenames{$possrules[$i]}.'</label></span></td>';
           }
           my $rem = @possrules%($numinrow);
           my $colsleft = $numinrow - $rem;
           if ($colsleft > 1 ) {
               $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                             '&nbsp;</td>';
           } elsif ($colsleft == 1) {
               $datatable .= '<td class="LC_left_item">&nbsp;</td>';
           }
           $datatable .='</table></td></tr>';
           $itemcount ++;
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
                         '<td class="LC_left_item"><span class="LC_nobreak">'.
                         '<input type="text" name="passwords_expire" value="'.$expire.'" size="4" '.
                         'onblur="javascript:warnIntPass(this);" />'.
                         '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
                         '</span></td></tr>';
           $itemcount ++;
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
                         '<td class="LC_left_item"><span class="LC_nobreak">'.
                         '<input type="text" name="passwords_numsaved" value="'.$numsaved.'" size="3" '.
                         'onblur="javascript:warnIntPass(this);" />'. 
                         '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
                         '</span></td></tr>';
       } else {
           my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
           my %ownerchg = (
                             by  => {},
                             for => {},
                          );
           my %ownertitles = &Apache::lonlocal::texthash (
                               by  => 'Course owner status(es) allowed',
                               for => 'Student status(es) allowed',
                             );
           if (ref($settings) eq 'HASH') {
               if (ref($settings->{crsownerchg}) eq 'HASH') {
                   if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
                       map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
                   }
                   if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
                       map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
                   }
               }
           }
           $css_class = $itemcount%2?' class="LC_odd_row"':'';
           $datatable .= '<tr '.$css_class.'>'.
                         '<td>'.
                         &mt('Requirements').'<ul>'.
                         '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
                         '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
                         '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
                         '<li>'.&mt('User, course, and student share same domain').'</li>'.
                         '</ul>'.
                         '</td>'.
                         '<td class="LC_left_item">';
           foreach my $item ('by','for') {
               $datatable .= '<fieldset style="display: inline-block;">'.
                             '<legend>'.$ownertitles{$item}.'</legend>';
               if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
                   foreach my $type (@{$types}) {
                       my $checked;
                       if ($ownerchg{$item}{$type}) {
                           $checked = ' checked="checked"';
                       }
                       $datatable .= '<span class="LC_nobreak"><label>'.
                                     '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
                                     $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
                                     '</span>&nbsp;&nbsp; ';
                   }
               }
               my $checked;
               if ($ownerchg{$item}{'default'}) {
                   $checked = ' checked="checked"';
               }
               $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
                             'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
                             $othertitle.'</label></span></fieldset>';
           }
           $datatable .= '</td></tr>';
       }
       return $datatable;
   }
   
 sub print_usersessions {  sub print_usersessions {
     my ($position,$dom,$settings,$rowtotal) = @_;      my ($position,$dom,$settings,$rowtotal) = @_;
     my ($css_class,$datatable,$itemcount,%checked,%choices);      my ($css_class,$datatable,$itemcount,%checked,%choices);
Line 6010  sub print_loadbalancing { Line 7030  sub print_loadbalancing {
     my $numinrow = 1;      my $numinrow = 1;
     my $datatable;      my $datatable;
     my %servers = &Apache::lonnet::internet_dom_servers($dom);      my %servers = &Apache::lonnet::internet_dom_servers($dom);
     my (%currbalancer,%currtargets,%currrules,%existing);      my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
         %existing = %{$settings};          %existing = %{$settings};
     }      }
     if ((keys(%servers) > 1) || (keys(%existing) > 0)) {      if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
         &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,          &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                                   \%currtargets,\%currrules);                                    \%currtargets,\%currrules,\%currcookies);
     } else {      } else {
         return;          return;
     }      }
Line 6093  sub print_loadbalancing { Line 7113  sub print_loadbalancing {
         my %hostherechecked = (          my %hostherechecked = (
                                   no => ' checked="checked"',                                    no => ' checked="checked"',
                               );                                );
           my %balcookiechecked = (
                                     no => ' checked="checked"', 
                                  );
         foreach my $sparetype (@sparestypes) {          foreach my $sparetype (@sparestypes) {
             my $targettable;              my $targettable;
             for (my $i=0; $i<$numspares; $i++) {              for (my $i=0; $i<$numspares; $i++) {
Line 6148  sub print_loadbalancing { Line 7171  sub print_loadbalancing {
                 }                  }
             }              }
         }          }
           if ($currcookies{$lonhost}) {
               %balcookiechecked = (
                                       yes => ' checked="checked"',
                                   );
           }
         $datatable .= &mt('Hosting on balancer itself').'<br />'.          $datatable .= &mt('Hosting on balancer itself').'<br />'.
                       '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.                        '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
                       $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';                        $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
Line 6156  sub print_loadbalancing { Line 7184  sub print_loadbalancing {
                           'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.                            'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
                           '</i></label><br />';                            '</i></label><br />';
         }          }
         $datatable .= '</div></td></tr>'.          $datatable .= &mt('Use balancer cookie').'<br />'.
                         '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
                         $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
                         '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
                         $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
                         '</div></td></tr>'.
                       &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},                        &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
                                            $othertitle,$usertypes,$types,\%servers,                                             $othertitle,$usertypes,$types,\%servers,
                                            \%currbalancer,$lonhost,                                             \%currbalancer,$lonhost,
Line 6170  sub print_loadbalancing { Line 7203  sub print_loadbalancing {
 }  }
   
 sub get_loadbalancers_config {  sub get_loadbalancers_config {
     my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;      my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
     return unless ((ref($servers) eq 'HASH') &&      return unless ((ref($servers) eq 'HASH') &&
                    (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&                     (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
                    (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));                     (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
                      (ref($currcookies) eq 'HASH'));
     if (keys(%{$existing}) > 0) {      if (keys(%{$existing}) > 0) {
         my $oldlonhost;          my $oldlonhost;
         foreach my $key (sort(keys(%{$existing}))) {          foreach my $key (sort(keys(%{$existing}))) {
Line 6192  sub get_loadbalancers_config { Line 7226  sub get_loadbalancers_config {
                 $currbalancer->{$key} = 1;                  $currbalancer->{$key} = 1;
                 $currtargets->{$key} = $existing->{$key}{'targets'};                  $currtargets->{$key} = $existing->{$key}{'targets'};
                 $currrules->{$key} = $existing->{$key}{'rules'};                  $currrules->{$key} = $existing->{$key}{'rules'};
                   if ($existing->{$key}{'cookie'}) {
                       $currcookies->{$key} = 1;
                   }
             }              }
         }          }
     } else {      } else {
Line 6387  sub contact_titles { Line 7424  sub contact_titles {
                    'requestsmail'    => 'E-mail from course requests requiring approval',                     'requestsmail'    => 'E-mail from course requests requiring approval',
                    'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',                     'updatesmail'     => 'E-mail from nightly check of LON-CAPA module integrity/updates',
                    'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',                     'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
                      'hostipmail'      => 'E-mail from nightly check of hostname/IP network changes',
                      'errorthreshold'  => 'Error/warning threshold for status e-mail',
                      'errorsysmail'    => 'Error threshold for e-mail to core group',
                      'errorweights'    => 'Weights used to compute error count',
                      'errorexcluded'   => 'Servers with unsent updates excluded from count',
                  );                   );
     my %short_titles = &Apache::lonlocal::texthash (      my %short_titles = &Apache::lonlocal::texthash (
                            adminemail   => 'Admin E-mail address',                             adminemail   => 'Admin E-mail address',
Line 6445  sub courserequest_titles { Line 7487  sub courserequest_titles {
                                    community  => 'Communities',                                     community  => 'Communities',
                                    textbook   => 'Textbook',                                     textbook   => 'Textbook',
                                    placement  => 'Placement tests',                                     placement  => 'Placement tests',
                                      lti        => 'LTI Provider',
                                    norequest  => 'Not allowed',                                     norequest  => 'Not allowed',
                                    approval   => 'Approval by Dom. Coord.',                                     approval   => 'Approval by DC',
                                    validate   => 'With validation',                                     validate   => 'With validation',
                                    autolimit  => 'Numerical limit',                                     autolimit  => 'Numerical limit',
                                    unlimited  => '(blank for unlimited)',                                     unlimited  => '(blank for unlimited)',
Line 6558  sub print_usercreation { Line 7601  sub print_usercreation {
         }          }
     } else {      } else {
         my @contexts = ('author','course','domain');          my @contexts = ('author','course','domain');
         my @authtypes = ('int','krb4','krb5','loc');          my @authtypes = ('int','krb4','krb5','loc','lti');
         my %checked;          my %checked;
         if (ref($settings) eq 'HASH') {          if (ref($settings) eq 'HASH') {
             if (ref($settings->{'authtypes'}) eq 'HASH') {              if (ref($settings->{'authtypes'}) eq 'HASH') {
Line 6675  sub print_selfcreation { Line 7718  sub print_selfcreation {
         $datatable .= '<tr'.$css_class.'>'.          $datatable .= '<tr'.$css_class.'>'.
                      '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.                       '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
                      '<td class="LC_left_item">'."\n".                       '<td class="LC_left_item">'."\n".
                      '<table><tr><td>'."\n";                       '<table>'."\n";
         for (my $i=0; $i<@fields; $i++) {          for (my $i=0; $i<@fields; $i++) {
             $rem = $i%($numperrow);              $rem = $i%($numperrow);
             if ($rem == 0) {              if ($rem == 0) {
Line 7123  sub captcha_choice { Line 8166  sub captcha_choice {
         $vertext,$currver);          $vertext,$currver);
     my %lt = &captcha_phrases();      my %lt = &captcha_phrases();
     $keyentry = 'hidden';      $keyentry = 'hidden';
       my $colspan=2;
     if ($context eq 'cancreate') {      if ($context eq 'cancreate') {
         $rowname = &mt('CAPTCHA validation');          $rowname = &mt('CAPTCHA validation');
     } elsif ($context eq 'login') {      } elsif ($context eq 'login') {
         $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');          $rowname =  &mt('"Contact helpdesk" CAPTCHA validation');
       } elsif ($context eq 'passwords') {
           $rowname = &mt('"Forgot Password" CAPTCHA validation');
           $colspan=1;
     }      }
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
         if ($settings->{'captcha'}) {          if ($settings->{'captcha'}) {
Line 7166  sub captcha_choice { Line 8213  sub captcha_choice {
         $css_class .= ' style="'.$rowstyle.'"';          $css_class .= ' style="'.$rowstyle.'"';
     }      }
     my $output = '<tr'.$css_class.'>'.      my $output = '<tr'.$css_class.'>'.
                  '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".                   '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
                  '<table><tr><td>'."\n";                   '<table><tr><td>'."\n";
     foreach my $option ('original','recaptcha','notused') {      foreach my $option ('original','recaptcha','notused') {
         $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.          $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
Line 7298  sub authtype_names { Line 8345  sub authtype_names {
                       krb4   => 'Kerberos 4',                        krb4   => 'Kerberos 4',
                       krb5   => 'Kerberos 5',                        krb5   => 'Kerberos 5',
                       loc    => 'Local',                        loc    => 'Local',
                         lti    => 'LTI',
                   );                    );
     return %lt;      return %lt;
 }  }
Line 7366  sub print_defaults { Line 8414  sub print_defaults {
                           '<td><span class="LC_nobreak">'.$titles->{$item}.                            '<td><span class="LC_nobreak">'.$titles->{$item}.
                           '</span></td><td class="LC_right_item" colspan="3">';                            '</span></td><td class="LC_right_item" colspan="3">';
             if ($item eq 'auth_def') {              if ($item eq 'auth_def') {
                 my @authtypes = ('internal','krb4','krb5','localauth');                  my @authtypes = ('internal','krb4','krb5','localauth','lti');
                 my %shortauth = (                  my %shortauth = (
                                  internal => 'int',                                   internal => 'int',
                                  krb4 => 'krb4',                                   krb4 => 'krb4',
                                  krb5 => 'krb5',                                   krb5 => 'krb5',
                                  localauth  => 'loc'                                   localauth  => 'loc',
                                    lti => 'lti',
                                 );                                  );
                 my %authnames = &authtype_names();                  my %authnames = &authtype_names();
                 foreach my $auth (@authtypes) {                  foreach my $auth (@authtypes) {
Line 7403  sub print_defaults { Line 8452  sub print_defaults {
             $datatable .= '</td></tr>';              $datatable .= '</td></tr>';
             $rownum ++;              $rownum ++;
         }          }
     } elsif ($position eq 'middle') {  
         my @items = ('intauth_cost','intauth_check','intauth_switch');  
         my %defaults;  
         if (ref($settings) eq 'HASH') {  
             %defaults = %{$settings};  
             if ($defaults{'intauth_cost'} !~ /^\d+$/) {  
                 $defaults{'intauth_cost'} = 10;  
             }  
             if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {  
                 $defaults{'intauth_check'} = 0;  
             }  
             if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {  
                 $defaults{'intauth_switch'} = 0;  
             }  
         } else {  
             %defaults = (  
                           'intauth_cost'   => 10,  
                           'intauth_check'  => 0,  
                           'intauth_switch' => 0,  
                         );  
         }  
         foreach my $item (@items) {  
             if ($rownum%2) {  
                 $css_class = '';  
             } else {  
                 $css_class = ' class="LC_odd_row" ';  
             }  
             $datatable .= '<tr'.$css_class.'>'.  
                           '<td><span class="LC_nobreak">'.$titles->{$item}.  
                           '</span></td><td class="LC_left_item" colspan="3">';  
             if ($item eq 'intauth_switch') {  
                 my @options = (0,1,2);  
                 my %optiondesc = &Apache::lonlocal::texthash (  
                                    0 => 'No',  
                                    1 => 'Yes',  
                                    2 => 'Yes, and copy existing passwd file to passwd.bak file',  
                                  );  
                 $datatable .= '<table width="100%">';  
                 foreach my $option (@options) {  
                     my $checked = ' ';  
                     if ($defaults{$item} eq $option) {  
                         $checked = ' checked="checked"';  
                     }  
                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.  
                                   '<label><input type="radio" name="'.$item.  
                                   '" value="'.$option.'"'.$checked.' />'.  
                                   $optiondesc{$option}.'</label></span></td></tr>';  
                 }  
                 $datatable .= '</table>';  
             } elsif ($item eq 'intauth_check') {  
                 my @options = (0,1,2);  
                 my %optiondesc = &Apache::lonlocal::texthash (  
                                    0 => 'No',  
                                    1 => 'Yes, allow login then update passwd file using default cost (if higher)',  
                                    2 => 'Yes, disallow login if stored cost is less than domain default',  
                                  );  
                 $datatable .= '<table wisth="100%">';  
                 foreach my $option (@options) {  
                     my $checked = ' ';  
                     my $onclick;  
                     if ($defaults{$item} eq $option) {  
                         $checked = ' checked="checked"';  
                     }  
                     if ($option == 2) {  
                         $onclick = ' onclick="javascript:warnIntAuth(this);"';  
                     }  
                     $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.  
                                   '<label><input type="radio" name="'.$item.  
                                   '" value="'.$option.'"'.$checked.$onclick.' />'.  
                                   $optiondesc{$option}.'</label></span></td></tr>';  
                 }  
                 $datatable .= '</table>';  
             } else {  
                 $datatable .= '<input type="text" name="'.$item.'" value="'.  
                               $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';   
             }  
             $datatable .= '</td></tr>';  
             $rownum ++;  
         }  
     } else {      } else {
         my %defaults;          my %defaults;
         if (ref($settings) eq 'HASH') {          if (ref($settings) eq 'HASH') {
Line 7574  sub defaults_titles { Line 8544  sub defaults_titles {
     return (\%titles);      return (\%titles);
 }  }
   
   sub print_scantron {
       my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
       if ($position eq 'top') {
           return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
       } else {
           return &print_scantronconfig($dom,$settings,\$rowtotal);
       }
   }
   
   sub scantron_javascript {
       return <<"ENDSCRIPT";
   
   <script type="text/javascript">
   // <![CDATA[
   
   function toggleScantron(form) {
       var csvfieldset = new Array();
       if (document.getElementById('scantroncsv_cols')) {
           csvfieldset.push(document.getElementById('scantroncsv_cols'));
       }
       if (document.getElementById('scantroncsv_options')) {
           csvfieldset.push(document.getElementById('scantroncsv_options'));
       }
       if (csvfieldset.length) {
           if (document.getElementById('scantronconfcsv')) {
               var scantroncsv = document.getElementById('scantronconfcsv');
               if (scantroncsv.checked) {
                   for (var i=0; i<csvfieldset.length; i++) {
                       csvfieldset[i].style.display = 'block';
                   }
               } else {
                   for (var i=0; i<csvfieldset.length; i++) {
                       csvfieldset[i].style.display = 'none';
                   }
                   var csvselects = document.getElementsByClassName('scantronconfig_csv');
                   if (csvselects.length) {
                       for (var j=0; j<csvselects.length; j++) {
                           csvselects[j].selectedIndex = 0;
                       }
                   }
               }
           }
       }
       return;
   }
   // ]]>
   </script>
   
   ENDSCRIPT
   
   }
   
 sub print_scantronformat {  sub print_scantronformat {
     my ($r,$dom,$confname,$settings,$rowtotal) = @_;      my ($r,$dom,$confname,$settings,$rowtotal) = @_;
     my $itemcount = 1;      my $itemcount = 1;
Line 7600  sub print_scantronformat { Line 8622  sub print_scantronformat {
             if ($configuserok eq 'ok') {              if ($configuserok eq 'ok') {
                 if ($author_ok eq 'ok') {                  if ($author_ok eq 'ok') {
                     my %legacyfile = (                      my %legacyfile = (
  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',    default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',    custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
                     );                      );
                     my %md5chk;                      my %md5chk;
                     foreach my $type (keys(%legacyfile)) {                      foreach my $type (keys(%legacyfile)) {
Line 7610  sub print_scantronformat { Line 8632  sub print_scantronformat {
                     }                      }
                     if ($md5chk{'default'} ne $md5chk{'custom'}) {                      if ($md5chk{'default'} ne $md5chk{'custom'}) {
                         foreach my $type (keys(%legacyfile)) {                          foreach my $type (keys(%legacyfile)) {
                             ($scantronurls{$type},my $error) =                               ($scantronurls{$type},my $error) =
                                 &legacy_scantronformat($r,$dom,$confname,                                  &legacy_scantronformat($r,$dom,$confname,
                                                  $type,$legacyfile{$type},                                                   $type,$legacyfile{$type},
                                                  $scantronurls{$type},                                                   $scantronurls{$type},
Line 7621  sub print_scantronformat { Line 8643  sub print_scantronformat {
                         }                          }
                         if (keys(%error) == 0) {                          if (keys(%error) == 0) {
                             $is_custom = 1;                              $is_custom = 1;
                             $confhash{'scantron'}{'scantronformat'} =                               $confhash{'scantron'}{'scantronformat'} =
                                 $scantronurls{'custom'};                                  $scantronurls{'custom'};
                             my $putresult =                               my $putresult =
                                 &Apache::lonnet::put_dom('configuration',                                  &Apache::lonnet::put_dom('configuration',
                                                          \%confhash,$dom);                                                           \%confhash,$dom);
                             if ($putresult ne 'ok') {                              if ($putresult ne 'ok') {
                                 $error{'custom'} =                                   $error{'custom'} =
                                     '<span class="LC_error">'.                                      '<span class="LC_error">'.
                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';                                      &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                             }                              }
Line 7747  sub legacy_scantronformat { Line 8769  sub legacy_scantronformat {
     return ($url,$error);      return ($url,$error);
 }  }
   
   sub print_scantronconfig {
       my ($dom,$settings,$rowtotal) = @_;
       my $itemcount = 2;
       my $is_checked = ' checked="checked"';
       my %optionson = (
                        hdr => ' checked="checked"',
                        pad => ' checked="checked"',
                        rem => ' checked="checked"',
                       );
       my %optionsoff = (
                         hdr => '',
                         pad => '',
                         rem => '',
                        );
       my $currcsvsty = 'none';
       my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
       my @fields = &scantroncsv_fields();
       my %titles = &scantronconfig_titles();
       if (ref($settings) eq 'HASH') {
           if (ref($settings->{config}) eq 'HASH') {
               if ($settings->{config}->{dat}) {
                   $checked{'dat'} = $is_checked;
               }
               if (ref($settings->{config}->{csv}) eq 'HASH') {
                   if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
                       %csvfields = %{$settings->{config}->{csv}->{fields}};
                       if (keys(%csvfields) > 0) {
                           $checked{'csv'} = $is_checked;
                           $currcsvsty = 'block';
                       }
                   }
                   if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
                       %csvoptions = %{$settings->{config}->{csv}->{options}};
                       foreach my $option (keys(%optionson)) {
                           unless ($csvoptions{$option}) {
                               $optionsoff{$option} = $optionson{$option};
                               $optionson{$option} = '';
                           }
                       }
                   }
               }
           } else {
               $checked{'dat'} = $is_checked;
           }
       } else {
           $checked{'dat'} = $is_checked;
       }
       $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
       my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
       $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
                    '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
       foreach my $item ('dat','csv') {
           my $id;
           if ($item eq 'csv') {
               $id = 'id="scantronconfcsv" ';
           }
           $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
                         $titles{$item}.'</label>'.('&nbsp;'x3);
           if ($item eq 'csv') {
               $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
                             '<legend>'.&mt('CSV Column Mapping').'</legend>'.
                             '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
               foreach my $col (@fields) {
                   my $selnone;
                   if ($csvfields{$col} eq '') {
                       $selnone = ' selected="selected"';
                   }
                   $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
                                 '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
                                 '<option value=""'.$selnone.'></option>';
                   for (my $i=0; $i<20; $i++) {
                       my $shown = $i+1;
                       my $sel;
                       unless ($selnone) {
                           if (exists($csvfields{$col})) {
                               if ($csvfields{$col} == $i) {
                                   $sel = ' selected="selected"';
                               }
                           }
                       }
                       $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
                   }
                   $datatable .= '</select></td></tr>';
              }
              $datatable .= '</table></fieldset>'.
                            '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
                            '<legend>'.&mt('CSV Options').'</legend>';
              foreach my $option ('hdr','pad','rem') {
                  $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
                            '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
                            &mt('Yes').'</label>'.('&nbsp;'x2)."\n".
                            '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
              }
              $datatable .= '</fieldset>';
              $itemcount ++;
           }
       }
       $datatable .= '</td></tr>';
       $$rowtotal ++;
       return $datatable;
   }
   
   sub scantronconfig_titles {
       return &Apache::lonlocal::texthash(
                                             dat => 'Standard format (.dat)',
                                             csv => 'Comma separated values (.csv)',
                                             hdr => 'Remove first line in file (contains column titles)',
                                             pad => 'Prepend 0s to PaperID',
                                             rem => 'Remove leading spaces (except Question Response columns)',
                                             CODE => 'CODE',
                                             ID   => 'Student ID',
                                             PaperID => 'Paper ID',
                                             FirstName => 'First Name',
                                             LastName => 'Last Name',
                                             FirstQuestion => 'First Question Response',
                                             Section => 'Section',
       );
   }
   
   sub scantroncsv_fields {
       return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
   }
   
 sub print_coursecategories {  sub print_coursecategories {
     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;      my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
     my $datatable;      my $datatable;
Line 7789  sub print_coursecategories { Line 8934  sub print_coursecategories {
                              '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.                               '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
                              ' />'.$lt{$type}.'</label>&nbsp;';                               ' />'.$lt{$type}.'</label>&nbsp;';
            }             }
            $datatable .= '</td></tr>';             $datatable .= '</span></td></tr>';
            $itemcount ++;             $itemcount ++;
         }          }
         $$rowtotal += $itemcount;          $$rowtotal += $itemcount;
Line 7875  sub print_coursecategories { Line 9020  sub print_coursecategories {
                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.                    $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                   '<label><input type="radio" name="categorizecomm"'.                    '<label><input type="radio" name="categorizecomm"'.
                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.                    $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
                   '</tr><tr>'.                    '</tr><tr class="LC_odd_row">'.
                   '<td>'.$title{'togglecatsplace'}.'</td>'.                    '<td>'.$title{'togglecatsplace'}.'</td>'.
                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.                    '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   '<input type="radio" name="togglecatsplace"'.                    '<input type="radio" name="togglecatsplace"'.
Line 8032  sub print_coursecategories { Line 9177  sub print_coursecategories {
                 $datatable .= &initialize_categories($itemcount);                  $datatable .= &initialize_categories($itemcount);
             }              }
         } else {          } else {
             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td>'              $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
                           .&initialize_categories($itemcount);                            .&initialize_categories($itemcount);
         }          }
         $$rowtotal += $itemcount;          $$rowtotal += $itemcount;
Line 8080  sub print_serverstatuses { Line 9225  sub print_serverstatuses {
                       '<span class="LC_nobreak">'.                        '<span class="LC_nobreak">'.
                       '<input type="text" name="'.$type.'_machines" '.                        '<input type="text" name="'.$type.'_machines" '.
                       'value="'.$machineaccess{$type}.'" size="10" />'.                        'value="'.$machineaccess{$type}.'" size="10" />'.
                       '</td></tr>'."\n";                        '</span></td></tr>'."\n";
     }      }
     $$rowtotal += $rownum;      $$rowtotal += $rownum;
     return $datatable;      return $datatable;
Line 8095  sub serverstatus_pages { Line 9240  sub serverstatus_pages {
   
 sub defaults_javascript {  sub defaults_javascript {
     my ($settings) = @_;      my ($settings) = @_;
     my $intauthcheck = &mt('Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.');      return unless (ref($settings) eq 'HASH');
     my $intauthcost = &mt('Warning: bcrypt encryption cost for internal authentication must be an integer.');  
     &js_escape(\$intauthcheck);  
     &js_escape(\$intauthcost);  
     my $intauthjs = <<"ENDSCRIPT";  
   
 function warnIntAuth(field) {  
     if (field.name == 'intauth_check') {  
         if (field.value == '2') {  
             alert('$intauthcheck');  
         }  
     }  
     if (field.name == 'intauth_cost') {  
         field.value.replace(/\s/g,'');  
         if (field.value != '') {  
             var regexdigit=/^\\d+\$/;  
             if (!regexdigit.test(field.value)) {  
                 alert('$intauthcost');  
             }  
         }  
     }  
     return;  
 }  
   
 ENDSCRIPT  
   
     if (ref($settings) ne 'HASH') {  
         return &Apache::lonhtmlcommon::scripttag($intauthjs);  
     }  
     if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {      if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
         my $maxnum = scalar(@{$settings->{'inststatusorder'}});          my $maxnum = scalar(@{$settings->{'inststatusorder'}});
         if ($maxnum eq '') {          if ($maxnum eq '') {
Line 8177  $jstext Line 9294  $jstext
     return;      return;
 }  }
   
 $intauthjs  
   
 // ]]>  // ]]>
 </script>  </script>
   
 ENDSCRIPT  ENDSCRIPT
       }
       return;
   }
   
   sub passwords_javascript {
       my %intalert = &Apache::lonlocal::texthash (
           authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
           authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
           passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
           passmax => 'Warning: maximum password length must be a positive integer (or blank).',
           passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
           passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
       );
       &js_escape(\%intalert);
       my $defmin = $Apache::lonnet::passwdmin;
       my $intauthjs = <<"ENDSCRIPT";
   
   function warnIntAuth(field) {
       if (field.name == 'intauth_check') {
           if (field.value == '2') {
               alert('$intalert{authcheck}');
           }
       }
       if (field.name == 'intauth_cost') {
           field.value.replace(/\s/g,'');
           if (field.value != '') {
               var regexdigit=/^\\d+\$/;
               if (!regexdigit.test(field.value)) {
                   alert('$intalert{authcost}');
               }
           }
       }
       return;
   }
   
   function warnIntPass(field) {
       field.value.replace(/^\s+/,'');
       field.value.replace(/\s+\$/,'');
       var regexdigit=/^\\d+\$/;
       if (field.name == 'passwords_min') {
           if (field.value == '') {
               alert('$intalert{passmin}');
               field.value = '$defmin';
           } else {
               if (!regexdigit.test(field.value)) {
                   alert('$intalert{passmin}');
                   field.value = '$defmin';
               }
               var minval = parseInt(field.value,10);
               if (minval < $defmin) {
                   alert('$intalert{passmin}');
                   field.value = '$defmin';
               }
           }
     } else {      } else {
         return &Apache::lonhtmlcommon::scripttag($intauthjs);          if (field.value == '0') {
               field.value = '';
           }
           if (field.value != '') {
               if (field.name == 'passwords_expire') {
                   var regexpposnum=/^\\d+(|\\.\\d*)\$/; 
                   if (!regexpposnum.test(field.value)) {
                       alert('$intalert{passexp}');
                       field.value = '';
                   } else {
                       var expval = parseFloat(field.value);
                       if (expval == 0) {
                           alert('$intalert{passexp}');
                           field.value = '';
                       }
                   }
               } else {
                   if (!regexdigit.test(field.value)) {
                       if (field.name == 'passwords_max') {
                           alert('$intalert{passmax}');
                       } else {
                           if (field.name == 'passwords_numsaved') {
                               alert('$intalert{passnum}');
                           }
                       }
                   }
                   field.value = '';
               }
           }
     }      }
       return;
   }
   
   ENDSCRIPT
       return &Apache::lonhtmlcommon::scripttag($intauthjs);
 }  }
   
 sub coursecategories_javascript {  sub coursecategories_javascript {
Line 8308  sub initialize_categories { Line 9510  sub initialize_categories {
                       communities => 'Communities',                        communities => 'Communities',
                       placement   => 'Placement Tests',                        placement   => 'Placement Tests',
                         );                          );
     my $select0 = ' selected="selected"';      my %selnum = (
     my $select1 = '';                     instcode    => '0',
                      communities => '1',
                      placement   => '2',
                    );
       my %selected;
     foreach my $default ('instcode','communities','placement') {      foreach my $default ('instcode','communities','placement') {
         $css_class = $itemcount%2?' class="LC_odd_row"':'';          $css_class = $itemcount%2?' class="LC_odd_row"':'';
         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';          $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
         if (($default eq 'communities') || ($default eq 'placement')) {          map { $selected{$selnum{$_}} = '' } keys(%selnum);
             $select1 = $select0;          $selected{$selnum{$default}} = ' selected="selected"';
             $select0 = '';  
         }  
         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'          $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                      .'<select name="'.$default.'_pos">'                       .'<select name="'.$default.'_pos"'.$chgstr.'>'
                      .'<option value="0"'.$select0.'>1</option>'                       .'<option value="0"'.$selected{'0'}.'>1</option>'
                      .'<option value="1"'.$select1.'>2</option>'                       .'<option value="1"'.$selected{'1'}.'>2</option>'
                      .'<option value="2">3</option></select>&nbsp;'                       .'<option value="2"'.$selected{'2'}.'>3</option>'
                        .'<option value="3">4</option></select>&nbsp;'
                      .$default_names{$default}                       .$default_names{$default}
                      .'</span></td><td><span class="LC_nobreak">'                       .'</span></td><td><span class="LC_nobreak">'
                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'                       .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
Line 8336  sub initialize_categories { Line 9541  sub initialize_categories {
                   .'<select name="addcategory_pos"'.$chgstr.'>'                    .'<select name="addcategory_pos"'.$chgstr.'>'
                   .'<option value="0">1</option>'                    .'<option value="0">1</option>'
                   .'<option value="1">2</option>'                    .'<option value="1">2</option>'
                   .'<option value="2" selected="selected">3</option></select>&nbsp;'                    .'<option value="2">3</option>'
                   .&mt('Add category').'</td><td>'.&mt('Name:')                    .'<option value="3" selected="selected">4</option></select>&nbsp;'
                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';                    .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
                     .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></span>'
                     .'</td></tr>';
     return $datatable;      return $datatable;
 }  }
   
Line 8393  sub build_category_rows { Line 9600  sub build_category_rows {
                             pop(@{$path});                              pop(@{$path});
                         }                          }
                     } else {                      } else {
                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';                          $text .= &mt('Add subcategory:').'&nbsp;</span><input type="text" size="20" name="addcategory_name_';
                         if ($j == $numchildren) {                          if ($j == $numchildren) {
                             $text .= $name;                              $text .= $name;
                         } else {                          } else {
Line 8416  sub build_category_rows { Line 9623  sub build_category_rows {
                 my $colspan;                  my $colspan;
                 if ($parent ne 'instcode') {                  if ($parent ne 'instcode') {
                     $colspan = $maxdepth - $depth - 1;                      $colspan = $maxdepth - $depth - 1;
                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';                      $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
                 }                  }
             }              }
         }          }
Line 8426  sub build_category_rows { Line 9633  sub build_category_rows {
   
 sub modifiable_userdata_row {  sub modifiable_userdata_row {
     my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,      my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
         $rowid,$customcss,$rowstyle) = @_;          $rowid,$customcss,$rowstyle,$itemdesc) = @_;
     my ($role,$rolename,$statustype);      my ($role,$rolename,$statustype);
     $role = $item;      $role = $item;
     if ($context eq 'cancreate') {      if ($context eq 'cancreate') {
Line 8447  sub modifiable_userdata_row { Line 9654  sub modifiable_userdata_row {
         } else {          } else {
             $rolename = $role;              $rolename = $role;
         }          }
       } elsif ($context eq 'lti') {
           $rolename = &mt('Institutional data used (if available)');
       } elsif ($context eq 'privacy') {
           $rolename = $itemdesc;
     } else {      } else {
         if ($role eq 'cr') {          if ($role eq 'cr') {
             $rolename = &mt('Custom role');              $rolename = &mt('Custom role');
Line 8489  sub modifiable_userdata_row { Line 9700  sub modifiable_userdata_row {
               '<td class="LC_left_item" colspan="2"><table>';                '<td class="LC_left_item" colspan="2"><table>';
     my $rem;      my $rem;
     my %checks;      my %checks;
       my %current;
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
         if (ref($settings->{$context}) eq 'HASH') {          my $hashref;
           if ($context eq 'lti') {
               if (ref($settings) eq 'HASH') {
                   $hashref = $settings->{'instdata'};
               }
           } elsif ($context eq 'privacy') {
               my ($key,$inner) = split(/_/,$role);
               if (ref($settings) eq 'HASH') {
                   if (ref($settings->{$key}) eq 'HASH') {
                       $hashref = $settings->{$key}->{$inner};
                   }
               }
           } elsif (ref($settings->{$context}) eq 'HASH') {
             if (ref($settings->{$context}->{$role}) eq 'HASH') {              if (ref($settings->{$context}->{$role}) eq 'HASH') {
                 my $hashref = $settings->{$context}->{$role};                  $hashref = $settings->{'lti_instdata'};
                 if ($role eq 'emailusername') {              }
                     if ($statustype) {              if ($role eq 'emailusername') {
                         if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {                  if ($statustype) {
                             $hashref = $settings->{$context}->{$role}->{$statustype};                      if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
                             if (ref($hashref) eq 'HASH') {                           $hashref = $settings->{$context}->{$role}->{$statustype};
                                 foreach my $field (@fields) {  
                                     if ($hashref->{$field}) {  
                                         $checks{$field} = $hashref->{$field};  
                                     }  
                                 }  
                             }  
                         }  
                     }                      }
                 } else {                  }
                     if (ref($hashref) eq 'HASH') {              }
                         foreach my $field (@fields) {          }
                             if ($hashref->{$field}) {          if (ref($hashref) eq 'HASH') { 
                                 $checks{$field} = ' checked="checked" ';              foreach my $field (@fields) {
                             }                  if ($hashref->{$field}) {
                         }                      if ($role eq 'emailusername') {
                           $checks{$field} = $hashref->{$field};
                       } else {
                           $checks{$field} = ' checked="checked" ';
                     }                      }
                 }                  }
             }              }
Line 8531  sub modifiable_userdata_row { Line 9751  sub modifiable_userdata_row {
         my $check = ' ';          my $check = ' ';
         unless ($role eq 'emailusername') {          unless ($role eq 'emailusername') {
             if (exists($checks{$fields[$i]})) {              if (exists($checks{$fields[$i]})) {
                 $check = $checks{$fields[$i]}                  $check = $checks{$fields[$i]};
             } else {              } elsif ($context eq 'privacy') {
                   if ($role =~ /^priv_(domain|course)$/) {
                       if (ref($settings) ne 'HASH') {
                           $check = ' checked="checked" ';
                       }
                   } elsif ($role =~ /^priv_(author|community)$/) {
                       if (ref($settings) ne 'HASH') {
                           unless ($fields[$i] eq 'id') {
                               $check = ' checked="checked" ';
                           }
                       }
                   } elsif ($role =~ /^(unpriv|othdom)_/) {
                       if (ref($settings) ne 'HASH') {
                           if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
                               $check = ' checked="checked" ';
                           }
                       }
                   }
               } elsif ($context ne 'lti') {
                 if ($role eq 'st') {                  if ($role eq 'st') {
                     if (ref($settings) ne 'HASH') {                      if (ref($settings) ne 'HASH') {
                         $check = ' checked="checked" ';                           $check = ' checked="checked" '; 
Line 8542  sub modifiable_userdata_row { Line 9780  sub modifiable_userdata_row {
         }          }
         $output .= '<td class="LC_left_item">'.          $output .= '<td class="LC_left_item">'.
                    '<span class="LC_nobreak">';                     '<span class="LC_nobreak">';
           my $prefix = 'canmodify';
         if ($role eq 'emailusername') {          if ($role eq 'emailusername') {
             unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {              unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
                 $checks{$fields[$i]} = 'omit';                  $checks{$fields[$i]} = 'omit';
Line 8552  sub modifiable_userdata_row { Line 9791  sub modifiable_userdata_row {
                     $checked='checked="checked" ';                      $checked='checked="checked" ';
                 }                  }
                 $output .= '<label>'.                  $output .= '<label>'.
                            '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.                             '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
                            &mt($option).'</label>'.('&nbsp;' x2);                             &mt($option).'</label>'.('&nbsp;' x2);
             }              }
             $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';              $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
         } else {          } else {
               if ($context eq 'lti') {
                   $prefix = 'lti';
               } elsif ($context eq 'privacy') {
                   $prefix = 'privacy';
               }
             $output .= '<label>'.              $output .= '<label>'.
                        '<input type="checkbox" name="canmodify_'.$role.'" '.                         '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
                        'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.                         'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                        '</label>';                         '</label>';
         }          }
Line 8660  sub insttypes_row { Line 9904  sub insttypes_row {
         }          }
         $output .= '&nbsp;';            $output .= '&nbsp;';  
     } else {      } else {
         if (($rem == 0) && (@{$types} > 0)) {          if ($rem == 0) {
             $output .= '<tr>';              $output .= '<tr>';
         }          }
         if ($colsleft > 1) {          if ($colsleft > 1) {
Line 9643  sub check_configuser { Line 10887  sub check_configuser {
     my ($configuserok,%currroles);      my ($configuserok,%currroles);
     if ($uhome eq 'no_host') {      if ($uhome eq 'no_host') {
         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.          srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
         my $configpass = &LONCAPA::Enrollment::create_password();          my $configpass = &LONCAPA::Enrollment::create_password($dom);
         $configuserok =           $configuserok = 
             &Apache::lonnet::modifyuser($dom,$confname,'','internal',              &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                              $configpass,'','','','','',undef,$servadm);                               $configpass,'','','','','',undef,$servadm);
Line 9968  sub modify_quotas { Line 11212  sub modify_quotas {
         $context = $action;          $context = $action;
     }      }
     if ($context eq 'requestcourses') {      if ($context eq 'requestcourses') {
         @usertools = ('official','unofficial','community','textbook','placement');          @usertools = ('official','unofficial','community','textbook','placement','lti');
         @options =('norequest','approval','validate','autolimit');          @options =('norequest','approval','validate','autolimit');
         %validations = &Apache::lonnet::auto_courserequest_checks($dom);          %validations = &Apache::lonnet::auto_courserequest_checks($dom);
         %titles = &courserequest_titles();          %titles = &courserequest_titles();
Line 10017  sub modify_quotas { Line 11261  sub modify_quotas {
         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');          my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
         @approvalnotify = sort(@approvalnotify);          @approvalnotify = sort(@approvalnotify);
         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);          $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
         my @crstypes = ('official','unofficial','community','textbook','placement');          my @crstypes = ('official','unofficial','community','textbook','placement','lti');
         my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');          my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
         foreach my $type (@hasuniquecode) {          foreach my $type (@hasuniquecode) {
             if (grep(/^\Q$type\E$/,@crstypes)) {              if (grep(/^\Q$type\E$/,@crstypes)) {
Line 10939  sub modify_ltitools { Line 12183  sub modify_ltitools {
                         if ($env{'form.ltitools_'.$extra.'_'.$i}) {                          if ($env{'form.ltitools_'.$extra.'_'.$i}) {
                             $confhash{$itemid}{$extra} = 1;                              $confhash{$itemid}{$extra} = 1;
                             if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {                              if ($env{'form.ltitools_'.$extra.'valid_'.$i} ne '') {
                                 my $lifetime = $env{'form.ltitools_'.$extra.'valid_add'};                                  my $lifetime = $env{'form.ltitools_'.$extra.'valid_'.$i};
                                 $lifetime =~ s/^\s+|\s+$//g;                                  $lifetime =~ s/^\s+|\s+$//g;
                                 if ($lifetime =~ /^\d+\.?\d*$/) {                                  if ($lifetime =~ /^\d+\.?\d*$/) {
                                     $confhash{$itemid}{$extra.'valid'} = $lifetime;                                      $confhash{$itemid}{$extra.'valid'} = $lifetime;
Line 11361  sub modify_lti { Line 12605  sub modify_lti {
                                textbook   => 'Textbook',                                 textbook   => 'Textbook',
                                placement  => 'Placement Test',                                 placement  => 'Placement Test',
     );      );
       my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
     my %lt = &lti_names();      my %lt = &lti_names();
     map { $posslti{$_} = 1; } @ltiroles;      map { $posslti{$_} = 1; } @ltiroles;
     map { $posslticrs{$_} = 1; } @lticourseroles;      map { $posslticrs{$_} = 1; } @lticourseroles;
     map { $posscrstype{$_} = 1; } @coursetypes;      map { $posscrstype{$_} = 1; } @coursetypes;
       
       my %menutitles = &ltimenu_titles();
   
     my (@items,%deletions,%itemids);      my (@items,%deletions,%itemids);
     if ($env{'form.lti_add'}) {      if ($env{'form.lti_add'}) {
         my $consumer = $env{'form.lti_consumer_add'};          my $consumer = $env{'form.lti_consumer_add'};
Line 11407  sub modify_lti { Line 12654  sub modify_lti {
         if ($position ne '') {          if ($position ne '') {
             $allpos[$position] = $itemid;              $allpos[$position] = $itemid;
         }          }
         foreach my $item ('consumer','key','secret','lifetime') {          foreach my $item ('consumer','key','secret','lifetime','requser') {
             my $formitem = 'form.lti_'.$item.'_'.$idx;              my $formitem = 'form.lti_'.$item.'_'.$idx;
             $env{$formitem} =~ s/(`)/'/g;              $env{$formitem} =~ s/(`)/'/g;
             if ($item eq 'lifetime') {              if ($item eq 'lifetime') {
Line 11429  sub modify_lti { Line 12676  sub modify_lti {
         if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {          if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
             $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};              $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
         }          }
         if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {          if ($confhash{$itemid}{'requser'}) {
             $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';               if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
         } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {                  $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid'; 
             $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';              } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
         } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {                  $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
             my $mapuser = $env{'form.lti_customuser_'.$idx};              } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
             $mapuser =~ s/(`)/'/g;                  my $mapuser = $env{'form.lti_customuser_'.$idx};
             $mapuser =~ s/^\s+|\s+$//g;                   $mapuser =~ s/(`)/'/g;
             $confhash{$itemid}{'mapuser'} = $mapuser;                   $mapuser =~ s/^\s+|\s+$//g; 
         }                  $confhash{$itemid}{'mapuser'} = $mapuser; 
         foreach my $ltirole (@lticourseroles) {              }
             my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};              foreach my $ltirole (@lticourseroles) {
             if (grep(/^\Q$possrole\E$/,@courseroles)) {                  my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
                 $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;                  if (grep(/^\Q$possrole\E$/,@courseroles)) {
             }                      $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
         }                  }
         my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);              }
         my @makeuser;              my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
         foreach my $ltirole (sort(@possmakeuser)) {              my @makeuser;
             if ($posslti{$ltirole}) {              foreach my $ltirole (sort(@possmakeuser)) {
                 push(@makeuser,$ltirole);                  if ($posslti{$ltirole}) {
             }                      push(@makeuser,$ltirole);
         }                  }
         $confhash{$itemid}{'makeuser'} = \@makeuser;              }
         if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||              $confhash{$itemid}{'makeuser'} = \@makeuser;
             ($env{'form.lti_mapcrs_'.$idx} eq 'context_id'))  {              if (@makeuser) {
             $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};                  my $lcauth = $env{'form.lti_lcauth_'.$idx};
         } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {                  if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
             my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};                       $confhash{$itemid}{'lcauth'} = $lcauth;
             $mapcrs =~ s/(`)/'/g;                      if ($lcauth ne 'internal') {
             $mapcrs =~ s/^\s+|\s+$//g;                          my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
             $confhash{$itemid}{'mapcrs'} = $mapcrs;                          $lcauthparm =~ s/^(\s+|\s+)$//g;
         }                          $lcauthparm =~ s/`//g;
         my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);                          if ($lcauthparm ne '') {
         my @crstypes;                              $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
         foreach my $type (sort(@posstypes)) {                          }
             if ($posscrstype{$type}) {                      }
                 push(@crstypes,$type);                  } else {
                       $confhash{$itemid}{'lcauth'} = 'lti';
                   }
             }              }
         }              my @possinstdata =  &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
         $confhash{$itemid}{'mapcrstype'} = \@crstypes;              if (@possinstdata) {
         if ($env{'form.lti_makecrs_'.$idx}) {                  foreach my $field (@possinstdata) {
             $confhash{$itemid}{'makecrs'} = 1;                      if (exists($fieldtitles{$field})) {
         }                          push(@{$confhash{$itemid}{'instdata'}});
         my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);                      }
         my @selfenroll;                  }
         foreach my $type (sort(@possenroll)) {  
             if ($posslticrs{$type}) {  
                 push(@selfenroll,$type);  
             }              }
         }              if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
         $confhash{$itemid}{'selfenroll'} = \@selfenroll;                  ($env{'form.lti_mapcrs_'.$idx} eq 'context_id'))  {
         if ($env{'form.lti_crssec_'.$idx}) {                  $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
             if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {              } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
                 $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};                  my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx}; 
             } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {                  $mapcrs =~ s/(`)/'/g;
                 my $section = $env{'form.lti_customsection_'.$idx};                  $mapcrs =~ s/^\s+|\s+$//g;
                 $section =~ s/(`)/'/g;                  $confhash{$itemid}{'mapcrs'} = $mapcrs;
                 $section =~ s/^\s+|\s+$//g;              }
                 if ($section ne '') {              my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
                     $confhash{$itemid}{'section'} = $section;              my @crstypes;
               foreach my $type (sort(@posstypes)) {
                   if ($posscrstype{$type}) {
                       push(@crstypes,$type);
                 }                  }
             }              }
         }              $confhash{$itemid}{'mapcrstype'} = \@crstypes;
         foreach my $field ('passback','roster') {              if ($env{'form.lti_makecrs_'.$idx}) {
             if ($env{'form.lti_'.$field.'_'.$idx}) {                  $confhash{$itemid}{'makecrs'} = 1;
                 $confhash{$itemid}{$field} = 1;  
             }              }
         }              my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
         unless (($idx eq 'add') || ($changes{$itemid})) {              my @selfenroll;
             foreach my $field ('mapuser','mapcrs','section','passback','roster') {              foreach my $type (sort(@possenroll)) {
                 if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {                  if ($posslticrs{$type}) {
                     $changes{$itemid} = 1;                      push(@selfenroll,$type);
                 }                  }
             }              }
             foreach my $field ('makeuser','mapcrstype','selfenroll') {              $confhash{$itemid}{'selfenroll'} = \@selfenroll;
                 unless ($changes{$itemid}) {              if ($env{'form.lti_crssec_'.$idx}) {
                     if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {                  if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
                         if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {                      $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
                             my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},                  } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
                                                                            $confhash{$itemid}{$field});                      my $section = $env{'form.lti_customsection_'.$idx};
                             if (@diffs) {                      $section =~ s/(`)/'/g;
                                 $changes{$itemid} = 1;                      $section =~ s/^\s+|\s+$//g;
                             }                      if ($section ne '') {
                         } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {                          $confhash{$itemid}{'section'} = $section;
                             $changes{$itemid} = 1;                      }
                   }
               }
               if ($env{'form.lti_callback_'.$idx}) {
                   if ($env{'form.lti_callbackparam_'.$idx}) {
                       my $callback = $env{'form.lti_callbackparam_'.$idx};
                       $callback =~ s/^\s+|\s+$//g;
                       $confhash{$itemid}{'callback'} = $callback;
                   }
               }
               foreach my $field ('passback','roster','topmenu','inlinemenu') {
                   if ($env{'form.lti_'.$field.'_'.$idx}) {
                       $confhash{$itemid}{$field} = 1;
                   }
               }
               if ($env{'form.lti_passback_'.$idx}) {
                   if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
                       $confhash{$itemid}{'passbackformat'} = '1.0';
                   } else {
                       $confhash{$itemid}{'passbackformat'} = '1.1';
                   }
               }
               if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
                   $confhash{$itemid}{lcmenu} = [];
                   my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
                   foreach my $field (@possmenu) {
                       if (exists($menutitles{$field})) {
                           if ($field eq 'grades') {
                               next unless ($env{'form.lti_inlinemenu_'.$idx});
                         }                          }
                     } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {                          push(@{$confhash{$itemid}{lcmenu}},$field);
                         if (@{$confhash{$itemid}{$field}} > 0) {                      }
                   }
               }
               unless (($idx eq 'add') || ($changes{$itemid})) {
                   foreach my $field ('mapuser','mapcrs','makecrs','section','passback','roster','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
                       if ($domconfig{$action}{$itemid}{$field} ne $confhash{$itemid}{$field}) {
                           $changes{$itemid} = 1;
                       }
                   }
                   unless ($changes{$itemid}) {
                       if ($domconfig{$action}{$itemid}{'passback'} eq $confhash{$itemid}{'passback'}) {
                           if ($domconfig{$action}{$itemid}{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
                             $changes{$itemid} = 1;                              $changes{$itemid} = 1;
                         }                          }
                     }                       }
                 }                  }
             }                  foreach my $field ('makeuser','mapcrstype','selfenroll','instdata','lcmenu') {
             unless ($changes{$itemid}) {                      unless ($changes{$itemid}) {
                 if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {                          if (ref($domconfig{$action}{$itemid}{$field}) eq 'ARRAY') {
                     if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {                              if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                         foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {                                  my @diffs = &Apache::loncommon::compare_arrays($domconfig{$action}{$itemid}{$field},
                             if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne                                                                                  $confhash{$itemid}{$field});
                                 $confhash{$itemid}{'maproles'}{$ltirole}) {                                  if (@diffs) {
                                       $changes{$itemid} = 1;
                                   }
                               } elsif (@{$domconfig{$action}{$itemid}{$field}} > 0) {
                                   $changes{$itemid} = 1;
                               }
                           } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
                               if (@{$confhash{$itemid}{$field}} > 0) {
                                 $changes{$itemid} = 1;                                  $changes{$itemid} = 1;
                                 last;  
                             }                              }
                         }                          }
                         unless ($changes{$itemid}) {                      }
                             foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {                  }
                                 if ($confhash{$itemid}{'maproles'}{$ltirole} ne                   unless ($changes{$itemid}) {
                                     $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {                      if (ref($domconfig{$action}{$itemid}{'maproles'}) eq 'HASH') {
                           if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                               foreach my $ltirole (keys(%{$domconfig{$action}{$itemid}{'maproles'}})) {
                                   if ($domconfig{$action}{$itemid}{'maproles'}{$ltirole} ne 
                                       $confhash{$itemid}{'maproles'}{$ltirole}) {
                                     $changes{$itemid} = 1;                                      $changes{$itemid} = 1;
                                     last;                                      last;
                                 }                                  }
                             }                              }
                         }                              unless ($changes{$itemid}) {
                     } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {                                  foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
                         $changes{$itemid} = 1;                                      if ($confhash{$itemid}{'maproles'}{$ltirole} ne 
                     }                                          $domconfig{$action}{$itemid}{'maproles'}{$ltirole}) {
                 } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {                                          $changes{$itemid} = 1;
                     unless ($changes{$itemid}) {                                          last;
                         if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {                                      }
                                   }
                               }
                           } elsif (keys(%{$domconfig{$action}{$itemid}{'maproles'}}) > 0) {
                             $changes{$itemid} = 1;                              $changes{$itemid} = 1;
                         }                          }
                       } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                           unless ($changes{$itemid}) {
                               if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
                                   $changes{$itemid} = 1;
                               }
                           }
                     }                      }
                 }                  }
             }              }
Line 11622  sub modify_lti { Line 12928  sub modify_lti {
                         my $num = length($encconfig{$itemid}{'secret'});                          my $num = length($encconfig{$itemid}{'secret'});
                         $resulttext .= ('*'x$num).'</li>';                          $resulttext .= ('*'x$num).'</li>';
                     }                      }
                     if ($confhash{$itemid}{'mapuser'}) {                      if ($confhash{$itemid}{'requser'}) {
                         my $shownmapuser;                          if ($confhash{$itemid}{'mapuser'}) {
                         if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {                              my $shownmapuser;
                             $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';                              if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
                         } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {                                  $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
                             $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';                              } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
                         } else {                                  $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
                             $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';                              } else {
                         }                                   $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
                         $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';  
                     }  
                     if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {  
                         my $rolemaps;  
                         foreach my $role (@ltiroles) {  
                             if ($confhash{$itemid}{'maproles'}{$role}) {  
                                 $rolemaps .= ('&nbsp;'x2).$role.'='.  
                                              &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},  
                                                                         'Course').',';  
                             }                              }
                               $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
                         }                          }
                         if ($rolemaps) {                          if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
                             $rolemaps =~ s/,$//;                              my $rolemaps;
                             $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';                              foreach my $role (@ltiroles) {
                                   if ($confhash{$itemid}{'maproles'}{$role}) {
                                       $rolemaps .= ('&nbsp;'x2).$role.'='.
                                                    &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
                                                                               'Course').',';
                                   }
                               }
                               if ($rolemaps) {
                                   $rolemaps =~ s/,$//;
                                   $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
                               }
                           }
                           if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
                               if (@{$confhash{$itemid}{'makeuser'}} > 0) { 
                                   $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
                                                             join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
                                   if ($confhash{$itemid}{'lcauth'} eq 'lti') {
                                       $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
                                   } else {
                                       $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
                                                          $confhash{$itemid}{'lcauth'});
                                       if ($confhash{$itemid}{'lcauth'} eq 'internal') {
                                           $resulttext .= '; '.&mt('a randomly generated password will be created');
                                       } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
                                           if ($confhash{$itemid}{'lcauthparm'} ne '') {
                                               $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
                                           }
                                       } else {
                                           $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
                                       }
                                   }
                                   $resulttext .= '</li>';
                               } else {
                                   $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
                               }
                         }                          }
                     }                          if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
                     if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {                              if (@{$confhash{$itemid}{'instdata'}} > 0) {
                         if (@{$confhash{$itemid}{'makeuser'}} > 0) {                                   $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
                             $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',                                                            join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
                                                       join(', ',@{$confhash{$itemid}{'makeuser'}})).'</li>';                              } else {
                         } else {                                  $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
                             $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';                              }
                         }                          }
                     }                          if ($confhash{$itemid}{'mapcrs'}) {
                     if ($confhash{$itemid}{'mapcrs'}) {                              $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
                         $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';  
                     }  
                     if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {  
                         if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {  
                             $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',  
                                            join(', ',map { $coursetypetitles{$_}; } @coursetypes)).  
                                            '</li>';  
                         } else {  
                             $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';  
                         }                          }
                     }                          if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
                     if ($confhash{$itemid}{'makecrs'}) {                              if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
                         $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';                                  $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
                     } else {                                                 join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
                         $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';                                                 '</li>';
                     }                              } else {
                     if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {                                  $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
                         if (@{$confhash{$itemid}{'selfenroll'}} > 0) {                              }
                             $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',                          }
                                                       join(', ',@{$confhash{$itemid}{'selfenroll'}})).                          if ($confhash{$itemid}{'makecrs'}) {
                                            '</li>';                              $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
                         } else {                          } else {
                             $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';                              $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
                         }                          }
                     }                          if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
                     if ($confhash{$itemid}{'section'}) {                              if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
                         if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {                                  $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
                             $resulttext .= '<li>'.&mt('User section from standard field:').                                                            join(', ',@{$confhash{$itemid}{'selfenroll'}})).
                                                  ' (course_section_sourcedid)'.'</li>';                                                   '</li>';
                               } else {
                                   $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
                               }
                           }
                           if ($confhash{$itemid}{'section'}) {
                               if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
                                   $resulttext .= '<li>'.&mt('User section from standard field:').
                                                        ' (course_section_sourcedid)'.'</li>';  
                               } else {
                                   $resulttext .= '<li>'.&mt('User section from:').' '.
                                                         $confhash{$itemid}{'section'}.'</li>';
                               }
                         } else {                          } else {
                             $resulttext .= '<li>'.&mt('User section from:').' '.                              $resulttext .= '<li>'.&mt('No section assignment').'</li>';
                                                   $confhash{$itemid}{'section'}.'</li>';  
                         }                          }
                     } else {                          if ($confhash{$itemid}{'callback'}) {
                         $resulttext .= '<li>'.&mt('No section assignment').'</li>';                              $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
                     }  
                     foreach my $item ('passback','roster') {  
                         $resulttext .= '<li>'.$lt{$item}.'&nbsp;';  
                         if ($confhash{$itemid}{$item}) {  
                             $resulttext .= &mt('Yes');  
                         } else {                          } else {
                             $resulttext .= &mt('No');                              $resulttext .= '<li>'.&mt('No callback to logout LON-CAPA session when user logs out of Comsumer');
                           }
                           foreach my $item ('passback','roster','topmenu','inlinemenu') {
                               $resulttext .= '<li>'.$lt{$item}.':&nbsp;';
                               if ($confhash{$itemid}{$item}) {
                                   $resulttext .= &mt('Yes');
                                   if ($item eq 'passback') {
                                       if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
                                           $resulttext .= '&nbsp;('.&mt('Outcomes Extension (1.0)').')';
                                       } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
                                           $resulttext .= '&nbsp;('.&mt('Outcomes Service (1.1)').')';
                                       }
                                   }
                               } else {
                                   $resulttext .= &mt('No');
                               }
                               $resulttext .= '</li>';
                           }
                           if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
                               if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
                                   $resulttext .= '<li>'.&mt('Menu items:').' '.
                                                  join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>'; 
                               } else {
                                   $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>'; 
                               }
                         }                          }
                         $resulttext .= '</li>';  
                     }                      }
                     $resulttext .= '</ul></li>';                      $resulttext .= '</ul></li>';
                 }                  }
Line 12346  sub modify_contacts { Line 13698  sub modify_contacts {
     my (%others,%to,%bcc,%includestr,%includeloc);      my (%others,%to,%bcc,%includestr,%includeloc);
     my @contacts = ('supportemail','adminemail');      my @contacts = ('supportemail','adminemail');
     my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',      my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
                     'lonstatusmail','requestsmail','updatesmail','idconflictsmail');                      'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
     my @toggles = ('reporterrors','reportupdates');      my @toggles = ('reporterrors','reportupdates','reportstatus');
       my @lonstatus = ('threshold','sysmail','weights','excluded');
     my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();      my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
     foreach my $type (@mailings) {      foreach my $type (@mailings) {
         @{$newsetting{$type}} =           @{$newsetting{$type}} = 
Line 12380  sub modify_contacts { Line 13733  sub modify_contacts {
             $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};              $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
         }          }
     }      }
       my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
       foreach my $item (@lonstatus) {
           if ($item eq 'excluded') {
               my (%serverhomes,@excluded);
               map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
               my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
               if (@possexcluded) {
                   foreach my $id (sort(@possexcluded)) {
                       if ($serverhomes{$id}) {
                           push(@excluded,$id);
                       }
                   }
               }
               if (@excluded) {
                   $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
               }
           } elsif ($item eq 'weights') {
               foreach my $type ('E','W','N') {
                   $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
                   if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
                       unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
                           $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
                               $env{'form.error'.$item.'_'.$type};
                       }
                   }
               }
           } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
               $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
               if ($env{'form.error'.$item} =~ /^\d+$/) {
                   unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
                       $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
                   }
               }
           }
       }
     if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {      if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
         foreach my $field (@{$fields}) {          foreach my $field (@{$fields}) {
             if (ref($possoptions->{$field}) eq 'ARRAY') {              if (ref($possoptions->{$field}) eq 'ARRAY') {
Line 12518  sub modify_contacts { Line 13906  sub modify_contacts {
                 }                  }
             }              }
         }          }
           if (ref($currsetting{'lonstatus'}) eq 'HASH') {
               foreach my $key ('excluded','weights','threshold','sysmail') {
                   if ($key eq 'excluded') {
                       if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                           (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
                           if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                               (@{$currsetting{'lonstatus'}{$key}})) {
                               my @diffs =
                                   &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
                                                                      $currsetting{'lonstatus'}{$key});
                               if (@diffs) {
                                   push(@{$changes{'lonstatus'}},$key);
                               }
                           } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
                               push(@{$changes{'lonstatus'}},$key);
                           }
                       } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
                                (@{$currsetting{'lonstatus'}{$key}})) {
                           push(@{$changes{'lonstatus'}},$key);
                       }
                   } elsif ($key eq 'weights') {
                       if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
                           (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
                           if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
                               foreach my $type ('E','W','N','U') {
                                   unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
                                           $currsetting{'lonstatus'}{$key}{$type}) {
                                       push(@{$changes{'lonstatus'}},$key);
                                       last;
                                   }
                               }
                           } else {
                               foreach my $type ('E','W','N','U') {
                                   if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
                                       push(@{$changes{'lonstatus'}},$key);
                                       last;
                                   }
                               }
                           }
                       } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
                           foreach my $type ('E','W','N','U') {
                               if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
                                   push(@{$changes{'lonstatus'}},$key);
                                   last;
                               }
                           }
                       }
                   } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
                       if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                           if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                               if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
                                   push(@{$changes{'lonstatus'}},$key);
                               }
                           } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
                               push(@{$changes{'lonstatus'}},$key);
                           }
                       } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
                           push(@{$changes{'lonstatus'}},$key);
                       }
                   }
               }
           } else {
               if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
                   foreach my $key ('excluded','weights','threshold','sysmail') {
                       if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                           push(@{$changes{'lonstatus'}},$key);
                       }
                   }
               }
           }
     } else {      } else {
         my %default;          my %default;
         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};          $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
Line 12529  sub modify_contacts { Line 13987  sub modify_contacts {
         $default{'lonstatusmail'} = 'adminemail';          $default{'lonstatusmail'} = 'adminemail';
         $default{'requestsmail'} = 'adminemail';          $default{'requestsmail'} = 'adminemail';
         $default{'updatesmail'} = 'adminemail';          $default{'updatesmail'} = 'adminemail';
           $default{'hostipmail'} = 'adminemail';
         foreach my $item (@contacts) {          foreach my $item (@contacts) {
            if ($to{$item} ne $default{$item}) {             if ($to{$item} ne $default{$item}) {
                $changes{$item} = 1;                 $changes{$item} = 1;
Line 12562  sub modify_contacts { Line 14021  sub modify_contacts {
                 }                  }
             }              }
         }          }
           if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
               foreach my $key ('excluded','weights','threshold','sysmail') {
                   if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
                       push(@{$changes{'lonstatus'}},$key);
                   }
               }
           }
     }      }
     foreach my $item (@toggles) {      foreach my $item (@toggles) {
         if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {          if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
Line 12687  sub modify_contacts { Line 14153  sub modify_contacts {
                 }                  }
             }              }
             my @offon = ('off','on');              my @offon = ('off','on');
               my $corelink = &core_link_msu();
             if ($changes{'reporterrors'}) {              if ($changes{'reporterrors'}) {
                 $resulttext .= '<li>'.                  $resulttext .= '<li>'.
                                &mt('E-mail error reports to [_1] set to "'.                                 &mt('E-mail error reports to [_1] set to "'.
                                    $offon[$env{'form.reporterrors'}].'".',                                     $offon[$env{'form.reporterrors'}].'".',
                                    &Apache::loncommon::modal_link('http://loncapa.org/core.html',                                     $corelink).
                                        &mt('LON-CAPA core group - MSU'),600,500)).  
                                '</li>';                                 '</li>';
             }              }
             if ($changes{'reportupdates'}) {              if ($changes{'reportupdates'}) {
                 $resulttext .= '<li>'.                  $resulttext .= '<li>'.
                                 &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.                                  &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
                                     $offon[$env{'form.reportupdates'}].'".',                                      $offon[$env{'form.reportupdates'}].'".',
                                     &Apache::loncommon::modal_link('http://loncapa.org/core.html',                                      $corelink).
                                         &mt('LON-CAPA core group - MSU'),600,500)).                                  '</li>';
               }
               if ($changes{'reportstatus'}) {
                   $resulttext .= '<li>'.
                                   &mt('E-mail status if errors above threshold to [_1] set to "'.
                                       $offon[$env{'form.reportstatus'}].'".',
                                       $corelink).
                                 '</li>';                                  '</li>';
             }              }
               if (ref($changes{'lonstatus'}) eq 'ARRAY') {
                   $resulttext .= '<li>'.
                                  &mt('Nightly status check e-mail settings').':<ul>';
                   my (%defval,%use_def,%shown);
                   $defval{'threshold'} = $lonstatus_defs->{'threshold'};
                   $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
                   $defval{'weights'} =
                       join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
                   $defval{'excluded'} = &mt('None');
                   if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
                       foreach my $item ('threshold','sysmail','weights','excluded') {
                           if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
                               if (($item eq 'threshold') || ($item eq 'sysmail')) {
                                   $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
                               } elsif ($item eq 'weights') {
                                   if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
                                       foreach my $type ('E','W','N','U') {
                                           $shown{$item} .= $lonstatus_names->{$type}.'=';
                                           if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
                                               $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
                                           } else {
                                               $shown{$item} .= $lonstatus_defs->{$type};
                                           }
                                           $shown{$item} .= ', ';
                                       }
                                       $shown{$item} =~ s/, $//;
                                   } else {
                                       $shown{$item} = $defval{$item};
                                   }
                               } elsif ($item eq 'excluded') {
                                   if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
                                       $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
                                   } else {
                                       $shown{$item} = $defval{$item};
                                   }
                               }
                           } else {
                               $shown{$item} = $defval{$item};
                           }
                       }
                   } else {
                       foreach my $item ('threshold','weights','excluded','sysmail') {
                           $shown{$item} = $defval{$item};
                       }
                   }
                   foreach my $item ('threshold','weights','excluded','sysmail') {
                       $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
                                             $shown{$item}).'</li>';
                   }
                   $resulttext .= '</ul></li>';
               }
             if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {              if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
                 my (@optional,@required,@unused,$maxsizechg);                  my (@optional,@required,@unused,$maxsizechg);
                 foreach my $field (@{$changes{'helpform'}}) {                  foreach my $field (@{$changes{'helpform'}}) {
Line 12754  sub modify_contacts { Line 14277  sub modify_contacts {
     return $resulttext;      return $resulttext;
 }  }
   
   sub modify_privacy {
       my ($dom,%domconfig) = @_;
       my ($resulttext,%current,%changes);
       if (ref($domconfig{'privacy'}) eq 'HASH') {
           %current = %{$domconfig{'privacy'}};
       }
       my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
       my @items = ('domain','author','course','community');
       my %names = &Apache::lonlocal::texthash (
                      domain => 'Assigned domain role(s)',
                      author => 'Assigned co-author role(s)',
                      course => 'Assigned course role(s)',
                      community => 'Assigned community role',
                   );
       my %roles = &Apache::lonlocal::texthash (
                      domain => 'Domain role',
                      author => 'Co-author role',
                      course => 'Course role',
                      community => 'Community role',
                   );
       my %titles = &Apache::lonlocal::texthash (
                     approval => 'Approval for role in different domain',
                     othdom   => 'User information available in other domain',
                     priv     => 'Information viewable by privileged user in same domain',
                     unpriv   => 'Information viewable by unprivileged user in same domain',
                     instdom  => 'Other domain shares institution/provider',
                     extdom   => 'Other domain has different institution/provider',
                     none     => 'Not allowed',
                     user     => 'User authorizes',
                     domain   => 'Domain Coordinator authorizes',
                     auto     => 'Unrestricted',
       );
       my %fieldnames = &Apache::lonlocal::texthash (
                           id => 'Student/Employee ID',
                           permanentemail => 'E-mail address',
                           lastname => 'Last Name',
                           firstname => 'First Name',
                           middlename => 'Middle Name',
                           generation => 'Generation',
       );
       my ($othertitle,$usertypes,$types) =
           &Apache::loncommon::sorted_inst_types($dom);
       my (%by_ip,%by_location,@intdoms,@instdoms);
       &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
   
       my %privacyhash = (
                          'approval' => {
                                          instdom => {},
                                          extdom  => {},
                                        },
                          'othdom'   => {},
                          'priv'     => {},
                          'unpriv'   => {},
                         );
       foreach my $item (@items) {
           if (@instdoms > 1) {
               if ($env{'form.privacy_approval_instdom'.$item} =~ /^(none|user|domain|auto)$/) {
                   $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
               }
               if (ref($current{'approval'}) eq 'HASH') {
                   if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
                       unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
                           $changes{'approval'} = 1;
                       }
                   }
               } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
                   $changes{'approval'} = 1;
               }
           }
           if (keys(%by_location) > 0) {
               if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
                   $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
               }
               if (ref($current{'approval'}) eq 'HASH') {
                   if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
                       unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
                           $changes{'approval'} = 1;
                       }
                   }
               } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
                   $changes{'approval'} = 1;
               }
           }
           foreach my $status ('priv','unpriv') {
               my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
               my @newvalues;
               foreach my $field (@possibles) {
                   if (grep(/^\Q$field\E$/,@fields)) {
                       $privacyhash{$status}{$item}{$field} = 1;
                       push(@newvalues,$field);
                   }
               }
               @newvalues = sort(@newvalues);
               if (ref($current{$status}) eq 'HASH') {
                   if (ref($current{$status}{$item}) eq 'HASH') {
                       my @currvalues = sort(keys(%{$current{$status}{$item}}));
                       my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                       if (@diffs > 0) {
                           $changes{$status} = 1;
                       }
                   }
               } else {
                   my @stdfields;
                   foreach my $field (@fields) {
                       if ($field eq 'id') {
                           next if ($status eq 'unpriv');
                           next if (($status eq 'priv') && ($item eq 'community'));
                       }
                       push(@stdfields,$field);
                   }
                   my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   if (@diffs > 0) {
                       $changes{$status} = 1;
                   }
               }
           }
       }
       if ((@instdoms > 1) || (keys(%by_location) > 0)) {
           my @statuses;
           if (ref($types) eq 'ARRAY') {
               @statuses = @{$types};
           }
           foreach my $type (@statuses,'default') {
               my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
               my @newvalues;
               foreach my $field (sort(@possfields)) {
                   if (grep(/^\Q$field\E$/,@fields)) {
                       $privacyhash{'othdom'}{$type}{$field} = 1;
                       push(@newvalues,$field);
                   }
               }
               @newvalues = sort(@newvalues);
               if (ref($current{'othdom'}) eq 'HASH') {
                   if (ref($current{'othdom'}{$type}) eq 'HASH') {
                       my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
                       my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
                       if (@diffs > 0) {
                           $changes{'othdom'} = 1;
                       }
                   }
               } else {
                   my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
                   my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
                   if (@diffs > 0) {
                       $changes{'othdom'} = 1;
                   }
               }
           }
       }
       my %confighash = (
                           privacy => \%privacyhash,
                        );
       my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
       if ($putresult eq 'ok') {
           if (keys(%changes) > 0) {
               $resulttext = &mt('Changes made: ').'<ul>';
               foreach my $key ('approval','othdom','priv','unpriv') {
                   if ($changes{$key}) {
                       $resulttext .= '<li>'.$titles{$key}.':<ul>';
                       if ($key eq 'approval') {
                           if (keys(%{$privacyhash{$key}{instdom}})) {
                               $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
                               foreach my $item (@items) {
                                   $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
                               }
                               $resulttext .= '</ul></li>';
                           }
                           if (keys(%{$privacyhash{$key}{extdom}})) {
                               $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
                               foreach my $item (@items) {
                                   $resulttext .=  '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
                               }
                               $resulttext .= '</ul></li>';
                           }
                       } elsif ($key eq 'othdom') {
                           my @statuses;
                           if (ref($types) eq 'ARRAY') {
                               @statuses = @{$types};
                           }
                           if (ref($privacyhash{$key}) eq 'HASH') {
                               foreach my $status (@statuses,'default') {
                                   if ($status eq 'default') {
                                       $resulttext .= '<li>'.$othertitle.': ';
                                   } elsif (ref($usertypes) eq 'HASH') {
                                       $resulttext .= '<li>'.$usertypes->{$status}.': ';
                                   } else {
                                       next;
                                   }
                                   if (ref($privacyhash{$key}{$status}) eq 'HASH') {
                                       if (keys(%{$privacyhash{$key}{$status}})) {
                                           $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
                                       } else {
                                           $resulttext .= &mt('none');
                                       }
                                   }
                                   $resulttext .= '</li>';
                               }
                           }
                       } else {
                           foreach my $item (@items) {
                               if (ref($privacyhash{$key}{$item}) eq 'HASH') {
                                   $resulttext .= '<li>'.$names{$item}.': ';
                                   if (keys(%{$privacyhash{$key}{$item}})) {
                                       $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
                                   } else {
                                       $resulttext .= &mt('none');
                                   }
                                   $resulttext .= '</li>';
                               }
                           }
                       }
                       $resulttext .= '</ul></li>';
                   }
               }
           } else {
               $resulttext = &mt('No changes made to user information settings');
           }
       } else {
           $resulttext = '<span class="LC_error">'.
               &mt('An error occurred: [_1]',$putresult).'</span>';
       }
       return $resulttext;
   }
   
   sub modify_passwords {
       my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
       my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
           $updatedefaults,$updateconf);
       my $customfn = 'resetpw.html';
       if (ref($domconfig{'passwords'}) eq 'HASH') {
           %current = %{$domconfig{'passwords'}};
       }
       my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
       my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
       if (ref($types) eq 'ARRAY') {
           @oktypes = @{$types};
       }
       push(@oktypes,'default');
   
       my %titles = &Apache::lonlocal::texthash (
           intauth_cost   => 'Encryption cost for bcrypt (positive integer)',
           intauth_check  => 'Check bcrypt cost if authenticated',
           intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
           permanent      => 'Permanent e-mail address',
           critical       => 'Critical notification address',
           notify         => 'Notification address',
           min            => 'Minimum password length',
           max            => 'Maximum password length',
           chars          => 'Required characters',
           expire         => 'Password expiration (days)',
           numsaved       => 'Number of previous passwords to save',
           reset          => 'Resetting Forgotten Password',
           intauth        => 'Encryption of Stored Passwords (Internal Auth)',
           rules          => 'Rules for LON-CAPA Passwords',
           crsownerchg    => 'Course Owner Changing Student Passwords',
           username       => 'Username',
           email          => 'E-mail address',
       );
   
   #
   # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
   #
       my (%curr_defaults,%save_defaults);
       if (ref($domconfig{'defaults'}) eq 'HASH') {
           foreach my $key (keys(%{$domconfig{'defaults'}})) {
               if ($key =~ /^intauth_(cost|check|switch)$/) {
                   $curr_defaults{$key} = $domconfig{'defaults'}{$key};
               } else {
                   $save_defaults{$key} = $domconfig{'defaults'}{$key};
               }
           }
       }
       my %staticdefaults = (
           'resetlink'      => 2,
           'resetcase'      => \@oktypes,
           'resetprelink'   => 'both',
           'resetemail'     => ['critical','notify','permanent'],
           'intauth_cost'   => 10,
           'intauth_check'  => 0,
           'intauth_switch' => 0,
       );
       $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
       foreach my $type (@oktypes) {
           $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
       }
       my $linklife = $env{'form.passwords_link'};
       $linklife =~ s/^\s+|\s+$//g;
       if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
           $newvalues{'resetlink'} = $linklife;
           if ($current{'resetlink'}) {
               if ($current{'resetlink'} ne $linklife) {
                   $changes{'reset'} = 1;
               }
           } elsif (!ref($domconfig{passwords}) eq 'HASH') {
               if ($staticdefaults{'resetlink'} ne $linklife) {
                   $changes{'reset'} = 1;
               }
           }
       } elsif ($current{'resetlink'}) {
           $changes{'reset'} = 1;
       }
       my @casesens;
       my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
       foreach my $case (sort(@posscase)) {
           if (grep(/^\Q$case\E$/,@oktypes)) {
               push(@casesens,$case);
           }
       }
       $newvalues{'resetcase'} = \@casesens;
       if (ref($current{'resetcase'}) eq 'ARRAY') {
           my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
           if (@diffs > 0) {
               $changes{'reset'} = 1;
           }
       } elsif (!ref($domconfig{passwords}) eq 'HASH') {
           my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
           if (@diffs > 0) {
               $changes{'reset'} = 1;
           }
       }
       if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
           $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
           if (exists($current{'resetprelink'})) {
               if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   $changes{'reset'} = 1;
               }
           } elsif (!ref($domconfig{passwords}) eq 'HASH') {
               if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
                   $changes{'reset'} = 1;
               }
           }
       } elsif ($current{'resetprelink'}) {
           $changes{'reset'} = 1;
       }
       foreach my $type (@oktypes) {
           my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
           my @postlink;
           foreach my $item (sort(@possplink)) {
               if ($item =~ /^(email|username)$/) {
                   push(@postlink,$item);
               }
           }
           $newvalues{'resetpostlink'}{$type} = \@postlink;
           unless ($changes{'reset'}) {
               if (ref($current{'resetpostlink'}) eq 'HASH') {
                   if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
                       my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
                       if (@diffs > 0) {
                           $changes{'reset'} = 1;
                       }
                   } else {
                       $changes{'reset'} = 1;
                   }
               } elsif (!ref($domconfig{passwords}) eq 'HASH') {
                   my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
                   if (@diffs > 0) {
                       $changes{'reset'} = 1;
                   }
               }
           }
       }
       my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
       my @resetemail;
       foreach my $item (sort(@possemailsrc)) {
           if ($item =~ /^(permanent|critical|notify)$/) {
               push(@resetemail,$item);
           }
       }
       $newvalues{'resetemail'} = \@resetemail;
       unless ($changes{'reset'}) {
           if (ref($current{'resetemail'}) eq 'ARRAY') {
               my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
               if (@diffs > 0) {
                   $changes{'reset'} = 1;
               }
           } elsif (!ref($domconfig{passwords}) eq 'HASH') {
               my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
               if (@diffs > 0) {
                   $changes{'reset'} = 1;
               }
           }
       }
       if ($env{'form.passwords_stdtext'} == 0) {
           $newvalues{'resetremove'} = 1;
           unless ($current{'resetremove'}) {
               $changes{'reset'} = 1;
           }
       } elsif ($current{'resetremove'}) {
           $changes{'reset'} = 1;
       }
       if ($env{'form.passwords_customfile.filename'} ne '') {
           my $servadm = $r->dir_config('lonAdmEMail');
           my ($configuserok,$author_ok,$switchserver) =
               &config_check($dom,$confname,$servadm);
           my $error;
           if ($configuserok eq 'ok') {
               if ($switchserver) {
                   $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
               } else {
                   if ($author_ok eq 'ok') {
                       my ($result,$customurl) =
                           &publishlogo($r,'upload','passwords_customfile',$dom,
                                        $confname,'customtext/resetpw','','',$customfn);
                       if ($result eq 'ok') {
                           $newvalues{'resetcustom'} = $customurl;
                           $changes{'reset'} = 1;
                       } else {
                           $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
                       }
                   } else {
                       $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$customfn,$confname,$dom,$author_ok);
                   }
               }
           } else {
               $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$customfn,$confname,$dom,$configuserok);
           }
           if ($error) {
               &Apache::lonnet::logthis($error);
               $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
           }
       } elsif ($current{'resetcustom'}) {
           if ($env{'form.passwords_custom_del'}) {
               $changes{'reset'} = 1;
           } else {
               $newvalues{'resetcustom'} = $current{'resetcustom'};
           }
       }
       $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
       if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
           $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
           if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
               $changes{'intauth'} = 1;
           }
       } else {
           $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
       }
       if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
           $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
           if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
               $changes{'intauth'} = 1;
           }
       } else {
           $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
       }
       if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
           $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
           if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
               $changes{'intauth'} = 1;
           }
       } else {
           $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
       }
       foreach my $item ('cost','check','switch') {
           if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
               $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
               $updatedefaults = 1;
           }
       }
       foreach my $rule ('min','max','expire','numsaved') {
           $env{'form.passwords_'.$rule} =~ s/^\s+|\s+$//g;
           my $ruleok;
           if ($rule eq 'expire') {
               if (($env{'form.passwords_'.$rule} =~ /^\d+(|\.\d*)$/) &&
                   ($env{'form.passwords_'.$rule} ne '0')) {
                   $ruleok = 1;
               }
           } elsif ($rule eq 'min') {
               if ($env{'form.passwords_'.$rule} =~ /^\d+$/) {
                   if ($env{'form.passwords_'.$rule} >= $Apache::lonnet::passwdmin) {
                       $ruleok = 1;
                   }
               }
           } elsif (($env{'form.passwords_'.$rule} =~ /^\d+$/) &&
                    ($env{'form.passwords_'.$rule} ne '0')) {
               $ruleok = 1;
           }
           if ($ruleok) {
               $newvalues{$rule} = $env{'form.passwords_'.$rule};
               if (exists($current{$rule})) {
                   if ($newvalues{$rule} ne $current{$rule}) {
                       $changes{'rules'} = 1;
                   }
               } elsif ($rule eq 'min') {
                   if ($staticdefaults{$rule} ne $newvalues{$rule}) {
                       $changes{'rules'} = 1;
                   }
               }
           } elsif (exists($current{$rule})) {
               $changes{'rules'} = 1;
           }
       }
       my @posschars = &Apache::loncommon::get_env_multiple('form.passwords_chars');
       my @chars;
       foreach my $item (sort(@posschars)) {
           if ($item =~ /^(uc|lc|num|spec)$/) {
               push(@chars,$item);
           }
       }
       $newvalues{'chars'} = \@chars;
       unless ($changes{'rules'}) {
           if (ref($current{'chars'}) eq 'ARRAY') {
               my @diffs = &Apache::loncommon::compare_arrays($current{'chars'},\@chars);
               if (@diffs > 0) {
                   $changes{'rules'} = 1;
               }
           } else {
               if (@chars > 0) {
                   $changes{'rules'} = 1;
               }
           }
       }
       my %crsownerchg = (
                           by => [],
                           for => [],
                         );
       foreach my $item ('by','for') {
           my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
           foreach my $type (sort(@posstypes)) {
               if (grep(/^\Q$type\E$/,@oktypes)) {
                   push(@{$crsownerchg{$item}},$type);
               }
           }
       }
       $newvalues{'crsownerchg'} = \%crsownerchg;
       if (ref($current{'crsownerchg'}) eq 'HASH') {
           foreach my $item ('by','for') {
               if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
                   my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
                   if (@diffs > 0) {
                       $changes{'crsownerchg'} = 1;
                       last;
                   }
               }
           }
       } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
           foreach my $item ('by','for') {
               if (@{$crsownerchg{$item}} > 0) {
                   $changes{'crsownerchg'} = 1;
                   last;
               }
           }
       }
   
       my %confighash = (
                           defaults  => \%save_defaults,
                           passwords => \%newvalues,
                        );
       &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
   
       my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
       if ($putresult eq 'ok') {
           if (keys(%changes) > 0) {
               $resulttext = &mt('Changes made: ').'<ul>';
               foreach my $key ('reset','intauth','rules','crsownerchg') {
                   if ($changes{$key}) {
                       unless ($key eq 'intauth') {
                           $updateconf = 1;
                       }
                       $resulttext .= '<li>'.$titles{$key}.':<ul>';
                       if ($key eq 'reset') {
                           if ($confighash{'passwords'}{'captcha'} eq 'original') {
                               $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
                           } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
                               $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
                                              &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
                               if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
                                   $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
                                                  &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
                               }
                           } else {
                               $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
                           }
                           if ($confighash{'passwords'}{'resetlink'}) {
                               $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
                           } else {
                               $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
                                                     &mt('Will default to 2 hours').'</li>';
                           }
                           if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
                               if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
                                   $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
                               } else {
                                   my $casesens;
                                   foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
                                       if ($type eq 'default') {
                                           $casesens .= $othertitle.', ';
                                       } elsif ($usertypes->{$type} ne '') {
                                           $casesens .= $usertypes->{$type}.', ';
                                       }
                                   }
                                   $casesens =~ s/\Q, \E$//;
                                   $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
                               }
                           } else {
                               $resulttext .= '<li>'.&mt('Case-sensitivity not set for "Forgot Password" web form').' '.&mt('Will default to case-sensitive for username and/or e-mail address for all').'</li>';
                           }
                           if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
                               $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
                           } else {
                               $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
                           }
                           if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
                               my $output;
                               if (ref($types) eq 'ARRAY') {
                                   foreach my $type (@{$types}) {
                                       if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
                                           if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
                                               $output .= $usertypes->{$type}.' -- '.&mt('none');
                                           } else {
                                               $output .= $usertypes->{$type}.' -- '.
                                                          join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
                                           }
                                       }
                                   }
                               }
                               if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
                                   if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
                                       $output .= $othertitle.' -- '.&mt('none');
                                   } else {
                                       $output .= $othertitle.' -- '.
                                                  join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
                                   }
                               }
                               if ($output) {
                                   $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
                               } else {
                                   $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
                               }
                           } else {
                               $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
                           }
                           if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
                               if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
                                   $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
                               } else {
                                   $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                               }
                           } else {
                               $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA usedfor verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
                           }
                           if ($confighash{'passwords'}{'resetremove'}) {
                               $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
                           } else {
                               $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
                           }
                           if ($confighash{'passwords'}{'resetcustom'}) {
                               my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
                                                                               &mt('custom text'),600,500,undef,undef,
                                                                               undef,undef,'background-color:#ffffff');
                               $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
                           } else {
                               $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
                           }
                       } elsif ($key eq 'intauth') {
                           foreach my $item ('cost','switch','check') {
                               my $value = $save_defaults{$key.'_'.$item};
                               if ($item eq 'switch') {
                                   my %optiondesc = &Apache::lonlocal::texthash (
                                                        0 => 'No',
                                                        1 => 'Yes',
                                                        2 => 'Yes, and copy existing passwd file to passwd.bak file',
                                                    );
                                   if ($value =~ /^(0|1|2)$/) {
                                       $value = $optiondesc{$value};
                                   } else {
                                       $value = &mt('none -- defaults to No');
                                   }
                               } elsif ($item eq 'check') {
                                   my %optiondesc = &Apache::lonlocal::texthash (
                                                        0 => 'No',
                                                        1 => 'Yes, allow login then update passwd file using default cost (if higher)',
                                                        2 => 'Yes, disallow login if stored cost is less than domain default',
                                                    );
                                   if ($value =~ /^(0|1|2)$/) {
                                       $value = $optiondesc{$value};
                                   } else {
                                       $value = &mt('none -- defaults to No');
                                   }
                               }
                               $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
                           }
                       } elsif ($key eq 'rules') {
                           foreach my $rule ('min','max','expire','numsaved') {
                               if ($confighash{'passwords'}{$rule} eq '') {
                                   if ($rule eq 'min') {
                                       $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
                                                      ' '.&mt('Default of [_1] will be used',
                                                              $Apache::lonnet::passwdmin).'</li>';
                                   } else {
                                       $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
                                   }
                               } else {
                                   $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
                               }
                           }
                       } elsif ($key eq 'crsownerchg') {
                           if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
                               if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
                                   (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
                                   $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                               } else {
                                   my %crsownerstr;
                                   foreach my $item ('by','for') {
                                       if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
                                           foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
                                               if ($type eq 'default') {
                                                   $crsownerstr{$item} .= $othertitle.', ';
                                               } elsif ($usertypes->{$type} ne '') {
                                                   $crsownerstr{$item} .= $usertypes->{$type}.', ';
                                               }
                                           }
                                           $crsownerstr{$item} =~ s/\Q, \E$//;
                                       }
                                   }
                                   $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
                                              $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
                               }
                           } else {
                               $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
                           }
                       }
                       $resulttext .= '</ul></li>';
                   }
               }
               $resulttext .= '</ul>';
           } else {
               $resulttext = &mt('No changes made to password settings');
           }
           my $cachetime = 24*60*60;
           if ($updatedefaults) {
               &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
               if (ref($lastactref) eq 'HASH') {
                   $lastactref->{'domdefaults'} = 1;
               }
           }
           if ($updateconf) {
               &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
               if (ref($lastactref) eq 'HASH') {
                   $lastactref->{'passwdconf'} = 1;
               }
           }
       } else {
           $resulttext = '<span class="LC_error">'.
               &mt('An error occurred: [_1]',$putresult).'</span>';
       }
       if ($errors) {
           $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                          $errors.'</ul></p>';
       }
       return $resulttext;
   }
   
 sub modify_usercreation {  sub modify_usercreation {
     my ($dom,%domconfig) = @_;      my ($dom,%domconfig) = @_;
     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);      my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
Line 12838  sub modify_usercreation { Line 15113  sub modify_usercreation {
     }      }
   
     my @authen_contexts = ('author','course','domain');      my @authen_contexts = ('author','course','domain');
     my @authtypes = ('int','krb4','krb5','loc');      my @authtypes = ('int','krb4','krb5','loc','lti');
     my %authhash;      my %authhash;
     foreach my $item (@authen_contexts) {      foreach my $item (@authen_contexts) {
         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');          my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
Line 13567  sub modify_selfcreation { Line 15842  sub modify_selfcreation {
                                 $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').                                  $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
                                             '<ul>';                                              '<ul>';
                                 foreach my $status (@statuses) {                                  foreach my $status (@statuses) {
                                     if ($type eq 'default') {                                      if ($status eq 'default') {
                                         $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';                                          $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
                                     } else {                                      } else {
                                         $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';                                          $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
Line 13836  sub modify_selfcreation { Line 16111  sub modify_selfcreation {
 }  }
   
 sub process_captcha {  sub process_captcha {
     my ($container,$changes,$newsettings,$current) = @_;      my ($container,$changes,$newsettings,$currsettings) = @_;
     return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));      return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
     $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};      $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
     unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {      unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
         $newsettings->{'captcha'} = 'original';          $newsettings->{'captcha'} = 'original';
     }      }
     if ($current->{'captcha'} ne $newsettings->{'captcha'}) {      my %current;
       if (ref($currsettings) eq 'HASH') {
           %current = %{$currsettings};
       }
       if ($current{'captcha'} ne $newsettings->{'captcha'}) {
         if ($container eq 'cancreate') {          if ($container eq 'cancreate') {
             if (ref($changes->{'cancreate'}) eq 'ARRAY') {              if (ref($changes->{'cancreate'}) eq 'ARRAY') {
                 push(@{$changes->{'cancreate'}},'captcha');                  push(@{$changes->{'cancreate'}},'captcha');
             } elsif (!defined($changes->{'cancreate'})) {              } elsif (!defined($changes->{'cancreate'})) {
                 $changes->{'cancreate'} = ['captcha'];                  $changes->{'cancreate'} = ['captcha'];
             }              }
           } elsif ($container eq 'passwords') {
               $changes->{'reset'} = 1;
         } else {          } else {
             $changes->{'captcha'} = 1;              $changes->{'captcha'} = 1;
         }          }
Line 13870  sub process_captcha { Line 16151  sub process_captcha {
         }          }
         $newsettings->{'recaptchaversion'} = $newversion;          $newsettings->{'recaptchaversion'} = $newversion;
     }      }
     if (ref($current->{'recaptchakeys'}) eq 'HASH') {      if (ref($current{'recaptchakeys'}) eq 'HASH') {
         $currpub = $current->{'recaptchakeys'}{'public'};          $currpub = $current{'recaptchakeys'}{'public'};
         $currpriv = $current->{'recaptchakeys'}{'private'};          $currpriv = $current{'recaptchakeys'}{'private'};
         unless ($newsettings->{'captcha'} eq 'recaptcha') {          unless ($newsettings->{'captcha'} eq 'recaptcha') {
             $newsettings->{'recaptchakeys'} = {              $newsettings->{'recaptchakeys'} = {
                                                  public  => '',                                                   public  => '',
Line 13880  sub process_captcha { Line 16161  sub process_captcha {
                                               }                                                }
         }          }
     }      }
     if ($current->{'captcha'} eq 'recaptcha') {      if ($current{'captcha'} eq 'recaptcha') {
         $currversion = $current->{'recaptchaversion'};          $currversion = $current{'recaptchaversion'};
         if ($currversion ne '2') {          if ($currversion ne '2') {
             $currversion = 1;              $currversion = 1;
         }          }
Line 13893  sub process_captcha { Line 16174  sub process_captcha {
             } elsif (!defined($changes->{'cancreate'})) {              } elsif (!defined($changes->{'cancreate'})) {
                 $changes->{'cancreate'} = ['recaptchaversion'];                  $changes->{'cancreate'} = ['recaptchaversion'];
             }              }
           } elsif ($container eq 'passwords') {
               $changes->{'reset'} = 1;
         } else {          } else {
             $changes->{'recaptchaversion'} = 1;              $changes->{'recaptchaversion'} = 1;
         }          }
Line 13904  sub process_captcha { Line 16187  sub process_captcha {
             } elsif (!defined($changes->{'cancreate'})) {              } elsif (!defined($changes->{'cancreate'})) {
                 $changes->{'cancreate'} = ['recaptchakeys'];                  $changes->{'cancreate'} = ['recaptchakeys'];
             }              }
           } elsif ($container eq 'passwords') {
               $changes->{'reset'} = 1;
         } else {          } else {
             $changes->{'recaptchakeys'} = 1;              $changes->{'recaptchakeys'} = 1;
         }          }
Line 14019  sub modify_defaults { Line 16304  sub modify_defaults {
     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);      my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);      my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',      my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
                  'portal_def','intauth_cost','intauth_check','intauth_switch');                   'portal_def');
     my @authtypes = ('internal','krb4','krb5','localauth');      my @authtypes = ('internal','krb4','krb5','localauth','lti');
     foreach my $item (@items) {      foreach my $item (@items) {
         $newvalues{$item} = $env{'form.'.$item};          $newvalues{$item} = $env{'form.'.$item};
         if ($item eq 'auth_def') {          if ($item eq 'auth_def') {
Line 14061  sub modify_defaults { Line 16346  sub modify_defaults {
                     push(@errors,$item);                      push(@errors,$item);
                 }                  }
             }              }
         } elsif ($item eq 'intauth_cost') {  
             if ($newvalues{$item} ne '') {  
                 if ($newvalues{$item} =~ /\D/) {  
                     push(@errors,$item);  
                 }  
             }  
         } elsif ($item eq 'intauth_check') {  
             if ($newvalues{$item} ne '') {  
                 unless ($newvalues{$item} =~ /^(0|1|2)$/) {  
                     push(@errors,$item);  
                 }  
             }  
         } elsif ($item eq 'intauth_switch') {  
             if ($newvalues{$item} ne '') {  
                 unless ($newvalues{$item} =~ /^(0|1|2)$/) {  
                     push(@errors,$item);  
                 }  
             }  
         }          }
         if (grep(/^\Q$item\E$/,@errors)) {          if (grep(/^\Q$item\E$/,@errors)) {
             $newvalues{$item} = $domdefaults{$item};              $newvalues{$item} = $domdefaults{$item};
Line 14087  sub modify_defaults { Line 16354  sub modify_defaults {
         }          }
         $domdefaults{$item} = $newvalues{$item};          $domdefaults{$item} = $newvalues{$item};
     }      }
       my %staticdefaults = (
                              'intauth_cost'   => 10,
                              'intauth_check'  => 0,
                              'intauth_switch' => 0,
                            );
       foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
           if (exists($domdefaults{$item})) {
               $newvalues{$item} = $domdefaults{$item};
           } else {
               $newvalues{$item} = $staticdefaults{$item};
           }
       }
     my %defaults_hash = (      my %defaults_hash = (
                          defaults => \%newvalues,                           defaults => \%newvalues,
                         );                          );
Line 14212  sub modify_defaults { Line 16491  sub modify_defaults {
                                           krb4       => 'krb4',                                            krb4       => 'krb4',
                                           krb5       => 'krb5',                                            krb5       => 'krb5',
                                           localauth  => 'loc',                                            localauth  => 'loc',
                                             lti        => 'lti',
                         );                          );
                         $value = $authnames{$shortauth{$value}};                          $value = $authnames{$shortauth{$value}};
                     } elsif ($item eq 'intauth_switch') {  
                         my %optiondesc = &Apache::lonlocal::texthash (  
                                             0 => 'No',  
                                             1 => 'Yes',  
                                             2 => 'Yes, and copy existing passwd file to passwd.bak file',  
                                          );  
                         if ($value =~ /^(0|1|2)$/) {  
                             $value = $optiondesc{$value};  
                         } else {  
                             $value = &mt('none -- defaults to No');  
                         }  
                     } elsif ($item eq 'intauth_check') {  
                         my %optiondesc = &Apache::lonlocal::texthash (  
                                              0 => 'No',  
                                              1 => 'Yes, allow login then update passwd file using default cost (if higher)',  
                                              2 => 'Yes, disallow login if stored cost is less than domain default',  
                                          );  
                         if ($value =~ /^(0|1|2)$/) {  
                             $value = $optiondesc{$value};  
                         } else {  
                             $value = &mt('none -- defaults to No');  
                         }  
                     }                      }
                     $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';                      $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
                     $mailmsgtext .= "$title->{$item} set to $value\n";                        $mailmsgtext .= "$title->{$item} set to $value\n";  
Line 14284  sub modify_scantron { Line 16542  sub modify_scantron {
     my $custom = 'custom.tab';      my $custom = 'custom.tab';
     my $default = 'default.tab';      my $default = 'default.tab';
     my $servadm = $r->dir_config('lonAdmEMail');      my $servadm = $r->dir_config('lonAdmEMail');
     my ($configuserok,$author_ok,$switchserver) =       my ($configuserok,$author_ok,$switchserver) =
         &config_check($dom,$confname,$servadm);          &config_check($dom,$confname,$servadm);
     if ($env{'form.scantronformat.filename'} ne '') {      if ($env{'form.scantronformat.filename'} ne '') {
         my $error;          my $error;
Line 14319  sub modify_scantron { Line 16577  sub modify_scantron {
             if ($env{'form.scantronformat_del'}) {              if ($env{'form.scantronformat_del'}) {
                 $confhash{'scantron'}{'scantronformat'} = '';                  $confhash{'scantron'}{'scantronformat'} = '';
                 $changes{'scantronformat'} = 1;                  $changes{'scantronformat'} = 1;
               } else {
                   $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
               }
           }
       }
       my @options = ('hdr','pad','rem');
       my @fields = &scantroncsv_fields();
       my %titles = &scantronconfig_titles();
       my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
       my ($newdat,$currdat,%newcol,%currcol);
       if (grep(/^dat$/,@formats)) {
           $confhash{'scantron'}{config}{dat} = 1;
           $newdat = 1;
       } else {
           $newdat = 0;
       }
       if (grep(/^csv$/,@formats)) {
           my %bynum;
           foreach my $field (@fields) {
               if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
                   my $posscol = $1;
                   if (($posscol < 20) && (!$bynum{$posscol})) {
                       $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
                       $bynum{$posscol} = $field;
                       $newcol{$field} = $posscol;
                   }
               }
           }
           if (keys(%newcol)) {
               foreach my $option (@options) {
                   if ($env{'form.scantroncsv_'.$option}) {
                       $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
                   }
               }
           }
       }
       $currdat = 1;
       if (ref($domconfig{'scantron'}) eq 'HASH') {
           if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
               unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
                   $currdat = 0;
               }
               if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
                   if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                       %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
                   }
               }
           }
       }
       if ($currdat != $newdat) {
           $changes{'config'} = 1;
       } else {
           foreach my $field (@fields) {
               if ($currcol{$field} ne '') {
                   if ($currcol{$field} ne $newcol{$field}) {
                       $changes{'config'} = 1;
                       last;
                   }
               } elsif ($newcol{$field} ne '') {
                   $changes{'config'} = 1;
                   last;
             }              }
         }          }
     }      }
Line 14329  sub modify_scantron { Line 16648  sub modify_scantron {
             if (keys(%changes) > 0) {              if (keys(%changes) > 0) {
                 if (ref($confhash{'scantron'}) eq 'HASH') {                  if (ref($confhash{'scantron'}) eq 'HASH') {
                     $resulttext = &mt('Changes made:').'<ul>';                      $resulttext = &mt('Changes made:').'<ul>';
                     if ($confhash{'scantron'}{'scantronformat'} eq '') {                      if ($changes{'scantronformat'}) {
                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';                          if ($confhash{'scantron'}{'scantronformat'} eq '') {
                     } else {                              $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';                          } else {
                               $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
                           }
                       }
                       if ($changes{'config'}) {
                           if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
                               if ($confhash{'scantron'}{'config'}{'dat'}) {
                                   $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
                               }
                               if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
                                   if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
                                       if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
                                           $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
                                           foreach my $field (@fields) {
                                               if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
                                                   my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
                                                   $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
                                               }
                                           }
                                           $resulttext .= '</ul></li>';
                                           if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
                                               if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
                                                   $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
                                                   foreach my $option (@options) {
                                                       if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
                                                           $resulttext .= '<li>'.$titles{$option}.'</li>';
                                                       }
                                                   }
                                                   $resulttext .= '</ul></li>';
                                               }
                                           }
                                       }
                                   }
                               }
                           } else {
                               $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
                           }
                     }                      }
                     $resulttext .= '</ul>';                      $resulttext .= '</ul>';
                 } else {                  } else {
                     $resulttext = &mt('Changes made to bubblesheet format file.');                      $resulttext = &mt('Changes made to bubblesheet format file.');
                 }                  }
                 $resulttext .= '</ul>';  
                 &Apache::loncommon::devalidate_domconfig_cache($dom);                  &Apache::loncommon::devalidate_domconfig_cache($dom);
                 if (ref($lastactref) eq 'HASH') {                  if (ref($lastactref) eq 'HASH') {
                     $lastactref->{'domainconfig'} = 1;                      $lastactref->{'domainconfig'} = 1;
                 }                  }
             } else {              } else {
                 $resulttext = &mt('No changes made to bubblesheet format file');                  $resulttext = &mt('No changes made to bubblesheet format settings');
             }              }
         } else {          } else {
             $resulttext = '<span class="LC_error">'.              $resulttext = '<span class="LC_error">'.
Line 14354  sub modify_scantron { Line 16708  sub modify_scantron {
         $resulttext = &mt('No changes made to bubblesheet format file');           $resulttext = &mt('No changes made to bubblesheet format file'); 
     }      }
     if ($errors) {      if ($errors) {
         $resulttext .= &mt('The following errors occurred: ').'<ul>'.          $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
                        $errors.'</ul>';                         $errors.'</ul></p>';
     }      }
     return $resulttext;      return $resulttext;
 }  }
Line 14630  sub modify_coursecategories { Line 16984  sub modify_coursecategories {
                     }                      }
                     $resulttext .= '</ul></li>';                      $resulttext .= '</ul></li>';
                 }                  }
                   &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
                   if (ref($lastactref) eq 'HASH') {
                       $lastactref->{'cats'} = 1;
                   }
             }              }
             $resulttext .= '</ul>';              $resulttext .= '</ul>';
             if ($changes{'unauth'} || $changes{'auth'}) {              if ($changes{'unauth'} || $changes{'auth'}) {
Line 15176  sub modify_coursedefaults { Line 17534  sub modify_coursedefaults {
                 $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;                  $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
             }              }
             if ($currdef ne $newdef) {              if ($currdef ne $newdef) {
                 my $staticdef;  
                 if ($item eq 'anonsurvey_threshold') {                  if ($item eq 'anonsurvey_threshold') {
                     unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {                      unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
                         $changes{$item} = 1;                          $changes{$item} = 1;
Line 15192  sub modify_coursedefaults { Line 17549  sub modify_coursedefaults {
         my $texengine;          my $texengine;
         if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {          if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
             $texengine = $env{'form.texengine'};              $texengine = $env{'form.texengine'};
             if ($defaultshash{'coursedefaults'}{'texengine'} eq '') {              my $currdef = $domconfig{'coursedefaults'}{'texengine'};
                 unless ($texengine eq 'MathJax') {              if ($currdef eq '') {
                   unless ($texengine eq $Apache::lonnet::deftex) {
                     $changes{'texengine'} = 1;                      $changes{'texengine'} = 1;
                 }                  }
             } elsif ($defaultshash{'coursedefaults'}{'texengine'} ne $texengine) {              } elsif ($currdef ne $texengine) {
                 $changes{'texengine'} = 1;                  $changes{'texengine'} = 1;
             }              }
         }          }
Line 16013  sub modify_usersessions { Line 18371  sub modify_usersessions {
                         } else {                          } else {
                             foreach my $type (@{$types{$prefix}}) {                              foreach my $type (@{$types{$prefix}}) {
                                 if (defined($changes{$prefix}{$type})) {                                  if (defined($changes{$prefix}{$type})) {
                                     my $newvalue;                                      my ($newvalue,$notinuse);
                                     if (ref($defaultshash{'usersessions'}) eq 'HASH') {                                      if (ref($defaultshash{'usersessions'}) eq 'HASH') {
                                         if (ref($defaultshash{'usersessions'}{$prefix})) {                                          if (ref($defaultshash{'usersessions'}{$prefix})) {
                                             if ($type eq 'version') {                                              if ($type eq 'version') {
                                                 $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};                                                  $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
                                             } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {                                              } else {
                                                 if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {                                                  if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
                                                     $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});                                                      if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
                                                           $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
                                                       }
                                                   } else {
                                                       $notinuse = 1;
                                                 }                                                  }
                                             }                                              }
                                         }                                          }
Line 16028  sub modify_usersessions { Line 18390  sub modify_usersessions {
                                     if ($newvalue eq '') {                                      if ($newvalue eq '') {
                                         if ($type eq 'version') {                                          if ($type eq 'version') {
                                             $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';                                              $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
                                           } elsif ($notinuse) {
                                               $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
                                         } else {                                          } else {
                                             $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';                                              $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                                         }                                          }
                                     } else {                                      } else {
                                         if ($type eq 'version') {                                          if ($type eq 'version') {
                                             $newvalue .= ' '.&mt('(or later)');                                               $newvalue .= ' '.&mt('(or later)');
                                         }                                          }
                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';                                          $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
                                     }                                      }
Line 16101  sub modify_ssl { Line 18465  sub modify_ssl {
                 if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {                  if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
                     $value = $env{'form.'.$prefix.'_'.$type};                      $value = $env{'form.'.$prefix.'_'.$type};
                 }                  }
                 if (ref($domconfig{$action}{$prefix}) eq 'HASH') {                  if (ref($domconfig{$action}) eq 'HASH') {
                     if ($domconfig{$action}{$prefix}{$type} ne '') {                      if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
                         if ($value ne $domconfig{$action}{$prefix}{$type}) {                          if ($domconfig{$action}{$prefix}{$type} ne '') {
                               if ($value ne $domconfig{$action}{$prefix}{$type}) {
                                   $changes{$prefix}{$type} = 1;
                               }
                               $defaultshash{$action}{$prefix}{$type} = $value;
                           } else {
                               $defaultshash{$action}{$prefix}{$type} = $value;
                             $changes{$prefix}{$type} = 1;                              $changes{$prefix}{$type} = 1;
                         }                          }
                         $defaultshash{$action}{$prefix}{$type} = $value;  
                     } else {                      } else {
                         $defaultshash{$action}{$prefix}{$type} = $value;                          $defaultshash{$action}{$prefix}{$type} = $value;
                         $changes{$prefix}{$type} = 1;                          $changes{$prefix}{$type} = 1;
Line 16176  sub modify_ssl { Line 18545  sub modify_ssl {
             }              }
         }          }
     }      }
       if (keys(%changes)) {
           foreach my $prefix (keys(%changes)) {
               if (ref($changes{$prefix}) eq 'HASH') {
                   if (scalar(keys(%{$changes{$prefix}})) == 0) {
                       delete($changes{$prefix});
                   }
               } else {
                   delete($changes{$prefix});
               }
           }
       }
     my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');      my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
     if (keys(%changes) > 0) {      if (keys(%changes) > 0) {
         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,          my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
Line 16186  sub modify_ssl { Line 18566  sub modify_ssl {
                     $domdefaults{'replication'} = $defaultshash{$action}{'replication'};                      $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
                 }                  }
                 if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {                  if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
                     $domdefaults{'connto'} = $domconfig{$action}{'connto'};                      $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
                 }                  }
                 if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {                  if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
                     $domdefaults{'connfrom'} = $domconfig{$action}{'connfrom'};                      $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
                 }                  }
             }              }
             my $cachetime = 24*60*60;              my $cachetime = 24*60*60;
Line 16205  sub modify_ssl { Line 18585  sub modify_ssl {
                         $resulttext .= '<li>'.$titles{$prefix}.'<ul>';                          $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
                         foreach my $type (@{$types{$prefix}}) {                          foreach my $type (@{$types{$prefix}}) {
                             if (defined($changes{$prefix}{$type})) {                              if (defined($changes{$prefix}{$type})) {
                                 my $newvalue;                                  my ($newvalue,$notinuse);
                                 if (ref($defaultshash{$action}) eq 'HASH') {                                  if (ref($defaultshash{$action}) eq 'HASH') {
                                     if (ref($defaultshash{$action}{$prefix})) {                                      if (ref($defaultshash{$action}{$prefix})) {
                                         if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {                                          if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
                                             $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};                                              $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
                                         } elsif (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {                                          } else {
                                             if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {                                              if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
                                                 $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});                                                  if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
                                                       $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
                                                   }
                                               } else {
                                                   $notinuse = 1;
                                             }                                              }
                                         }                                          }
                                     }                                      }
                                     if ($newvalue eq '') {                                      if ($notinuse) {
                                           $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
                                       } elsif ($newvalue eq '') {
                                         $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';                                          $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
                                     } else {                                      } else {
                                         $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';                                          $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
Line 16330  sub modify_trust { Line 18716  sub modify_trust {
                         $resulttext .= '<li>'.$lt{$prefix}.'<ul>';                          $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
                         foreach my $type (@types) {                          foreach my $type (@types) {
                             if (defined($changes{$prefix}{$type})) {                              if (defined($changes{$prefix}{$type})) {
                                 my $newvalue;                                  my ($newvalue,$notinuse);
                                 if (ref($defaultshash{'trust'}) eq 'HASH') {                                  if (ref($defaultshash{'trust'}) eq 'HASH') {
                                     if (ref($defaultshash{'trust'}{$prefix})) {                                      if (ref($defaultshash{'trust'}{$prefix})) {
                                         if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {                                          if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
                                             if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {                                              if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
                                                 $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});                                                  $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
                                             }                                              }
                                           } else {
                                               $notinuse = 1;
                                         }                                          }
                                     }                                      }
                                 }                                  }
                                 if ($newvalue eq '') {                                  if ($notinuse) {
                                       $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
                                   } elsif ($newvalue eq '') {
                                     $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';                                      $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
                                 } else {                                  } else {
                                     $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';                                      $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
Line 16375  sub modify_loadbalancing { Line 18765  sub modify_loadbalancing {
     my @sparestypes = ('primary','default');      my @sparestypes = ('primary','default');
     my %typetitles = &sparestype_titles();      my %typetitles = &sparestype_titles();
     my $resulttext;      my $resulttext;
     my (%currbalancer,%currtargets,%currrules,%existing);      my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
     if (ref($domconfig{'loadbalancing'}) eq 'HASH') {      if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
         %existing = %{$domconfig{'loadbalancing'}};          %existing = %{$domconfig{'loadbalancing'}};
     }      }
     &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,      &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
                               \%currtargets,\%currrules);                                \%currtargets,\%currrules,\%currcookies);
     my ($saveloadbalancing,%defaultshash,%changes);      my ($saveloadbalancing,%defaultshash,%changes);
     my ($alltypes,$othertypes,$titles) =      my ($alltypes,$othertypes,$titles) =
         &loadbalancing_titles($dom,$intdom,$usertypes,$types);          &loadbalancing_titles($dom,$intdom,$usertypes,$types);
Line 16432  sub modify_loadbalancing { Line 18822  sub modify_loadbalancing {
             }              }
             $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;              $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
         }          }
           if ($env{'form.loadbalancing_cookie_'.$i}) {
               $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
               if (exists($currbalancer{$balancer})) { 
                   unless ($currcookies{$balancer}) {
                       $changes{'curr'}{$balancer}{'cookie'} = 1;
                   }
               }
           } elsif (exists($currbalancer{$balancer})) {
               if ($currcookies{$balancer}) {
                   $changes{'curr'}{$balancer}{'cookie'} = 1;
               }
           }
         if (ref($currtargets{$balancer}) eq 'HASH') {          if (ref($currtargets{$balancer}) eq 'HASH') {
             foreach my $sparetype (@sparestypes) {              foreach my $sparetype (@sparestypes) {
                 if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {                  if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
Line 16585  sub modify_loadbalancing { Line 18987  sub modify_loadbalancing {
                                 }                                  }
                             }                              }
                         }                          }
                           if ($changes{'curr'}{$balancer}{'cookie'}) {
                               $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
                                                         $balancer).'</li>'; 
                           }
                         if (keys(%toupdate)) {                          if (keys(%toupdate)) {
                             my %thismachine;                              my %thismachine;
                             my $updatedhere;                              my $updatedhere;
Line 16814  sub lonbalance_targets_js { Line 19220  sub lonbalance_targets_js {
     }      }
     push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');      push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
     $allinsttypes = join("','",@alltypes);      $allinsttypes = join("','",@alltypes);
     my (%currbalancer,%currtargets,%currrules,%existing);      my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
         %existing = %{$settings};          %existing = %{$settings};
     }      }
     &get_loadbalancers_config($servers,\%existing,\%currbalancer,      &get_loadbalancers_config($servers,\%existing,\%currbalancer,
                               \%currtargets,\%currrules);                                \%currtargets,\%currrules,\%currcookies);
     my $balancers = join("','",sort(keys(%currbalancer)));      my $balancers = join("','",sort(keys(%currbalancer)));
     return <<"END";      return <<"END";
   
Line 17361  sub devalidate_remote_domconfs { Line 19767  sub devalidate_remote_domconfs {
     my %servers = &Apache::lonnet::internet_dom_servers($dom);      my %servers = &Apache::lonnet::internet_dom_servers($dom);
     my %thismachine;      my %thismachine;
     map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();      map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
     my @posscached = ('domainconfig','domdefaults','ltitools','usersessions','directorysrch');      my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
                         'directorysrch','passwdconf','cats');
     if (keys(%servers)) {      if (keys(%servers)) {
         foreach my $server (keys(%servers)) {          foreach my $server (keys(%servers)) {
             next if ($thismachine{$server});              next if ($thismachine{$server});

Removed from v.1.324  
changed lines
  Added in v.1.369


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