File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.96: download - view: text, annotated - select for diffs
Tue May 19 20:00:24 2009 UTC (15 years ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Sanity checking.
 - Confirm $cancreate{'selfcreate'} and $cancreate{'statustocreate'} are array refs.

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

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