File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.72: download - view: text, annotated - select for diffs
Mon Dec 8 22:42:43 2008 UTC (15 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 5839. DCs can set defaults for availability of User Tools (About Me, Portfolio, Blog) to users in a domain.
  - Defaults defined for different institutional affiliation.
  - Default for users with $env{'user.adv'} will override default based on affiliation.
- Storage of default portfolio quota will now be in a hash in $quotas{'defaultquota'}, instead of in top level hash in $quotas in configuration.db
  - backwards compatibility maintained.

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

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