File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.104: download - view: text, annotated - select for diffs
Sat Aug 22 18:09:17 2009 UTC (14 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Change setting name where DC approval is required from approve to approval for consistency with lonrequestcourse.pm
- Additional radio button for "LON-CAPA Advanced Users" - No override set (this is the default), i.e., no specific course request settng applied for LON-CAPA Advanced Users. [Setting based on affiliation is used].
- (blank for unlimited) text added for default and LC_adv.

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

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