File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.87: download - view: text, annotated - select for diffs
Mon Feb 9 03:42:03 2009 UTC (15 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- If $domconfig{'coursecategories'} is not a hash ref ... make it one.

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

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