File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.62: download - view: text, annotated - select for diffs
Wed Jul 9 21:34:27 2008 UTC (15 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Using the provided method: is_valid_name() to validate selected default timezone for domain.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.62 2008/07/09 21:34:27 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#
   23: # /home/httpd/html/adm/gpl.txt
   24: #
   25: # http://www.lon-capa.org/
   26: #
   27: #
   28: ###############################################################
   29: ##############################################################
   30: 
   31: package Apache::domainprefs;
   32: 
   33: use strict;
   34: use Apache::Constants qw(:common :http);
   35: use Apache::lonnet;
   36: use Apache::loncommon();
   37: use Apache::lonhtmlcommon();
   38: use Apache::lonlocal;
   39: use Apache::lonmsg();
   40: use LONCAPA;
   41: use LONCAPA::Enrollment;
   42: use File::Copy;
   43: use Locale::Language;
   44: use DateTime::TimeZone;
   45: 
   46: sub handler {
   47:     my $r=shift;
   48:     if ($r->header_only) {
   49:         &Apache::loncommon::content_type($r,'text/html');
   50:         $r->send_http_header;
   51:         return OK;
   52:     }
   53: 
   54:     my $dom = $env{'request.role.domain'};
   55:     my $domdesc = &Apache::lonnet::domain($dom,'description');
   56:     if (&Apache::lonnet::allowed('mau',$dom)) {
   57:         &Apache::loncommon::content_type($r,'text/html');
   58:         $r->send_http_header;
   59:     } else {
   60:         $env{'user.error.msg'}=
   61:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
   62:         return HTTP_NOT_ACCEPTABLE;
   63:     }
   64:     &Apache::lonhtmlcommon::clear_breadcrumbs();
   65:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   66:                                             ['phase','actions']);
   67:     my $phase = 'pickactions';
   68:     if ( exists($env{'form.phase'}) ) {
   69:         $phase = $env{'form.phase'};
   70:     }
   71:     my %domconfig =
   72:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
   73:                 'quotas','autoenroll','autoupdate','directorysrch',
   74:                 'usercreation','usermodification','contacts','defaults',
   75:                 'scantron','coursecategories'],$dom);
   76:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
   77:                        'autoupdate','directorysrch','contacts',
   78:                        'usercreation','usermodification','scantron',
   79:                        'coursecategories');
   80:     my %prefs = (
   81:         'rolecolors' =>
   82:                    { text => 'Default color schemes',
   83:                      help => 'Default_Color_Schemes',
   84:                      header => [{col1 => 'Student Settings',
   85:                                  col2 => '',},
   86:                                 {col1 => 'Coordinator Settings',
   87:                                  col2 => '',},
   88:                                 {col1 => 'Author Settings',
   89:                                  col2 => '',},
   90:                                 {col1 => 'Administrator Settings',
   91:                                  col2 => '',}],
   92:                     },
   93:         'login' =>  
   94:                     { text => 'Log-in page options',
   95:                       help => 'Domain_Log-in_Page',
   96:                       header => [{col1 => 'Item',
   97:                                   col2 => '',}],
   98:                     },
   99:         'defaults' => 
  100:                     { text => 'Default authentication/language/timezone',
  101:                       help => '',
  102:                       header => [{col1 => 'Setting',
  103:                                   col2 => 'Value'}],
  104:                     },
  105:         'quotas' => 
  106:                     { text => 'Default quotas for user portfolios',
  107:                       help => 'Default_User_Quota',
  108:                       header => [{col1 => 'User type',
  109:                                   col2 => 'Default quota'}],
  110:                     },
  111:         'autoenroll' =>
  112:                    { text => 'Auto-enrollment settings',
  113:                      help => 'Domain_Auto_Enrollment',
  114:                      header => [{col1 => 'Configuration setting',
  115:                                  col2 => 'Value(s)'}],
  116:                    },
  117:         'autoupdate' => 
  118:                    { text => 'Auto-update settings',
  119:                      help => 'Domain_Auto_Update',
  120:                      header => [{col1 => 'Setting',
  121:                                  col2 => 'Value',},
  122:                                 {col1 => 'User population',
  123:                                  col2 => 'Updataeable user data'}],
  124:                   },
  125:         'directorysrch' => 
  126:                   { text => 'Institutional directory searches',
  127:                     help => 'Domain_Directory_Search',
  128:                     header => [{col1 => 'Setting',
  129:                                 col2 => 'Value',}],
  130:                   },
  131:         'contacts' =>
  132:                   { text => 'Contact Information',
  133:                     help => 'Domain_Contact_Information',
  134:                     header => [{col1 => 'Setting',
  135:                                 col2 => 'Value',}],
  136:                   },
  137: 
  138:         'usercreation' => 
  139:                   { text => 'User creation',
  140:                     help => 'Domain_User_Creation',
  141:                     header => [{col1 => 'Format rule type',
  142:                                 col2 => 'Format rules in force'},
  143:                                {col1 => 'User account creation',
  144:                                 col2 => 'Usernames which may be created',},
  145:                                {col1 => 'Context',
  146:                                 col2 => 'Assignable authentication types'}],
  147:                   },
  148:         'usermodification' => 
  149:                   { text => 'User modification',
  150:                     help => 'Domain_User_Modification',
  151:                     header => [{col1 => 'Target user has role',
  152:                                 col2 => 'User information updateable in author context'},
  153:                                {col1 => 'Target user has role',
  154:                                 col2 => 'User information updateable in course context'}],
  155:                   },
  156:         'scantron' => 
  157:                   { text => 'Scantron format file',
  158:                     help => 'Domain_Scantron_Formats',
  159:                     header => [ {col1 => 'Item',
  160:                                  col2 => '',
  161:                               }],
  162:                   },
  163:         'coursecategories' => 
  164:                   { text => 'Cataloging of courses',
  165:                     help => 'Domain_Course_Catalog',
  166:                     header => [{col1 => 'Category settings',  
  167:                                 col2 => '',},
  168:                                {col1 => 'Categories',
  169:                                 col2 => '',
  170:                                }],
  171:                   }
  172:     );
  173:     my @roles = ('student','coordinator','author','admin');
  174:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  175:     &Apache::lonhtmlcommon::add_breadcrumb
  176:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
  177:       text=>"Pick functionality"});
  178:     my $confname = $dom.'-domainconfig';
  179:     if ($phase eq 'process') {
  180:         &Apache::lonhtmlcommon::add_breadcrumb
  181:           ({href=>"javascript:changePage(document.$phase,'display')",
  182:             text=>"Domain Configuration"},
  183:            {href=>"javascript:changePage(document.$phase,'$phase')",
  184:             text=>"Updated"});
  185:         &print_header($r,$phase);
  186:         foreach my $item (@prefs_order) {
  187:             if (grep(/^\Q$item\E$/,@actions)) {
  188:                 $r->print('<h3>'.&mt($prefs{$item}{'text'}).'</h3>'.
  189:                           &process_changes($r,$dom,$confname,$item,
  190:                           \@roles,%domconfig));
  191:             }
  192:         }
  193:         $r->print('<p>');
  194:         &print_footer($r,$phase,'display','Back to configuration display',
  195:                       \@actions);
  196:         $r->print('</p>');
  197:     } elsif ($phase eq 'display') {
  198:         &Apache::lonhtmlcommon::add_breadcrumb
  199:             ({href=>"javascript:changePage(document.$phase,'display')",
  200:               text=>"Domain Configuration"});
  201:         &print_header($r,$phase);
  202:         if (@actions > 0) {
  203:             my $rowsum = 0;
  204:             my (%output,%rowtotal,@items);
  205:             my $halfway = @actions/2;
  206:             foreach my $item (@prefs_order) {
  207:                 if (grep(/^\Q$item\E$/,@actions)) {
  208:                     push(@items,$item);
  209:                     ($output{$item},$rowtotal{$item}) = 
  210:                         &print_config_box($r,$dom,$confname,$phase,
  211:                                           $item,$prefs{$item},
  212:                                           $domconfig{$item});
  213:                     $rowsum += $rowtotal{$item};
  214:                 }
  215:             }
  216:             my $colend;
  217:             my $halfway = $rowsum/2;
  218:             my $aggregate = 0;
  219:             my $sumleft = 0;
  220:             my $sumright = 0;
  221:             my $crossover;
  222:             for (my $i=0; $i<@items; $i++) {
  223:                 $aggregate += $rowtotal{$items[$i]};
  224:                 if ($aggregate > $halfway) {
  225:                     $crossover = $i;
  226:                     last;
  227:                 }
  228:             }
  229:             for (my $i=0; $i<$crossover; $i++) {
  230:                 $sumleft += $rowtotal{$items[$i]}; 
  231:             }
  232:             for (my $i=$crossover+1; $i<@items; $i++) {
  233:                 $sumright += $rowtotal{$items[$i]};
  234:             }
  235:             if ((@items > 1) && ($env{'form.numcols'} == 2)) {
  236:                 my $sumdiff = $sumright - $sumleft;
  237:                 if ($sumdiff > 0) {
  238:                     $colend = $crossover + 1;
  239:                 } else {
  240:                     $colend = $crossover;
  241:                 }
  242:             } else {
  243:                 $colend = @items;
  244:             }
  245:             $r->print('<p><table class="LC_double_column"><tr><td class="LC_left_col">');
  246:             for (my $i=0; $i<$colend; $i++) {
  247:                 $r->print($output{$items[$i]});
  248:             }
  249:             $r->print('</td><td></td><td class="LC_right_col">');
  250:             if ($colend < @items) {
  251:                 for (my $i=$colend; $i<@items; $i++) { 
  252:                     $r->print($output{$items[$i]});
  253:                 }
  254:             }
  255:             $r->print('</td></tr></table></p>');
  256:             $r->print(&print_footer($r,$phase,'process','Save',\@actions));
  257:         } else {
  258:             $r->print('<input type="hidden" name="phase" value="" />'.
  259:                       '<input type="hidden" name="numcols" value="'.
  260:                       $env{'form.numcols'}.'" />'."\n".
  261:                       '<span clas="LC_error">'.&mt('No settings chosen').
  262:                       '</span>');
  263:         }
  264:         $r->print('</form>');
  265:         $r->print(&Apache::loncommon::end_page());
  266:     } else {
  267:         if ($phase eq '') {
  268:             $phase = 'pickactions';
  269:         }
  270:         my %helphash;
  271:         &print_header($r,$phase);
  272:         if (keys(%domconfig) == 0) {
  273:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
  274:             my @ids=&Apache::lonnet::current_machine_ids();
  275:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
  276:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
  277:                 my @loginimages = ('img','logo','domlogo','login');
  278:                 my $custom_img_count = 0;
  279:                 foreach my $img (@loginimages) {
  280:                     if ($designhash{$dom.'.login.'.$img} ne '') {
  281:                         $custom_img_count ++;
  282:                     }
  283:                 }
  284:                 foreach my $role (@roles) {
  285:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  286:                         $custom_img_count ++;
  287:                     }
  288:                 }
  289:                 if ($custom_img_count > 0) {
  290:                     my $switch_server = &check_switchserver($dom,$confname);
  291:                     $r->print(
  292:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
  293:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
  294:     &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
  295:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
  296:                     if ($switch_server) {
  297:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
  298:                     }
  299:                     return OK;
  300:                 }
  301:             }
  302:         }
  303:         $r->print('<h3>'.&mt('Functionality to display/modify').'</h3>');
  304:         $r->print('<script type="text/javascript">'."\n".
  305:               &Apache::loncommon::check_uncheck_jscript()."\n".
  306:               '</script>'."\n".'<p><input type="button" value="'.&mt('check all').'" '.
  307:               'onclick="javascript:checkAll(document.pickactions.actions)"'.
  308:               ' />&nbsp;&nbsp;'.
  309:               '<input type="button" value="'.&mt('uncheck all').'" '.
  310:               'onclick="javascript:uncheckAll(document.pickactions.actions)"'.
  311:               ' /></p><div class="LC_left_float">');
  312:         my ($numitems,$midpoint,$seconddiv,$count); 
  313:         $numitems = @prefs_order;
  314:         $midpoint = int($numitems/2);
  315:         if ($numitems%2) {
  316:             $midpoint ++;
  317:         }
  318:         $count = 0;
  319:         foreach my $item (@prefs_order) {
  320:             $r->print('<h4><label><input type="checkbox" name="actions" value="'.$item.'" />&nbsp;'.&mt($prefs{$item}->{'text'}).'</label></h4>');
  321:             $count ++;
  322:             if ((!$seconddiv) && ($count >= $midpoint)) {
  323:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  324:                 $seconddiv = 1;
  325:             }
  326:         }
  327:         $r->print('</div><div class="LC_clear_float_footer"></div><h3>'.
  328:                   &mt('Display options').'</h3>'."\n".
  329:                   '<p><span class="LC_nobreak">'.&mt('Display using: ')."\n".
  330:                   '<label><input type="radio" name="numcols" value="1" />'.
  331:                   &mt('one column').'</label>&nbsp;&nbsp;<label>'.
  332:                   '<input type="radio" name="numcols" value="2" />'.
  333:                   &mt('two columns').'</label></span></p>');
  334:         $r->print(&print_footer($r,$phase,'display','Go'));
  335:         $r->print('</form>');
  336:         $r->print(&Apache::loncommon::end_page());
  337:     }
  338:     return OK;
  339: }
  340: 
  341: sub process_changes {
  342:     my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
  343:     my $output;
  344:     if ($action eq 'login') {
  345:         $output = &modify_login($r,$dom,$confname,%domconfig);
  346:     } elsif ($action eq 'rolecolors') {
  347:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
  348:                                      %domconfig);
  349:     } elsif ($action eq 'quotas') {
  350:         $output = &modify_quotas($dom,%domconfig);
  351:     } elsif ($action eq 'autoenroll') {
  352:         $output = &modify_autoenroll($dom,%domconfig);
  353:     } elsif ($action eq 'autoupdate') {
  354:         $output = &modify_autoupdate($dom,%domconfig);
  355:     } elsif ($action eq 'directorysrch') {
  356:         $output = &modify_directorysrch($dom,%domconfig);
  357:     } elsif ($action eq 'usercreation') {
  358:         $output = &modify_usercreation($dom,%domconfig);
  359:     } elsif ($action eq 'usermodification') {
  360:         $output = &modify_usermodification($dom,%domconfig);
  361:     } elsif ($action eq 'contacts') {
  362:         $output = &modify_contacts($dom,%domconfig);
  363:     } elsif ($action eq 'defaults') {
  364:         $output = &modify_defaults($dom,$r);
  365:     } elsif ($action eq 'scantron') {
  366:         $output = &modify_scantron($r,$dom,$confname,%domconfig);
  367:     } elsif ($action eq 'coursecategories') {
  368:         $output = &modify_coursecategories($dom,%domconfig);
  369:     }
  370:     return $output;
  371: }
  372: 
  373: sub print_config_box {
  374:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
  375:     my $rowtotal = 0;
  376:     my $output;
  377:     if ($action eq 'coursecategories') {
  378:         $output = &coursecategories_javascript($settings);
  379:     }  
  380:     $output .= 
  381:          '<table class="LC_nested_outer">
  382:           <tr>
  383:            <th align="left"><span class="LC_nobreak">'.&mt($item->{text}).
  384:            '&nbsp;</span></th></tr>';
  385: # 
  386: # FIXME - put the help link back in when the help files exist
  387: #           <th>'.&mt($item->{text}).'&nbsp;'.
  388: #           &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
  389: #          </tr>');
  390:     $rowtotal ++;
  391:     if (($action eq 'autoupdate') || ($action eq 'rolecolors') || 
  392:         ($action eq 'usercreation') || ($action eq 'usermodification') ||
  393:         ($action eq 'coursecategories')) {
  394:         my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
  395:         $output .= '
  396:           <tr>
  397:            <td>
  398:             <table class="LC_nested">
  399:              <tr class="LC_info_row">
  400:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
  401:               <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
  402:              </tr>';
  403:              $rowtotal ++;
  404:         if ($action eq 'autoupdate') {
  405:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
  406:         } elsif ($action eq 'usercreation') {
  407:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
  408:         } elsif ($action eq 'usermodification') {
  409:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
  410:         } elsif ($action eq 'coursecategories') {
  411:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
  412:         } else {
  413:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
  414:         }
  415:         $output .= '
  416:            </table>
  417:           </td>
  418:          </tr>
  419:          <tr>
  420:            <td>
  421:             <table class="LC_nested">
  422:              <tr class="LC_info_row">
  423:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
  424:         my $colspan = ($action eq 'coursecategories')?' colspan="2"':'';
  425:         $output .= '
  426:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
  427:              </tr>';
  428:             $rowtotal ++;
  429:         if ($action eq 'autoupdate') {
  430:             $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
  431:         } elsif ($action eq 'usercreation') {
  432:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
  433:            </table>
  434:           </td>
  435:          </tr>
  436:          <tr>
  437:            <td>
  438:             <table class="LC_nested">
  439:              <tr class="LC_info_row">
  440:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  441:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
  442:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
  443:             $rowtotal ++;
  444:         } elsif ($action eq 'usermodification') {
  445:             $output .= &print_usermodification('bottom',$dom,$settings,\$rowtotal);
  446:         } elsif ($action eq 'coursecategories') {
  447:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
  448:         } else {
  449:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
  450:            </table>
  451:           </td>
  452:          </tr>
  453:          <tr>
  454:            <td>
  455:             <table class="LC_nested">
  456:              <tr class="LC_info_row">
  457:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  458:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
  459:              </tr>'.
  460:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
  461:            </table>
  462:           </td>
  463:          </tr>
  464:          <tr>
  465:            <td>
  466:             <table class="LC_nested">
  467:              <tr class="LC_info_row">
  468:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
  469:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
  470:              </tr>'.
  471:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
  472:             $rowtotal += 2;
  473:         }
  474:     } else {
  475:         $output .= '
  476:           <tr>
  477:            <td>
  478:             <table class="LC_nested">
  479:              <tr class="LC_info_row">';
  480:         if (($action eq 'login') || ($action eq 'directorysrch')) {
  481:             $output .= '  
  482:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  483:         } else {
  484:             $output .= '
  485:               <td class="LC_left_item">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  486:         }
  487:         $output .= '
  488:               <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
  489:              </tr>';
  490:         $rowtotal ++;
  491:         if ($action eq 'login') {
  492:             $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal);
  493:         } elsif ($action eq 'quotas') {
  494:             $output .= &print_quotas($dom,$settings,\$rowtotal);
  495:         } elsif ($action eq 'autoenroll') {
  496:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
  497:         } elsif ($action eq 'directorysrch') {
  498:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
  499:         } elsif ($action eq 'contacts') {
  500:             $output .= &print_contacts($dom,$settings,\$rowtotal);
  501:         } elsif ($action eq 'defaults') {
  502:             $output .= &print_defaults($dom,\$rowtotal);
  503:         } elsif ($action eq 'scantron') {
  504:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
  505:         }
  506:     }
  507:     $output .= '
  508:    </table>
  509:   </td>
  510:  </tr>
  511: </table><br />';
  512:     return ($output,$rowtotal);
  513: }
  514: 
  515: sub print_header {
  516:     my ($r,$phase) = @_;
  517:     my $alert = &mt('You must select at least one functionality type to display.'); 
  518:     my $js = '
  519: <script type="text/javascript">
  520: function changePage(formname,newphase) {
  521:     formname.phase.value = newphase;
  522:     numchecked = 0;
  523:     if (formname == document.pickactions) {
  524:         if (formname.actions.length > 0) {
  525:             for (var i = 0; i<formname.actions.length; i++) {
  526:                 if (formname.actions[i].checked) {
  527:                     numchecked ++;
  528:                 }
  529:             }
  530:         } else {
  531:             if (formname.actions.checked) {
  532:                 numchecked ++;
  533:             }
  534:         }
  535:         if (numchecked > 0) {
  536:             formname.submit();
  537:         } else {
  538:             alert("'.$alert.'");
  539:             return;
  540:         }
  541:     }
  542:     formname.submit();
  543: }'."\n";
  544:     if ($phase eq 'pickactions') {
  545:         $js .= 
  546:             &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox',numcols => 'radio',})."\n".
  547:             &javascript_set_colnums();
  548:     } elsif ($phase eq 'display') {
  549:         $js .= &color_pick_js()."\n";
  550:     }
  551:     $js .= &Apache::loncommon::viewport_size_js().'
  552: </script>
  553: ';
  554:     my $additem;
  555:     if ($phase eq 'pickactions') {
  556:         my %loaditems = (
  557:                     'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);setDisplayColumns();setFormElements(document.pickactions);",
  558:                         );
  559:         $additem = {'add_entries' => \%loaditems,};
  560:     } else {
  561:         my %loaditems = (
  562:                     'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);",
  563:                         );
  564:         $additem = {'add_entries' => \%loaditems,};
  565:     }
  566:     $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
  567:                                            $js,$additem));
  568:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
  569:     $r->print('
  570: <form name="parmform" action="">
  571: <input type="hidden" name="pres_marker" />
  572: <input type="hidden" name="pres_type" />
  573: <input type="hidden" name="pres_value" />
  574: </form>
  575: ');
  576:     $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
  577:               ' enctype="multipart/form-data">');
  578:     return;
  579: }
  580: 
  581: sub print_footer {
  582:     my ($r,$phase,$newphase,$button_text,$actions) = @_;
  583:     $button_text = &mt($button_text);
  584:     $r->print('<input type="hidden" name="phase" value="" />'.
  585:               '<input type="hidden" name="width" value="'.
  586:               $env{'form.width'}.'" />'.
  587:               '<input type="hidden" name="height" value="'.
  588:               $env{'form.height'}.'" />');
  589:     if (($phase eq 'display') || ($phase eq 'process')) {
  590:         if (ref($actions) eq 'ARRAY') {
  591:             foreach my $item (@{$actions}) {
  592:                 $r->print('<input type="hidden" name="actions" value="'.$item.'" />')."\n";
  593:             }
  594:         }
  595:         $r->print('<input type="hidden" name="numcols" value="'.$env{'form.numcols'}.'" />');
  596:     }
  597:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  598:     if ($phase eq 'process') {
  599:         $r->print('<p><a href='.$dest.'>'.$button_text.'</a></p>');
  600:     } else {
  601:         my $onclick;
  602:         if ($phase eq 'display') {
  603:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  604:         } else {
  605:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  606:         } 
  607:         $r->print('<p><input type="button" name="store" value="'.
  608:                   $button_text.'" onclick='.$onclick.' /></p>');
  609:     }
  610:     if ($phase eq 'process') {
  611:         $r->print('</form>'.&Apache::loncommon::end_page());
  612:     }
  613:     return;
  614: }
  615: 
  616: sub print_login {
  617:     my ($dom,$confname,$phase,$settings,$rowtotal) = @_;
  618:     my %choices = &login_choices();
  619:     my %defaultchecked = ( 
  620:                            'coursecatalog' => 'on',
  621:                            'adminmail'     => 'off',
  622:                            'newuser'       => 'off',
  623:                          );
  624:     my @toggles = ('coursecatalog','adminmail','newuser');
  625:     my (%checkedon,%checkedoff);
  626:     foreach my $item (@toggles) {
  627:         if ($defaultchecked{$item} eq 'on') { 
  628:             $checkedon{$item} = ' checked="checked" ';
  629:             $checkedoff{$item} = ' ';
  630:         } elsif ($defaultchecked{$item} eq 'off') {
  631:             $checkedoff{$item} = ' checked="checked" ';
  632:             $checkedon{$item} = ' ';
  633:         }
  634:     }
  635:     my $loginheader = 'image';
  636:     my @images = ('img','logo','domlogo','login');
  637:     my @logintext = ('textcol','bgcol');
  638:     my @bgs = ('pgbg','mainbg','sidebg');
  639:     my @links = ('link','alink','vlink');
  640:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  641:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  642:     my (%is_custom,%designs);
  643:     my %defaults = (
  644:                    font => $defaultdesign{'login.font'},
  645:                    );
  646:     foreach my $item (@images) {
  647:         $defaults{$item} = $defaultdesign{'login.'.$item};
  648:     }
  649:     foreach my $item (@bgs) {
  650:         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
  651:     }
  652:     foreach my $item (@logintext) {
  653:         $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
  654:     }
  655:     foreach my $item (@links) {
  656:         $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
  657:     }
  658:     if (ref($settings) eq 'HASH') {
  659:         foreach my $item (@toggles) {
  660:             if ($settings->{$item} eq '1') {
  661:                 $checkedon{$item} =  ' checked="checked" ';
  662:                 $checkedoff{$item} = ' ';
  663:             } elsif ($settings->{$item} eq '0') {
  664:                 $checkedoff{$item} =  ' checked="checked" ';
  665:                 $checkedon{$item} = ' ';
  666:             }
  667:         }
  668:         foreach my $item (@images) {
  669:             if ($settings->{$item} ne '') {
  670:                 $designs{$item} = $settings->{$item};
  671:                 $is_custom{$item} = 1;
  672:             }
  673:         }
  674:         foreach my $item (@logintext) {
  675:             if ($settings->{$item} ne '') {
  676:                 $designs{'logintext'}{$item} = $settings->{$item};
  677:                 $is_custom{$item} = 1;
  678:             }
  679:         }
  680:         if ($settings->{'loginheader'} ne '') {
  681:             $loginheader = $settings->{'loginheader'};
  682:         }
  683:         if ($settings->{'font'} ne '') {
  684:             $designs{'font'} = $settings->{'font'};
  685:             $is_custom{'font'} = 1;
  686:         }
  687:         foreach my $item (@bgs) {
  688:             if ($settings->{$item} ne '') {
  689:                 $designs{'bgs'}{$item} = $settings->{$item};
  690:                 $is_custom{$item} = 1;
  691:             }
  692:         }
  693:         foreach my $item (@links) {
  694:             if ($settings->{$item} ne '') {
  695:                 $designs{'links'}{$item} = $settings->{$item};
  696:                 $is_custom{$item} = 1;
  697:             }
  698:         }
  699:     } else {
  700:         if ($designhash{$dom.'.login.font'} ne '') {
  701:             $designs{'font'} = $designhash{$dom.'.login.font'};
  702:             $is_custom{'font'} = 1;
  703:         }
  704:         foreach my $item (@images) {
  705:             if ($designhash{$dom.'.login.'.$item} ne '') {
  706:                 $designs{$item} = $designhash{$dom.'.login.'.$item};
  707:                 $is_custom{$item} = 1;
  708:             }
  709:         }
  710:         foreach my $item (@bgs) {
  711:             if ($designhash{$dom.'.login.'.$item} ne '') {
  712:                 $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
  713:                 $is_custom{$item} = 1;
  714:             }
  715:         }
  716:         foreach my $item (@links) {
  717:             if ($designhash{$dom.'.login.'.$item} ne '') {
  718:                 $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
  719:                 $is_custom{$item} = 1;
  720:             }
  721:         }
  722:     }
  723:     my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
  724:                                                   logo => 'Institution Logo',
  725:                                                   domlogo => 'Domain Logo',
  726:                                                   login => 'Login box');
  727:     my $itemcount = 1;
  728:     my ($css_class,$datatable);
  729:     foreach my $item (@toggles) {
  730:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
  731:         $datatable .=  
  732:             '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
  733:             '</td><td>'.
  734:             '<span class="LC_nobreak"><label><input type="radio" name="'.
  735:             $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
  736:             '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
  737:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
  738:             '</tr>';
  739:         $itemcount ++;
  740:     }
  741:     $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext,$loginheader);
  742:     $datatable .= '</tr></table></td></tr>';
  743:     return $datatable;
  744: }
  745: 
  746: sub login_choices {
  747:     my %choices =
  748:         &Apache::lonlocal::texthash (
  749:             coursecatalog => 'Display Course Catalog link?',
  750:             adminmail => "Display Administrator's E-mail Address?",
  751:             newuser   => "Link to create a user account",
  752:             img => "Header",
  753:             logo => "Main Logo",
  754:             domlogo => "Domain Logo",
  755:             login => "Log-in Header", 
  756:             textcol => "Text color",
  757:             bgcol   => "Box color",
  758:             bgs => "Background colors",
  759:             links => "Link colors",
  760:             font => "Font color",
  761:             pgbg => "Page",
  762:             mainbg => "Main panel",
  763:             sidebg => "Side panel",
  764:             link => "Link",
  765:             alink => "Active link",
  766:             vlink => "Visited link",
  767:         );
  768:     return %choices;
  769: }
  770: 
  771: sub print_rolecolors {
  772:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
  773:     my %choices = &color_font_choices();
  774:     my @bgs = ('pgbg','tabbg','sidebg');
  775:     my @links = ('link','alink','vlink');
  776:     my @images = ('img');
  777:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
  778:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  779:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  780:     my (%is_custom,%designs);
  781:     my %defaults = (
  782:                    img => $defaultdesign{$role.'.img'},
  783:                    font => $defaultdesign{$role.'.font'},
  784:                    );
  785:     foreach my $item (@bgs) {
  786:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
  787:     }
  788:     foreach my $item (@links) {
  789:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
  790:     }
  791:     if (ref($settings) eq 'HASH') {
  792:         if (ref($settings->{$role}) eq 'HASH') {
  793:             if ($settings->{$role}->{'img'} ne '') {
  794:                 $designs{'img'} = $settings->{$role}->{'img'};
  795:                 $is_custom{'img'} = 1;
  796:             }
  797:             if ($settings->{$role}->{'font'} ne '') {
  798:                 $designs{'font'} = $settings->{$role}->{'font'};
  799:                 $is_custom{'font'} = 1;
  800:             }
  801:             foreach my $item (@bgs) {
  802:                 if ($settings->{$role}->{$item} ne '') {
  803:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
  804:                     $is_custom{$item} = 1;
  805:                 }
  806:             }
  807:             foreach my $item (@links) {
  808:                 if ($settings->{$role}->{$item} ne '') {
  809:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
  810:                     $is_custom{$item} = 1;
  811:                 }
  812:             }
  813:         }
  814:     } else {
  815:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  816:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
  817:             $is_custom{'img'} = 1;
  818:         }
  819:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
  820:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
  821:             $is_custom{'font'} = 1;
  822:         }
  823:         foreach my $item (@bgs) {
  824:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  825:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  826:                 $is_custom{$item} = 1;
  827:             
  828:             }
  829:         }
  830:         foreach my $item (@links) {
  831:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  832:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  833:                 $is_custom{$item} = 1;
  834:             }
  835:         }
  836:     }
  837:     my $itemcount = 1;
  838:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
  839:     $datatable .= '</tr></table></td></tr>';
  840:     return $datatable;
  841: }
  842: 
  843: sub display_color_options {
  844:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
  845:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext,$loginheader) = @_;
  846:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
  847:     my $datatable = '<tr'.$css_class.'>'.
  848:         '<td>'.$choices->{'font'}.'</td>';
  849:     if (!$is_custom->{'font'}) {
  850:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
  851:     } else {
  852:         $datatable .= '<td>&nbsp;</td>';
  853:     }
  854:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
  855:     $datatable .= '<td><span class="LC_nobreak">'.
  856:                   '<input type="text" size="10" name="'.$role.'_font"'.
  857:                   ' value="'.$designs->{'font'}.'" />&nbsp;'.$fontlink.
  858:                   '&nbsp;<span id="css_'.$role.'_font" style="background-color: '.
  859:                   $designs->{'font'}.';">&nbsp;&nbsp;&nbsp;</span>'.
  860:                   '</span></td></tr>';
  861:     my $switchserver = &check_switchserver($dom,$confname);
  862:     foreach my $img (@{$images}) {
  863: 	$itemcount ++;
  864:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
  865:         $datatable .= '<tr'.$css_class.'>'.
  866:                       '<td>'.$choices->{$img}.'</td>';
  867:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
  868:         if ($designs->{$img} ne '') {
  869:             $imgfile = $designs->{$img};
  870: 	    $img_import = ($imgfile =~ m{^/adm/});
  871:         } else {
  872:             $imgfile = $defaults->{$img};
  873:         }
  874:         if ($img eq 'login') {
  875:             $login_hdr_pick = &login_header_options($img,$role,$defaults,$is_custom,$choices,
  876:                                                     $loginheader);
  877:             $logincolors =
  878:                 &login_text_colors($img,$role,$logintext,$phase,$choices,$designs);
  879:         }
  880:         if ($imgfile) {
  881:             my ($showfile,$fullsize);
  882:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
  883:                 my $urldir = $1;
  884:                 my $filename = $2;
  885:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
  886:                 if (@info) {
  887:                     my $thumbfile = 'tn-'.$filename;
  888:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
  889:                     if (@thumb) {
  890:                         $showfile = $urldir.'/'.$thumbfile;
  891:                     } else {
  892:                         $showfile = $imgfile;
  893:                     }
  894:                 } else {
  895:                     $showfile = '';
  896:                 }
  897:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
  898:                 $showfile = $imgfile;
  899:                 my $imgdir = $1;
  900:                 my $filename = $2;
  901:                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
  902:                     $showfile = "/$imgdir/tn-".$filename;
  903:                 } else {
  904:                     my $input = "/home/httpd/html".$imgfile;
  905:                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
  906:                     if (!-e $output) {
  907:                         my ($width,$height) = &thumb_dimensions();
  908:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
  909:                         if ($fullwidth ne '' && $fullheight ne '') {
  910:                             if ($fullwidth > $width && $fullheight > $height) { 
  911:                                 my $size = $width.'x'.$height;
  912:                                 system("convert -sample $size $input $output");
  913:                                 $showfile = '/'.$imgdir.'/tn-'.$filename;
  914:                             }
  915:                         }
  916:                     }
  917:                 }
  918:             }
  919:             if ($showfile) {
  920:                 if ($showfile =~ m{^/(adm|res)/}) {
  921:                     if ($showfile =~ m{^/res/}) {
  922:                         my $local_showfile =
  923:                             &Apache::lonnet::filelocation('',$showfile);
  924:                         &Apache::lonnet::repcopy($local_showfile);
  925:                     }
  926:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
  927:                 }
  928:                 if ($imgfile) {
  929:                     if ($imgfile  =~ m{^/(adm|res)/}) {
  930:                         if ($imgfile =~ m{^/res/}) {
  931:                             my $local_imgfile =
  932:                                 &Apache::lonnet::filelocation('',$imgfile);
  933:                             &Apache::lonnet::repcopy($local_imgfile);
  934:                         }
  935:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
  936:                     } else {
  937:                         $fullsize = $imgfile;
  938:                     }
  939:                 }
  940:                 $datatable .= '<td>';
  941:                 if ($img eq 'login') {
  942:                     $datatable .= $login_hdr_pick;    
  943:                 }
  944:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
  945:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
  946:             } else {
  947:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
  948:                               &mt('Upload:');
  949:             }
  950:         } else {
  951:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
  952:                           &mt('Upload:');
  953:         }
  954:         if ($switchserver) {
  955:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
  956:         } else {
  957:             $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
  958:         }
  959:         $datatable .= '</td></tr>';
  960:     }
  961:     $itemcount ++;
  962:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  963:     $datatable .= '<tr'.$css_class.'>'.
  964:                   '<td>'.$choices->{'bgs'}.'</td>';
  965:     my $bgs_def;
  966:     foreach my $item (@{$bgs}) {
  967:         if (!$is_custom->{$item}) {
  968:             $bgs_def .= '<td>'.$choices->{$item}.'&nbsp;<span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span><br />'.$defaults->{'bgs'}{$item}.'</td>';
  969:         }
  970:     }
  971:     if ($bgs_def) {
  972:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
  973:     } else {
  974:         $datatable .= '<td>&nbsp;</td>';
  975:     }
  976:     $datatable .= '<td class="LC_right_item">'.
  977:                   '<table border="0"><tr>';
  978:     foreach my $item (@{$bgs}) {
  979:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
  980:         $datatable .= '<td align="center">'.$link;
  981:         if ($designs->{'bgs'}{$item}) {
  982:             $datatable .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
  983:         }
  984:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
  985:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
  986:     }
  987:     $datatable .= '</tr></table></td></tr>';
  988:     $itemcount ++;
  989:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  990:     $datatable .= '<tr'.$css_class.'>'.
  991:                   '<td>'.$choices->{'links'}.'</td>';
  992:     my $links_def;
  993:     foreach my $item (@{$links}) {
  994:         if (!$is_custom->{$item}) {
  995:             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
  996:         }
  997:     }
  998:     if ($links_def) {
  999:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
 1000:     } else {
 1001:         $datatable .= '<td>&nbsp;</td>';
 1002:     }
 1003:     $datatable .= '<td class="LC_right_item">'.
 1004:                   '<table border="0"><tr>';
 1005:     foreach my $item (@{$links}) {
 1006:         $datatable .= '<td align="center">'."\n".
 1007:                       &color_pick($phase,$role,$item,$choices->{$item},
 1008:                                   $designs->{'links'}{$item});
 1009:         if ($designs->{'links'}{$item}) {
 1010:             $datatable.='&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
 1011:         }
 1012:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
 1013:                       '" /></td>';
 1014:     }
 1015:     $$rowtotal += $itemcount;
 1016:     return $datatable;
 1017: }
 1018: 
 1019: sub login_header_options  {
 1020:     my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_;
 1021:     my $image_checked = ' checked="checked" ';
 1022:     my $text_checked = ' ';
 1023:     if ($loginheader eq 'text') {
 1024:         $image_checked = ' ';
 1025:         $text_checked = ' checked="checked" ';
 1026:     }
 1027:     my $output = '<span class="LC_nobreak"><label><input type="radio" name="'.
 1028:               'loginheader" value="image" '.$image_checked.'/>'.
 1029:               &mt('use image').'</label>&nbsp;&nbsp;&nbsp;'.
 1030:               '<label><input type="radio" name="loginheader" value="text"'.
 1031:               $text_checked.'/>'.&mt('use text').'</label><br />'."\n";
 1032:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
 1033:         $output .= &mt('Text default(s)').':<br />';
 1034:         if (!$is_custom->{'textcol'}) {
 1035:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
 1036:                        '&nbsp;&nbsp;&nbsp;';
 1037:         }
 1038:         if (!$is_custom->{'bgcol'}) {
 1039:             $output .= $choices->{'bgcol'}.':&nbsp;'.
 1040:                        '<span id="css_'.$role.'_font" style="background-color: '.
 1041:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
 1042:         }
 1043:         $output .= '<br />';
 1044:     }
 1045:     $output .='<br />';
 1046:     return $output;
 1047: }
 1048: 
 1049: sub login_text_colors {
 1050:     my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
 1051:     my $color_menu = '<table border="0"><tr>';
 1052:     foreach my $item (@{$logintext}) {
 1053:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
 1054:         $color_menu .= '<td align="center">'.$link;
 1055:         if ($designs->{'logintext'}{$item}) {
 1056:             $color_menu .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
 1057:         }
 1058:         $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
 1059:                        $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
 1060:                        '<td>&nbsp;</td>';
 1061:     }
 1062:     $color_menu .= '</tr></table><br />';
 1063:     return $color_menu;
 1064: }
 1065: 
 1066: sub image_changes {
 1067:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
 1068:     my $output;
 1069:     if (!$is_custom) {
 1070:         if ($img eq 'login') {
 1071:             $output .= &mt('Default image:').'<br />';
 1072:         } else {
 1073:             $output .= &mt('Default in use:').'<br />';
 1074:         }
 1075:     }
 1076:     if ($img_import) {
 1077:         $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
 1078:     }
 1079:     $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
 1080:                $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
 1081:     if ($is_custom) {
 1082:         $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
 1083:                    '<input type="checkbox" name="'.
 1084:                    $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
 1085:                    '</label>&nbsp;'.&mt('Replace:').'</span><br />';
 1086:     } else {
 1087:         $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
 1088:     }
 1089:     return $output;
 1090: }
 1091: 
 1092: sub color_pick {
 1093:     my ($phase,$role,$item,$desc,$curcol) = @_;
 1094:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
 1095:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
 1096:                ');">'.$desc.'</a>';
 1097:     return $link;
 1098: }
 1099: 
 1100: sub color_pick_js {
 1101:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
 1102:     my $output = <<"ENDCOL";
 1103:     function pclose() {
 1104:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
 1105:         parmwin.close();
 1106:     }
 1107: 
 1108:     $pjump_def
 1109: 
 1110:     function psub() {
 1111:         pclose();
 1112:         if (document.parmform.pres_marker.value!='') {
 1113:             if (document.parmform.pres_type.value!='') {
 1114:                 eval('document.display.'+
 1115:                      document.parmform.pres_marker.value+
 1116:                      '.value=document.parmform.pres_value.value;');
 1117:             }
 1118:         } else {
 1119:             document.parmform.pres_value.value='';
 1120:             document.parmform.pres_marker.value='';
 1121:         }
 1122:     }
 1123: 
 1124:     function get_id (span_id) {
 1125: 	if (document.getElementById) {
 1126:             return document.getElementById(span_id);
 1127:         }
 1128: 	if (document.all) {
 1129:             return document.all[span_id];
 1130:         } 
 1131: 	return false;
 1132:     }
 1133: 
 1134:     function colchg_span (span_id_str,new_color_item) {
 1135: 	var span_ref = get_id(span_id_str);
 1136: 	if (span_ref.style) { span_ref = span_ref.style; }
 1137: 	span_ref.background = new_color_item.value;
 1138: 	span_ref.backgroundColor = new_color_item.value;
 1139: 	span_ref.bgColor = new_color_item.value;
 1140:     }
 1141: 
 1142: ENDCOL
 1143:     return $output;
 1144: }
 1145: 
 1146: sub print_quotas {
 1147:     my ($dom,$settings,$rowtotal) = @_;
 1148:     my $datatable;
 1149:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1150:     my $typecount = 0;
 1151:     my $css_class;
 1152:     if (ref($types) eq 'ARRAY') {
 1153:         foreach my $type (@{$types}) {
 1154:             if (defined($usertypes->{$type})) {
 1155:                 $typecount ++;
 1156:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
 1157:                 $datatable .= '<tr'.$css_class.'>'. 
 1158:                               '<td>'.$usertypes->{$type}.'</td>'.
 1159:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
 1160:                               '<input type="text" name="quota_'.$type.
 1161:                               '" value="'.$settings->{$type}.
 1162:                               '" size="5" /> Mb</span></td></tr>';
 1163:             }
 1164:         }
 1165:     }
 1166:     my $defaultquota = '20';
 1167:     if (ref($settings) eq 'HASH') {
 1168:         if (defined($settings->{'default'})) {
 1169:             $defaultquota = $settings->{'default'};
 1170:         }
 1171:     }
 1172:     $typecount ++;
 1173:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1174:     $datatable .= '<tr'.$css_class.'>'.
 1175:                   '<td>'.$othertitle.'</td>'.
 1176:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 1177:                   '<input type="text" name="defaultquota" value="'.
 1178:                   $defaultquota.'" size="5" /> Mb</span></td></tr>';
 1179:     $$rowtotal += $typecount;
 1180:     return $datatable;
 1181: }
 1182: 
 1183: sub print_autoenroll {
 1184:     my ($dom,$settings,$rowtotal) = @_;
 1185:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 1186:     my ($defdom,$runon,$runoff);
 1187:     if (ref($settings) eq 'HASH') {
 1188:         if (exists($settings->{'run'})) {
 1189:             if ($settings->{'run'} eq '0') {
 1190:                 $runoff = ' checked="checked" ';
 1191:                 $runon = ' ';
 1192:             } else {
 1193:                 $runon = ' checked="checked" ';
 1194:                 $runoff = ' ';
 1195:             }
 1196:         } else {
 1197:             if ($autorun) {
 1198:                 $runon = ' checked="checked" ';
 1199:                 $runoff = ' ';
 1200:             } else {
 1201:                 $runoff = ' checked="checked" ';
 1202:                 $runon = ' ';
 1203:             }
 1204:         }
 1205:         if (exists($settings->{'sender_domain'})) {
 1206:             $defdom = $settings->{'sender_domain'};
 1207:         }
 1208:     } else {
 1209:         if ($autorun) {
 1210:             $runon = ' checked="checked" ';
 1211:             $runoff = ' ';
 1212:         } else {
 1213:             $runoff = ' checked="checked" ';
 1214:             $runon = ' ';
 1215:         }
 1216:     }
 1217:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
 1218:     my $notif_sender;
 1219:     if (ref($settings) eq 'HASH') {
 1220:         $notif_sender = $settings->{'sender_uname'};
 1221:     }
 1222:     my $datatable='<tr class="LC_odd_row">'.
 1223:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
 1224:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1225:                   '<input type="radio" name="autoenroll_run"'.
 1226:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1227:                   '<label><input type="radio" name="autoenroll_run"'.
 1228:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1229:                   '</tr><tr>'.
 1230:                   '<td>'.&mt('Notification messages - sender').
 1231:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 1232:                   &mt('username').':&nbsp;'.
 1233:                   '<input type="text" name="sender_uname" value="'.
 1234:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
 1235:                   ':&nbsp;'.$domform.'</span></td></tr>';
 1236:     $$rowtotal += 2;
 1237:     return $datatable;
 1238: }
 1239: 
 1240: sub print_autoupdate {
 1241:     my ($position,$dom,$settings,$rowtotal) = @_;
 1242:     my $datatable;
 1243:     if ($position eq 'top') {
 1244:         my $updateon = ' ';
 1245:         my $updateoff = ' checked="checked" ';
 1246:         my $classlistson = ' ';
 1247:         my $classlistsoff = ' checked="checked" ';
 1248:         if (ref($settings) eq 'HASH') {
 1249:             if ($settings->{'run'} eq '1') {
 1250:                 $updateon = $updateoff;
 1251:                 $updateoff = ' ';
 1252:             }
 1253:             if ($settings->{'classlists'} eq '1') {
 1254:                 $classlistson = $classlistsoff;
 1255:                 $classlistsoff = ' ';
 1256:             }
 1257:         }
 1258:         my %title = (
 1259:                    run => 'Auto-update active?',
 1260:                    classlists => 'Update information in classlists?',
 1261:                     );
 1262:         $datatable = '<tr class="LC_odd_row">'. 
 1263:                   '<td>'.&mt($title{'run'}).'</td>'.
 1264:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1265:                   '<input type="radio" name="autoupdate_run"'.
 1266:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1267:                   '<label><input type="radio" name="autoupdate_run"'.
 1268:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
 1269:                   '</tr><tr>'.
 1270:                   '<td>'.&mt($title{'classlists'}).'</td>'.
 1271:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 1272:                   '<label><input type="radio" name="classlists"'.
 1273:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1274:                   '<label><input type="radio" name="classlists"'.
 1275:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
 1276:                   '</tr>';
 1277:         $$rowtotal += 2;
 1278:     } else {
 1279:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1280:         my @fields = ('lastname','firstname','middlename','gen',
 1281:                       'permanentemail','id');
 1282:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 1283:         my $numrows = 0;
 1284:         if (ref($types) eq 'ARRAY') {
 1285:             if (@{$types} > 0) {
 1286:                 $datatable = 
 1287:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
 1288:                                          \@fields,$types,\$numrows);
 1289:                     $$rowtotal += @{$types}; 
 1290:             }
 1291:         }
 1292:         $datatable .= 
 1293:             &usertype_update_row($settings,{'default' => $othertitle},
 1294:                                  \%fieldtitles,\@fields,['default'],
 1295:                                  \$numrows);
 1296:         $$rowtotal ++;     
 1297:     }
 1298:     return $datatable;
 1299: }
 1300: 
 1301: sub print_directorysrch {
 1302:     my ($dom,$settings,$rowtotal) = @_;
 1303:     my $srchon = ' ';
 1304:     my $srchoff = ' checked="checked" ';
 1305:     my ($exacton,$containson,$beginson);
 1306:     my $localon = ' ';
 1307:     my $localoff = ' checked="checked" ';
 1308:     if (ref($settings) eq 'HASH') {
 1309:         if ($settings->{'available'} eq '1') {
 1310:             $srchon = $srchoff;
 1311:             $srchoff = ' ';
 1312:         }
 1313:         if ($settings->{'localonly'} eq '1') {
 1314:             $localon = $localoff;
 1315:             $localoff = ' ';
 1316:         }
 1317:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
 1318:             foreach my $type (@{$settings->{'searchtypes'}}) {
 1319:                 if ($type eq 'exact') {
 1320:                     $exacton = ' checked="checked" ';
 1321:                 } elsif ($type eq 'contains') {
 1322:                     $containson = ' checked="checked" ';
 1323:                 } elsif ($type eq 'begins') {
 1324:                     $beginson = ' checked="checked" ';
 1325:                 }
 1326:             }
 1327:         } else {
 1328:             if ($settings->{'searchtypes'} eq 'exact') {
 1329:                 $exacton = ' checked="checked" ';
 1330:             } elsif ($settings->{'searchtypes'} eq 'contains') {
 1331:                 $containson = ' checked="checked" ';
 1332:             } elsif ($settings->{'searchtypes'} eq 'specify') {
 1333:                 $exacton = ' checked="checked" ';
 1334:                 $containson = ' checked="checked" ';
 1335:             }
 1336:         }
 1337:     }
 1338:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
 1339:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1340: 
 1341:     my $numinrow = 4;
 1342:     my $cansrchrow = 0;
 1343:     my $datatable='<tr class="LC_odd_row">'.
 1344:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
 1345:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1346:                   '<input type="radio" name="dirsrch_available"'.
 1347:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1348:                   '<label><input type="radio" name="dirsrch_available"'.
 1349:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1350:                   '</tr><tr>'.
 1351:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
 1352:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1353:                   '<input type="radio" name="dirsrch_localonly"'.
 1354:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
 1355:                   '<label><input type="radio" name="dirsrch_localonly"'.
 1356:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
 1357:                   '</tr>';
 1358:     $$rowtotal += 2;
 1359:     if (ref($usertypes) eq 'HASH') {
 1360:         if (keys(%{$usertypes}) > 0) {
 1361:             $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
 1362:                                                $numinrow,$othertitle);
 1363:             $cansrchrow = 1;
 1364:         }
 1365:     }
 1366:     if ($cansrchrow) {
 1367:         $$rowtotal ++;
 1368:         $datatable .= '<tr>';
 1369:     } else {
 1370:         $datatable .= '<tr class="LC_odd_row">';
 1371:     }
 1372:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
 1373:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
 1374:     foreach my $title (@{$titleorder}) {
 1375:         if (defined($searchtitles->{$title})) {
 1376:             my $check = ' ';
 1377:             if (ref($settings) eq 'HASH') { 
 1378:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
 1379:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
 1380:                         $check = ' checked="checked" ';
 1381:                     }
 1382:                 }
 1383:             }
 1384:             $datatable .= '<td class="LC_left_item">'.
 1385:                           '<span class="LC_nobreak"><label>'.
 1386:                           '<input type="checkbox" name="searchby" '.
 1387:                           'value="'.$title.'"'.$check.'/>'.
 1388:                           $searchtitles->{$title}.'</label></span></td>';
 1389:         }
 1390:     }
 1391:     $datatable .= '</tr></table></td></tr>';
 1392:     $$rowtotal ++;
 1393:     if ($cansrchrow) {
 1394:         $datatable .= '<tr class="LC_odd_row">';
 1395:     } else {
 1396:         $datatable .= '<tr>';
 1397:     }
 1398:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
 1399:                   '<td class="LC_left_item" colspan="2">'.
 1400:                   '<span class="LC_nobreak"><label>'.
 1401:                   '<input type="checkbox" name="searchtypes" '.
 1402:                   $exacton.' value="exact" />'.&mt('Exact match').
 1403:                   '</label>&nbsp;'.
 1404:                   '<label><input type="checkbox" name="searchtypes" '.
 1405:                   $beginson.' value="begins" />'.&mt('Begins with').
 1406:                   '</label>&nbsp;'.
 1407:                   '<label><input type="checkbox" name="searchtypes" '.
 1408:                   $containson.' value="contains" />'.&mt('Contains').
 1409:                   '</label></span></td></tr>';
 1410:     $$rowtotal ++;
 1411:     return $datatable;
 1412: }
 1413: 
 1414: sub print_contacts {
 1415:     my ($dom,$settings,$rowtotal) = @_;
 1416:     my $datatable;
 1417:     my @contacts = ('adminemail','supportemail');
 1418:     my (%checked,%to,%otheremails);
 1419:     my @mailings = ('errormail','packagesmail','helpdeskmail');
 1420:     foreach my $type (@mailings) {
 1421:         $otheremails{$type} = '';
 1422:     }
 1423:     if (ref($settings) eq 'HASH') {
 1424:         foreach my $item (@contacts) {
 1425:             if (exists($settings->{$item})) {
 1426:                 $to{$item} = $settings->{$item};
 1427:             }
 1428:         }
 1429:         foreach my $type (@mailings) {
 1430:             if (exists($settings->{$type})) {
 1431:                 if (ref($settings->{$type}) eq 'HASH') {
 1432:                     foreach my $item (@contacts) {
 1433:                         if ($settings->{$type}{$item}) {
 1434:                             $checked{$type}{$item} = ' checked="checked" ';
 1435:                         }
 1436:                     }
 1437:                     $otheremails{$type} = $settings->{$type}{'others'};
 1438:                 }
 1439:             }
 1440:         }
 1441:     } else {
 1442:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 1443:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 1444:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
 1445:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
 1446:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" '; 
 1447:     }
 1448:     my ($titles,$short_titles) = &contact_titles();
 1449:     my $rownum = 0;
 1450:     my $css_class;
 1451:     foreach my $item (@contacts) {
 1452:         if ($rownum%2) {
 1453:             $css_class = '';
 1454:         } else {
 1455:             $css_class = ' class="LC_odd_row" ';
 1456:         }
 1457:         $datatable .= '<tr'.$css_class.'>'. 
 1458:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 1459:                   '</span></td><td class="LC_right_item">'.
 1460:                   '<input type="text" name="'.$item.'" value="'.
 1461:                   $to{$item}.'" /></td></tr>';
 1462:         $rownum ++;
 1463:     }
 1464:     foreach my $type (@mailings) {
 1465:         if ($rownum%2) {
 1466:             $css_class = '';
 1467:         } else {
 1468:             $css_class = ' class="LC_odd_row" ';
 1469:         }
 1470:         $datatable .= '<tr'.$css_class.'>'.
 1471:                       '<td><span class="LC_nobreak">'.
 1472:                       $titles->{$type}.': </span></td>'.
 1473:                       '<td class="LC_left_item">'.
 1474:                       '<span class="LC_nobreak">';
 1475:         foreach my $item (@contacts) {
 1476:             $datatable .= '<label>'.
 1477:                           '<input type="checkbox" name="'.$type.'"'.
 1478:                           $checked{$type}{$item}.
 1479:                           ' value="'.$item.'" />'.$short_titles->{$item}.
 1480:                           '</label>&nbsp;';
 1481:         }
 1482:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
 1483:                       '<input type="text" name="'.$type.'_others" '.
 1484:                       'value="'.$otheremails{$type}.'"  />'.
 1485:                       '</td></tr>'."\n";
 1486:         $rownum ++;
 1487:     }
 1488:     $$rowtotal += $rownum;
 1489:     return $datatable;
 1490: }
 1491: 
 1492: sub contact_titles {
 1493:     my %titles = &Apache::lonlocal::texthash (
 1494:                    'supportemail' => 'Support E-mail address',
 1495:                    'adminemail'    => 'Default Server Admin E-mail address',
 1496:                    'errormail'    => 'Error reports to be e-mailed to',
 1497:                    'packagesmail' => 'Package update alerts to be e-mailed to',
 1498:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
 1499:                  );
 1500:     my %short_titles = &Apache::lonlocal::texthash (
 1501:                            adminemail   => 'Admin E-mail address',
 1502:                            supportemail => 'Support E-mail',
 1503:                        );   
 1504:     return (\%titles,\%short_titles);
 1505: }
 1506: 
 1507: sub print_usercreation {
 1508:     my ($position,$dom,$settings,$rowtotal) = @_;
 1509:     my $numinrow = 4;
 1510:     my $datatable;
 1511:     if ($position eq 'top') {
 1512:         $$rowtotal ++;
 1513:         my $rowcount = 0;
 1514:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
 1515:         if (ref($rules) eq 'HASH') {
 1516:             if (keys(%{$rules}) > 0) {
 1517:                 $datatable .= &user_formats_row('username',$settings,$rules,
 1518:                                                 $ruleorder,$numinrow,$rowcount);
 1519:                 $$rowtotal ++;
 1520:                 $rowcount ++;
 1521:             }
 1522:         }
 1523:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
 1524:         if (ref($idrules) eq 'HASH') {
 1525:             if (keys(%{$idrules}) > 0) {
 1526:                 $datatable .= &user_formats_row('id',$settings,$idrules,
 1527:                                                 $idruleorder,$numinrow,$rowcount);
 1528:                 $$rowtotal ++;
 1529:                 $rowcount ++;
 1530:             }
 1531:         }
 1532:         my ($emailrules,$emailruleorder) = 
 1533:             &Apache::lonnet::inst_userrules($dom,'email');
 1534:         if (ref($emailrules) eq 'HASH') {
 1535:             if (keys(%{$emailrules}) > 0) {
 1536:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
 1537:                                                 $emailruleorder,$numinrow,$rowcount);
 1538:                 $$rowtotal ++;
 1539:                 $rowcount ++;
 1540:             }
 1541:         }
 1542:         if ($rowcount == 0) {
 1543:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
 1544:             $$rowtotal ++;
 1545:             $rowcount ++;
 1546:         }
 1547:     } elsif ($position eq 'middle') {
 1548:         my @creators = ('author','course','selfcreate');
 1549:         my ($rules,$ruleorder) =
 1550:             &Apache::lonnet::inst_userrules($dom,'username');
 1551:         my %lt = &usercreation_types();
 1552:         my %checked;
 1553:         my @selfcreate; 
 1554:         if (ref($settings) eq 'HASH') {
 1555:             if (ref($settings->{'cancreate'}) eq 'HASH') {
 1556:                 foreach my $item (@creators) {
 1557:                     $checked{$item} = $settings->{'cancreate'}{$item};
 1558:                 }
 1559:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
 1560:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
 1561:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
 1562:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
 1563:                         @selfcreate = ('email','login','sso');
 1564:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
 1565:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
 1566:                     }
 1567:                 }
 1568:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
 1569:                 foreach my $item (@creators) {
 1570:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
 1571:                         $checked{$item} = 'none';
 1572:                     }
 1573:                 }
 1574:             }
 1575:         }
 1576:         my $rownum = 0;
 1577:         foreach my $item (@creators) {
 1578:             $rownum ++;
 1579:             if ($item ne 'selfcreate') {  
 1580:                 if ($checked{$item} eq '') {
 1581:                     $checked{$item} = 'any';
 1582:                 }
 1583:             }
 1584:             my $css_class;
 1585:             if ($rownum%2) {
 1586:                 $css_class = '';
 1587:             } else {
 1588:                 $css_class = ' class="LC_odd_row" ';
 1589:             }
 1590:             $datatable .= '<tr'.$css_class.'>'.
 1591:                          '<td><span class="LC_nobreak">'.$lt{$item}.
 1592:                          '</span></td><td align="right">';
 1593:             my @options;
 1594:             if ($item eq 'selfcreate') {
 1595:                 push(@options,('email','login','sso'));
 1596:             } else {
 1597:                 @options = ('any');
 1598:                 if (ref($rules) eq 'HASH') {
 1599:                     if (keys(%{$rules}) > 0) {
 1600:                         push(@options,('official','unofficial'));
 1601:                     }
 1602:                 }
 1603:                 push(@options,'none');
 1604:             }
 1605:             foreach my $option (@options) {
 1606:                 my $type = 'radio';
 1607:                 my $check = ' ';
 1608:                 if ($item eq 'selfcreate') {
 1609:                     $type = 'checkbox';
 1610:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
 1611:                         $check = ' checked="checked" ';
 1612:                     }
 1613:                 } else {
 1614:                     if ($checked{$item} eq $option) {
 1615:                         $check = ' checked="checked" ';
 1616:                     }
 1617:                 } 
 1618:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1619:                               '<input type="'.$type.'" name="can_createuser_'.
 1620:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
 1621:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
 1622:             }
 1623:             $datatable .= '</td></tr>';
 1624:         }
 1625:     } else {
 1626:         my @contexts = ('author','course','domain');
 1627:         my @authtypes = ('int','krb4','krb5','loc');
 1628:         my %checked;
 1629:         if (ref($settings) eq 'HASH') {
 1630:             if (ref($settings->{'authtypes'}) eq 'HASH') {
 1631:                 foreach my $item (@contexts) {
 1632:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
 1633:                         foreach my $auth (@authtypes) {
 1634:                             if ($settings->{'authtypes'}{$item}{$auth}) {
 1635:                                 $checked{$item}{$auth} = ' checked="checked" ';
 1636:                             }
 1637:                         }
 1638:                     }
 1639:                 }
 1640:             }
 1641:         } else {
 1642:             foreach my $item (@contexts) {
 1643:                 foreach my $auth (@authtypes) {
 1644:                     $checked{$item}{$auth} = ' checked="checked" ';
 1645:                 }
 1646:             }
 1647:         }
 1648:         my %title = &context_names();
 1649:         my %authname = &authtype_names();
 1650:         my $rownum = 0;
 1651:         my $css_class; 
 1652:         foreach my $item (@contexts) {
 1653:             if ($rownum%2) {
 1654:                 $css_class = '';
 1655:             } else {
 1656:                 $css_class = ' class="LC_odd_row" ';
 1657:             }
 1658:             $datatable .=   '<tr'.$css_class.'>'.
 1659:                             '<td>'.$title{$item}.
 1660:                             '</td><td class="LC_left_item">'.
 1661:                             '<span class="LC_nobreak">';
 1662:             foreach my $auth (@authtypes) {
 1663:                 $datatable .= '<label>'. 
 1664:                               '<input type="checkbox" name="'.$item.'_auth" '.
 1665:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
 1666:                               $authname{$auth}.'</label>&nbsp;';
 1667:             }
 1668:             $datatable .= '</span></td></tr>';
 1669:             $rownum ++;
 1670:         }
 1671:         $$rowtotal += $rownum;
 1672:     }
 1673:     return $datatable;
 1674: }
 1675: 
 1676: sub user_formats_row {
 1677:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
 1678:     my $output;
 1679:     my %text = (
 1680:                    'username' => 'new usernames',
 1681:                    'id'       => 'IDs',
 1682:                    'email'    => 'self-created accounts (e-mail)',
 1683:                );
 1684:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 1685:     $output = '<tr '.$css_class.'>'.
 1686:               '<td><span class="LC_nobreak">'.
 1687:               &mt("Format rules to check for $text{$type}: ").
 1688:               '</span></td>'.
 1689:               '<td class="LC_left_item" colspan="2"><table>';
 1690:     my $rem;
 1691:     if (ref($ruleorder) eq 'ARRAY') {
 1692:         for (my $i=0; $i<@{$ruleorder}; $i++) {
 1693:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
 1694:                 my $rem = $i%($numinrow);
 1695:                 if ($rem == 0) {
 1696:                     if ($i > 0) {
 1697:                         $output .= '</tr>';
 1698:                     }
 1699:                     $output .= '<tr>';
 1700:                 }
 1701:                 my $check = ' ';
 1702:                 if (ref($settings) eq 'HASH') {
 1703:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
 1704:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
 1705:                             $check = ' checked="checked" ';
 1706:                         }
 1707:                     }
 1708:                 }
 1709:                 $output .= '<td class="LC_left_item">'.
 1710:                            '<span class="LC_nobreak"><label>'.
 1711:                            '<input type="checkbox" name="'.$type.'_rule" '.
 1712:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
 1713:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
 1714:             }
 1715:         }
 1716:         $rem = @{$ruleorder}%($numinrow);
 1717:     }
 1718:     my $colsleft = $numinrow - $rem;
 1719:     if ($colsleft > 1 ) {
 1720:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 1721:                    '&nbsp;</td>';
 1722:     } elsif ($colsleft == 1) {
 1723:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 1724:     }
 1725:     $output .= '</tr></table></td></tr>';
 1726:     return $output;
 1727: }
 1728: 
 1729: sub usercreation_types {
 1730:     my %lt = &Apache::lonlocal::texthash (
 1731:                     author     => 'When adding a co-author',
 1732:                     course     => 'When adding a user to a course',
 1733:                     selfcreate => 'User creates own account', 
 1734:                     any        => 'Any',
 1735:                     official   => 'Institutional only ',
 1736:                     unofficial => 'Non-institutional only',
 1737:                     email      => 'Email address',
 1738:                     login      => 'Institutional Login',
 1739:                     sso        => 'SSO', 
 1740:                     none       => 'None',
 1741:     );
 1742:     return %lt;
 1743: }
 1744: 
 1745: sub authtype_names {
 1746:     my %lt = &Apache::lonlocal::texthash(
 1747:                       int    => 'Internal',
 1748:                       krb4   => 'Kerberos 4',
 1749:                       krb5   => 'Kerberos 5',
 1750:                       loc    => 'Local',
 1751:                   );
 1752:     return %lt;
 1753: }
 1754: 
 1755: sub context_names {
 1756:     my %context_title = &Apache::lonlocal::texthash(
 1757:        author => 'Creating users when an Author',
 1758:        course => 'Creating users when in a course',
 1759:        domain => 'Creating users when a Domain Coordinator',
 1760:     );
 1761:     return %context_title;
 1762: }
 1763: 
 1764: sub print_usermodification {
 1765:     my ($position,$dom,$settings,$rowtotal) = @_;
 1766:     my $numinrow = 4;
 1767:     my ($context,$datatable,$rowcount);
 1768:     if ($position eq 'top') {
 1769:         $rowcount = 0;
 1770:         $context = 'author'; 
 1771:         foreach my $role ('ca','aa') {
 1772:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 1773:                                                    $numinrow,$rowcount);
 1774:             $$rowtotal ++;
 1775:             $rowcount ++;
 1776:         }
 1777:     } else {
 1778:         $context = 'course';
 1779:         $rowcount = 0;
 1780:         foreach my $role ('st','ep','ta','in','cr') {
 1781:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 1782:                                                    $numinrow,$rowcount);
 1783:             $$rowtotal ++;
 1784:             $rowcount ++;
 1785:         }
 1786:     }
 1787:     return $datatable;
 1788: }
 1789: 
 1790: sub print_defaults {
 1791:     my ($dom,$rowtotal) = @_;
 1792:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def');
 1793:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 1794:     my $titles = &defaults_titles();
 1795:     my $rownum = 0;
 1796:     my ($datatable,$css_class);
 1797:     foreach my $item (@items) {
 1798:         if ($rownum%2) {
 1799:             $css_class = '';
 1800:         } else {
 1801:             $css_class = ' class="LC_odd_row" ';
 1802:         }
 1803:         $datatable .= '<tr'.$css_class.'>'.
 1804:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 1805:                   '</span></td><td class="LC_right_item">';
 1806:         if ($item eq 'auth_def') {
 1807:             my @authtypes = ('internal','krb4','krb5','localauth');
 1808:             my %shortauth = (
 1809:                              internal => 'int',
 1810:                              krb4 => 'krb4',
 1811:                              krb5 => 'krb5',
 1812:                              localauth  => 'loc'
 1813:                            );
 1814:             my %authnames = &authtype_names();
 1815:             foreach my $auth (@authtypes) {
 1816:                 my $checked = ' ';
 1817:                 if ($domdefaults{$item} eq $auth) {
 1818:                     $checked = ' checked="checked" ';
 1819:                 }
 1820:                 $datatable .= '<label><input type="radio" name="'.$item.
 1821:                               '" value="'.$auth.'"'.$checked.'/>'.
 1822:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
 1823:             }
 1824:         } elsif ($item eq 'timezone_def') {
 1825:             my $includeempty = 1;
 1826:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
 1827:         } else {
 1828:             $datatable .= '<input type="text" name="'.$item.'" value="'.
 1829:                           $domdefaults{$item}.'" />';
 1830:         }
 1831:         $datatable .= '</td></tr>';
 1832:         $rownum ++;
 1833:     }
 1834:     $$rowtotal += $rownum;
 1835:     return $datatable;
 1836: }
 1837: 
 1838: sub defaults_titles {
 1839:     my %titles = &Apache::lonlocal::texthash (
 1840:                    'auth_def'      => 'Default authentication type',
 1841:                    'auth_arg_def'  => 'Default authentication argument',
 1842:                    'lang_def'      => 'Default language',
 1843:                    'timezone_def'  => 'Default timezone',
 1844:                  );
 1845:     return (\%titles);
 1846: }
 1847: 
 1848: sub print_scantronformat {
 1849:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
 1850:     my $itemcount = 1;
 1851:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
 1852:         %confhash);
 1853:     my $switchserver = &check_switchserver($dom,$confname);
 1854:     my %lt = &Apache::lonlocal::texthash (
 1855:                 default => 'Default scantron format file error',
 1856:                 custom  => 'Custom scantron format file error',
 1857:              );
 1858:     my %scantronfiles = (
 1859:         default => 'default.tab',
 1860:         custom => 'custom.tab',
 1861:     );
 1862:     foreach my $key (keys(%scantronfiles)) {
 1863:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
 1864:                               .$scantronfiles{$key};
 1865:     }
 1866:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
 1867:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
 1868:         if (!$switchserver) {
 1869:             my $servadm = $r->dir_config('lonAdmEMail');
 1870:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
 1871:             if ($configuserok eq 'ok') {
 1872:                 if ($author_ok eq 'ok') {
 1873:                     my %legacyfile = (
 1874:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
 1875:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
 1876:                     );
 1877:                     my %md5chk;
 1878:                     foreach my $type (keys(%legacyfile)) {
 1879:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
 1880:                         chomp($md5chk{$type});
 1881:                     }
 1882:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
 1883:                         foreach my $type (keys(%legacyfile)) {
 1884:                             ($scantronurls{$type},my $error) = 
 1885:                                 &legacy_scantronformat($r,$dom,$confname,
 1886:                                                  $type,$legacyfile{$type},
 1887:                                                  $scantronurls{$type},
 1888:                                                  $scantronfiles{$type});
 1889:                             if ($error ne '') {
 1890:                                 $error{$type} = $error;
 1891:                             }
 1892:                         }
 1893:                         if (keys(%error) == 0) {
 1894:                             $is_custom = 1;
 1895:                             $confhash{'scantron'}{'scantronformat'} = 
 1896:                                 $scantronurls{'custom'};
 1897:                             my $putresult = 
 1898:                                 &Apache::lonnet::put_dom('configuration',
 1899:                                                          \%confhash,$dom);
 1900:                             if ($putresult ne 'ok') {
 1901:                                 $error{'custom'} = 
 1902:                                     '<span class="LC_error">'.
 1903:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 1904:                             }
 1905:                         }
 1906:                     } else {
 1907:                         ($scantronurls{'default'},my $error) =
 1908:                             &legacy_scantronformat($r,$dom,$confname,
 1909:                                           'default',$legacyfile{'default'},
 1910:                                           $scantronurls{'default'},
 1911:                                           $scantronfiles{'default'});
 1912:                         if ($error eq '') {
 1913:                             $confhash{'scantron'}{'scantronformat'} = ''; 
 1914:                             my $putresult =
 1915:                                 &Apache::lonnet::put_dom('configuration',
 1916:                                                          \%confhash,$dom);
 1917:                             if ($putresult ne 'ok') {
 1918:                                 $error{'default'} =
 1919:                                     '<span class="LC_error">'.
 1920:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 1921:                             }
 1922:                         } else {
 1923:                             $error{'default'} = $error;
 1924:                         }
 1925:                     }
 1926:                 }
 1927:             }
 1928:         } else {
 1929:             $error{'default'} = &mt("Unable to copy default scantron formatfile to domain's RES space: [_1]",$switchserver);
 1930:         }
 1931:     }
 1932:     if (ref($settings) eq 'HASH') {
 1933:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
 1934:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
 1935:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
 1936:                 $scantronurl = '';
 1937:             } else {
 1938:                 $scantronurl = $settings->{'scantronformat'};
 1939:             }
 1940:             $is_custom = 1;
 1941:         } else {
 1942:             $scantronurl = $scantronurls{'default'};
 1943:         }
 1944:     } else {
 1945:         if ($is_custom) {
 1946:             $scantronurl = $scantronurls{'custom'};
 1947:         } else {
 1948:             $scantronurl = $scantronurls{'default'};
 1949:         }
 1950:     }
 1951:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1952:     $datatable .= '<tr'.$css_class.'>';
 1953:     if (!$is_custom) {
 1954:         $datatable .= '<td>'.&mt('Default in use:').'<br />';
 1955:         if ($scantronurl) {
 1956:             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
 1957:                           &mt('Default scantron format file').'</a>';
 1958:         } else {
 1959:             $datatable = &mt('File unavailable for display');
 1960:         }
 1961:         $datatable .= '</td>';
 1962:         if (keys(%error) == 0) { 
 1963:             $datatable .= '<td valign="bottom">';
 1964:             if (!$switchserver) {
 1965:                 $datatable .= &mt('Upload:').'<br />';
 1966:             }
 1967:         } else {
 1968:             my $errorstr;
 1969:             foreach my $key (sort(keys(%error))) {
 1970:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 1971:             }
 1972:             $datatable .= '<td>'.$errorstr;
 1973:         }
 1974:     } else {
 1975:         if (keys(%error) > 0) {
 1976:             my $errorstr;
 1977:             foreach my $key (sort(keys(%error))) {
 1978:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 1979:             } 
 1980:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
 1981:         } elsif ($scantronurl) {
 1982:             $datatable .= '<td><a href="'.$scantronurl.'" target="_blank">'
 1983:                           .&mt('Custom scantron format file').'</a>'
 1984:                           .'<span class="LC_nobreak"><label>'
 1985:                           .'<input type="checkbox" name="scantronformat_del"'
 1986:                           .'" value="1" />'.&mt('Delete?').'</label></td>'
 1987:                           .'<td>'.&mt('Replace:').'</span><br />';
 1988:         }
 1989:     }
 1990:     if (keys(%error) == 0) {
 1991:         if ($switchserver) {
 1992:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1993:         } else {
 1994:             $datatable .='&nbsp;<input type="file" name="scantronformat" />';
 1995:         }
 1996:     }
 1997:     $datatable .= '</td></tr>';
 1998:     $$rowtotal ++;
 1999:     return $datatable;
 2000: }
 2001: 
 2002: sub legacy_scantronformat {
 2003:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
 2004:     my ($url,$error);
 2005:     my @statinfo = &Apache::lonnet::stat_file($newurl);
 2006:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
 2007:         (my $result,$url) =
 2008:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
 2009:                          '','',$newfile);
 2010:         if ($result ne 'ok') {
 2011:             $error = &mt("An error occurred publishing the [_1] scantron format file in RES space. Error was: [_2].",$newfile,$result);
 2012:         }
 2013:     }
 2014:     return ($url,$error);
 2015: }
 2016: 
 2017: sub print_coursecategories {
 2018:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
 2019:     my $datatable;
 2020:     if ($position eq 'top') {
 2021:         my $toggle_cats_crs = ' ';
 2022:         my $toggle_cats_dom = ' checked="checked" ';
 2023:         my $can_cat_crs = ' ';
 2024:         my $can_cat_dom = ' checked="checked" ';
 2025:         if (ref($settings) eq 'HASH') {
 2026:             if ($settings->{'togglecats'} eq 'crs') {
 2027:                 $toggle_cats_crs = $toggle_cats_dom;
 2028:                 $toggle_cats_dom = ' ';
 2029:             }
 2030:             if ($settings->{'categorize'} eq 'crs') {
 2031:                 $can_cat_crs = $can_cat_dom;
 2032:                 $can_cat_dom = ' ';
 2033:             }
 2034:         }
 2035:         my %title = &Apache::lonlocal::texthash (
 2036:                      togglecats => 'Show/Hide a course in the catalog',
 2037:                      categorize    => 'Assign a category to a course',
 2038:                     );
 2039:         my %level = &Apache::lonlocal::texthash (
 2040:                      dom => 'Set in "Modify Course" (Domain)',
 2041:                      crs => 'Set in "Modify Parameters" (Course)',   
 2042:                     );
 2043:         $datatable = '<tr class="LC_odd_row">'.
 2044:                   '<td>'.$title{'togglecats'}.'</td>'.
 2045:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2046:                   '<input type="radio" name="togglecats"'.
 2047:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 2048:                   '<label><input type="radio" name="togglecats"'.
 2049:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
 2050:                   '</tr><tr>'.
 2051:                   '<td>'.$title{'categorize'}.'</td>'.
 2052:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 2053:                   '<label><input type="radio" name="categorize"'.
 2054:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 2055:                   '<label><input type="radio" name="categorize"'.
 2056:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
 2057:                   '</tr>';
 2058:         $$rowtotal += 2;
 2059:     } else {
 2060:         my $css_class;
 2061:         my $itemcount = 1;
 2062:         my $cathash; 
 2063:         if (ref($settings) eq 'HASH') {
 2064:             $cathash = $settings->{'cats'};
 2065:         }
 2066:         if (ref($cathash) eq 'HASH') {
 2067:             my (@cats,@trails,%allitems,%idx,@jsarray);
 2068:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
 2069:                                                    \%allitems,\%idx,\@jsarray);
 2070:             my $maxdepth = scalar(@cats);
 2071:             my $colattrib = '';
 2072:             if ($maxdepth > 2) {
 2073:                 $colattrib = ' colspan="2" ';
 2074:             }
 2075:             my @path;
 2076:             if (@cats > 0) {
 2077:                 if (ref($cats[0]) eq 'ARRAY') {
 2078:                     my $numtop = @{$cats[0]};
 2079:                     my $maxnum = $numtop;
 2080:                     if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
 2081:                         $maxnum ++;
 2082:                     }
 2083:                     my $lastidx;
 2084:                     for (my $i=0; $i<$numtop; $i++) {
 2085:                         my $parent = $cats[0][$i];
 2086:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2087:                         my $item = &escape($parent).'::0';
 2088:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
 2089:                         $lastidx = $idx{$item};
 2090:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 2091:                                       .'<select name="'.$item.'"'.$chgstr.'>';
 2092:                         for (my $k=0; $k<=$maxnum; $k++) {
 2093:                             my $vpos = $k+1;
 2094:                             my $selstr;
 2095:                             if ($k == $i) {
 2096:                                 $selstr = ' selected="selected" ';
 2097:                             }
 2098:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 2099:                         }
 2100:                         $datatable .= '</select></td><td>';
 2101:                         if ($parent eq 'instcode') {
 2102:                             $datatable .=  '<span class="LC_nobreak">'.&mt('Official courses')
 2103:                                            .'</span><br /><span class="LC_nobreak">('
 2104:                                            .&mt('with institutional codes').')</span></td>'
 2105:                                            .'<td'.$colattrib.'><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" checked="checked" />'
 2106:                                             .&mt('Display').'</label>&nbsp;'
 2107:                                             .'<label><input type="radio" name="instcode" value="0" />'
 2108:                                             .&mt('Do not display').'</label></span></td>';
 2109:                         } else {
 2110:                             $datatable .= $parent
 2111:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
 2112:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
 2113:                         }
 2114:                         my $depth = 1;
 2115:                         push(@path,$parent);
 2116:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
 2117:                         pop(@path);
 2118:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
 2119:                         $itemcount ++;
 2120:                     }
 2121:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2122:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
 2123:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
 2124:                     for (my $k=0; $k<=$maxnum; $k++) {
 2125:                         my $vpos = $k+1;
 2126:                         my $selstr;
 2127:                         if ($k == $numtop) {
 2128:                             $selstr = ' selected="selected" ';
 2129:                         }
 2130:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 2131:                     }
 2132:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
 2133:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
 2134:                                   .'</tr>'."\n";
 2135:                     $itemcount ++;
 2136:                     if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
 2137:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2138:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"';
 2139:                         $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
 2140:                                       '<span class="LC_nobreak"><select name="instcode_pos"'.$chgstr.'>';
 2141:                         for (my $k=0; $k<=$maxnum; $k++) {
 2142:                             my $vpos = $k+1;
 2143:                             my $selstr;
 2144:                             if ($k == $maxnum) {
 2145:                                 $selstr = ' selected="selected" ';
 2146:                             }
 2147:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 2148:                         }
 2149:                         $datatable .= '</select></span></td><td><span class="LC_nobreak">'
 2150:                                       .&mt('Official courses').'</span>'.'<br /><span class="LC_nobreak">('
 2151:                                       .&mt('with institutional codes').')</span></td>'
 2152:                                       .'<td><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" />'
 2153:                                       .&mt('Display').'</label>&nbsp;'
 2154:                                       .'<label><input type="radio" name="instcode" value="0" checked="checked"/>'
 2155:                                       .&mt('Do not display').'</label></span></td></tr>';
 2156:                     }
 2157:                 }
 2158:             } else {
 2159:                 $datatable .= &initialize_categories($itemcount);
 2160:             }
 2161:         } else {
 2162:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
 2163:                           .&initialize_categories($itemcount);
 2164:         }
 2165:         $$rowtotal += $itemcount;
 2166:     }
 2167:     return $datatable;
 2168: }
 2169: 
 2170: sub coursecategories_javascript {
 2171:     my ($settings) = @_;
 2172:     my ($output,$jstext,$cathash);
 2173:     if (ref($settings) eq 'HASH') {
 2174:         $cathash = $settings->{'cats'};
 2175:     }
 2176:     if (ref($cathash) eq 'HASH') {
 2177:         my (@cats,@jsarray,%idx);
 2178:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
 2179:         if (@jsarray > 0) {
 2180:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
 2181:             for (my $i=0; $i<@jsarray; $i++) {
 2182:                 if (ref($jsarray[$i]) eq 'ARRAY') {
 2183:                     my $catstr = join('","',@{$jsarray[$i]});
 2184:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
 2185:                 }
 2186:             }
 2187:         }
 2188:     } else {
 2189:         $jstext  = '    var categories = Array(1);'."\n".
 2190:                    '    categories[0] = Array("instcode_pos");'."\n"; 
 2191:     }
 2192:     $output = <<"ENDSCRIPT";
 2193: <script type="text/javascript">
 2194: function reorderCats(form,parent,item,idx) {
 2195:     var changedVal;
 2196: $jstext
 2197:     var newpos = 'addcategory_pos';
 2198:     var current = new Array;
 2199:     if (parent == '') {
 2200:         var has_instcode = 0;
 2201:         var maxtop = categories[idx].length;
 2202:         for (var j=0; j<maxtop; j++) {
 2203:             if (categories[idx][j] == 'instcode::0') {
 2204:                 has_instcode == 1;
 2205:             }
 2206:         }
 2207:         if (has_instcode == 0) {
 2208:             categories[idx][maxtop] = 'instcode_pos';
 2209:         }
 2210:     } else {
 2211:         newpos += '_'+parent;
 2212:     }
 2213:     var maxh = 1 + categories[idx].length;
 2214:     var current = new Array;
 2215:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 2216:     if (item == newpos) {
 2217:         changedVal = newitemVal;
 2218:     } else {
 2219:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
 2220:         current[newitemVal] = newpos;
 2221:     }
 2222:     for (var i=0; i<categories[idx].length; i++) {
 2223:         var elementName = categories[idx][i];
 2224:         if (elementName != item) {
 2225:             if (form.elements[elementName]) {
 2226:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 2227:                 current[currVal] = elementName;
 2228:             }
 2229:         }
 2230:     }
 2231:     var oldVal;
 2232:     for (var j=0; j<maxh; j++) {
 2233:         if (current[j] == undefined) {
 2234:             oldVal = j;
 2235:         }
 2236:     }
 2237:     if (oldVal < changedVal) {
 2238:         for (var k=oldVal+1; k<=changedVal ; k++) {
 2239:            var elementName = current[k];
 2240:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 2241:         }
 2242:     } else {
 2243:         for (var k=changedVal; k<oldVal; k++) {
 2244:             var elementName = current[k];
 2245:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 2246:         }
 2247:     }
 2248:     return;
 2249: }
 2250: </script>
 2251: 
 2252: ENDSCRIPT
 2253:     return $output;
 2254: }
 2255: 
 2256: sub initialize_categories {
 2257:     my ($itemcount) = @_;
 2258:     my $datatable;
 2259:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2260:     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','0'".');"';
 2261: 
 2262:     $datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">'
 2263:                  .'<select name="instcode_pos"><option value="0" selected="selected">1</option>'
 2264:                  .'<option value="1">2</option></select>&nbsp;'
 2265:                  .&mt('Official courses (with institutional codes)')
 2266:                  .'</span></td><td><span class="LC_nobreak">'
 2267:                  .'<label><input type="radio" name="instcode" value="1" checked="checked" />'
 2268:                  .&mt('Display').'</label>&nbsp;<label>'
 2269:                  .'<input type="radio" name="instcode" value="0" />'.&mt('Do not display')
 2270:                  .'</label></span></td></tr>';
 2271:     $itemcount ++;
 2272:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2273:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
 2274:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 2275:                   .'<select name="addcategory_pos"'.$chgstr.'><option value="0">1</option>'
 2276:                   .'<option value="1" selected="selected">2</option></select>&nbsp;'
 2277:                   .&mt('Add category').'</td><td>'.&mt('Name:')
 2278:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
 2279:     return $datatable;
 2280: }
 2281: 
 2282: sub build_category_rows {
 2283:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
 2284:     my ($text,$name,$item,$chgstr);
 2285:     if (ref($cats) eq 'ARRAY') {
 2286:         my $maxdepth = scalar(@{$cats});
 2287:         if (ref($cats->[$depth]) eq 'HASH') {
 2288:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
 2289:                 my $numchildren = @{$cats->[$depth]{$parent}};
 2290:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2291:                 $text .= '<td><table class="LC_datatable">';
 2292:                 my ($idxnum,$parent_name,$parent_item);
 2293:                 my $higher = $depth - 1;
 2294:                 if ($higher == 0) {
 2295:                     $parent_name = &escape($parent).'::'.$higher;
 2296:                 } else {
 2297:                     if (ref($path) eq 'ARRAY') {
 2298:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 2299:                     }
 2300:                 }
 2301:                 $parent_item = 'addcategory_pos_'.$parent_name;
 2302:                 for (my $j=0; $j<=$numchildren; $j++) {
 2303:                     if ($j < $numchildren) {
 2304:                         $name = $cats->[$depth]{$parent}[$j];
 2305:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
 2306:                         $idxnum = $idx->{$item};
 2307:                     } else {
 2308:                         $name = $parent_name;
 2309:                         $item = $parent_item;
 2310:                     }
 2311:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
 2312:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
 2313:                     for (my $i=0; $i<=$numchildren; $i++) {
 2314:                         my $vpos = $i+1;
 2315:                         my $selstr;
 2316:                         if ($j == $i) {
 2317:                             $selstr = ' selected="selected" ';
 2318:                         }
 2319:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
 2320:                     }
 2321:                     $text .= '</select>&nbsp;';
 2322:                     if ($j < $numchildren) {
 2323:                         my $deeper = $depth+1;
 2324:                         $text .= $name.'&nbsp;'
 2325:                                  .'<label><input type="checkbox" name="deletecategory" value="'
 2326:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
 2327:                         if(ref($path) eq 'ARRAY') {
 2328:                             push(@{$path},$name);
 2329:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
 2330:                             pop(@{$path});
 2331:                         }
 2332:                     } else {
 2333:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
 2334:                         if ($j == $numchildren) {
 2335:                             $text .= $name;
 2336:                         } else {
 2337:                             $text .= $item;
 2338:                         }
 2339:                         $text .= '" value="" />';
 2340:                     }
 2341:                     $text .= '</td></tr>';
 2342:                 }
 2343:                 $text .= '</table></td>';
 2344:             } else {
 2345:                 my $higher = $depth-1;
 2346:                 if ($higher == 0) {
 2347:                     $name = &escape($parent).'::'.$higher;
 2348:                 } else {
 2349:                     if (ref($path) eq 'ARRAY') {
 2350:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 2351:                     }
 2352:                 }
 2353:                 my $colspan;
 2354:                 if ($parent ne 'instcode') {
 2355:                     $colspan = $maxdepth - $depth - 1;
 2356:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
 2357:                 }
 2358:             }
 2359:         }
 2360:     }
 2361:     return $text;
 2362: }
 2363: 
 2364: sub modifiable_userdata_row {
 2365:     my ($context,$role,$settings,$numinrow,$rowcount) = @_;
 2366:     my $rolename;
 2367:     if ($role eq 'cr') {
 2368:         $rolename = &mt('Custom role');
 2369:     } else {
 2370:         $rolename = &Apache::lonnet::plaintext($role);
 2371:     }
 2372:     my @fields = ('lastname','firstname','middlename','generation',
 2373:                   'permanentemail','id');
 2374:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 2375:     my $output;
 2376:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 2377:     $output = '<tr '.$css_class.'>'.
 2378:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
 2379:               '<td class="LC_left_item" colspan="2"><table>';
 2380:     my $rem;
 2381:     my %checks;
 2382:     if (ref($settings) eq 'HASH') {
 2383:         if (ref($settings->{$context}) eq 'HASH') {
 2384:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
 2385:                 foreach my $field (@fields) {
 2386:                     if ($settings->{$context}->{$role}->{$field}) {
 2387:                         $checks{$field} = ' checked="checked" ';
 2388:                     }
 2389:                 }
 2390:             }
 2391:         }
 2392:     }
 2393:     for (my $i=0; $i<@fields; $i++) {
 2394:         my $rem = $i%($numinrow);
 2395:         if ($rem == 0) {
 2396:             if ($i > 0) {
 2397:                 $output .= '</tr>';
 2398:             }
 2399:             $output .= '<tr>';
 2400:         }
 2401:         my $check = ' ';
 2402:         if (exists($checks{$fields[$i]})) {
 2403:             $check = $checks{$fields[$i]}
 2404:         } else {
 2405:             if ($role eq 'st') {
 2406:                 if (ref($settings) ne 'HASH') {
 2407:                     $check = ' checked="checked" '; 
 2408:                 }
 2409:             }
 2410:         }
 2411:         $output .= '<td class="LC_left_item">'.
 2412:                    '<span class="LC_nobreak"><label>'.
 2413:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
 2414:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
 2415:                    '</label></span></td>';
 2416:         $rem = @fields%($numinrow);
 2417:     }
 2418:     my $colsleft = $numinrow - $rem;
 2419:     if ($colsleft > 1 ) {
 2420:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 2421:                    '&nbsp;</td>';
 2422:     } elsif ($colsleft == 1) {
 2423:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 2424:     }
 2425:     $output .= '</tr></table></td></tr>';
 2426:     return $output;
 2427: }
 2428: 
 2429: sub users_cansearch_row {
 2430:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
 2431:     my $output =  '<tr class="LC_odd_row">'.
 2432:                   '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
 2433:                   '</td><td class="LC_left_item" colspan="2"><table>';
 2434:     my $rem;
 2435:     if (ref($types) eq 'ARRAY') {
 2436:         for (my $i=0; $i<@{$types}; $i++) {
 2437:             if (defined($usertypes->{$types->[$i]})) {
 2438:                 my $rem = $i%($numinrow);
 2439:                 if ($rem == 0) {
 2440:                     if ($i > 0) {
 2441:                         $output .= '</tr>';
 2442:                     }
 2443:                     $output .= '<tr>';
 2444:                 }
 2445:                 my $check = ' ';
 2446:                 if (ref($settings->{'cansearch'}) eq 'ARRAY') {
 2447:                     if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
 2448:                         $check = ' checked="checked" ';
 2449:                     }
 2450:                 }
 2451:                 $output .= '<td class="LC_left_item">'.
 2452:                            '<span class="LC_nobreak"><label>'.
 2453:                            '<input type="checkbox" name="cansearch" '.
 2454:                            'value="'.$types->[$i].'"'.$check.'/>'.
 2455:                            $usertypes->{$types->[$i]}.'</label></span></td>';
 2456:             }
 2457:         }
 2458:        
 2459:         $rem = @{$types}%($numinrow);
 2460:     }
 2461:     my $colsleft = $numinrow - $rem;
 2462:     if ($colsleft > 1) {
 2463:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 2464:     } else {
 2465:         $output .= '<td class="LC_left_item">';
 2466:     }
 2467:     my $defcheck = ' ';
 2468:     if (ref($settings->{'cansearch'}) eq 'ARRAY') {
 2469:         if (grep(/^default$/,@{$settings->{'cansearch'}})) {
 2470:             $defcheck = ' checked="checked" ';
 2471:         }
 2472:     }
 2473:     $output .= '<span class="LC_nobreak"><label>'.
 2474:                '<input type="checkbox" name="cansearch" '.
 2475:                'value="default"'.$defcheck.'/>'.
 2476:                $othertitle.'</label></span></td>'.
 2477:                '</tr></table></td></tr>';
 2478:     return $output;
 2479: }
 2480: 
 2481: sub sorted_searchtitles {
 2482:     my %searchtitles = &Apache::lonlocal::texthash(
 2483:                          'uname' => 'username',
 2484:                          'lastname' => 'last name',
 2485:                          'lastfirst' => 'last name, first name',
 2486:                      );
 2487:     my @titleorder = ('uname','lastname','lastfirst');
 2488:     return (\%searchtitles,\@titleorder);
 2489: }
 2490: 
 2491: sub sorted_searchtypes {
 2492:     my %srchtypes_desc = (
 2493:                            exact    => 'is exact match',
 2494:                            contains => 'contains ..',
 2495:                            begins   => 'begins with ..',
 2496:                          );
 2497:     my @srchtypeorder = ('exact','begins','contains');
 2498:     return (\%srchtypes_desc,\@srchtypeorder);
 2499: }
 2500: 
 2501: sub usertype_update_row {
 2502:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
 2503:     my $datatable;
 2504:     my $numinrow = 4;
 2505:     foreach my $type (@{$types}) {
 2506:         if (defined($usertypes->{$type})) {
 2507:             $$rownums ++;
 2508:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
 2509:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
 2510:                           '</td><td class="LC_left_item"><table>';
 2511:             for (my $i=0; $i<@{$fields}; $i++) {
 2512:                 my $rem = $i%($numinrow);
 2513:                 if ($rem == 0) {
 2514:                     if ($i > 0) {
 2515:                         $datatable .= '</tr>';
 2516:                     }
 2517:                     $datatable .= '<tr>';
 2518:                 }
 2519:                 my $check = ' ';
 2520:                 if (ref($settings) eq 'HASH') {
 2521:                     if (ref($settings->{'fields'}) eq 'HASH') {
 2522:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
 2523:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
 2524:                                 $check = ' checked="checked" ';
 2525:                             }
 2526:                         }
 2527:                     }
 2528:                 }
 2529: 
 2530:                 if ($i == @{$fields}-1) {
 2531:                     my $colsleft = $numinrow - $rem;
 2532:                     if ($colsleft > 1) {
 2533:                         $datatable .= '<td colspan="'.$colsleft.'">';
 2534:                     } else {
 2535:                         $datatable .= '<td>';
 2536:                     }
 2537:                 } else {
 2538:                     $datatable .= '<td>';
 2539:                 }
 2540:                 $datatable .= '<span class="LC_nobreak"><label>'.
 2541:                               '<input type="checkbox" name="updateable_'.$type.
 2542:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
 2543:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
 2544:             }
 2545:             $datatable .= '</tr></table></td></tr>';
 2546:         }
 2547:     }
 2548:     return $datatable;
 2549: }
 2550: 
 2551: sub modify_login {
 2552:     my ($r,$dom,$confname,%domconfig) = @_;
 2553:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
 2554:     my %title = ( coursecatalog => 'Display course catalog',
 2555:                   adminmail => 'Display administrator E-mail address',
 2556:                   newuser => 'Link for visitors to create a user account',
 2557:                   loginheader => 'Log-in box header');
 2558:     my @offon = ('off','on');
 2559:     my %loginhash;
 2560:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
 2561:                                            \%domconfig,\%loginhash);
 2562:     my @toggles = ('coursecatalog','adminmail','newuser');
 2563:     foreach my $item (@toggles) {
 2564:         $loginhash{login}{$item} = $env{'form.'.$item};
 2565:     }
 2566:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
 2567:     if (ref($colchanges{'login'}) eq 'HASH') {  
 2568:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
 2569:                                          \%loginhash);
 2570:     }
 2571:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
 2572:                                              $dom);
 2573:     if ($putresult eq 'ok') {
 2574:         my @toggles = ('coursecatalog','adminmail','newuser');
 2575:         my %defaultchecked = (
 2576:                     'coursecatalog' => 'on',
 2577:                     'adminmail'     => 'off',
 2578:                     'newuser'       => 'off',
 2579:         );
 2580:         if (ref($domconfig{'login'}) eq 'HASH') {
 2581:             foreach my $item (@toggles) {
 2582:                 if ($defaultchecked{$item} eq 'on') { 
 2583:                     if (($domconfig{'login'}{$item} eq '0') &&
 2584:                         ($env{'form.'.$item} eq '1')) {
 2585:                         $changes{$item} = 1;
 2586:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 2587:                               $domconfig{'login'}{$item} eq '1') &&
 2588:                              ($env{'form.'.$item} eq '0')) {
 2589:                         $changes{$item} = 1;
 2590:                     }
 2591:                 } elsif ($defaultchecked{$item} eq 'off') {
 2592:                     if (($domconfig{'login'}{$item} eq '1') &&
 2593:                         ($env{'form.'.$item} eq '0')) {
 2594:                         $changes{$item} = 1;
 2595:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 2596:                               $domconfig{'login'}{$item} eq '0') &&
 2597:                              ($env{'form.'.$item} eq '1')) {
 2598:                         $changes{$item} = 1;
 2599:                     }
 2600:                 }
 2601:             }
 2602:             if (($domconfig{'login'}{'loginheader'} eq 'text') && 
 2603:                 ($env{'form.loginheader'} eq 'image')) {
 2604:                 $changes{'loginheader'} = 1;
 2605:             } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
 2606:                       $domconfig{'login'}{'loginheader'} eq 'image') &&
 2607:                      ($env{'form.loginheader'} eq 'text')) {
 2608:                 $changes{'loginheader'} = 1;
 2609:             }
 2610:         }
 2611:         if (keys(%changes) > 0 || $colchgtext) {
 2612:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 2613:             $resulttext = &mt('Changes made:').'<ul>';
 2614:             foreach my $item (sort(keys(%changes))) {
 2615:                 if ($item eq 'loginheader') {
 2616:                     $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
 2617:                 } else {
 2618:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 2619:                 }
 2620:             }
 2621:             $resulttext .= $colchgtext.'</ul>';
 2622:         } else {
 2623:             $resulttext = &mt('No changes made to log-in page settings');
 2624:         }
 2625:     } else {
 2626:         $resulttext = '<span class="LC_error">'.
 2627: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 2628:     }
 2629:     if ($errors) {
 2630:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 2631:                        $errors.'</ul>';
 2632:     }
 2633:     return $resulttext;
 2634: }
 2635: 
 2636: sub color_font_choices {
 2637:     my %choices =
 2638:         &Apache::lonlocal::texthash (
 2639:             img => "Header",
 2640:             bgs => "Background colors",
 2641:             links => "Link colors",
 2642:             images => "Images",
 2643:             font => "Font color",
 2644:             pgbg => "Page",
 2645:             tabbg => "Header",
 2646:             sidebg => "Border",
 2647:             link => "Link",
 2648:             alink => "Active link",
 2649:             vlink => "Visited link",
 2650:         );
 2651:     return %choices;
 2652: }
 2653: 
 2654: sub modify_rolecolors {
 2655:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
 2656:     my ($resulttext,%rolehash);
 2657:     $rolehash{'rolecolors'} = {};
 2658:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
 2659:         if ($domconfig{'rolecolors'} eq '') {
 2660:             $domconfig{'rolecolors'} = {};
 2661:         }
 2662:     }
 2663:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 2664:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 2665:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 2666:                                              $dom);
 2667:     if ($putresult eq 'ok') {
 2668:         if (keys(%changes) > 0) {
 2669:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 2670:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 2671:                                              $rolehash{'rolecolors'});
 2672:         } else {
 2673:             $resulttext = &mt('No changes made to default color schemes');
 2674:         }
 2675:     } else {
 2676:         $resulttext = '<span class="LC_error">'.
 2677: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 2678:     }
 2679:     if ($errors) {
 2680:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 2681:                        $errors.'</ul>';
 2682:     }
 2683:     return $resulttext;
 2684: }
 2685: 
 2686: sub modify_colors {
 2687:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 2688:     my (%changes,%choices);
 2689:     my @bgs;
 2690:     my @links = ('link','alink','vlink');
 2691:     my @logintext;
 2692:     my @images;
 2693:     my $servadm = $r->dir_config('lonAdmEMail');
 2694:     my $errors;
 2695:     foreach my $role (@{$roles}) {
 2696:         if ($role eq 'login') {
 2697:             %choices = &login_choices();
 2698:             @logintext = ('textcol','bgcol');
 2699:         } else {
 2700:             %choices = &color_font_choices();
 2701:         }
 2702:         if ($role eq 'login') {
 2703:             @images = ('img','logo','domlogo','login');
 2704:             @bgs = ('pgbg','mainbg','sidebg');
 2705:         } else {
 2706:             @images = ('img');
 2707:             @bgs = ('pgbg','tabbg','sidebg'); 
 2708:         }
 2709:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 2710:         foreach my $item (@bgs,@links,@logintext) {
 2711:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 2712:         }
 2713:         my ($configuserok,$author_ok,$switchserver) = 
 2714:             &config_check($dom,$confname,$servadm);
 2715:         my ($width,$height) = &thumb_dimensions();
 2716:         if (ref($domconfig->{$role}) ne 'HASH') {
 2717:             $domconfig->{$role} = {};
 2718:         }
 2719:         foreach my $img (@images) {
 2720: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 2721: 		 && !defined($domconfig->{$role}{$img})
 2722: 		 && !$env{'form.'.$role.'_del_'.$img}
 2723: 		 && $env{'form.'.$role.'_import_'.$img}) {
 2724: 		# import the old configured image from the .tab setting
 2725: 		# if they haven't provided a new one 
 2726: 		$domconfig->{$role}{$img} = 
 2727: 		    $env{'form.'.$role.'_import_'.$img};
 2728: 	    }
 2729:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 2730:                 my $error;
 2731:                 if ($configuserok eq 'ok') {
 2732:                     if ($switchserver) {
 2733:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 2734:                     } else {
 2735:                         if ($author_ok eq 'ok') {
 2736:                             my ($result,$logourl) = 
 2737:                                 &publishlogo($r,'upload',$role.'_'.$img,
 2738:                                            $dom,$confname,$img,$width,$height);
 2739:                             if ($result eq 'ok') {
 2740:                                 $confhash->{$role}{$img} = $logourl;
 2741:                                 $changes{$role}{'images'}{$img} = 1;
 2742:                             } else {
 2743:                                 $error = &mt("Upload of [_1] image for $role page(s) failed because an error occurred publishing the file in RES space. Error was: [_2].",$choices{img},$result);
 2744:                             }
 2745:                         } else {
 2746:                             $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
 2747:                         }
 2748:                     }
 2749:                 } else {
 2750:                     $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
 2751:                 }
 2752:                 if ($error) {
 2753:                     &Apache::lonnet::logthis($error);
 2754:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 2755:                 }
 2756:             } elsif ($domconfig->{$role}{$img} ne '') {
 2757:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 2758:                     my $error;
 2759:                     if ($configuserok eq 'ok') {
 2760: # is confname an author?
 2761:                         if ($switchserver eq '') {
 2762:                             if ($author_ok eq 'ok') {
 2763:                                 my ($result,$logourl) = 
 2764:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 2765:                                             $dom,$confname,$img,$width,$height);
 2766:                                 if ($result eq 'ok') {
 2767:                                     $confhash->{$role}{$img} = $logourl;
 2768: 				    $changes{$role}{'images'}{$img} = 1;
 2769:                                 }
 2770:                             }
 2771:                         }
 2772:                     }
 2773:                 }
 2774:             }
 2775:         }
 2776:         if (ref($domconfig) eq 'HASH') {
 2777:             if (ref($domconfig->{$role}) eq 'HASH') {
 2778:                 foreach my $img (@images) {
 2779:                     if ($domconfig->{$role}{$img} ne '') {
 2780:                         if ($env{'form.'.$role.'_del_'.$img}) {
 2781:                             $confhash->{$role}{$img} = '';
 2782:                             $changes{$role}{'images'}{$img} = 1;
 2783:                         } else {
 2784:                             if ($confhash->{$role}{$img} eq '') {
 2785:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 2786:                             }
 2787:                         }
 2788:                     } else {
 2789:                         if ($env{'form.'.$role.'_del_'.$img}) {
 2790:                             $confhash->{$role}{$img} = '';
 2791:                             $changes{$role}{'images'}{$img} = 1;
 2792:                         } 
 2793:                     }
 2794:                 }  
 2795:                 if ($domconfig->{$role}{'font'} ne '') {
 2796:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 2797:                         $changes{$role}{'font'} = 1;
 2798:                     }
 2799:                 } else {
 2800:                     if ($confhash->{$role}{'font'}) {
 2801:                         $changes{$role}{'font'} = 1;
 2802:                     }
 2803:                 }
 2804:                 foreach my $item (@bgs) {
 2805:                     if ($domconfig->{$role}{$item} ne '') {
 2806:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 2807:                             $changes{$role}{'bgs'}{$item} = 1;
 2808:                         } 
 2809:                     } else {
 2810:                         if ($confhash->{$role}{$item}) {
 2811:                             $changes{$role}{'bgs'}{$item} = 1;
 2812:                         }
 2813:                     }
 2814:                 }
 2815:                 foreach my $item (@links) {
 2816:                     if ($domconfig->{$role}{$item} ne '') {
 2817:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 2818:                             $changes{$role}{'links'}{$item} = 1;
 2819:                         }
 2820:                     } else {
 2821:                         if ($confhash->{$role}{$item}) {
 2822:                             $changes{$role}{'links'}{$item} = 1;
 2823:                         }
 2824:                     }
 2825:                 }
 2826:                 foreach my $item (@logintext) {
 2827:                     if ($domconfig->{$role}{$item} ne '') {
 2828:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 2829:                             $changes{$role}{'logintext'}{$item} = 1;
 2830:                         }
 2831:                     } else {
 2832:                         if ($confhash->{$role}{$item}) {
 2833:                             $changes{$role}{'logintext'}{$item} = 1;
 2834:                         }
 2835:                     }
 2836:                 }
 2837:             } else {
 2838:                 &default_change_checker($role,\@images,\@links,\@bgs,
 2839:                                         \@logintext,$confhash,\%changes); 
 2840:             }
 2841:         } else {
 2842:             &default_change_checker($role,\@images,\@links,\@bgs,
 2843:                                     \@logintext,$confhash,\%changes); 
 2844:         }
 2845:     }
 2846:     return ($errors,%changes);
 2847: }
 2848: 
 2849: sub config_check {
 2850:     my ($dom,$confname,$servadm) = @_;
 2851:     my ($configuserok,$author_ok,$switchserver,%currroles);
 2852:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 2853:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 2854:                                                    $confname,$servadm);
 2855:     if ($configuserok eq 'ok') {
 2856:         $switchserver = &check_switchserver($dom,$confname);
 2857:         if ($switchserver eq '') {
 2858:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
 2859:         }
 2860:     }
 2861:     return ($configuserok,$author_ok,$switchserver);
 2862: }
 2863: 
 2864: sub default_change_checker {
 2865:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
 2866:     foreach my $item (@{$links}) {
 2867:         if ($confhash->{$role}{$item}) {
 2868:             $changes->{$role}{'links'}{$item} = 1;
 2869:         }
 2870:     }
 2871:     foreach my $item (@{$bgs}) {
 2872:         if ($confhash->{$role}{$item}) {
 2873:             $changes->{$role}{'bgs'}{$item} = 1;
 2874:         }
 2875:     }
 2876:     foreach my $item (@{$logintext}) {
 2877:         if ($confhash->{$role}{$item}) {
 2878:             $changes->{$role}{'logintext'}{$item} = 1;
 2879:         }
 2880:     }
 2881:     foreach my $img (@{$images}) {
 2882:         if ($env{'form.'.$role.'_del_'.$img}) {
 2883:             $confhash->{$role}{$img} = '';
 2884:             $changes->{$role}{'images'}{$img} = 1;
 2885:         }
 2886:     }
 2887:     if ($confhash->{$role}{'font'}) {
 2888:         $changes->{$role}{'font'} = 1;
 2889:     }
 2890: }
 2891: 
 2892: sub display_colorchgs {
 2893:     my ($dom,$changes,$roles,$confhash) = @_;
 2894:     my (%choices,$resulttext);
 2895:     if (!grep(/^login$/,@{$roles})) {
 2896:         $resulttext = &mt('Changes made:').'<br />';
 2897:     }
 2898:     foreach my $role (@{$roles}) {
 2899:         if ($role eq 'login') {
 2900:             %choices = &login_choices();
 2901:         } else {
 2902:             %choices = &color_font_choices();
 2903:         }
 2904:         if (ref($changes->{$role}) eq 'HASH') {
 2905:             if ($role ne 'login') {
 2906:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 2907:             }
 2908:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 2909:                 if ($role ne 'login') {
 2910:                     $resulttext .= '<ul>';
 2911:                 }
 2912:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 2913:                     if ($role ne 'login') {
 2914:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 2915:                     }
 2916:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 2917:                         if ($confhash->{$role}{$item} eq '') {
 2918:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 2919:                         } else {
 2920:                             my $newitem = $confhash->{$role}{$item};
 2921:                             if ($key eq 'images') {
 2922:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 2923:                             }
 2924:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 2925:                         }
 2926:                     }
 2927:                     if ($role ne 'login') {
 2928:                         $resulttext .= '</ul></li>';
 2929:                     }
 2930:                 } else {
 2931:                     if ($confhash->{$role}{$key} eq '') {
 2932:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 2933:                     } else {
 2934:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 2935:                     }
 2936:                 }
 2937:                 if ($role ne 'login') {
 2938:                     $resulttext .= '</ul>';
 2939:                 }
 2940:             }
 2941:         }
 2942:     }
 2943:     return $resulttext;
 2944: }
 2945: 
 2946: sub thumb_dimensions {
 2947:     return ('200','50');
 2948: }
 2949: 
 2950: sub check_dimensions {
 2951:     my ($inputfile) = @_;
 2952:     my ($fullwidth,$fullheight);
 2953:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 2954:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 2955:             my $imageinfo = <PIPE>;
 2956:             if (!close(PIPE)) {
 2957:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 2958:             }
 2959:             chomp($imageinfo);
 2960:             my ($fullsize) = 
 2961:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
 2962:             if ($fullsize) {
 2963:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 2964:             }
 2965:         }
 2966:     }
 2967:     return ($fullwidth,$fullheight);
 2968: }
 2969: 
 2970: sub check_configuser {
 2971:     my ($uhome,$dom,$confname,$servadm) = @_;
 2972:     my ($configuserok,%currroles);
 2973:     if ($uhome eq 'no_host') {
 2974:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 2975:         my $configpass = &LONCAPA::Enrollment::create_password();
 2976:         $configuserok = 
 2977:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 2978:                              $configpass,'','','','','',undef,$servadm);
 2979:     } else {
 2980:         $configuserok = 'ok';
 2981:         %currroles = 
 2982:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 2983:     }
 2984:     return ($configuserok,%currroles);
 2985: }
 2986: 
 2987: sub check_authorstatus {
 2988:     my ($dom,$confname,%currroles) = @_;
 2989:     my $author_ok;
 2990:     if (!$currroles{':'.$dom.':au'}) {
 2991:         my $start = time;
 2992:         my $end = 0;
 2993:         $author_ok = 
 2994:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 2995:                                         'au',$end,$start,'','','domconfig');
 2996:     } else {
 2997:         $author_ok = 'ok';
 2998:     }
 2999:     return $author_ok;
 3000: }
 3001: 
 3002: sub publishlogo {
 3003:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
 3004:     my ($output,$fname,$logourl);
 3005:     if ($action eq 'upload') {
 3006:         $fname=$env{'form.'.$formname.'.filename'};
 3007:         chop($env{'form.'.$formname});
 3008:     } else {
 3009:         ($fname) = ($formname =~ /([^\/]+)$/);
 3010:     }
 3011:     if ($savefileas ne '') {
 3012:         $fname = $savefileas;
 3013:     }
 3014:     $fname=&Apache::lonnet::clean_filename($fname);
 3015: # See if there is anything left
 3016:     unless ($fname) { return ('error: no uploaded file'); }
 3017:     $fname="$subdir/$fname";
 3018:     my $filepath='/home/'.$confname.'/public_html';
 3019:     my ($fnamepath,$file,$fetchthumb);
 3020:     $file=$fname;
 3021:     if ($fname=~m|/|) {
 3022:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 3023:     }
 3024:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
 3025:     my $count;
 3026:     for ($count=4;$count<=$#parts;$count++) {
 3027:         $filepath.="/$parts[$count]";
 3028:         if ((-e $filepath)!=1) {
 3029:             mkdir($filepath,02770);
 3030:         }
 3031:     }
 3032:     # Check for bad extension and disallow upload
 3033:     if ($file=~/\.(\w+)$/ &&
 3034:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 3035:         $output = 
 3036:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
 3037:     } elsif ($file=~/\.(\w+)$/ &&
 3038:         !defined(&Apache::loncommon::fileembstyle($1))) {
 3039:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 3040:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 3041:         $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 3042:     } elsif (-d "$filepath/$file") {
 3043:         $output = &mt('File name is a directory name - rename the file and re-upload');
 3044:     } else {
 3045:         my $source = $filepath.'/'.$file;
 3046:         my $logfile;
 3047:         if (!open($logfile,">>$source".'.log')) {
 3048:             return (&mt('No write permission to Construction Space'));
 3049:         }
 3050:         print $logfile
 3051: "\n================= Publish ".localtime()." ================\n".
 3052: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 3053: # Save the file
 3054:         if (!open(FH,'>'.$source)) {
 3055:             &Apache::lonnet::logthis('Failed to create '.$source);
 3056:             return (&mt('Failed to create file'));
 3057:         }
 3058:         if ($action eq 'upload') {
 3059:             if (!print FH ($env{'form.'.$formname})) {
 3060:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 3061:                 return (&mt('Failed to write file'));
 3062:             }
 3063:         } else {
 3064:             my $original = &Apache::lonnet::filelocation('',$formname);
 3065:             if(!copy($original,$source)) {
 3066:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 3067:                 return (&mt('Failed to write file'));
 3068:             }
 3069:         }
 3070:         close(FH);
 3071:         chmod(0660, $source); # Permissions to rw-rw---.
 3072: 
 3073:         my $docroot=$r->dir_config('lonDocRoot');
 3074:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 3075:         my $copyfile=$targetdir.'/'.$file;
 3076: 
 3077:         my @parts=split(/\//,$targetdir);
 3078:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 3079:         for (my $count=5;$count<=$#parts;$count++) {
 3080:             $path.="/$parts[$count]";
 3081:             if (!-e $path) {
 3082:                 print $logfile "\nCreating directory ".$path;
 3083:                 mkdir($path,02770);
 3084:             }
 3085:         }
 3086:         my $versionresult;
 3087:         if (-e $copyfile) {
 3088:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 3089:         } else {
 3090:             $versionresult = 'ok';
 3091:         }
 3092:         if ($versionresult eq 'ok') {
 3093:             if (copy($source,$copyfile)) {
 3094:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 3095:                 $output = 'ok';
 3096:                 &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 3097:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 3098:             } else {
 3099:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 3100:                 $output = &mt('Failed to copy file to RES space').", $!";
 3101:             }
 3102:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 3103:                 my $inputfile = $filepath.'/'.$file;
 3104:                 my $outfile = $filepath.'/'.'tn-'.$file;
 3105:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 3106:                 if ($fullwidth ne '' && $fullheight ne '') { 
 3107:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 3108:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 3109:                         system("convert -sample $thumbsize $inputfile $outfile");
 3110:                         chmod(0660, $filepath.'/tn-'.$file);
 3111:                         if (-e $outfile) {
 3112:                             my $copyfile=$targetdir.'/tn-'.$file;
 3113:                             if (copy($outfile,$copyfile)) {
 3114:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 3115:                                 &write_metadata($dom,$confname,$formname,
 3116:                                                 $targetdir,'tn-'.$file,$logfile);
 3117:                             } else {
 3118:                                 print $logfile "\nUnable to write ".$copyfile.
 3119:                                                ':'.$!."\n";
 3120:                             }
 3121:                         }
 3122:                     }
 3123:                 }
 3124:             }
 3125:         } else {
 3126:             $output = $versionresult;
 3127:         }
 3128:     }
 3129:     return ($output,$logourl);
 3130: }
 3131: 
 3132: sub logo_versioning {
 3133:     my ($targetdir,$file,$logfile) = @_;
 3134:     my $target = $targetdir.'/'.$file;
 3135:     my ($maxversion,$fn,$extn,$output);
 3136:     $maxversion = 0;
 3137:     if ($file =~ /^(.+)\.(\w+)$/) {
 3138:         $fn=$1;
 3139:         $extn=$2;
 3140:     }
 3141:     opendir(DIR,$targetdir);
 3142:     while (my $filename=readdir(DIR)) {
 3143:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 3144:             $maxversion=($1>$maxversion)?$1:$maxversion;
 3145:         }
 3146:     }
 3147:     $maxversion++;
 3148:     print $logfile "\nCreating old version ".$maxversion."\n";
 3149:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 3150:     if (copy($target,$copyfile)) {
 3151:         print $logfile "Copied old target to ".$copyfile."\n";
 3152:         $copyfile=$copyfile.'.meta';
 3153:         if (copy($target.'.meta',$copyfile)) {
 3154:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 3155:             $output = 'ok';
 3156:         } else {
 3157:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 3158:             $output = &mt('Failed to copy old meta').", $!, ";
 3159:         }
 3160:     } else {
 3161:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 3162:         $output = &mt('Failed to copy old target').", $!, ";
 3163:     }
 3164:     return $output;
 3165: }
 3166: 
 3167: sub write_metadata {
 3168:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 3169:     my (%metadatafields,%metadatakeys,$output);
 3170:     $metadatafields{'title'}=$formname;
 3171:     $metadatafields{'creationdate'}=time;
 3172:     $metadatafields{'lastrevisiondate'}=time;
 3173:     $metadatafields{'copyright'}='public';
 3174:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 3175:                                          $env{'user.domain'};
 3176:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 3177:     $metadatafields{'domain'}=$dom;
 3178:     {
 3179:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 3180:         my $mfh;
 3181:         unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 3182:             $output = &mt('Could not write metadata');
 3183:         }
 3184:         foreach (sort keys %metadatafields) {
 3185:             unless ($_=~/\./) {
 3186:                 my $unikey=$_;
 3187:                 $unikey=~/^([A-Za-z]+)/;
 3188:                 my $tag=$1;
 3189:                 $tag=~tr/A-Z/a-z/;
 3190:                 print $mfh "\n\<$tag";
 3191:                 foreach (split(/\,/,$metadatakeys{$unikey})) {
 3192:                     my $value=$metadatafields{$unikey.'.'.$_};
 3193:                     $value=~s/\"/\'\'/g;
 3194:                     print $mfh ' '.$_.'="'.$value.'"';
 3195:                 }
 3196:                 print $mfh '>'.
 3197:                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 3198:                         .'</'.$tag.'>';
 3199:             }
 3200:         }
 3201:         $output = 'ok';
 3202:         print $logfile "\nWrote metadata";
 3203:         close($mfh);
 3204:     }
 3205: }
 3206: 
 3207: sub check_switchserver {
 3208:     my ($dom,$confname) = @_;
 3209:     my ($allowed,$switchserver);
 3210:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 3211:     if ($home eq 'no_host') {
 3212:         $home = &Apache::lonnet::domain($dom,'primary');
 3213:     }
 3214:     my @ids=&Apache::lonnet::current_machine_ids();
 3215:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 3216:     if (!$allowed) {
 3217: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
 3218:     }
 3219:     return $switchserver;
 3220: }
 3221: 
 3222: sub javascript_set_colnums {
 3223:     return <<END;
 3224: function setDisplayColumns() {
 3225:     if (document.pickactions.width.value > 1100) {
 3226:         document.pickactions.numcols[1].checked = true;
 3227:     } else {
 3228:         document.pickactions.numcols[0].checked = true;
 3229:     }
 3230: }
 3231: END
 3232: }
 3233: 
 3234: sub modify_quotas {
 3235:     my ($dom,%domconfig) = @_;
 3236:     my ($resulttext,%changes);
 3237:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 3238:     my %formhash;
 3239:     foreach my $key (keys(%env)) {
 3240:         if ($key =~ /^form\.quota_(.+)$/) {
 3241:             $formhash{$1} = $env{$key};
 3242:         }
 3243:     }
 3244:     $formhash{'default'} = $env{'form.defaultquota'};
 3245:     if (ref($domconfig{'quotas'}) eq 'HASH') {
 3246:         foreach my $key (keys(%{$domconfig{'quotas'}})) {
 3247:             if (exists($formhash{$key})) {
 3248:                 if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
 3249:                     $changes{$key} = 1;
 3250:                 }
 3251:             } else {
 3252:                 $formhash{$key} = $domconfig{'quotas'}{$key};
 3253:             }
 3254:         }
 3255:     }
 3256:     foreach my $key (keys(%formhash)) {
 3257:         if ($formhash{$key} ne '') {
 3258:             if (ref($domconfig{'quotas'}) eq 'HASH') {
 3259:                 if (!exists($domconfig{'quotas'}{$key})) {
 3260:                     $changes{$key} = 1;
 3261:                 }
 3262:             } else {
 3263:                 $changes{$key} = 1;
 3264:             }
 3265:         }
 3266:     }
 3267:     my %quotahash = (
 3268:                       quotas => {%formhash},
 3269:                     );
 3270:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 3271:                                              $dom);
 3272:     if ($putresult eq 'ok') {
 3273:         if (keys(%changes) > 0) {
 3274:             $resulttext = &mt('Changes made:').'<ul>';
 3275:             foreach my $type (@{$types},'default') {
 3276:                 if (defined($changes{$type})) { 
 3277:                     my $typetitle = $usertypes->{$type};
 3278:                     if ($type eq 'default') {
 3279:                         $typetitle = $othertitle;
 3280:                     }
 3281:                     $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
 3282:                 }
 3283:             }
 3284:             $resulttext .= '</ul>';
 3285:         } else {
 3286:             $resulttext = &mt('No changes made to default quotas');
 3287:         }
 3288:     } else {
 3289:         $resulttext = '<span class="LC_error">'.
 3290: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 3291:     }
 3292:     return $resulttext;
 3293: }
 3294: 
 3295: sub modify_autoenroll {
 3296:     my ($dom,%domconfig) = @_;
 3297:     my ($resulttext,%changes);
 3298:     my %currautoenroll;
 3299:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 3300:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 3301:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 3302:         }
 3303:     }
 3304:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 3305:     my %title = ( run => 'Auto-enrollment active',
 3306:                   sender => 'Sender for notification messages');
 3307:     my @offon = ('off','on');
 3308:     my $sender_uname = $env{'form.sender_uname'};
 3309:     my $sender_domain = $env{'form.sender_domain'};
 3310:     if ($sender_domain eq '') {
 3311:         $sender_uname = '';
 3312:     } elsif ($sender_uname eq '') {
 3313:         $sender_domain = '';
 3314:     }
 3315:     my %autoenrollhash =  (
 3316:                        autoenroll => { run => $env{'form.autoenroll_run'},
 3317:                                        sender_uname => $sender_uname,
 3318:                                        sender_domain => $sender_domain,
 3319: 
 3320:                                 }
 3321:                      );
 3322:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 3323:                                              $dom);
 3324:     if ($putresult eq 'ok') {
 3325:         if (exists($currautoenroll{'run'})) {
 3326:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 3327:                  $changes{'run'} = 1;
 3328:              }
 3329:         } elsif ($autorun) {
 3330:             if ($env{'form.autoenroll_run'} ne '1') {
 3331:                  $changes{'run'} = 1;
 3332:             }
 3333:         }
 3334:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 3335:             $changes{'sender'} = 1;
 3336:         }
 3337:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 3338:             $changes{'sender'} = 1;
 3339:         }
 3340:         if (keys(%changes) > 0) {
 3341:             $resulttext = &mt('Changes made:').'<ul>';
 3342:             if ($changes{'run'}) {
 3343:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 3344:             }
 3345:             if ($changes{'sender'}) {
 3346:                 if ($sender_uname eq '' || $sender_domain eq '') {
 3347:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 3348:                 } else {
 3349:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 3350:                 }
 3351:             }
 3352:             $resulttext .= '</ul>';
 3353:         } else {
 3354:             $resulttext = &mt('No changes made to auto-enrollment settings');
 3355:         }
 3356:     } else {
 3357:         $resulttext = '<span class="LC_error">'.
 3358: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 3359:     }
 3360:     return $resulttext;
 3361: }
 3362: 
 3363: sub modify_autoupdate {
 3364:     my ($dom,%domconfig) = @_;
 3365:     my ($resulttext,%currautoupdate,%fields,%changes);
 3366:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 3367:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 3368:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 3369:         }
 3370:     }
 3371:     my @offon = ('off','on');
 3372:     my %title = &Apache::lonlocal::texthash (
 3373:                    run => 'Auto-update:',
 3374:                    classlists => 'Updates to user information in classlists?'
 3375:                 );
 3376:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 3377:     my %fieldtitles = &Apache::lonlocal::texthash (
 3378:                         id => 'Student/Employee ID',
 3379:                         permanentemail => 'E-mail address',
 3380:                         lastname => 'Last Name',
 3381:                         firstname => 'First Name',
 3382:                         middlename => 'Middle Name',
 3383:                         gen => 'Generation',
 3384:                       );
 3385:     my $othertitle = &mt('All users');
 3386:     if (keys(%{$usertypes}) >  0) {
 3387:         $othertitle = &mt('Other users');
 3388:     }
 3389:     foreach my $key (keys(%env)) {
 3390:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 3391:             push(@{$fields{$1}},$2);
 3392:         }
 3393:     }
 3394:     my %updatehash = (
 3395:                       autoupdate => { run => $env{'form.autoupdate_run'},
 3396:                                       classlists => $env{'form.classlists'},
 3397:                                       fields => {%fields},
 3398:                                     }
 3399:                      );
 3400:     foreach my $key (keys(%currautoupdate)) {
 3401:         if (($key eq 'run') || ($key eq 'classlists')) {
 3402:             if (exists($updatehash{autoupdate}{$key})) {
 3403:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 3404:                     $changes{$key} = 1;
 3405:                 }
 3406:             }
 3407:         } elsif ($key eq 'fields') {
 3408:             if (ref($currautoupdate{$key}) eq 'HASH') {
 3409:                 foreach my $item (@{$types},'default') {
 3410:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 3411:                         my $change = 0;
 3412:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 3413:                             if (!exists($fields{$item})) {
 3414:                                 $change = 1;
 3415:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 3416:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
 3417:                                     $change = 1;
 3418:                                 }
 3419:                             }
 3420:                         }
 3421:                         if ($change) {
 3422:                             push(@{$changes{$key}},$item);
 3423:                         }
 3424:                     } 
 3425:                 }
 3426:             }
 3427:         }
 3428:     }
 3429:     foreach my $item (@{$types},'default') {
 3430:         if (defined($fields{$item})) {
 3431:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
 3432:                 if (!exists($currautoupdate{'fields'}{$item})) {
 3433:                     push(@{$changes{'fields'}},$item);
 3434:                 }
 3435:             } else {
 3436:                 push(@{$changes{'fields'}},$item);
 3437:             }
 3438:         }
 3439:     }
 3440:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 3441:                                              $dom);
 3442:     if ($putresult eq 'ok') {
 3443:         if (keys(%changes) > 0) {
 3444:             $resulttext = &mt('Changes made:').'<ul>';
 3445:             foreach my $key (sort(keys(%changes))) {
 3446:                 if (ref($changes{$key}) eq 'ARRAY') {
 3447:                     foreach my $item (@{$changes{$key}}) {
 3448:                         my @newvalues;
 3449:                         foreach my $type (@{$fields{$item}}) {
 3450:                             push(@newvalues,$fieldtitles{$type});
 3451:                         }
 3452:                         my $newvaluestr;
 3453:                         if (@newvalues > 0) {
 3454:                             $newvaluestr = join(', ',@newvalues);
 3455:                         } else {
 3456:                             $newvaluestr = &mt('none');
 3457:                         }
 3458:                         if ($item eq 'default') {
 3459:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
 3460:                         } else {
 3461:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
 3462:                         }
 3463:                     }
 3464:                 } else {
 3465:                     my $newvalue;
 3466:                     if ($key eq 'run') {
 3467:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 3468:                     } else {
 3469:                         $newvalue = $offon[$env{'form.'.$key}];
 3470:                     }
 3471:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 3472:                 }
 3473:             }
 3474:             $resulttext .= '</ul>';
 3475:         } else {
 3476:             $resulttext = &mt('No changes made to autoupdates');
 3477:         }
 3478:     } else {
 3479:         $resulttext = '<span class="LC_error">'.
 3480: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 3481:     }
 3482:     return $resulttext;
 3483: }
 3484: 
 3485: sub modify_directorysrch {
 3486:     my ($dom,%domconfig) = @_;
 3487:     my ($resulttext,%changes);
 3488:     my %currdirsrch;
 3489:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
 3490:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
 3491:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
 3492:         }
 3493:     }
 3494:     my %title = ( available => 'Directory search available',
 3495:                   localonly => 'Other domains can search',
 3496:                   searchby => 'Search types',
 3497:                   searchtypes => 'Search latitude');
 3498:     my @offon = ('off','on');
 3499:     my @otherdoms = ('Yes','No');
 3500: 
 3501:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
 3502:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
 3503:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
 3504: 
 3505:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 3506:     if (keys(%{$usertypes}) == 0) {
 3507:         @cansearch = ('default');
 3508:     } else {
 3509:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
 3510:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
 3511:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
 3512:                     push(@{$changes{'cansearch'}},$type);
 3513:                 }
 3514:             }
 3515:             foreach my $type (@cansearch) {
 3516:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
 3517:                     push(@{$changes{'cansearch'}},$type);
 3518:                 }
 3519:             }
 3520:         } else {
 3521:             push(@{$changes{'cansearch'}},@cansearch);
 3522:         }
 3523:     }
 3524: 
 3525:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
 3526:         foreach my $by (@{$currdirsrch{'searchby'}}) {
 3527:             if (!grep(/^\Q$by\E$/,@searchby)) {
 3528:                 push(@{$changes{'searchby'}},$by);
 3529:             }
 3530:         }
 3531:         foreach my $by (@searchby) {
 3532:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
 3533:                 push(@{$changes{'searchby'}},$by);
 3534:             }
 3535:         }
 3536:     } else {
 3537:         push(@{$changes{'searchby'}},@searchby);
 3538:     }
 3539: 
 3540:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
 3541:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
 3542:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
 3543:                 push(@{$changes{'searchtypes'}},$type);
 3544:             }
 3545:         }
 3546:         foreach my $type (@searchtypes) {
 3547:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
 3548:                 push(@{$changes{'searchtypes'}},$type);
 3549:             }
 3550:         }
 3551:     } else {
 3552:         if (exists($currdirsrch{'searchtypes'})) {
 3553:             foreach my $type (@searchtypes) {  
 3554:                 if ($type ne $currdirsrch{'searchtypes'}) { 
 3555:                     push(@{$changes{'searchtypes'}},$type);
 3556:                 }
 3557:             }
 3558:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
 3559:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
 3560:             }   
 3561:         } else {
 3562:             push(@{$changes{'searchtypes'}},@searchtypes); 
 3563:         }
 3564:     }
 3565: 
 3566:     my %dirsrch_hash =  (
 3567:             directorysrch => { available => $env{'form.dirsrch_available'},
 3568:                                cansearch => \@cansearch,
 3569:                                localonly => $env{'form.dirsrch_localonly'},
 3570:                                searchby => \@searchby,
 3571:                                searchtypes => \@searchtypes,
 3572:                              }
 3573:             );
 3574:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
 3575:                                              $dom);
 3576:     if ($putresult eq 'ok') {
 3577:         if (exists($currdirsrch{'available'})) {
 3578:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
 3579:                  $changes{'available'} = 1;
 3580:              }
 3581:         } else {
 3582:             if ($env{'form.dirsrch_available'} eq '1') {
 3583:                 $changes{'available'} = 1;
 3584:             }
 3585:         }
 3586:         if (exists($currdirsrch{'localonly'})) {
 3587:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
 3588:                  $changes{'localonly'} = 1;
 3589:              }
 3590:         } else {
 3591:             if ($env{'form.dirsrch_localonly'} eq '1') {
 3592:                 $changes{'localonly'} = 1;
 3593:             }
 3594:         }
 3595:         if (keys(%changes) > 0) {
 3596:             $resulttext = &mt('Changes made:').'<ul>';
 3597:             if ($changes{'available'}) {
 3598:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
 3599:             }
 3600:             if ($changes{'localonly'}) {
 3601:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
 3602:             }
 3603: 
 3604:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
 3605:                 my $chgtext;
 3606:                 if (ref($usertypes) eq 'HASH') {
 3607:                     if (keys(%{$usertypes}) > 0) {
 3608:                         foreach my $type (@{$types}) {
 3609:                             if (grep(/^\Q$type\E$/,@cansearch)) {
 3610:                                 $chgtext .= $usertypes->{$type}.'; ';
 3611:                             }
 3612:                         }
 3613:                         if (grep(/^default$/,@cansearch)) {
 3614:                             $chgtext .= $othertitle;
 3615:                         } else {
 3616:                             $chgtext =~ s/\; $//;
 3617:                         }
 3618:                         $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
 3619:                     }
 3620:                 }
 3621:             }
 3622:             if (ref($changes{'searchby'}) eq 'ARRAY') {
 3623:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
 3624:                 my $chgtext;
 3625:                 foreach my $type (@{$titleorder}) {
 3626:                     if (grep(/^\Q$type\E$/,@searchby)) {
 3627:                         if (defined($searchtitles->{$type})) {
 3628:                             $chgtext .= $searchtitles->{$type}.'; ';
 3629:                         }
 3630:                     }
 3631:                 }
 3632:                 $chgtext =~ s/\; $//;
 3633:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
 3634:             }
 3635:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
 3636:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
 3637:                 my $chgtext;
 3638:                 foreach my $type (@{$srchtypeorder}) {
 3639:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
 3640:                         if (defined($srchtypes_desc->{$type})) {
 3641:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
 3642:                         }
 3643:                     }
 3644:                 }
 3645:                 $chgtext =~ s/\; $//;
 3646:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
 3647:             }
 3648:             $resulttext .= '</ul>';
 3649:         } else {
 3650:             $resulttext = &mt('No changes made to institution directory search settings');
 3651:         }
 3652:     } else {
 3653:         $resulttext = '<span class="LC_error">'.
 3654:                       &mt('An error occurred: [_1]',$putresult).'</span>';
 3655:     }
 3656:     return $resulttext;
 3657: }
 3658: 
 3659: sub modify_contacts {
 3660:     my ($dom,%domconfig) = @_;
 3661:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
 3662:     if (ref($domconfig{'contacts'}) eq 'HASH') {
 3663:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
 3664:             $currsetting{$key} = $domconfig{'contacts'}{$key};
 3665:         }
 3666:     }
 3667:     my (%others,%to);
 3668:     my @contacts = ('supportemail','adminemail');
 3669:     my @mailings = ('errormail','packagesmail','helpdeskmail');
 3670:     foreach my $type (@mailings) {
 3671:         @{$newsetting{$type}} = 
 3672:             &Apache::loncommon::get_env_multiple('form.'.$type);
 3673:         foreach my $item (@contacts) {
 3674:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
 3675:                 $contacts_hash{contacts}{$type}{$item} = 1;
 3676:             } else {
 3677:                 $contacts_hash{contacts}{$type}{$item} = 0;
 3678:             }
 3679:         }  
 3680:         $others{$type} = $env{'form.'.$type.'_others'};
 3681:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
 3682:     }
 3683:     foreach my $item (@contacts) {
 3684:         $to{$item} = $env{'form.'.$item};
 3685:         $contacts_hash{'contacts'}{$item} = $to{$item};
 3686:     }
 3687:     if (keys(%currsetting) > 0) {
 3688:         foreach my $item (@contacts) {
 3689:             if ($to{$item} ne $currsetting{$item}) {
 3690:                 $changes{$item} = 1;
 3691:             }
 3692:         }
 3693:         foreach my $type (@mailings) {
 3694:             foreach my $item (@contacts) {
 3695:                 if (ref($currsetting{$type}) eq 'HASH') {
 3696:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
 3697:                         push(@{$changes{$type}},$item);
 3698:                     }
 3699:                 } else {
 3700:                     push(@{$changes{$type}},@{$newsetting{$type}});
 3701:                 }
 3702:             }
 3703:             if ($others{$type} ne $currsetting{$type}{'others'}) {
 3704:                 push(@{$changes{$type}},'others');
 3705:             }
 3706:         }
 3707:     } else {
 3708:         my %default;
 3709:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 3710:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 3711:         $default{'errormail'} = 'adminemail';
 3712:         $default{'packagesmail'} = 'adminemail';
 3713:         $default{'helpdeskmail'} = 'supportemail';
 3714:         foreach my $item (@contacts) {
 3715:            if ($to{$item} ne $default{$item}) {
 3716:               $changes{$item} = 1;
 3717:            } 
 3718:         }
 3719:         foreach my $type (@mailings) {
 3720:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
 3721:                
 3722:                 push(@{$changes{$type}},@{$newsetting{$type}});
 3723:             }
 3724:             if ($others{$type} ne '') {
 3725:                 push(@{$changes{$type}},'others');
 3726:             } 
 3727:         }
 3728:     }
 3729:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
 3730:                                              $dom);
 3731:     if ($putresult eq 'ok') {
 3732:         if (keys(%changes) > 0) {
 3733:             my ($titles,$short_titles)  = &contact_titles();
 3734:             $resulttext = &mt('Changes made:').'<ul>';
 3735:             foreach my $item (@contacts) {
 3736:                 if ($changes{$item}) {
 3737:                     $resulttext .= '<li>'.$titles->{$item}.
 3738:                                     &mt(' set to: ').
 3739:                                     '<span class="LC_cusr_emph">'.
 3740:                                     $to{$item}.'</span></li>';
 3741:                 }
 3742:             }
 3743:             foreach my $type (@mailings) {
 3744:                 if (ref($changes{$type}) eq 'ARRAY') {
 3745:                     $resulttext .= '<li>'.$titles->{$type}.': ';
 3746:                     my @text;
 3747:                     foreach my $item (@{$newsetting{$type}}) {
 3748:                         push(@text,$short_titles->{$item});
 3749:                     }
 3750:                     if ($others{$type} ne '') {
 3751:                         push(@text,$others{$type});
 3752:                     }
 3753:                     $resulttext .= '<span class="LC_cusr_emph">'.
 3754:                                    join(', ',@text).'</span></li>';
 3755:                 }
 3756:             }
 3757:             $resulttext .= '</ul>';
 3758:         } else {
 3759:             $resulttext = &mt('No changes made to contact information');
 3760:         }
 3761:     } else {
 3762:         $resulttext = '<span class="LC_error">'.
 3763:             &mt('An error occurred: [_1].',$putresult).'</span>';
 3764:     }
 3765:     return $resulttext;
 3766: }
 3767: 
 3768: sub modify_usercreation {
 3769:     my ($dom,%domconfig) = @_;
 3770:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
 3771:     my $warningmsg;
 3772:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 3773:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 3774:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 3775:         }
 3776:     }
 3777:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
 3778:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
 3779:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
 3780:     my @contexts = ('author','course','selfcreate');
 3781:     foreach my $item(@contexts) {
 3782:         if ($item eq 'selfcreate') {
 3783:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
 3784:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 3785:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
 3786:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
 3787:                     if (grep(/^login$/,@{$cancreate{$item}})) {
 3788:                         $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.');   
 3789:                     }
 3790:                 }
 3791:             }
 3792:         } else {
 3793:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
 3794:         }
 3795:     }
 3796:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 3797:         foreach my $item (@contexts) {
 3798:             if ($item eq 'selfcreate') {
 3799:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') { 
 3800:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
 3801:                         if (!grep(/^$curr$/,@{$cancreate{$item}})) {
 3802:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 3803:                                 push(@{$changes{'cancreate'}},$item);
 3804:                             }
 3805:                         }
 3806:                     }
 3807:                 } else {
 3808:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
 3809:                         if (@{$cancreate{$item}} > 0) {
 3810:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 3811:                                 push(@{$changes{'cancreate'}},$item);
 3812:                             }
 3813:                         }
 3814:                     } else {
 3815:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
 3816:                             if (@{$cancreate{$item}} < 3) {
 3817:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 3818:                                     push(@{$changes{'cancreate'}},$item);
 3819:                                 }
 3820:                             }
 3821:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
 3822:                             if (@{$cancreate{$item}} > 0) {
 3823:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 3824:                                     push(@{$changes{'cancreate'}},$item);
 3825:                                 }
 3826:                             }
 3827:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
 3828:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 3829:                                 push(@{$changes{'cancreate'}},$item);
 3830:                             }
 3831:                         }
 3832:                     }
 3833:                 }
 3834:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 3835:                     foreach my $type (@{$cancreate{$item}}) {
 3836:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 3837:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
 3838:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 3839:                                     push(@{$changes{'cancreate'}},$item);
 3840:                                 }
 3841:                             }
 3842:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
 3843:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
 3844:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
 3845:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 3846:                                     push(@{$changes{'cancreate'}},$item);
 3847:                                 }
 3848:                             }
 3849:                         }
 3850:                     }
 3851:                 }
 3852:             } else {
 3853:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
 3854:                     push(@{$changes{'cancreate'}},$item);
 3855:                 }
 3856:             }
 3857:         }
 3858:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
 3859:         foreach my $item (@contexts) {
 3860:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
 3861:                 if ($cancreate{$item} ne 'any') {
 3862:                     push(@{$changes{'cancreate'}},$item);
 3863:                 }
 3864:             } else {
 3865:                 if ($cancreate{$item} ne 'none') {
 3866:                     push(@{$changes{'cancreate'}},$item);
 3867:                 }
 3868:             }
 3869:         }
 3870:     } else {
 3871:         foreach my $item (@contexts)  {
 3872:             push(@{$changes{'cancreate'}},$item);
 3873:         }
 3874:     }
 3875: 
 3876:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
 3877:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
 3878:             if (!grep(/^\Q$type\E$/,@username_rule)) {
 3879:                 push(@{$changes{'username_rule'}},$type);
 3880:             }
 3881:         }
 3882:         foreach my $type (@username_rule) {
 3883:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
 3884:                 push(@{$changes{'username_rule'}},$type);
 3885:             }
 3886:         }
 3887:     } else {
 3888:         push(@{$changes{'username_rule'}},@username_rule);
 3889:     }
 3890: 
 3891:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
 3892:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
 3893:             if (!grep(/^\Q$type\E$/,@id_rule)) {
 3894:                 push(@{$changes{'id_rule'}},$type);
 3895:             }
 3896:         }
 3897:         foreach my $type (@id_rule) {
 3898:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
 3899:                 push(@{$changes{'id_rule'}},$type);
 3900:             }
 3901:         }
 3902:     } else {
 3903:         push(@{$changes{'id_rule'}},@id_rule);
 3904:     }
 3905: 
 3906:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
 3907:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
 3908:             if (!grep(/^\Q$type\E$/,@email_rule)) {
 3909:                 push(@{$changes{'email_rule'}},$type);
 3910:             }
 3911:         }
 3912:         foreach my $type (@email_rule) {
 3913:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
 3914:                 push(@{$changes{'email_rule'}},$type);
 3915:             }
 3916:         }
 3917:     } else {
 3918:         push(@{$changes{'email_rule'}},@email_rule);
 3919:     }
 3920: 
 3921:     my @authen_contexts = ('author','course','domain');
 3922:     my @authtypes = ('int','krb4','krb5','loc');
 3923:     my %authhash;
 3924:     foreach my $item (@authen_contexts) {
 3925:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
 3926:         foreach my $auth (@authtypes) {
 3927:             if (grep(/^\Q$auth\E$/,@authallowed)) {
 3928:                 $authhash{$item}{$auth} = 1;
 3929:             } else {
 3930:                 $authhash{$item}{$auth} = 0;
 3931:             }
 3932:         }
 3933:     }
 3934:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
 3935:         foreach my $item (@authen_contexts) {
 3936:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
 3937:                 foreach my $auth (@authtypes) {
 3938:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
 3939:                         push(@{$changes{'authtypes'}},$item);
 3940:                         last;
 3941:                     }
 3942:                 }
 3943:             }
 3944:         }
 3945:     } else {
 3946:         foreach my $item (@authen_contexts) {
 3947:             push(@{$changes{'authtypes'}},$item);
 3948:         }
 3949:     }
 3950: 
 3951:     my %usercreation_hash =  (
 3952:             usercreation => {
 3953:                               cancreate     => \%cancreate,
 3954:                               username_rule => \@username_rule,
 3955:                               id_rule       => \@id_rule,
 3956:                               email_rule    => \@email_rule,
 3957:                               authtypes     => \%authhash,
 3958:                             }
 3959:             );
 3960: 
 3961:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
 3962:                                              $dom);
 3963: 
 3964:     my %selfcreatetypes = (
 3965:                              sso   => 'users authenticated by institutional single sign on',
 3966:                              login => 'users authenticated by institutional log-in',
 3967:                              email => 'users who provide a valid e-mail address for use as the username',
 3968:                           );
 3969:     if ($putresult eq 'ok') {
 3970:         if (keys(%changes) > 0) {
 3971:             $resulttext = &mt('Changes made:').'<ul>';
 3972:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 3973:                 my %lt = &usercreation_types();
 3974:                 foreach my $type (@{$changes{'cancreate'}}) {
 3975:                     my $chgtext =  $lt{$type}.', ';
 3976:                     if ($type eq 'selfcreate') {
 3977:                         if (@{$cancreate{$type}} == 0) {
 3978:                             $chgtext .= &mt('creation of a new user account is not permitted.');
 3979:                         } else {
 3980:                             $chgtext .= &mt('creation of a new account is permitted for:<ul>');
 3981:                             foreach my $case (@{$cancreate{$type}}) {
 3982:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
 3983:                             }
 3984:                             $chgtext .= '</ul>';
 3985:                         }
 3986:                     } else {
 3987:                         if ($cancreate{$type} eq 'none') {
 3988:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
 3989:                         } elsif ($cancreate{$type} eq 'any') {
 3990:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
 3991:                         } elsif ($cancreate{$type} eq 'official') {
 3992:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
 3993:                         } elsif ($cancreate{$type} eq 'unofficial') {
 3994:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
 3995:                         }
 3996:                     }
 3997:                     $resulttext .= '<li>'.$chgtext.'</li>';
 3998:                 }
 3999:             }
 4000:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
 4001:                 my ($rules,$ruleorder) = 
 4002:                     &Apache::lonnet::inst_userrules($dom,'username');
 4003:                 my $chgtext = '<ul>';
 4004:                 foreach my $type (@username_rule) {
 4005:                     if (ref($rules->{$type}) eq 'HASH') {
 4006:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
 4007:                     }
 4008:                 }
 4009:                 $chgtext .= '</ul>';
 4010:                 if (@username_rule > 0) {
 4011:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
 4012:                 } else {
 4013:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
 4014:                 }
 4015:             }
 4016:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
 4017:                 my ($idrules,$idruleorder) = 
 4018:                     &Apache::lonnet::inst_userrules($dom,'id');
 4019:                 my $chgtext = '<ul>';
 4020:                 foreach my $type (@id_rule) {
 4021:                     if (ref($idrules->{$type}) eq 'HASH') {
 4022:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
 4023:                     }
 4024:                 }
 4025:                 $chgtext .= '</ul>';
 4026:                 if (@id_rule > 0) {
 4027:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
 4028:                 } else {
 4029:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
 4030:                 }
 4031:             }
 4032:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
 4033:                 my ($emailrules,$emailruleorder) =
 4034:                     &Apache::lonnet::inst_userrules($dom,'email');
 4035:                 my $chgtext = '<ul>';
 4036:                 foreach my $type (@email_rule) {
 4037:                     if (ref($emailrules->{$type}) eq 'HASH') {
 4038:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
 4039:                     }
 4040:                 }
 4041:                 $chgtext .= '</ul>';
 4042:                 if (@email_rule > 0) {
 4043:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
 4044:                 } else {
 4045:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
 4046:                 }
 4047:             }
 4048: 
 4049:             my %authname = &authtype_names();
 4050:             my %context_title = &context_names();
 4051:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
 4052:                 my $chgtext = '<ul>';
 4053:                 foreach my $type (@{$changes{'authtypes'}}) {
 4054:                     my @allowed;
 4055:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
 4056:                     foreach my $auth (@authtypes) {
 4057:                         if ($authhash{$type}{$auth}) {
 4058:                             push(@allowed,$authname{$auth});
 4059:                         }
 4060:                     }
 4061:                     if (@allowed > 0) {
 4062:                         $chgtext .= join(', ',@allowed).'</li>';
 4063:                     } else {
 4064:                         $chgtext .= &mt('none').'</li>';
 4065:                     }
 4066:                 }
 4067:                 $chgtext .= '</ul>';
 4068:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
 4069:                 $resulttext .= '</li>';
 4070:             }
 4071:             $resulttext .= '</ul>';
 4072:         } else {
 4073:             $resulttext = &mt('No changes made to user creation settings');
 4074:         }
 4075:     } else {
 4076:         $resulttext = '<span class="LC_error">'.
 4077:             &mt('An error occurred: [_1]',$putresult).'</span>';
 4078:     }
 4079:     if ($warningmsg ne '') {
 4080:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
 4081:     }
 4082:     return $resulttext;
 4083: }
 4084: 
 4085: sub modify_usermodification {
 4086:     my ($dom,%domconfig) = @_;
 4087:     my ($resulttext,%curr_usermodification,%changes);
 4088:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 4089:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 4090:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
 4091:         }
 4092:     }
 4093:     my @contexts = ('author','course');
 4094:     my %context_title = (
 4095:                            author => 'In author context',
 4096:                            course => 'In course context',
 4097:                         );
 4098:     my @fields = ('lastname','firstname','middlename','generation',
 4099:                   'permanentemail','id');
 4100:     my %roles = (
 4101:                   author => ['ca','aa'],
 4102:                   course => ['st','ep','ta','in','cr'],
 4103:                 );
 4104:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 4105:     my %modifyhash;
 4106:     foreach my $context (@contexts) {
 4107:         foreach my $role (@{$roles{$context}}) {
 4108:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
 4109:             foreach my $item (@fields) {
 4110:                 if (grep(/^\Q$item\E$/,@modifiable)) {
 4111:                     $modifyhash{$context}{$role}{$item} = 1;
 4112:                 } else {
 4113:                     $modifyhash{$context}{$role}{$item} = 0;
 4114:                 }
 4115:             }
 4116:         }
 4117:         if (ref($curr_usermodification{$context}) eq 'HASH') {
 4118:             foreach my $role (@{$roles{$context}}) {
 4119:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
 4120:                     foreach my $field (@fields) {
 4121:                         if ($modifyhash{$context}{$role}{$field} ne 
 4122:                                 $curr_usermodification{$context}{$role}{$field}) {
 4123:                             push(@{$changes{$context}},$role);
 4124:                             last;
 4125:                         }
 4126:                     }
 4127:                 }
 4128:             }
 4129:         } else {
 4130:             foreach my $context (@contexts) {
 4131:                 foreach my $role (@{$roles{$context}}) {
 4132:                     push(@{$changes{$context}},$role);
 4133:                 }
 4134:             }
 4135:         }
 4136:     }
 4137:     my %usermodification_hash =  (
 4138:                                    usermodification => \%modifyhash,
 4139:                                  );
 4140:     my $putresult = &Apache::lonnet::put_dom('configuration',
 4141:                                              \%usermodification_hash,$dom);
 4142:     if ($putresult eq 'ok') {
 4143:         if (keys(%changes) > 0) {
 4144:             $resulttext = &mt('Changes made: ').'<ul>';
 4145:             foreach my $context (@contexts) {
 4146:                 if (ref($changes{$context}) eq 'ARRAY') {
 4147:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
 4148:                     if (ref($changes{$context}) eq 'ARRAY') {
 4149:                         foreach my $role (@{$changes{$context}}) {
 4150:                             my $rolename;
 4151:                             if ($role eq 'cr') {
 4152:                                 $rolename = &mt('Custom');
 4153:                             } else {
 4154:                                 $rolename = &Apache::lonnet::plaintext($role);
 4155:                             }
 4156:                             my @modifiable;
 4157:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
 4158:                             foreach my $field (@fields) {
 4159:                                 if ($modifyhash{$context}{$role}{$field}) {
 4160:                                     push(@modifiable,$fieldtitles{$field});
 4161:                                 }
 4162:                             }
 4163:                             if (@modifiable > 0) {
 4164:                                 $resulttext .= join(', ',@modifiable);
 4165:                             } else {
 4166:                                 $resulttext .= &mt('none'); 
 4167:                             }
 4168:                             $resulttext .= '</li>';
 4169:                         }
 4170:                         $resulttext .= '</ul></li>';
 4171:                     }
 4172:                 }
 4173:             }
 4174:             $resulttext .= '</ul>';
 4175:         } else {
 4176:             $resulttext = &mt('No changes made to user modification settings');
 4177:         }
 4178:     } else {
 4179:         $resulttext = '<span class="LC_error">'.
 4180:             &mt('An error occurred: [_1]',$putresult).'</span>';
 4181:     }
 4182:     return $resulttext;
 4183: }
 4184: 
 4185: sub modify_defaults {
 4186:     my ($dom,$r) = @_;
 4187:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
 4188:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 4189:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def');
 4190:     my @authtypes = ('internal','krb4','krb5','localauth');
 4191:     foreach my $item (@items) {
 4192:         $newvalues{$item} = $env{'form.'.$item};
 4193:         if ($item eq 'auth_def') {
 4194:             if ($newvalues{$item} ne '') {
 4195:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
 4196:                     push(@errors,$item);
 4197:                 }
 4198:             }
 4199:         } elsif ($item eq 'lang_def') {
 4200:             if ($newvalues{$item} ne '') {
 4201:                 if ($newvalues{$item} =~ /^(\w+)/) {
 4202:                     my $langcode = $1;
 4203:                     if (code2language($langcode) eq '') {
 4204:                         push(@errors,$item);
 4205:                     }
 4206:                 } else {
 4207:                     push(@errors,$item);
 4208:                 }
 4209:             }
 4210:         } elsif ($item eq 'timezone_def') {
 4211:             if ($newvalues{$item} ne '') {
 4212:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
 4213:                     push(@errors,$item);   
 4214:                 }
 4215:             }
 4216:         }
 4217:         if (grep(/^\Q$item\E$/,@errors)) {
 4218:             $newvalues{$item} = $domdefaults{$item};
 4219:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
 4220:             $changes{$item} = 1;
 4221:         }
 4222:     }
 4223:     my %defaults_hash = (
 4224:                          defaults => { auth_def => $newvalues{'auth_def'},
 4225:                                        auth_arg_def => $newvalues{'auth_arg_def'},
 4226:                                        lang_def => $newvalues{'lang_def'},
 4227:                                        timezone_def => $newvalues{'timezone_def'},
 4228:                                      }
 4229:                        );
 4230:     my $title = &defaults_titles();
 4231:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
 4232:                                              $dom);
 4233:     if ($putresult eq 'ok') {
 4234:         if (keys(%changes) > 0) {
 4235:             $resulttext = &mt('Changes made:').'<ul>';
 4236:             my $version = $r->dir_config('lonVersion');
 4237:             my $mailmsgtext = "Changes made to domain settings in a LON-CAPA installation - domain: $dom (running version: $version) - dns_domain.tab needs to be updated with the following changes, to support legacy 2.4, 2.5 and 2.6 versions of LON-CAPA.\n\n";
 4238:             foreach my $item (sort(keys(%changes))) {
 4239:                 my $value = $env{'form.'.$item};
 4240:                 if ($value eq '') {
 4241:                     $value = &mt('none');
 4242:                 } elsif ($item eq 'auth_def') {
 4243:                     my %authnames = &authtype_names();
 4244:                     my %shortauth = (
 4245:                              internal => 'int',
 4246:                              krb4 => 'krb4',
 4247:                              krb5 => 'krb5',
 4248:                              localauth  => 'loc',
 4249:                     );
 4250:                     $value = $authnames{$shortauth{$value}};
 4251:                 }
 4252:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
 4253:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
 4254:             }
 4255:             $resulttext .= '</ul>';
 4256:             $mailmsgtext .= "\n";
 4257:             my $cachetime = 24*60*60;
 4258:             &Apache::lonnet::do_cache_new('domdefaults',$dom,
 4259:                                           $defaults_hash{'defaults'},$cachetime);
 4260:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'}) {
 4261:                 my $sysmail = $r->dir_config('lonSysEMail');
 4262:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
 4263:             }
 4264:         } else {
 4265:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
 4266:         }
 4267:     } else {
 4268:         $resulttext = '<span class="LC_error">'.
 4269:             &mt('An error occurred: [_1]',$putresult).'</span>';
 4270:     }
 4271:     if (@errors > 0) {
 4272:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
 4273:         foreach my $item (@errors) {
 4274:             $resulttext .= ' "'.$title->{$item}.'",';
 4275:         }
 4276:         $resulttext =~ s/,$//;
 4277:     }
 4278:     return $resulttext;
 4279: }
 4280: 
 4281: sub modify_scantron {
 4282:     my ($r,$dom,$confname,%domconfig) = @_;
 4283:     my ($resulttext,%confhash,%changes,$errors);
 4284:     my $custom = 'custom.tab';
 4285:     my $default = 'default.tab';
 4286:     my $servadm = $r->dir_config('lonAdmEMail');
 4287:     my ($configuserok,$author_ok,$switchserver) = 
 4288:         &config_check($dom,$confname,$servadm);
 4289:     if ($env{'form.scantronformat.filename'} ne '') {
 4290:         my $error;
 4291:         if ($configuserok eq 'ok') {
 4292:             if ($switchserver) {
 4293:                 $error = &mt("Upload of scantron format file is not permitted to this server: [_1]",$switchserver);
 4294:             } else {
 4295:                 if ($author_ok eq 'ok') {
 4296:                     my ($result,$scantronurl) =
 4297:                         &publishlogo($r,'upload','scantronformat',$dom,
 4298:                                      $confname,'scantron','','',$custom);
 4299:                     if ($result eq 'ok') {
 4300:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
 4301:                         $changes{'scantronformat'} = 1;
 4302:                     } else {
 4303:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
 4304:                     }
 4305:                 } else {
 4306:                     $error = &mt("Upload of [_1] failed because an author role could not be assigned to a Domain Configuration user ([_2]) in domain: [_3].  Error was: [_4].",$custom,$confname,$dom,$author_ok);
 4307:                 }
 4308:             }
 4309:         } else {
 4310:             $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$custom,$confname,$dom,$configuserok);
 4311:         }
 4312:         if ($error) {
 4313:             &Apache::lonnet::logthis($error);
 4314:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 4315:         }
 4316:     }
 4317:     if (ref($domconfig{'scantron'}) eq 'HASH') {
 4318:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
 4319:             if ($env{'form.scantronformat_del'}) {
 4320:                 $confhash{'scantron'}{'scantronformat'} = '';
 4321:                 $changes{'scantronformat'} = 1;
 4322:             }
 4323:         }
 4324:     }
 4325:     if (keys(%confhash) > 0) {
 4326:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
 4327:                                                  $dom);
 4328:         if ($putresult eq 'ok') {
 4329:             if (keys(%changes) > 0) {
 4330:                 if (ref($confhash{'scantron'}) eq 'HASH') {
 4331:                     $resulttext = &mt('Changes made:').'<ul>';
 4332:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
 4333:                         $resulttext .= '<li>'.&mt('[_1] scantron format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
 4334:                     } else {
 4335:                         $resulttext .= '<li>'.&mt('Custom scantron format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
 4336:                     }
 4337:                     $resulttext .= '</ul>';
 4338:                 } else {
 4339:                     $resulttext = &mt('Changes made to scantron format file.');
 4340:                 }
 4341:                 $resulttext .= '</ul>';
 4342:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 4343:             } else {
 4344:                 $resulttext = &mt('No changes made to scantron format file');
 4345:             }
 4346:         } else {
 4347:             $resulttext = '<span class="LC_error">'.
 4348:                 &mt('An error occurred: [_1]',$putresult).'</span>';
 4349:         }
 4350:     } else {
 4351:         $resulttext = &mt('No changes made to scantron format file'); 
 4352:     }
 4353:     if ($errors) {
 4354:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 4355:                        $errors.'</ul>';
 4356:     }
 4357:     return $resulttext;
 4358: }
 4359: 
 4360: sub modify_coursecategories {
 4361:     my ($dom,%domconfig) = @_;
 4362:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
 4363:         $cathash);
 4364:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
 4365:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 4366:         $cathash = $domconfig{'coursecategories'}{'cats'};
 4367:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
 4368:             $changes{'togglecats'} = 1;
 4369:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
 4370:         }
 4371:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
 4372:             $changes{'categorize'} = 1;
 4373:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
 4374:         }
 4375:     } else {
 4376:         $changes{'togglecats'} = 1;
 4377:         $changes{'categorize'} = 1;
 4378:         $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
 4379:         $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
 4380:     }
 4381:     if (ref($cathash) eq 'HASH') {
 4382:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
 4383:             push (@deletecategory,'instcode::0');
 4384:         }
 4385:     }
 4386:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
 4387:     if (ref($cathash) eq 'HASH') {
 4388:         if (@deletecategory > 0) {
 4389:             #FIXME Need to remove category from all courses using a deleted category 
 4390:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
 4391:             foreach my $item (@deletecategory) {
 4392:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
 4393:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
 4394:                     $deletions{$item} = 1;
 4395:                     &recurse_cat_deletes($item,$cathash,\%deletions);
 4396:                 }
 4397:             }
 4398:         }
 4399:         foreach my $item (keys(%{$cathash})) {
 4400:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 4401:             if ($cathash->{$item} ne $env{'form.'.$item}) {
 4402:                 $reorderings{$item} = 1;
 4403:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
 4404:             }
 4405:             if ($env{'form.addcategory_name_'.$item} ne '') {
 4406:                 my $newcat = $env{'form.addcategory_name_'.$item};
 4407:                 my $newdepth = $depth+1;
 4408:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 4409:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
 4410:                 $adds{$newitem} = 1; 
 4411:             }
 4412:             if ($env{'form.subcat_'.$item} ne '') {
 4413:                 my $newcat = $env{'form.subcat_'.$item};
 4414:                 my $newdepth = $depth+1;
 4415:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 4416:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
 4417:                 $adds{$newitem} = 1;
 4418:             }
 4419:         }
 4420:     }
 4421:     if ($env{'form.instcode'} eq '1') {
 4422:         if (ref($cathash) eq 'HASH') {
 4423:             my $newitem = 'instcode::0';
 4424:             if ($cathash->{$newitem} eq '') {  
 4425:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 4426:                 $adds{$newitem} = 1;
 4427:             }
 4428:         } else {
 4429:             my $newitem = 'instcode::0';
 4430:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 4431:             $adds{$newitem} = 1;
 4432:         }
 4433:     }
 4434:     if ($env{'form.addcategory_name'} ne '') {
 4435:         my $newitem = &escape($env{'form.addcategory_name'}).'::0';
 4436:         $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
 4437:         $adds{$newitem} = 1;
 4438:     }
 4439:     my $putresult;
 4440:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 4441:         if (keys(%deletions) > 0) {
 4442:             foreach my $key (keys(%deletions)) {
 4443:                 if ($predelallitems{$key} ne '') {
 4444:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
 4445:                 }
 4446:             }
 4447:         }
 4448:         my (@chkcats,@chktrails,%chkallitems);
 4449:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
 4450:         if (ref($chkcats[0]) eq 'ARRAY') {
 4451:             my $depth = 0;
 4452:             my $chg = 0;
 4453:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
 4454:                 my $name = $chkcats[0][$i];
 4455:                 my $item;
 4456:                 if ($name eq '') {
 4457:                     $chg ++;
 4458:                 } else {
 4459:                     $item = &escape($name).'::0';
 4460:                     if ($chg) {
 4461:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
 4462:                     }
 4463:                     $depth ++; 
 4464:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
 4465:                     $depth --;
 4466:                 }
 4467:             }
 4468:         }
 4469:     }
 4470:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 4471:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
 4472:         if ($putresult eq 'ok') {
 4473:             my %title = (
 4474:                          togglecats  => 'Show/Hide a course in the catalog',
 4475:                          categorize     => 'Category assigned to course',
 4476:                         );
 4477:             my %level = (
 4478:                          dom => 'set from "Modify Course" (Domain)',
 4479:                          crs => 'set from "Parameters" (Course)',
 4480:                         );
 4481:             $resulttext = &mt('Changes made:').'<ul>';
 4482:             if ($changes{'togglecats'}) {
 4483:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
 4484:             }
 4485:             if ($changes{'categorize'}) {
 4486:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
 4487:             }
 4488:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 4489:                 my $cathash;
 4490:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 4491:                     $cathash = $domconfig{'coursecategories'}{'cats'};
 4492:                 } else {
 4493:                     $cathash = {};
 4494:                 } 
 4495:                 my (@cats,@trails,%allitems);
 4496:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
 4497:                 if (keys(%deletions) > 0) {
 4498:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
 4499:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
 4500:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
 4501:                     }
 4502:                     $resulttext .= '</ul></li>';
 4503:                 }
 4504:                 if (keys(%reorderings) > 0) {
 4505:                     my %sort_by_trail;
 4506:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
 4507:                     foreach my $key (keys(%reorderings)) {
 4508:                         if ($allitems{$key} ne '') {
 4509:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 4510:                         }
 4511:                     }
 4512:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 4513:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 4514:                     }
 4515:                     $resulttext .= '</ul></li>';
 4516:                 }
 4517:                 if (keys(%adds) > 0) {
 4518:                     my %sort_by_trail;
 4519:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
 4520:                     foreach my $key (keys(%adds)) {
 4521:                         if ($allitems{$key} ne '') {
 4522:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 4523:                         }
 4524:                     }
 4525:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 4526:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 4527:                     }
 4528:                     $resulttext .= '</ul></li>';
 4529:                 }
 4530:             }
 4531:             $resulttext .= '</ul>';
 4532:         } else {
 4533:             $resulttext = '<span class="LC_error">'.
 4534:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 4535:         }
 4536:     } else {
 4537:         $resulttext = &mt('No changes made to course categories');
 4538:     }
 4539:     return $resulttext;
 4540: }
 4541: 
 4542: sub recurse_check {
 4543:     my ($chkcats,$categories,$depth,$name) = @_;
 4544:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
 4545:         my $chg = 0;
 4546:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
 4547:             my $category = $chkcats->[$depth]{$name}[$j];
 4548:             my $item;
 4549:             if ($category eq '') {
 4550:                 $chg ++;
 4551:             } else {
 4552:                 my $deeper = $depth + 1;
 4553:                 $item = &escape($category).':'.&escape($name).':'.$depth;
 4554:                 if ($chg) {
 4555:                     $categories->{$item} -= $chg;
 4556:                 }
 4557:                 &recurse_check($chkcats,$categories,$deeper,$category);
 4558:                 $deeper --;
 4559:             }
 4560:         }
 4561:     }
 4562:     return;
 4563: }
 4564: 
 4565: sub recurse_cat_deletes {
 4566:     my ($item,$coursecategories,$deletions) = @_;
 4567:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 4568:     my $subdepth = $depth + 1;
 4569:     if (ref($coursecategories) eq 'HASH') {
 4570:         foreach my $subitem (keys(%{$coursecategories})) {
 4571:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
 4572:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
 4573:                 delete($coursecategories->{$subitem});
 4574:                 $deletions->{$subitem} = 1;
 4575:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
 4576:             }  
 4577:         }
 4578:     }
 4579:     return;
 4580: }
 4581: 
 4582: 1;

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