Diff for /loncom/interface/domainprefs.pm between versions 1.55 and 1.87

version 1.55, 2008/06/03 17:02:12 version 1.87, 2009/02/09 03:42:03
Line 37  use Apache::loncommon(); Line 37  use Apache::loncommon();
 use Apache::lonhtmlcommon();  use Apache::lonhtmlcommon();
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonmsg();  use Apache::lonmsg();
 use LONCAPA;  use LONCAPA qw(:DEFAULT :match);
 use LONCAPA::Enrollment;  use LONCAPA::Enrollment;
   use LONCAPA::lonauthcgi();
 use File::Copy;  use File::Copy;
 use Locale::Language;  use Locale::Language;
   use DateTime::TimeZone;
   use DateTime::Locale;
   
 sub handler {  sub handler {
     my $r=shift;      my $r=shift;
Line 62  sub handler { Line 65  sub handler {
     }      }
     &Apache::lonhtmlcommon::clear_breadcrumbs();      &Apache::lonhtmlcommon::clear_breadcrumbs();
     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},      &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                             ['phase']);                                              ['phase','actions']);
     my $phase = 'pickactions';      my $phase = 'pickactions';
     if ( exists($env{'form.phase'}) ) {      if ( exists($env{'form.phase'}) ) {
         $phase = $env{'form.phase'};          $phase = $env{'form.phase'};
Line 71  sub handler { Line 74  sub handler {
       &Apache::lonnet::get_dom('configuration',['login','rolecolors',        &Apache::lonnet::get_dom('configuration',['login','rolecolors',
                 'quotas','autoenroll','autoupdate','directorysrch',                  'quotas','autoenroll','autoupdate','directorysrch',
                 'usercreation','usermodification','contacts','defaults',                  'usercreation','usermodification','contacts','defaults',
                 'scantron','coursecategories'],$dom);                  'scantron','coursecategories','serverstatuses',
                   'requestcourses'],$dom);
     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',      my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
                        'autoupdate','directorysrch','contacts',                         'autoupdate','directorysrch','contacts',
                        'usercreation','usermodification','scantron',                         'usercreation','usermodification','scantron',
                        'coursecategories');                         'requestcourses','coursecategories','serverstatuses');
     my %prefs = (      my %prefs = (
         'rolecolors' =>          'rolecolors' =>
                    { text => 'Default color schemes',                     { text => 'Default color schemes',
                      help => 'Default_Color_Schemes',                       help => 'Domain_Configuration_Color_Schemes',
                      header => [{col1 => 'Student Settings',                       header => [{col1 => 'Student Settings',
                                  col2 => '',},                                   col2 => '',},
                                 {col1 => 'Coordinator Settings',                                  {col1 => 'Coordinator Settings',
Line 91  sub handler { Line 95  sub handler {
                     },                      },
         'login' =>            'login' =>  
                     { text => 'Log-in page options',                      { text => 'Log-in page options',
                       help => 'Domain_Log-in_Page',                        help => 'Domain_Configuration_Login_Page',
                       header => [{col1 => 'Item',                        header => [{col1 => 'Item',
                                   col2 => '',}],                                    col2 => '',}],
                     },                      },
         'defaults' =>           'defaults' => 
                     { text => 'Default authentication/language/timezone',                      { text => 'Default authentication/language/timezone',
                       help => '',                        help => 'Domain_Configuration_LangTZAuth',
                       header => [{col1 => 'Setting',                        header => [{col1 => 'Setting',
                                   col2 => 'Value'}],                                    col2 => 'Value'}],
                     },                      },
         'quotas' =>           'quotas' => 
                     { text => 'Default quotas for user portfolios',                      { text => 'User blogs, home pages and portfolios',
                       help => 'Default_User_Quota',                        help => 'Domain_Configuration_Quotas',
                       header => [{col1 => 'User type',                        header => [{col1 => 'User affiliation',
                                   col2 => 'Default quota'}],                                    col2 => 'Available tools',
                                     col3 => 'Portfolio quota',}],
                     },                      },
         'autoenroll' =>          'autoenroll' =>
                    { text => 'Auto-enrollment settings',                     { text => 'Auto-enrollment settings',
                      help => 'Domain_Auto_Enrollment',                       help => 'Domain_Configuration_Auto_Enrollment',
                      header => [{col1 => 'Configuration setting',                       header => [{col1 => 'Configuration setting',
                                  col2 => 'Value(s)'}],                                   col2 => 'Value(s)'}],
                    },                     },
         'autoupdate' =>           'autoupdate' => 
                    { text => 'Auto-update settings',                     { text => 'Auto-update settings',
                      help => 'Domain_Auto_Update',                       help => 'Domain_Configuration_Auto_Updates',
                      header => [{col1 => 'Setting',                       header => [{col1 => 'Setting',
                                  col2 => 'Value',},                                   col2 => 'Value',},
                                 {col1 => 'User population',                                  {col1 => 'User population',
Line 123  sub handler { Line 128  sub handler {
                   },                    },
         'directorysrch' =>           'directorysrch' => 
                   { text => 'Institutional directory searches',                    { text => 'Institutional directory searches',
                     help => 'Domain_Directory_Search',                      help => 'Domain_Configuration_InstDirectory_Search',
                     header => [{col1 => 'Setting',                      header => [{col1 => 'Setting',
                                 col2 => 'Value',}],                                  col2 => 'Value',}],
                   },                    },
         'contacts' =>          'contacts' =>
                   { text => 'Contact Information',                    { text => 'Contact Information',
                     help => 'Domain_Contact_Information',                      help => 'Domain_Configuration_Contact_Info',
                     header => [{col1 => 'Setting',                      header => [{col1 => 'Setting',
                                 col2 => 'Value',}],                                  col2 => 'Value',}],
                   },                    },
   
         'usercreation' =>           'usercreation' => 
                   { text => 'User creation',                    { text => 'User creation',
                     help => 'Domain_User_Creation',                      help => 'Domain_Configuration_User_Creation',
                     header => [{col1 => 'Format rule type',                      header => [{col1 => 'Format rule type',
                                 col2 => 'Format rules in force'},                                  col2 => 'Format rules in force'},
                                {col1 => 'User account creation',                                 {col1 => 'User account creation',
Line 144  sub handler { Line 149  sub handler {
                                {col1 => 'Context',                                 {col1 => 'Context',
                                 col2 => 'Assignable authentication types'}],                                  col2 => 'Assignable authentication types'}],
                   },                    },
         'usermodification' =>           'usermodification' =>
                   { text => 'User modification',                    { text => 'User modification',
                     help => 'Domain_User_Modification',                      help => 'Domain_Configuration_User_Modification',
                     header => [{col1 => 'Target user has role',                      header => [{col1 => 'Target user has role',
                                 col2 => 'User information updateable in author context'},                                  col2 => 'User information updateable in author context'},
                                {col1 => 'Target user has role',                                 {col1 => 'Target user has role',
                                 col2 => 'User information updateable in course context'}],                                  col2 => 'User information updateable in course context'},
                                  {col1 => "Status of user",
                                   col2 => 'Information settable when self-creating account (if directory data blank)'}],
                   },                    },
         'scantron' =>           'scantron' =>
                   { text => 'Scantron format file',                    { text => 'Scantron format file',
                     help => 'Domain_Scantron_Formats',                      help => 'Domain_Configuration_Scantron_Format',
                     header => [ {col1 => 'Item',                      header => [ {col1 => 'Item',
                                  col2 => '',                                   col2 => '',
                               }],                                }],
                   },                    },
         'coursecategories' =>           'requestcourses' => 
                    {text => 'Request creation of courses',
                     help => 'Domain_Configuration_Request_Courses',
                     header => [{col1 => 'User affiliation',
                                 col2 => 'Requestable course types',}],
                    },
           'coursecategories' =>
                   { text => 'Cataloging of courses',                    { text => 'Cataloging of courses',
                     help => 'Domain_Course_Catalog',                      help => 'Domain_Configuration_Cataloging_Courses',
                     header => [  {col1 => 'Categories',                      header => [{col1 => 'Category settings',
                                   col2 => '',                                  col2 => '',},
                               }],                                 {col1 => 'Categories',
                   }                                  col2 => '',
                                  }],
                     },
           'serverstatuses' =>
                    {text   => 'Access to server status pages',
                     help   => 'Domain_Configuration_Server_Status',
                     header => [{col1 => 'Status Page',
                                 col2 => 'Other named users',
                                 col3 => 'Specific IPs',
                               }],
                    },
     );      );
     my @roles = ('student','coordinator','author','admin');      my @roles = ('student','coordinator','author','admin');
     my @actions = &Apache::loncommon::get_env_multiple('form.actions');      my @actions = &Apache::loncommon::get_env_multiple('form.actions');
Line 255  sub handler { Line 278  sub handler {
             $r->print('<input type="hidden" name="phase" value="" />'.              $r->print('<input type="hidden" name="phase" value="" />'.
                       '<input type="hidden" name="numcols" value="'.                        '<input type="hidden" name="numcols" value="'.
                       $env{'form.numcols'}.'" />'."\n".                        $env{'form.numcols'}.'" />'."\n".
                       '<span clas="LC_error">'.&mt('No settings chosen').                        '<span class="LC_error">'.&mt('No settings chosen').
                       '</span>');                        '</span>');
         }          }
         $r->print('</form>');          $r->print('</form>');
Line 300  sub handler { Line 323  sub handler {
         $r->print('<h3>'.&mt('Functionality to display/modify').'</h3>');          $r->print('<h3>'.&mt('Functionality to display/modify').'</h3>');
         $r->print('<script type="text/javascript">'."\n".          $r->print('<script type="text/javascript">'."\n".
               &Apache::loncommon::check_uncheck_jscript()."\n".                &Apache::loncommon::check_uncheck_jscript()."\n".
               '</script>'."\n".'<p><input type="button" value="check all" '.                '</script>'."\n".'<p><input type="button" value="'.&mt('check all').'" '.
               'onclick="javascript:checkAll(document.pickactions.actions)"'.                'onclick="javascript:checkAll(document.pickactions.actions)"'.
               ' />&nbsp;&nbsp;'.                ' />&nbsp;&nbsp;'.
               '<input type="button" value="uncheck all" '.                '<input type="button" value="'.&mt('uncheck all').'" '.
               'onclick="javascript:uncheckAll(document.pickactions.actions)"'.                'onclick="javascript:uncheckAll(document.pickactions.actions)"'.
               ' /></p><div class="LC_left_float">');                ' /></p><div class="LC_left_float">');
         my ($numitems,$midpoint,$seconddiv,$count);           my ($numitems,$midpoint,$seconddiv,$count); 
Line 314  sub handler { Line 337  sub handler {
         }          }
         $count = 0;          $count = 0;
         foreach my $item (@prefs_order) {          foreach my $item (@prefs_order) {
             $r->print('<h4><label><input type="checkbox" name="actions" value="'.$item.'" />&nbsp;'.$prefs{$item}->{'text'}.'</label></h4>');              $r->print('<h4>'.
                         &Apache::loncommon::help_open_topic($prefs{$item}->{'help'}).
                         '<label><input type="checkbox" name="actions" value="'.$item.
                         '" />&nbsp;'.&mt($prefs{$item}->{'text'}).'</label></h4>');
             $count ++;              $count ++;
             if ((!$seconddiv) && ($count >= $midpoint)) {              if ((!$seconddiv) && ($count >= $midpoint)) {
                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");                  $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
Line 344  sub process_changes { Line 370  sub process_changes {
         $output = &modify_rolecolors($r,$dom,$confname,$roles,          $output = &modify_rolecolors($r,$dom,$confname,$roles,
                                      %domconfig);                                       %domconfig);
     } elsif ($action eq 'quotas') {      } elsif ($action eq 'quotas') {
         $output = &modify_quotas($dom,%domconfig);          $output = &modify_quotas($dom,$action,%domconfig);
     } elsif ($action eq 'autoenroll') {      } elsif ($action eq 'autoenroll') {
         $output = &modify_autoenroll($dom,%domconfig);          $output = &modify_autoenroll($dom,%domconfig);
     } elsif ($action eq 'autoupdate') {      } elsif ($action eq 'autoupdate') {
Line 363  sub process_changes { Line 389  sub process_changes {
         $output = &modify_scantron($r,$dom,$confname,%domconfig);          $output = &modify_scantron($r,$dom,$confname,%domconfig);
     } elsif ($action eq 'coursecategories') {      } elsif ($action eq 'coursecategories') {
         $output = &modify_coursecategories($dom,%domconfig);          $output = &modify_coursecategories($dom,%domconfig);
       } elsif ($action eq 'serverstatuses') {
           $output = &modify_serverstatuses($dom,%domconfig);
       } elsif ($action eq 'requestcourses') {
           $output = &modify_quotas($dom,$action,%domconfig);
     }      }
     return $output;      return $output;
 }  }
Line 377  sub print_config_box { Line 407  sub print_config_box {
     $output .=       $output .= 
          '<table class="LC_nested_outer">           '<table class="LC_nested_outer">
           <tr>            <tr>
            <th align="left"><span class="LC_nobreak">'.&mt($item->{text}).             <th align="left" valign="middle"><span class="LC_nobreak">'.
            '&nbsp;</span></th></tr>';             &mt($item->{text}).'&nbsp;'.
 #              &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
 # FIXME - put the help link back in when the help files exist            '</tr>';
 #           <th>'.&mt($item->{text}).'&nbsp;'.  
 #           &Apache::loncommon::help_open_topic($item->{'help'}).'</th>  
 #          </tr>');  
     $rowtotal ++;      $rowtotal ++;
     if (($action eq 'autoupdate') || ($action eq 'rolecolors') ||       if (($action eq 'autoupdate') || ($action eq 'rolecolors') || 
         ($action eq 'usercreation') || ($action eq 'usermodification')) {          ($action eq 'usercreation') || ($action eq 'usermodification') ||
         my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';          ($action eq 'coursecategories')) {
           my $colspan = '';
           if (($action eq 'rolecolors') || ($action eq 'coursecategories')) {
               $colspan = ' colspan="2"';
           }
         $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.'>'.$item->{'header'}->[0]->{'col1'}.'</td>                <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>                <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
              </tr>';               </tr>';
              $rowtotal ++;          $rowtotal ++;
         if ($action eq 'autoupdate') {          if ($action eq 'autoupdate') {
             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);              $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'usercreation') {          } elsif ($action eq 'usercreation') {
             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);              $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
         } elsif ($action eq 'usermodification') {          } elsif ($action eq 'usermodification') {
             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);              $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
           } elsif ($action eq 'coursecategories') {
               $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
         } else {          } else {
             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);              $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
         }          }
Line 414  sub print_config_box { Line 447  sub print_config_box {
            <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.'>'.$item->{'header'}->[1]->{'col1'}.'</td>                <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
               <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>          $output .= '
                 <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
              </tr>';               </tr>';
             $rowtotal ++;              $rowtotal ++;
         if ($action eq 'autoupdate') {          if ($action eq 'autoupdate') {
Line 429  sub print_config_box { Line 463  sub print_config_box {
            <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.'>'.$item->{'header'}->[2]->{'col1'}.'</td>                <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
               <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>             </tr>'.                <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
             &print_usercreation('bottom',$dom,$settings,\$rowtotal);              &print_usercreation('bottom',$dom,$settings,\$rowtotal);
             $rowtotal ++;              $rowtotal ++;
         } elsif ($action eq 'usermodification') {          } elsif ($action eq 'usermodification') {
             $output .= &print_usermodification('bottom',$dom,$settings,\$rowtotal);              $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
              </table>
             </td>
            </tr>
            <tr>
              <td>
               <table class="LC_nested">
                <tr class="LC_info_row">
                 <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
                 <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
   
                          &print_usermodification('bottom',$dom,$settings,\$rowtotal);
               $rowtotal ++;
           } elsif ($action eq 'coursecategories') {
               $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
         } else {          } else {
             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'              $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
            </table>             </table>
Line 444  sub print_config_box { Line 492  sub print_config_box {
            <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.'>'.$item->{'header'}->[2]->{'col1'}.'</td>                <td class="LC_left_item"'.$colspan.' valign="top">'.
               <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>                 &mt($item->{'header'}->[2]->{'col1'}).'</td>
                 <td class="LC_right_item" valign="top">'.
                  &mt($item->{'header'}->[2]->{'col2'}).'</td>
              </tr>'.               </tr>'.
             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'              &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
            </table>             </table>
Line 455  sub print_config_box { Line 505  sub print_config_box {
            <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.'>'.$item->{'header'}->[3]->{'col1'}.'</td>                <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
               <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>                <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
              </tr>'.               </tr>'.
             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);              &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
             $rowtotal += 2;              $rowtotal += 2;
Line 469  sub print_config_box { Line 519  sub print_config_box {
              <tr class="LC_info_row">';               <tr class="LC_info_row">';
         if (($action eq 'login') || ($action eq 'directorysrch')) {          if (($action eq 'login') || ($action eq 'directorysrch')) {
             $output .= '                $output .= '  
               <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>';                <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
           } elsif ($action eq 'serverstatuses') {
               $output .= '
                 <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
                 '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
   
         } else {          } else {
             $output .= '              $output .= '
               <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>';                <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
         }          }
         my $colspan = ($action eq 'coursecategories')?' colspan="2"':'';          if (defined($item->{'header'}->[0]->{'col3'})) {
         $output .= '              $output .= '<td class="LC_left_item" valign="top">'.
               <td class="LC_right_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col2'}.'</td>                         &mt($item->{'header'}->[0]->{'col2'});
              </tr>';              if ($action eq 'serverstatuses') {
                   $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
               } 
           } else {
               $output .= '<td class="LC_right_item" valign="top">'.
                          &mt($item->{'header'}->[0]->{'col2'});
           }
           $output .= '</td>';
           if ($item->{'header'}->[0]->{'col3'}) {
               $output .= '<td class="LC_right_item" valign="top">'.
                          &mt($item->{'header'}->[0]->{'col3'});
               if ($action eq 'serverstatuses') {
                   $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
               }
               $output .= '</td>';
           }
           $output .= '</tr>';
         $rowtotal ++;          $rowtotal ++;
         if ($action eq 'login') {          if ($action eq 'login') {
             $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal);              $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal);
         } elsif ($action eq 'quotas') {          } elsif ($action eq 'quotas') {
             $output .= &print_quotas($dom,$settings,\$rowtotal);              $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
         } elsif ($action eq 'autoenroll') {          } elsif ($action eq 'autoenroll') {
             $output .= &print_autoenroll($dom,$settings,\$rowtotal);              $output .= &print_autoenroll($dom,$settings,\$rowtotal);
         } elsif ($action eq 'directorysrch') {          } elsif ($action eq 'directorysrch') {
Line 493  sub print_config_box { Line 564  sub print_config_box {
             $output .= &print_defaults($dom,\$rowtotal);              $output .= &print_defaults($dom,\$rowtotal);
         } elsif ($action eq 'scantron') {          } elsif ($action eq 'scantron') {
             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);              $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
         } elsif ($action eq 'coursecategories'){          } elsif ($action eq 'serverstatuses') {
             $output .= &print_coursecategories($dom,$item,$settings,\$rowtotal);              $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
           } elsif ($action eq 'requestcourses') {
               $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
         }          }
     }      }
     $output .= '      $output .= '
Line 638  sub print_login { Line 711  sub print_login {
                    );                     );
     foreach my $item (@images) {      foreach my $item (@images) {
         $defaults{$item} = $defaultdesign{'login.'.$item};          $defaults{$item} = $defaultdesign{'login.'.$item};
           $defaults{'showlogo'}{$item} = 1;
     }      }
     foreach my $item (@bgs) {      foreach my $item (@bgs) {
         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};          $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
Line 659  sub print_login { Line 733  sub print_login {
             }              }
         }          }
         foreach my $item (@images) {          foreach my $item (@images) {
             if ($settings->{$item} ne '') {              if (defined($settings->{$item})) {
                 $designs{$item} = $settings->{$item};                  $designs{$item} = $settings->{$item};
                 $is_custom{$item} = 1;                  $is_custom{$item} = 1;
             }              }
               if (defined($settings->{'showlogo'}{$item})) {
                   $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
               }
         }          }
         foreach my $item (@logintext) {          foreach my $item (@logintext) {
             if ($settings->{$item} ne '') {              if ($settings->{$item} ne '') {
Line 751  sub login_choices { Line 828  sub login_choices {
             bgs => "Background colors",              bgs => "Background colors",
             links => "Link colors",              links => "Link colors",
             font => "Font color",              font => "Font color",
             pgbg => "Page",              pgbg => "Header",
             mainbg => "Main panel",              mainbg => "Page",
             sidebg => "Side panel",              sidebg => "Login box",
             link => "Link",              link => "Link",
             alink => "Active link",              alink => "Active link",
             vlink => "Visited link",              vlink => "Visited link",
Line 856  sub display_color_options { Line 933  sub display_color_options {
  $itemcount ++;   $itemcount ++;
         $css_class = $itemcount%2?' class="LC_odd_row"':'';          $css_class = $itemcount%2?' class="LC_odd_row"':'';
         $datatable .= '<tr'.$css_class.'>'.          $datatable .= '<tr'.$css_class.'>'.
                       '<td>'.$choices->{$img}.'</td>';                        '<td>'.$choices->{$img};
         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);          my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
           if ($role eq 'login') {
               if ($img eq 'login') {
                   $login_hdr_pick =
                       &login_header_options($img,$role,$defaults,$is_custom,$choices,
                                             $loginheader);
                   $logincolors =
                       &login_text_colors($img,$role,$logintext,$phase,$choices,
                                               $designs);
               } elsif ($img ne 'domlogo') {
                   $datatable.= &logo_display_options($img,$defaults,$designs);
               }
           }
           $datatable .= '</td>';
         if ($designs->{$img} ne '') {          if ($designs->{$img} ne '') {
             $imgfile = $designs->{$img};              $imgfile = $designs->{$img};
     $img_import = ($imgfile =~ m{^/adm/});      $img_import = ($imgfile =~ m{^/adm/});
         } else {          } else {
             $imgfile = $defaults->{$img};              $imgfile = $defaults->{$img};
         }          }
         if ($img eq 'login') {  
             $login_hdr_pick = &login_header_options($img,$role,$defaults,$is_custom,$choices,  
                                                     $loginheader);  
             $logincolors =  
                 &login_text_colors($img,$role,$logintext,$phase,$choices,$designs);  
         }  
         if ($imgfile) {          if ($imgfile) {
             my ($showfile,$fullsize);              my ($showfile,$fullsize);
             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {              if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
Line 958  sub display_color_options { Line 1042  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>'.$choices->{$item}.'&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 id="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 1009  sub display_color_options { Line 1093  sub display_color_options {
     return $datatable;      return $datatable;
 }  }
   
   sub logo_display_options {
       my ($img,$defaults,$designs) = @_;
       my $checkedon;
       if (ref($defaults) eq 'HASH') {
           if (ref($defaults->{'showlogo'}) eq 'HASH') {
               if ($defaults->{'showlogo'}{$img}) {
                   $checkedon = 'checked="checked" ';     
               }
           } 
       }
       if (ref($designs) eq 'HASH') {
           if (ref($designs->{'showlogo'}) eq 'HASH') {
               if (defined($designs->{'showlogo'}{$img})) {
                   if ($designs->{'showlogo'}{$img} == 0) {
                       $checkedon = '';
                   } elsif ($designs->{'showlogo'}{$img} == 1) {
                       $checkedon = 'checked="checked" ';
                   }
               }
           }
       }
       return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
              'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
              &mt('show').'</label>'."\n";
   }
   
 sub login_header_options  {  sub login_header_options  {
     my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_;      my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_;
     my $image_checked = ' checked="checked" ';      my $image_checked = ' checked="checked" ';
Line 1060  sub image_changes { Line 1170  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 (!$is_custom) {      if (!$is_custom) {
         if ($img eq 'login') {          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 />';
Line 1137  ENDCOL Line 1247  ENDCOL
 }  }
   
 sub print_quotas {  sub print_quotas {
     my ($dom,$settings,$rowtotal) = @_;      my ($dom,$settings,$rowtotal,$action) = @_;
     my $datatable;      my $context;
       if ($action eq 'quotas') {
           $context = 'tools';
       } else {
           $context = $action;
       }
       my ($datatable,$defaultquota,@usertools);
     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);      my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
     my $typecount = 0;      my $typecount = 0;
     my $css_class;      my $css_class;
       if ($context eq 'requestcourses') {
           @usertools = ('official','unofficial');
       } else {
           @usertools = ('aboutme','blog','portfolio');
       }
       my %titles = &tool_titles();
     if (ref($types) eq 'ARRAY') {      if (ref($types) eq 'ARRAY') {
         foreach my $type (@{$types}) {          foreach my $type (@{$types}) {
               my $currdefquota;
               unless ($context eq 'requestcourses') {
                   if (ref($settings) eq 'HASH') {
                       if (ref($settings->{defaultquota}) eq 'HASH') {
                           $currdefquota = $settings->{defaultquota}->{$type}; 
                       } else {
                           $currdefquota = $settings->{$type};
                       }
                   }
               }
             if (defined($usertypes->{$type})) {              if (defined($usertypes->{$type})) {
                 $typecount ++;                  $typecount ++;
                 $css_class = $typecount%2?' class="LC_odd_row"':'';                  $css_class = $typecount%2?' class="LC_odd_row"':'';
                 $datatable .= '<tr'.$css_class.'>'.                   $datatable .= '<tr'.$css_class.'>'.
                               '<td>'.$usertypes->{$type}.'</td>'.                                '<td>'.$usertypes->{$type}.'</td>'.
                                 '<td class="LC_left_item">';
                   foreach my $item (@usertools) {
                       my $checked;
                       unless ($context eq 'requestcourses') {
                           $checked = 'checked="checked" ';
                       }
                       if (ref($settings) eq 'HASH') {
                           if (ref($settings->{$item}) eq 'HASH') {
                               if ($settings->{$item}->{$type} == 0) {
                                   $checked = '';
                               } elsif ($settings->{$item}->{$type} == 1) {
                                   $checked =  'checked="checked" ';
                               }
                           }
                       }
                       $datatable .= '<span class="LC_nobreak"><label>'.
                                     '<input type="checkbox" name="'.$context.'_'.$item.
                                     '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
                                     '</label></span>&nbsp; ';
                   }
                   $datatable .= '</td>';
                   unless ($context eq 'requestcourses') {
                       $datatable .= 
                               '<td class="LC_right_item"><span class="LC_nobreak">'.                                '<td class="LC_right_item"><span class="LC_nobreak">'.
                               '<input type="text" name="quota_'.$type.                                '<input type="text" name="quota_'.$type.
                               '" value="'.$settings->{$type}.                                '" value="'.$currdefquota.
                               '" size="5" /> Mb</span></td></tr>';                                '" size="5" /> Mb</span></td>';
                   }
                   $datatable .= '</tr>';
             }              }
         }          }
     }      }
     my $defaultquota = '20';      unless ($context eq 'requestcourses') {
     if (ref($settings) eq 'HASH') {          $defaultquota = '20';
         if (defined($settings->{'default'})) {          if (ref($settings) eq 'HASH') {
             $defaultquota = $settings->{'default'};              if (ref($settings->{'defaultquota'}) eq 'HASH') {
                   $defaultquota = $settings->{'defaultquota'}->{'default'};
               } elsif (defined($settings->{'default'})) {
                   $defaultquota = $settings->{'default'};
               }
         }          }
     }      }
     $typecount ++;      $typecount ++;
     $css_class = $typecount%2?' class="LC_odd_row"':'';      $css_class = $typecount%2?' class="LC_odd_row"':'';
     $datatable .= '<tr'.$css_class.'>'.      $datatable .= '<tr'.$css_class.'>'.
                   '<td>'.$othertitle.'</td>'.                    '<td>'.$othertitle.'</td>'.
                   '<td class="LC_right_item"><span class="LC_nobreak">'.                    '<td class="LC_left_item">';
                   '<input type="text" name="defaultquota" value="'.      foreach my $item (@usertools) {
                   $defaultquota.'" size="5" /> Mb</span></td></tr>';          my $checked;
           unless ($context eq 'requestcourses') {
               $checked = 'checked="checked" ';
           }
           if (ref($settings) eq 'HASH') {
               if (ref($settings->{$item}) eq 'HASH') {
                   if ($settings->{$item}->{'default'} == 0) {
                       $checked = '';
                   } elsif ($settings->{$item}->{'default'} == 1) {
                       $checked = 'checked="checked" ';
                   }
               }
           }
           $datatable .= '<span class="LC_nobreak"><label>'.
                         '<input type="checkbox" name="'.$context.'_'.$item.
                         '" value="default" '.$checked.'/>'.$titles{$item}.
                         '</label></span>&nbsp; ';
       }
       $datatable .= '</td>';
       unless ($context eq 'requestcourses') {
           $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
                         '<input type="text" name="defaultquota" value="'.
                         $defaultquota.'" size="5" /> Mb</span></td>';
       }
       $datatable .= '</tr>';
       $typecount ++;
       $css_class = $typecount%2?' class="LC_odd_row"':'';
       $datatable .= '<tr'.$css_class.'>'.
                     '<td><br/>'.&mt('LON-CAPA Advanced Users').'</td>'.
                     '<td class="LC_left_item" colspan="2"><br />';
       foreach my $item (@usertools) {
           my $checked;
           unless ($context eq 'requestcourses') {
               $checked = 'checked="checked" ';
           }
           if (ref($settings) eq 'HASH') {
               if (ref($settings->{$item}) eq 'HASH') {
                   if ($settings->{$item}->{'_LC_adv'} == 0) {
                       $checked = '';
                   } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
                       $checked = 'checked="checked" ';
                   }
               }
           }
           $datatable .= '<span class="LC_nobreak"><label>'.
                         '<input type="checkbox" name="'.$context.'_'.$item.
                         '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
                         '</label></span>&nbsp; ';
       }
       $datatable .= '<span class="LC_nobreak">('.&mt('overrides affiliation').
                     ')</span></td></tr>';
     $$rowtotal += $typecount;      $$rowtotal += $typecount;
     return $datatable;      return $datatable;
 }  }
Line 1442  sub print_contacts { Line 1653  sub print_contacts {
     my $rownum = 0;      my $rownum = 0;
     my $css_class;      my $css_class;
     foreach my $item (@contacts) {      foreach my $item (@contacts) {
         if ($rownum%2) {          $rownum ++;
             $css_class = '';          $css_class = $rownum%2?' class="LC_odd_row"':'';
         } else {  
             $css_class = ' class="LC_odd_row" ';  
         }  
         $datatable .= '<tr'.$css_class.'>'.           $datatable .= '<tr'.$css_class.'>'. 
                   '<td><span class="LC_nobreak">'.$titles->{$item}.                    '<td><span class="LC_nobreak">'.$titles->{$item}.
                   '</span></td><td class="LC_right_item">'.                    '</span></td><td class="LC_right_item">'.
                   '<input type="text" name="'.$item.'" value="'.                    '<input type="text" name="'.$item.'" value="'.
                   $to{$item}.'" /></td></tr>';                    $to{$item}.'" /></td></tr>';
         $rownum ++;  
     }      }
     foreach my $type (@mailings) {      foreach my $type (@mailings) {
         if ($rownum%2) {          $rownum ++;
             $css_class = '';          $css_class = $rownum%2?' class="LC_odd_row"':'';
         } else {  
             $css_class = ' class="LC_odd_row" ';  
         }  
         $datatable .= '<tr'.$css_class.'>'.          $datatable .= '<tr'.$css_class.'>'.
                       '<td><span class="LC_nobreak">'.                        '<td><span class="LC_nobreak">'.
                       $titles->{$type}.': </span></td>'.                        $titles->{$type}.': </span></td>'.
Line 1476  sub print_contacts { Line 1680  sub print_contacts {
                       '<input type="text" name="'.$type.'_others" '.                        '<input type="text" name="'.$type.'_others" '.
                       'value="'.$otheremails{$type}.'"  />'.                        'value="'.$otheremails{$type}.'"  />'.
                       '</td></tr>'."\n";                        '</td></tr>'."\n";
         $rownum ++;  
     }      }
     $$rowtotal += $rownum;      $$rowtotal += $rownum;
     return $datatable;      return $datatable;
Line 1485  sub print_contacts { Line 1688  sub print_contacts {
 sub contact_titles {  sub contact_titles {
     my %titles = &Apache::lonlocal::texthash (      my %titles = &Apache::lonlocal::texthash (
                    'supportemail' => 'Support E-mail address',                     'supportemail' => 'Support E-mail address',
                    'adminemail'    => 'Default Server Admin E-mail address',                     'adminemail'   => 'Default Server Admin E-mail address',
                    'errormail'    => 'Error reports to be e-mailed to',                     'errormail'    => 'Error reports to be e-mailed to',
                    'packagesmail' => 'Package update alerts to be e-mailed to',                     'packagesmail' => 'Package update alerts to be e-mailed to',
                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to'                     'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
Line 1497  sub contact_titles { Line 1700  sub contact_titles {
     return (\%titles,\%short_titles);      return (\%titles,\%short_titles);
 }  }
   
   sub tool_titles {
       my %titles = &Apache::lonlocal::texthash (
                        aboutme    => 'Personal Home Page',
                        blog       => 'Blog',
                        portfolio  => 'Portfolio',
                        official   => 'Official courses (with institutional codes)',                      unofficial => 'Unofficial courses',
                    );
       return %titles;
   }
   
 sub print_usercreation {  sub print_usercreation {
     my ($position,$dom,$settings,$rowtotal) = @_;      my ($position,$dom,$settings,$rowtotal) = @_;
     my $numinrow = 4;      my $numinrow = 4;
Line 1676  sub user_formats_row { Line 1889  sub user_formats_row {
                );                 );
     my $css_class = $rowcount%2?' class="LC_odd_row"':'';      my $css_class = $rowcount%2?' class="LC_odd_row"':'';
     $output = '<tr '.$css_class.'>'.      $output = '<tr '.$css_class.'>'.
               '<td><span class="LC_nobreak">'.                '<td><span class="LC_nobreak">';
               &mt("Format rules to check for $text{$type}: ").      if ($type eq 'email') {
               '</span></td>'.          $output .= &mt("Formats disallowed for $text{$type}: ");
               '<td class="LC_left_item" colspan="2"><table>';      } else {
           $output .= &mt("Format rules to check for $text{$type}: ");
       }
       $output .= '</span></td>'.
                  '<td class="LC_left_item" colspan="2"><table>';
     my $rem;      my $rem;
     if (ref($ruleorder) eq 'ARRAY') {      if (ref($ruleorder) eq 'ARRAY') {
         for (my $i=0; $i<@{$ruleorder}; $i++) {          for (my $i=0; $i<@{$ruleorder}; $i++) {
Line 1727  sub usercreation_types { Line 1944  sub usercreation_types {
                     any        => 'Any',                      any        => 'Any',
                     official   => 'Institutional only ',                      official   => 'Institutional only ',
                     unofficial => 'Non-institutional only',                      unofficial => 'Non-institutional only',
                     email      => 'Email address',                      email      => 'E-mail address',
                     login      => 'Institutional Login',                      login      => 'Institutional Login',
                     sso        => 'SSO',                       sso        => 'SSO', 
                     none       => 'None',                      none       => 'None',
Line 1767  sub print_usermodification { Line 1984  sub print_usermodification {
             $$rowtotal ++;              $$rowtotal ++;
             $rowcount ++;              $rowcount ++;
         }          }
     } else {      } elsif ($position eq 'middle') {
         $context = 'course';          $context = 'course';
         $rowcount = 0;          $rowcount = 0;
         foreach my $role ('st','ep','ta','in','cr') {          foreach my $role ('st','ep','ta','in','cr') {
Line 1776  sub print_usermodification { Line 1993  sub print_usermodification {
             $$rowtotal ++;              $$rowtotal ++;
             $rowcount ++;              $rowcount ++;
         }          }
       } elsif ($position eq 'bottom') {
           $context = 'selfcreate';
           my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
           $usertypes->{'default'} = $othertitle;
           if (ref($types) eq 'ARRAY') {
               push(@{$types},'default');
               $usertypes->{'default'} = $othertitle;
               foreach my $status (@{$types}) {
                   $datatable .= &modifiable_userdata_row($context,$status,$settings,
                                                          $numinrow,$rowcount,$usertypes);
                   $$rowtotal ++;
                   $rowcount ++;
               }
           }
     }      }
     return $datatable;      return $datatable;
 }  }
   
 sub print_defaults {  sub print_defaults {
     my ($dom,$rowtotal) = @_;      my ($dom,$rowtotal) = @_;
     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def');      my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
                    'datelocale_def');
     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);      my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
     my $titles = &defaults_titles();      my $titles = &defaults_titles();
     my $rownum = 0;      my $rownum = 0;
Line 1817  sub print_defaults { Line 2049  sub print_defaults {
         } elsif ($item eq 'timezone_def') {          } elsif ($item eq 'timezone_def') {
             my $includeempty = 1;              my $includeempty = 1;
             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);              $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
           } elsif ($item eq 'datelocale_def') {
               my $includeempty = 1;
               $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
         } else {          } else {
             $datatable .= '<input type="text" name="'.$item.'" value="'.              $datatable .= '<input type="text" name="'.$item.'" value="'.
                           $domdefaults{$item}.'" />';                            $domdefaults{$item}.'" />';
Line 1834  sub defaults_titles { Line 2069  sub defaults_titles {
                    'auth_arg_def'  => 'Default authentication argument',                     'auth_arg_def'  => 'Default authentication argument',
                    'lang_def'      => 'Default language',                     'lang_def'      => 'Default language',
                    'timezone_def'  => 'Default timezone',                     'timezone_def'  => 'Default timezone',
                      'datelocale_def' => 'Default locale for dates',
                  );                   );
     return (\%titles);      return (\%titles);
 }  }
Line 1841  sub defaults_titles { Line 2077  sub defaults_titles {
 sub print_scantronformat {  sub print_scantronformat {
     my ($r,$dom,$confname,$settings,$rowtotal) = @_;      my ($r,$dom,$confname,$settings,$rowtotal) = @_;
     my $itemcount = 1;      my $itemcount = 1;
     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls);      my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
           %confhash);
     my $switchserver = &check_switchserver($dom,$confname);      my $switchserver = &check_switchserver($dom,$confname);
     my %lt = &Apache::lonlocal::texthash (      my %lt = &Apache::lonlocal::texthash (
                 default => 'Default scantron format file error',                  default => 'Default scantron format file error',
Line 1868  sub print_scantronformat { Line 2105  sub print_scantronformat {
                     );                      );
                     my %md5chk;                      my %md5chk;
                     foreach my $type (keys(%legacyfile)) {                      foreach my $type (keys(%legacyfile)) {
                         $md5chk{$type} = split(/ /,`md5sum $legacyfile{$type}`);                          ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
                         chop($md5chk{$type});                          chomp($md5chk{$type});
                     }                      }
                     if ($md5chk{'default'} ne $md5chk{'custom'}) {                      if ($md5chk{'default'} ne $md5chk{'custom'}) {
                         foreach my $type (keys(%legacyfile)) {                          foreach my $type (keys(%legacyfile)) {
                             ($scantronurls{$type},$error{$type}) =                               ($scantronurls{$type},my $error) = 
                                 &legacy_scantronformat($r,$dom,$confname,                                  &legacy_scantronformat($r,$dom,$confname,
                                                  $type,$legacyfile{$type},                                                   $type,$legacyfile{$type},
                                                  $scantronurls{$type},                                                   $scantronurls{$type},
                                                  $scantronfiles{$type});                                                   $scantronfiles{$type});
                               if ($error ne '') {
                                   $error{$type} = $error;
                               }
                           }
                           if (keys(%error) == 0) {
                               $is_custom = 1;
                               $confhash{'scantron'}{'scantronformat'} = 
                                   $scantronurls{'custom'};
                               my $putresult = 
                                   &Apache::lonnet::put_dom('configuration',
                                                            \%confhash,$dom);
                               if ($putresult ne 'ok') {
                                   $error{'custom'} = 
                                       '<span class="LC_error">'.
                                       &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                               }
                         }                          }
                     } else {                      } else {
                         ($scantronurls{'default'},$error{'default'}) =                          ($scantronurls{'default'},my $error) =
                             &legacy_scantronformat($r,$dom,$confname,                              &legacy_scantronformat($r,$dom,$confname,
                                           'default',$legacyfile{'default'},                                            'default',$legacyfile{'default'},
                                           $scantronurls{'default'},                                            $scantronurls{'default'},
                                           $scantronfiles{'default'});                                            $scantronfiles{'default'});
                           if ($error eq '') {
                               $confhash{'scantron'}{'scantronformat'} = ''; 
                               my $putresult =
                                   &Apache::lonnet::put_dom('configuration',
                                                            \%confhash,$dom);
                               if ($putresult ne 'ok') {
                                   $error{'default'} =
                                       '<span class="LC_error">'.
                                       &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
                               }
                           } else {
                               $error{'default'} = $error;
                           }
                     }                      }
                 }                  }
             }              }
Line 1905  sub print_scantronformat { Line 2171  sub print_scantronformat {
             $scantronurl = $scantronurls{'default'};              $scantronurl = $scantronurls{'default'};
         }          }
     } else {      } else {
         $scantronurl = $scantronurls{'default'};          if ($is_custom) {
               $scantronurl = $scantronurls{'custom'};
           } else {
               $scantronurl = $scantronurls{'default'};
           }
     }      }
     $css_class = $itemcount%2?' class="LC_odd_row"':'';      $css_class = $itemcount%2?' class="LC_odd_row"':'';
     $datatable .= '<tr'.$css_class.'>';      $datatable .= '<tr'.$css_class.'>';
     if (!$is_custom) {      if (!$is_custom) {
         $datatable .= '<td>'.&mt('Default in use:').'<br />';          $datatable .= '<td>'.&mt('Default in use:').'<br />'.
                         '<span class="LC_nobreak">';
         if ($scantronurl) {          if ($scantronurl) {
             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.              $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
                           &mt('Default scantron format file').'</a>';                            &mt('Default scantron format file').'</a>';
         } else {          } else {
             $datatable = &mt('File unavailable for display');              $datatable = &mt('File unavailable for display');
         }          }
         $datatable .= '</td><td valign="bottom">'.&mt('Upload:').'<br />';          $datatable .= '</span></td>';
           if (keys(%error) == 0) { 
               $datatable .= '<td valign="bottom">';
               if (!$switchserver) {
                   $datatable .= &mt('Upload:').'<br />';
               }
           } else {
               my $errorstr;
               foreach my $key (sort(keys(%error))) {
                   $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
               }
               $datatable .= '<td>'.$errorstr;
           }
     } else {      } else {
         if (keys(%error) > 0) {          if (keys(%error) > 0) {
             my $errorstr;              my $errorstr;
             foreach my $key (sort(keys(%error))) {              foreach my $key (sort(keys(%error))) {
                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';                  $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
             }               } 
             $datatable .= '<td>'.$errorstr.'</td><td>';              $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
         } elsif ($scantronurl) {          } elsif ($scantronurl) {
             $datatable .= '<td><a href="'.$scantronurl.'" target="_blank">'                          .&mt('Custom scantron format file').'</a>'              $datatable .= '<td><span class="LC_nobreak">'.
                           .'<span class="LC_nobreak"><label>'                            '<a href="'.$scantronurl.'" target="_blank">'.
                           .'<input type="checkbox" name="scantronformat_del"'                            &mt('Custom scantron format file').'</a><label>'.
                           .'" value="1" />'.&mt('Delete?').'</label></td>'                            '<input type="checkbox" name="scantronformat_del"'.
                           .'<td>'.&mt('Replace:').'</span><br />';                            '" value="1" />'.&mt('Delete?').'</label></span></td>'.
                             '<td><span class="LC_nobreak">&nbsp;'.
                             &mt('Replace:').'</span><br />';
         }          }
     }      }
     if (keys(%error) == 0) {      if (keys(%error) == 0) {
         if ($switchserver) {          if ($switchserver) {
             $datatable .= &mt('Upload to library server: [_1]',$switchserver);              $datatable .= &mt('Upload to library server: [_1]',$switchserver);
         } else {          } else {
             $datatable .='&nbsp;<input type="file" name="scantronformat" />';              $datatable .='<span class="LC_nobreak">&nbsp;'.
                            '<input type="file" name="scantronformat" /></span>';
         }          }
     }      }
     $datatable .= '</td></tr>';      $datatable .= '</td></tr>';
Line 1961  sub legacy_scantronformat { Line 2247  sub legacy_scantronformat {
 }  }
   
 sub print_coursecategories {  sub print_coursecategories {
     my ($dom,$hdritem,$settings,$rowtotal) = @_;      my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
     my ($datatable,$css_class);      my $datatable;
     my $itemcount = 1;      if ($position eq 'top') {
     if (ref($settings) eq 'HASH') {          my $toggle_cats_crs = ' ';
         my (@cats,@trails,%allitems,%idx,@jsarray);          my $toggle_cats_dom = ' checked="checked" ';
         &Apache::loncommon::extract_categories($settings,\@cats,\@trails,          my $can_cat_crs = ' ';
                                                \%allitems,\%idx,\@jsarray);          my $can_cat_dom = ' checked="checked" ';
         my $maxdepth = scalar(@cats);          if (ref($settings) eq 'HASH') {
         my $colattrib = '';              if ($settings->{'togglecats'} eq 'crs') {
         if ($maxdepth > 2) {                  $toggle_cats_crs = $toggle_cats_dom;
             $colattrib = ' colspan="2" ';                  $toggle_cats_dom = ' ';
         }              }
         my @path;              if ($settings->{'categorize'} eq 'crs') {
         if (@cats > 0) {                  $can_cat_crs = $can_cat_dom;
             if (ref($cats[0]) eq 'ARRAY') {                  $can_cat_dom = ' ';
                 my $numtop = @{$cats[0]};              }
                 my $maxnum = $numtop;          }
                 if ((!grep(/^instcode$/,@{$cats[0]})) || ($settings->{'instcode::0'} eq '')) {          my %title = &Apache::lonlocal::texthash (
                     $maxnum ++;                       togglecats => 'Show/Hide a course in the catalog',
                 }                       categorize    => 'Assign a category to a course',
                 my $lastidx;                      );
                 for (my $i=0; $i<$numtop; $i++) {          my %level = &Apache::lonlocal::texthash (
                     my $parent = $cats[0][$i];                       dom => 'Set in "Modify Course" (Domain)',
                        crs => 'Set in "Modify Parameters" (Course)',   
                       );
           $datatable = '<tr class="LC_odd_row">'.
                     '<td>'.$title{'togglecats'}.'</td>'.
                     '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                     '<input type="radio" name="togglecats"'.
                     $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                     '<label><input type="radio" name="togglecats"'.
                     $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
                     '</tr><tr>'.
                     '<td>'.$title{'categorize'}.'</td>'.
                     '<td class="LC_right_item"><span class="LC_nobreak">'.
                     '<label><input type="radio" name="categorize"'.
                     $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
                     '<label><input type="radio" name="categorize"'.
                     $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
                     '</tr>';
           $$rowtotal += 2;
       } else {
           my $css_class;
           my $itemcount = 1;
           my $cathash; 
           if (ref($settings) eq 'HASH') {
               $cathash = $settings->{'cats'};
           }
           if (ref($cathash) eq 'HASH') {
               my (@cats,@trails,%allitems,%idx,@jsarray);
               &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
                                                      \%allitems,\%idx,\@jsarray);
               my $maxdepth = scalar(@cats);
               my $colattrib = '';
               if ($maxdepth > 2) {
                   $colattrib = ' colspan="2" ';
               }
               my @path;
               if (@cats > 0) {
                   if (ref($cats[0]) eq 'ARRAY') {
                       my $numtop = @{$cats[0]};
                       my $maxnum = $numtop;
                       if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
                           $maxnum ++;
                       }
                       my $lastidx;
                       for (my $i=0; $i<$numtop; $i++) {
                           my $parent = $cats[0][$i];
                           $css_class = $itemcount%2?' class="LC_odd_row"':'';
                           my $item = &escape($parent).'::0';
                           my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
                           $lastidx = $idx{$item};
                           $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                                         .'<select name="'.$item.'"'.$chgstr.'>';
                           for (my $k=0; $k<=$maxnum; $k++) {
                               my $vpos = $k+1;
                               my $selstr;
                               if ($k == $i) {
                                   $selstr = ' selected="selected" ';
                               }
                               $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                           }
                           $datatable .= '</select></td><td>';
                           if ($parent eq 'instcode') {
                               $datatable .=  '<span class="LC_nobreak">'.&mt('Official courses')
                                              .'</span><br /><span class="LC_nobreak">('
                                              .&mt('with institutional codes').')</span></td>'
                                              .'<td'.$colattrib.'><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" checked="checked" />'
                                               .&mt('Display').'</label>&nbsp;'
                                               .'<label><input type="radio" name="instcode" value="0" />'
                                               .&mt('Do not display').'</label></span></td>';
                           } else {
                               $datatable .= $parent
                                             .'&nbsp;<label><input type="checkbox" name="deletecategory" '
                                             .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
                           }
                           my $depth = 1;
                           push(@path,$parent);
                           $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
                           pop(@path);
                           $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                           $itemcount ++;
                       }
                     $css_class = $itemcount%2?' class="LC_odd_row"':'';                      $css_class = $itemcount%2?' class="LC_odd_row"':'';
                     my $item = &escape($parent).'::0';                      my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';                      $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
                     $lastidx = $idx{$item};  
                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'  
                                   .'<select name="'.$item.'"'.$chgstr.'>';  
                     for (my $k=0; $k<=$maxnum; $k++) {                      for (my $k=0; $k<=$maxnum; $k++) {
                         my $vpos = $k+1;                          my $vpos = $k+1;
                         my $selstr;                          my $selstr;
                         if ($k == $i) {                          if ($k == $numtop) {
                             $selstr = ' selected="selected" ';                              $selstr = ' selected="selected" ';
                         }                          }
                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';                          $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                     }                      }
                     $datatable .= '</select></td><td>';                      $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
                     if ($parent eq 'instcode') {                                    .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
                         $datatable .=  '<span class="LC_nobreak">'.&mt('Official courses')                                    .'</tr>'."\n";
                                        .'</span><br /><span class="LC_nobreak">('  
                                        .&mt('with institutional codes').')</span></td>'  
                                        .'<td'.$colattrib.'><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" checked="checked" />'  
                                         .&mt('Display').'</label>&nbsp;'  
                                         .'<label><input type="radio" name="instcode" value="0" />'  
                                         .&mt('Do not display').'</label></span></td>';  
                     } else {  
                         $datatable .= $parent  
                                       .'&nbsp;<label><input type="checkbox" name="deletecategory" '  
                                       .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';  
                     }  
                     my $depth = 1;  
                     push(@path,$parent);  
                     $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);  
                     pop(@path);  
                     $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';  
                     $itemcount ++;                      $itemcount ++;
                 }                      if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
                 $css_class = $itemcount%2?' class="LC_odd_row"':'';                          $css_class = $itemcount%2?' class="LC_odd_row"':'';
                 my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';                          my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"';
                 $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';                          $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                 for (my $k=0; $k<=$maxnum; $k++) {                                        '<span class="LC_nobreak"><select name="instcode_pos"'.$chgstr.'>';
                     my $vpos = $k+1;                          for (my $k=0; $k<=$maxnum; $k++) {
                     my $selstr;                              my $vpos = $k+1;
                     if ($k == $numtop) {                              my $selstr;
                         $selstr = ' selected="selected" ';                              if ($k == $maxnum) {
                     }                                  $selstr = ' selected="selected" ';
                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';                              }
                 }                              $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                 $datatable .= '</select></span></td><td colspan="2">'.&mt('New:').'&nbsp;'  
                               .'<input type="text" size="20" name="addcategory_name" value="" /></td>'  
                               .'</tr>'."\n";  
                 $itemcount ++;  
                 if ((!grep(/^instcode$/,@{$cats[0]})) || ($settings->{'instcode::0'} eq '')) {  
                     $css_class = $itemcount%2?' class="LC_odd_row"':'';  
                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"';  
                     $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.  
                                   '<span class="LC_nobreak"><select name="instcode_pos"'.$chgstr.'>';  
                     for (my $k=0; $k<=$maxnum; $k++) {  
                         my $vpos = $k+1;  
                         my $selstr;  
                         if ($k == $maxnum) {  
                             $selstr = ' selected="selected" ';  
                         }                          }
                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';                          $datatable .= '</select></span></td><td><span class="LC_nobreak">'
                                         .&mt('Official courses').'</span>'.'<br /><span class="LC_nobreak">('
                                         .&mt('with institutional codes').')</span></td>'
                                         .'<td><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" />'
                                         .&mt('Display').'</label>&nbsp;'
                                         .'<label><input type="radio" name="instcode" value="0" checked="checked"/>'
                                         .&mt('Do not display').'</label></span></td></tr>';
                     }                      }
                     $datatable .= '</select></span></td><td><span class="LC_nobreak">'  
                                   .&mt('Official courses').'</span>'.'<br /><span class="LC_nobreak">('  
                                   .&mt('with institutional codes').')</span></td>'  
                                   .'<td><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" />'  
                                   .&mt('Display').'</label>&nbsp;'  
                                   .'<label><input type="radio" name="instcode" value="0" checked="checked"/>'  
                                   .&mt('Do not display').'</label></span></td></tr>';  
                 }                  }
               } else {
                   $datatable .= &initialize_categories($itemcount);
             }              }
         } else {          } else {
             $datatable .= &initialize_categories($itemcount);              $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
                             .&initialize_categories($itemcount);
         }          }
     } else {          $$rowtotal += $itemcount;
         $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'  
                       .&initialize_categories($itemcount);  
     }      }
     $$rowtotal += $itemcount;  
     return $datatable;      return $datatable;
 }  }
   
   sub print_serverstatuses {
       my ($dom,$settings,$rowtotal) = @_;
       my $datatable;
       my @pages = &serverstatus_pages();
       my (%namedaccess,%machineaccess);
       foreach my $type (@pages) {
           $namedaccess{$type} = '';
           $machineaccess{$type}= '';
       }
       if (ref($settings) eq 'HASH') {
           foreach my $type (@pages) {
               if (exists($settings->{$type})) {
                   if (ref($settings->{$type}) eq 'HASH') {
                       foreach my $key (keys(%{$settings->{$type}})) {
                           if ($key eq 'namedusers') {
                               $namedaccess{$type} = $settings->{$type}->{$key};
                           } elsif ($key eq 'machines') {
                               $machineaccess{$type} = $settings->{$type}->{$key};
                           }
                       }
                   }
               }
           }
       }
       my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
       my $rownum = 0;
       my $css_class;
       foreach my $type (@pages) {
           $rownum ++;
           $css_class = $rownum%2?' class="LC_odd_row"':'';
           $datatable .= '<tr'.$css_class.'>'.
                         '<td><span class="LC_nobreak">'.
                         $titles->{$type}.'</span></td>'.
                         '<td class="LC_left_item">'.
                         '<input type="text" name="'.$type.'_namedusers" '.
                         'value="'.$namedaccess{$type}.'" size="30" /></td>'.
                         '<td class="LC_right_item">'.
                         '<span class="LC_nobreak">'.
                         '<input type="text" name="'.$type.'_machines" '.
                         'value="'.$machineaccess{$type}.'" size="10" />'.
                         '</td></tr>'."\n";
       }
       $$rowtotal += $rownum;
       return $datatable;
   }
   
   sub serverstatus_pages {
       return ('userstatus','lonstatus','loncron','server-status','codeversions',
               'clusterstatus','metadata_keywords','metadata_harvest',
               'takeoffline','takeonline','showenv');
   }
   
 sub coursecategories_javascript {  sub coursecategories_javascript {
     my ($settings) = @_;      my ($settings) = @_;
     my ($output,$jstext);      my ($output,$jstext,$cathash);
     if (ref($settings) eq 'HASH') {      if (ref($settings) eq 'HASH') {
           $cathash = $settings->{'cats'};
       }
       if (ref($cathash) eq 'HASH') {
         my (@cats,@jsarray,%idx);          my (@cats,@jsarray,%idx);
         &Apache::loncommon::gather_categories($settings,\@cats,\%idx,\@jsarray);          &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
         if (@jsarray > 0) {          if (@jsarray > 0) {
             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";              $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
             for (my $i=0; $i<@jsarray; $i++) {              for (my $i=0; $i<@jsarray; $i++) {
Line 2227  sub build_category_rows { Line 2614  sub build_category_rows {
                             pop(@{$path});                              pop(@{$path});
                         }                          }
                     } else {                      } else {
                         $text .= &mt('New:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';                          $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
                         if ($j == $numchildren) {                          if ($j == $numchildren) {
                             $text .= $name;                              $text .= $name;
                         } else {                          } else {
Line 2259  sub build_category_rows { Line 2646  sub build_category_rows {
 }  }
   
 sub modifiable_userdata_row {  sub modifiable_userdata_row {
     my ($context,$role,$settings,$numinrow,$rowcount) = @_;      my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
     my $rolename;      my $rolename;
     if ($role eq 'cr') {      if ($context eq 'selfcreate') {
         $rolename = &mt('Custom role');          if (ref($usertypes) eq 'HASH') {
               $rolename = $usertypes->{$role};
           } else {
               $rolename = $role;
           }
     } else {      } else {
         $rolename = &Apache::lonnet::plaintext($role);          if ($role eq 'cr') {
               $rolename = &mt('Custom role');
           } else {
               $rolename = &Apache::lonnet::plaintext($role);
           }
     }      }
     my @fields = ('lastname','firstname','middlename','generation',      my @fields = ('lastname','firstname','middlename','generation',
                   'permanentemail','id');                    'permanentemail','id');
Line 2614  sub modify_colors { Line 3009  sub modify_colors {
             $domconfig->{$role} = {};              $domconfig->{$role} = {};
         }          }
         foreach my $img (@images) {          foreach my $img (@images) {
               if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
                   if (defined($env{'form.login_showlogo_'.$img})) {
                       $confhash->{$role}{'showlogo'}{$img} = 1;
                   } else { 
                       $confhash->{$role}{'showlogo'}{$img} = 0;
                   }
               } 
     if ( ! $env{'form.'.$role.'_'.$img.'.filename'}       if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
  && !defined($domconfig->{$role}{$img})   && !defined($domconfig->{$role}{$img})
  && !$env{'form.'.$role.'_del_'.$img}   && !$env{'form.'.$role.'_del_'.$img}
Line 2688  sub modify_colors { Line 3090  sub modify_colors {
                             $changes{$role}{'images'}{$img} = 1;                              $changes{$role}{'images'}{$img} = 1;
                         }                           } 
                     }                      }
                 }                        if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
                           if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
                               if ($confhash->{$role}{'showlogo'}{$img} ne 
                                   $domconfig->{$role}{'showlogo'}{$img}) {
                                   $changes{$role}{'showlogo'}{$img} = 1; 
                               }
                           } else {
                               if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                                   $changes{$role}{'showlogo'}{$img} = 1;
                               }
                           }
                       }
                   }
                 if ($domconfig->{$role}{'font'} ne '') {                  if ($domconfig->{$role}{'font'} ne '') {
                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {                      if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                         $changes{$role}{'font'} = 1;                          $changes{$role}{'font'} = 1;
Line 2780  sub default_change_checker { Line 3194  sub default_change_checker {
             $confhash->{$role}{$img} = '';              $confhash->{$role}{$img} = '';
             $changes->{$role}{'images'}{$img} = 1;              $changes->{$role}{'images'}{$img} = 1;
         }          }
           if ($role eq 'login') {
               if ($confhash->{$role}{'showlogo'}{$img} == 0) {
                   $changes->{$role}{'showlogo'}{$img} = 1;
               }
           }
     }      }
     if ($confhash->{$role}{'font'}) {      if ($confhash->{$role}{'font'}) {
         $changes->{$role}{'font'} = 1;          $changes->{$role}{'font'} = 1;
Line 2811  sub display_colorchgs { Line 3230  sub display_colorchgs {
                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';                          $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                     }                      }
                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {                      foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
                         if ($confhash->{$role}{$item} eq '') {                          if (($role eq 'login') && ($key eq 'showlogo')) {
                               if ($confhash->{$role}{$key}{$item}) {
                                   $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
                               } else {
                                   $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
                               }
                           } elsif ($confhash->{$role}{$item} eq '') {
                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';                              $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                         } else {                          } else {
                             my $newitem = $confhash->{$role}{$item};                              my $newitem = $confhash->{$role}{$item};
Line 3129  END Line 3554  END
 }  }
   
 sub modify_quotas {  sub modify_quotas {
     my ($dom,%domconfig) = @_;      my ($dom,$action,%domconfig) = @_;
       my ($context,@usertools);
       if ($action eq 'quotas') {
           $context = 'tools'; 
       } else { 
           $context = $action;
       }
       if ($context eq 'requestcourses') {
           @usertools = ('official','unofficial');
       } else {
           @usertools = ('aboutme','blog','portfolio');
       }
       my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
     my ($resulttext,%changes);      my ($resulttext,%changes);
     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);      my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
     my %formhash;      my %titles = &tool_titles();
       my (%confhash,%toolshash);
     foreach my $key (keys(%env)) {      foreach my $key (keys(%env)) {
         if ($key =~ /^form\.quota_(.+)$/) {          unless ($context eq 'requestcourses') {
             $formhash{$1} = $env{$key};              if ($key =~ /^form\.quota_(.+)$/) {
                   $confhash{'defaultquota'}{$1} = $env{$key};
               }
           }
           if ($key =~ /^form\.\Q$context\E_(.+)$/) {
               @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
         }          }
     }      }
     $formhash{'default'} = $env{'form.defaultquota'};      unless ($context eq 'requestcourses') {
     if (ref($domconfig{'quotas'}) eq 'HASH') {          $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
         foreach my $key (keys(%{$domconfig{'quotas'}})) {      }
             if (exists($formhash{$key})) {      foreach my $item (@usertools) {
                 if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {          foreach my $type (@{$types},'default','_LC_adv') {
                     $changes{$key} = 1;              if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
                   $confhash{$item}{$type} = 1;
               } else {
                   $confhash{$item}{$type} = 0;
               }
               if (ref($domconfig{$action}) eq 'HASH') {
                   if (ref($domconfig{$action}{$item}) eq 'HASH') {
                       if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
                           $changes{$item}{$type} = 1;
                       }
                   } else {
                       if ($context eq 'requestcourses') {
                           if ($confhash{$item}{$type}) {
                               $changes{$item}{$type} = 1;
                           }
                       } else {
                           if (!$confhash{$item}{$type}) {
                               $changes{$item}{$type} = 1;
                           }
                       }
                 }                  }
             } else {              } else {
                 $formhash{$key} = $domconfig{'quotas'}{$key};                  if ($context eq 'requestcourses') {
                       if ($confhash{$item}{$type}) {
                           $changes{$item}{$type} = 1;
                       }
                   } else {
                       if (!$confhash{$item}{$type}) {
                           $changes{$item}{$type} = 1;
                       }
                   }
             }              }
         }          }
     }      }
     foreach my $key (keys(%formhash)) {      unless ($context eq 'requestcourses') {
         if ($formhash{$key} ne '') {          if (ref($domconfig{'quotas'}) eq 'HASH') {
             if (ref($domconfig{'quotas'}) eq 'HASH') {              if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                 if (!exists($domconfig{'quotas'}{$key})) {                  foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
                     $changes{$key} = 1;                      if (exists($confhash{'defaultquota'}{$key})) {
                           if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
                               $changes{'defaultquota'}{$key} = 1;
                           }
                       } else {
                           $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
                       }
                 }                  }
             } else {              } else {
                 $changes{$key} = 1;                  foreach my $key (keys(%{$domconfig{'quotas'}})) {
                       if (exists($confhash{'defaultquota'}{$key})) {
                           if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
                               $changes{'defaultquota'}{$key} = 1;
                           }
                       } else {
                           $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
                       }
                   }
               }
           }
           if (ref($confhash{'defaultquota'}) eq 'HASH') {
               foreach my $key (keys(%{$confhash{'defaultquota'}})) {
                   if (ref($domconfig{'quotas'}) eq 'HASH') {
                       if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
                           if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
                               $changes{'defaultquota'}{$key} = 1;
                           }
                       } else {
                           if (!exists($domconfig{'quotas'}{$key})) {
                               $changes{'defaultquota'}{$key} = 1;
                           }
                       }
                   } else {
                       $changes{'defaultquota'}{$key} = 1;
                   }
             }              }
         }          }
     }      }
   
       foreach my $key (keys(%confhash)) {
           $domdefaults{$key} = $confhash{$key};
       }
      
     my %quotahash = (      my %quotahash = (
                       quotas => {%formhash},                        $action => { %confhash }
                     );                      );
     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,      my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                                              $dom);                                               $dom);
     if ($putresult eq 'ok') {      if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {          if (keys(%changes) > 0) {
               my $cachetime = 24*60*60;
               &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
   
             $resulttext = &mt('Changes made:').'<ul>';              $resulttext = &mt('Changes made:').'<ul>';
             foreach my $type (@{$types},'default') {              unless ($context eq 'requestcourses') {
                 if (defined($changes{$type})) {                   if (ref($changes{'defaultquota'}) eq 'HASH') {
                     my $typetitle = $usertypes->{$type};                      $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
                     if ($type eq 'default') {                      foreach my $type (@{$types},'default') {
                         $typetitle = $othertitle;                          if (defined($changes{'defaultquota'}{$type})) {
                               my $typetitle = $usertypes->{$type};
                               if ($type eq 'default') {
                                   $typetitle = $othertitle;
                               }
                               $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
                           }
                     }                      }
                     $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';                      $resulttext .= '</ul></li>';
                   }
               }
               my %newenv;
               foreach my $item (@usertools) {
                   if (ref($changes{$item}) eq 'HASH') {
                       my $newacc = 
                           &Apache::lonnet::usertools_access($env{'user.name'},
                                                             $env{'user.domain'},
                                                             $item,'reload',$context);
                       if ($context eq 'requestcourses') {
                           if ($env{'environment.canrequest.'.$item} ne $newacc) {
                               $newenv{'environment.canrequest.'.$item} = $newacc;
                           }
                       } else {
                           if ($env{'environment.availabletools.'.$item} ne $newacc) { 
                               $newenv{'environment.availabletools.'.$item} = $newacc;
                           }
                       }
                       $resulttext .= '<li>'.$titles{$item}.'<ul>';
                       foreach my $type (@{$types},'default','_LC_adv') {
                           if ($changes{$item}{$type}) {
                               my $typetitle = $usertypes->{$type};
                               if ($type eq 'default') {
                                   $typetitle = $othertitle;
                               } elsif ($type eq '_LC_adv') {
                                   $typetitle = 'LON-CAPA Advanced Users'; 
                               }
                               if ($confhash{$item}{$type}) {
                                   $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
                               } else {
                                   $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
                               }
                           }
                       }
                       $resulttext .= '</ul></li>';
                 }                  }
             }              }
             $resulttext .= '</ul>';              $resulttext .= '</ul>';
               if (keys(%newenv)) {
                   &Apache::lonnet::appenv(\%newenv);
               }
         } else {          } else {
             $resulttext = &mt('No changes made to default quotas');              if ($context eq 'requestcourses') {
                   $resulttext = &mt('No changes made to rights to request creation of courses.');
               } else {
                   $resulttext = &mt('No changes made to availability of home pages, blogs, portfolios or default quotas');
               }
         }          }
     } else {      } else {
         $resulttext = '<span class="LC_error">'.          $resulttext = '<span class="LC_error">'.
Line 3987  sub modify_usermodification { Line 4544  sub modify_usermodification {
             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};              $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
         }          }
     }      }
     my @contexts = ('author','course');      my @contexts = ('author','course','selfcreate');
     my %context_title = (      my %context_title = (
                            author => 'In author context',                             author => 'In author context',
                            course => 'In course context',                             course => 'In course context',
                              selfcreate => 'When self creating account', 
                         );                          );
     my @fields = ('lastname','firstname','middlename','generation',      my @fields = ('lastname','firstname','middlename','generation',
                   'permanentemail','id');                    'permanentemail','id');
Line 3998  sub modify_usermodification { Line 4556  sub modify_usermodification {
                   author => ['ca','aa'],                    author => ['ca','aa'],
                   course => ['st','ep','ta','in','cr'],                    course => ['st','ep','ta','in','cr'],
                 );                  );
       my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
       if (ref($types) eq 'ARRAY') {
           push(@{$types},'default');
           $usertypes->{'default'} = $othertitle;
       }
       $roles{'selfcreate'} = $types;  
     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();      my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
     my %modifyhash;      my %modifyhash;
     foreach my $context (@contexts) {      foreach my $context (@contexts) {
Line 4045  sub modify_usermodification { Line 4609  sub modify_usermodification {
                     if (ref($changes{$context}) eq 'ARRAY') {                      if (ref($changes{$context}) eq 'ARRAY') {
                         foreach my $role (@{$changes{$context}}) {                          foreach my $role (@{$changes{$context}}) {
                             my $rolename;                              my $rolename;
                             if ($role eq 'cr') {                              if ($context eq 'selfcreate') {
                                 $rolename = &mt('Custom');                                  $rolename = $role;
                                   if (ref($usertypes) eq 'HASH') {
                                       if ($usertypes->{$role} ne '') {
                                           $rolename = $usertypes->{$role};
                                       }
                                   }
                             } else {                              } else {
                                 $rolename = &Apache::lonnet::plaintext($role);                                  if ($role eq 'cr') {
                                       $rolename = &mt('Custom');
                                   } else {
                                       $rolename = &Apache::lonnet::plaintext($role);
                                   }
                             }                              }
                             my @modifiable;                              my @modifiable;
                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');                              if ($context eq 'selfcreate') {
                                   $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Self-creation of account by users with status: [_1]  ',$rolename).'</span> - '.&mt('modifiable fields (if institutional data blank): ');
                               } else {
                                   $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                               }
                             foreach my $field (@fields) {                              foreach my $field (@fields) {
                                 if ($modifyhash{$context}{$role}{$field}) {                                  if ($modifyhash{$context}{$role}{$field}) {
                                     push(@modifiable,$fieldtitles{$field});                                      push(@modifiable,$fieldtitles{$field});
Line 4083  sub modify_defaults { Line 4660  sub modify_defaults {
     my ($dom,$r) = @_;      my ($dom,$r) = @_;
     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);      my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);      my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def');      my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
     my @authtypes = ('internal','krb4','krb5','localauth');      my @authtypes = ('internal','krb4','krb5','localauth');
     foreach my $item (@items) {      foreach my $item (@items) {
         $newvalues{$item} = $env{'form.'.$item};          $newvalues{$item} = $env{'form.'.$item};
Line 4106  sub modify_defaults { Line 4683  sub modify_defaults {
             }              }
         } elsif ($item eq 'timezone_def') {          } elsif ($item eq 'timezone_def') {
             if ($newvalues{$item} ne '') {              if ($newvalues{$item} ne '') {
                 my @timezones = &DateTime::TimeZone->all_names;                  if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
                 if (!grep(/^\Q$newvalues{$item}\E/,@timezones)) {  
                     push(@errors,$item);                         push(@errors,$item);   
                 }                  }
             }              }
           } elsif ($item eq 'datelocale_def') {
               if ($newvalues{$item} ne '') {
                   my @datelocale_ids = DateTime::Locale->ids();
                   if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
                       push(@errors,$item);
                   }
               }
         }          }
         if (grep(/^\Q$item\E$/,@errors)) {          if (grep(/^\Q$item\E$/,@errors)) {
             $newvalues{$item} = $domdefaults{$item};              $newvalues{$item} = $domdefaults{$item};
         } elsif ($domdefaults{$item} ne $newvalues{$item}) {          } elsif ($domdefaults{$item} ne $newvalues{$item}) {
             $changes{$item} = 1;              $changes{$item} = 1;
         }          }
           $domdefaults{$item} = $newvalues{$item};
     }      }
     my %defaults_hash = (      my %defaults_hash = (
                          defaults => { auth_def => $newvalues{'auth_def'},                           defaults => \%newvalues,
                                        auth_arg_def => $newvalues{'auth_arg_def'},                          );
                                        lang_def => $newvalues{'lang_def'},  
                                        timezone_def => $newvalues{'timezone_def'},  
                                      }  
                        );  
     my $title = &defaults_titles();      my $title = &defaults_titles();
     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,      my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
                                              $dom);                                               $dom);
Line 4153  sub modify_defaults { Line 4733  sub modify_defaults {
             $resulttext .= '</ul>';              $resulttext .= '</ul>';
             $mailmsgtext .= "\n";              $mailmsgtext .= "\n";
             my $cachetime = 24*60*60;              my $cachetime = 24*60*60;
             &Apache::lonnet::do_cache_new('domdefaults',$dom,              &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
                                           $defaults_hash{'defaults'},$cachetime);              if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'}) {  
                 my $sysmail = $r->dir_config('lonSysEMail');                  my $sysmail = $r->dir_config('lonSysEMail');
                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);                  &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
             }              }
Line 4257  sub modify_scantron { Line 4836  sub modify_scantron {
   
 sub modify_coursecategories {  sub modify_coursecategories {
     my ($dom,%domconfig) = @_;      my ($dom,%domconfig) = @_;
     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,$errors);      my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
           $cathash);
     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');      my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
     if (ref($domconfig{'coursecategories'}) eq 'HASH') {      if (ref($domconfig{'coursecategories'}) eq 'HASH') {
         if (($domconfig{'coursecategories'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {          $cathash = $domconfig{'coursecategories'}{'cats'};
           if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
               $changes{'togglecats'} = 1;
               $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
           }
           if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
               $changes{'categorize'} = 1;
               $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
           }
       } else {
           $changes{'togglecats'} = 1;
           $changes{'categorize'} = 1;
           $domconfig{'coursecategories'} = {
                                                togglecats => $env{'form.togglecats'},
                                                categorize => $env{'form.categorize'},
                                            };
       }
       if (ref($cathash) eq 'HASH') {
           if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
             push (@deletecategory,'instcode::0');              push (@deletecategory,'instcode::0');
         }          }
     }      }
     my (@predelcats,@predeltrails,%predelallitems);      my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
     if (ref($domconfig{'coursecategories'}) eq 'HASH') {      if (ref($cathash) eq 'HASH') {
         if (@deletecategory > 0) {          if (@deletecategory > 0) {
             #FIXME Need to remove category from all courses using a deleted category               #FIXME Need to remove category from all courses using a deleted category 
             &Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@predelcats,\@predeltrails,\%predelallitems);              &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
             foreach my $item (@deletecategory) {              foreach my $item (@deletecategory) {
                 if ($domconfig{'coursecategories'}{$item} ne '') {                  if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
                     delete($domconfig{'coursecategories'}{$item});                      delete($domconfig{'coursecategories'}{'cats'}{$item});
                     $deletions{$item} = 1;                      $deletions{$item} = 1;
                     &recurse_cat_deletes($item,$domconfig{'coursecategories'},                      &recurse_cat_deletes($item,$cathash,\%deletions);
                                          \%deletions);  
                 }                  }
             }              }
         }          }
         foreach my $item (keys(%{$domconfig{'coursecategories'}})) {          foreach my $item (keys(%{$cathash})) {
             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);              my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
             if ($domconfig{'coursecategories'}{$item} ne $env{'form.'.$item}) {              if ($cathash->{$item} ne $env{'form.'.$item}) {
                 $reorderings{$item} = 1;                  $reorderings{$item} = 1;
                 $domconfig{'coursecategories'}{$item} = $env{'form.'.$item};                  $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
             }              }
             if ($env{'form.addcategory_name_'.$item} ne '') {              if ($env{'form.addcategory_name_'.$item} ne '') {
                 my $newcat = $env{'form.addcategory_name_'.$item};                  my $newcat = $env{'form.addcategory_name_'.$item};
                 my $newdepth = $depth+1;                  my $newdepth = $depth+1;
                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;                  my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
                 $domconfig{'coursecategories'}{$newitem} = $env{'form.addcategory_pos_'.$item};                  $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
                 $adds{$newitem} = 1;                   $adds{$newitem} = 1; 
             }              }
             if ($env{'form.subcat_'.$item} ne '') {              if ($env{'form.subcat_'.$item} ne '') {
                 my $newcat = $env{'form.subcat_'.$item};                  my $newcat = $env{'form.subcat_'.$item};
                 my $newdepth = $depth+1;                  my $newdepth = $depth+1;
                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;                  my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
                 $domconfig{'coursecategories'}{$newitem} = 0;                  $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
                 $adds{$newitem} = 1;                  $adds{$newitem} = 1;
             }              }
         }          }
     }      }
     if ($env{'form.instcode'} eq '1') {      if ($env{'form.instcode'} eq '1') {
         if (ref($domconfig{'coursecategories'}) eq 'HASH') {          if (ref($cathash) eq 'HASH') {
             my $newitem = 'instcode::0';              my $newitem = 'instcode::0';
             if ($domconfig{'coursecategories'}{$newitem} eq '') {                if ($cathash->{$newitem} eq '') {  
                 $domconfig{'coursecategories'}{$newitem} = $env{'form.instcode_pos'};                  $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
                 $adds{$newitem} = 1;                  $adds{$newitem} = 1;
             }              }
         } else {          } else {
             my $newitem = 'instcode::0';              my $newitem = 'instcode::0';
             $domconfig{'coursecategories'}{$newitem} = $env{'form.instcode_pos'};              $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
             $adds{$newitem} = 1;              $adds{$newitem} = 1;
         }          }
     }      }
     if ($env{'form.addcategory_name'} ne '') {      if ($env{'form.addcategory_name'} ne '') {
         my $newitem = &escape($env{'form.addcategory_name'}).'::0';          my $newitem = &escape($env{'form.addcategory_name'}).'::0';
         $domconfig{'coursecategories'}{$newitem} = $env{'form.addcategory_pos'};          $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
         $adds{$newitem} = 1;          $adds{$newitem} = 1;
     }      }
       my $putresult;
     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {      if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
         my %sort_by_deltrail;  
         if (keys(%deletions) > 0) {          if (keys(%deletions) > 0) {
             foreach my $key (keys(%deletions)) {              foreach my $key (keys(%deletions)) {
                 if ($predelallitems{$key} ne '') {                  if ($predelallitems{$key} ne '') {
Line 4328  sub modify_coursecategories { Line 4925  sub modify_coursecategories {
             }              }
         }          }
         my (@chkcats,@chktrails,%chkallitems);          my (@chkcats,@chktrails,%chkallitems);
         &Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@chkcats,\@chktrails,\%chkallitems);          &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
         if (ref($chkcats[0]) eq 'ARRAY') {          if (ref($chkcats[0]) eq 'ARRAY') {
             my $depth = 0;              my $depth = 0;
             my $chg = 0;              my $chg = 0;
Line 4340  sub modify_coursecategories { Line 4937  sub modify_coursecategories {
                 } else {                  } else {
                     $item = &escape($name).'::0';                      $item = &escape($name).'::0';
                     if ($chg) {                      if ($chg) {
                         $domconfig{'coursecategories'}{$item} -= $chg;                          $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
                     }                      }
                     $depth ++;                       $depth ++; 
                     &recurse_check(\@chkcats,$domconfig{'coursecategories'},$depth,$name);                      &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
                     $depth --;                      $depth --;
                 }                  }
             }              }
         }          }
         my $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);      }
         my (@cats,@trails,%allitems);      if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
         &Apache::loncommon::extract_categories($domconfig{'coursecategories'},\@cats,\@trails,\%allitems);          $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
         if ($putresult eq 'ok') {          if ($putresult eq 'ok') {
               my %title = (
                            togglecats  => 'Show/Hide a course in the catalog',
                            categorize     => 'Category assigned to course',
                           );
               my %level = (
                            dom => 'set from "Modify Course" (Domain)',
                            crs => 'set from "Parameters" (Course)',
                           );
             $resulttext = &mt('Changes made:').'<ul>';              $resulttext = &mt('Changes made:').'<ul>';
             if (keys(%deletions) > 0) {              if ($changes{'togglecats'}) {
                 $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';                  $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
                 foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {               }
                     $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';              if ($changes{'categorize'}) {
                   $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
               }
               if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                   my $cathash;
                   if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                       $cathash = $domconfig{'coursecategories'}{'cats'};
                   } else {
                       $cathash = {};
                   } 
                   my (@cats,@trails,%allitems);
                       &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
                   if (keys(%deletions) > 0) {
                       $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
                       foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
                           $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
                       }
                       $resulttext .= '</ul></li>';
                   }
                   if (keys(%reorderings) > 0) {
                       my %sort_by_trail;
                       $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
                       foreach my $key (keys(%reorderings)) {
                           if ($allitems{$key} ne '') {
                               $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                           }
                       }
                       foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                           $resulttext .= '<li>'.$trails[$trail].'</li>';
                       }
                       $resulttext .= '</ul></li>';
                   }
                   if (keys(%adds) > 0) {
                       my %sort_by_trail;
                       $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
                       foreach my $key (keys(%adds)) {
                           if ($allitems{$key} ne '') {
                               $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
                           }
                       }
                       foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
                           $resulttext .= '<li>'.$trails[$trail].'</li>';
                       }
                       $resulttext .= '</ul></li>';
                   }
               }
               $resulttext .= '</ul>';
           } else {
               $resulttext = '<span class="LC_error">'.
                             &mt('An error occurred: [_1]',$putresult).'</span>';
           }
       } else {
           $resulttext = &mt('No changes made to course categories');
       }
       return $resulttext;
   }
   
   sub modify_serverstatuses {
       my ($dom,%domconfig) = @_;
       my ($resulttext,%changes,%currserverstatus,%newserverstatus);
       if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
           %currserverstatus = %{$domconfig{'serverstatuses'}};
       }
       my @pages = &serverstatus_pages();
       foreach my $type (@pages) {
           $newserverstatus{$type}{'namedusers'} = '';
           $newserverstatus{$type}{'machines'} = '';
           if (defined($env{'form.'.$type.'_namedusers'})) {
               my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
               my @okusers;
               foreach my $user (@users) {
                   my ($uname,$udom) = split(/:/,$user);
                   if (($udom =~ /^$match_domain$/) &&   
                       (&Apache::lonnet::domain($udom)) &&
                       ($uname =~ /^$match_username$/)) {
                       if (!grep(/^\Q$user\E/,@okusers)) {
                           push(@okusers,$user);
                       }
                 }                  }
                 $resulttext .= '</ul></li>';  
             }              }
             if (keys(%reorderings) > 0) {              if (@okusers > 0) {
                 my %sort_by_trail;                   @okusers = sort(@okusers);
                 $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';                   $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
                 foreach my $key (keys(%reorderings)) {              }
                     if ($allitems{$key} ne '') {          }
                         $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];          if (defined($env{'form.'.$type.'_machines'})) {
               my @machines = split(/,/,$env{'form.'.$type.'_machines'});
               my @okmachines;
               foreach my $ip (@machines) {
                   my @parts = split(/\./,$ip);
                   next if (@parts < 4);
                   my $badip = 0;
                   for (my $i=0; $i<4; $i++) {
                       if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
                           $badip = 1;
                           last;
                     }                      }
                 }                  }
                 foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {                  if (!$badip) {
                     $resulttext .= '<li>'.$trails[$trail].'</li>';                      push(@okmachines,$ip);     
                 }                  }
                 $resulttext .= '</ul></li>';  
             }              }
             if (keys(%adds) > 0) {              @okmachines = sort(@okmachines);
                 my %sort_by_trail;              $newserverstatus{$type}{'machines'} = join(',',@okmachines);
                 $resulttext .= '<li>'.&mt('Added categories:').'<ul>';          }
                 foreach my $key (keys(%adds)) {      }
                     if ($allitems{$key} ne '') {      my %serverstatushash =  (
                         $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];                                  serverstatuses => \%newserverstatus,
                               );
       my %changes;
       foreach my $type (@pages) {
           foreach my $setting ('namedusers','machines') {
               my (@current,@new);
               if (ref($currserverstatus{$type}) eq 'HASH') {
                   if ($currserverstatus{$type}{$setting} ne '') { 
                       @current = split(/,/,$currserverstatus{$type}{$setting});
                   }
               }
               if ($newserverstatus{$type}{$setting} ne '') {
                   @new = split(/,/,$newserverstatus{$type}{$setting});
               }
               if (@current > 0) {
                   if (@new > 0) {
                       foreach my $item (@current) {
                           if (!grep(/^\Q$item\E$/,@new)) {
                               $changes{$type}{$setting} = 1;
                               last;
                           }
                       }
                       foreach my $item (@new) {
                           if (!grep(/^\Q$item\E$/,@current)) {
                               $changes{$type}{$setting} = 1;
                               last;
                           }
                     }                      }
                   } else {
                       $changes{$type}{$setting} = 1;
                 }                  }
                 foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {              } elsif (@new > 0) {
                     $resulttext .= '<li>'.$trails[$trail].'</li>';                  $changes{$type}{$setting} = 1;
               }
           }
       }
       if (keys(%changes) > 0) {
           my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
           my $putresult = &Apache::lonnet::put_dom('configuration',
                                                    \%serverstatushash,$dom);
           if ($putresult eq 'ok') {
               $resulttext .= &mt('Changes made:').'<ul>';
               foreach my $type (@pages) {
                   if (ref($changes{$type}) eq 'HASH') {
                       $resulttext .= '<li>'.$titles->{$type}.'<ul>';
                       if ($changes{$type}{'namedusers'}) {
                           if ($newserverstatus{$type}{'namedusers'} eq '') {
                               $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
                           } else {
                               $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
                           }
                       }
                       if ($changes{$type}{'machines'}) {
                           if ($newserverstatus{$type}{'machines'} eq '') {
                               $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
                           } else {
                               $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
                           }
   
                       }
                       $resulttext .= '</ul></li>';
                 }                  }
                 $resulttext .= '</ul></li>';  
             }              }
             $resulttext .= '</ul>';              $resulttext .= '</ul>';
         } else {          } else {
             $resulttext = '<span class="LC_error">'.              $resulttext = '<span class="LC_error">'.
                 &mt('An error occurred: [_1]',$putresult).'</span>';                            &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
   
         }          }
     } else {      } else {
         $resulttext = &mt('No changes made to course categories');          $resulttext = &mt('No changes made to access to server status pages');
     }      }
     return $resulttext;      return $resulttext;
 }  }

Removed from v.1.55  
changed lines
  Added in v.1.87


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