File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.83: download - view: text, annotated - select for diffs
Fri Dec 26 21:48:43 2008 UTC (15 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Eliminate duplicate code.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.83 2008/12/26 21:48: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::lonauthcgi();
   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 affiliation',
  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 class="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 => "Login box",
  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) eq 'HASH') {
 1250:                 if (ref($settings->{defaultquota}) eq 'HASH') {
 1251:                     $currdefquota = $settings->{defaultquota}->{$type}; 
 1252:                 } else {
 1253:                     $currdefquota = $settings->{$type};
 1254:                 }
 1255:             }
 1256:             if (defined($usertypes->{$type})) {
 1257:                 $typecount ++;
 1258:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
 1259:                 $datatable .= '<tr'.$css_class.'>'.
 1260:                               '<td>'.$usertypes->{$type}.'</td>'.
 1261:                               '<td class="LC_left_item">';
 1262:                 foreach my $item (@usertools) {
 1263:                     my $checked = 'checked="checked" ';
 1264:                     if (ref($settings) eq 'HASH') {
 1265:                         if (ref($settings->{$item}) eq 'HASH') {
 1266:                             if ($settings->{$item}->{$type} == 0) {
 1267:                                 $checked = '';
 1268:                             }
 1269:                         }
 1270:                     }
 1271:                     $datatable .= '<span class="LC_nobreak"><label>'.
 1272:                                   '<input type="checkbox" name="tools_'.$item.
 1273:                                   '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
 1274:                                   '</label></span>&nbsp; ';
 1275:                 }
 1276:                 $datatable .= '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 1277:                               '<input type="text" name="quota_'.$type.
 1278:                               '" value="'.$currdefquota.
 1279:                               '" size="5" /> Mb</span></td></tr>';
 1280:             }
 1281:         }
 1282:     }
 1283:     my $defaultquota = '20';
 1284:     if (ref($settings) eq 'HASH') {
 1285:         if (ref($settings->{'defaultquota'}) eq 'HASH') {
 1286:             $defaultquota = $settings->{'defaultquota'}->{'default'};
 1287:         } elsif (defined($settings->{'default'})) {
 1288:             $defaultquota = $settings->{'default'};
 1289:         }
 1290:     }
 1291:     $typecount ++;
 1292:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1293:     $datatable .= '<tr'.$css_class.'>'.
 1294:                   '<td>'.$othertitle.'</td>'.
 1295:                   '<td class="LC_left_item">';
 1296:     foreach my $item (@usertools) {
 1297:         my $checked = 'checked="checked" ';
 1298:         if (ref($settings) eq 'HASH') {
 1299:             if (ref($settings->{$item}) eq 'HASH') {
 1300:                 if ($settings->{$item}->{'default'} == 0) {
 1301:                     $checked = '';
 1302:                 }
 1303:             }
 1304:         }
 1305:         $datatable .= '<span class="LC_nobreak"><label>'.
 1306:                       '<input type="checkbox" name="tools_'.$item.
 1307:                       '" value="default" '.$checked.'/>'.$titles{$item}.
 1308:                       '</label></span>&nbsp; ';
 1309:     }
 1310:     $datatable .= '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 1311:                   '<input type="text" name="defaultquota" value="'.
 1312:                   $defaultquota.'" size="5" /> Mb</span></td></tr>';
 1313:     $typecount ++;
 1314:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1315:     $datatable .= '<tr'.$css_class.'>'.
 1316:                   '<td><br/>'.&mt('LON-CAPA Advanced Users').'</td>'.
 1317:                   '<td class="LC_left_item" colspan="2"><br />';
 1318:     foreach my $item (@usertools) {
 1319:         my $checked = 'checked="checked" ';
 1320:         if (ref($settings) eq 'HASH') {
 1321:             if (ref($settings->{$item}) eq 'HASH') {
 1322:                 if ($settings->{$item}->{'_LC_adv'} == 0) {
 1323:                     $checked = '';
 1324:                 }
 1325:             }
 1326:         }
 1327:         $datatable .= '<span class="LC_nobreak"><label>'.
 1328:                       '<input type="checkbox" name="tools_'.$item.
 1329:                       '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
 1330:                       '</label></span>&nbsp; ';
 1331:     }
 1332:     $datatable .= '<span class="LC_nobreak">('.&mt('overrides affiliation').
 1333:                   ')</span</td></tr>';
 1334:     $$rowtotal += $typecount;
 1335:     return $datatable;
 1336: }
 1337: 
 1338: sub print_autoenroll {
 1339:     my ($dom,$settings,$rowtotal) = @_;
 1340:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 1341:     my ($defdom,$runon,$runoff);
 1342:     if (ref($settings) eq 'HASH') {
 1343:         if (exists($settings->{'run'})) {
 1344:             if ($settings->{'run'} eq '0') {
 1345:                 $runoff = ' checked="checked" ';
 1346:                 $runon = ' ';
 1347:             } else {
 1348:                 $runon = ' checked="checked" ';
 1349:                 $runoff = ' ';
 1350:             }
 1351:         } else {
 1352:             if ($autorun) {
 1353:                 $runon = ' checked="checked" ';
 1354:                 $runoff = ' ';
 1355:             } else {
 1356:                 $runoff = ' checked="checked" ';
 1357:                 $runon = ' ';
 1358:             }
 1359:         }
 1360:         if (exists($settings->{'sender_domain'})) {
 1361:             $defdom = $settings->{'sender_domain'};
 1362:         }
 1363:     } else {
 1364:         if ($autorun) {
 1365:             $runon = ' checked="checked" ';
 1366:             $runoff = ' ';
 1367:         } else {
 1368:             $runoff = ' checked="checked" ';
 1369:             $runon = ' ';
 1370:         }
 1371:     }
 1372:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
 1373:     my $notif_sender;
 1374:     if (ref($settings) eq 'HASH') {
 1375:         $notif_sender = $settings->{'sender_uname'};
 1376:     }
 1377:     my $datatable='<tr class="LC_odd_row">'.
 1378:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
 1379:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1380:                   '<input type="radio" name="autoenroll_run"'.
 1381:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1382:                   '<label><input type="radio" name="autoenroll_run"'.
 1383:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1384:                   '</tr><tr>'.
 1385:                   '<td>'.&mt('Notification messages - sender').
 1386:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 1387:                   &mt('username').':&nbsp;'.
 1388:                   '<input type="text" name="sender_uname" value="'.
 1389:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
 1390:                   ':&nbsp;'.$domform.'</span></td></tr>';
 1391:     $$rowtotal += 2;
 1392:     return $datatable;
 1393: }
 1394: 
 1395: sub print_autoupdate {
 1396:     my ($position,$dom,$settings,$rowtotal) = @_;
 1397:     my $datatable;
 1398:     if ($position eq 'top') {
 1399:         my $updateon = ' ';
 1400:         my $updateoff = ' checked="checked" ';
 1401:         my $classlistson = ' ';
 1402:         my $classlistsoff = ' checked="checked" ';
 1403:         if (ref($settings) eq 'HASH') {
 1404:             if ($settings->{'run'} eq '1') {
 1405:                 $updateon = $updateoff;
 1406:                 $updateoff = ' ';
 1407:             }
 1408:             if ($settings->{'classlists'} eq '1') {
 1409:                 $classlistson = $classlistsoff;
 1410:                 $classlistsoff = ' ';
 1411:             }
 1412:         }
 1413:         my %title = (
 1414:                    run => 'Auto-update active?',
 1415:                    classlists => 'Update information in classlists?',
 1416:                     );
 1417:         $datatable = '<tr class="LC_odd_row">'. 
 1418:                   '<td>'.&mt($title{'run'}).'</td>'.
 1419:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1420:                   '<input type="radio" name="autoupdate_run"'.
 1421:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1422:                   '<label><input type="radio" name="autoupdate_run"'.
 1423:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
 1424:                   '</tr><tr>'.
 1425:                   '<td>'.&mt($title{'classlists'}).'</td>'.
 1426:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 1427:                   '<label><input type="radio" name="classlists"'.
 1428:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1429:                   '<label><input type="radio" name="classlists"'.
 1430:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
 1431:                   '</tr>';
 1432:         $$rowtotal += 2;
 1433:     } else {
 1434:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1435:         my @fields = ('lastname','firstname','middlename','gen',
 1436:                       'permanentemail','id');
 1437:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 1438:         my $numrows = 0;
 1439:         if (ref($types) eq 'ARRAY') {
 1440:             if (@{$types} > 0) {
 1441:                 $datatable = 
 1442:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
 1443:                                          \@fields,$types,\$numrows);
 1444:                     $$rowtotal += @{$types}; 
 1445:             }
 1446:         }
 1447:         $datatable .= 
 1448:             &usertype_update_row($settings,{'default' => $othertitle},
 1449:                                  \%fieldtitles,\@fields,['default'],
 1450:                                  \$numrows);
 1451:         $$rowtotal ++;     
 1452:     }
 1453:     return $datatable;
 1454: }
 1455: 
 1456: sub print_directorysrch {
 1457:     my ($dom,$settings,$rowtotal) = @_;
 1458:     my $srchon = ' ';
 1459:     my $srchoff = ' checked="checked" ';
 1460:     my ($exacton,$containson,$beginson);
 1461:     my $localon = ' ';
 1462:     my $localoff = ' checked="checked" ';
 1463:     if (ref($settings) eq 'HASH') {
 1464:         if ($settings->{'available'} eq '1') {
 1465:             $srchon = $srchoff;
 1466:             $srchoff = ' ';
 1467:         }
 1468:         if ($settings->{'localonly'} eq '1') {
 1469:             $localon = $localoff;
 1470:             $localoff = ' ';
 1471:         }
 1472:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
 1473:             foreach my $type (@{$settings->{'searchtypes'}}) {
 1474:                 if ($type eq 'exact') {
 1475:                     $exacton = ' checked="checked" ';
 1476:                 } elsif ($type eq 'contains') {
 1477:                     $containson = ' checked="checked" ';
 1478:                 } elsif ($type eq 'begins') {
 1479:                     $beginson = ' checked="checked" ';
 1480:                 }
 1481:             }
 1482:         } else {
 1483:             if ($settings->{'searchtypes'} eq 'exact') {
 1484:                 $exacton = ' checked="checked" ';
 1485:             } elsif ($settings->{'searchtypes'} eq 'contains') {
 1486:                 $containson = ' checked="checked" ';
 1487:             } elsif ($settings->{'searchtypes'} eq 'specify') {
 1488:                 $exacton = ' checked="checked" ';
 1489:                 $containson = ' checked="checked" ';
 1490:             }
 1491:         }
 1492:     }
 1493:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
 1494:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1495: 
 1496:     my $numinrow = 4;
 1497:     my $cansrchrow = 0;
 1498:     my $datatable='<tr class="LC_odd_row">'.
 1499:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
 1500:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1501:                   '<input type="radio" name="dirsrch_available"'.
 1502:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1503:                   '<label><input type="radio" name="dirsrch_available"'.
 1504:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1505:                   '</tr><tr>'.
 1506:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
 1507:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1508:                   '<input type="radio" name="dirsrch_localonly"'.
 1509:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
 1510:                   '<label><input type="radio" name="dirsrch_localonly"'.
 1511:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
 1512:                   '</tr>';
 1513:     $$rowtotal += 2;
 1514:     if (ref($usertypes) eq 'HASH') {
 1515:         if (keys(%{$usertypes}) > 0) {
 1516:             $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
 1517:                                                $numinrow,$othertitle);
 1518:             $cansrchrow = 1;
 1519:         }
 1520:     }
 1521:     if ($cansrchrow) {
 1522:         $$rowtotal ++;
 1523:         $datatable .= '<tr>';
 1524:     } else {
 1525:         $datatable .= '<tr class="LC_odd_row">';
 1526:     }
 1527:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
 1528:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
 1529:     foreach my $title (@{$titleorder}) {
 1530:         if (defined($searchtitles->{$title})) {
 1531:             my $check = ' ';
 1532:             if (ref($settings) eq 'HASH') { 
 1533:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
 1534:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
 1535:                         $check = ' checked="checked" ';
 1536:                     }
 1537:                 }
 1538:             }
 1539:             $datatable .= '<td class="LC_left_item">'.
 1540:                           '<span class="LC_nobreak"><label>'.
 1541:                           '<input type="checkbox" name="searchby" '.
 1542:                           'value="'.$title.'"'.$check.'/>'.
 1543:                           $searchtitles->{$title}.'</label></span></td>';
 1544:         }
 1545:     }
 1546:     $datatable .= '</tr></table></td></tr>';
 1547:     $$rowtotal ++;
 1548:     if ($cansrchrow) {
 1549:         $datatable .= '<tr class="LC_odd_row">';
 1550:     } else {
 1551:         $datatable .= '<tr>';
 1552:     }
 1553:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
 1554:                   '<td class="LC_left_item" colspan="2">'.
 1555:                   '<span class="LC_nobreak"><label>'.
 1556:                   '<input type="checkbox" name="searchtypes" '.
 1557:                   $exacton.' value="exact" />'.&mt('Exact match').
 1558:                   '</label>&nbsp;'.
 1559:                   '<label><input type="checkbox" name="searchtypes" '.
 1560:                   $beginson.' value="begins" />'.&mt('Begins with').
 1561:                   '</label>&nbsp;'.
 1562:                   '<label><input type="checkbox" name="searchtypes" '.
 1563:                   $containson.' value="contains" />'.&mt('Contains').
 1564:                   '</label></span></td></tr>';
 1565:     $$rowtotal ++;
 1566:     return $datatable;
 1567: }
 1568: 
 1569: sub print_contacts {
 1570:     my ($dom,$settings,$rowtotal) = @_;
 1571:     my $datatable;
 1572:     my @contacts = ('adminemail','supportemail');
 1573:     my (%checked,%to,%otheremails);
 1574:     my @mailings = ('errormail','packagesmail','helpdeskmail');
 1575:     foreach my $type (@mailings) {
 1576:         $otheremails{$type} = '';
 1577:     }
 1578:     if (ref($settings) eq 'HASH') {
 1579:         foreach my $item (@contacts) {
 1580:             if (exists($settings->{$item})) {
 1581:                 $to{$item} = $settings->{$item};
 1582:             }
 1583:         }
 1584:         foreach my $type (@mailings) {
 1585:             if (exists($settings->{$type})) {
 1586:                 if (ref($settings->{$type}) eq 'HASH') {
 1587:                     foreach my $item (@contacts) {
 1588:                         if ($settings->{$type}{$item}) {
 1589:                             $checked{$type}{$item} = ' checked="checked" ';
 1590:                         }
 1591:                     }
 1592:                     $otheremails{$type} = $settings->{$type}{'others'};
 1593:                 }
 1594:             }
 1595:         }
 1596:     } else {
 1597:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 1598:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 1599:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
 1600:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
 1601:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" '; 
 1602:     }
 1603:     my ($titles,$short_titles) = &contact_titles();
 1604:     my $rownum = 0;
 1605:     my $css_class;
 1606:     foreach my $item (@contacts) {
 1607:         $rownum ++;
 1608:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 1609:         $datatable .= '<tr'.$css_class.'>'. 
 1610:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 1611:                   '</span></td><td class="LC_right_item">'.
 1612:                   '<input type="text" name="'.$item.'" value="'.
 1613:                   $to{$item}.'" /></td></tr>';
 1614:     }
 1615:     foreach my $type (@mailings) {
 1616:         $rownum ++;
 1617:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 1618:         $datatable .= '<tr'.$css_class.'>'.
 1619:                       '<td><span class="LC_nobreak">'.
 1620:                       $titles->{$type}.': </span></td>'.
 1621:                       '<td class="LC_left_item">'.
 1622:                       '<span class="LC_nobreak">';
 1623:         foreach my $item (@contacts) {
 1624:             $datatable .= '<label>'.
 1625:                           '<input type="checkbox" name="'.$type.'"'.
 1626:                           $checked{$type}{$item}.
 1627:                           ' value="'.$item.'" />'.$short_titles->{$item}.
 1628:                           '</label>&nbsp;';
 1629:         }
 1630:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
 1631:                       '<input type="text" name="'.$type.'_others" '.
 1632:                       'value="'.$otheremails{$type}.'"  />'.
 1633:                       '</td></tr>'."\n";
 1634:     }
 1635:     $$rowtotal += $rownum;
 1636:     return $datatable;
 1637: }
 1638: 
 1639: sub contact_titles {
 1640:     my %titles = &Apache::lonlocal::texthash (
 1641:                    'supportemail' => 'Support E-mail address',
 1642:                    'adminemail'   => 'Default Server Admin E-mail address',
 1643:                    'errormail'    => 'Error reports to be e-mailed to',
 1644:                    'packagesmail' => 'Package update alerts to be e-mailed to',
 1645:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
 1646:                  );
 1647:     my %short_titles = &Apache::lonlocal::texthash (
 1648:                            adminemail   => 'Admin E-mail address',
 1649:                            supportemail => 'Support E-mail',
 1650:                        );   
 1651:     return (\%titles,\%short_titles);
 1652: }
 1653: 
 1654: sub tool_titles {
 1655:     my %titles = &Apache::lonlocal::texthash (
 1656:                                               aboutme   => 'Personal Home Page',
 1657:                                               blog      => 'Blog',
 1658:                                               portfolio => 'Portfolio',
 1659:                                              );
 1660:     return %titles;
 1661: }
 1662: 
 1663: sub print_usercreation {
 1664:     my ($position,$dom,$settings,$rowtotal) = @_;
 1665:     my $numinrow = 4;
 1666:     my $datatable;
 1667:     if ($position eq 'top') {
 1668:         $$rowtotal ++;
 1669:         my $rowcount = 0;
 1670:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
 1671:         if (ref($rules) eq 'HASH') {
 1672:             if (keys(%{$rules}) > 0) {
 1673:                 $datatable .= &user_formats_row('username',$settings,$rules,
 1674:                                                 $ruleorder,$numinrow,$rowcount);
 1675:                 $$rowtotal ++;
 1676:                 $rowcount ++;
 1677:             }
 1678:         }
 1679:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
 1680:         if (ref($idrules) eq 'HASH') {
 1681:             if (keys(%{$idrules}) > 0) {
 1682:                 $datatable .= &user_formats_row('id',$settings,$idrules,
 1683:                                                 $idruleorder,$numinrow,$rowcount);
 1684:                 $$rowtotal ++;
 1685:                 $rowcount ++;
 1686:             }
 1687:         }
 1688:         my ($emailrules,$emailruleorder) = 
 1689:             &Apache::lonnet::inst_userrules($dom,'email');
 1690:         if (ref($emailrules) eq 'HASH') {
 1691:             if (keys(%{$emailrules}) > 0) {
 1692:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
 1693:                                                 $emailruleorder,$numinrow,$rowcount);
 1694:                 $$rowtotal ++;
 1695:                 $rowcount ++;
 1696:             }
 1697:         }
 1698:         if ($rowcount == 0) {
 1699:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
 1700:             $$rowtotal ++;
 1701:             $rowcount ++;
 1702:         }
 1703:     } elsif ($position eq 'middle') {
 1704:         my @creators = ('author','course','selfcreate');
 1705:         my ($rules,$ruleorder) =
 1706:             &Apache::lonnet::inst_userrules($dom,'username');
 1707:         my %lt = &usercreation_types();
 1708:         my %checked;
 1709:         my @selfcreate; 
 1710:         if (ref($settings) eq 'HASH') {
 1711:             if (ref($settings->{'cancreate'}) eq 'HASH') {
 1712:                 foreach my $item (@creators) {
 1713:                     $checked{$item} = $settings->{'cancreate'}{$item};
 1714:                 }
 1715:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
 1716:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
 1717:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
 1718:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
 1719:                         @selfcreate = ('email','login','sso');
 1720:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
 1721:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
 1722:                     }
 1723:                 }
 1724:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
 1725:                 foreach my $item (@creators) {
 1726:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
 1727:                         $checked{$item} = 'none';
 1728:                     }
 1729:                 }
 1730:             }
 1731:         }
 1732:         my $rownum = 0;
 1733:         foreach my $item (@creators) {
 1734:             $rownum ++;
 1735:             if ($item ne 'selfcreate') {  
 1736:                 if ($checked{$item} eq '') {
 1737:                     $checked{$item} = 'any';
 1738:                 }
 1739:             }
 1740:             my $css_class;
 1741:             if ($rownum%2) {
 1742:                 $css_class = '';
 1743:             } else {
 1744:                 $css_class = ' class="LC_odd_row" ';
 1745:             }
 1746:             $datatable .= '<tr'.$css_class.'>'.
 1747:                          '<td><span class="LC_nobreak">'.$lt{$item}.
 1748:                          '</span></td><td align="right">';
 1749:             my @options;
 1750:             if ($item eq 'selfcreate') {
 1751:                 push(@options,('email','login','sso'));
 1752:             } else {
 1753:                 @options = ('any');
 1754:                 if (ref($rules) eq 'HASH') {
 1755:                     if (keys(%{$rules}) > 0) {
 1756:                         push(@options,('official','unofficial'));
 1757:                     }
 1758:                 }
 1759:                 push(@options,'none');
 1760:             }
 1761:             foreach my $option (@options) {
 1762:                 my $type = 'radio';
 1763:                 my $check = ' ';
 1764:                 if ($item eq 'selfcreate') {
 1765:                     $type = 'checkbox';
 1766:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
 1767:                         $check = ' checked="checked" ';
 1768:                     }
 1769:                 } else {
 1770:                     if ($checked{$item} eq $option) {
 1771:                         $check = ' checked="checked" ';
 1772:                     }
 1773:                 } 
 1774:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1775:                               '<input type="'.$type.'" name="can_createuser_'.
 1776:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
 1777:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
 1778:             }
 1779:             $datatable .= '</td></tr>';
 1780:         }
 1781:     } else {
 1782:         my @contexts = ('author','course','domain');
 1783:         my @authtypes = ('int','krb4','krb5','loc');
 1784:         my %checked;
 1785:         if (ref($settings) eq 'HASH') {
 1786:             if (ref($settings->{'authtypes'}) eq 'HASH') {
 1787:                 foreach my $item (@contexts) {
 1788:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
 1789:                         foreach my $auth (@authtypes) {
 1790:                             if ($settings->{'authtypes'}{$item}{$auth}) {
 1791:                                 $checked{$item}{$auth} = ' checked="checked" ';
 1792:                             }
 1793:                         }
 1794:                     }
 1795:                 }
 1796:             }
 1797:         } else {
 1798:             foreach my $item (@contexts) {
 1799:                 foreach my $auth (@authtypes) {
 1800:                     $checked{$item}{$auth} = ' checked="checked" ';
 1801:                 }
 1802:             }
 1803:         }
 1804:         my %title = &context_names();
 1805:         my %authname = &authtype_names();
 1806:         my $rownum = 0;
 1807:         my $css_class; 
 1808:         foreach my $item (@contexts) {
 1809:             if ($rownum%2) {
 1810:                 $css_class = '';
 1811:             } else {
 1812:                 $css_class = ' class="LC_odd_row" ';
 1813:             }
 1814:             $datatable .=   '<tr'.$css_class.'>'.
 1815:                             '<td>'.$title{$item}.
 1816:                             '</td><td class="LC_left_item">'.
 1817:                             '<span class="LC_nobreak">';
 1818:             foreach my $auth (@authtypes) {
 1819:                 $datatable .= '<label>'. 
 1820:                               '<input type="checkbox" name="'.$item.'_auth" '.
 1821:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
 1822:                               $authname{$auth}.'</label>&nbsp;';
 1823:             }
 1824:             $datatable .= '</span></td></tr>';
 1825:             $rownum ++;
 1826:         }
 1827:         $$rowtotal += $rownum;
 1828:     }
 1829:     return $datatable;
 1830: }
 1831: 
 1832: sub user_formats_row {
 1833:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
 1834:     my $output;
 1835:     my %text = (
 1836:                    'username' => 'new usernames',
 1837:                    'id'       => 'IDs',
 1838:                    'email'    => 'self-created accounts (e-mail)',
 1839:                );
 1840:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 1841:     $output = '<tr '.$css_class.'>'.
 1842:               '<td><span class="LC_nobreak">';
 1843:     if ($type eq 'email') {
 1844:         $output .= &mt("Formats disallowed for $text{$type}: ");
 1845:     } else {
 1846:         $output .= &mt("Format rules to check for $text{$type}: ");
 1847:     }
 1848:     $output .= '</span></td>'.
 1849:                '<td class="LC_left_item" colspan="2"><table>';
 1850:     my $rem;
 1851:     if (ref($ruleorder) eq 'ARRAY') {
 1852:         for (my $i=0; $i<@{$ruleorder}; $i++) {
 1853:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
 1854:                 my $rem = $i%($numinrow);
 1855:                 if ($rem == 0) {
 1856:                     if ($i > 0) {
 1857:                         $output .= '</tr>';
 1858:                     }
 1859:                     $output .= '<tr>';
 1860:                 }
 1861:                 my $check = ' ';
 1862:                 if (ref($settings) eq 'HASH') {
 1863:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
 1864:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
 1865:                             $check = ' checked="checked" ';
 1866:                         }
 1867:                     }
 1868:                 }
 1869:                 $output .= '<td class="LC_left_item">'.
 1870:                            '<span class="LC_nobreak"><label>'.
 1871:                            '<input type="checkbox" name="'.$type.'_rule" '.
 1872:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
 1873:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
 1874:             }
 1875:         }
 1876:         $rem = @{$ruleorder}%($numinrow);
 1877:     }
 1878:     my $colsleft = $numinrow - $rem;
 1879:     if ($colsleft > 1 ) {
 1880:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 1881:                    '&nbsp;</td>';
 1882:     } elsif ($colsleft == 1) {
 1883:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 1884:     }
 1885:     $output .= '</tr></table></td></tr>';
 1886:     return $output;
 1887: }
 1888: 
 1889: sub usercreation_types {
 1890:     my %lt = &Apache::lonlocal::texthash (
 1891:                     author     => 'When adding a co-author',
 1892:                     course     => 'When adding a user to a course',
 1893:                     selfcreate => 'User creates own account', 
 1894:                     any        => 'Any',
 1895:                     official   => 'Institutional only ',
 1896:                     unofficial => 'Non-institutional only',
 1897:                     email      => 'Email address',
 1898:                     login      => 'Institutional Login',
 1899:                     sso        => 'SSO', 
 1900:                     none       => 'None',
 1901:     );
 1902:     return %lt;
 1903: }
 1904: 
 1905: sub authtype_names {
 1906:     my %lt = &Apache::lonlocal::texthash(
 1907:                       int    => 'Internal',
 1908:                       krb4   => 'Kerberos 4',
 1909:                       krb5   => 'Kerberos 5',
 1910:                       loc    => 'Local',
 1911:                   );
 1912:     return %lt;
 1913: }
 1914: 
 1915: sub context_names {
 1916:     my %context_title = &Apache::lonlocal::texthash(
 1917:        author => 'Creating users when an Author',
 1918:        course => 'Creating users when in a course',
 1919:        domain => 'Creating users when a Domain Coordinator',
 1920:     );
 1921:     return %context_title;
 1922: }
 1923: 
 1924: sub print_usermodification {
 1925:     my ($position,$dom,$settings,$rowtotal) = @_;
 1926:     my $numinrow = 4;
 1927:     my ($context,$datatable,$rowcount);
 1928:     if ($position eq 'top') {
 1929:         $rowcount = 0;
 1930:         $context = 'author'; 
 1931:         foreach my $role ('ca','aa') {
 1932:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 1933:                                                    $numinrow,$rowcount);
 1934:             $$rowtotal ++;
 1935:             $rowcount ++;
 1936:         }
 1937:     } elsif ($position eq 'middle') {
 1938:         $context = 'course';
 1939:         $rowcount = 0;
 1940:         foreach my $role ('st','ep','ta','in','cr') {
 1941:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 1942:                                                    $numinrow,$rowcount);
 1943:             $$rowtotal ++;
 1944:             $rowcount ++;
 1945:         }
 1946:     } elsif ($position eq 'bottom') {
 1947:         $context = 'selfcreate';
 1948:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1949:         $usertypes->{'default'} = $othertitle;
 1950:         if (ref($types) eq 'ARRAY') {
 1951:             push(@{$types},'default');
 1952:             $usertypes->{'default'} = $othertitle;
 1953:             foreach my $status (@{$types}) {
 1954:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
 1955:                                                        $numinrow,$rowcount,$usertypes);
 1956:                 $$rowtotal ++;
 1957:                 $rowcount ++;
 1958:             }
 1959:         }
 1960:     }
 1961:     return $datatable;
 1962: }
 1963: 
 1964: sub print_defaults {
 1965:     my ($dom,$rowtotal) = @_;
 1966:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
 1967:                  'datelocale_def');
 1968:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 1969:     my $titles = &defaults_titles();
 1970:     my $rownum = 0;
 1971:     my ($datatable,$css_class);
 1972:     foreach my $item (@items) {
 1973:         if ($rownum%2) {
 1974:             $css_class = '';
 1975:         } else {
 1976:             $css_class = ' class="LC_odd_row" ';
 1977:         }
 1978:         $datatable .= '<tr'.$css_class.'>'.
 1979:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 1980:                   '</span></td><td class="LC_right_item">';
 1981:         if ($item eq 'auth_def') {
 1982:             my @authtypes = ('internal','krb4','krb5','localauth');
 1983:             my %shortauth = (
 1984:                              internal => 'int',
 1985:                              krb4 => 'krb4',
 1986:                              krb5 => 'krb5',
 1987:                              localauth  => 'loc'
 1988:                            );
 1989:             my %authnames = &authtype_names();
 1990:             foreach my $auth (@authtypes) {
 1991:                 my $checked = ' ';
 1992:                 if ($domdefaults{$item} eq $auth) {
 1993:                     $checked = ' checked="checked" ';
 1994:                 }
 1995:                 $datatable .= '<label><input type="radio" name="'.$item.
 1996:                               '" value="'.$auth.'"'.$checked.'/>'.
 1997:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
 1998:             }
 1999:         } elsif ($item eq 'timezone_def') {
 2000:             my $includeempty = 1;
 2001:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
 2002:         } elsif ($item eq 'datelocale_def') {
 2003:             my $includeempty = 1;
 2004:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
 2005:         } else {
 2006:             $datatable .= '<input type="text" name="'.$item.'" value="'.
 2007:                           $domdefaults{$item}.'" />';
 2008:         }
 2009:         $datatable .= '</td></tr>';
 2010:         $rownum ++;
 2011:     }
 2012:     $$rowtotal += $rownum;
 2013:     return $datatable;
 2014: }
 2015: 
 2016: sub defaults_titles {
 2017:     my %titles = &Apache::lonlocal::texthash (
 2018:                    'auth_def'      => 'Default authentication type',
 2019:                    'auth_arg_def'  => 'Default authentication argument',
 2020:                    'lang_def'      => 'Default language',
 2021:                    'timezone_def'  => 'Default timezone',
 2022:                    'datelocale_def' => 'Default locale for dates',
 2023:                  );
 2024:     return (\%titles);
 2025: }
 2026: 
 2027: sub print_scantronformat {
 2028:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
 2029:     my $itemcount = 1;
 2030:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
 2031:         %confhash);
 2032:     my $switchserver = &check_switchserver($dom,$confname);
 2033:     my %lt = &Apache::lonlocal::texthash (
 2034:                 default => 'Default scantron format file error',
 2035:                 custom  => 'Custom scantron format file error',
 2036:              );
 2037:     my %scantronfiles = (
 2038:         default => 'default.tab',
 2039:         custom => 'custom.tab',
 2040:     );
 2041:     foreach my $key (keys(%scantronfiles)) {
 2042:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
 2043:                               .$scantronfiles{$key};
 2044:     }
 2045:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
 2046:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
 2047:         if (!$switchserver) {
 2048:             my $servadm = $r->dir_config('lonAdmEMail');
 2049:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
 2050:             if ($configuserok eq 'ok') {
 2051:                 if ($author_ok eq 'ok') {
 2052:                     my %legacyfile = (
 2053:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
 2054:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
 2055:                     );
 2056:                     my %md5chk;
 2057:                     foreach my $type (keys(%legacyfile)) {
 2058:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
 2059:                         chomp($md5chk{$type});
 2060:                     }
 2061:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
 2062:                         foreach my $type (keys(%legacyfile)) {
 2063:                             ($scantronurls{$type},my $error) = 
 2064:                                 &legacy_scantronformat($r,$dom,$confname,
 2065:                                                  $type,$legacyfile{$type},
 2066:                                                  $scantronurls{$type},
 2067:                                                  $scantronfiles{$type});
 2068:                             if ($error ne '') {
 2069:                                 $error{$type} = $error;
 2070:                             }
 2071:                         }
 2072:                         if (keys(%error) == 0) {
 2073:                             $is_custom = 1;
 2074:                             $confhash{'scantron'}{'scantronformat'} = 
 2075:                                 $scantronurls{'custom'};
 2076:                             my $putresult = 
 2077:                                 &Apache::lonnet::put_dom('configuration',
 2078:                                                          \%confhash,$dom);
 2079:                             if ($putresult ne 'ok') {
 2080:                                 $error{'custom'} = 
 2081:                                     '<span class="LC_error">'.
 2082:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 2083:                             }
 2084:                         }
 2085:                     } else {
 2086:                         ($scantronurls{'default'},my $error) =
 2087:                             &legacy_scantronformat($r,$dom,$confname,
 2088:                                           'default',$legacyfile{'default'},
 2089:                                           $scantronurls{'default'},
 2090:                                           $scantronfiles{'default'});
 2091:                         if ($error eq '') {
 2092:                             $confhash{'scantron'}{'scantronformat'} = ''; 
 2093:                             my $putresult =
 2094:                                 &Apache::lonnet::put_dom('configuration',
 2095:                                                          \%confhash,$dom);
 2096:                             if ($putresult ne 'ok') {
 2097:                                 $error{'default'} =
 2098:                                     '<span class="LC_error">'.
 2099:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 2100:                             }
 2101:                         } else {
 2102:                             $error{'default'} = $error;
 2103:                         }
 2104:                     }
 2105:                 }
 2106:             }
 2107:         } else {
 2108:             $error{'default'} = &mt("Unable to copy default scantron formatfile to domain's RES space: [_1]",$switchserver);
 2109:         }
 2110:     }
 2111:     if (ref($settings) eq 'HASH') {
 2112:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
 2113:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
 2114:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
 2115:                 $scantronurl = '';
 2116:             } else {
 2117:                 $scantronurl = $settings->{'scantronformat'};
 2118:             }
 2119:             $is_custom = 1;
 2120:         } else {
 2121:             $scantronurl = $scantronurls{'default'};
 2122:         }
 2123:     } else {
 2124:         if ($is_custom) {
 2125:             $scantronurl = $scantronurls{'custom'};
 2126:         } else {
 2127:             $scantronurl = $scantronurls{'default'};
 2128:         }
 2129:     }
 2130:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2131:     $datatable .= '<tr'.$css_class.'>';
 2132:     if (!$is_custom) {
 2133:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
 2134:                       '<span class="LC_nobreak">';
 2135:         if ($scantronurl) {
 2136:             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
 2137:                           &mt('Default scantron format file').'</a>';
 2138:         } else {
 2139:             $datatable = &mt('File unavailable for display');
 2140:         }
 2141:         $datatable .= '</span></td>';
 2142:         if (keys(%error) == 0) { 
 2143:             $datatable .= '<td valign="bottom">';
 2144:             if (!$switchserver) {
 2145:                 $datatable .= &mt('Upload:').'<br />';
 2146:             }
 2147:         } else {
 2148:             my $errorstr;
 2149:             foreach my $key (sort(keys(%error))) {
 2150:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 2151:             }
 2152:             $datatable .= '<td>'.$errorstr;
 2153:         }
 2154:     } else {
 2155:         if (keys(%error) > 0) {
 2156:             my $errorstr;
 2157:             foreach my $key (sort(keys(%error))) {
 2158:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 2159:             } 
 2160:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
 2161:         } elsif ($scantronurl) {
 2162:             $datatable .= '<td><span class="LC_nobreak">'.
 2163:                           '<a href="'.$scantronurl.'" target="_blank">'.
 2164:                           &mt('Custom scantron format file').'</a><label>'.
 2165:                           '<input type="checkbox" name="scantronformat_del"'.
 2166:                           '" value="1" />'.&mt('Delete?').'</label></span></td>'.
 2167:                           '<td><span class="LC_nobreak">&nbsp;'.
 2168:                           &mt('Replace:').'</span><br />';
 2169:         }
 2170:     }
 2171:     if (keys(%error) == 0) {
 2172:         if ($switchserver) {
 2173:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 2174:         } else {
 2175:             $datatable .='<span class="LC_nobreak">&nbsp;'.
 2176:                          '<input type="file" name="scantronformat" /></span>';
 2177:         }
 2178:     }
 2179:     $datatable .= '</td></tr>';
 2180:     $$rowtotal ++;
 2181:     return $datatable;
 2182: }
 2183: 
 2184: sub legacy_scantronformat {
 2185:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
 2186:     my ($url,$error);
 2187:     my @statinfo = &Apache::lonnet::stat_file($newurl);
 2188:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
 2189:         (my $result,$url) =
 2190:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
 2191:                          '','',$newfile);
 2192:         if ($result ne 'ok') {
 2193:             $error = &mt("An error occurred publishing the [_1] scantron format file in RES space. Error was: [_2].",$newfile,$result);
 2194:         }
 2195:     }
 2196:     return ($url,$error);
 2197: }
 2198: 
 2199: sub print_coursecategories {
 2200:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
 2201:     my $datatable;
 2202:     if ($position eq 'top') {
 2203:         my $toggle_cats_crs = ' ';
 2204:         my $toggle_cats_dom = ' checked="checked" ';
 2205:         my $can_cat_crs = ' ';
 2206:         my $can_cat_dom = ' checked="checked" ';
 2207:         if (ref($settings) eq 'HASH') {
 2208:             if ($settings->{'togglecats'} eq 'crs') {
 2209:                 $toggle_cats_crs = $toggle_cats_dom;
 2210:                 $toggle_cats_dom = ' ';
 2211:             }
 2212:             if ($settings->{'categorize'} eq 'crs') {
 2213:                 $can_cat_crs = $can_cat_dom;
 2214:                 $can_cat_dom = ' ';
 2215:             }
 2216:         }
 2217:         my %title = &Apache::lonlocal::texthash (
 2218:                      togglecats => 'Show/Hide a course in the catalog',
 2219:                      categorize    => 'Assign a category to a course',
 2220:                     );
 2221:         my %level = &Apache::lonlocal::texthash (
 2222:                      dom => 'Set in "Modify Course" (Domain)',
 2223:                      crs => 'Set in "Modify Parameters" (Course)',   
 2224:                     );
 2225:         $datatable = '<tr class="LC_odd_row">'.
 2226:                   '<td>'.$title{'togglecats'}.'</td>'.
 2227:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 2228:                   '<input type="radio" name="togglecats"'.
 2229:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 2230:                   '<label><input type="radio" name="togglecats"'.
 2231:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
 2232:                   '</tr><tr>'.
 2233:                   '<td>'.$title{'categorize'}.'</td>'.
 2234:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 2235:                   '<label><input type="radio" name="categorize"'.
 2236:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 2237:                   '<label><input type="radio" name="categorize"'.
 2238:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
 2239:                   '</tr>';
 2240:         $$rowtotal += 2;
 2241:     } else {
 2242:         my $css_class;
 2243:         my $itemcount = 1;
 2244:         my $cathash; 
 2245:         if (ref($settings) eq 'HASH') {
 2246:             $cathash = $settings->{'cats'};
 2247:         }
 2248:         if (ref($cathash) eq 'HASH') {
 2249:             my (@cats,@trails,%allitems,%idx,@jsarray);
 2250:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
 2251:                                                    \%allitems,\%idx,\@jsarray);
 2252:             my $maxdepth = scalar(@cats);
 2253:             my $colattrib = '';
 2254:             if ($maxdepth > 2) {
 2255:                 $colattrib = ' colspan="2" ';
 2256:             }
 2257:             my @path;
 2258:             if (@cats > 0) {
 2259:                 if (ref($cats[0]) eq 'ARRAY') {
 2260:                     my $numtop = @{$cats[0]};
 2261:                     my $maxnum = $numtop;
 2262:                     if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
 2263:                         $maxnum ++;
 2264:                     }
 2265:                     my $lastidx;
 2266:                     for (my $i=0; $i<$numtop; $i++) {
 2267:                         my $parent = $cats[0][$i];
 2268:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2269:                         my $item = &escape($parent).'::0';
 2270:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
 2271:                         $lastidx = $idx{$item};
 2272:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 2273:                                       .'<select name="'.$item.'"'.$chgstr.'>';
 2274:                         for (my $k=0; $k<=$maxnum; $k++) {
 2275:                             my $vpos = $k+1;
 2276:                             my $selstr;
 2277:                             if ($k == $i) {
 2278:                                 $selstr = ' selected="selected" ';
 2279:                             }
 2280:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 2281:                         }
 2282:                         $datatable .= '</select></td><td>';
 2283:                         if ($parent eq 'instcode') {
 2284:                             $datatable .=  '<span class="LC_nobreak">'.&mt('Official courses')
 2285:                                            .'</span><br /><span class="LC_nobreak">('
 2286:                                            .&mt('with institutional codes').')</span></td>'
 2287:                                            .'<td'.$colattrib.'><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" checked="checked" />'
 2288:                                             .&mt('Display').'</label>&nbsp;'
 2289:                                             .'<label><input type="radio" name="instcode" value="0" />'
 2290:                                             .&mt('Do not display').'</label></span></td>';
 2291:                         } else {
 2292:                             $datatable .= $parent
 2293:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
 2294:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
 2295:                         }
 2296:                         my $depth = 1;
 2297:                         push(@path,$parent);
 2298:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
 2299:                         pop(@path);
 2300:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
 2301:                         $itemcount ++;
 2302:                     }
 2303:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2304:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
 2305:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
 2306:                     for (my $k=0; $k<=$maxnum; $k++) {
 2307:                         my $vpos = $k+1;
 2308:                         my $selstr;
 2309:                         if ($k == $numtop) {
 2310:                             $selstr = ' selected="selected" ';
 2311:                         }
 2312:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 2313:                     }
 2314:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
 2315:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
 2316:                                   .'</tr>'."\n";
 2317:                     $itemcount ++;
 2318:                     if ((!grep(/^instcode$/,@{$cats[0]})) || ($cathash->{'instcode::0'} eq '')) {
 2319:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2320:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','$lastidx'".');"';
 2321:                         $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
 2322:                                       '<span class="LC_nobreak"><select name="instcode_pos"'.$chgstr.'>';
 2323:                         for (my $k=0; $k<=$maxnum; $k++) {
 2324:                             my $vpos = $k+1;
 2325:                             my $selstr;
 2326:                             if ($k == $maxnum) {
 2327:                                 $selstr = ' selected="selected" ';
 2328:                             }
 2329:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 2330:                         }
 2331:                         $datatable .= '</select></span></td><td><span class="LC_nobreak">'
 2332:                                       .&mt('Official courses').'</span>'.'<br /><span class="LC_nobreak">('
 2333:                                       .&mt('with institutional codes').')</span></td>'
 2334:                                       .'<td><span class="LC_nobreak"><label><input type="radio" name="instcode" value="1" />'
 2335:                                       .&mt('Display').'</label>&nbsp;'
 2336:                                       .'<label><input type="radio" name="instcode" value="0" checked="checked"/>'
 2337:                                       .&mt('Do not display').'</label></span></td></tr>';
 2338:                     }
 2339:                 }
 2340:             } else {
 2341:                 $datatable .= &initialize_categories($itemcount);
 2342:             }
 2343:         } else {
 2344:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
 2345:                           .&initialize_categories($itemcount);
 2346:         }
 2347:         $$rowtotal += $itemcount;
 2348:     }
 2349:     return $datatable;
 2350: }
 2351: 
 2352: sub print_serverstatuses {
 2353:     my ($dom,$settings,$rowtotal) = @_;
 2354:     my $datatable;
 2355:     my @pages = &serverstatus_pages();
 2356:     my (%namedaccess,%machineaccess);
 2357:     foreach my $type (@pages) {
 2358:         $namedaccess{$type} = '';
 2359:         $machineaccess{$type}= '';
 2360:     }
 2361:     if (ref($settings) eq 'HASH') {
 2362:         foreach my $type (@pages) {
 2363:             if (exists($settings->{$type})) {
 2364:                 if (ref($settings->{$type}) eq 'HASH') {
 2365:                     foreach my $key (keys(%{$settings->{$type}})) {
 2366:                         if ($key eq 'namedusers') {
 2367:                             $namedaccess{$type} = $settings->{$type}->{$key};
 2368:                         } elsif ($key eq 'machines') {
 2369:                             $machineaccess{$type} = $settings->{$type}->{$key};
 2370:                         }
 2371:                     }
 2372:                 }
 2373:             }
 2374:         }
 2375:     }
 2376:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 2377:     my $rownum = 0;
 2378:     my $css_class;
 2379:     foreach my $type (@pages) {
 2380:         $rownum ++;
 2381:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2382:         $datatable .= '<tr'.$css_class.'>'.
 2383:                       '<td><span class="LC_nobreak">'.
 2384:                       $titles->{$type}.'</span></td>'.
 2385:                       '<td class="LC_left_item">'.
 2386:                       '<input type="text" name="'.$type.'_namedusers" '.
 2387:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
 2388:                       '<td class="LC_right_item">'.
 2389:                       '<span class="LC_nobreak">'.
 2390:                       '<input type="text" name="'.$type.'_machines" '.
 2391:                       'value="'.$machineaccess{$type}.'" size="10" />'.
 2392:                       '</td></tr>'."\n";
 2393:     }
 2394:     $$rowtotal += $rownum;
 2395:     return $datatable;
 2396: }
 2397: 
 2398: sub serverstatus_pages {
 2399:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
 2400:             'clusterstatus','metadata_keywords','metadata_harvest',
 2401:             'takeoffline','takeonline','showenv');
 2402: }
 2403: 
 2404: sub coursecategories_javascript {
 2405:     my ($settings) = @_;
 2406:     my ($output,$jstext,$cathash);
 2407:     if (ref($settings) eq 'HASH') {
 2408:         $cathash = $settings->{'cats'};
 2409:     }
 2410:     if (ref($cathash) eq 'HASH') {
 2411:         my (@cats,@jsarray,%idx);
 2412:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
 2413:         if (@jsarray > 0) {
 2414:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
 2415:             for (my $i=0; $i<@jsarray; $i++) {
 2416:                 if (ref($jsarray[$i]) eq 'ARRAY') {
 2417:                     my $catstr = join('","',@{$jsarray[$i]});
 2418:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
 2419:                 }
 2420:             }
 2421:         }
 2422:     } else {
 2423:         $jstext  = '    var categories = Array(1);'."\n".
 2424:                    '    categories[0] = Array("instcode_pos");'."\n"; 
 2425:     }
 2426:     $output = <<"ENDSCRIPT";
 2427: <script type="text/javascript">
 2428: function reorderCats(form,parent,item,idx) {
 2429:     var changedVal;
 2430: $jstext
 2431:     var newpos = 'addcategory_pos';
 2432:     var current = new Array;
 2433:     if (parent == '') {
 2434:         var has_instcode = 0;
 2435:         var maxtop = categories[idx].length;
 2436:         for (var j=0; j<maxtop; j++) {
 2437:             if (categories[idx][j] == 'instcode::0') {
 2438:                 has_instcode == 1;
 2439:             }
 2440:         }
 2441:         if (has_instcode == 0) {
 2442:             categories[idx][maxtop] = 'instcode_pos';
 2443:         }
 2444:     } else {
 2445:         newpos += '_'+parent;
 2446:     }
 2447:     var maxh = 1 + categories[idx].length;
 2448:     var current = new Array;
 2449:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 2450:     if (item == newpos) {
 2451:         changedVal = newitemVal;
 2452:     } else {
 2453:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
 2454:         current[newitemVal] = newpos;
 2455:     }
 2456:     for (var i=0; i<categories[idx].length; i++) {
 2457:         var elementName = categories[idx][i];
 2458:         if (elementName != item) {
 2459:             if (form.elements[elementName]) {
 2460:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 2461:                 current[currVal] = elementName;
 2462:             }
 2463:         }
 2464:     }
 2465:     var oldVal;
 2466:     for (var j=0; j<maxh; j++) {
 2467:         if (current[j] == undefined) {
 2468:             oldVal = j;
 2469:         }
 2470:     }
 2471:     if (oldVal < changedVal) {
 2472:         for (var k=oldVal+1; k<=changedVal ; k++) {
 2473:            var elementName = current[k];
 2474:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 2475:         }
 2476:     } else {
 2477:         for (var k=changedVal; k<oldVal; k++) {
 2478:             var elementName = current[k];
 2479:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 2480:         }
 2481:     }
 2482:     return;
 2483: }
 2484: </script>
 2485: 
 2486: ENDSCRIPT
 2487:     return $output;
 2488: }
 2489: 
 2490: sub initialize_categories {
 2491:     my ($itemcount) = @_;
 2492:     my $datatable;
 2493:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2494:     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','instcode_pos','0'".');"';
 2495: 
 2496:     $datatable = '<tr '.$css_class.'><td><span class="LC_nobreak">'
 2497:                  .'<select name="instcode_pos"><option value="0" selected="selected">1</option>'
 2498:                  .'<option value="1">2</option></select>&nbsp;'
 2499:                  .&mt('Official courses (with institutional codes)')
 2500:                  .'</span></td><td><span class="LC_nobreak">'
 2501:                  .'<label><input type="radio" name="instcode" value="1" checked="checked" />'
 2502:                  .&mt('Display').'</label>&nbsp;<label>'
 2503:                  .'<input type="radio" name="instcode" value="0" />'.&mt('Do not display')
 2504:                  .'</label></span></td></tr>';
 2505:     $itemcount ++;
 2506:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2507:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
 2508:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 2509:                   .'<select name="addcategory_pos"'.$chgstr.'><option value="0">1</option>'
 2510:                   .'<option value="1" selected="selected">2</option></select>&nbsp;'
 2511:                   .&mt('Add category').'</td><td>'.&mt('Name:')
 2512:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
 2513:     return $datatable;
 2514: }
 2515: 
 2516: sub build_category_rows {
 2517:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
 2518:     my ($text,$name,$item,$chgstr);
 2519:     if (ref($cats) eq 'ARRAY') {
 2520:         my $maxdepth = scalar(@{$cats});
 2521:         if (ref($cats->[$depth]) eq 'HASH') {
 2522:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
 2523:                 my $numchildren = @{$cats->[$depth]{$parent}};
 2524:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2525:                 $text .= '<td><table class="LC_datatable">';
 2526:                 my ($idxnum,$parent_name,$parent_item);
 2527:                 my $higher = $depth - 1;
 2528:                 if ($higher == 0) {
 2529:                     $parent_name = &escape($parent).'::'.$higher;
 2530:                 } else {
 2531:                     if (ref($path) eq 'ARRAY') {
 2532:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 2533:                     }
 2534:                 }
 2535:                 $parent_item = 'addcategory_pos_'.$parent_name;
 2536:                 for (my $j=0; $j<=$numchildren; $j++) {
 2537:                     if ($j < $numchildren) {
 2538:                         $name = $cats->[$depth]{$parent}[$j];
 2539:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
 2540:                         $idxnum = $idx->{$item};
 2541:                     } else {
 2542:                         $name = $parent_name;
 2543:                         $item = $parent_item;
 2544:                     }
 2545:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
 2546:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
 2547:                     for (my $i=0; $i<=$numchildren; $i++) {
 2548:                         my $vpos = $i+1;
 2549:                         my $selstr;
 2550:                         if ($j == $i) {
 2551:                             $selstr = ' selected="selected" ';
 2552:                         }
 2553:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
 2554:                     }
 2555:                     $text .= '</select>&nbsp;';
 2556:                     if ($j < $numchildren) {
 2557:                         my $deeper = $depth+1;
 2558:                         $text .= $name.'&nbsp;'
 2559:                                  .'<label><input type="checkbox" name="deletecategory" value="'
 2560:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
 2561:                         if(ref($path) eq 'ARRAY') {
 2562:                             push(@{$path},$name);
 2563:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
 2564:                             pop(@{$path});
 2565:                         }
 2566:                     } else {
 2567:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
 2568:                         if ($j == $numchildren) {
 2569:                             $text .= $name;
 2570:                         } else {
 2571:                             $text .= $item;
 2572:                         }
 2573:                         $text .= '" value="" />';
 2574:                     }
 2575:                     $text .= '</td></tr>';
 2576:                 }
 2577:                 $text .= '</table></td>';
 2578:             } else {
 2579:                 my $higher = $depth-1;
 2580:                 if ($higher == 0) {
 2581:                     $name = &escape($parent).'::'.$higher;
 2582:                 } else {
 2583:                     if (ref($path) eq 'ARRAY') {
 2584:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 2585:                     }
 2586:                 }
 2587:                 my $colspan;
 2588:                 if ($parent ne 'instcode') {
 2589:                     $colspan = $maxdepth - $depth - 1;
 2590:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
 2591:                 }
 2592:             }
 2593:         }
 2594:     }
 2595:     return $text;
 2596: }
 2597: 
 2598: sub modifiable_userdata_row {
 2599:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
 2600:     my $rolename;
 2601:     if ($context eq 'selfcreate') {
 2602:         if (ref($usertypes) eq 'HASH') {
 2603:             $rolename = $usertypes->{$role};
 2604:         } else {
 2605:             $rolename = $role;
 2606:         }
 2607:     } else {
 2608:         if ($role eq 'cr') {
 2609:             $rolename = &mt('Custom role');
 2610:         } else {
 2611:             $rolename = &Apache::lonnet::plaintext($role);
 2612:         }
 2613:     }
 2614:     my @fields = ('lastname','firstname','middlename','generation',
 2615:                   'permanentemail','id');
 2616:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 2617:     my $output;
 2618:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 2619:     $output = '<tr '.$css_class.'>'.
 2620:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
 2621:               '<td class="LC_left_item" colspan="2"><table>';
 2622:     my $rem;
 2623:     my %checks;
 2624:     if (ref($settings) eq 'HASH') {
 2625:         if (ref($settings->{$context}) eq 'HASH') {
 2626:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
 2627:                 foreach my $field (@fields) {
 2628:                     if ($settings->{$context}->{$role}->{$field}) {
 2629:                         $checks{$field} = ' checked="checked" ';
 2630:                     }
 2631:                 }
 2632:             }
 2633:         }
 2634:     }
 2635:     for (my $i=0; $i<@fields; $i++) {
 2636:         my $rem = $i%($numinrow);
 2637:         if ($rem == 0) {
 2638:             if ($i > 0) {
 2639:                 $output .= '</tr>';
 2640:             }
 2641:             $output .= '<tr>';
 2642:         }
 2643:         my $check = ' ';
 2644:         if (exists($checks{$fields[$i]})) {
 2645:             $check = $checks{$fields[$i]}
 2646:         } else {
 2647:             if ($role eq 'st') {
 2648:                 if (ref($settings) ne 'HASH') {
 2649:                     $check = ' checked="checked" '; 
 2650:                 }
 2651:             }
 2652:         }
 2653:         $output .= '<td class="LC_left_item">'.
 2654:                    '<span class="LC_nobreak"><label>'.
 2655:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
 2656:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
 2657:                    '</label></span></td>';
 2658:         $rem = @fields%($numinrow);
 2659:     }
 2660:     my $colsleft = $numinrow - $rem;
 2661:     if ($colsleft > 1 ) {
 2662:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 2663:                    '&nbsp;</td>';
 2664:     } elsif ($colsleft == 1) {
 2665:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 2666:     }
 2667:     $output .= '</tr></table></td></tr>';
 2668:     return $output;
 2669: }
 2670: 
 2671: sub users_cansearch_row {
 2672:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
 2673:     my $output =  '<tr class="LC_odd_row">'.
 2674:                   '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
 2675:                   '</td><td class="LC_left_item" colspan="2"><table>';
 2676:     my $rem;
 2677:     if (ref($types) eq 'ARRAY') {
 2678:         for (my $i=0; $i<@{$types}; $i++) {
 2679:             if (defined($usertypes->{$types->[$i]})) {
 2680:                 my $rem = $i%($numinrow);
 2681:                 if ($rem == 0) {
 2682:                     if ($i > 0) {
 2683:                         $output .= '</tr>';
 2684:                     }
 2685:                     $output .= '<tr>';
 2686:                 }
 2687:                 my $check = ' ';
 2688:                 if (ref($settings->{'cansearch'}) eq 'ARRAY') {
 2689:                     if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
 2690:                         $check = ' checked="checked" ';
 2691:                     }
 2692:                 }
 2693:                 $output .= '<td class="LC_left_item">'.
 2694:                            '<span class="LC_nobreak"><label>'.
 2695:                            '<input type="checkbox" name="cansearch" '.
 2696:                            'value="'.$types->[$i].'"'.$check.'/>'.
 2697:                            $usertypes->{$types->[$i]}.'</label></span></td>';
 2698:             }
 2699:         }
 2700:        
 2701:         $rem = @{$types}%($numinrow);
 2702:     }
 2703:     my $colsleft = $numinrow - $rem;
 2704:     if ($colsleft > 1) {
 2705:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 2706:     } else {
 2707:         $output .= '<td class="LC_left_item">';
 2708:     }
 2709:     my $defcheck = ' ';
 2710:     if (ref($settings->{'cansearch'}) eq 'ARRAY') {
 2711:         if (grep(/^default$/,@{$settings->{'cansearch'}})) {
 2712:             $defcheck = ' checked="checked" ';
 2713:         }
 2714:     }
 2715:     $output .= '<span class="LC_nobreak"><label>'.
 2716:                '<input type="checkbox" name="cansearch" '.
 2717:                'value="default"'.$defcheck.'/>'.
 2718:                $othertitle.'</label></span></td>'.
 2719:                '</tr></table></td></tr>';
 2720:     return $output;
 2721: }
 2722: 
 2723: sub sorted_searchtitles {
 2724:     my %searchtitles = &Apache::lonlocal::texthash(
 2725:                          'uname' => 'username',
 2726:                          'lastname' => 'last name',
 2727:                          'lastfirst' => 'last name, first name',
 2728:                      );
 2729:     my @titleorder = ('uname','lastname','lastfirst');
 2730:     return (\%searchtitles,\@titleorder);
 2731: }
 2732: 
 2733: sub sorted_searchtypes {
 2734:     my %srchtypes_desc = (
 2735:                            exact    => 'is exact match',
 2736:                            contains => 'contains ..',
 2737:                            begins   => 'begins with ..',
 2738:                          );
 2739:     my @srchtypeorder = ('exact','begins','contains');
 2740:     return (\%srchtypes_desc,\@srchtypeorder);
 2741: }
 2742: 
 2743: sub usertype_update_row {
 2744:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
 2745:     my $datatable;
 2746:     my $numinrow = 4;
 2747:     foreach my $type (@{$types}) {
 2748:         if (defined($usertypes->{$type})) {
 2749:             $$rownums ++;
 2750:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
 2751:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
 2752:                           '</td><td class="LC_left_item"><table>';
 2753:             for (my $i=0; $i<@{$fields}; $i++) {
 2754:                 my $rem = $i%($numinrow);
 2755:                 if ($rem == 0) {
 2756:                     if ($i > 0) {
 2757:                         $datatable .= '</tr>';
 2758:                     }
 2759:                     $datatable .= '<tr>';
 2760:                 }
 2761:                 my $check = ' ';
 2762:                 if (ref($settings) eq 'HASH') {
 2763:                     if (ref($settings->{'fields'}) eq 'HASH') {
 2764:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
 2765:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
 2766:                                 $check = ' checked="checked" ';
 2767:                             }
 2768:                         }
 2769:                     }
 2770:                 }
 2771: 
 2772:                 if ($i == @{$fields}-1) {
 2773:                     my $colsleft = $numinrow - $rem;
 2774:                     if ($colsleft > 1) {
 2775:                         $datatable .= '<td colspan="'.$colsleft.'">';
 2776:                     } else {
 2777:                         $datatable .= '<td>';
 2778:                     }
 2779:                 } else {
 2780:                     $datatable .= '<td>';
 2781:                 }
 2782:                 $datatable .= '<span class="LC_nobreak"><label>'.
 2783:                               '<input type="checkbox" name="updateable_'.$type.
 2784:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
 2785:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
 2786:             }
 2787:             $datatable .= '</tr></table></td></tr>';
 2788:         }
 2789:     }
 2790:     return $datatable;
 2791: }
 2792: 
 2793: sub modify_login {
 2794:     my ($r,$dom,$confname,%domconfig) = @_;
 2795:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
 2796:     my %title = ( coursecatalog => 'Display course catalog',
 2797:                   adminmail => 'Display administrator E-mail address',
 2798:                   newuser => 'Link for visitors to create a user account',
 2799:                   loginheader => 'Log-in box header');
 2800:     my @offon = ('off','on');
 2801:     my %loginhash;
 2802:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
 2803:                                            \%domconfig,\%loginhash);
 2804:     my @toggles = ('coursecatalog','adminmail','newuser');
 2805:     foreach my $item (@toggles) {
 2806:         $loginhash{login}{$item} = $env{'form.'.$item};
 2807:     }
 2808:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
 2809:     if (ref($colchanges{'login'}) eq 'HASH') {  
 2810:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
 2811:                                          \%loginhash);
 2812:     }
 2813:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
 2814:                                              $dom);
 2815:     if ($putresult eq 'ok') {
 2816:         my @toggles = ('coursecatalog','adminmail','newuser');
 2817:         my %defaultchecked = (
 2818:                     'coursecatalog' => 'on',
 2819:                     'adminmail'     => 'off',
 2820:                     'newuser'       => 'off',
 2821:         );
 2822:         if (ref($domconfig{'login'}) eq 'HASH') {
 2823:             foreach my $item (@toggles) {
 2824:                 if ($defaultchecked{$item} eq 'on') { 
 2825:                     if (($domconfig{'login'}{$item} eq '0') &&
 2826:                         ($env{'form.'.$item} eq '1')) {
 2827:                         $changes{$item} = 1;
 2828:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 2829:                               $domconfig{'login'}{$item} eq '1') &&
 2830:                              ($env{'form.'.$item} eq '0')) {
 2831:                         $changes{$item} = 1;
 2832:                     }
 2833:                 } elsif ($defaultchecked{$item} eq 'off') {
 2834:                     if (($domconfig{'login'}{$item} eq '1') &&
 2835:                         ($env{'form.'.$item} eq '0')) {
 2836:                         $changes{$item} = 1;
 2837:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 2838:                               $domconfig{'login'}{$item} eq '0') &&
 2839:                              ($env{'form.'.$item} eq '1')) {
 2840:                         $changes{$item} = 1;
 2841:                     }
 2842:                 }
 2843:             }
 2844:             if (($domconfig{'login'}{'loginheader'} eq 'text') && 
 2845:                 ($env{'form.loginheader'} eq 'image')) {
 2846:                 $changes{'loginheader'} = 1;
 2847:             } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
 2848:                       $domconfig{'login'}{'loginheader'} eq 'image') &&
 2849:                      ($env{'form.loginheader'} eq 'text')) {
 2850:                 $changes{'loginheader'} = 1;
 2851:             }
 2852:         }
 2853:         if (keys(%changes) > 0 || $colchgtext) {
 2854:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 2855:             $resulttext = &mt('Changes made:').'<ul>';
 2856:             foreach my $item (sort(keys(%changes))) {
 2857:                 if ($item eq 'loginheader') {
 2858:                     $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
 2859:                 } else {
 2860:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 2861:                 }
 2862:             }
 2863:             $resulttext .= $colchgtext.'</ul>';
 2864:         } else {
 2865:             $resulttext = &mt('No changes made to log-in page settings');
 2866:         }
 2867:     } else {
 2868:         $resulttext = '<span class="LC_error">'.
 2869: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 2870:     }
 2871:     if ($errors) {
 2872:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 2873:                        $errors.'</ul>';
 2874:     }
 2875:     return $resulttext;
 2876: }
 2877: 
 2878: sub color_font_choices {
 2879:     my %choices =
 2880:         &Apache::lonlocal::texthash (
 2881:             img => "Header",
 2882:             bgs => "Background colors",
 2883:             links => "Link colors",
 2884:             images => "Images",
 2885:             font => "Font color",
 2886:             pgbg => "Page",
 2887:             tabbg => "Header",
 2888:             sidebg => "Border",
 2889:             link => "Link",
 2890:             alink => "Active link",
 2891:             vlink => "Visited link",
 2892:         );
 2893:     return %choices;
 2894: }
 2895: 
 2896: sub modify_rolecolors {
 2897:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
 2898:     my ($resulttext,%rolehash);
 2899:     $rolehash{'rolecolors'} = {};
 2900:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
 2901:         if ($domconfig{'rolecolors'} eq '') {
 2902:             $domconfig{'rolecolors'} = {};
 2903:         }
 2904:     }
 2905:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 2906:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 2907:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 2908:                                              $dom);
 2909:     if ($putresult eq 'ok') {
 2910:         if (keys(%changes) > 0) {
 2911:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 2912:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 2913:                                              $rolehash{'rolecolors'});
 2914:         } else {
 2915:             $resulttext = &mt('No changes made to default color schemes');
 2916:         }
 2917:     } else {
 2918:         $resulttext = '<span class="LC_error">'.
 2919: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 2920:     }
 2921:     if ($errors) {
 2922:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 2923:                        $errors.'</ul>';
 2924:     }
 2925:     return $resulttext;
 2926: }
 2927: 
 2928: sub modify_colors {
 2929:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 2930:     my (%changes,%choices);
 2931:     my @bgs;
 2932:     my @links = ('link','alink','vlink');
 2933:     my @logintext;
 2934:     my @images;
 2935:     my $servadm = $r->dir_config('lonAdmEMail');
 2936:     my $errors;
 2937:     foreach my $role (@{$roles}) {
 2938:         if ($role eq 'login') {
 2939:             %choices = &login_choices();
 2940:             @logintext = ('textcol','bgcol');
 2941:         } else {
 2942:             %choices = &color_font_choices();
 2943:         }
 2944:         if ($role eq 'login') {
 2945:             @images = ('img','logo','domlogo','login');
 2946:             @bgs = ('pgbg','mainbg','sidebg');
 2947:         } else {
 2948:             @images = ('img');
 2949:             @bgs = ('pgbg','tabbg','sidebg'); 
 2950:         }
 2951:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 2952:         foreach my $item (@bgs,@links,@logintext) {
 2953:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 2954:         }
 2955:         my ($configuserok,$author_ok,$switchserver) = 
 2956:             &config_check($dom,$confname,$servadm);
 2957:         my ($width,$height) = &thumb_dimensions();
 2958:         if (ref($domconfig->{$role}) ne 'HASH') {
 2959:             $domconfig->{$role} = {};
 2960:         }
 2961:         foreach my $img (@images) {
 2962:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
 2963:                 if (defined($env{'form.login_showlogo_'.$img})) {
 2964:                     $confhash->{$role}{'showlogo'}{$img} = 1;
 2965:                 } else { 
 2966:                     $confhash->{$role}{'showlogo'}{$img} = 0;
 2967:                 }
 2968:             } 
 2969: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 2970: 		 && !defined($domconfig->{$role}{$img})
 2971: 		 && !$env{'form.'.$role.'_del_'.$img}
 2972: 		 && $env{'form.'.$role.'_import_'.$img}) {
 2973: 		# import the old configured image from the .tab setting
 2974: 		# if they haven't provided a new one 
 2975: 		$domconfig->{$role}{$img} = 
 2976: 		    $env{'form.'.$role.'_import_'.$img};
 2977: 	    }
 2978:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 2979:                 my $error;
 2980:                 if ($configuserok eq 'ok') {
 2981:                     if ($switchserver) {
 2982:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 2983:                     } else {
 2984:                         if ($author_ok eq 'ok') {
 2985:                             my ($result,$logourl) = 
 2986:                                 &publishlogo($r,'upload',$role.'_'.$img,
 2987:                                            $dom,$confname,$img,$width,$height);
 2988:                             if ($result eq 'ok') {
 2989:                                 $confhash->{$role}{$img} = $logourl;
 2990:                                 $changes{$role}{'images'}{$img} = 1;
 2991:                             } else {
 2992:                                 $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);
 2993:                             }
 2994:                         } else {
 2995:                             $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);
 2996:                         }
 2997:                     }
 2998:                 } else {
 2999:                     $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);
 3000:                 }
 3001:                 if ($error) {
 3002:                     &Apache::lonnet::logthis($error);
 3003:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 3004:                 }
 3005:             } elsif ($domconfig->{$role}{$img} ne '') {
 3006:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 3007:                     my $error;
 3008:                     if ($configuserok eq 'ok') {
 3009: # is confname an author?
 3010:                         if ($switchserver eq '') {
 3011:                             if ($author_ok eq 'ok') {
 3012:                                 my ($result,$logourl) = 
 3013:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 3014:                                             $dom,$confname,$img,$width,$height);
 3015:                                 if ($result eq 'ok') {
 3016:                                     $confhash->{$role}{$img} = $logourl;
 3017: 				    $changes{$role}{'images'}{$img} = 1;
 3018:                                 }
 3019:                             }
 3020:                         }
 3021:                     }
 3022:                 }
 3023:             }
 3024:         }
 3025:         if (ref($domconfig) eq 'HASH') {
 3026:             if (ref($domconfig->{$role}) eq 'HASH') {
 3027:                 foreach my $img (@images) {
 3028:                     if ($domconfig->{$role}{$img} ne '') {
 3029:                         if ($env{'form.'.$role.'_del_'.$img}) {
 3030:                             $confhash->{$role}{$img} = '';
 3031:                             $changes{$role}{'images'}{$img} = 1;
 3032:                         } else {
 3033:                             if ($confhash->{$role}{$img} eq '') {
 3034:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 3035:                             }
 3036:                         }
 3037:                     } else {
 3038:                         if ($env{'form.'.$role.'_del_'.$img}) {
 3039:                             $confhash->{$role}{$img} = '';
 3040:                             $changes{$role}{'images'}{$img} = 1;
 3041:                         } 
 3042:                     }
 3043:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
 3044:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
 3045:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
 3046:                                 $domconfig->{$role}{'showlogo'}{$img}) {
 3047:                                 $changes{$role}{'showlogo'}{$img} = 1; 
 3048:                             }
 3049:                         } else {
 3050:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 3051:                                 $changes{$role}{'showlogo'}{$img} = 1;
 3052:                             }
 3053:                         }
 3054:                     }
 3055:                 }
 3056:                 if ($domconfig->{$role}{'font'} ne '') {
 3057:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 3058:                         $changes{$role}{'font'} = 1;
 3059:                     }
 3060:                 } else {
 3061:                     if ($confhash->{$role}{'font'}) {
 3062:                         $changes{$role}{'font'} = 1;
 3063:                     }
 3064:                 }
 3065:                 foreach my $item (@bgs) {
 3066:                     if ($domconfig->{$role}{$item} ne '') {
 3067:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 3068:                             $changes{$role}{'bgs'}{$item} = 1;
 3069:                         } 
 3070:                     } else {
 3071:                         if ($confhash->{$role}{$item}) {
 3072:                             $changes{$role}{'bgs'}{$item} = 1;
 3073:                         }
 3074:                     }
 3075:                 }
 3076:                 foreach my $item (@links) {
 3077:                     if ($domconfig->{$role}{$item} ne '') {
 3078:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 3079:                             $changes{$role}{'links'}{$item} = 1;
 3080:                         }
 3081:                     } else {
 3082:                         if ($confhash->{$role}{$item}) {
 3083:                             $changes{$role}{'links'}{$item} = 1;
 3084:                         }
 3085:                     }
 3086:                 }
 3087:                 foreach my $item (@logintext) {
 3088:                     if ($domconfig->{$role}{$item} ne '') {
 3089:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 3090:                             $changes{$role}{'logintext'}{$item} = 1;
 3091:                         }
 3092:                     } else {
 3093:                         if ($confhash->{$role}{$item}) {
 3094:                             $changes{$role}{'logintext'}{$item} = 1;
 3095:                         }
 3096:                     }
 3097:                 }
 3098:             } else {
 3099:                 &default_change_checker($role,\@images,\@links,\@bgs,
 3100:                                         \@logintext,$confhash,\%changes); 
 3101:             }
 3102:         } else {
 3103:             &default_change_checker($role,\@images,\@links,\@bgs,
 3104:                                     \@logintext,$confhash,\%changes); 
 3105:         }
 3106:     }
 3107:     return ($errors,%changes);
 3108: }
 3109: 
 3110: sub config_check {
 3111:     my ($dom,$confname,$servadm) = @_;
 3112:     my ($configuserok,$author_ok,$switchserver,%currroles);
 3113:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 3114:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 3115:                                                    $confname,$servadm);
 3116:     if ($configuserok eq 'ok') {
 3117:         $switchserver = &check_switchserver($dom,$confname);
 3118:         if ($switchserver eq '') {
 3119:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
 3120:         }
 3121:     }
 3122:     return ($configuserok,$author_ok,$switchserver);
 3123: }
 3124: 
 3125: sub default_change_checker {
 3126:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
 3127:     foreach my $item (@{$links}) {
 3128:         if ($confhash->{$role}{$item}) {
 3129:             $changes->{$role}{'links'}{$item} = 1;
 3130:         }
 3131:     }
 3132:     foreach my $item (@{$bgs}) {
 3133:         if ($confhash->{$role}{$item}) {
 3134:             $changes->{$role}{'bgs'}{$item} = 1;
 3135:         }
 3136:     }
 3137:     foreach my $item (@{$logintext}) {
 3138:         if ($confhash->{$role}{$item}) {
 3139:             $changes->{$role}{'logintext'}{$item} = 1;
 3140:         }
 3141:     }
 3142:     foreach my $img (@{$images}) {
 3143:         if ($env{'form.'.$role.'_del_'.$img}) {
 3144:             $confhash->{$role}{$img} = '';
 3145:             $changes->{$role}{'images'}{$img} = 1;
 3146:         }
 3147:         if ($role eq 'login') {
 3148:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 3149:                 $changes->{$role}{'showlogo'}{$img} = 1;
 3150:             }
 3151:         }
 3152:     }
 3153:     if ($confhash->{$role}{'font'}) {
 3154:         $changes->{$role}{'font'} = 1;
 3155:     }
 3156: }
 3157: 
 3158: sub display_colorchgs {
 3159:     my ($dom,$changes,$roles,$confhash) = @_;
 3160:     my (%choices,$resulttext);
 3161:     if (!grep(/^login$/,@{$roles})) {
 3162:         $resulttext = &mt('Changes made:').'<br />';
 3163:     }
 3164:     foreach my $role (@{$roles}) {
 3165:         if ($role eq 'login') {
 3166:             %choices = &login_choices();
 3167:         } else {
 3168:             %choices = &color_font_choices();
 3169:         }
 3170:         if (ref($changes->{$role}) eq 'HASH') {
 3171:             if ($role ne 'login') {
 3172:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 3173:             }
 3174:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 3175:                 if ($role ne 'login') {
 3176:                     $resulttext .= '<ul>';
 3177:                 }
 3178:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 3179:                     if ($role ne 'login') {
 3180:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 3181:                     }
 3182:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 3183:                         if (($role eq 'login') && ($key eq 'showlogo')) {
 3184:                             if ($confhash->{$role}{$key}{$item}) {
 3185:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
 3186:                             } else {
 3187:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
 3188:                             }
 3189:                         } elsif ($confhash->{$role}{$item} eq '') {
 3190:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 3191:                         } else {
 3192:                             my $newitem = $confhash->{$role}{$item};
 3193:                             if ($key eq 'images') {
 3194:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 3195:                             }
 3196:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 3197:                         }
 3198:                     }
 3199:                     if ($role ne 'login') {
 3200:                         $resulttext .= '</ul></li>';
 3201:                     }
 3202:                 } else {
 3203:                     if ($confhash->{$role}{$key} eq '') {
 3204:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 3205:                     } else {
 3206:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 3207:                     }
 3208:                 }
 3209:                 if ($role ne 'login') {
 3210:                     $resulttext .= '</ul>';
 3211:                 }
 3212:             }
 3213:         }
 3214:     }
 3215:     return $resulttext;
 3216: }
 3217: 
 3218: sub thumb_dimensions {
 3219:     return ('200','50');
 3220: }
 3221: 
 3222: sub check_dimensions {
 3223:     my ($inputfile) = @_;
 3224:     my ($fullwidth,$fullheight);
 3225:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 3226:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 3227:             my $imageinfo = <PIPE>;
 3228:             if (!close(PIPE)) {
 3229:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 3230:             }
 3231:             chomp($imageinfo);
 3232:             my ($fullsize) = 
 3233:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
 3234:             if ($fullsize) {
 3235:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 3236:             }
 3237:         }
 3238:     }
 3239:     return ($fullwidth,$fullheight);
 3240: }
 3241: 
 3242: sub check_configuser {
 3243:     my ($uhome,$dom,$confname,$servadm) = @_;
 3244:     my ($configuserok,%currroles);
 3245:     if ($uhome eq 'no_host') {
 3246:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 3247:         my $configpass = &LONCAPA::Enrollment::create_password();
 3248:         $configuserok = 
 3249:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 3250:                              $configpass,'','','','','',undef,$servadm);
 3251:     } else {
 3252:         $configuserok = 'ok';
 3253:         %currroles = 
 3254:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 3255:     }
 3256:     return ($configuserok,%currroles);
 3257: }
 3258: 
 3259: sub check_authorstatus {
 3260:     my ($dom,$confname,%currroles) = @_;
 3261:     my $author_ok;
 3262:     if (!$currroles{':'.$dom.':au'}) {
 3263:         my $start = time;
 3264:         my $end = 0;
 3265:         $author_ok = 
 3266:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 3267:                                         'au',$end,$start,'','','domconfig');
 3268:     } else {
 3269:         $author_ok = 'ok';
 3270:     }
 3271:     return $author_ok;
 3272: }
 3273: 
 3274: sub publishlogo {
 3275:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
 3276:     my ($output,$fname,$logourl);
 3277:     if ($action eq 'upload') {
 3278:         $fname=$env{'form.'.$formname.'.filename'};
 3279:         chop($env{'form.'.$formname});
 3280:     } else {
 3281:         ($fname) = ($formname =~ /([^\/]+)$/);
 3282:     }
 3283:     if ($savefileas ne '') {
 3284:         $fname = $savefileas;
 3285:     }
 3286:     $fname=&Apache::lonnet::clean_filename($fname);
 3287: # See if there is anything left
 3288:     unless ($fname) { return ('error: no uploaded file'); }
 3289:     $fname="$subdir/$fname";
 3290:     my $filepath='/home/'.$confname.'/public_html';
 3291:     my ($fnamepath,$file,$fetchthumb);
 3292:     $file=$fname;
 3293:     if ($fname=~m|/|) {
 3294:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 3295:     }
 3296:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
 3297:     my $count;
 3298:     for ($count=4;$count<=$#parts;$count++) {
 3299:         $filepath.="/$parts[$count]";
 3300:         if ((-e $filepath)!=1) {
 3301:             mkdir($filepath,02770);
 3302:         }
 3303:     }
 3304:     # Check for bad extension and disallow upload
 3305:     if ($file=~/\.(\w+)$/ &&
 3306:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 3307:         $output = 
 3308:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
 3309:     } elsif ($file=~/\.(\w+)$/ &&
 3310:         !defined(&Apache::loncommon::fileembstyle($1))) {
 3311:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 3312:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 3313:         $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 3314:     } elsif (-d "$filepath/$file") {
 3315:         $output = &mt('File name is a directory name - rename the file and re-upload');
 3316:     } else {
 3317:         my $source = $filepath.'/'.$file;
 3318:         my $logfile;
 3319:         if (!open($logfile,">>$source".'.log')) {
 3320:             return (&mt('No write permission to Construction Space'));
 3321:         }
 3322:         print $logfile
 3323: "\n================= Publish ".localtime()." ================\n".
 3324: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 3325: # Save the file
 3326:         if (!open(FH,'>'.$source)) {
 3327:             &Apache::lonnet::logthis('Failed to create '.$source);
 3328:             return (&mt('Failed to create file'));
 3329:         }
 3330:         if ($action eq 'upload') {
 3331:             if (!print FH ($env{'form.'.$formname})) {
 3332:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 3333:                 return (&mt('Failed to write file'));
 3334:             }
 3335:         } else {
 3336:             my $original = &Apache::lonnet::filelocation('',$formname);
 3337:             if(!copy($original,$source)) {
 3338:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 3339:                 return (&mt('Failed to write file'));
 3340:             }
 3341:         }
 3342:         close(FH);
 3343:         chmod(0660, $source); # Permissions to rw-rw---.
 3344: 
 3345:         my $docroot=$r->dir_config('lonDocRoot');
 3346:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 3347:         my $copyfile=$targetdir.'/'.$file;
 3348: 
 3349:         my @parts=split(/\//,$targetdir);
 3350:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 3351:         for (my $count=5;$count<=$#parts;$count++) {
 3352:             $path.="/$parts[$count]";
 3353:             if (!-e $path) {
 3354:                 print $logfile "\nCreating directory ".$path;
 3355:                 mkdir($path,02770);
 3356:             }
 3357:         }
 3358:         my $versionresult;
 3359:         if (-e $copyfile) {
 3360:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 3361:         } else {
 3362:             $versionresult = 'ok';
 3363:         }
 3364:         if ($versionresult eq 'ok') {
 3365:             if (copy($source,$copyfile)) {
 3366:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 3367:                 $output = 'ok';
 3368:                 &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 3369:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 3370:             } else {
 3371:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 3372:                 $output = &mt('Failed to copy file to RES space').", $!";
 3373:             }
 3374:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 3375:                 my $inputfile = $filepath.'/'.$file;
 3376:                 my $outfile = $filepath.'/'.'tn-'.$file;
 3377:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 3378:                 if ($fullwidth ne '' && $fullheight ne '') { 
 3379:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 3380:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 3381:                         system("convert -sample $thumbsize $inputfile $outfile");
 3382:                         chmod(0660, $filepath.'/tn-'.$file);
 3383:                         if (-e $outfile) {
 3384:                             my $copyfile=$targetdir.'/tn-'.$file;
 3385:                             if (copy($outfile,$copyfile)) {
 3386:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 3387:                                 &write_metadata($dom,$confname,$formname,
 3388:                                                 $targetdir,'tn-'.$file,$logfile);
 3389:                             } else {
 3390:                                 print $logfile "\nUnable to write ".$copyfile.
 3391:                                                ':'.$!."\n";
 3392:                             }
 3393:                         }
 3394:                     }
 3395:                 }
 3396:             }
 3397:         } else {
 3398:             $output = $versionresult;
 3399:         }
 3400:     }
 3401:     return ($output,$logourl);
 3402: }
 3403: 
 3404: sub logo_versioning {
 3405:     my ($targetdir,$file,$logfile) = @_;
 3406:     my $target = $targetdir.'/'.$file;
 3407:     my ($maxversion,$fn,$extn,$output);
 3408:     $maxversion = 0;
 3409:     if ($file =~ /^(.+)\.(\w+)$/) {
 3410:         $fn=$1;
 3411:         $extn=$2;
 3412:     }
 3413:     opendir(DIR,$targetdir);
 3414:     while (my $filename=readdir(DIR)) {
 3415:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 3416:             $maxversion=($1>$maxversion)?$1:$maxversion;
 3417:         }
 3418:     }
 3419:     $maxversion++;
 3420:     print $logfile "\nCreating old version ".$maxversion."\n";
 3421:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 3422:     if (copy($target,$copyfile)) {
 3423:         print $logfile "Copied old target to ".$copyfile."\n";
 3424:         $copyfile=$copyfile.'.meta';
 3425:         if (copy($target.'.meta',$copyfile)) {
 3426:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 3427:             $output = 'ok';
 3428:         } else {
 3429:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 3430:             $output = &mt('Failed to copy old meta').", $!, ";
 3431:         }
 3432:     } else {
 3433:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 3434:         $output = &mt('Failed to copy old target').", $!, ";
 3435:     }
 3436:     return $output;
 3437: }
 3438: 
 3439: sub write_metadata {
 3440:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 3441:     my (%metadatafields,%metadatakeys,$output);
 3442:     $metadatafields{'title'}=$formname;
 3443:     $metadatafields{'creationdate'}=time;
 3444:     $metadatafields{'lastrevisiondate'}=time;
 3445:     $metadatafields{'copyright'}='public';
 3446:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 3447:                                          $env{'user.domain'};
 3448:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 3449:     $metadatafields{'domain'}=$dom;
 3450:     {
 3451:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 3452:         my $mfh;
 3453:         unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 3454:             $output = &mt('Could not write metadata');
 3455:         }
 3456:         foreach (sort keys %metadatafields) {
 3457:             unless ($_=~/\./) {
 3458:                 my $unikey=$_;
 3459:                 $unikey=~/^([A-Za-z]+)/;
 3460:                 my $tag=$1;
 3461:                 $tag=~tr/A-Z/a-z/;
 3462:                 print $mfh "\n\<$tag";
 3463:                 foreach (split(/\,/,$metadatakeys{$unikey})) {
 3464:                     my $value=$metadatafields{$unikey.'.'.$_};
 3465:                     $value=~s/\"/\'\'/g;
 3466:                     print $mfh ' '.$_.'="'.$value.'"';
 3467:                 }
 3468:                 print $mfh '>'.
 3469:                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 3470:                         .'</'.$tag.'>';
 3471:             }
 3472:         }
 3473:         $output = 'ok';
 3474:         print $logfile "\nWrote metadata";
 3475:         close($mfh);
 3476:     }
 3477: }
 3478: 
 3479: sub check_switchserver {
 3480:     my ($dom,$confname) = @_;
 3481:     my ($allowed,$switchserver);
 3482:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 3483:     if ($home eq 'no_host') {
 3484:         $home = &Apache::lonnet::domain($dom,'primary');
 3485:     }
 3486:     my @ids=&Apache::lonnet::current_machine_ids();
 3487:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 3488:     if (!$allowed) {
 3489: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
 3490:     }
 3491:     return $switchserver;
 3492: }
 3493: 
 3494: sub javascript_set_colnums {
 3495:     return <<END;
 3496: function setDisplayColumns() {
 3497:     if (document.pickactions.width.value > 1100) {
 3498:         document.pickactions.numcols[1].checked = true;
 3499:     } else {
 3500:         document.pickactions.numcols[0].checked = true;
 3501:     }
 3502: }
 3503: END
 3504: }
 3505: 
 3506: sub modify_quotas {
 3507:     my ($dom,%domconfig) = @_;
 3508:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 3509:     my ($resulttext,%changes);
 3510:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 3511:     my @usertools = ('aboutme','blog','portfolio');
 3512:     my %titles = &tool_titles();
 3513:     my (%confhash,%toolshash);
 3514:     foreach my $key (keys(%env)) {
 3515:         if ($key =~ /^form\.quota_(.+)$/) {
 3516:             $confhash{'defaultquota'}{$1} = $env{$key};
 3517:         } elsif ($key =~ /^form\.tools_(.+)$/) {
 3518:             @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
 3519:         }
 3520:     }
 3521:     $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
 3522:     foreach my $item (@usertools) {
 3523:         foreach my $type (@{$types},'default','_LC_adv') {
 3524:             if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
 3525:                 $confhash{$item}{$type} = 1;
 3526:             } else {
 3527:                 $confhash{$item}{$type} = 0;
 3528:             }
 3529:             if (ref($domconfig{'quotas'}) eq 'HASH') {
 3530:                 if (ref($domconfig{'quotas'}{$item}) eq 'HASH') {
 3531:                     if ($domconfig{'quotas'}{$item}{$type} ne $confhash{$item}{$type}) {
 3532:                         $changes{$item}{$type} = 1;
 3533:                     }
 3534:                 } else {
 3535:                     if (!$confhash{$item}{$type}) {
 3536:                         $changes{$item}{$type} = 1;
 3537:                     }
 3538:                 }
 3539:             } else {
 3540:                 if (!$confhash{$item}{$type}) {
 3541:                     $changes{$item}{$type} = 1;
 3542:                 }
 3543:             }
 3544:         }
 3545:     }
 3546:     if (ref($domconfig{'quotas'}) eq 'HASH') {
 3547:         if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 3548:             foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
 3549:                 if (exists($confhash{'defaultquota'}{$key})) {
 3550:                     if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
 3551:                         $changes{'defaultquota'}{$key} = 1;
 3552:                     }
 3553:                 } else {
 3554:                     $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
 3555:                 }
 3556:             }
 3557:         } else {
 3558:             foreach my $key (keys(%{$domconfig{'quotas'}})) {
 3559:                 if (exists($confhash{'defaultquota'}{$key})) {
 3560:                     if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
 3561:                         $changes{'defaultquota'}{$key} = 1;
 3562:                     }
 3563:                 } else {
 3564:                     $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
 3565:                 }
 3566:             }
 3567:         }
 3568:     }
 3569:     if (ref($confhash{'defaultquota'}) eq 'HASH') {
 3570:         foreach my $key (keys(%{$confhash{'defaultquota'}})) {
 3571:             if (ref($domconfig{'quotas'}) eq 'HASH') {
 3572:                 if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 3573:                     if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
 3574:                         $changes{'defaultquota'}{$key} = 1;
 3575:                     }
 3576:                 } else {
 3577:                     if (!exists($domconfig{'quotas'}{$key})) {
 3578:                         $changes{'defaultquota'}{$key} = 1;
 3579:                     }
 3580:                 }
 3581:             } else {
 3582:                 $changes{'defaultquota'}{$key} = 1;
 3583:             }
 3584:         }
 3585:     }
 3586: 
 3587:     foreach my $key (keys(%confhash)) {
 3588:         $domdefaults{$key} = $confhash{$key};
 3589:     }
 3590:    
 3591:     my %quotahash = (
 3592:                       quotas => { %confhash }
 3593:                     );
 3594:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 3595:                                              $dom);
 3596:     if ($putresult eq 'ok') {
 3597:         if (keys(%changes) > 0) {
 3598:             my $cachetime = 24*60*60;
 3599:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 3600: 
 3601:             $resulttext = &mt('Changes made:').'<ul>';
 3602:             if (ref($changes{'defaultquota'}) eq 'HASH') {
 3603:                 $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
 3604:                 foreach my $type (@{$types},'default') {
 3605:                     if (defined($changes{'defaultquota'}{$type})) {
 3606:                         my $typetitle = $usertypes->{$type};
 3607:                         if ($type eq 'default') {
 3608:                             $typetitle = $othertitle;
 3609:                         }
 3610:                         $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
 3611:                     }
 3612:                 }
 3613:                 $resulttext .= '</ul></li>';
 3614:             }
 3615:             my %newenv;
 3616:             foreach my $item (@usertools) {
 3617:                 if (ref($changes{$item}) eq 'HASH') {
 3618:                     my $newacc = 
 3619:                         &Apache::lonnet::usertools_access($env{'user.name'},
 3620:                                                           $env{'user.domain'},
 3621:                                                           $item,'reload');
 3622:                     if ($env{'environment.availabletools.'.$item} ne $newacc) { 
 3623:                         $newenv{'environment.availabletools.'.$item} = $newacc;
 3624:                     }
 3625:                     $resulttext .= '<li>'.$titles{$item}.'<ul>';
 3626:                     foreach my $type (@{$types},'default','_LC_adv') {
 3627:                         if ($changes{$item}{$type}) {
 3628:                             my $typetitle = $usertypes->{$type};
 3629:                             if ($type eq 'default') {
 3630:                                 $typetitle = $othertitle;
 3631:                             } elsif ($type eq '_LC_adv') {
 3632:                                 $typetitle = 'LON-CAPA Advanced Users'; 
 3633:                             }
 3634:                             if ($confhash{$item}{$type}) {
 3635:                                 $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
 3636:                             } else {
 3637:                                 $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 3638:                             }
 3639:                         }
 3640:                     }
 3641:                     $resulttext .= '</ul></li>';
 3642:                 }
 3643:             }
 3644:             $resulttext .= '</ul>';
 3645:             if (keys(%newenv)) {
 3646:                 &Apache::lonnet::appenv(\%newenv);
 3647:             }
 3648:         } else {
 3649:             $resulttext = &mt('No changes made to availability of home pages, blogs, portfolios or default quotas');
 3650:         }
 3651:     } else {
 3652:         $resulttext = '<span class="LC_error">'.
 3653: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 3654:     }
 3655:     return $resulttext;
 3656: }
 3657: 
 3658: sub modify_autoenroll {
 3659:     my ($dom,%domconfig) = @_;
 3660:     my ($resulttext,%changes);
 3661:     my %currautoenroll;
 3662:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 3663:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 3664:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 3665:         }
 3666:     }
 3667:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 3668:     my %title = ( run => 'Auto-enrollment active',
 3669:                   sender => 'Sender for notification messages');
 3670:     my @offon = ('off','on');
 3671:     my $sender_uname = $env{'form.sender_uname'};
 3672:     my $sender_domain = $env{'form.sender_domain'};
 3673:     if ($sender_domain eq '') {
 3674:         $sender_uname = '';
 3675:     } elsif ($sender_uname eq '') {
 3676:         $sender_domain = '';
 3677:     }
 3678:     my %autoenrollhash =  (
 3679:                        autoenroll => { run => $env{'form.autoenroll_run'},
 3680:                                        sender_uname => $sender_uname,
 3681:                                        sender_domain => $sender_domain,
 3682: 
 3683:                                 }
 3684:                      );
 3685:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 3686:                                              $dom);
 3687:     if ($putresult eq 'ok') {
 3688:         if (exists($currautoenroll{'run'})) {
 3689:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 3690:                  $changes{'run'} = 1;
 3691:              }
 3692:         } elsif ($autorun) {
 3693:             if ($env{'form.autoenroll_run'} ne '1') {
 3694:                  $changes{'run'} = 1;
 3695:             }
 3696:         }
 3697:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 3698:             $changes{'sender'} = 1;
 3699:         }
 3700:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 3701:             $changes{'sender'} = 1;
 3702:         }
 3703:         if (keys(%changes) > 0) {
 3704:             $resulttext = &mt('Changes made:').'<ul>';
 3705:             if ($changes{'run'}) {
 3706:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 3707:             }
 3708:             if ($changes{'sender'}) {
 3709:                 if ($sender_uname eq '' || $sender_domain eq '') {
 3710:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 3711:                 } else {
 3712:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 3713:                 }
 3714:             }
 3715:             $resulttext .= '</ul>';
 3716:         } else {
 3717:             $resulttext = &mt('No changes made to auto-enrollment settings');
 3718:         }
 3719:     } else {
 3720:         $resulttext = '<span class="LC_error">'.
 3721: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 3722:     }
 3723:     return $resulttext;
 3724: }
 3725: 
 3726: sub modify_autoupdate {
 3727:     my ($dom,%domconfig) = @_;
 3728:     my ($resulttext,%currautoupdate,%fields,%changes);
 3729:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 3730:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 3731:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 3732:         }
 3733:     }
 3734:     my @offon = ('off','on');
 3735:     my %title = &Apache::lonlocal::texthash (
 3736:                    run => 'Auto-update:',
 3737:                    classlists => 'Updates to user information in classlists?'
 3738:                 );
 3739:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 3740:     my %fieldtitles = &Apache::lonlocal::texthash (
 3741:                         id => 'Student/Employee ID',
 3742:                         permanentemail => 'E-mail address',
 3743:                         lastname => 'Last Name',
 3744:                         firstname => 'First Name',
 3745:                         middlename => 'Middle Name',
 3746:                         gen => 'Generation',
 3747:                       );
 3748:     my $othertitle = &mt('All users');
 3749:     if (keys(%{$usertypes}) >  0) {
 3750:         $othertitle = &mt('Other users');
 3751:     }
 3752:     foreach my $key (keys(%env)) {
 3753:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 3754:             push(@{$fields{$1}},$2);
 3755:         }
 3756:     }
 3757:     my %updatehash = (
 3758:                       autoupdate => { run => $env{'form.autoupdate_run'},
 3759:                                       classlists => $env{'form.classlists'},
 3760:                                       fields => {%fields},
 3761:                                     }
 3762:                      );
 3763:     foreach my $key (keys(%currautoupdate)) {
 3764:         if (($key eq 'run') || ($key eq 'classlists')) {
 3765:             if (exists($updatehash{autoupdate}{$key})) {
 3766:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 3767:                     $changes{$key} = 1;
 3768:                 }
 3769:             }
 3770:         } elsif ($key eq 'fields') {
 3771:             if (ref($currautoupdate{$key}) eq 'HASH') {
 3772:                 foreach my $item (@{$types},'default') {
 3773:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 3774:                         my $change = 0;
 3775:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 3776:                             if (!exists($fields{$item})) {
 3777:                                 $change = 1;
 3778:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 3779:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
 3780:                                     $change = 1;
 3781:                                 }
 3782:                             }
 3783:                         }
 3784:                         if ($change) {
 3785:                             push(@{$changes{$key}},$item);
 3786:                         }
 3787:                     } 
 3788:                 }
 3789:             }
 3790:         }
 3791:     }
 3792:     foreach my $item (@{$types},'default') {
 3793:         if (defined($fields{$item})) {
 3794:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
 3795:                 if (!exists($currautoupdate{'fields'}{$item})) {
 3796:                     push(@{$changes{'fields'}},$item);
 3797:                 }
 3798:             } else {
 3799:                 push(@{$changes{'fields'}},$item);
 3800:             }
 3801:         }
 3802:     }
 3803:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 3804:                                              $dom);
 3805:     if ($putresult eq 'ok') {
 3806:         if (keys(%changes) > 0) {
 3807:             $resulttext = &mt('Changes made:').'<ul>';
 3808:             foreach my $key (sort(keys(%changes))) {
 3809:                 if (ref($changes{$key}) eq 'ARRAY') {
 3810:                     foreach my $item (@{$changes{$key}}) {
 3811:                         my @newvalues;
 3812:                         foreach my $type (@{$fields{$item}}) {
 3813:                             push(@newvalues,$fieldtitles{$type});
 3814:                         }
 3815:                         my $newvaluestr;
 3816:                         if (@newvalues > 0) {
 3817:                             $newvaluestr = join(', ',@newvalues);
 3818:                         } else {
 3819:                             $newvaluestr = &mt('none');
 3820:                         }
 3821:                         if ($item eq 'default') {
 3822:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
 3823:                         } else {
 3824:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
 3825:                         }
 3826:                     }
 3827:                 } else {
 3828:                     my $newvalue;
 3829:                     if ($key eq 'run') {
 3830:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 3831:                     } else {
 3832:                         $newvalue = $offon[$env{'form.'.$key}];
 3833:                     }
 3834:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 3835:                 }
 3836:             }
 3837:             $resulttext .= '</ul>';
 3838:         } else {
 3839:             $resulttext = &mt('No changes made to autoupdates');
 3840:         }
 3841:     } else {
 3842:         $resulttext = '<span class="LC_error">'.
 3843: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 3844:     }
 3845:     return $resulttext;
 3846: }
 3847: 
 3848: sub modify_directorysrch {
 3849:     my ($dom,%domconfig) = @_;
 3850:     my ($resulttext,%changes);
 3851:     my %currdirsrch;
 3852:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
 3853:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
 3854:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
 3855:         }
 3856:     }
 3857:     my %title = ( available => 'Directory search available',
 3858:                   localonly => 'Other domains can search',
 3859:                   searchby => 'Search types',
 3860:                   searchtypes => 'Search latitude');
 3861:     my @offon = ('off','on');
 3862:     my @otherdoms = ('Yes','No');
 3863: 
 3864:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
 3865:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
 3866:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
 3867: 
 3868:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 3869:     if (keys(%{$usertypes}) == 0) {
 3870:         @cansearch = ('default');
 3871:     } else {
 3872:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
 3873:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
 3874:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
 3875:                     push(@{$changes{'cansearch'}},$type);
 3876:                 }
 3877:             }
 3878:             foreach my $type (@cansearch) {
 3879:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
 3880:                     push(@{$changes{'cansearch'}},$type);
 3881:                 }
 3882:             }
 3883:         } else {
 3884:             push(@{$changes{'cansearch'}},@cansearch);
 3885:         }
 3886:     }
 3887: 
 3888:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
 3889:         foreach my $by (@{$currdirsrch{'searchby'}}) {
 3890:             if (!grep(/^\Q$by\E$/,@searchby)) {
 3891:                 push(@{$changes{'searchby'}},$by);
 3892:             }
 3893:         }
 3894:         foreach my $by (@searchby) {
 3895:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
 3896:                 push(@{$changes{'searchby'}},$by);
 3897:             }
 3898:         }
 3899:     } else {
 3900:         push(@{$changes{'searchby'}},@searchby);
 3901:     }
 3902: 
 3903:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
 3904:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
 3905:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
 3906:                 push(@{$changes{'searchtypes'}},$type);
 3907:             }
 3908:         }
 3909:         foreach my $type (@searchtypes) {
 3910:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
 3911:                 push(@{$changes{'searchtypes'}},$type);
 3912:             }
 3913:         }
 3914:     } else {
 3915:         if (exists($currdirsrch{'searchtypes'})) {
 3916:             foreach my $type (@searchtypes) {  
 3917:                 if ($type ne $currdirsrch{'searchtypes'}) { 
 3918:                     push(@{$changes{'searchtypes'}},$type);
 3919:                 }
 3920:             }
 3921:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
 3922:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
 3923:             }   
 3924:         } else {
 3925:             push(@{$changes{'searchtypes'}},@searchtypes); 
 3926:         }
 3927:     }
 3928: 
 3929:     my %dirsrch_hash =  (
 3930:             directorysrch => { available => $env{'form.dirsrch_available'},
 3931:                                cansearch => \@cansearch,
 3932:                                localonly => $env{'form.dirsrch_localonly'},
 3933:                                searchby => \@searchby,
 3934:                                searchtypes => \@searchtypes,
 3935:                              }
 3936:             );
 3937:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
 3938:                                              $dom);
 3939:     if ($putresult eq 'ok') {
 3940:         if (exists($currdirsrch{'available'})) {
 3941:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
 3942:                  $changes{'available'} = 1;
 3943:              }
 3944:         } else {
 3945:             if ($env{'form.dirsrch_available'} eq '1') {
 3946:                 $changes{'available'} = 1;
 3947:             }
 3948:         }
 3949:         if (exists($currdirsrch{'localonly'})) {
 3950:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
 3951:                  $changes{'localonly'} = 1;
 3952:              }
 3953:         } else {
 3954:             if ($env{'form.dirsrch_localonly'} eq '1') {
 3955:                 $changes{'localonly'} = 1;
 3956:             }
 3957:         }
 3958:         if (keys(%changes) > 0) {
 3959:             $resulttext = &mt('Changes made:').'<ul>';
 3960:             if ($changes{'available'}) {
 3961:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
 3962:             }
 3963:             if ($changes{'localonly'}) {
 3964:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
 3965:             }
 3966: 
 3967:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
 3968:                 my $chgtext;
 3969:                 if (ref($usertypes) eq 'HASH') {
 3970:                     if (keys(%{$usertypes}) > 0) {
 3971:                         foreach my $type (@{$types}) {
 3972:                             if (grep(/^\Q$type\E$/,@cansearch)) {
 3973:                                 $chgtext .= $usertypes->{$type}.'; ';
 3974:                             }
 3975:                         }
 3976:                         if (grep(/^default$/,@cansearch)) {
 3977:                             $chgtext .= $othertitle;
 3978:                         } else {
 3979:                             $chgtext =~ s/\; $//;
 3980:                         }
 3981:                         $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>';
 3982:                     }
 3983:                 }
 3984:             }
 3985:             if (ref($changes{'searchby'}) eq 'ARRAY') {
 3986:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
 3987:                 my $chgtext;
 3988:                 foreach my $type (@{$titleorder}) {
 3989:                     if (grep(/^\Q$type\E$/,@searchby)) {
 3990:                         if (defined($searchtitles->{$type})) {
 3991:                             $chgtext .= $searchtitles->{$type}.'; ';
 3992:                         }
 3993:                     }
 3994:                 }
 3995:                 $chgtext =~ s/\; $//;
 3996:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
 3997:             }
 3998:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
 3999:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
 4000:                 my $chgtext;
 4001:                 foreach my $type (@{$srchtypeorder}) {
 4002:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
 4003:                         if (defined($srchtypes_desc->{$type})) {
 4004:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
 4005:                         }
 4006:                     }
 4007:                 }
 4008:                 $chgtext =~ s/\; $//;
 4009:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
 4010:             }
 4011:             $resulttext .= '</ul>';
 4012:         } else {
 4013:             $resulttext = &mt('No changes made to institution directory search settings');
 4014:         }
 4015:     } else {
 4016:         $resulttext = '<span class="LC_error">'.
 4017:                       &mt('An error occurred: [_1]',$putresult).'</span>';
 4018:     }
 4019:     return $resulttext;
 4020: }
 4021: 
 4022: sub modify_contacts {
 4023:     my ($dom,%domconfig) = @_;
 4024:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
 4025:     if (ref($domconfig{'contacts'}) eq 'HASH') {
 4026:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
 4027:             $currsetting{$key} = $domconfig{'contacts'}{$key};
 4028:         }
 4029:     }
 4030:     my (%others,%to);
 4031:     my @contacts = ('supportemail','adminemail');
 4032:     my @mailings = ('errormail','packagesmail','helpdeskmail');
 4033:     foreach my $type (@mailings) {
 4034:         @{$newsetting{$type}} = 
 4035:             &Apache::loncommon::get_env_multiple('form.'.$type);
 4036:         foreach my $item (@contacts) {
 4037:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
 4038:                 $contacts_hash{contacts}{$type}{$item} = 1;
 4039:             } else {
 4040:                 $contacts_hash{contacts}{$type}{$item} = 0;
 4041:             }
 4042:         }  
 4043:         $others{$type} = $env{'form.'.$type.'_others'};
 4044:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
 4045:     }
 4046:     foreach my $item (@contacts) {
 4047:         $to{$item} = $env{'form.'.$item};
 4048:         $contacts_hash{'contacts'}{$item} = $to{$item};
 4049:     }
 4050:     if (keys(%currsetting) > 0) {
 4051:         foreach my $item (@contacts) {
 4052:             if ($to{$item} ne $currsetting{$item}) {
 4053:                 $changes{$item} = 1;
 4054:             }
 4055:         }
 4056:         foreach my $type (@mailings) {
 4057:             foreach my $item (@contacts) {
 4058:                 if (ref($currsetting{$type}) eq 'HASH') {
 4059:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
 4060:                         push(@{$changes{$type}},$item);
 4061:                     }
 4062:                 } else {
 4063:                     push(@{$changes{$type}},@{$newsetting{$type}});
 4064:                 }
 4065:             }
 4066:             if ($others{$type} ne $currsetting{$type}{'others'}) {
 4067:                 push(@{$changes{$type}},'others');
 4068:             }
 4069:         }
 4070:     } else {
 4071:         my %default;
 4072:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 4073:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 4074:         $default{'errormail'} = 'adminemail';
 4075:         $default{'packagesmail'} = 'adminemail';
 4076:         $default{'helpdeskmail'} = 'supportemail';
 4077:         foreach my $item (@contacts) {
 4078:            if ($to{$item} ne $default{$item}) {
 4079:               $changes{$item} = 1;
 4080:            } 
 4081:         }
 4082:         foreach my $type (@mailings) {
 4083:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
 4084:                
 4085:                 push(@{$changes{$type}},@{$newsetting{$type}});
 4086:             }
 4087:             if ($others{$type} ne '') {
 4088:                 push(@{$changes{$type}},'others');
 4089:             } 
 4090:         }
 4091:     }
 4092:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
 4093:                                              $dom);
 4094:     if ($putresult eq 'ok') {
 4095:         if (keys(%changes) > 0) {
 4096:             my ($titles,$short_titles)  = &contact_titles();
 4097:             $resulttext = &mt('Changes made:').'<ul>';
 4098:             foreach my $item (@contacts) {
 4099:                 if ($changes{$item}) {
 4100:                     $resulttext .= '<li>'.$titles->{$item}.
 4101:                                     &mt(' set to: ').
 4102:                                     '<span class="LC_cusr_emph">'.
 4103:                                     $to{$item}.'</span></li>';
 4104:                 }
 4105:             }
 4106:             foreach my $type (@mailings) {
 4107:                 if (ref($changes{$type}) eq 'ARRAY') {
 4108:                     $resulttext .= '<li>'.$titles->{$type}.': ';
 4109:                     my @text;
 4110:                     foreach my $item (@{$newsetting{$type}}) {
 4111:                         push(@text,$short_titles->{$item});
 4112:                     }
 4113:                     if ($others{$type} ne '') {
 4114:                         push(@text,$others{$type});
 4115:                     }
 4116:                     $resulttext .= '<span class="LC_cusr_emph">'.
 4117:                                    join(', ',@text).'</span></li>';
 4118:                 }
 4119:             }
 4120:             $resulttext .= '</ul>';
 4121:         } else {
 4122:             $resulttext = &mt('No changes made to contact information');
 4123:         }
 4124:     } else {
 4125:         $resulttext = '<span class="LC_error">'.
 4126:             &mt('An error occurred: [_1].',$putresult).'</span>';
 4127:     }
 4128:     return $resulttext;
 4129: }
 4130: 
 4131: sub modify_usercreation {
 4132:     my ($dom,%domconfig) = @_;
 4133:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
 4134:     my $warningmsg;
 4135:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 4136:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 4137:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 4138:         }
 4139:     }
 4140:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
 4141:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
 4142:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
 4143:     my @contexts = ('author','course','selfcreate');
 4144:     foreach my $item(@contexts) {
 4145:         if ($item eq 'selfcreate') {
 4146:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
 4147:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 4148:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
 4149:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
 4150:                     if (grep(/^login$/,@{$cancreate{$item}})) {
 4151:                         $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.');   
 4152:                     }
 4153:                 }
 4154:             }
 4155:         } else {
 4156:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
 4157:         }
 4158:     }
 4159:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 4160:         foreach my $item (@contexts) {
 4161:             if ($item eq 'selfcreate') {
 4162:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') { 
 4163:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
 4164:                         if (!grep(/^$curr$/,@{$cancreate{$item}})) {
 4165:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 4166:                                 push(@{$changes{'cancreate'}},$item);
 4167:                             }
 4168:                         }
 4169:                     }
 4170:                 } else {
 4171:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
 4172:                         if (@{$cancreate{$item}} > 0) {
 4173:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 4174:                                 push(@{$changes{'cancreate'}},$item);
 4175:                             }
 4176:                         }
 4177:                     } else {
 4178:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
 4179:                             if (@{$cancreate{$item}} < 3) {
 4180:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 4181:                                     push(@{$changes{'cancreate'}},$item);
 4182:                                 }
 4183:                             }
 4184:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
 4185:                             if (@{$cancreate{$item}} > 0) {
 4186:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 4187:                                     push(@{$changes{'cancreate'}},$item);
 4188:                                 }
 4189:                             }
 4190:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
 4191:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 4192:                                 push(@{$changes{'cancreate'}},$item);
 4193:                             }
 4194:                         }
 4195:                     }
 4196:                 }
 4197:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 4198:                     foreach my $type (@{$cancreate{$item}}) {
 4199:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 4200:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
 4201:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 4202:                                     push(@{$changes{'cancreate'}},$item);
 4203:                                 }
 4204:                             }
 4205:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
 4206:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
 4207:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
 4208:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 4209:                                     push(@{$changes{'cancreate'}},$item);
 4210:                                 }
 4211:                             }
 4212:                         }
 4213:                     }
 4214:                 }
 4215:             } else {
 4216:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
 4217:                     push(@{$changes{'cancreate'}},$item);
 4218:                 }
 4219:             }
 4220:         }
 4221:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
 4222:         foreach my $item (@contexts) {
 4223:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
 4224:                 if ($cancreate{$item} ne 'any') {
 4225:                     push(@{$changes{'cancreate'}},$item);
 4226:                 }
 4227:             } else {
 4228:                 if ($cancreate{$item} ne 'none') {
 4229:                     push(@{$changes{'cancreate'}},$item);
 4230:                 }
 4231:             }
 4232:         }
 4233:     } else {
 4234:         foreach my $item (@contexts)  {
 4235:             push(@{$changes{'cancreate'}},$item);
 4236:         }
 4237:     }
 4238: 
 4239:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
 4240:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
 4241:             if (!grep(/^\Q$type\E$/,@username_rule)) {
 4242:                 push(@{$changes{'username_rule'}},$type);
 4243:             }
 4244:         }
 4245:         foreach my $type (@username_rule) {
 4246:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
 4247:                 push(@{$changes{'username_rule'}},$type);
 4248:             }
 4249:         }
 4250:     } else {
 4251:         push(@{$changes{'username_rule'}},@username_rule);
 4252:     }
 4253: 
 4254:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
 4255:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
 4256:             if (!grep(/^\Q$type\E$/,@id_rule)) {
 4257:                 push(@{$changes{'id_rule'}},$type);
 4258:             }
 4259:         }
 4260:         foreach my $type (@id_rule) {
 4261:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
 4262:                 push(@{$changes{'id_rule'}},$type);
 4263:             }
 4264:         }
 4265:     } else {
 4266:         push(@{$changes{'id_rule'}},@id_rule);
 4267:     }
 4268: 
 4269:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
 4270:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
 4271:             if (!grep(/^\Q$type\E$/,@email_rule)) {
 4272:                 push(@{$changes{'email_rule'}},$type);
 4273:             }
 4274:         }
 4275:         foreach my $type (@email_rule) {
 4276:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
 4277:                 push(@{$changes{'email_rule'}},$type);
 4278:             }
 4279:         }
 4280:     } else {
 4281:         push(@{$changes{'email_rule'}},@email_rule);
 4282:     }
 4283: 
 4284:     my @authen_contexts = ('author','course','domain');
 4285:     my @authtypes = ('int','krb4','krb5','loc');
 4286:     my %authhash;
 4287:     foreach my $item (@authen_contexts) {
 4288:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
 4289:         foreach my $auth (@authtypes) {
 4290:             if (grep(/^\Q$auth\E$/,@authallowed)) {
 4291:                 $authhash{$item}{$auth} = 1;
 4292:             } else {
 4293:                 $authhash{$item}{$auth} = 0;
 4294:             }
 4295:         }
 4296:     }
 4297:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
 4298:         foreach my $item (@authen_contexts) {
 4299:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
 4300:                 foreach my $auth (@authtypes) {
 4301:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
 4302:                         push(@{$changes{'authtypes'}},$item);
 4303:                         last;
 4304:                     }
 4305:                 }
 4306:             }
 4307:         }
 4308:     } else {
 4309:         foreach my $item (@authen_contexts) {
 4310:             push(@{$changes{'authtypes'}},$item);
 4311:         }
 4312:     }
 4313: 
 4314:     my %usercreation_hash =  (
 4315:             usercreation => {
 4316:                               cancreate     => \%cancreate,
 4317:                               username_rule => \@username_rule,
 4318:                               id_rule       => \@id_rule,
 4319:                               email_rule    => \@email_rule,
 4320:                               authtypes     => \%authhash,
 4321:                             }
 4322:             );
 4323: 
 4324:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
 4325:                                              $dom);
 4326: 
 4327:     my %selfcreatetypes = (
 4328:                              sso   => 'users authenticated by institutional single sign on',
 4329:                              login => 'users authenticated by institutional log-in',
 4330:                              email => 'users who provide a valid e-mail address for use as the username',
 4331:                           );
 4332:     if ($putresult eq 'ok') {
 4333:         if (keys(%changes) > 0) {
 4334:             $resulttext = &mt('Changes made:').'<ul>';
 4335:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 4336:                 my %lt = &usercreation_types();
 4337:                 foreach my $type (@{$changes{'cancreate'}}) {
 4338:                     my $chgtext =  $lt{$type}.', ';
 4339:                     if ($type eq 'selfcreate') {
 4340:                         if (@{$cancreate{$type}} == 0) {
 4341:                             $chgtext .= &mt('creation of a new user account is not permitted.');
 4342:                         } else {
 4343:                             $chgtext .= &mt('creation of a new account is permitted for:<ul>');
 4344:                             foreach my $case (@{$cancreate{$type}}) {
 4345:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
 4346:                             }
 4347:                             $chgtext .= '</ul>';
 4348:                         }
 4349:                     } else {
 4350:                         if ($cancreate{$type} eq 'none') {
 4351:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
 4352:                         } elsif ($cancreate{$type} eq 'any') {
 4353:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
 4354:                         } elsif ($cancreate{$type} eq 'official') {
 4355:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
 4356:                         } elsif ($cancreate{$type} eq 'unofficial') {
 4357:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
 4358:                         }
 4359:                     }
 4360:                     $resulttext .= '<li>'.$chgtext.'</li>';
 4361:                 }
 4362:             }
 4363:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
 4364:                 my ($rules,$ruleorder) = 
 4365:                     &Apache::lonnet::inst_userrules($dom,'username');
 4366:                 my $chgtext = '<ul>';
 4367:                 foreach my $type (@username_rule) {
 4368:                     if (ref($rules->{$type}) eq 'HASH') {
 4369:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
 4370:                     }
 4371:                 }
 4372:                 $chgtext .= '</ul>';
 4373:                 if (@username_rule > 0) {
 4374:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
 4375:                 } else {
 4376:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
 4377:                 }
 4378:             }
 4379:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
 4380:                 my ($idrules,$idruleorder) = 
 4381:                     &Apache::lonnet::inst_userrules($dom,'id');
 4382:                 my $chgtext = '<ul>';
 4383:                 foreach my $type (@id_rule) {
 4384:                     if (ref($idrules->{$type}) eq 'HASH') {
 4385:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
 4386:                     }
 4387:                 }
 4388:                 $chgtext .= '</ul>';
 4389:                 if (@id_rule > 0) {
 4390:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
 4391:                 } else {
 4392:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
 4393:                 }
 4394:             }
 4395:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
 4396:                 my ($emailrules,$emailruleorder) =
 4397:                     &Apache::lonnet::inst_userrules($dom,'email');
 4398:                 my $chgtext = '<ul>';
 4399:                 foreach my $type (@email_rule) {
 4400:                     if (ref($emailrules->{$type}) eq 'HASH') {
 4401:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
 4402:                     }
 4403:                 }
 4404:                 $chgtext .= '</ul>';
 4405:                 if (@email_rule > 0) {
 4406:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
 4407:                 } else {
 4408:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
 4409:                 }
 4410:             }
 4411: 
 4412:             my %authname = &authtype_names();
 4413:             my %context_title = &context_names();
 4414:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
 4415:                 my $chgtext = '<ul>';
 4416:                 foreach my $type (@{$changes{'authtypes'}}) {
 4417:                     my @allowed;
 4418:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
 4419:                     foreach my $auth (@authtypes) {
 4420:                         if ($authhash{$type}{$auth}) {
 4421:                             push(@allowed,$authname{$auth});
 4422:                         }
 4423:                     }
 4424:                     if (@allowed > 0) {
 4425:                         $chgtext .= join(', ',@allowed).'</li>';
 4426:                     } else {
 4427:                         $chgtext .= &mt('none').'</li>';
 4428:                     }
 4429:                 }
 4430:                 $chgtext .= '</ul>';
 4431:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
 4432:                 $resulttext .= '</li>';
 4433:             }
 4434:             $resulttext .= '</ul>';
 4435:         } else {
 4436:             $resulttext = &mt('No changes made to user creation settings');
 4437:         }
 4438:     } else {
 4439:         $resulttext = '<span class="LC_error">'.
 4440:             &mt('An error occurred: [_1]',$putresult).'</span>';
 4441:     }
 4442:     if ($warningmsg ne '') {
 4443:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
 4444:     }
 4445:     return $resulttext;
 4446: }
 4447: 
 4448: sub modify_usermodification {
 4449:     my ($dom,%domconfig) = @_;
 4450:     my ($resulttext,%curr_usermodification,%changes);
 4451:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 4452:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 4453:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
 4454:         }
 4455:     }
 4456:     my @contexts = ('author','course','selfcreate');
 4457:     my %context_title = (
 4458:                            author => 'In author context',
 4459:                            course => 'In course context',
 4460:                            selfcreate => 'When self creating account', 
 4461:                         );
 4462:     my @fields = ('lastname','firstname','middlename','generation',
 4463:                   'permanentemail','id');
 4464:     my %roles = (
 4465:                   author => ['ca','aa'],
 4466:                   course => ['st','ep','ta','in','cr'],
 4467:                 );
 4468:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 4469:     if (ref($types) eq 'ARRAY') {
 4470:         push(@{$types},'default');
 4471:         $usertypes->{'default'} = $othertitle;
 4472:     }
 4473:     $roles{'selfcreate'} = $types;  
 4474:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 4475:     my %modifyhash;
 4476:     foreach my $context (@contexts) {
 4477:         foreach my $role (@{$roles{$context}}) {
 4478:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
 4479:             foreach my $item (@fields) {
 4480:                 if (grep(/^\Q$item\E$/,@modifiable)) {
 4481:                     $modifyhash{$context}{$role}{$item} = 1;
 4482:                 } else {
 4483:                     $modifyhash{$context}{$role}{$item} = 0;
 4484:                 }
 4485:             }
 4486:         }
 4487:         if (ref($curr_usermodification{$context}) eq 'HASH') {
 4488:             foreach my $role (@{$roles{$context}}) {
 4489:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
 4490:                     foreach my $field (@fields) {
 4491:                         if ($modifyhash{$context}{$role}{$field} ne 
 4492:                                 $curr_usermodification{$context}{$role}{$field}) {
 4493:                             push(@{$changes{$context}},$role);
 4494:                             last;
 4495:                         }
 4496:                     }
 4497:                 }
 4498:             }
 4499:         } else {
 4500:             foreach my $context (@contexts) {
 4501:                 foreach my $role (@{$roles{$context}}) {
 4502:                     push(@{$changes{$context}},$role);
 4503:                 }
 4504:             }
 4505:         }
 4506:     }
 4507:     my %usermodification_hash =  (
 4508:                                    usermodification => \%modifyhash,
 4509:                                  );
 4510:     my $putresult = &Apache::lonnet::put_dom('configuration',
 4511:                                              \%usermodification_hash,$dom);
 4512:     if ($putresult eq 'ok') {
 4513:         if (keys(%changes) > 0) {
 4514:             $resulttext = &mt('Changes made: ').'<ul>';
 4515:             foreach my $context (@contexts) {
 4516:                 if (ref($changes{$context}) eq 'ARRAY') {
 4517:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
 4518:                     if (ref($changes{$context}) eq 'ARRAY') {
 4519:                         foreach my $role (@{$changes{$context}}) {
 4520:                             my $rolename;
 4521:                             if ($context eq 'selfcreate') {
 4522:                                 $rolename = $role;
 4523:                                 if (ref($usertypes) eq 'HASH') {
 4524:                                     if ($usertypes->{$role} ne '') {
 4525:                                         $rolename = $usertypes->{$role};
 4526:                                     }
 4527:                                 }
 4528:                             } else {
 4529:                                 if ($role eq 'cr') {
 4530:                                     $rolename = &mt('Custom');
 4531:                                 } else {
 4532:                                     $rolename = &Apache::lonnet::plaintext($role);
 4533:                                 }
 4534:                             }
 4535:                             my @modifiable;
 4536:                             if ($context eq 'selfcreate') {
 4537:                                 $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): ');
 4538:                             } else {
 4539:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
 4540:                             }
 4541:                             foreach my $field (@fields) {
 4542:                                 if ($modifyhash{$context}{$role}{$field}) {
 4543:                                     push(@modifiable,$fieldtitles{$field});
 4544:                                 }
 4545:                             }
 4546:                             if (@modifiable > 0) {
 4547:                                 $resulttext .= join(', ',@modifiable);
 4548:                             } else {
 4549:                                 $resulttext .= &mt('none'); 
 4550:                             }
 4551:                             $resulttext .= '</li>';
 4552:                         }
 4553:                         $resulttext .= '</ul></li>';
 4554:                     }
 4555:                 }
 4556:             }
 4557:             $resulttext .= '</ul>';
 4558:         } else {
 4559:             $resulttext = &mt('No changes made to user modification settings');
 4560:         }
 4561:     } else {
 4562:         $resulttext = '<span class="LC_error">'.
 4563:             &mt('An error occurred: [_1]',$putresult).'</span>';
 4564:     }
 4565:     return $resulttext;
 4566: }
 4567: 
 4568: sub modify_defaults {
 4569:     my ($dom,$r) = @_;
 4570:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
 4571:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 4572:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
 4573:     my @authtypes = ('internal','krb4','krb5','localauth');
 4574:     foreach my $item (@items) {
 4575:         $newvalues{$item} = $env{'form.'.$item};
 4576:         if ($item eq 'auth_def') {
 4577:             if ($newvalues{$item} ne '') {
 4578:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
 4579:                     push(@errors,$item);
 4580:                 }
 4581:             }
 4582:         } elsif ($item eq 'lang_def') {
 4583:             if ($newvalues{$item} ne '') {
 4584:                 if ($newvalues{$item} =~ /^(\w+)/) {
 4585:                     my $langcode = $1;
 4586:                     if (code2language($langcode) eq '') {
 4587:                         push(@errors,$item);
 4588:                     }
 4589:                 } else {
 4590:                     push(@errors,$item);
 4591:                 }
 4592:             }
 4593:         } elsif ($item eq 'timezone_def') {
 4594:             if ($newvalues{$item} ne '') {
 4595:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
 4596:                     push(@errors,$item);   
 4597:                 }
 4598:             }
 4599:         } elsif ($item eq 'datelocale_def') {
 4600:             if ($newvalues{$item} ne '') {
 4601:                 my @datelocale_ids = DateTime::Locale->ids();
 4602:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
 4603:                     push(@errors,$item);
 4604:                 }
 4605:             }
 4606:         }
 4607:         if (grep(/^\Q$item\E$/,@errors)) {
 4608:             $newvalues{$item} = $domdefaults{$item};
 4609:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
 4610:             $changes{$item} = 1;
 4611:         }
 4612:         $domdefaults{$item} = $newvalues{$item};
 4613:     }
 4614:     my %defaults_hash = (
 4615:                          defaults => \%newvalues,
 4616:                         );
 4617:     my $title = &defaults_titles();
 4618:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
 4619:                                              $dom);
 4620:     if ($putresult eq 'ok') {
 4621:         if (keys(%changes) > 0) {
 4622:             $resulttext = &mt('Changes made:').'<ul>';
 4623:             my $version = $r->dir_config('lonVersion');
 4624:             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";
 4625:             foreach my $item (sort(keys(%changes))) {
 4626:                 my $value = $env{'form.'.$item};
 4627:                 if ($value eq '') {
 4628:                     $value = &mt('none');
 4629:                 } elsif ($item eq 'auth_def') {
 4630:                     my %authnames = &authtype_names();
 4631:                     my %shortauth = (
 4632:                              internal => 'int',
 4633:                              krb4 => 'krb4',
 4634:                              krb5 => 'krb5',
 4635:                              localauth  => 'loc',
 4636:                     );
 4637:                     $value = $authnames{$shortauth{$value}};
 4638:                 }
 4639:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
 4640:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
 4641:             }
 4642:             $resulttext .= '</ul>';
 4643:             $mailmsgtext .= "\n";
 4644:             my $cachetime = 24*60*60;
 4645:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 4646:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
 4647:                 my $sysmail = $r->dir_config('lonSysEMail');
 4648:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
 4649:             }
 4650:         } else {
 4651:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
 4652:         }
 4653:     } else {
 4654:         $resulttext = '<span class="LC_error">'.
 4655:             &mt('An error occurred: [_1]',$putresult).'</span>';
 4656:     }
 4657:     if (@errors > 0) {
 4658:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
 4659:         foreach my $item (@errors) {
 4660:             $resulttext .= ' "'.$title->{$item}.'",';
 4661:         }
 4662:         $resulttext =~ s/,$//;
 4663:     }
 4664:     return $resulttext;
 4665: }
 4666: 
 4667: sub modify_scantron {
 4668:     my ($r,$dom,$confname,%domconfig) = @_;
 4669:     my ($resulttext,%confhash,%changes,$errors);
 4670:     my $custom = 'custom.tab';
 4671:     my $default = 'default.tab';
 4672:     my $servadm = $r->dir_config('lonAdmEMail');
 4673:     my ($configuserok,$author_ok,$switchserver) = 
 4674:         &config_check($dom,$confname,$servadm);
 4675:     if ($env{'form.scantronformat.filename'} ne '') {
 4676:         my $error;
 4677:         if ($configuserok eq 'ok') {
 4678:             if ($switchserver) {
 4679:                 $error = &mt("Upload of scantron format file is not permitted to this server: [_1]",$switchserver);
 4680:             } else {
 4681:                 if ($author_ok eq 'ok') {
 4682:                     my ($result,$scantronurl) =
 4683:                         &publishlogo($r,'upload','scantronformat',$dom,
 4684:                                      $confname,'scantron','','',$custom);
 4685:                     if ($result eq 'ok') {
 4686:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
 4687:                         $changes{'scantronformat'} = 1;
 4688:                     } else {
 4689:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
 4690:                     }
 4691:                 } else {
 4692:                     $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);
 4693:                 }
 4694:             }
 4695:         } else {
 4696:             $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);
 4697:         }
 4698:         if ($error) {
 4699:             &Apache::lonnet::logthis($error);
 4700:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 4701:         }
 4702:     }
 4703:     if (ref($domconfig{'scantron'}) eq 'HASH') {
 4704:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
 4705:             if ($env{'form.scantronformat_del'}) {
 4706:                 $confhash{'scantron'}{'scantronformat'} = '';
 4707:                 $changes{'scantronformat'} = 1;
 4708:             }
 4709:         }
 4710:     }
 4711:     if (keys(%confhash) > 0) {
 4712:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
 4713:                                                  $dom);
 4714:         if ($putresult eq 'ok') {
 4715:             if (keys(%changes) > 0) {
 4716:                 if (ref($confhash{'scantron'}) eq 'HASH') {
 4717:                     $resulttext = &mt('Changes made:').'<ul>';
 4718:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
 4719:                         $resulttext .= '<li>'.&mt('[_1] scantron format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
 4720:                     } else {
 4721:                         $resulttext .= '<li>'.&mt('Custom scantron format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
 4722:                     }
 4723:                     $resulttext .= '</ul>';
 4724:                 } else {
 4725:                     $resulttext = &mt('Changes made to scantron format file.');
 4726:                 }
 4727:                 $resulttext .= '</ul>';
 4728:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 4729:             } else {
 4730:                 $resulttext = &mt('No changes made to scantron format file');
 4731:             }
 4732:         } else {
 4733:             $resulttext = '<span class="LC_error">'.
 4734:                 &mt('An error occurred: [_1]',$putresult).'</span>';
 4735:         }
 4736:     } else {
 4737:         $resulttext = &mt('No changes made to scantron format file'); 
 4738:     }
 4739:     if ($errors) {
 4740:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 4741:                        $errors.'</ul>';
 4742:     }
 4743:     return $resulttext;
 4744: }
 4745: 
 4746: sub modify_coursecategories {
 4747:     my ($dom,%domconfig) = @_;
 4748:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
 4749:         $cathash);
 4750:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
 4751:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 4752:         $cathash = $domconfig{'coursecategories'}{'cats'};
 4753:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
 4754:             $changes{'togglecats'} = 1;
 4755:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
 4756:         }
 4757:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
 4758:             $changes{'categorize'} = 1;
 4759:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
 4760:         }
 4761:     } else {
 4762:         $changes{'togglecats'} = 1;
 4763:         $changes{'categorize'} = 1;
 4764:         $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
 4765:         $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
 4766:     }
 4767:     if (ref($cathash) eq 'HASH') {
 4768:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
 4769:             push (@deletecategory,'instcode::0');
 4770:         }
 4771:     }
 4772:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
 4773:     if (ref($cathash) eq 'HASH') {
 4774:         if (@deletecategory > 0) {
 4775:             #FIXME Need to remove category from all courses using a deleted category 
 4776:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
 4777:             foreach my $item (@deletecategory) {
 4778:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
 4779:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
 4780:                     $deletions{$item} = 1;
 4781:                     &recurse_cat_deletes($item,$cathash,\%deletions);
 4782:                 }
 4783:             }
 4784:         }
 4785:         foreach my $item (keys(%{$cathash})) {
 4786:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 4787:             if ($cathash->{$item} ne $env{'form.'.$item}) {
 4788:                 $reorderings{$item} = 1;
 4789:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
 4790:             }
 4791:             if ($env{'form.addcategory_name_'.$item} ne '') {
 4792:                 my $newcat = $env{'form.addcategory_name_'.$item};
 4793:                 my $newdepth = $depth+1;
 4794:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 4795:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
 4796:                 $adds{$newitem} = 1; 
 4797:             }
 4798:             if ($env{'form.subcat_'.$item} ne '') {
 4799:                 my $newcat = $env{'form.subcat_'.$item};
 4800:                 my $newdepth = $depth+1;
 4801:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 4802:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
 4803:                 $adds{$newitem} = 1;
 4804:             }
 4805:         }
 4806:     }
 4807:     if ($env{'form.instcode'} eq '1') {
 4808:         if (ref($cathash) eq 'HASH') {
 4809:             my $newitem = 'instcode::0';
 4810:             if ($cathash->{$newitem} eq '') {  
 4811:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 4812:                 $adds{$newitem} = 1;
 4813:             }
 4814:         } else {
 4815:             my $newitem = 'instcode::0';
 4816:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 4817:             $adds{$newitem} = 1;
 4818:         }
 4819:     }
 4820:     if ($env{'form.addcategory_name'} ne '') {
 4821:         my $newitem = &escape($env{'form.addcategory_name'}).'::0';
 4822:         $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
 4823:         $adds{$newitem} = 1;
 4824:     }
 4825:     my $putresult;
 4826:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 4827:         if (keys(%deletions) > 0) {
 4828:             foreach my $key (keys(%deletions)) {
 4829:                 if ($predelallitems{$key} ne '') {
 4830:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
 4831:                 }
 4832:             }
 4833:         }
 4834:         my (@chkcats,@chktrails,%chkallitems);
 4835:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
 4836:         if (ref($chkcats[0]) eq 'ARRAY') {
 4837:             my $depth = 0;
 4838:             my $chg = 0;
 4839:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
 4840:                 my $name = $chkcats[0][$i];
 4841:                 my $item;
 4842:                 if ($name eq '') {
 4843:                     $chg ++;
 4844:                 } else {
 4845:                     $item = &escape($name).'::0';
 4846:                     if ($chg) {
 4847:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
 4848:                     }
 4849:                     $depth ++; 
 4850:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
 4851:                     $depth --;
 4852:                 }
 4853:             }
 4854:         }
 4855:     }
 4856:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 4857:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
 4858:         if ($putresult eq 'ok') {
 4859:             my %title = (
 4860:                          togglecats  => 'Show/Hide a course in the catalog',
 4861:                          categorize     => 'Category assigned to course',
 4862:                         );
 4863:             my %level = (
 4864:                          dom => 'set from "Modify Course" (Domain)',
 4865:                          crs => 'set from "Parameters" (Course)',
 4866:                         );
 4867:             $resulttext = &mt('Changes made:').'<ul>';
 4868:             if ($changes{'togglecats'}) {
 4869:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
 4870:             }
 4871:             if ($changes{'categorize'}) {
 4872:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
 4873:             }
 4874:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 4875:                 my $cathash;
 4876:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 4877:                     $cathash = $domconfig{'coursecategories'}{'cats'};
 4878:                 } else {
 4879:                     $cathash = {};
 4880:                 } 
 4881:                 my (@cats,@trails,%allitems);
 4882:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
 4883:                 if (keys(%deletions) > 0) {
 4884:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
 4885:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
 4886:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
 4887:                     }
 4888:                     $resulttext .= '</ul></li>';
 4889:                 }
 4890:                 if (keys(%reorderings) > 0) {
 4891:                     my %sort_by_trail;
 4892:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
 4893:                     foreach my $key (keys(%reorderings)) {
 4894:                         if ($allitems{$key} ne '') {
 4895:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 4896:                         }
 4897:                     }
 4898:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 4899:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 4900:                     }
 4901:                     $resulttext .= '</ul></li>';
 4902:                 }
 4903:                 if (keys(%adds) > 0) {
 4904:                     my %sort_by_trail;
 4905:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
 4906:                     foreach my $key (keys(%adds)) {
 4907:                         if ($allitems{$key} ne '') {
 4908:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 4909:                         }
 4910:                     }
 4911:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 4912:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 4913:                     }
 4914:                     $resulttext .= '</ul></li>';
 4915:                 }
 4916:             }
 4917:             $resulttext .= '</ul>';
 4918:         } else {
 4919:             $resulttext = '<span class="LC_error">'.
 4920:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 4921:         }
 4922:     } else {
 4923:         $resulttext = &mt('No changes made to course categories');
 4924:     }
 4925:     return $resulttext;
 4926: }
 4927: 
 4928: sub modify_serverstatuses {
 4929:     my ($dom,%domconfig) = @_;
 4930:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
 4931:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
 4932:         %currserverstatus = %{$domconfig{'serverstatuses'}};
 4933:     }
 4934:     my @pages = &serverstatus_pages();
 4935:     foreach my $type (@pages) {
 4936:         $newserverstatus{$type}{'namedusers'} = '';
 4937:         $newserverstatus{$type}{'machines'} = '';
 4938:         if (defined($env{'form.'.$type.'_namedusers'})) {
 4939:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
 4940:             my @okusers;
 4941:             foreach my $user (@users) {
 4942:                 my ($uname,$udom) = split(/:/,$user);
 4943:                 if (($udom =~ /^$match_domain$/) &&   
 4944:                     (&Apache::lonnet::domain($udom)) &&
 4945:                     ($uname =~ /^$match_username$/)) {
 4946:                     if (!grep(/^\Q$user\E/,@okusers)) {
 4947:                         push(@okusers,$user);
 4948:                     }
 4949:                 }
 4950:             }
 4951:             if (@okusers > 0) {
 4952:                  @okusers = sort(@okusers);
 4953:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
 4954:             }
 4955:         }
 4956:         if (defined($env{'form.'.$type.'_machines'})) {
 4957:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
 4958:             my @okmachines;
 4959:             foreach my $ip (@machines) {
 4960:                 my @parts = split(/\./,$ip);
 4961:                 next if (@parts < 4);
 4962:                 my $badip = 0;
 4963:                 for (my $i=0; $i<4; $i++) {
 4964:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
 4965:                         $badip = 1;
 4966:                         last;
 4967:                     }
 4968:                 }
 4969:                 if (!$badip) {
 4970:                     push(@okmachines,$ip);     
 4971:                 }
 4972:             }
 4973:             @okmachines = sort(@okmachines);
 4974:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
 4975:         }
 4976:     }
 4977:     my %serverstatushash =  (
 4978:                                 serverstatuses => \%newserverstatus,
 4979:                             );
 4980:     my %changes;
 4981:     foreach my $type (@pages) {
 4982:         foreach my $setting ('namedusers','machines') {
 4983:             my @current = ();
 4984:             if (ref($currserverstatus{$type}) eq 'HASH') {
 4985:                 @current = split(/,/,$currserverstatus{$type}{$setting});
 4986:             }
 4987:             my @new = split(/,/,$newserverstatus{$type}{$setting});
 4988:             if (@current > 0) {
 4989:                 if (@new > 0) {
 4990:                     foreach my $item (@current) {
 4991:                         if (!grep(/^\Q$item\E$/,@new)) {
 4992:                             $changes{$type}{$setting} = 1;
 4993:                             last;
 4994:                         }
 4995:                     }
 4996:                     if (!$changes{$type}{$setting}) {
 4997:                         foreach my $item (@new) {
 4998:                             if (!grep(/^\Q$item\E$/,@current)) {
 4999:                                 $changes{$type}{$setting} = 1;
 5000:                                 last;
 5001:                             }
 5002:                         }
 5003:                     }
 5004:                 } else {
 5005:                     $changes{$type}{$setting} = 1;
 5006:                 }
 5007:             } elsif (@new > 0) {
 5008:                 $changes{$type}{$setting} = 1;
 5009:             }
 5010:         }
 5011:     }
 5012:     if (keys(%changes) > 0) {
 5013:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 5014:         my $putresult = &Apache::lonnet::put_dom('configuration',
 5015:                                                  \%serverstatushash,$dom);
 5016:         if ($putresult eq 'ok') {
 5017:             $resulttext .= &mt('Changes made:').'<ul>';
 5018:             foreach my $type (@pages) {
 5019:                 if (defined($changes{$type})) {
 5020:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
 5021:                     if (defined($changes{$type}{'namedusers'})) {
 5022:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
 5023:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
 5024:                         } else {
 5025:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
 5026:                         }
 5027:                     } elsif (defined($changes{$type}{'machines'})) {
 5028:                         if ($newserverstatus{$type}{'machines'} eq '') {
 5029:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
 5030:                         } else {
 5031:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
 5032:                         }
 5033: 
 5034:                     }
 5035:                     $resulttext .= '</ul></li>';
 5036:                 }
 5037:             }
 5038:             $resulttext .= '</ul>';
 5039:         } else {
 5040:             $resulttext = '<span class="LC_error">'.
 5041:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
 5042: 
 5043:         }
 5044:     } else {
 5045:         $resulttext = &mt('No changes made to access to server status pages');
 5046:     }
 5047:     return $resulttext;
 5048: }
 5049: 
 5050: sub recurse_check {
 5051:     my ($chkcats,$categories,$depth,$name) = @_;
 5052:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
 5053:         my $chg = 0;
 5054:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
 5055:             my $category = $chkcats->[$depth]{$name}[$j];
 5056:             my $item;
 5057:             if ($category eq '') {
 5058:                 $chg ++;
 5059:             } else {
 5060:                 my $deeper = $depth + 1;
 5061:                 $item = &escape($category).':'.&escape($name).':'.$depth;
 5062:                 if ($chg) {
 5063:                     $categories->{$item} -= $chg;
 5064:                 }
 5065:                 &recurse_check($chkcats,$categories,$deeper,$category);
 5066:                 $deeper --;
 5067:             }
 5068:         }
 5069:     }
 5070:     return;
 5071: }
 5072: 
 5073: sub recurse_cat_deletes {
 5074:     my ($item,$coursecategories,$deletions) = @_;
 5075:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 5076:     my $subdepth = $depth + 1;
 5077:     if (ref($coursecategories) eq 'HASH') {
 5078:         foreach my $subitem (keys(%{$coursecategories})) {
 5079:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
 5080:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
 5081:                 delete($coursecategories->{$subitem});
 5082:                 $deletions->{$subitem} = 1;
 5083:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
 5084:             }  
 5085:         }
 5086:     }
 5087:     return;
 5088: }
 5089: 
 5090: 1;

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