Diff for /loncom/interface/domainprefs.pm between versions 1.48 and 1.62

version 1.48, 2008/05/07 23:01:50 version 1.62, 2008/07/09 21:34:27
Line 41  use LONCAPA; Line 41  use LONCAPA;
 use LONCAPA::Enrollment;  use LONCAPA::Enrollment;
 use File::Copy;  use File::Copy;
 use Locale::Language;  use Locale::Language;
   use DateTime::TimeZone;
   
 sub handler {  sub handler {
     my $r=shift;      my $r=shift;
Line 62  sub handler { Line 63  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 96  sub handler { Line 97  sub handler {
                                   col2 => '',}],                                    col2 => '',}],
                     },                      },
         'defaults' =>           'defaults' => 
                     { text => 'Default authentication/language',                      { text => 'Default authentication/language/timezone',
                       help => '',                        help => '',
                       header => [{col1 => 'Setting',                        header => [{col1 => 'Setting',
                                   col2 => 'Value'}],                                    col2 => 'Value'}],
Line 162  sub handler { Line 163  sub handler {
         'coursecategories' =>           'coursecategories' => 
                   { text => 'Cataloging of courses',                    { text => 'Cataloging of courses',
                     help => 'Domain_Course_Catalog',                      help => 'Domain_Course_Catalog',
                     header => [  {col1 => 'Categories',                      header => [{col1 => 'Category settings',  
                                   col2 => '',                                  col2 => '',},
                               }],                                 {col1 => 'Categories',
                                   col2 => '',
                                  }],
                   }                    }
     );      );
     my @roles = ('student','coordinator','author','admin');      my @roles = ('student','coordinator','author','admin');
Line 300  sub handler { Line 303  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 317  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><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 370  sub process_changes { Line 373  sub process_changes {
 sub print_config_box {  sub print_config_box {
     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;      my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
     my $rowtotal = 0;      my $rowtotal = 0;
     my $output =       my $output;
       if ($action eq 'coursecategories') {
           $output = &coursecategories_javascript($settings);
       }  
       $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"><span class="LC_nobreak">'.&mt($item->{text}).
Line 382  sub print_config_box { Line 389  sub print_config_box {
 #          </tr>');  #          </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') ||
           ($action eq 'coursecategories')) {
         my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';          my $colspan = ($action eq 'rolecolors')?' 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') {
Line 399  sub print_config_box { Line 407  sub print_config_box {
             $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 410  sub print_config_box { Line 420  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>          my $colspan = ($action eq 'coursecategories')?' colspan="2"':'';
           $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 425  sub print_config_box { Line 437  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('bottom',$dom,$settings,\$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 440  sub print_config_box { Line 454  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>                <td class="LC_right_item">'.&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 451  sub print_config_box { Line 465  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 465  sub print_config_box { Line 479  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>';
         } else {          } else {
             $output .= '              $output .= '
               <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>';                <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
         }          }
         my $colspan = ($action eq 'coursecategories')?' colspan="2"':'';  
         $output .= '          $output .= '
               <td class="LC_right_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col2'}.'</td>                <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
              </tr>';               </tr>';
         $rowtotal ++;          $rowtotal ++;
         if ($action eq 'login') {          if ($action eq 'login') {
Line 489  sub print_config_box { Line 502  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'){  
             $output .= &print_coursecategories($dom,$item,$settings,\$rowtotal);  
         }          }
     }      }
     $output .= '      $output .= '
Line 1539  sub print_usercreation { Line 1550  sub print_usercreation {
             &Apache::lonnet::inst_userrules($dom,'username');              &Apache::lonnet::inst_userrules($dom,'username');
         my %lt = &usercreation_types();          my %lt = &usercreation_types();
         my %checked;          my %checked;
           my @selfcreate; 
         if (ref($settings) eq 'HASH') {          if (ref($settings) eq 'HASH') {
             if (ref($settings->{'cancreate'}) eq 'HASH') {              if (ref($settings->{'cancreate'}) eq 'HASH') {
                 foreach my $item (@creators) {                  foreach my $item (@creators) {
                     $checked{$item} = $settings->{'cancreate'}{$item};                      $checked{$item} = $settings->{'cancreate'}{$item};
                 }                  }
                   if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
                       @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
                   } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
                       if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
                           @selfcreate = ('email','login','sso');
                       } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
                           @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
                       }
                   }
             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {              } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                 foreach my $item (@creators) {                  foreach my $item (@creators) {
                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {                      if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
Line 1555  sub print_usercreation { Line 1576  sub print_usercreation {
         my $rownum = 0;          my $rownum = 0;
         foreach my $item (@creators) {          foreach my $item (@creators) {
             $rownum ++;              $rownum ++;
             if ($checked{$item} eq '') {              if ($item ne 'selfcreate') {  
                 if ($item eq 'selfcreate') {                  if ($checked{$item} eq '') {
                     $checked{$item} = 'none';  
                 } else {  
                     $checked{$item} = 'any';                      $checked{$item} = 'any';
                 }                  }
             }              }
Line 1571  sub print_usercreation { Line 1590  sub print_usercreation {
             $datatable .= '<tr'.$css_class.'>'.              $datatable .= '<tr'.$css_class.'>'.
                          '<td><span class="LC_nobreak">'.$lt{$item}.                           '<td><span class="LC_nobreak">'.$lt{$item}.
                          '</span></td><td align="right">';                           '</span></td><td align="right">';
             my @options = ('any');              my @options;
             if ($item eq 'selfcreate') {              if ($item eq 'selfcreate') {
                 push(@options,('email','login','sso'));                  push(@options,('email','login','sso'));
             } else {              } else {
                   @options = ('any');
                 if (ref($rules) eq 'HASH') {                  if (ref($rules) eq 'HASH') {
                     if (keys(%{$rules}) > 0) {                      if (keys(%{$rules}) > 0) {
                         push(@options,('official','unofficial'));                          push(@options,('official','unofficial'));
                     }                      }
                 }                  }
                   push(@options,'none');
             }              }
             push(@options,'none');  
             foreach my $option (@options) {              foreach my $option (@options) {
                   my $type = 'radio';
                 my $check = ' ';                  my $check = ' ';
                 if ($checked{$item} eq $option) {                  if ($item eq 'selfcreate') {
                     $check = ' checked="checked" ';                      $type = 'checkbox';
                       if (grep(/^\Q$option\E$/,@selfcreate)) {
                           $check = ' checked="checked" ';
                       }
                   } else {
                       if ($checked{$item} eq $option) {
                           $check = ' checked="checked" ';
                       }
                 }                   } 
                 $datatable .= '<span class="LC_nobreak"><label>'.                  $datatable .= '<span class="LC_nobreak"><label>'.
                               '<input type="radio" name="can_createuser_'.                                '<input type="'.$type.'" name="can_createuser_'.
                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.                                $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';                                $lt{$option}.'</label>&nbsp;&nbsp;</span>';
             }              }
Line 1761  sub print_usermodification { Line 1789  sub print_usermodification {
   
 sub print_defaults {  sub print_defaults {
     my ($dom,$rowtotal) = @_;      my ($dom,$rowtotal) = @_;
     my @items = ('auth_def','auth_arg_def','lang_def');      my @items = ('auth_def','auth_arg_def','lang_def','timezone_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 1793  sub print_defaults { Line 1821  sub print_defaults {
                               '" value="'.$auth.'"'.$checked.'/>'.                                '" value="'.$auth.'"'.$checked.'/>'.
                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';                                $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
             }              }
           } elsif ($item eq 'timezone_def') {
               my $includeempty = 1;
               $datatable .= &Apache::loncommon::select_timezone($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 1809  sub defaults_titles { Line 1840  sub defaults_titles {
                    'auth_def'      => 'Default authentication type',                     'auth_def'      => 'Default authentication type',
                    'auth_arg_def'  => 'Default authentication argument',                     'auth_arg_def'  => 'Default authentication argument',
                    'lang_def'      => 'Default language',                     'lang_def'      => 'Default language',
                      'timezone_def'  => 'Default timezone',
                  );                   );
     return (\%titles);      return (\%titles);
 }  }
Line 1816  sub defaults_titles { Line 1848  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 1843  sub print_scantronformat { Line 1876  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 1880  sub print_scantronformat { Line 1942  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.'>';
Line 1892  sub print_scantronformat { Line 1958  sub print_scantronformat {
         } else {          } else {
             $datatable = &mt('File unavailable for display');              $datatable = &mt('File unavailable for display');
         }          }
         $datatable .= '</td><td valign="bottom">'.&mt('Upload:').'<br />';          $datatable .= '</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><a href="'.$scantronurl.'" target="_blank">'
                             .&mt('Custom scantron format file').'</a>'
                           .'<span class="LC_nobreak"><label>'                            .'<span class="LC_nobreak"><label>'
                           .'<input type="checkbox" name="scantronformat_del"'                            .'<input type="checkbox" name="scantronformat_del"'
                           .'" value="1" />'.&mt('Delete?').'</label></td>'                            .'" value="1" />'.&mt('Delete?').'</label></td>'
Line 1935  sub legacy_scantronformat { Line 2014  sub legacy_scantronformat {
     return ($url,$error);      return ($url,$error);
 }  }
   
 sub print_coursecategories {   sub print_coursecategories {
     my ($dom,$item,$settings,$rowtotal) = @_;      my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
     my ($datatable,$css_class);      my $datatable;
     my $itemcount = 1;      if ($position eq 'top') {
     # FIXME Need to add javascrpt to update other select boxes when one is changed.          my $toggle_cats_crs = ' ';
     if (ref($settings) eq 'HASH') {          my $toggle_cats_dom = ' checked="checked" ';
         my (@cats,@trails,%allitems);          my $can_cat_crs = ' ';
         &extract_categories($settings,\@cats,\@trails,\%allitems);          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',
                 for (my $i=0; $i<$numtop; $i++) {                      );
                     my $parent = $cats[0][$i];          my %level = &Apache::lonlocal::texthash (
                        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'".');"';
                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'                      $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
                                   .'<select name="'.$item.'">';  
                     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);  
                     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"':'';
                 $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos">';                          my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"';
                 for (my $k=0; $k<=$maxnum; $k++) {                          $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
                     my $vpos = $k+1;                                        '<span class="LC_nobreak"><select name="instcode_pos"'.$chgstr.'>';
                     my $selstr;                          for (my $k=0; $k<=$maxnum; $k++) {
                     if ($k == $numtop) {                              my $vpos = $k+1;
                         $selstr = ' selected="selected" ';                              my $selstr;
                     }                              if ($k == $maxnum) {
                     $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';                                  $selstr = ' selected="selected" ';
                 }                              }
                 $datatable .= '</select></span></td><td colspan="2">'.&mt('New:').'&nbsp;'                              $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
                               .'<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"':'';  
                     $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.  
                                   '<span class="LC_nobreak"><select name="instcode_pos">';  
                     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">'.$item->{'header'}->[0]->{'col2'}.'</td>'  
                       .&initialize_categories($itemcount);  
     }      }
     $$rowtotal += $itemcount;  
     return $datatable;      return $datatable;
 }  }
   
   sub coursecategories_javascript {
       my ($settings) = @_;
       my ($output,$jstext,$cathash);
       if (ref($settings) eq 'HASH') {
           $cathash = $settings->{'cats'};
       }
       if (ref($cathash) eq 'HASH') {
           my (@cats,@jsarray,%idx);
           &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
           if (@jsarray > 0) {
               $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
               for (my $i=0; $i<@jsarray; $i++) {
                   if (ref($jsarray[$i]) eq 'ARRAY') {
                       my $catstr = join('","',@{$jsarray[$i]});
                       $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
                   }
               }
           }
       } else {
           $jstext  = '    var categories = Array(1);'."\n".
                      '    categories[0] = Array("instcode_pos");'."\n"; 
       }
       $output = <<"ENDSCRIPT";
   <script type="text/javascript">
   function reorderCats(form,parent,item,idx) {
       var changedVal;
   $jstext
       var newpos = 'addcategory_pos';
       var current = new Array;
       if (parent == '') {
           var has_instcode = 0;
           var maxtop = categories[idx].length;
           for (var j=0; j<maxtop; j++) {
               if (categories[idx][j] == 'instcode::0') {
                   has_instcode == 1;
               }
           }
           if (has_instcode == 0) {
               categories[idx][maxtop] = 'instcode_pos';
           }
       } else {
           newpos += '_'+parent;
       }
       var maxh = 1 + categories[idx].length;
       var current = new Array;
       var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
       if (item == newpos) {
           changedVal = newitemVal;
       } else {
           changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
           current[newitemVal] = newpos;
       }
       for (var i=0; i<categories[idx].length; i++) {
           var elementName = categories[idx][i];
           if (elementName != item) {
               if (form.elements[elementName]) {
                   var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
                   current[currVal] = elementName;
               }
           }
       }
       var oldVal;
       for (var j=0; j<maxh; j++) {
           if (current[j] == undefined) {
               oldVal = j;
           }
       }
       if (oldVal < changedVal) {
           for (var k=oldVal+1; k<=changedVal ; k++) {
              var elementName = current[k];
              form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
           }
       } else {
           for (var k=changedVal; k<oldVal; k++) {
               var elementName = current[k];
               form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
           }
       }
       return;
   }
   </script>
   
   ENDSCRIPT
       return $output;
   }
   
 sub initialize_categories {  sub initialize_categories {
     my ($itemcount) = @_;      my ($itemcount) = @_;
     my $datatable;      my $datatable;
     my $css_class = $itemcount%2?' class="LC_odd_row"':'';      my $css_class = $itemcount%2?' class="LC_odd_row"':'';
       my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','0'".');"';
   
     $datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">'      $datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">'
                  .'<select name="instcode_pos"><option value="0" selected="selected">1</option>'                   .'<select name="instcode_pos"><option value="0" selected="selected">1</option>'
                  .'<option value="1">2</option></select>&nbsp;'                   .'<option value="1">2</option></select>&nbsp;'
Line 2052  sub initialize_categories { Line 2270  sub initialize_categories {
                  .'</label></span></td></tr>';                   .'</label></span></td></tr>';
     $itemcount ++;      $itemcount ++;
     $css_class = $itemcount%2?' class="LC_odd_row"':'';      $css_class = $itemcount%2?' class="LC_odd_row"':'';
       $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'      $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
                   .'<select name="addcategory_pos"><option value="0">1</option>'                    .'<select name="addcategory_pos"'.$chgstr.'><option value="0">1</option>'
                   .'<option value="1" selected="selected">2</option></select>&nbsp;'                    .'<option value="1" selected="selected">2</option></select>&nbsp;'
                   .&mt('Add category').'</td><td>'.&mt('Name:')                    .&mt('Add category').'</td><td>'.&mt('Name:')
                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';                    .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
Line 2061  sub initialize_categories { Line 2280  sub initialize_categories {
 }  }
   
 sub build_category_rows {  sub build_category_rows {
     my ($itemcount,$cats,$depth,$parent,$path) = @_;      my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
     my ($text,$name,$item);      my ($text,$name,$item,$chgstr);
     if (ref($cats) eq 'ARRAY') {      if (ref($cats) eq 'ARRAY') {
         my $maxdepth = scalar(@{$cats});          my $maxdepth = scalar(@{$cats});
         if (ref($cats->[$depth]) eq 'HASH') {          if (ref($cats->[$depth]) eq 'HASH') {
Line 2070  sub build_category_rows { Line 2289  sub build_category_rows {
                 my $numchildren = @{$cats->[$depth]{$parent}};                  my $numchildren = @{$cats->[$depth]{$parent}};
                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';                  my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                 $text .= '<td><table class="LC_datatable">';                  $text .= '<td><table class="LC_datatable">';
                   my ($idxnum,$parent_name,$parent_item);
                   my $higher = $depth - 1;
                   if ($higher == 0) {
                       $parent_name = &escape($parent).'::'.$higher;
                   } else {
                       if (ref($path) eq 'ARRAY') {
                           $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
                       }
                   }
                   $parent_item = 'addcategory_pos_'.$parent_name;
                 for (my $j=0; $j<=$numchildren; $j++) {                  for (my $j=0; $j<=$numchildren; $j++) {
                     if ($j == $numchildren) {                      if ($j < $numchildren) {
                         my $higher = $depth-1;  
                         if ($higher == 0) {  
                             $name = &escape($parent).'::'.$higher;  
                         } else {  
                             if (ref($path) eq 'ARRAY') {  
                                 $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;  
                             }  
                         }  
                         $item = 'addcategory_pos_'.$name;  
                     } else {  
                         $name = $cats->[$depth]{$parent}[$j];                          $name = $cats->[$depth]{$parent}[$j];
                         $item = &escape($name).':'.&escape($parent).':'.$depth;                          $item = &escape($name).':'.&escape($parent).':'.$depth;
                           $idxnum = $idx->{$item};
                       } else {
                           $name = $parent_name;
                           $item = $parent_item;
                     }                      }
                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'">';                      $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
                       $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
                     for (my $i=0; $i<=$numchildren; $i++) {                      for (my $i=0; $i<=$numchildren; $i++) {
                         my $vpos = $i+1;                          my $vpos = $i+1;
                         my $selstr;                          my $selstr;
Line 2102  sub build_category_rows { Line 2326  sub build_category_rows {
                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';                                   .$item.'" />'.&mt('Delete').'</label></span></td><td>';
                         if(ref($path) eq 'ARRAY') {                          if(ref($path) eq 'ARRAY') {
                             push(@{$path},$name);                              push(@{$path},$name);
                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path);                              $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
                             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 2353  sub modify_login { Line 2577  sub modify_login {
                     'adminmail'     => 'off',                      'adminmail'     => 'off',
                     'newuser'       => 'off',                      'newuser'       => 'off',
         );          );
         foreach my $item (@toggles) {          if (ref($domconfig{'login'}) eq 'HASH') {
             if ($defaultchecked{$item} eq 'on') {               foreach my $item (@toggles) {
                 if (($domconfig{'login'}{$item} eq '0') &&                  if ($defaultchecked{$item} eq 'on') { 
                     ($env{'form.'.$item} eq '1')) {                      if (($domconfig{'login'}{$item} eq '0') &&
                     $changes{$item} = 1;                          ($env{'form.'.$item} eq '1')) {
                 } elsif (($domconfig{'login'}{$item} eq '' ||                          $changes{$item} = 1;
                           $domconfig{'login'}{$item} eq '1') &&                      } elsif (($domconfig{'login'}{$item} eq '' ||
                          ($env{'form.'.$item} eq '0')) {                                $domconfig{'login'}{$item} eq '1') &&
                     $changes{$item} = 1;                               ($env{'form.'.$item} eq '0')) {
                 }                          $changes{$item} = 1;
             } elsif ($defaultchecked{$item} eq 'off') {                      }
                 if (($domconfig{'login'}{$item} eq '1') &&                  } elsif ($defaultchecked{$item} eq 'off') {
                     ($env{'form.'.$item} eq '0')) {                      if (($domconfig{'login'}{$item} eq '1') &&
                     $changes{$item} = 1;                          ($env{'form.'.$item} eq '0')) {
                 } elsif (($domconfig{'login'}{$item} eq '' ||                          $changes{$item} = 1;
                           $domconfig{'login'}{$item} eq '0') &&                      } elsif (($domconfig{'login'}{$item} eq '' ||
                          ($env{'form.'.$item} eq '1')) {                                $domconfig{'login'}{$item} eq '0') &&
                     $changes{$item} = 1;                               ($env{'form.'.$item} eq '1')) {
                           $changes{$item} = 1;
                       }
                 }                  }
             }              }
         }              if (($domconfig{'login'}{'loginheader'} eq 'text') && 
         if (($domconfig{'login'}{'loginheader'} eq 'text') &&                   ($env{'form.loginheader'} eq 'image')) {
             ($env{'form.loginheader'} eq 'image')) {                  $changes{'loginheader'} = 1;
             $changes{'loginheader'} = 1;              } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
         } elsif (($domconfig{'login'}{'loginheader'} eq '' ||                        $domconfig{'login'}{'loginheader'} eq 'image') &&
                   $domconfig{'login'}{'loginheader'} eq 'image') &&                       ($env{'form.loginheader'} eq 'text')) {
                  ($env{'form.loginheader'} eq 'text')) {                  $changes{'loginheader'} = 1;
             $changes{'loginheader'} = 1;              }
         }          }
         if (keys(%changes) > 0 || $colchgtext) {          if (keys(%changes) > 0 || $colchgtext) {
             &Apache::loncommon::devalidate_domconfig_cache($dom);              &Apache::loncommon::devalidate_domconfig_cache($dom);
Line 2413  sub color_font_choices { Line 2639  sub color_font_choices {
             img => "Header",              img => "Header",
             bgs => "Background colors",              bgs => "Background colors",
             links => "Link colors",              links => "Link colors",
               images => "Images",
             font => "Font color",              font => "Font color",
             pgbg => "Page",              pgbg => "Page",
             tabbg => "Header",              tabbg => "Header",
Line 2428  sub modify_rolecolors { Line 2655  sub modify_rolecolors {
     my ($r,$dom,$confname,$roles,%domconfig) = @_;      my ($r,$dom,$confname,$roles,%domconfig) = @_;
     my ($resulttext,%rolehash);      my ($resulttext,%rolehash);
     $rolehash{'rolecolors'} = {};      $rolehash{'rolecolors'} = {};
       if (ref($domconfig{'rolecolors'}) ne 'HASH') {
           if ($domconfig{'rolecolors'} eq '') {
               $domconfig{'rolecolors'} = {};
           }
       }
     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,      my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});                           $domconfig{'rolecolors'},$rolehash{'rolecolors'});
     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,      my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
Line 2454  sub modify_rolecolors { Line 2686  sub modify_rolecolors {
 sub modify_colors {  sub modify_colors {
     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;      my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
     my (%changes,%choices);      my (%changes,%choices);
     my @bgs = ('pgbg','mainbg','sidebg');      my @bgs;
     my @links = ('link','alink','vlink');      my @links = ('link','alink','vlink');
     my @logintext;      my @logintext;
     my @images;      my @images;
Line 2469  sub modify_colors { Line 2701  sub modify_colors {
         }          }
         if ($role eq 'login') {          if ($role eq 'login') {
             @images = ('img','logo','domlogo','login');              @images = ('img','logo','domlogo','login');
               @bgs = ('pgbg','mainbg','sidebg');
         } else {          } else {
             @images = ('img');              @images = ('img');
               @bgs = ('pgbg','tabbg','sidebg'); 
         }          }
         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};          $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
         foreach my $item (@bgs,@links,@logintext) {          foreach my $item (@bgs,@links,@logintext) {
Line 3021  sub modify_quotas { Line 3255  sub modify_quotas {
     }      }
     foreach my $key (keys(%formhash)) {      foreach my $key (keys(%formhash)) {
         if ($formhash{$key} ne '') {          if ($formhash{$key} ne '') {
             if (!exists($domconfig{'quotas'}{$key})) {              if (ref($domconfig{'quotas'}) eq 'HASH') {
                   if (!exists($domconfig{'quotas'}{$key})) {
                       $changes{$key} = 1;
                   }
               } else {
                 $changes{$key} = 1;                  $changes{$key} = 1;
             }              }
         }          }
Line 3541  sub modify_usercreation { Line 3779  sub modify_usercreation {
     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');      my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
     my @contexts = ('author','course','selfcreate');      my @contexts = ('author','course','selfcreate');
     foreach my $item(@contexts) {      foreach my $item(@contexts) {
         $cancreate{$item} = $env{'form.can_createuser_'.$item};  
         if ($item eq 'selfcreate') {          if ($item eq 'selfcreate') {
               @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);              my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {              if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
                 if (($cancreate{$item} eq 'any') || ($cancreate{$item} eq 'login')) {                  if (ref($cancreate{$item}) eq 'ARRAY') { 
                     $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.&mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');                         if (grep(/^login$/,@{$cancreate{$item}})) {
                           $warningmsg = &mt('Although account creation has been set to be available for institutional logins, currently default authentication in this domain has not been set to support this.').' '.&mt('You need to set the default authentication type to Kerberos 4 or 5 (with a Kerberos domain specified), or to Local authentication, if the localauth module has been customized in your domain to authenticate institutional logins.');   
                       }
                 }                  }
             }              }
           } else {
               $cancreate{$item} = $env{'form.can_createuser_'.$item};
         }          }
     }      }
     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {      if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
         foreach my $item (@contexts) {          foreach my $item (@contexts) {
             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {              if ($item eq 'selfcreate') {
                 push(@{$changes{'cancreate'}},$item);                  if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') { 
             }                       foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
                           if (!grep(/^$curr$/,@{$cancreate{$item}})) {
                               if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                   push(@{$changes{'cancreate'}},$item);
                               }
                           }
                       }
                   } else {
                       if ($curr_usercreation{'cancreate'}{$item} eq '') {
                           if (@{$cancreate{$item}} > 0) {
                               if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                   push(@{$changes{'cancreate'}},$item);
                               }
                           }
                       } else {
                           if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
                               if (@{$cancreate{$item}} < 3) {
                                   if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                       push(@{$changes{'cancreate'}},$item);
                                   }
                               }
                           } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
                               if (@{$cancreate{$item}} > 0) {
                                   if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                       push(@{$changes{'cancreate'}},$item);
                                   }
                               }
                           } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
                               if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                   push(@{$changes{'cancreate'}},$item);
                               }
                           }
                       }
                   }
                   if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                       foreach my $type (@{$cancreate{$item}}) {
                           if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
                               if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
                                   if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                       push(@{$changes{'cancreate'}},$item);
                                   }
                               }
                           } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
                                    ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
                               if ($curr_usercreation{'cancreate'}{$item} ne $type) {
                                   if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
                                       push(@{$changes{'cancreate'}},$item);
                                   }
                               }
                           }
                       }
                   }
               } else {
                   if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                       push(@{$changes{'cancreate'}},$item);
                   }
               }
         }          }
     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {      } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
         foreach my $item (@contexts) {          foreach my $item (@contexts) {
Line 3662  sub modify_usercreation { Line 3960  sub modify_usercreation {
   
     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,      my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                                              $dom);                                               $dom);
   
       my %selfcreatetypes = (
                                sso   => 'users authenticated by institutional single sign on',
                                login => 'users authenticated by institutional log-in',
                                email => 'users who provide a valid e-mail address for use as the username',
                             );
     if ($putresult eq 'ok') {      if ($putresult eq 'ok') {
         if (keys(%changes) > 0) {          if (keys(%changes) > 0) {
             $resulttext = &mt('Changes made:').'<ul>';              $resulttext = &mt('Changes made:').'<ul>';
Line 3670  sub modify_usercreation { Line 3974  sub modify_usercreation {
                 foreach my $type (@{$changes{'cancreate'}}) {                  foreach my $type (@{$changes{'cancreate'}}) {
                     my $chgtext =  $lt{$type}.', ';                      my $chgtext =  $lt{$type}.', ';
                     if ($type eq 'selfcreate') {                      if ($type eq 'selfcreate') {
                         if ($cancreate{$type} eq 'none') {                          if (@{$cancreate{$type}} == 0) {
                             $chgtext .= &mt('creation of a new user account is not permitted.');                              $chgtext .= &mt('creation of a new user account is not permitted.');
                         } elsif ($cancreate{$type} eq 'any') {                          } else {
                             $chgtext .= &mt('creation of a new account is permitted for users authenticated by institutional log-in and SSO, and also for e-mail addresses used as usernames.');                              $chgtext .= &mt('creation of a new account is permitted for:<ul>');
                         } elsif ($cancreate{$type} eq 'login') {                              foreach my $case (@{$cancreate{$type}}) {
                             $chgtext .= &mt('creation of a new account is only permitted for users authenticated by institutional log-in.');                                  $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
                         } elsif ($cancreate{$type} eq 'sso') {                              }
                             $chgtext .= &mt('creation of a new account is only permitted for users authenticated by institutional single sign on.');                              $chgtext .= '</ul>';
                         } elsif ($cancreate{$type} eq 'email') {  
                             $chgtext .= &mt('creation of a new account is only permitted for users who provide a valid e-mail address for use as the username.');  
                         }                          }
                     } else {                      } else {
                         if ($cancreate{$type} eq 'none') {                          if ($cancreate{$type} eq 'none') {
Line 3884  sub modify_defaults { Line 4186  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');      my @items = ('auth_def','auth_arg_def','lang_def','timezone_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 3905  sub modify_defaults { Line 4207  sub modify_defaults {
                     push(@errors,$item);                      push(@errors,$item);
                 }                  }
             }              }
           } elsif ($item eq 'timezone_def') {
               if ($newvalues{$item} ne '') {
                   if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
                       push(@errors,$item);   
                   }
               }
         }          }
         if (grep(/^\Q$item\E$/,@errors)) {          if (grep(/^\Q$item\E$/,@errors)) {
             $newvalues{$item} = $domdefaults{$item};              $newvalues{$item} = $domdefaults{$item};
Line 3916  sub modify_defaults { Line 4224  sub modify_defaults {
                          defaults => { auth_def => $newvalues{'auth_def'},                           defaults => { auth_def => $newvalues{'auth_def'},
                                        auth_arg_def => $newvalues{'auth_arg_def'},                                         auth_arg_def => $newvalues{'auth_arg_def'},
                                        lang_def => $newvalues{'lang_def'},                                         lang_def => $newvalues{'lang_def'},
                                          timezone_def => $newvalues{'timezone_def'},
                                      }                                       }
                        );                         );
     my $title = &defaults_titles();      my $title = &defaults_titles();
Line 3948  sub modify_defaults { Line 4257  sub modify_defaults {
             my $cachetime = 24*60*60;              my $cachetime = 24*60*60;
             &Apache::lonnet::do_cache_new('domdefaults',$dom,              &Apache::lonnet::do_cache_new('domdefaults',$dom,
                                           $defaults_hash{'defaults'},$cachetime);                                            $defaults_hash{'defaults'},$cachetime);
             my $sysmail = $r->dir_config('lonSysEMail');              if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'}) {
             &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);                  my $sysmail = $r->dir_config('lonSysEMail');
                   &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
               }
         } else {          } else {
             $resulttext = &mt('No changes made to default authentication/language settings');              $resulttext = &mt('No changes made to default authentication/language/timezone settings');
         }          }
     } else {      } else {
         $resulttext = '<span class="LC_error">'.          $resulttext = '<span class="LC_error">'.
Line 4048  sub modify_scantron { Line 4359  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 (($domconfig{'coursecategories'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {  
         push (@deletecategory,'instcode::0');  
     }  
     my (@predelcats,@predeltrails,%predelallitems);  
     if (ref($domconfig{'coursecategories'}) eq 'HASH') {      if (ref($domconfig{'coursecategories'}) eq 'HASH') {
           $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'};
           $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
       }
       if (ref($cathash) eq 'HASH') {
           if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
               push (@deletecategory,'instcode::0');
           }
       }
       my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
       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 
             &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 4117  sub modify_coursecategories { Line 4446  sub modify_coursecategories {
             }              }
         }          }
         my (@chkcats,@chktrails,%chkallitems);          my (@chkcats,@chktrails,%chkallitems);
         &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 4129  sub modify_coursecategories { Line 4458  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)) {
         &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>';  
                 }  
                 $resulttext .= '</ul></li>';  
             }              }
             if (keys(%reorderings) > 0) {              if ($changes{'categorize'}) {
                 my %sort_by_trail;                  $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
                 $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) {              if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
                 my %sort_by_trail;                  my $cathash;
                 $resulttext .= '<li>'.&mt('Added categories:').'<ul>';                  if (ref($domconfig{'coursecategories'}) eq 'HASH') {
                 foreach my $key (keys(%adds)) {                      $cathash = $domconfig{'coursecategories'}{'cats'};
                     if ($allitems{$key} ne '') {                  } else {
                         $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];                      $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>';
                 }                  }
                 foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {                  if (keys(%adds) > 0) {
                     $resulttext .= '<li>'.$trails[$trail].'</li>';                      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></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: [_1]',$putresult).'</span>';
         }          }
     } else {      } else {
         $resulttext = &mt('No changes made to course categories');          $resulttext = &mt('No changes made to course categories');
Line 4224  sub recurse_cat_deletes { Line 4577  sub recurse_cat_deletes {
         }          }
     }      }
     return;      return;
 }  
   
 sub extract_categories {  
     my ($categories,$cats,$trails,$allitems) = @_;  
     if (ref($categories) eq 'HASH') {  
         foreach my $item (keys(%{$categories})) {  
             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);  
             if ($container eq '' && $depth == 0) {  
                 $cats->[$depth][$categories->{$item}] = $cat;  
             } else {  
                 $cats->[$depth]{$container}[$categories->{$item}] = $cat;  
             }  
         }  
         if (ref($cats->[0]) eq 'ARRAY') {  
             for (my $i=0; $i<@{$cats->[0]}; $i++) {  
                 my $name = $cats->[0][$i];  
                 my $item = &escape($name).'::0';  
                 my $trailstr;   
                 if ($name eq 'instcode') {  
                     $trailstr = &mt('Official courses (with institutional codes)');  
                 } else {  
                     $trailstr = $name;  
                 }  
                 if ($allitems->{$item} eq '') {  
                     push(@{$trails},$trailstr);  
                     $allitems->{$item} = scalar(@{$trails})-1;  
                 }  
                 my @parents = ($name);  
                 if (ref($cats->[1]{$name}) eq 'ARRAY') {  
                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {  
                         my $category = $cats->[1]{$name}[$j];  
                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents);  
                     }  
                 }  
             }  
         }  
     }  
     return;  
 }  
   
 sub recurse_categories {  
     my ($cats,$depth,$category,$trails,$allitems,$parents) = @_;  
     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {  
         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {  
             my $shallower = $depth - 1;  
             my $name = $cats->[$depth]{$category}[$k];  
             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;  
             my $trailstr = join(' -&gt; ',(@{$parents},$category));  
             if ($allitems->{$item} eq '') {   
                 push(@{$trails},$trailstr);  
                 $allitems->{$item} = scalar(@{$trails})-1;  
             }  
             my $deeper = $depth+1;  
             push(@{$parents},$category);  
             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents);  
             pop(@{$parents});  
         }  
     } else {  
         $depth --;  
         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$depth;  
         my $trailstr = join(' -&gt; ',(@{$parents},$category));  
         if ($allitems->{$item} eq '') {  
             push(@{$trails},$trailstr);  
             $allitems->{$item} = scalar(@{$trails})-1;  
         }  
     }  
     return;  
 }  }
   
 1;  1;

Removed from v.1.48  
changed lines
  Added in v.1.62


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