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

version 1.55, 2008/06/03 17:02:12 version 1.68, 2008/09/19 03:27:04
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;
   use DateTime::Locale;
   
 sub handler {  sub handler {
     my $r=shift;      my $r=shift;
Line 62  sub handler { Line 64  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 79  sub handler { Line 81  sub handler {
     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 93  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 => 'Default quotas for user portfolios',
                       help => 'Default_User_Quota',                        help => 'Domain_Configuration_Quotas',
                       header => [{col1 => 'User type',                        header => [{col1 => 'User type',
                                   col2 => 'Default quota'}],                                    col2 => 'Default 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 125  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 146  sub handler { Line 148  sub handler {
                   },                    },
         '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' =>           '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 => '',
                                  }],
                   }                    }
     );      );
     my @roles = ('student','coordinator','author','admin');      my @roles = ('student','coordinator','author','admin');
Line 300  sub handler { Line 306  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 320  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 377  sub print_config_box { Line 386  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') {
Line 403  sub print_config_box { Line 413  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 414  sub print_config_box { Line 426  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 442  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 471  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 455  sub print_config_box { Line 482  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 496  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 493  sub print_config_box { Line 519  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 1676  sub user_formats_row { Line 1700  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 1767  sub print_usermodification { Line 1795  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 1804  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 1860  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 1880  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 1888  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 1916  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 1982  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 2058  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 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 2373  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 2405  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 3987  sub modify_usermodification { Line 4141  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 4153  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 4206  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 4257  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 4280  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};
Line 4123  sub modify_defaults { Line 4303  sub modify_defaults {
                                        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'},                                         timezone_def => $newvalues{'timezone_def'},
                                          datelocale_def => $newvalues{'datelocale_def'},
                                      }                                       }
                        );                         );
     my $title = &defaults_titles();      my $title = &defaults_titles();
Line 4155  sub modify_defaults { Line 4336  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);
             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'}) {              if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_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 4438  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'};
           $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');              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 4525  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 4537  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>';  
                 }  
                 $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');

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


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