File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.138.2.1: download - view: text, annotated - select for diffs
Fri Aug 13 05:45:05 2010 UTC (13 years, 9 months ago) by raeburn
Branches: version_2_10_X
- For 2.10.
  - Course default for PDFForms fixed as "No" for all domains in 2.10.
  - Helpsettings domain configuration not included in 2.10.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.138.2.1 2010/08/13 05:45:05 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','autocreate',
  203:                 'directorysrch','usercreation','usermodification',
  204:                 'contacts','defaults','scantron','coursecategories',
  205:                 'serverstatuses','requestcourses','usersessions'],$dom);
  206:     my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
  207:                        'autoupdate','autocreate','directorysrch','contacts',
  208:                        'usercreation','usermodification','scantron',
  209:                        'requestcourses','coursecategories','serverstatuses',
  210:                        'usersessions');
  211:     my %prefs = (
  212:         'rolecolors' =>
  213:                    { text => 'Default color schemes',
  214:                      help => 'Domain_Configuration_Color_Schemes',
  215:                      header => [{col1 => 'Student Settings',
  216:                                  col2 => '',},
  217:                                 {col1 => 'Coordinator Settings',
  218:                                  col2 => '',},
  219:                                 {col1 => 'Author Settings',
  220:                                  col2 => '',},
  221:                                 {col1 => 'Administrator Settings',
  222:                                  col2 => '',}],
  223:                     },
  224:         'login' =>
  225:                     { text => 'Log-in page options',
  226:                       help => 'Domain_Configuration_Login_Page',
  227:                       header => [{col1 => 'Item',
  228:                                   col2 => '',}],
  229:                     },
  230: 
  231:         'defaults' => 
  232:                     { text => 'Default authentication/language/timezone',
  233:                       help => 'Domain_Configuration_LangTZAuth',
  234:                       header => [{col1 => 'Setting',
  235:                                   col2 => 'Value'}],
  236:                     },
  237:         'quotas' => 
  238:                     { text => 'User blogs, personal information pages, portfolios',
  239:                       help => 'Domain_Configuration_Quotas',
  240:                       header => [{col1 => 'User affiliation',
  241:                                   col2 => 'Available tools',
  242:                                   col3 => 'Portfolio quota',}],
  243:                     },
  244:         'autoenroll' =>
  245:                    { text => 'Auto-enrollment settings',
  246:                      help => 'Domain_Configuration_Auto_Enrollment',
  247:                      header => [{col1 => 'Configuration setting',
  248:                                  col2 => 'Value(s)'}],
  249:                    },
  250:         'autoupdate' => 
  251:                    { text => 'Auto-update settings',
  252:                      help => 'Domain_Configuration_Auto_Updates',
  253:                      header => [{col1 => 'Setting',
  254:                                  col2 => 'Value',},
  255:                                 {col1 => 'Setting',
  256:                                  col2 => 'Affiliation'},
  257:                                 {col1 => 'User population',
  258:                                  col2 => 'Updateable user data'}],
  259:                   },
  260:         'autocreate' => 
  261:                   { text => 'Auto-course creation settings',
  262:                      help => 'Domain_Configuration_Auto_Creation',
  263:                      header => [{col1 => 'Configuration Setting',
  264:                                  col2 => 'Value',}],
  265:                   },
  266:         'directorysrch' => 
  267:                   { text => 'Institutional directory searches',
  268:                     help => 'Domain_Configuration_InstDirectory_Search',
  269:                     header => [{col1 => 'Setting',
  270:                                 col2 => 'Value',}],
  271:                   },
  272:         'contacts' =>
  273:                   { text => 'Contact Information',
  274:                     help => 'Domain_Configuration_Contact_Info',
  275:                     header => [{col1 => 'Setting',
  276:                                 col2 => 'Value',}],
  277:                   },
  278: 
  279:         'usercreation' => 
  280:                   { text => 'User creation',
  281:                     help => 'Domain_Configuration_User_Creation',
  282:                     header => [{col1 => 'Format rule type',
  283:                                 col2 => 'Format rules in force'},
  284:                                {col1 => 'User account creation',
  285:                                 col2 => 'Usernames which may be created',},
  286:                                {col1 => 'Context',
  287:                                 col2 => 'Assignable authentication types'}],
  288:                   },
  289:         'usermodification' =>
  290:                   { text => 'User modification',
  291:                     help => 'Domain_Configuration_User_Modification',
  292:                     header => [{col1 => 'Target user has role',
  293:                                 col2 => 'User information updateable in author context'},
  294:                                {col1 => 'Target user has role',
  295:                                 col2 => 'User information updateable in course context'},
  296:                                {col1 => "Status of user",
  297:                                 col2 => 'Information settable when self-creating account (if directory data blank)'}],
  298:                   },
  299:         'scantron' =>
  300:                   { text => 'Bubblesheet format file',
  301:                     help => 'Domain_Configuration_Scantron_Format',
  302:                     header => [ {col1 => 'Item',
  303:                                  col2 => '',
  304:                               }],
  305:                   },
  306:         'requestcourses' => 
  307:                  {text => 'Request creation of courses',
  308:                   help => 'Domain_Configuration_Request_Courses',
  309:                   header => [{col1 => 'User affiliation',
  310:                               col2 => 'Availability/Processing of requests',},
  311:                              {col1 => 'Setting',
  312:                               col2 => 'Value'}],
  313:                  },
  314:         'coursecategories' =>
  315:                   { text => 'Cataloging of courses/communities',
  316:                     help => 'Domain_Configuration_Cataloging_Courses',
  317:                     header => [{col1 => 'Category settings',
  318:                                 col2 => '',},
  319:                                {col1 => 'Categories',
  320:                                 col2 => '',
  321:                                }],
  322:                   },
  323:         'serverstatuses' =>
  324:                  {text   => 'Access to server status pages',
  325:                   help   => 'Domain_Configuration_Server_Status',
  326:                   header => [{col1 => 'Status Page',
  327:                               col2 => 'Other named users',
  328:                               col3 => 'Specific IPs',
  329:                             }],
  330:                  },
  331:         'helpsettings' =>
  332:                  {text   => 'Help page settings',
  333:                   help   => 'Domain_Configuration_Help_Settings',
  334:                   header => [{col1 => 'Authenticated Help Settings',
  335:                               col2 => ''},
  336:                              {col1 => 'Unauthenticated Help Settings',
  337:                               col2 => ''}],
  338:                  },
  339:         'coursedefaults' => 
  340:                  {text => 'Course/Community defaults',
  341:                   help => 'Domain_Configuration_Course_Defaults',
  342:                   header => [{col1 => 'Setting',
  343:                               col2 => 'Value',}],
  344:                  },
  345:         'privacy' => 
  346:                  {text   => 'User Privacy',
  347:                   help   => 'Domain_Configuration_User_Privacy',
  348:                   header => [{col1 => 'Setting',
  349:                               col2 => 'Value',}],
  350:                  },
  351:          'usersessions' =>
  352:                  {text  => 'User session hosting',
  353:                   help  => 'Domain_Configuration_User_Sessions',
  354:                   header => [{col1 => 'Hosting of users from other domains',
  355:                               col2 => 'Rules'},
  356:                              {col1 => "Hosting domain's own users elsewhere",
  357:                               col2 => 'Rules'}],
  358:                  },
  359:     );
  360:     my %servers = &dom_servers($dom);
  361:     if (keys(%servers) > 1) {
  362:         $prefs{'login'}  = { text   => 'Log-in page options',
  363:                              help   => 'Domain_Configuration_Login_Page',
  364:                             header => [{col1 => 'Log-in Service',
  365:                                         col2 => 'Server Setting',},
  366:                                        {col1 => 'Log-in Page Items',
  367:                                         col2 => ''}],
  368:                            };
  369:     }
  370:     my @roles = ('student','coordinator','author','admin');
  371:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  372:     &Apache::lonhtmlcommon::add_breadcrumb
  373:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
  374:       text=>"Settings to display/modify"});
  375:     my $confname = $dom.'-domainconfig';
  376:     if ($phase eq 'process') {
  377:         &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
  378:     } elsif ($phase eq 'display') {
  379:         &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname);
  380:     } else {
  381:         if (keys(%domconfig) == 0) {
  382:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
  383:             my @ids=&Apache::lonnet::current_machine_ids();
  384:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
  385:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
  386:                 my @loginimages = ('img','logo','domlogo','login');
  387:                 my $custom_img_count = 0;
  388:                 foreach my $img (@loginimages) {
  389:                     if ($designhash{$dom.'.login.'.$img} ne '') {
  390:                         $custom_img_count ++;
  391:                     }
  392:                 }
  393:                 foreach my $role (@roles) {
  394:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  395:                         $custom_img_count ++;
  396:                     }
  397:                 }
  398:                 if ($custom_img_count > 0) {
  399:                     &Apache::lonconfigsettings::print_header($r,$phase,$context);
  400:                     my $switch_server = &check_switchserver($dom,$confname);
  401:                     $r->print(
  402:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
  403:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
  404:     &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 />'.
  405:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
  406:                     if ($switch_server) {
  407:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
  408:                     }
  409:                     $r->print(&Apache::loncommon::end_page());
  410:                     return OK;
  411:                 }
  412:             }
  413:         }
  414:         &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
  415:     }
  416:     return OK;
  417: }
  418: 
  419: sub process_changes {
  420:     my ($r,$dom,$confname,$action,$roles,$values) = @_;
  421:     my %domconfig;
  422:     if (ref($values) eq 'HASH') {
  423:         %domconfig = %{$values};
  424:     }
  425:     my $output;
  426:     if ($action eq 'login') {
  427:         $output = &modify_login($r,$dom,$confname,%domconfig);
  428:     } elsif ($action eq 'rolecolors') {
  429:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
  430:                                      %domconfig);
  431:     } elsif ($action eq 'quotas') {
  432:         $output = &modify_quotas($dom,$action,%domconfig);
  433:     } elsif ($action eq 'autoenroll') {
  434:         $output = &modify_autoenroll($dom,%domconfig);
  435:     } elsif ($action eq 'autoupdate') {
  436:         $output = &modify_autoupdate($dom,%domconfig);
  437:     } elsif ($action eq 'autocreate') {
  438:         $output = &modify_autocreate($dom,%domconfig);
  439:     } elsif ($action eq 'directorysrch') {
  440:         $output = &modify_directorysrch($dom,%domconfig);
  441:     } elsif ($action eq 'usercreation') {
  442:         $output = &modify_usercreation($dom,%domconfig);
  443:     } elsif ($action eq 'usermodification') {
  444:         $output = &modify_usermodification($dom,%domconfig);
  445:     } elsif ($action eq 'contacts') {
  446:         $output = &modify_contacts($dom,%domconfig);
  447:     } elsif ($action eq 'defaults') {
  448:         $output = &modify_defaults($dom,$r);
  449:     } elsif ($action eq 'scantron') {
  450:         $output = &modify_scantron($r,$dom,$confname,%domconfig);
  451:     } elsif ($action eq 'coursecategories') {
  452:         $output = &modify_coursecategories($dom,%domconfig);
  453:     } elsif ($action eq 'serverstatuses') {
  454:         $output = &modify_serverstatuses($dom,%domconfig);
  455:     } elsif ($action eq 'requestcourses') {
  456:         $output = &modify_quotas($dom,$action,%domconfig);
  457:     } elsif ($action eq 'usersessions') {
  458:         $output = &modify_usersessions($dom,%domconfig);
  459:     }
  460:     return $output;
  461: }
  462: 
  463: sub print_config_box {
  464:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
  465:     my $rowtotal = 0;
  466:     my $output;
  467:     if ($action eq 'coursecategories') {
  468:         $output = &coursecategories_javascript($settings);
  469:     }
  470:     $output .= 
  471:          '<table class="LC_nested_outer">
  472:           <tr>
  473:            <th align="left" valign="middle"><span class="LC_nobreak">'.
  474:            &mt($item->{text}).'&nbsp;'.
  475:            &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
  476:           '</tr>';
  477:     $rowtotal ++;
  478:     my $numheaders = 1;
  479:     if (ref($item->{'header'}) eq 'ARRAY') {
  480:         $numheaders = scalar(@{$item->{'header'}});
  481:     }
  482:     if ($numheaders > 1) {
  483:         my $colspan = '';
  484:         if (($action eq 'rolecolors') || ($action eq 'coursecategories') || ($action eq 'helpsettings')) {
  485:             $colspan = ' colspan="2"';
  486:         }
  487:         $output .= '
  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'}->[0]->{'col1'}).'</td>
  493:               <td class="LC_right_item">'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
  494:              </tr>';
  495:         $rowtotal ++;
  496:         if ($action eq 'autoupdate') {
  497:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
  498:         } elsif ($action eq 'usercreation') {
  499:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
  500:         } elsif ($action eq 'usermodification') {
  501:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
  502:         } elsif ($action eq 'coursecategories') {
  503:             $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
  504:         } elsif ($action eq 'login') {
  505:             $output .= &print_login('top',$dom,$confname,$phase,$settings,\$rowtotal);
  506:             $colspan = ' colspan="2"';
  507:         } elsif ($action eq 'requestcourses') {
  508:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  509:         } elsif ($action eq 'helpsettings') {
  510:             $output .= &print_helpsettings('top',$dom,$confname,$settings,\$rowtotal);
  511:         } elsif ($action eq 'usersessions') {
  512:             $output .= &print_usersessions('top',$dom,$settings,\$rowtotal); 
  513:         } elsif ($action eq 'rolecolors') {
  514:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
  515:         }
  516:         $output .= '
  517:            </table>
  518:           </td>
  519:          </tr>
  520:          <tr>
  521:            <td>
  522:             <table class="LC_nested">
  523:              <tr class="LC_info_row">
  524:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
  525:         $output .= '
  526:               <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
  527:              </tr>';
  528:             $rowtotal ++;
  529:         if ($action eq 'autoupdate') {
  530:             $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
  531:            </table>
  532:           </td>
  533:          </tr>
  534:          <tr>
  535:            <td>
  536:             <table class="LC_nested">
  537:              <tr class="LC_info_row">
  538:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  539:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  540:             &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
  541:             $rowtotal ++;
  542:         } elsif ($action eq 'usercreation') {
  543:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
  544:            </table>
  545:           </td>
  546:          </tr>
  547:          <tr>
  548:            <td>
  549:             <table class="LC_nested">
  550:              <tr class="LC_info_row">
  551:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  552:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>             </tr>'.
  553:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
  554:             $rowtotal ++;
  555:         } elsif ($action eq 'usermodification') {
  556:             $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
  557:            </table>
  558:           </td>
  559:          </tr>
  560:          <tr>
  561:            <td>
  562:             <table class="LC_nested">
  563:              <tr class="LC_info_row">
  564:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
  565:               <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>      </tr>'.
  566:                        &print_usermodification('bottom',$dom,$settings,\$rowtotal);
  567:             $rowtotal ++;
  568:         } elsif ($action eq 'coursecategories') {
  569:             $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
  570:         } elsif ($action eq 'login') {
  571:             $output .= &print_login('bottom',$dom,$confname,$phase,$settings,\$rowtotal);
  572:         } elsif ($action eq 'requestcourses') {
  573:             $output .= &print_courserequestmail($dom,$settings,\$rowtotal);
  574:         } elsif ($action eq 'helpsettings') {
  575:             $output .= &print_helpsettings('bottom',$dom,$confname,$settings,\$rowtotal);
  576:         } elsif ($action eq 'usersessions') {
  577:             $output .= &print_usersessions('bottom',$dom,$settings,\$rowtotal);
  578:         } elsif ($action eq 'rolecolors') {
  579:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
  580:            </table>
  581:           </td>
  582:          </tr>
  583:          <tr>
  584:            <td>
  585:             <table class="LC_nested">
  586:              <tr class="LC_info_row">
  587:               <td class="LC_left_item"'.$colspan.' valign="top">'.
  588:                &mt($item->{'header'}->[2]->{'col1'}).'</td>
  589:               <td class="LC_right_item" valign="top">'.
  590:                &mt($item->{'header'}->[2]->{'col2'}).'</td>
  591:              </tr>'.
  592:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
  593:            </table>
  594:           </td>
  595:          </tr>
  596:          <tr>
  597:            <td>
  598:             <table class="LC_nested">
  599:              <tr class="LC_info_row">
  600:               <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
  601:               <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
  602:              </tr>'.
  603:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
  604:             $rowtotal += 2;
  605:         }
  606:     } else {
  607:         $output .= '
  608:           <tr>
  609:            <td>
  610:             <table class="LC_nested">
  611:              <tr class="LC_info_row">';
  612:         if (($action eq 'login') || ($action eq 'directorysrch')) {
  613:             $output .= '  
  614:               <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  615:         } elsif ($action eq 'serverstatuses') {
  616:             $output .= '
  617:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
  618:               '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
  619: 
  620:         } else {
  621:             $output .= '
  622:               <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
  623:         }
  624:         if (defined($item->{'header'}->[0]->{'col3'})) {
  625:             $output .= '<td class="LC_left_item" valign="top">'.
  626:                        &mt($item->{'header'}->[0]->{'col2'});
  627:             if ($action eq 'serverstatuses') {
  628:                 $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
  629:             } 
  630:         } else {
  631:             $output .= '<td class="LC_right_item" valign="top">'.
  632:                        &mt($item->{'header'}->[0]->{'col2'});
  633:         }
  634:         $output .= '</td>';
  635:         if ($item->{'header'}->[0]->{'col3'}) {
  636:             $output .= '<td class="LC_right_item" valign="top">'.
  637:                        &mt($item->{'header'}->[0]->{'col3'});
  638:             if ($action eq 'serverstatuses') {
  639:                 $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
  640:             }
  641:             $output .= '</td>';
  642:         }
  643:         $output .= '</tr>';
  644:         $rowtotal ++;
  645:         if ($action eq 'login') {
  646:             $output .= &print_login('bottom',$dom,$confname,$phase,$settings,
  647:                                     \$rowtotal);
  648:         } elsif ($action eq 'quotas') {
  649:             $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
  650:         } elsif ($action eq 'autoenroll') {
  651:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
  652:         } elsif ($action eq 'autocreate') {
  653:             $output .= &print_autocreate($dom,$settings,\$rowtotal);
  654:         } elsif ($action eq 'directorysrch') {
  655:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
  656:         } elsif ($action eq 'contacts') {
  657:             $output .= &print_contacts($dom,$settings,\$rowtotal);
  658:         } elsif ($action eq 'defaults') {
  659:             $output .= &print_defaults($dom,\$rowtotal);
  660:         } elsif ($action eq 'scantron') {
  661:             $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
  662:         } elsif ($action eq 'serverstatuses') {
  663:             $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
  664:         }
  665:     }
  666:     $output .= '
  667:    </table>
  668:   </td>
  669:  </tr>
  670: </table><br />';
  671:     return ($output,$rowtotal);
  672: }
  673: 
  674: sub print_login {
  675:     my ($position,$dom,$confname,$phase,$settings,$rowtotal) = @_;
  676:     my ($css_class,$datatable);
  677:     my %choices = &login_choices();
  678: 
  679:     if ($position eq 'top') {
  680:         my %servers = &dom_servers($dom);
  681:         my $choice = $choices{'disallowlogin'};
  682:         $css_class = ' class="LC_odd_row"';
  683:         $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
  684:                       '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
  685:                       '<th>'.$choices{'server'}.'</th>'.
  686:                       '<th>'.$choices{'serverpath'}.'</th>'.
  687:                       '<th>'.$choices{'custompath'}.'</th>'.
  688:                       '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
  689:         my %disallowed;
  690:         if (ref($settings) eq 'HASH') {
  691:             if (ref($settings->{'loginvia'}) eq 'HASH') {
  692:                %disallowed = %{$settings->{'loginvia'}};
  693:             }
  694:         }
  695:         foreach my $lonhost (sort(keys(%servers))) {
  696:             my $direct = 'selected="selected"';
  697:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  698:                 if ($disallowed{$lonhost}{'server'} ne '') {
  699:                     $direct = '';
  700:                 }
  701:             }
  702:             $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
  703:                           '<td><select name="'.$lonhost.'_server">'.
  704:                           '<option value=""'.$direct.'>'.$choices{'directlogin'}.
  705:                           '</option>';
  706:             foreach my $hostid (keys(%servers)) {
  707:                 next if ($servers{$hostid} eq $servers{$lonhost});
  708:                 my $selected = '';
  709:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  710:                     if ($hostid eq $disallowed{$lonhost}{'server'}) {
  711:                         $selected = 'selected="selected"';
  712:                     }
  713:                 }
  714:                 $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
  715:                               $servers{$hostid}.'</option>';
  716:             }
  717:             $datatable .= '</select></td>'.
  718:                           '<td><select name="'.$lonhost.'_serverpath">';
  719:             foreach my $path ('','/','/adm/login','/adm/roles','custom') {
  720:                 my $pathname = $path;
  721:                 if ($path eq 'custom') {
  722:                     $pathname = &mt('Custom Path').' ->';
  723:                 }
  724:                 my $selected = '';
  725:                 if (ref($disallowed{$lonhost}) eq 'HASH') {
  726:                     if ($path eq $disallowed{$lonhost}{'serverpath'}) {
  727:                         $selected = 'selected="selected"';
  728:                     }
  729:                 } elsif ($path eq '') {
  730:                     $selected = 'selected="selected"';
  731:                 }
  732:                 $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
  733:             }
  734:             $datatable .= '</select></td>';
  735:             my ($custom,$exempt);
  736:             if (ref($disallowed{$lonhost}) eq 'HASH') {
  737:                 $custom = $disallowed{$lonhost}{'custompath'};
  738:                 $exempt = $disallowed{$lonhost}{'exempt'};
  739:             }
  740:             $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
  741:                           '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
  742:                           '</tr>';
  743:         }
  744:         $datatable .= '</table></td></tr>';
  745:         return $datatable;
  746:     }
  747: 
  748:     my %defaultchecked = ( 
  749:                            'coursecatalog' => 'on',
  750:                            'adminmail'     => 'off',
  751:                            'newuser'       => 'off',
  752:                          );
  753:     my @toggles = ('coursecatalog','adminmail','newuser');
  754:     my (%checkedon,%checkedoff);
  755:     foreach my $item (@toggles) {
  756:         if ($defaultchecked{$item} eq 'on') { 
  757:             $checkedon{$item} = ' checked="checked" ';
  758:             $checkedoff{$item} = ' ';
  759:         } elsif ($defaultchecked{$item} eq 'off') {
  760:             $checkedoff{$item} = ' checked="checked" ';
  761:             $checkedon{$item} = ' ';
  762:         }
  763:     }
  764:     my @images = ('img','logo','domlogo','login');
  765:     my @logintext = ('textcol','bgcol');
  766:     my @bgs = ('pgbg','mainbg','sidebg');
  767:     my @links = ('link','alink','vlink');
  768:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  769:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  770:     my (%is_custom,%designs);
  771:     my %defaults = (
  772:                    font => $defaultdesign{'login.font'},
  773:                    );
  774:     foreach my $item (@images) {
  775:         $defaults{$item} = $defaultdesign{'login.'.$item};
  776:         $defaults{'showlogo'}{$item} = 1;
  777:     }
  778:     foreach my $item (@bgs) {
  779:         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
  780:     }
  781:     foreach my $item (@logintext) {
  782:         $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
  783:     }
  784:     foreach my $item (@links) {
  785:         $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
  786:     }
  787:     if (ref($settings) eq 'HASH') {
  788:         foreach my $item (@toggles) {
  789:             if ($settings->{$item} eq '1') {
  790:                 $checkedon{$item} =  ' checked="checked" ';
  791:                 $checkedoff{$item} = ' ';
  792:             } elsif ($settings->{$item} eq '0') {
  793:                 $checkedoff{$item} =  ' checked="checked" ';
  794:                 $checkedon{$item} = ' ';
  795:             }
  796:         }
  797:         foreach my $item (@images) {
  798:             if (defined($settings->{$item})) {
  799:                 $designs{$item} = $settings->{$item};
  800:                 $is_custom{$item} = 1;
  801:             }
  802:             if (defined($settings->{'showlogo'}{$item})) {
  803:                 $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
  804:             }
  805:         }
  806:         foreach my $item (@logintext) {
  807:             if ($settings->{$item} ne '') {
  808:                 $designs{'logintext'}{$item} = $settings->{$item};
  809:                 $is_custom{$item} = 1;
  810:             }
  811:         }
  812:         if ($settings->{'font'} ne '') {
  813:             $designs{'font'} = $settings->{'font'};
  814:             $is_custom{'font'} = 1;
  815:         }
  816:         foreach my $item (@bgs) {
  817:             if ($settings->{$item} ne '') {
  818:                 $designs{'bgs'}{$item} = $settings->{$item};
  819:                 $is_custom{$item} = 1;
  820:             }
  821:         }
  822:         foreach my $item (@links) {
  823:             if ($settings->{$item} ne '') {
  824:                 $designs{'links'}{$item} = $settings->{$item};
  825:                 $is_custom{$item} = 1;
  826:             }
  827:         }
  828:     } else {
  829:         if ($designhash{$dom.'.login.font'} ne '') {
  830:             $designs{'font'} = $designhash{$dom.'.login.font'};
  831:             $is_custom{'font'} = 1;
  832:         }
  833:         foreach my $item (@images) {
  834:             if ($designhash{$dom.'.login.'.$item} ne '') {
  835:                 $designs{$item} = $designhash{$dom.'.login.'.$item};
  836:                 $is_custom{$item} = 1;
  837:             }
  838:         }
  839:         foreach my $item (@bgs) {
  840:             if ($designhash{$dom.'.login.'.$item} ne '') {
  841:                 $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
  842:                 $is_custom{$item} = 1;
  843:             }
  844:         }
  845:         foreach my $item (@links) {
  846:             if ($designhash{$dom.'.login.'.$item} ne '') {
  847:                 $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
  848:                 $is_custom{$item} = 1;
  849:             }
  850:         }
  851:     }
  852:     my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
  853:                                                   logo => 'Institution Logo',
  854:                                                   domlogo => 'Domain Logo',
  855:                                                   login => 'Login box');
  856:     my $itemcount = 1;
  857:     my ($css_class,$datatable);
  858:     foreach my $item (@toggles) {
  859:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
  860:         $datatable .=  
  861:             '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
  862:             '</td><td>'.
  863:             '<span class="LC_nobreak"><label><input type="radio" name="'.
  864:             $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
  865:             '</label>&nbsp;<label><input type="radio" name="'.$item.'"'.
  866:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
  867:             '</tr>';
  868:         $itemcount ++;
  869:     }
  870:     $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
  871:     $datatable .= '</tr></table></td></tr>';
  872:     return $datatable;
  873: }
  874: 
  875: sub login_choices {
  876:     my %choices =
  877:         &Apache::lonlocal::texthash (
  878:             coursecatalog => 'Display Course/Community Catalog link?',
  879:             adminmail     => "Display Administrator's E-mail Address?",
  880:             disallowlogin => "Login page requests redirected",
  881:             hostid        => "Server",
  882:             server        => "Redirect to:",
  883:             serverpath    => "Path",
  884:             custompath    => "Custom", 
  885:             exempt        => "Exempt IP(s)",
  886:             directlogin   => "No redirect",
  887:             newuser       => "Link to create a user account",
  888:             img           => "Header",
  889:             logo          => "Main Logo",
  890:             domlogo       => "Domain Logo",
  891:             login         => "Log-in Header", 
  892:             textcol       => "Text color",
  893:             bgcol         => "Box color",
  894:             bgs           => "Background colors",
  895:             links         => "Link colors",
  896:             font          => "Font color",
  897:             pgbg          => "Header",
  898:             mainbg        => "Page",
  899:             sidebg        => "Login box",
  900:             link          => "Link",
  901:             alink         => "Active link",
  902:             vlink         => "Visited link",
  903:         );
  904:     return %choices;
  905: }
  906: 
  907: sub print_rolecolors {
  908:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
  909:     my %choices = &color_font_choices();
  910:     my @bgs = ('pgbg','tabbg','sidebg');
  911:     my @links = ('link','alink','vlink');
  912:     my @images = ('img');
  913:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
  914:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  915:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  916:     my (%is_custom,%designs);
  917:     my %defaults = (
  918:                    img => $defaultdesign{$role.'.img'},
  919:                    font => $defaultdesign{$role.'.font'},
  920: 		   fontmenu => $defaultdesign{$role.'.fontmenu'},
  921:                    );
  922:     foreach my $item (@bgs) {
  923:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
  924:     }
  925:     foreach my $item (@links) {
  926:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
  927:     }
  928:     if (ref($settings) eq 'HASH') {
  929:         if (ref($settings->{$role}) eq 'HASH') {
  930:             if ($settings->{$role}->{'img'} ne '') {
  931:                 $designs{'img'} = $settings->{$role}->{'img'};
  932:                 $is_custom{'img'} = 1;
  933:             }
  934:             if ($settings->{$role}->{'font'} ne '') {
  935:                 $designs{'font'} = $settings->{$role}->{'font'};
  936:                 $is_custom{'font'} = 1;
  937:             }
  938:             if ($settings->{$role}->{'fontmenu'} ne '') {
  939:                 $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
  940:                 $is_custom{'fontmenu'} = 1;
  941:             }
  942:             foreach my $item (@bgs) {
  943:                 if ($settings->{$role}->{$item} ne '') {
  944:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
  945:                     $is_custom{$item} = 1;
  946:                 }
  947:             }
  948:             foreach my $item (@links) {
  949:                 if ($settings->{$role}->{$item} ne '') {
  950:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
  951:                     $is_custom{$item} = 1;
  952:                 }
  953:             }
  954:         }
  955:     } else {
  956:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  957:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
  958:             $is_custom{'img'} = 1;
  959:         }
  960:         if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
  961:             $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
  962:             $is_custom{'fontmenu'} = 1; 
  963:         }
  964:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
  965:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
  966:             $is_custom{'font'} = 1;
  967:         }
  968:         foreach my $item (@bgs) {
  969:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  970:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  971:                 $is_custom{$item} = 1;
  972:             
  973:             }
  974:         }
  975:         foreach my $item (@links) {
  976:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  977:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  978:                 $is_custom{$item} = 1;
  979:             }
  980:         }
  981:     }
  982:     my $itemcount = 1;
  983:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
  984:     $datatable .= '</tr></table></td></tr>';
  985:     return $datatable;
  986: }
  987: 
  988: sub display_color_options {
  989:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
  990:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
  991:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
  992:     my $datatable = '<tr'.$css_class.'>'.
  993:         '<td>'.$choices->{'font'}.'</td>';
  994:     if (!$is_custom->{'font'}) {
  995:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
  996:     } else {
  997:         $datatable .= '<td>&nbsp;</td>';
  998:     }
  999:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
 1000:     $datatable .= '<td><span class="LC_nobreak">'.
 1001:                   '<input type="text" size="10" name="'.$role.'_font"'.
 1002:                   ' value="'.$designs->{'font'}.'" />&nbsp;'.$fontlink.
 1003:                   '&nbsp;<span id="css_'.$role.'_font" style="background-color: '.
 1004:                   $designs->{'font'}.';">&nbsp;&nbsp;&nbsp;</span>'.
 1005:                   '</span></td></tr>';
 1006:     unless ($role eq 'login') { 
 1007:         $datatable .= '<tr'.$css_class.'>'.
 1008:                       '<td>'.$choices->{'fontmenu'}.'</td>';
 1009:         if (!$is_custom->{'fontmenu'}) {
 1010:             $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
 1011:         } else {
 1012:             $datatable .= '<td>&nbsp;</td>';
 1013:         }
 1014:         $fontlink = &color_pick($phase,$role,'fontmenu',$choices->{'fontmenu'},$designs->{'fontmenu'});
 1015:         $datatable .= '<td><span class="LC_nobreak">'.
 1016:                       '<input type="text" size="10" name="'.$role.'_fontmenu"'.
 1017:                       ' value="'.$designs->{'fontmenu'}.'" />&nbsp;'.$fontlink.
 1018:                       '&nbsp;<span id="css_'.$role.'_fontmenu" style="background-color: '.
 1019:                       $designs->{'fontmenu'}.';">&nbsp;&nbsp;&nbsp;</span>'.
 1020:                       '</span></td></tr>';
 1021:     }
 1022:     my $switchserver = &check_switchserver($dom,$confname);
 1023:     foreach my $img (@{$images}) {
 1024: 	$itemcount ++;
 1025:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1026:         $datatable .= '<tr'.$css_class.'>'.
 1027:                       '<td>'.$choices->{$img};
 1028:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
 1029:         if ($role eq 'login') {
 1030:             if ($img eq 'login') {
 1031:                 $login_hdr_pick =
 1032:                     &login_header_options($img,$role,$defaults,$is_custom,$choices);
 1033:                 $logincolors =
 1034:                     &login_text_colors($img,$role,$logintext,$phase,$choices,
 1035:                                             $designs);
 1036:             } elsif ($img ne 'domlogo') {
 1037:                 $datatable.= &logo_display_options($img,$defaults,$designs);
 1038:             }
 1039:         }
 1040:         $datatable .= '</td>';
 1041:         if ($designs->{$img} ne '') {
 1042:             $imgfile = $designs->{$img};
 1043: 	    $img_import = ($imgfile =~ m{^/adm/});
 1044:         } else {
 1045:             $imgfile = $defaults->{$img};
 1046:         }
 1047:         if ($imgfile) {
 1048:             my ($showfile,$fullsize);
 1049:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 1050:                 my $urldir = $1;
 1051:                 my $filename = $2;
 1052:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
 1053:                 if (@info) {
 1054:                     my $thumbfile = 'tn-'.$filename;
 1055:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
 1056:                     if (@thumb) {
 1057:                         $showfile = $urldir.'/'.$thumbfile;
 1058:                     } else {
 1059:                         $showfile = $imgfile;
 1060:                     }
 1061:                 } else {
 1062:                     $showfile = '';
 1063:                 }
 1064:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
 1065:                 $showfile = $imgfile;
 1066:                 my $imgdir = $1;
 1067:                 my $filename = $2;
 1068:                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
 1069:                     $showfile = "/$imgdir/tn-".$filename;
 1070:                 } else {
 1071:                     my $input = "/home/httpd/html".$imgfile;
 1072:                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
 1073:                     if (!-e $output) {
 1074:                         my ($width,$height) = &thumb_dimensions();
 1075:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
 1076:                         if ($fullwidth ne '' && $fullheight ne '') {
 1077:                             if ($fullwidth > $width && $fullheight > $height) { 
 1078:                                 my $size = $width.'x'.$height;
 1079:                                 system("convert -sample $size $input $output");
 1080:                                 $showfile = '/'.$imgdir.'/tn-'.$filename;
 1081:                             }
 1082:                         }
 1083:                     }
 1084:                 }
 1085:             }
 1086:             if ($showfile) {
 1087:                 if ($showfile =~ m{^/(adm|res)/}) {
 1088:                     if ($showfile =~ m{^/res/}) {
 1089:                         my $local_showfile =
 1090:                             &Apache::lonnet::filelocation('',$showfile);
 1091:                         &Apache::lonnet::repcopy($local_showfile);
 1092:                     }
 1093:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
 1094:                 }
 1095:                 if ($imgfile) {
 1096:                     if ($imgfile  =~ m{^/(adm|res)/}) {
 1097:                         if ($imgfile =~ m{^/res/}) {
 1098:                             my $local_imgfile =
 1099:                                 &Apache::lonnet::filelocation('',$imgfile);
 1100:                             &Apache::lonnet::repcopy($local_imgfile);
 1101:                         }
 1102:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
 1103:                     } else {
 1104:                         $fullsize = $imgfile;
 1105:                     }
 1106:                 }
 1107:                 $datatable .= '<td>';
 1108:                 if ($img eq 'login') {
 1109:                     $datatable .= $login_hdr_pick;
 1110:                 } 
 1111:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
 1112:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
 1113:             } else {
 1114:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
 1115:                               &mt('Upload:');
 1116:             }
 1117:         } else {
 1118:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
 1119:                           &mt('Upload:');
 1120:         }
 1121:         if ($switchserver) {
 1122:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 1123:         } else {
 1124:             if ($img ne 'login') { # suppress file selection for Log-in header
 1125:                 $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
 1126:             }
 1127:         }
 1128:         $datatable .= '</td></tr>';
 1129:     }
 1130:     $itemcount ++;
 1131:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1132:     $datatable .= '<tr'.$css_class.'>'.
 1133:                   '<td>'.$choices->{'bgs'}.'</td>';
 1134:     my $bgs_def;
 1135:     foreach my $item (@{$bgs}) {
 1136:         if (!$is_custom->{$item}) {
 1137:             $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>';
 1138:         }
 1139:     }
 1140:     if ($bgs_def) {
 1141:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
 1142:     } else {
 1143:         $datatable .= '<td>&nbsp;</td>';
 1144:     }
 1145:     $datatable .= '<td class="LC_right_item">'.
 1146:                   '<table border="0"><tr>';
 1147:     foreach my $item (@{$bgs}) {
 1148:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
 1149:         $datatable .= '<td align="center">'.$link;
 1150:         if ($designs->{'bgs'}{$item}) {
 1151:             $datatable .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
 1152:         }
 1153:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
 1154:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
 1155:     }
 1156:     $datatable .= '</tr></table></td></tr>';
 1157:     $itemcount ++;
 1158:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 1159:     $datatable .= '<tr'.$css_class.'>'.
 1160:                   '<td>'.$choices->{'links'}.'</td>';
 1161:     my $links_def;
 1162:     foreach my $item (@{$links}) {
 1163:         if (!$is_custom->{$item}) {
 1164:             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
 1165:         }
 1166:     }
 1167:     if ($links_def) {
 1168:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
 1169:     } else {
 1170:         $datatable .= '<td>&nbsp;</td>';
 1171:     }
 1172:     $datatable .= '<td class="LC_right_item">'.
 1173:                   '<table border="0"><tr>';
 1174:     foreach my $item (@{$links}) {
 1175:         $datatable .= '<td align="center">'."\n".
 1176:                       &color_pick($phase,$role,$item,$choices->{$item},
 1177:                                   $designs->{'links'}{$item});
 1178:         if ($designs->{'links'}{$item}) {
 1179:             $datatable.='&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
 1180:         }
 1181:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
 1182:                       '" /></td>';
 1183:     }
 1184:     $$rowtotal += $itemcount;
 1185:     return $datatable;
 1186: }
 1187: 
 1188: sub logo_display_options {
 1189:     my ($img,$defaults,$designs) = @_;
 1190:     my $checkedon;
 1191:     if (ref($defaults) eq 'HASH') {
 1192:         if (ref($defaults->{'showlogo'}) eq 'HASH') {
 1193:             if ($defaults->{'showlogo'}{$img}) {
 1194:                 $checkedon = 'checked="checked" ';     
 1195:             }
 1196:         } 
 1197:     }
 1198:     if (ref($designs) eq 'HASH') {
 1199:         if (ref($designs->{'showlogo'}) eq 'HASH') {
 1200:             if (defined($designs->{'showlogo'}{$img})) {
 1201:                 if ($designs->{'showlogo'}{$img} == 0) {
 1202:                     $checkedon = '';
 1203:                 } elsif ($designs->{'showlogo'}{$img} == 1) {
 1204:                     $checkedon = 'checked="checked" ';
 1205:                 }
 1206:             }
 1207:         }
 1208:     }
 1209:     return '<br /><label>&nbsp;&nbsp;<input type="checkbox" name="'.
 1210:            'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
 1211:            &mt('show').'</label>'."\n";
 1212: }
 1213: 
 1214: sub login_header_options  {
 1215:     my ($img,$role,$defaults,$is_custom,$choices) = @_;
 1216:     my $output = '';
 1217:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
 1218:         $output .= &mt('Text default(s):').'<br />';
 1219:         if (!$is_custom->{'textcol'}) {
 1220:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
 1221:                        '&nbsp;&nbsp;&nbsp;';
 1222:         }
 1223:         if (!$is_custom->{'bgcol'}) {
 1224:             $output .= $choices->{'bgcol'}.':&nbsp;'.
 1225:                        '<span id="css_'.$role.'_font" style="background-color: '.
 1226:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
 1227:         }
 1228:         $output .= '<br />';
 1229:     }
 1230:     $output .='<br />';
 1231:     return $output;
 1232: }
 1233: 
 1234: sub login_text_colors {
 1235:     my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
 1236:     my $color_menu = '<table border="0"><tr>';
 1237:     foreach my $item (@{$logintext}) {
 1238:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
 1239:         $color_menu .= '<td align="center">'.$link;
 1240:         if ($designs->{'logintext'}{$item}) {
 1241:             $color_menu .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
 1242:         }
 1243:         $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
 1244:                        $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
 1245:                        '<td>&nbsp;</td>';
 1246:     }
 1247:     $color_menu .= '</tr></table><br />';
 1248:     return $color_menu;
 1249: }
 1250: 
 1251: sub image_changes {
 1252:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
 1253:     my $output;
 1254:     if ($img eq 'login') {
 1255:             # suppress image for Log-in header
 1256:     } elsif (!$is_custom) {
 1257:         if ($img ne 'domlogo') {
 1258:             $output .= &mt('Default image:').'<br />';
 1259:         } else {
 1260:             $output .= &mt('Default in use:').'<br />';
 1261:         }
 1262:     }
 1263:     if ($img eq 'login') { # suppress image for Log-in header
 1264:         $output .= '<td>'.$logincolors;
 1265:     } else {
 1266:         if ($img_import) {
 1267:             $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
 1268:         }
 1269:         $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
 1270:                    $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
 1271:         if ($is_custom) {
 1272:             $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
 1273:                        '<input type="checkbox" name="'.
 1274:                        $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
 1275:                        '</label>&nbsp;'.&mt('Replace:').'</span><br />';
 1276:         } else {
 1277:             $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
 1278:         }
 1279:     }
 1280:     return $output;
 1281: }
 1282: 
 1283: sub color_pick {
 1284:     my ($phase,$role,$item,$desc,$curcol) = @_;
 1285:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
 1286:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
 1287:                ');">'.$desc.'</a>';
 1288:     return $link;
 1289: }
 1290: 
 1291: sub print_quotas {
 1292:     my ($dom,$settings,$rowtotal,$action) = @_;
 1293:     my $context;
 1294:     if ($action eq 'quotas') {
 1295:         $context = 'tools';
 1296:     } else {
 1297:         $context = $action;
 1298:     }
 1299:     my ($datatable,$defaultquota,@usertools,@options,%validations);
 1300:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1301:     my $typecount = 0;
 1302:     my ($css_class,%titles);
 1303:     if ($context eq 'requestcourses') {
 1304:         @usertools = ('official','unofficial','community');
 1305:         @options =('norequest','approval','validate','autolimit');
 1306:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 1307:         %titles = &courserequest_titles();
 1308:     } else {
 1309:         @usertools = ('aboutme','blog','portfolio');
 1310:         %titles = &tool_titles();
 1311:     }
 1312:     if (ref($types) eq 'ARRAY') {
 1313:         foreach my $type (@{$types}) {
 1314:             my $currdefquota;
 1315:             unless ($context eq 'requestcourses') {
 1316:                 if (ref($settings) eq 'HASH') {
 1317:                     if (ref($settings->{defaultquota}) eq 'HASH') {
 1318:                         $currdefquota = $settings->{defaultquota}->{$type}; 
 1319:                     } else {
 1320:                         $currdefquota = $settings->{$type};
 1321:                     }
 1322:                 }
 1323:             }
 1324:             if (defined($usertypes->{$type})) {
 1325:                 $typecount ++;
 1326:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
 1327:                 $datatable .= '<tr'.$css_class.'>'.
 1328:                               '<td>'.$usertypes->{$type}.'</td>'.
 1329:                               '<td class="LC_left_item">';
 1330:                 if ($context eq 'requestcourses') {
 1331:                     $datatable .= '<table><tr>';
 1332:                 }
 1333:                 my %cell;  
 1334:                 foreach my $item (@usertools) {
 1335:                     if ($context eq 'requestcourses') {
 1336:                         my ($curroption,$currlimit);
 1337:                         if (ref($settings) eq 'HASH') {
 1338:                             if (ref($settings->{$item}) eq 'HASH') {
 1339:                                 $curroption = $settings->{$item}->{$type};
 1340:                                 if ($curroption =~ /^autolimit=(\d*)$/) {
 1341:                                     $currlimit = $1; 
 1342:                                 }
 1343:                             }
 1344:                         }
 1345:                         if (!$curroption) {
 1346:                             $curroption = 'norequest';
 1347:                         }
 1348:                         $datatable .= '<th>'.$titles{$item}.'</th>';
 1349:                         foreach my $option (@options) {
 1350:                             my $val = $option;
 1351:                             if ($option eq 'norequest') {
 1352:                                 $val = 0;  
 1353:                             }
 1354:                             if ($option eq 'validate') {
 1355:                                 my $canvalidate = 0;
 1356:                                 if (ref($validations{$item}) eq 'HASH') { 
 1357:                                     if ($validations{$item}{$type}) {
 1358:                                         $canvalidate = 1;
 1359:                                     }
 1360:                                 }
 1361:                                 next if (!$canvalidate);
 1362:                             }
 1363:                             my $checked = '';
 1364:                             if ($option eq $curroption) {
 1365:                                 $checked = ' checked="checked"';
 1366:                             } elsif ($option eq 'autolimit') {
 1367:                                 if ($curroption =~ /^autolimit/) {
 1368:                                     $checked = ' checked="checked"';
 1369:                                 }                       
 1370:                             } 
 1371:                             $cell{$item} .= '<span class="LC_nobreak"><label>'.
 1372:                                   '<input type="radio" name="crsreq_'.$item.
 1373:                                   '_'.$type.'" value="'.$val.'"'.$checked.' />'.
 1374:                                   $titles{$option}.'</label>';
 1375:                             if ($option eq 'autolimit') {
 1376:                                 $cell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1377:                                                 $item.'_limit_'.$type.'" size="1" '.
 1378:                                                 'value="'.$currlimit.'" />';
 1379:                             }
 1380:                             $cell{$item} .= '</span> ';
 1381:                             if ($option eq 'autolimit') {
 1382:                                 $cell{$item} .= $titles{'unlimited'};
 1383:                             }
 1384:                         }
 1385:                     } else {
 1386:                         my $checked = 'checked="checked" ';
 1387:                         if (ref($settings) eq 'HASH') {
 1388:                             if (ref($settings->{$item}) eq 'HASH') {
 1389:                                 if ($settings->{$item}->{$type} == 0) {
 1390:                                     $checked = '';
 1391:                                 } elsif ($settings->{$item}->{$type} == 1) {
 1392:                                     $checked =  'checked="checked" ';
 1393:                                 }
 1394:                             }
 1395:                         }
 1396:                         $datatable .= '<span class="LC_nobreak"><label>'.
 1397:                                       '<input type="checkbox" name="'.$context.'_'.$item.
 1398:                                       '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
 1399:                                       '</label></span>&nbsp; ';
 1400:                     }
 1401:                 }
 1402:                 if ($context eq 'requestcourses') {
 1403:                     $datatable .= '</tr><tr>';
 1404:                     foreach my $item (@usertools) {
 1405:                         $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';  
 1406:                     }
 1407:                     $datatable .= '</tr></table>';
 1408:                 }
 1409:                 $datatable .= '</td>';
 1410:                 unless ($context eq 'requestcourses') {
 1411:                     $datatable .= 
 1412:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
 1413:                               '<input type="text" name="quota_'.$type.
 1414:                               '" value="'.$currdefquota.
 1415:                               '" size="5" /> Mb</span></td>';
 1416:                 }
 1417:                 $datatable .= '</tr>';
 1418:             }
 1419:         }
 1420:     }
 1421:     unless ($context eq 'requestcourses') {
 1422:         $defaultquota = '20';
 1423:         if (ref($settings) eq 'HASH') {
 1424:             if (ref($settings->{'defaultquota'}) eq 'HASH') {
 1425:                 $defaultquota = $settings->{'defaultquota'}->{'default'};
 1426:             } elsif (defined($settings->{'default'})) {
 1427:                 $defaultquota = $settings->{'default'};
 1428:             }
 1429:         }
 1430:     }
 1431:     $typecount ++;
 1432:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1433:     $datatable .= '<tr'.$css_class.'>'.
 1434:                   '<td>'.$othertitle.'</td>'.
 1435:                   '<td class="LC_left_item">';
 1436:     if ($context eq 'requestcourses') {
 1437:         $datatable .= '<table><tr>';
 1438:     }
 1439:     my %defcell;
 1440:     foreach my $item (@usertools) {
 1441:         if ($context eq 'requestcourses') {
 1442:             my ($curroption,$currlimit);
 1443:             if (ref($settings) eq 'HASH') {
 1444:                 if (ref($settings->{$item}) eq 'HASH') {
 1445:                     $curroption = $settings->{$item}->{'default'};
 1446:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1447:                         $currlimit = $1;
 1448:                     }
 1449:                 }
 1450:             }
 1451:             if (!$curroption) {
 1452:                 $curroption = 'norequest';
 1453:             }
 1454:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1455:             foreach my $option (@options) {
 1456:                 my $val = $option;
 1457:                 if ($option eq 'norequest') {
 1458:                     $val = 0;
 1459:                 }
 1460:                 if ($option eq 'validate') {
 1461:                     my $canvalidate = 0;
 1462:                     if (ref($validations{$item}) eq 'HASH') {
 1463:                         if ($validations{$item}{'default'}) {
 1464:                             $canvalidate = 1;
 1465:                         }
 1466:                     }
 1467:                     next if (!$canvalidate);
 1468:                 }
 1469:                 my $checked = '';
 1470:                 if ($option eq $curroption) {
 1471:                     $checked = ' checked="checked"';
 1472:                 } elsif ($option eq 'autolimit') {
 1473:                     if ($curroption =~ /^autolimit/) {
 1474:                         $checked = ' checked="checked"';
 1475:                     }
 1476:                 }
 1477:                 $defcell{$item} .= '<span class="LC_nobreak"><label>'.
 1478:                                   '<input type="radio" name="crsreq_'.$item.
 1479:                                   '_default" value="'.$val.'"'.$checked.' />'.
 1480:                                   $titles{$option}.'</label>';
 1481:                 if ($option eq 'autolimit') {
 1482:                     $defcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1483:                                        $item.'_limit_default" size="1" '.
 1484:                                        'value="'.$currlimit.'" />';
 1485:                 }
 1486:                 $defcell{$item} .= '</span> ';
 1487:                 if ($option eq 'autolimit') {
 1488:                     $defcell{$item} .= $titles{'unlimited'};
 1489:                 }
 1490:             }
 1491:         } else {
 1492:             my $checked = 'checked="checked" ';
 1493:             if (ref($settings) eq 'HASH') {
 1494:                 if (ref($settings->{$item}) eq 'HASH') {
 1495:                     if ($settings->{$item}->{'default'} == 0) {
 1496:                         $checked = '';
 1497:                     } elsif ($settings->{$item}->{'default'} == 1) {
 1498:                         $checked = 'checked="checked" ';
 1499:                     }
 1500:                 }
 1501:             }
 1502:             $datatable .= '<span class="LC_nobreak"><label>'.
 1503:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1504:                           '" value="default" '.$checked.'/>'.$titles{$item}.
 1505:                           '</label></span>&nbsp; ';
 1506:         }
 1507:     }
 1508:     if ($context eq 'requestcourses') {
 1509:         $datatable .= '</tr><tr>';
 1510:         foreach my $item (@usertools) {
 1511:             $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
 1512:         }
 1513:         $datatable .= '</tr></table>';
 1514:     }
 1515:     $datatable .= '</td>';
 1516:     unless ($context eq 'requestcourses') {
 1517:         $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
 1518:                       '<input type="text" name="defaultquota" value="'.
 1519:                       $defaultquota.'" size="5" /> Mb</span></td>';
 1520:     }
 1521:     $datatable .= '</tr>';
 1522:     $typecount ++;
 1523:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1524:     $datatable .= '<tr'.$css_class.'>'.
 1525:                   '<td>'.&mt('LON-CAPA Advanced Users').' ';
 1526:     if ($context eq 'requestcourses') {
 1527:         $datatable .= &mt('(overrides affiliation, if set)').
 1528:                       '</td>'.
 1529:                       '<td class="LC_left_item">'.
 1530:                       '<table><tr>';
 1531:     } else {
 1532:         $datatable .= &mt('(overrides affiliation, if checked)').
 1533:                       '</td>'.
 1534:                       '<td class="LC_left_item" colspan="2">'.
 1535:                       '<br />';
 1536:     }
 1537:     my %advcell;
 1538:     foreach my $item (@usertools) {
 1539:         if ($context eq 'requestcourses') {
 1540:             my ($curroption,$currlimit);
 1541:             if (ref($settings) eq 'HASH') {
 1542:                 if (ref($settings->{$item}) eq 'HASH') {
 1543:                     $curroption = $settings->{$item}->{'_LC_adv'};
 1544:                     if ($curroption =~ /^autolimit=(\d*)$/) {
 1545:                         $currlimit = $1;
 1546:                     }
 1547:                 }
 1548:             }
 1549:             $datatable .= '<th>'.$titles{$item}.'</th>';
 1550:             my $checked = '';
 1551:             if ($curroption eq '') {
 1552:                 $checked = ' checked="checked"';
 1553:             }
 1554:             $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 1555:                                '<input type="radio" name="crsreq_'.$item.
 1556:                                '__LC_adv" value=""'.$checked.' />'.
 1557:                                &mt('No override set').'</label></span>&nbsp; ';
 1558:             foreach my $option (@options) {
 1559:                 my $val = $option;
 1560:                 if ($option eq 'norequest') {
 1561:                     $val = 0;
 1562:                 }
 1563:                 if ($option eq 'validate') {
 1564:                     my $canvalidate = 0;
 1565:                     if (ref($validations{$item}) eq 'HASH') {
 1566:                         if ($validations{$item}{'_LC_adv'}) {
 1567:                             $canvalidate = 1;
 1568:                         }
 1569:                     }
 1570:                     next if (!$canvalidate);
 1571:                 }
 1572:                 my $checked = '';
 1573:                 if ($val eq $curroption) {
 1574:                     $checked = ' checked="checked"';
 1575:                 } elsif ($option eq 'autolimit') {
 1576:                     if ($curroption =~ /^autolimit/) {
 1577:                         $checked = ' checked="checked"';
 1578:                     }
 1579:                 }
 1580:                 $advcell{$item} .= '<span class="LC_nobreak"><label>'.
 1581:                                   '<input type="radio" name="crsreq_'.$item.
 1582:                                   '__LC_adv" value="'.$val.'"'.$checked.' />'.
 1583:                                   $titles{$option}.'</label>';
 1584:                 if ($option eq 'autolimit') {
 1585:                     $advcell{$item} .= '&nbsp;<input type="text" name="crsreq_'.
 1586:                                        $item.'_limit__LC_adv" size="1" '.
 1587:                                        'value="'.$currlimit.'" />';
 1588:                 }
 1589:                 $advcell{$item} .= '</span> ';
 1590:                 if ($option eq 'autolimit') {
 1591:                     $advcell{$item} .= $titles{'unlimited'};
 1592:                 }
 1593:             }
 1594:         } else {
 1595:             my $checked = 'checked="checked" ';
 1596:             if (ref($settings) eq 'HASH') {
 1597:                 if (ref($settings->{$item}) eq 'HASH') {
 1598:                     if ($settings->{$item}->{'_LC_adv'} == 0) {
 1599:                         $checked = '';
 1600:                     } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
 1601:                         $checked = 'checked="checked" ';
 1602:                     }
 1603:                 }
 1604:             }
 1605:             $datatable .= '<span class="LC_nobreak"><label>'.
 1606:                           '<input type="checkbox" name="'.$context.'_'.$item.
 1607:                           '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
 1608:                           '</label></span>&nbsp; ';
 1609:         }
 1610:     }
 1611:     if ($context eq 'requestcourses') {
 1612:         $datatable .= '</tr><tr>';
 1613:         foreach my $item (@usertools) {
 1614:             $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
 1615:         }
 1616:         $datatable .= '</tr></table>';
 1617:     }
 1618:     $datatable .= '</td></tr>';
 1619:     $$rowtotal += $typecount;
 1620:     return $datatable;
 1621: }
 1622: 
 1623: sub print_courserequestmail {
 1624:     my ($dom,$settings,$rowtotal) = @_;
 1625:     my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
 1626:     $now = time;
 1627:     $rows = 0;
 1628:     %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
 1629:     foreach my $server (keys(%dompersonnel)) {
 1630:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
 1631:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
 1632:             if (!grep(/^$uname:$udom$/,@domcoord)) {
 1633:                 push(@domcoord,$uname.':'.$udom);
 1634:             }
 1635:         }
 1636:     }
 1637:     if (ref($settings) eq 'HASH') {
 1638:         if (ref($settings->{'notify'}) eq 'HASH') {
 1639:             if ($settings->{'notify'}{'approval'} ne '') {
 1640:                @currapproval = split(',',$settings->{'notify'}{'approval'});
 1641:             }
 1642:         }
 1643:     }
 1644:     if (@currapproval) {
 1645:         foreach my $dc (@currapproval) {
 1646:             unless (grep(/^\Q$dc\E$/,@domcoord)) {
 1647:                 push(@domcoord,$dc);
 1648:             }
 1649:         }
 1650:     }
 1651:     @domcoord = sort(@domcoord);
 1652:     my $numinrow = 4;
 1653:     my $numdc = @domcoord;
 1654:     my $css_class = 'class="LC_odd_row"';
 1655:     $datatable = '<tr'.$css_class.'>'.
 1656:                  ' <td>'.&mt('Receive notification of course requests requiring approval.').
 1657:                  ' </td>'.
 1658:                  ' <td class="LC_left_item">';
 1659:     if (@domcoord > 0) {
 1660:         $datatable .= '<table>';
 1661:         for (my $i=0; $i<$numdc; $i++) {
 1662:             my $rem = $i%($numinrow);
 1663:             if ($rem == 0) {
 1664:                 if ($i > 0) {
 1665:                     $datatable .= '</tr>';
 1666:                 }
 1667:                 $datatable .= '<tr>';
 1668:                 $rows ++;
 1669:             }
 1670:             my $check = ' ';
 1671:             if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
 1672:                 $check = ' checked="checked" ';
 1673:             }
 1674:             my ($uname,$udom) = split(':',$domcoord[$i]);
 1675:             my $fullname = &Apache::loncommon::plainname($uname,$udom);
 1676:             if ($i == $numdc-1) {
 1677:                 my $colsleft = $numinrow-$rem;
 1678:                 if ($colsleft > 1) {
 1679:                     $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 1680:                 } else {
 1681:                     $datatable .= '<td class="LC_left_item">';
 1682:                 }
 1683:             } else {
 1684:                 $datatable .= '<td class="LC_left_item">';
 1685:             }
 1686:             $datatable .= '<span class="LC_nobreak"><label>'.
 1687:                           '<input type="checkbox" name="reqapprovalnotify" '.
 1688:                           'value="'.$domcoord[$i].'"'.$check.'/>'.
 1689:                           $fullname.'</label></span></td>';
 1690:         }
 1691:         $datatable .= '</tr></table>';
 1692:     } else {
 1693:         $datatable .= &mt('There are no active Domain Coordinators');
 1694:         $rows ++;
 1695:     }
 1696:     $datatable .='</td></tr>';
 1697:     $$rowtotal += $rows;
 1698:     return $datatable;
 1699: }
 1700: 
 1701: sub print_autoenroll {
 1702:     my ($dom,$settings,$rowtotal) = @_;
 1703:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 1704:     my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
 1705:     if (ref($settings) eq 'HASH') {
 1706:         if (exists($settings->{'run'})) {
 1707:             if ($settings->{'run'} eq '0') {
 1708:                 $runoff = ' checked="checked" ';
 1709:                 $runon = ' ';
 1710:             } else {
 1711:                 $runon = ' checked="checked" ';
 1712:                 $runoff = ' ';
 1713:             }
 1714:         } else {
 1715:             if ($autorun) {
 1716:                 $runon = ' checked="checked" ';
 1717:                 $runoff = ' ';
 1718:             } else {
 1719:                 $runoff = ' checked="checked" ';
 1720:                 $runon = ' ';
 1721:             }
 1722:         }
 1723:         if (exists($settings->{'co-owners'})) {
 1724:             if ($settings->{'co-owners'} eq '0') {
 1725:                 $coownersoff = ' checked="checked" ';
 1726:                 $coownerson = ' ';
 1727:             } else {
 1728:                 $coownerson = ' checked="checked" ';
 1729:                 $coownersoff = ' ';
 1730:             }
 1731:         } else {
 1732:             $coownersoff = ' checked="checked" ';
 1733:             $coownerson = ' ';
 1734:         }
 1735:         if (exists($settings->{'sender_domain'})) {
 1736:             $defdom = $settings->{'sender_domain'};
 1737:         }
 1738:     } else {
 1739:         if ($autorun) {
 1740:             $runon = ' checked="checked" ';
 1741:             $runoff = ' ';
 1742:         } else {
 1743:             $runoff = ' checked="checked" ';
 1744:             $runon = ' ';
 1745:         }
 1746:     }
 1747:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
 1748:     my $notif_sender;
 1749:     if (ref($settings) eq 'HASH') {
 1750:         $notif_sender = $settings->{'sender_uname'};
 1751:     }
 1752:     my $datatable='<tr class="LC_odd_row">'.
 1753:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
 1754:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1755:                   '<input type="radio" name="autoenroll_run"'.
 1756:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1757:                   '<label><input type="radio" name="autoenroll_run"'.
 1758:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1759:                   '</tr><tr>'.
 1760:                   '<td>'.&mt('Notification messages - sender').
 1761:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 1762:                   &mt('username').':&nbsp;'.
 1763:                   '<input type="text" name="sender_uname" value="'.
 1764:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
 1765:                   ':&nbsp;'.$domform.'</span></td></tr>'.
 1766:                   '<tr class="LC_odd_row">'.
 1767:                   '<td>'.&mt('Automatically assign co-ownership').'</td>'.
 1768:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1769:                   '<input type="radio" name="autoassign_coowners"'.
 1770:                   $coownerson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1771:                   '<label><input type="radio" name="autoassign_coowners"'.
 1772:                   $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1773:                   '</tr>';
 1774:     $$rowtotal += 3;
 1775:     return $datatable;
 1776: }
 1777: 
 1778: sub print_autoupdate {
 1779:     my ($position,$dom,$settings,$rowtotal) = @_;
 1780:     my $datatable;
 1781:     if ($position eq 'top') {
 1782:         my $updateon = ' ';
 1783:         my $updateoff = ' checked="checked" ';
 1784:         my $classlistson = ' ';
 1785:         my $classlistsoff = ' checked="checked" ';
 1786:         if (ref($settings) eq 'HASH') {
 1787:             if ($settings->{'run'} eq '1') {
 1788:                 $updateon = $updateoff;
 1789:                 $updateoff = ' ';
 1790:             }
 1791:             if ($settings->{'classlists'} eq '1') {
 1792:                 $classlistson = $classlistsoff;
 1793:                 $classlistsoff = ' ';
 1794:             }
 1795:         }
 1796:         my %title = (
 1797:                    run => 'Auto-update active?',
 1798:                    classlists => 'Update information in classlists?',
 1799:                     );
 1800:         $datatable = '<tr class="LC_odd_row">'. 
 1801:                   '<td>'.&mt($title{'run'}).'</td>'.
 1802:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1803:                   '<input type="radio" name="autoupdate_run"'.
 1804:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1805:                   '<label><input type="radio" name="autoupdate_run"'.
 1806:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
 1807:                   '</tr><tr>'.
 1808:                   '<td>'.&mt($title{'classlists'}).'</td>'.
 1809:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 1810:                   '<label><input type="radio" name="classlists"'.
 1811:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1812:                   '<label><input type="radio" name="classlists"'.
 1813:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
 1814:                   '</tr>';
 1815:         $$rowtotal += 2;
 1816:     } elsif ($position eq 'middle') {
 1817:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1818:         my $numinrow = 3;
 1819:         my $locknamesettings;
 1820:         $datatable .= &insttypes_row($settings,$types,$usertypes,
 1821:                                      $dom,$numinrow,$othertitle,
 1822:                                     'lockablenames');
 1823:         $$rowtotal ++;
 1824:     } else {
 1825:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1826:         my @fields = ('lastname','firstname','middlename','generation',
 1827:                       'permanentemail','id');
 1828:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 1829:         my $numrows = 0;
 1830:         if (ref($types) eq 'ARRAY') {
 1831:             if (@{$types} > 0) {
 1832:                 $datatable = 
 1833:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
 1834:                                          \@fields,$types,\$numrows);
 1835:                     $$rowtotal += @{$types}; 
 1836:             }
 1837:         }
 1838:         $datatable .= 
 1839:             &usertype_update_row($settings,{'default' => $othertitle},
 1840:                                  \%fieldtitles,\@fields,['default'],
 1841:                                  \$numrows);
 1842:         $$rowtotal ++;     
 1843:     }
 1844:     return $datatable;
 1845: }
 1846: 
 1847: sub print_autocreate {
 1848:     my ($dom,$settings,$rowtotal) = @_;
 1849:     my (%createon,%createoff);
 1850:     my $curr_dc;
 1851:     my @types = ('xml','req');
 1852:     if (ref($settings) eq 'HASH') {
 1853:         foreach my $item (@types) {
 1854:             $createoff{$item} = ' checked="checked" ';
 1855:             $createon{$item} = ' ';
 1856:             if (exists($settings->{$item})) {
 1857:                 if ($settings->{$item}) {
 1858:                     $createon{$item} = ' checked="checked" ';
 1859:                     $createoff{$item} = ' ';
 1860:                 }
 1861:             }
 1862:         }
 1863:         $curr_dc = $settings->{'xmldc'};
 1864:     } else {
 1865:         foreach my $item (@types) {
 1866:             $createoff{$item} = ' checked="checked" ';
 1867:             $createon{$item} = ' ';
 1868:         }
 1869:     }
 1870:     $$rowtotal += 2;
 1871:     my $datatable='<tr class="LC_odd_row">'.
 1872:                   '<td>'.&mt('Create pending official courses from XML files').'</td>'.
 1873:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1874:                   '<input type="radio" name="autocreate_xml"'.
 1875:                   $createon{'xml'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1876:                   '<label><input type="radio" name="autocreate_xml"'.
 1877:                   $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>';
 1878:     my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
 1879:     if ($numdc > 1) {
 1880:         $datatable .= '</td><tr><td>'.
 1881:                       &mt('XML files processed as: (choose Dom. Coord.)'). 
 1882:                       '</td><td class="LC_left_item">'.$dctable.'</td></tr>'.
 1883:                       '<tr class="LC_odd_row">';
 1884:         $$rowtotal ++ ;
 1885:     } else {
 1886:         $datatable .= '</td></tr><tr>';
 1887:     }
 1888:     $datatable .= '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
 1889:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1890:                   '<input type="radio" name="autocreate_req"'.
 1891:                   $createon{'req'}.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1892:                   '<label><input type="radio" name="autocreate_req"'.
 1893:                   $createoff{'req'}.' value="0" />'.&mt('No').'</label></span></td>'.
 1894:                   '</tr>';
 1895:     return $datatable;
 1896: }
 1897: 
 1898: sub print_directorysrch {
 1899:     my ($dom,$settings,$rowtotal) = @_;
 1900:     my $srchon = ' ';
 1901:     my $srchoff = ' checked="checked" ';
 1902:     my ($exacton,$containson,$beginson);
 1903:     my $localon = ' ';
 1904:     my $localoff = ' checked="checked" ';
 1905:     if (ref($settings) eq 'HASH') {
 1906:         if ($settings->{'available'} eq '1') {
 1907:             $srchon = $srchoff;
 1908:             $srchoff = ' ';
 1909:         }
 1910:         if ($settings->{'localonly'} eq '1') {
 1911:             $localon = $localoff;
 1912:             $localoff = ' ';
 1913:         }
 1914:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
 1915:             foreach my $type (@{$settings->{'searchtypes'}}) {
 1916:                 if ($type eq 'exact') {
 1917:                     $exacton = ' checked="checked" ';
 1918:                 } elsif ($type eq 'contains') {
 1919:                     $containson = ' checked="checked" ';
 1920:                 } elsif ($type eq 'begins') {
 1921:                     $beginson = ' checked="checked" ';
 1922:                 }
 1923:             }
 1924:         } else {
 1925:             if ($settings->{'searchtypes'} eq 'exact') {
 1926:                 $exacton = ' checked="checked" ';
 1927:             } elsif ($settings->{'searchtypes'} eq 'contains') {
 1928:                 $containson = ' checked="checked" ';
 1929:             } elsif ($settings->{'searchtypes'} eq 'specify') {
 1930:                 $exacton = ' checked="checked" ';
 1931:                 $containson = ' checked="checked" ';
 1932:             }
 1933:         }
 1934:     }
 1935:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
 1936:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 1937: 
 1938:     my $numinrow = 4;
 1939:     my $cansrchrow = 0;
 1940:     my $datatable='<tr class="LC_odd_row">'.
 1941:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
 1942:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1943:                   '<input type="radio" name="dirsrch_available"'.
 1944:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1945:                   '<label><input type="radio" name="dirsrch_available"'.
 1946:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1947:                   '</tr><tr>'.
 1948:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
 1949:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1950:                   '<input type="radio" name="dirsrch_localonly"'.
 1951:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
 1952:                   '<label><input type="radio" name="dirsrch_localonly"'.
 1953:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
 1954:                   '</tr>';
 1955:     $$rowtotal += 2;
 1956:     if (ref($usertypes) eq 'HASH') {
 1957:         if (keys(%{$usertypes}) > 0) {
 1958:             $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
 1959:                                          $numinrow,$othertitle,'cansearch');
 1960:             $cansrchrow = 1;
 1961:         }
 1962:     }
 1963:     if ($cansrchrow) {
 1964:         $$rowtotal ++;
 1965:         $datatable .= '<tr>';
 1966:     } else {
 1967:         $datatable .= '<tr class="LC_odd_row">';
 1968:     }
 1969:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
 1970:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
 1971:     foreach my $title (@{$titleorder}) {
 1972:         if (defined($searchtitles->{$title})) {
 1973:             my $check = ' ';
 1974:             if (ref($settings) eq 'HASH') {
 1975:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
 1976:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
 1977:                         $check = ' checked="checked" ';
 1978:                     }
 1979:                 }
 1980:             }
 1981:             $datatable .= '<td class="LC_left_item">'.
 1982:                           '<span class="LC_nobreak"><label>'.
 1983:                           '<input type="checkbox" name="searchby" '.
 1984:                           'value="'.$title.'"'.$check.'/>'.
 1985:                           $searchtitles->{$title}.'</label></span></td>';
 1986:         }
 1987:     }
 1988:     $datatable .= '</tr></table></td></tr>';
 1989:     $$rowtotal ++;
 1990:     if ($cansrchrow) {
 1991:         $datatable .= '<tr class="LC_odd_row">';
 1992:     } else {
 1993:         $datatable .= '<tr>';
 1994:     }
 1995:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
 1996:                   '<td class="LC_left_item" colspan="2">'.
 1997:                   '<span class="LC_nobreak"><label>'.
 1998:                   '<input type="checkbox" name="searchtypes" '.
 1999:                   $exacton.' value="exact" />'.&mt('Exact match').
 2000:                   '</label>&nbsp;'.
 2001:                   '<label><input type="checkbox" name="searchtypes" '.
 2002:                   $beginson.' value="begins" />'.&mt('Begins with').
 2003:                   '</label>&nbsp;'.
 2004:                   '<label><input type="checkbox" name="searchtypes" '.
 2005:                   $containson.' value="contains" />'.&mt('Contains').
 2006:                   '</label></span></td></tr>';
 2007:     $$rowtotal ++;
 2008:     return $datatable;
 2009: }
 2010: 
 2011: sub print_contacts {
 2012:     my ($dom,$settings,$rowtotal) = @_;
 2013:     my $datatable;
 2014:     my @contacts = ('adminemail','supportemail');
 2015:     my (%checked,%to,%otheremails,%bccemails);
 2016:     my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
 2017:                     'requestsmail');
 2018:     foreach my $type (@mailings) {
 2019:         $otheremails{$type} = '';
 2020:     }
 2021:     $bccemails{'helpdeskmail'} = '';
 2022:     if (ref($settings) eq 'HASH') {
 2023:         foreach my $item (@contacts) {
 2024:             if (exists($settings->{$item})) {
 2025:                 $to{$item} = $settings->{$item};
 2026:             }
 2027:         }
 2028:         foreach my $type (@mailings) {
 2029:             if (exists($settings->{$type})) {
 2030:                 if (ref($settings->{$type}) eq 'HASH') {
 2031:                     foreach my $item (@contacts) {
 2032:                         if ($settings->{$type}{$item}) {
 2033:                             $checked{$type}{$item} = ' checked="checked" ';
 2034:                         }
 2035:                     }
 2036:                     $otheremails{$type} = $settings->{$type}{'others'};
 2037:                     if ($type eq 'helpdeskmail') {
 2038:                         $bccemails{$type} = $settings->{$type}{'bcc'};
 2039:                     }
 2040:                 }
 2041:             } elsif ($type eq 'lonstatusmail') {
 2042:                 $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
 2043:             }
 2044:         }
 2045:     } else {
 2046:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 2047:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 2048:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
 2049:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
 2050:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
 2051:         $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" '; 
 2052:         $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
 2053:     }
 2054:     my ($titles,$short_titles) = &contact_titles();
 2055:     my $rownum = 0;
 2056:     my $css_class;
 2057:     foreach my $item (@contacts) {
 2058:         $rownum ++;
 2059:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2060:         $datatable .= '<tr'.$css_class.'>'. 
 2061:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 2062:                   '</span></td><td class="LC_right_item">'.
 2063:                   '<input type="text" name="'.$item.'" value="'.
 2064:                   $to{$item}.'" /></td></tr>';
 2065:     }
 2066:     foreach my $type (@mailings) {
 2067:         $rownum ++;
 2068:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 2069:         $datatable .= '<tr'.$css_class.'>'.
 2070:                       '<td><span class="LC_nobreak">'.
 2071:                       $titles->{$type}.': </span></td>'.
 2072:                       '<td class="LC_left_item">'.
 2073:                       '<span class="LC_nobreak">';
 2074:         foreach my $item (@contacts) {
 2075:             $datatable .= '<label>'.
 2076:                           '<input type="checkbox" name="'.$type.'"'.
 2077:                           $checked{$type}{$item}.
 2078:                           ' value="'.$item.'" />'.$short_titles->{$item}.
 2079:                           '</label>&nbsp;';
 2080:         }
 2081:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
 2082:                       '<input type="text" name="'.$type.'_others" '.
 2083:                       'value="'.$otheremails{$type}.'"  />';
 2084:         if ($type eq 'helpdeskmail') {
 2085:             $datatable .= '<br />'.&mt('Bcc:').('&nbsp;'x6).
 2086:                           '<input type="text" name="'.$type.'_bcc" '.
 2087:                           'value="'.$bccemails{$type}.'"  />';
 2088:         }
 2089:         $datatable .= '</td></tr>'."\n";
 2090:     }
 2091:     $$rowtotal += $rownum;
 2092:     return $datatable;
 2093: }
 2094: 
 2095: sub print_helpsettings {
 2096: 
 2097: 	my ($position,$dom,$confname,$settings,$rowtotal) = @_;
 2098: 	my ($css_class,$datatable);
 2099: 	
 2100: 	my $switchserver = &check_switchserver($dom,$confname);
 2101: 	
 2102: 	my $itemcount = 1;
 2103: 	
 2104: 	if ($position eq 'top') {
 2105: 		
 2106: 		my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
 2107: 		
 2108: 		%choices =
 2109: 			&Apache::lonlocal::texthash (
 2110: 				submitbugs => 'Display &quot;Submit a bug&quot; link?',
 2111: 		);
 2112: 		
 2113: 		%defaultchecked = ('submitbugs' => 'on');
 2114: 		
 2115: 		@toggles = ('submitbugs',);
 2116: 		
 2117: 		foreach my $item (@toggles) {
 2118: 			if ($defaultchecked{$item} eq 'on') { 
 2119: 				$checkedon{$item} = ' checked="checked" ';
 2120: 				$checkedoff{$item} = ' ';
 2121: 			} elsif ($defaultchecked{$item} eq 'off') {
 2122: 				$checkedoff{$item} = ' checked="checked" ';
 2123: 				$checkedon{$item} = ' ';
 2124: 			}
 2125: 		}
 2126: 		
 2127: 		if (ref($settings) eq 'HASH') {
 2128: 			foreach my $item (@toggles) {
 2129: 				if ($settings->{$item} eq '1') {
 2130: 					$checkedon{$item} =  ' checked="checked" ';
 2131: 					$checkedoff{$item} = ' ';
 2132: 				} elsif ($settings->{$item} eq '0') {
 2133: 					$checkedoff{$item} =  ' checked="checked" ';
 2134: 					$checkedon{$item} = ' ';
 2135: 				}
 2136: 			}
 2137: 		 }
 2138: 		
 2139: 		 foreach my $item (@toggles) {
 2140: 			$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2141: 			$datatable .=  
 2142: 				'<tr'.$css_class.'>
 2143: 				<td><span class="LC_nobreak">'.$choices{$item}.'</span></td>
 2144: 				<td><span class="LC_nobreak">&nbsp;</span></td>
 2145: 				<td class="LC_right_item"><span class="LC_nobreak">
 2146: 				<label><input type="radio" name="'.$item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').'</label>&nbsp;
 2147: 				<label><input type="radio" name="'.$item.'" '.$checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
 2148: 				'</span></td>'.
 2149: 				'</tr>';
 2150: 			$itemcount ++;
 2151: 		 }
 2152:      
 2153:      } else {
 2154:      
 2155:      	$css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2156:      	
 2157:      	$datatable .= '<tr'.$css_class.'>';
 2158:      	
 2159:      	if (ref($settings) eq 'HASH') {
 2160: 			if ($settings->{'loginhelpurl'} ne '') {
 2161: 				my($directory, $filename) = $settings->{'loginhelpurl'} =~ m/(.*\/)(.*)$/;
 2162: 				$datatable .= '<td width="33%"><span class="LC_left_item"><label><a href="'.$settings->{'loginhelpurl'}.'" target="_blank">'.&mt('Custom Login Page Help File In Use').'</a></label></span></td>';
 2163: 				$datatable .= '<td width="33%"><span class="LC_right_item"><label><input type="checkbox" name="loginhelpurl_del" value="1" />'.&mt('Delete?').'</label></span></td>'
 2164: 			} else {
 2165: 				$datatable .= '<td width="33%"><span class="LC_left_item"><label>'.&mt('Default Login Page Help File In Use').'</label></span></td>';
 2166: 				$datatable .= '<td width="33%"><span class="LC_right_item">&nbsp;</span></td>';
 2167: 			}
 2168: 		} else {
 2169: 			$datatable .= '<td><span class="LC_left_item">&nbsp;</span></td>';
 2170: 			$datatable .= '<td><span class="LC_right_item">&nbsp;</span></td>';
 2171: 		}
 2172:     	
 2173:      	$datatable .= '<td width="33%"><span class="LC_right_item">';
 2174:      	if ($switchserver) {
 2175:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 2176:         } else {
 2177:         	$datatable .= &mt('Upload Custom Login Page Help File:');
 2178:             $datatable .='<input type="file" name="loginhelpurl" />';
 2179:         }
 2180:         $datatable .= '</span></td></tr>';
 2181:         
 2182:      }
 2183:      
 2184:      return $datatable;
 2185: 	
 2186: }
 2187: 
 2188: 
 2189: sub radiobutton_prefs {
 2190:     my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
 2191:     return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
 2192:                    (ref($choices) eq 'HASH'));
 2193: 
 2194:     my (%checkedon,%checkedoff,$datatable,$css_class);
 2195: 
 2196:     foreach my $item (@{$toggles}) {
 2197:         if ($defaultchecked->{$item} eq 'on') {
 2198:             $checkedon{$item} = ' checked="checked" ';
 2199:             $checkedoff{$item} = ' ';
 2200:         } elsif ($defaultchecked->{$item} eq 'off') {
 2201:             $checkedoff{$item} = ' checked="checked" ';
 2202:             $checkedon{$item} = ' ';
 2203:         }
 2204:     }
 2205:     if (ref($settings) eq 'HASH') {
 2206:         foreach my $item (@{$toggles}) {
 2207:             if ($settings->{$item} eq '1') {
 2208:                 $checkedon{$item} =  ' checked="checked" ';
 2209:                 $checkedoff{$item} = ' ';
 2210:             } elsif ($settings->{$item} eq '0') {
 2211:                 $checkedoff{$item} =  ' checked="checked" ';
 2212:                 $checkedon{$item} = ' ';
 2213:             }
 2214:         }
 2215:     }
 2216:     foreach my $item (@{$toggles}) {
 2217:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2218:         $datatable .=
 2219:             '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
 2220:             '</span></td>'.
 2221:             '<td class="LC_right_item"><span class="LC_nobreak">'.
 2222:             '<label><input type="radio" name="'.
 2223:             $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
 2224:             '</label>&nbsp;<label><input type="radio" name="'.$item.'" '.
 2225:             $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
 2226:             '</span></td>'.
 2227:             '</tr>';
 2228:         $itemcount ++;
 2229:     }
 2230:     return ($datatable,$itemcount);
 2231: }
 2232: 
 2233: sub print_coursedefaults {
 2234:     my ($dom,$settings,$rowtotal) = @_;
 2235:     my ($css_class,$datatable);
 2236:     my $itemcount = 1;
 2237:     my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
 2238:     %choices =
 2239:         &Apache::lonlocal::texthash (
 2240:             canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
 2241:     );
 2242:     %defaultchecked = ('canuse_pdfforms' => 'off');
 2243:     @toggles = ('canuse_pdfforms',);
 2244:     ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
 2245:                                                  \%choices,$itemcount);
 2246:     $$rowtotal += $itemcount;
 2247:     return $datatable;
 2248: }
 2249: 
 2250: sub print_usersessions {
 2251:     my ($position,$dom,$settings,$rowtotal) = @_;
 2252:     my ($css_class,$datatable,%checked,%choices);
 2253:     my %lt = &usersession_titles();
 2254:     my $itemcount = 1;
 2255:     my $numinrow = 6;
 2256:     my $prefix;
 2257:     my @types;
 2258:     if ($position eq 'top') {
 2259:         $prefix = 'hosted';
 2260:         @types = ('excludedomain','includedomain');
 2261:     } else {
 2262:         $prefix = 'remote';
 2263:         @types = ('version','excludedomain','includedomain');
 2264:     }
 2265:     my (%current,%checkedon,%checkedoff);
 2266:     my @lcversions = &Apache::lonnet::all_loncaparevs();
 2267:     my (%by_ip,%by_location,@intdoms);
 2268:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
 2269:     my @locations = sort(keys(%by_location));
 2270:     foreach my $type (@types) {
 2271:         $checkedon{$type} = '';
 2272:         $checkedoff{$type} = ' checked="checked"';
 2273:     }
 2274:     if (ref($settings) eq 'HASH') {
 2275:         if (ref($settings->{$prefix}) eq 'HASH') {
 2276:             foreach my $key (keys(%{$settings->{$prefix}})) {
 2277:                 $current{$key} = $settings->{$prefix}{$key};
 2278:                 if ($key eq 'version') {
 2279:                     if ($current{$key} ne '') {
 2280:                         $checkedon{$key} = ' checked="checked"';
 2281:                         $checkedoff{$key} = '';
 2282:                     }
 2283:                 } elsif (ref($current{$key}) eq 'ARRAY') {
 2284:                     $checkedon{$key} = ' checked="checked"';
 2285:                     $checkedoff{$key} = '';
 2286:                 }
 2287:             }
 2288:         }
 2289:     }
 2290:     foreach my $type (@types) {
 2291:         $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
 2292:         $datatable .= '<tr'.$css_class.'>
 2293:                        <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
 2294:                            <span class="LC_nobreak">&nbsp;
 2295:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>&nbsp;
 2296:                            <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
 2297:         if ($type eq 'version') {
 2298:             my $selector = '<select name="'.$prefix.'_version">';
 2299:             foreach my $version (@lcversions) {
 2300:                 my $selected = '';
 2301:                 if ($current{'version'} eq $version) {
 2302:                     $selected = ' selected="selected"';
 2303:                 }
 2304:                 $selector .= ' <option value="'.$version.'"'.
 2305:                              $selected.'>'.$version.'</option>';
 2306:             }
 2307:             $selector .= '</select> ';
 2308:             $datatable .= &mt('remote server must be version: [_1] or later',$selector);
 2309:         } else {
 2310:             $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
 2311:                          'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
 2312:                          ' />'.('&nbsp;'x2).
 2313:                          '<input type="button" value="'.&mt('uncheck all').'" '.
 2314:                          'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
 2315:                          "\n".
 2316:                          '</div><div><table>';
 2317:             my $rem;
 2318:             for (my $i=0; $i<@locations; $i++) {
 2319:                 my ($showloc,$value,$checkedtype);
 2320:                 if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
 2321:                     my $ip = $by_location{$locations[$i]}->[0];
 2322:                     if (ref($by_ip{$ip}) eq 'ARRAY') {
 2323:                         $value = join(':',@{$by_ip{$ip}});
 2324:                         $showloc = join(', ',@{$by_ip{$ip}});
 2325:                         if (ref($current{$type}) eq 'ARRAY') {
 2326:                             foreach my $loc (@{$by_ip{$ip}}) {  
 2327:                                 if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
 2328:                                     $checkedtype = ' checked="checked"';
 2329:                                     last;
 2330:                                 }
 2331:                             }
 2332:                         }
 2333:                     }
 2334:                 }
 2335:                 $rem = $i%($numinrow);
 2336:                 if ($rem == 0) {
 2337:                     if ($i > 0) {
 2338:                         $datatable .= '</tr>';
 2339:                     }
 2340:                     $datatable .= '<tr>';
 2341:                 }
 2342:                 $datatable .= '<td class="LC_left_item">'.
 2343:                               '<span class="LC_nobreak"><label>'.
 2344:                               '<input type="checkbox" name="'.$prefix.'_'.$type.
 2345:                               '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
 2346:                               '</label></span></td>';
 2347:             }
 2348:             $rem = @locations%($numinrow);
 2349:             my $colsleft = $numinrow - $rem;
 2350:             if ($colsleft > 1 ) {
 2351:                 $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 2352:                               '&nbsp;</td>';
 2353:             } elsif ($colsleft == 1) {
 2354:                 $datatable .= '<td class="LC_left_item">&nbsp;</td>';
 2355:             }
 2356:             $datatable .= '</tr></table>';
 2357:         }
 2358:         $datatable .= '</td></tr>';
 2359:         $itemcount ++;
 2360:     }
 2361:     $$rowtotal += $itemcount;
 2362:     return $datatable;
 2363: }
 2364: 
 2365: sub build_location_hashes {
 2366:     my ($intdoms,$by_ip,$by_location) = @_;
 2367:     return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
 2368:                   (ref($by_location) eq 'HASH')); 
 2369:     my %iphost = &Apache::lonnet::get_iphost();
 2370:     my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
 2371:     my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
 2372:     if (ref($iphost{$primary_ip}) eq 'ARRAY') {
 2373:         foreach my $id (@{$iphost{$primary_ip}}) {
 2374:             my $intdom = &Apache::lonnet::internet_dom($id);
 2375:             unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
 2376:                 push(@{$intdoms},$intdom);
 2377:             }
 2378:         }
 2379:     }
 2380:     foreach my $ip (keys(%iphost)) {
 2381:         if (ref($iphost{$ip}) eq 'ARRAY') {
 2382:             foreach my $id (@{$iphost{$ip}}) {
 2383:                 my $location = &Apache::lonnet::internet_dom($id);
 2384:                 if ($location) {
 2385:                     next if (grep(/^\Q$location\E$/,@{$intdoms}));
 2386:                     if (ref($by_ip->{$ip}) eq 'ARRAY') {
 2387:                         unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
 2388:                             push(@{$by_ip->{$ip}},$location);
 2389:                         }
 2390:                     } else {
 2391:                         $by_ip->{$ip} = [$location];
 2392:                     }
 2393:                 }
 2394:             }
 2395:         }
 2396:     }
 2397:     foreach my $ip (sort(keys(%{$by_ip}))) {
 2398:         if (ref($by_ip->{$ip}) eq 'ARRAY') {
 2399:             @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
 2400:             my $first = $by_ip->{$ip}->[0];
 2401:             if (ref($by_location->{$first}) eq 'ARRAY') {
 2402:                 unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
 2403:                     push(@{$by_location->{$first}},$ip);
 2404:                 }
 2405:             } else {
 2406:                 $by_location->{$first} = [$ip];
 2407:             }
 2408:         }
 2409:     }
 2410:     return;
 2411: }
 2412: 
 2413: sub contact_titles {
 2414:     my %titles = &Apache::lonlocal::texthash (
 2415:                    'supportemail' => 'Support E-mail address',
 2416:                    'adminemail'   => 'Default Server Admin E-mail address',
 2417:                    'errormail'    => 'Error reports to be e-mailed to',
 2418:                    'packagesmail' => 'Package update alerts to be e-mailed to',
 2419:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
 2420:                    'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
 2421:                    'requestsmail' => 'E-mail from course requests requiring approval',
 2422:                  );
 2423:     my %short_titles = &Apache::lonlocal::texthash (
 2424:                            adminemail   => 'Admin E-mail address',
 2425:                            supportemail => 'Support E-mail',
 2426:                        );   
 2427:     return (\%titles,\%short_titles);
 2428: }
 2429: 
 2430: sub tool_titles {
 2431:     my %titles = &Apache::lonlocal::texthash (
 2432:                      aboutme    => 'Personal Information Page',
 2433:                      blog       => 'Blog',
 2434:                      portfolio  => 'Portfolio',
 2435:                      official   => 'Official courses (with institutional codes)',
 2436:                      unofficial => 'Unofficial courses',
 2437:                      community  => 'Communities',
 2438:                  );
 2439:     return %titles;
 2440: }
 2441: 
 2442: sub courserequest_titles {
 2443:     my %titles = &Apache::lonlocal::texthash (
 2444:                                    official   => 'Official',
 2445:                                    unofficial => 'Unofficial',
 2446:                                    community  => 'Communities',
 2447:                                    norequest  => 'Not allowed',
 2448:                                    approval   => 'Approval by Dom. Coord.',
 2449:                                    validate   => 'With validation',
 2450:                                    autolimit  => 'Numerical limit',
 2451:                                    unlimited  => '(blank for unlimited)',
 2452:                  );
 2453:     return %titles;
 2454: }
 2455: 
 2456: sub courserequest_conditions {
 2457:     my %conditions = &Apache::lonlocal::texthash (
 2458:        approval    => '(Processing of request subject to approval by Domain Coordinator).',
 2459:        validate   => '(Processing of request subject to instittutional validation).',
 2460:                  );
 2461:     return %conditions;
 2462: }
 2463: 
 2464: 
 2465: sub print_usercreation {
 2466:     my ($position,$dom,$settings,$rowtotal) = @_;
 2467:     my $numinrow = 4;
 2468:     my $datatable;
 2469:     if ($position eq 'top') {
 2470:         $$rowtotal ++;
 2471:         my $rowcount = 0;
 2472:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
 2473:         if (ref($rules) eq 'HASH') {
 2474:             if (keys(%{$rules}) > 0) {
 2475:                 $datatable .= &user_formats_row('username',$settings,$rules,
 2476:                                                 $ruleorder,$numinrow,$rowcount);
 2477:                 $$rowtotal ++;
 2478:                 $rowcount ++;
 2479:             }
 2480:         }
 2481:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
 2482:         if (ref($idrules) eq 'HASH') {
 2483:             if (keys(%{$idrules}) > 0) {
 2484:                 $datatable .= &user_formats_row('id',$settings,$idrules,
 2485:                                                 $idruleorder,$numinrow,$rowcount);
 2486:                 $$rowtotal ++;
 2487:                 $rowcount ++;
 2488:             }
 2489:         }
 2490:         my ($emailrules,$emailruleorder) = 
 2491:             &Apache::lonnet::inst_userrules($dom,'email');
 2492:         if (ref($emailrules) eq 'HASH') {
 2493:             if (keys(%{$emailrules}) > 0) {
 2494:                 $datatable .= &user_formats_row('email',$settings,$emailrules,
 2495:                                                 $emailruleorder,$numinrow,$rowcount);
 2496:                 $$rowtotal ++;
 2497:                 $rowcount ++;
 2498:             }
 2499:         }
 2500:         if ($rowcount == 0) {
 2501:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
 2502:             $$rowtotal ++;
 2503:             $rowcount ++;
 2504:         }
 2505:     } elsif ($position eq 'middle') {
 2506:         my @creators = ('author','course','requestcrs','selfcreate');
 2507:         my ($rules,$ruleorder) =
 2508:             &Apache::lonnet::inst_userrules($dom,'username');
 2509:         my %lt = &usercreation_types();
 2510:         my %checked;
 2511:         my @selfcreate; 
 2512:         if (ref($settings) eq 'HASH') {
 2513:             if (ref($settings->{'cancreate'}) eq 'HASH') {
 2514:                 foreach my $item (@creators) {
 2515:                     $checked{$item} = $settings->{'cancreate'}{$item};
 2516:                 }
 2517:                 if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
 2518:                     @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
 2519:                 } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
 2520:                     if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
 2521:                         @selfcreate = ('email','login','sso');
 2522:                     } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
 2523:                         @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
 2524:                     }
 2525:                 }
 2526:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
 2527:                 foreach my $item (@creators) {
 2528:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
 2529:                         $checked{$item} = 'none';
 2530:                     }
 2531:                 }
 2532:             }
 2533:         }
 2534:         my $rownum = 0;
 2535:         foreach my $item (@creators) {
 2536:             $rownum ++;
 2537:             if ($item ne 'selfcreate') {  
 2538:                 if ($checked{$item} eq '') {
 2539:                     $checked{$item} = 'any';
 2540:                 }
 2541:             }
 2542:             my $css_class;
 2543:             if ($rownum%2) {
 2544:                 $css_class = '';
 2545:             } else {
 2546:                 $css_class = ' class="LC_odd_row" ';
 2547:             }
 2548:             $datatable .= '<tr'.$css_class.'>'.
 2549:                          '<td><span class="LC_nobreak">'.$lt{$item}.
 2550:                          '</span></td><td align="right">';
 2551:             my @options;
 2552:             if ($item eq 'selfcreate') {
 2553:                 push(@options,('email','login','sso'));
 2554:             } else {
 2555:                 @options = ('any');
 2556:                 if (ref($rules) eq 'HASH') {
 2557:                     if (keys(%{$rules}) > 0) {
 2558:                         push(@options,('official','unofficial'));
 2559:                     }
 2560:                 }
 2561:                 push(@options,'none');
 2562:             }
 2563:             foreach my $option (@options) {
 2564:                 my $type = 'radio';
 2565:                 my $check = ' ';
 2566:                 if ($item eq 'selfcreate') {
 2567:                     $type = 'checkbox';
 2568:                     if (grep(/^\Q$option\E$/,@selfcreate)) {
 2569:                         $check = ' checked="checked" ';
 2570:                     }
 2571:                 } else {
 2572:                     if ($checked{$item} eq $option) {
 2573:                         $check = ' checked="checked" ';
 2574:                     }
 2575:                 } 
 2576:                 $datatable .= '<span class="LC_nobreak"><label>'.
 2577:                               '<input type="'.$type.'" name="can_createuser_'.
 2578:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
 2579:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
 2580:             }
 2581:             $datatable .= '</td></tr>';
 2582:         }
 2583:         my ($othertitle,$usertypes,$types) =
 2584:             &Apache::loncommon::sorted_inst_types($dom);
 2585:         if (ref($usertypes) eq 'HASH') {
 2586:             if (keys(%{$usertypes}) > 0) {
 2587:                 my $createsettings;
 2588:                 if (ref($settings) eq 'HASH') {
 2589:                     $createsettings = $settings->{cancreate};
 2590:                 }
 2591:                 $datatable .= &insttypes_row($createsettings,$types,$usertypes,
 2592:                                              $dom,$numinrow,$othertitle,
 2593:                                              'statustocreate');
 2594:                 $$rowtotal ++;
 2595:             }
 2596:         }
 2597:     } else {
 2598:         my @contexts = ('author','course','domain');
 2599:         my @authtypes = ('int','krb4','krb5','loc');
 2600:         my %checked;
 2601:         if (ref($settings) eq 'HASH') {
 2602:             if (ref($settings->{'authtypes'}) eq 'HASH') {
 2603:                 foreach my $item (@contexts) {
 2604:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
 2605:                         foreach my $auth (@authtypes) {
 2606:                             if ($settings->{'authtypes'}{$item}{$auth}) {
 2607:                                 $checked{$item}{$auth} = ' checked="checked" ';
 2608:                             }
 2609:                         }
 2610:                     }
 2611:                 }
 2612:             }
 2613:         } else {
 2614:             foreach my $item (@contexts) {
 2615:                 foreach my $auth (@authtypes) {
 2616:                     $checked{$item}{$auth} = ' checked="checked" ';
 2617:                 }
 2618:             }
 2619:         }
 2620:         my %title = &context_names();
 2621:         my %authname = &authtype_names();
 2622:         my $rownum = 0;
 2623:         my $css_class; 
 2624:         foreach my $item (@contexts) {
 2625:             if ($rownum%2) {
 2626:                 $css_class = '';
 2627:             } else {
 2628:                 $css_class = ' class="LC_odd_row" ';
 2629:             }
 2630:             $datatable .=   '<tr'.$css_class.'>'.
 2631:                             '<td>'.$title{$item}.
 2632:                             '</td><td class="LC_left_item">'.
 2633:                             '<span class="LC_nobreak">';
 2634:             foreach my $auth (@authtypes) {
 2635:                 $datatable .= '<label>'. 
 2636:                               '<input type="checkbox" name="'.$item.'_auth" '.
 2637:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
 2638:                               $authname{$auth}.'</label>&nbsp;';
 2639:             }
 2640:             $datatable .= '</span></td></tr>';
 2641:             $rownum ++;
 2642:         }
 2643:         $$rowtotal += $rownum;
 2644:     }
 2645:     return $datatable;
 2646: }
 2647: 
 2648: sub user_formats_row {
 2649:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
 2650:     my $output;
 2651:     my %text = (
 2652:                    'username' => 'new usernames',
 2653:                    'id'       => 'IDs',
 2654:                    'email'    => 'self-created accounts (e-mail)',
 2655:                );
 2656:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 2657:     $output = '<tr '.$css_class.'>'.
 2658:               '<td><span class="LC_nobreak">';
 2659:     if ($type eq 'email') {
 2660:         $output .= &mt("Formats disallowed for $text{$type}: ");
 2661:     } else {
 2662:         $output .= &mt("Format rules to check for $text{$type}: ");
 2663:     }
 2664:     $output .= '</span></td>'.
 2665:                '<td class="LC_left_item" colspan="2"><table>';
 2666:     my $rem;
 2667:     if (ref($ruleorder) eq 'ARRAY') {
 2668:         for (my $i=0; $i<@{$ruleorder}; $i++) {
 2669:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
 2670:                 my $rem = $i%($numinrow);
 2671:                 if ($rem == 0) {
 2672:                     if ($i > 0) {
 2673:                         $output .= '</tr>';
 2674:                     }
 2675:                     $output .= '<tr>';
 2676:                 }
 2677:                 my $check = ' ';
 2678:                 if (ref($settings) eq 'HASH') {
 2679:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
 2680:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
 2681:                             $check = ' checked="checked" ';
 2682:                         }
 2683:                     }
 2684:                 }
 2685:                 $output .= '<td class="LC_left_item">'.
 2686:                            '<span class="LC_nobreak"><label>'.
 2687:                            '<input type="checkbox" name="'.$type.'_rule" '.
 2688:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
 2689:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
 2690:             }
 2691:         }
 2692:         $rem = @{$ruleorder}%($numinrow);
 2693:     }
 2694:     my $colsleft = $numinrow - $rem;
 2695:     if ($colsleft > 1 ) {
 2696:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 2697:                    '&nbsp;</td>';
 2698:     } elsif ($colsleft == 1) {
 2699:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 2700:     }
 2701:     $output .= '</tr></table></td></tr>';
 2702:     return $output;
 2703: }
 2704: 
 2705: sub usercreation_types {
 2706:     my %lt = &Apache::lonlocal::texthash (
 2707:                     author     => 'When adding a co-author',
 2708:                     course     => 'When adding a user to a course',
 2709:                     requestcrs => 'When requesting a course',
 2710:                     selfcreate => 'User creates own account', 
 2711:                     any        => 'Any',
 2712:                     official   => 'Institutional only ',
 2713:                     unofficial => 'Non-institutional only',
 2714:                     email      => 'E-mail address',
 2715:                     login      => 'Institutional Login',
 2716:                     sso        => 'SSO', 
 2717:                     none       => 'None',
 2718:     );
 2719:     return %lt;
 2720: }
 2721: 
 2722: sub authtype_names {
 2723:     my %lt = &Apache::lonlocal::texthash(
 2724:                       int    => 'Internal',
 2725:                       krb4   => 'Kerberos 4',
 2726:                       krb5   => 'Kerberos 5',
 2727:                       loc    => 'Local',
 2728:                   );
 2729:     return %lt;
 2730: }
 2731: 
 2732: sub context_names {
 2733:     my %context_title = &Apache::lonlocal::texthash(
 2734:        author => 'Creating users when an Author',
 2735:        course => 'Creating users when in a course',
 2736:        domain => 'Creating users when a Domain Coordinator',
 2737:     );
 2738:     return %context_title;
 2739: }
 2740: 
 2741: sub print_usermodification {
 2742:     my ($position,$dom,$settings,$rowtotal) = @_;
 2743:     my $numinrow = 4;
 2744:     my ($context,$datatable,$rowcount);
 2745:     if ($position eq 'top') {
 2746:         $rowcount = 0;
 2747:         $context = 'author'; 
 2748:         foreach my $role ('ca','aa') {
 2749:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 2750:                                                    $numinrow,$rowcount);
 2751:             $$rowtotal ++;
 2752:             $rowcount ++;
 2753:         }
 2754:     } elsif ($position eq 'middle') {
 2755:         $context = 'course';
 2756:         $rowcount = 0;
 2757:         foreach my $role ('st','ep','ta','in','cr') {
 2758:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 2759:                                                    $numinrow,$rowcount);
 2760:             $$rowtotal ++;
 2761:             $rowcount ++;
 2762:         }
 2763:     } elsif ($position eq 'bottom') {
 2764:         $context = 'selfcreate';
 2765:         my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 2766:         $usertypes->{'default'} = $othertitle;
 2767:         if (ref($types) eq 'ARRAY') {
 2768:             push(@{$types},'default');
 2769:             $usertypes->{'default'} = $othertitle;
 2770:             foreach my $status (@{$types}) {
 2771:                 $datatable .= &modifiable_userdata_row($context,$status,$settings,
 2772:                                                        $numinrow,$rowcount,$usertypes);
 2773:                 $$rowtotal ++;
 2774:                 $rowcount ++;
 2775:             }
 2776:         }
 2777:     }
 2778:     return $datatable;
 2779: }
 2780: 
 2781: sub print_defaults {
 2782:     my ($dom,$rowtotal) = @_;
 2783:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
 2784:                  'datelocale_def');
 2785:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 2786:     my $titles = &defaults_titles();
 2787:     my $rownum = 0;
 2788:     my ($datatable,$css_class);
 2789:     foreach my $item (@items) {
 2790:         if ($rownum%2) {
 2791:             $css_class = '';
 2792:         } else {
 2793:             $css_class = ' class="LC_odd_row" ';
 2794:         }
 2795:         $datatable .= '<tr'.$css_class.'>'.
 2796:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 2797:                   '</span></td><td class="LC_right_item">';
 2798:         if ($item eq 'auth_def') {
 2799:             my @authtypes = ('internal','krb4','krb5','localauth');
 2800:             my %shortauth = (
 2801:                              internal => 'int',
 2802:                              krb4 => 'krb4',
 2803:                              krb5 => 'krb5',
 2804:                              localauth  => 'loc'
 2805:                            );
 2806:             my %authnames = &authtype_names();
 2807:             foreach my $auth (@authtypes) {
 2808:                 my $checked = ' ';
 2809:                 if ($domdefaults{$item} eq $auth) {
 2810:                     $checked = ' checked="checked" ';
 2811:                 }
 2812:                 $datatable .= '<label><input type="radio" name="'.$item.
 2813:                               '" value="'.$auth.'"'.$checked.'/>'.
 2814:                               $authnames{$shortauth{$auth}}.'</label>&nbsp;&nbsp;';
 2815:             }
 2816:         } elsif ($item eq 'timezone_def') {
 2817:             my $includeempty = 1;
 2818:             $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
 2819:         } elsif ($item eq 'datelocale_def') {
 2820:             my $includeempty = 1;
 2821:             $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
 2822:         } else {
 2823:             $datatable .= '<input type="text" name="'.$item.'" value="'.
 2824:                           $domdefaults{$item}.'" />';
 2825:         }
 2826:         $datatable .= '</td></tr>';
 2827:         $rownum ++;
 2828:     }
 2829:     $$rowtotal += $rownum;
 2830:     return $datatable;
 2831: }
 2832: 
 2833: sub defaults_titles {
 2834:     my %titles = &Apache::lonlocal::texthash (
 2835:                    'auth_def'      => 'Default authentication type',
 2836:                    'auth_arg_def'  => 'Default authentication argument',
 2837:                    'lang_def'      => 'Default language',
 2838:                    'timezone_def'  => 'Default timezone',
 2839:                    'datelocale_def' => 'Default locale for dates',
 2840:                  );
 2841:     return (\%titles);
 2842: }
 2843: 
 2844: sub print_scantronformat {
 2845:     my ($r,$dom,$confname,$settings,$rowtotal) = @_;
 2846:     my $itemcount = 1;
 2847:     my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
 2848:         %confhash);
 2849:     my $switchserver = &check_switchserver($dom,$confname);
 2850:     my %lt = &Apache::lonlocal::texthash (
 2851:                 default => 'Default bubblesheet format file error',
 2852:                 custom  => 'Custom bubblesheet format file error',
 2853:              );
 2854:     my %scantronfiles = (
 2855:         default => 'default.tab',
 2856:         custom => 'custom.tab',
 2857:     );
 2858:     foreach my $key (keys(%scantronfiles)) {
 2859:         $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
 2860:                               .$scantronfiles{$key};
 2861:     }
 2862:     my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
 2863:     if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
 2864:         if (!$switchserver) {
 2865:             my $servadm = $r->dir_config('lonAdmEMail');
 2866:             my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
 2867:             if ($configuserok eq 'ok') {
 2868:                 if ($author_ok eq 'ok') {
 2869:                     my %legacyfile = (
 2870:  default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab', 
 2871:  custom  => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab', 
 2872:                     );
 2873:                     my %md5chk;
 2874:                     foreach my $type (keys(%legacyfile)) {
 2875:                         ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
 2876:                         chomp($md5chk{$type});
 2877:                     }
 2878:                     if ($md5chk{'default'} ne $md5chk{'custom'}) {
 2879:                         foreach my $type (keys(%legacyfile)) {
 2880:                             ($scantronurls{$type},my $error) = 
 2881:                                 &legacy_scantronformat($r,$dom,$confname,
 2882:                                                  $type,$legacyfile{$type},
 2883:                                                  $scantronurls{$type},
 2884:                                                  $scantronfiles{$type});
 2885:                             if ($error ne '') {
 2886:                                 $error{$type} = $error;
 2887:                             }
 2888:                         }
 2889:                         if (keys(%error) == 0) {
 2890:                             $is_custom = 1;
 2891:                             $confhash{'scantron'}{'scantronformat'} = 
 2892:                                 $scantronurls{'custom'};
 2893:                             my $putresult = 
 2894:                                 &Apache::lonnet::put_dom('configuration',
 2895:                                                          \%confhash,$dom);
 2896:                             if ($putresult ne 'ok') {
 2897:                                 $error{'custom'} = 
 2898:                                     '<span class="LC_error">'.
 2899:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 2900:                             }
 2901:                         }
 2902:                     } else {
 2903:                         ($scantronurls{'default'},my $error) =
 2904:                             &legacy_scantronformat($r,$dom,$confname,
 2905:                                           'default',$legacyfile{'default'},
 2906:                                           $scantronurls{'default'},
 2907:                                           $scantronfiles{'default'});
 2908:                         if ($error eq '') {
 2909:                             $confhash{'scantron'}{'scantronformat'} = ''; 
 2910:                             my $putresult =
 2911:                                 &Apache::lonnet::put_dom('configuration',
 2912:                                                          \%confhash,$dom);
 2913:                             if ($putresult ne 'ok') {
 2914:                                 $error{'default'} =
 2915:                                     '<span class="LC_error">'.
 2916:                                     &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
 2917:                             }
 2918:                         } else {
 2919:                             $error{'default'} = $error;
 2920:                         }
 2921:                     }
 2922:                 }
 2923:             }
 2924:         } else {
 2925:             $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
 2926:         }
 2927:     }
 2928:     if (ref($settings) eq 'HASH') {
 2929:         if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
 2930:             my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
 2931:             if ((!@info) || ($info[0] eq 'no_such_dir')) {
 2932:                 $scantronurl = '';
 2933:             } else {
 2934:                 $scantronurl = $settings->{'scantronformat'};
 2935:             }
 2936:             $is_custom = 1;
 2937:         } else {
 2938:             $scantronurl = $scantronurls{'default'};
 2939:         }
 2940:     } else {
 2941:         if ($is_custom) {
 2942:             $scantronurl = $scantronurls{'custom'};
 2943:         } else {
 2944:             $scantronurl = $scantronurls{'default'};
 2945:         }
 2946:     }
 2947:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 2948:     $datatable .= '<tr'.$css_class.'>';
 2949:     if (!$is_custom) {
 2950:         $datatable .= '<td>'.&mt('Default in use:').'<br />'.
 2951:                       '<span class="LC_nobreak">';
 2952:         if ($scantronurl) {
 2953:             $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
 2954:                           &mt('Default bubblesheet format file').'</a>';
 2955:         } else {
 2956:             $datatable = &mt('File unavailable for display');
 2957:         }
 2958:         $datatable .= '</span></td>';
 2959:         if (keys(%error) == 0) { 
 2960:             $datatable .= '<td valign="bottom">';
 2961:             if (!$switchserver) {
 2962:                 $datatable .= &mt('Upload:').'<br />';
 2963:             }
 2964:         } else {
 2965:             my $errorstr;
 2966:             foreach my $key (sort(keys(%error))) {
 2967:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 2968:             }
 2969:             $datatable .= '<td>'.$errorstr;
 2970:         }
 2971:     } else {
 2972:         if (keys(%error) > 0) {
 2973:             my $errorstr;
 2974:             foreach my $key (sort(keys(%error))) {
 2975:                 $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
 2976:             } 
 2977:             $datatable .= '<td>'.$errorstr.'</td><td>&nbsp;';
 2978:         } elsif ($scantronurl) {
 2979:             $datatable .= '<td><span class="LC_nobreak">'.
 2980:                           '<a href="'.$scantronurl.'" target="_blank">'.
 2981:                           &mt('Custom bubblesheet format file').'</a><label>'.
 2982:                           '<input type="checkbox" name="scantronformat_del"'.
 2983:                           '" value="1" />'.&mt('Delete?').'</label></span></td>'.
 2984:                           '<td><span class="LC_nobreak">&nbsp;'.
 2985:                           &mt('Replace:').'</span><br />';
 2986:         }
 2987:     }
 2988:     if (keys(%error) == 0) {
 2989:         if ($switchserver) {
 2990:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
 2991:         } else {
 2992:             $datatable .='<span class="LC_nobreak">&nbsp;'.
 2993:                          '<input type="file" name="scantronformat" /></span>';
 2994:         }
 2995:     }
 2996:     $datatable .= '</td></tr>';
 2997:     $$rowtotal ++;
 2998:     return $datatable;
 2999: }
 3000: 
 3001: sub legacy_scantronformat {
 3002:     my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
 3003:     my ($url,$error);
 3004:     my @statinfo = &Apache::lonnet::stat_file($newurl);
 3005:     if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
 3006:         (my $result,$url) =
 3007:             &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
 3008:                          '','',$newfile);
 3009:         if ($result ne 'ok') {
 3010:             $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
 3011:         }
 3012:     }
 3013:     return ($url,$error);
 3014: }
 3015: 
 3016: sub print_coursecategories {
 3017:     my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
 3018:     my $datatable;
 3019:     if ($position eq 'top') {
 3020:         my $toggle_cats_crs = ' ';
 3021:         my $toggle_cats_dom = ' checked="checked" ';
 3022:         my $can_cat_crs = ' ';
 3023:         my $can_cat_dom = ' checked="checked" ';
 3024:         my $toggle_catscomm_comm = ' ';
 3025:         my $toggle_catscomm_dom = ' checked="checked" ';
 3026:         my $can_catcomm_comm = ' ';
 3027:         my $can_catcomm_dom = ' checked="checked" ';
 3028: 
 3029:         if (ref($settings) eq 'HASH') {
 3030:             if ($settings->{'togglecats'} eq 'crs') {
 3031:                 $toggle_cats_crs = $toggle_cats_dom;
 3032:                 $toggle_cats_dom = ' ';
 3033:             }
 3034:             if ($settings->{'categorize'} eq 'crs') {
 3035:                 $can_cat_crs = $can_cat_dom;
 3036:                 $can_cat_dom = ' ';
 3037:             }
 3038:             if ($settings->{'togglecatscomm'} eq 'comm') {
 3039:                 $toggle_catscomm_comm = $toggle_catscomm_dom;
 3040:                 $toggle_catscomm_dom = ' ';
 3041:             }
 3042:             if ($settings->{'categorizecomm'} eq 'comm') {
 3043:                 $can_catcomm_comm = $can_catcomm_dom;
 3044:                 $can_catcomm_dom = ' ';
 3045:             }
 3046:         }
 3047:         my %title = &Apache::lonlocal::texthash (
 3048:                      togglecats     => 'Show/Hide a course in catalog',
 3049:                      togglecatscomm => 'Show/Hide a community in catalog',
 3050:                      categorize     => 'Assign a category to a course',
 3051:                      categorizecomm => 'Assign a category to a community',
 3052:                     );
 3053:         my %level = &Apache::lonlocal::texthash (
 3054:                      dom  => 'Set in Domain',
 3055:                      crs  => 'Set in Course',
 3056:                      comm => 'Set in Community',
 3057:                     );
 3058:         $datatable = '<tr class="LC_odd_row">'.
 3059:                   '<td>'.$title{'togglecats'}.'</td>'.
 3060:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 3061:                   '<input type="radio" name="togglecats"'.
 3062:                   $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 3063:                   '<label><input type="radio" name="togglecats"'.
 3064:                   $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
 3065:                   '</tr><tr>'.
 3066:                   '<td>'.$title{'categorize'}.'</td>'.
 3067:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 3068:                   '<label><input type="radio" name="categorize"'.
 3069:                   $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 3070:                   '<label><input type="radio" name="categorize"'.
 3071:                   $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
 3072:                   '</tr><tr class="LC_odd_row">'.
 3073:                   '<td>'.$title{'togglecatscomm'}.'</td>'.
 3074:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 3075:                   '<input type="radio" name="togglecatscomm"'.
 3076:                   $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 3077:                   '<label><input type="radio" name="togglecatscomm"'.
 3078:                   $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
 3079:                   '</tr><tr>'.
 3080:                   '<td>'.$title{'categorizecomm'}.'</td>'.
 3081:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 3082:                   '<label><input type="radio" name="categorizecomm"'.
 3083:                   $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label>&nbsp;'.
 3084:                   '<label><input type="radio" name="categorizecomm"'.
 3085:                   $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
 3086:                   '</tr>';
 3087:         $$rowtotal += 4;
 3088:     } else {
 3089:         my $css_class;
 3090:         my $itemcount = 1;
 3091:         my $cathash; 
 3092:         if (ref($settings) eq 'HASH') {
 3093:             $cathash = $settings->{'cats'};
 3094:         }
 3095:         if (ref($cathash) eq 'HASH') {
 3096:             my (@cats,@trails,%allitems,%idx,@jsarray);
 3097:             &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
 3098:                                                    \%allitems,\%idx,\@jsarray);
 3099:             my $maxdepth = scalar(@cats);
 3100:             my $colattrib = '';
 3101:             if ($maxdepth > 2) {
 3102:                 $colattrib = ' colspan="2" ';
 3103:             }
 3104:             my @path;
 3105:             if (@cats > 0) {
 3106:                 if (ref($cats[0]) eq 'ARRAY') {
 3107:                     my $numtop = @{$cats[0]};
 3108:                     my $maxnum = $numtop;
 3109:                     my %default_names = (
 3110:                           instcode    => &mt('Official courses'),
 3111:                           communities => &mt('Communities'),
 3112:                     );
 3113: 
 3114:                     if ((!grep(/^instcode$/,@{$cats[0]})) || 
 3115:                         ($cathash->{'instcode::0'} eq '') ||
 3116:                         (!grep(/^communities$/,@{$cats[0]})) || 
 3117:                         ($cathash->{'communities::0'} eq '')) {
 3118:                         $maxnum ++;
 3119:                     }
 3120:                     my $lastidx;
 3121:                     for (my $i=0; $i<$numtop; $i++) {
 3122:                         my $parent = $cats[0][$i];
 3123:                         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3124:                         my $item = &escape($parent).'::0';
 3125:                         my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
 3126:                         $lastidx = $idx{$item};
 3127:                         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 3128:                                       .'<select name="'.$item.'"'.$chgstr.'>';
 3129:                         for (my $k=0; $k<=$maxnum; $k++) {
 3130:                             my $vpos = $k+1;
 3131:                             my $selstr;
 3132:                             if ($k == $i) {
 3133:                                 $selstr = ' selected="selected" ';
 3134:                             }
 3135:                             $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 3136:                         }
 3137:                         $datatable .= '</select></td><td>';
 3138:                         if ($parent eq 'instcode' || $parent eq 'communities') {
 3139:                             $datatable .=  '<span class="LC_nobreak">'
 3140:                                            .$default_names{$parent}.'</span>';
 3141:                             if ($parent eq 'instcode') {
 3142:                                 $datatable .= '<br /><span class="LC_nobreak">('
 3143:                                               .&mt('with institutional codes')
 3144:                                               .')</span></td><td'.$colattrib.'>';
 3145:                             } else {
 3146:                                 $datatable .= '<table><tr><td>';
 3147:                             }
 3148:                             $datatable .= '<span class="LC_nobreak">'
 3149:                                           .'<label><input type="radio" name="'
 3150:                                           .$parent.'" value="1" checked="checked" />'
 3151:                                           .&mt('Display').'</label>';
 3152:                             if ($parent eq 'instcode') {
 3153:                                 $datatable .= '&nbsp;';
 3154:                             } else {
 3155:                                 $datatable .= '</span></td></tr><tr><td>'
 3156:                                               .'<span class="LC_nobreak">';
 3157:                             }
 3158:                             $datatable .= '<label><input type="radio" name="'
 3159:                                           .$parent.'" value="0" />'
 3160:                                           .&mt('Do not display').'</label></span>';
 3161:                             if ($parent eq 'communities') {
 3162:                                 $datatable .= '</td></tr></table>';
 3163:                             }
 3164:                             $datatable .= '</td>';
 3165:                         } else {
 3166:                             $datatable .= $parent
 3167:                                           .'&nbsp;<label><input type="checkbox" name="deletecategory" '
 3168:                                           .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
 3169:                         }
 3170:                         my $depth = 1;
 3171:                         push(@path,$parent);
 3172:                         $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
 3173:                         pop(@path);
 3174:                         $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
 3175:                         $itemcount ++;
 3176:                     }
 3177:                     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3178:                     my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
 3179:                     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
 3180:                     for (my $k=0; $k<=$maxnum; $k++) {
 3181:                         my $vpos = $k+1;
 3182:                         my $selstr;
 3183:                         if ($k == $numtop) {
 3184:                             $selstr = ' selected="selected" ';
 3185:                         }
 3186:                         $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 3187:                     }
 3188:                     $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').'&nbsp;'
 3189:                                   .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
 3190:                                   .'</tr>'."\n";
 3191:                     $itemcount ++;
 3192:                     foreach my $default ('instcode','communities') {
 3193:                         if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
 3194:                             $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3195:                             my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
 3196:                             $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
 3197:                                           '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
 3198:                             for (my $k=0; $k<=$maxnum; $k++) {
 3199:                                 my $vpos = $k+1;
 3200:                                 my $selstr;
 3201:                                 if ($k == $maxnum) {
 3202:                                     $selstr = ' selected="selected" ';
 3203:                                 }
 3204:                                 $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
 3205:                             }
 3206:                             $datatable .= '</select></span></td>'.
 3207:                                           '<td><span class="LC_nobreak">'.
 3208:                                           $default_names{$default}.'</span>';
 3209:                             if ($default eq 'instcode') {
 3210:                                 $datatable .= '<br /><span class="LC_nobreak">(' 
 3211:                                               .&mt('with institutional codes').')</span>';
 3212:                             }
 3213:                             $datatable .= '</td>'
 3214:                                           .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
 3215:                                           .&mt('Display').'</label>&nbsp;'
 3216:                                           .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
 3217:                                           .&mt('Do not display').'</label></span></td></tr>';
 3218:                         }
 3219:                     }
 3220:                 }
 3221:             } else {
 3222:                 $datatable .= &initialize_categories($itemcount);
 3223:             }
 3224:         } else {
 3225:             $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
 3226:                           .&initialize_categories($itemcount);
 3227:         }
 3228:         $$rowtotal += $itemcount;
 3229:     }
 3230:     return $datatable;
 3231: }
 3232: 
 3233: sub print_serverstatuses {
 3234:     my ($dom,$settings,$rowtotal) = @_;
 3235:     my $datatable;
 3236:     my @pages = &serverstatus_pages();
 3237:     my (%namedaccess,%machineaccess);
 3238:     foreach my $type (@pages) {
 3239:         $namedaccess{$type} = '';
 3240:         $machineaccess{$type}= '';
 3241:     }
 3242:     if (ref($settings) eq 'HASH') {
 3243:         foreach my $type (@pages) {
 3244:             if (exists($settings->{$type})) {
 3245:                 if (ref($settings->{$type}) eq 'HASH') {
 3246:                     foreach my $key (keys(%{$settings->{$type}})) {
 3247:                         if ($key eq 'namedusers') {
 3248:                             $namedaccess{$type} = $settings->{$type}->{$key};
 3249:                         } elsif ($key eq 'machines') {
 3250:                             $machineaccess{$type} = $settings->{$type}->{$key};
 3251:                         }
 3252:                     }
 3253:                 }
 3254:             }
 3255:         }
 3256:     }
 3257:     my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 3258:     my $rownum = 0;
 3259:     my $css_class;
 3260:     foreach my $type (@pages) {
 3261:         $rownum ++;
 3262:         $css_class = $rownum%2?' class="LC_odd_row"':'';
 3263:         $datatable .= '<tr'.$css_class.'>'.
 3264:                       '<td><span class="LC_nobreak">'.
 3265:                       $titles->{$type}.'</span></td>'.
 3266:                       '<td class="LC_left_item">'.
 3267:                       '<input type="text" name="'.$type.'_namedusers" '.
 3268:                       'value="'.$namedaccess{$type}.'" size="30" /></td>'.
 3269:                       '<td class="LC_right_item">'.
 3270:                       '<span class="LC_nobreak">'.
 3271:                       '<input type="text" name="'.$type.'_machines" '.
 3272:                       'value="'.$machineaccess{$type}.'" size="10" />'.
 3273:                       '</td></tr>'."\n";
 3274:     }
 3275:     $$rowtotal += $rownum;
 3276:     return $datatable;
 3277: }
 3278: 
 3279: sub serverstatus_pages {
 3280:     return ('userstatus','lonstatus','loncron','server-status','codeversions',
 3281:             'clusterstatus','metadata_keywords','metadata_harvest',
 3282:             'takeoffline','takeonline','showenv','toggledebug');
 3283: }
 3284: 
 3285: sub coursecategories_javascript {
 3286:     my ($settings) = @_;
 3287:     my ($output,$jstext,$cathash);
 3288:     if (ref($settings) eq 'HASH') {
 3289:         $cathash = $settings->{'cats'};
 3290:     }
 3291:     if (ref($cathash) eq 'HASH') {
 3292:         my (@cats,@jsarray,%idx);
 3293:         &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
 3294:         if (@jsarray > 0) {
 3295:             $jstext = '    var categories = Array('.scalar(@jsarray).');'."\n";
 3296:             for (my $i=0; $i<@jsarray; $i++) {
 3297:                 if (ref($jsarray[$i]) eq 'ARRAY') {
 3298:                     my $catstr = join('","',@{$jsarray[$i]});
 3299:                     $jstext .= '    categories['.$i.'] = Array("'.$catstr.'");'."\n";
 3300:                 }
 3301:             }
 3302:         }
 3303:     } else {
 3304:         $jstext  = '    var categories = Array(1);'."\n".
 3305:                    '    categories[0] = Array("instcode_pos");'."\n"; 
 3306:     }
 3307:     my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
 3308:     my $communities_reserved = &mt('The name: "communities" is a reserved category');
 3309:     my $choose_again = '\\n'.&mt('Please use a different name for the new top level category'); 
 3310:     $output = <<"ENDSCRIPT";
 3311: <script type="text/javascript">
 3312: // <![CDATA[
 3313: function reorderCats(form,parent,item,idx) {
 3314:     var changedVal;
 3315: $jstext
 3316:     var newpos = 'addcategory_pos';
 3317:     var current = new Array;
 3318:     if (parent == '') {
 3319:         var has_instcode = 0;
 3320:         var maxtop = categories[idx].length;
 3321:         for (var j=0; j<maxtop; j++) {
 3322:             if (categories[idx][j] == 'instcode::0') {
 3323:                 has_instcode == 1;
 3324:             }
 3325:         }
 3326:         if (has_instcode == 0) {
 3327:             categories[idx][maxtop] = 'instcode_pos';
 3328:         }
 3329:     } else {
 3330:         newpos += '_'+parent;
 3331:     }
 3332:     var maxh = 1 + categories[idx].length;
 3333:     var current = new Array;
 3334:     var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
 3335:     if (item == newpos) {
 3336:         changedVal = newitemVal;
 3337:     } else {
 3338:         changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
 3339:         current[newitemVal] = newpos;
 3340:     }
 3341:     for (var i=0; i<categories[idx].length; i++) {
 3342:         var elementName = categories[idx][i];
 3343:         if (elementName != item) {
 3344:             if (form.elements[elementName]) {
 3345:                 var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
 3346:                 current[currVal] = elementName;
 3347:             }
 3348:         }
 3349:     }
 3350:     var oldVal;
 3351:     for (var j=0; j<maxh; j++) {
 3352:         if (current[j] == undefined) {
 3353:             oldVal = j;
 3354:         }
 3355:     }
 3356:     if (oldVal < changedVal) {
 3357:         for (var k=oldVal+1; k<=changedVal ; k++) {
 3358:            var elementName = current[k];
 3359:            form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
 3360:         }
 3361:     } else {
 3362:         for (var k=changedVal; k<oldVal; k++) {
 3363:             var elementName = current[k];
 3364:             form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
 3365:         }
 3366:     }
 3367:     return;
 3368: }
 3369: 
 3370: function categoryCheck(form) {
 3371:     if (form.elements['addcategory_name'].value == 'instcode') {
 3372:         alert('$instcode_reserved\\n$choose_again');
 3373:         return false;
 3374:     }
 3375:     if (form.elements['addcategory_name'].value == 'communities') {
 3376:         alert('$communities_reserved\\n$choose_again');
 3377:         return false;
 3378:     }
 3379:     return true;
 3380: }
 3381: 
 3382: // ]]>
 3383: </script>
 3384: 
 3385: ENDSCRIPT
 3386:     return $output;
 3387: }
 3388: 
 3389: sub initialize_categories {
 3390:     my ($itemcount) = @_;
 3391:     my ($datatable,$css_class,$chgstr);
 3392:     my %default_names = (
 3393:                       instcode    => 'Official courses (with institutional codes)',
 3394:                       communities => 'Communities',
 3395:                         );
 3396:     my $select0 = ' selected="selected"';
 3397:     my $select1 = '';
 3398:     foreach my $default ('instcode','communities') {
 3399:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3400:         $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
 3401:         if ($default eq 'communities') {
 3402:             $select1 = $select0;
 3403:             $select0 = '';
 3404:         }
 3405:         $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 3406:                      .'<select name="'.$default.'_pos">'
 3407:                      .'<option value="0"'.$select0.'>1</option>'
 3408:                      .'<option value="1"'.$select1.'>2</option>'
 3409:                      .'<option value="2">3</option></select>&nbsp;'
 3410:                      .$default_names{$default}
 3411:                      .'</span></td><td><span class="LC_nobreak">'
 3412:                      .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
 3413:                      .&mt('Display').'</label>&nbsp;<label>'
 3414:                      .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
 3415:                  .'</label></span></td></tr>';
 3416:         $itemcount ++;
 3417:     }
 3418:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3419:     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
 3420:     $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
 3421:                   .'<select name="addcategory_pos"'.$chgstr.'>'
 3422:                   .'<option value="0">1</option>'
 3423:                   .'<option value="1">2</option>'
 3424:                   .'<option value="2" selected="selected">3</option></select>&nbsp;'
 3425:                   .&mt('Add category').'</td><td>'.&mt('Name:')
 3426:                   .'&nbsp;<input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
 3427:     return $datatable;
 3428: }
 3429: 
 3430: sub build_category_rows {
 3431:     my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
 3432:     my ($text,$name,$item,$chgstr);
 3433:     if (ref($cats) eq 'ARRAY') {
 3434:         my $maxdepth = scalar(@{$cats});
 3435:         if (ref($cats->[$depth]) eq 'HASH') {
 3436:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
 3437:                 my $numchildren = @{$cats->[$depth]{$parent}};
 3438:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
 3439:                 $text .= '<td><table class="LC_datatable">';
 3440:                 my ($idxnum,$parent_name,$parent_item);
 3441:                 my $higher = $depth - 1;
 3442:                 if ($higher == 0) {
 3443:                     $parent_name = &escape($parent).'::'.$higher;
 3444:                 } else {
 3445:                     if (ref($path) eq 'ARRAY') {
 3446:                         $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 3447:                     }
 3448:                 }
 3449:                 $parent_item = 'addcategory_pos_'.$parent_name;
 3450:                 for (my $j=0; $j<=$numchildren; $j++) {
 3451:                     if ($j < $numchildren) {
 3452:                         $name = $cats->[$depth]{$parent}[$j];
 3453:                         $item = &escape($name).':'.&escape($parent).':'.$depth;
 3454:                         $idxnum = $idx->{$item};
 3455:                     } else {
 3456:                         $name = $parent_name;
 3457:                         $item = $parent_item;
 3458:                     }
 3459:                     $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
 3460:                     $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
 3461:                     for (my $i=0; $i<=$numchildren; $i++) {
 3462:                         my $vpos = $i+1;
 3463:                         my $selstr;
 3464:                         if ($j == $i) {
 3465:                             $selstr = ' selected="selected" ';
 3466:                         }
 3467:                         $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
 3468:                     }
 3469:                     $text .= '</select>&nbsp;';
 3470:                     if ($j < $numchildren) {
 3471:                         my $deeper = $depth+1;
 3472:                         $text .= $name.'&nbsp;'
 3473:                                  .'<label><input type="checkbox" name="deletecategory" value="'
 3474:                                  .$item.'" />'.&mt('Delete').'</label></span></td><td>';
 3475:                         if(ref($path) eq 'ARRAY') {
 3476:                             push(@{$path},$name);
 3477:                             $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
 3478:                             pop(@{$path});
 3479:                         }
 3480:                     } else {
 3481:                         $text .= &mt('Add subcategory:').'&nbsp;</span><input type="textbox" size="20" name="addcategory_name_';
 3482:                         if ($j == $numchildren) {
 3483:                             $text .= $name;
 3484:                         } else {
 3485:                             $text .= $item;
 3486:                         }
 3487:                         $text .= '" value="" />';
 3488:                     }
 3489:                     $text .= '</td></tr>';
 3490:                 }
 3491:                 $text .= '</table></td>';
 3492:             } else {
 3493:                 my $higher = $depth-1;
 3494:                 if ($higher == 0) {
 3495:                     $name = &escape($parent).'::'.$higher;
 3496:                 } else {
 3497:                     if (ref($path) eq 'ARRAY') {
 3498:                         $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
 3499:                     }
 3500:                 }
 3501:                 my $colspan;
 3502:                 if ($parent ne 'instcode') {
 3503:                     $colspan = $maxdepth - $depth - 1;
 3504:                     $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
 3505:                 }
 3506:             }
 3507:         }
 3508:     }
 3509:     return $text;
 3510: }
 3511: 
 3512: sub modifiable_userdata_row {
 3513:     my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
 3514:     my $rolename;
 3515:     if ($context eq 'selfcreate') {
 3516:         if (ref($usertypes) eq 'HASH') {
 3517:             $rolename = $usertypes->{$role};
 3518:         } else {
 3519:             $rolename = $role;
 3520:         }
 3521:     } else {
 3522:         if ($role eq 'cr') {
 3523:             $rolename = &mt('Custom role');
 3524:         } else {
 3525:             $rolename = &Apache::lonnet::plaintext($role);
 3526:         }
 3527:     }
 3528:     my @fields = ('lastname','firstname','middlename','generation',
 3529:                   'permanentemail','id');
 3530:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 3531:     my $output;
 3532:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 3533:     $output = '<tr '.$css_class.'>'.
 3534:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
 3535:               '<td class="LC_left_item" colspan="2"><table>';
 3536:     my $rem;
 3537:     my %checks;
 3538:     if (ref($settings) eq 'HASH') {
 3539:         if (ref($settings->{$context}) eq 'HASH') {
 3540:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
 3541:                 foreach my $field (@fields) {
 3542:                     if ($settings->{$context}->{$role}->{$field}) {
 3543:                         $checks{$field} = ' checked="checked" ';
 3544:                     }
 3545:                 }
 3546:             }
 3547:         }
 3548:     }
 3549:     for (my $i=0; $i<@fields; $i++) {
 3550:         my $rem = $i%($numinrow);
 3551:         if ($rem == 0) {
 3552:             if ($i > 0) {
 3553:                 $output .= '</tr>';
 3554:             }
 3555:             $output .= '<tr>';
 3556:         }
 3557:         my $check = ' ';
 3558:         if (exists($checks{$fields[$i]})) {
 3559:             $check = $checks{$fields[$i]}
 3560:         } else {
 3561:             if ($role eq 'st') {
 3562:                 if (ref($settings) ne 'HASH') {
 3563:                     $check = ' checked="checked" '; 
 3564:                 }
 3565:             }
 3566:         }
 3567:         $output .= '<td class="LC_left_item">'.
 3568:                    '<span class="LC_nobreak"><label>'.
 3569:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
 3570:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
 3571:                    '</label></span></td>';
 3572:         $rem = @fields%($numinrow);
 3573:     }
 3574:     my $colsleft = $numinrow - $rem;
 3575:     if ($colsleft > 1 ) {
 3576:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 3577:                    '&nbsp;</td>';
 3578:     } elsif ($colsleft == 1) {
 3579:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 3580:     }
 3581:     $output .= '</tr></table></td></tr>';
 3582:     return $output;
 3583: }
 3584: 
 3585: sub insttypes_row {
 3586:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
 3587:     my %lt = &Apache::lonlocal::texthash (
 3588:                       cansearch => 'Users allowed to search',
 3589:                       statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
 3590:                       lockablenames => 'User preference to lock name',
 3591:              );
 3592:     my $showdom;
 3593:     if ($context eq 'cansearch') {
 3594:         $showdom = ' ('.$dom.')';
 3595:     }
 3596:     my $output =  '<tr class="LC_odd_row">'.
 3597:                   '<td>'.$lt{$context}.$showdom.
 3598:                   '</td><td class="LC_left_item" colspan="2"><table>';
 3599:     my $rem;
 3600:     if (ref($types) eq 'ARRAY') {
 3601:         for (my $i=0; $i<@{$types}; $i++) {
 3602:             if (defined($usertypes->{$types->[$i]})) {
 3603:                 my $rem = $i%($numinrow);
 3604:                 if ($rem == 0) {
 3605:                     if ($i > 0) {
 3606:                         $output .= '</tr>';
 3607:                     }
 3608:                     $output .= '<tr>';
 3609:                 }
 3610:                 my $check = ' ';
 3611:                 if (ref($settings) eq 'HASH') {
 3612:                     if (ref($settings->{$context}) eq 'ARRAY') {
 3613:                         if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
 3614:                             $check = ' checked="checked" ';
 3615:                         }
 3616:                     } elsif ($context eq 'statustocreate') {
 3617:                         $check = ' checked="checked" ';
 3618:                     }
 3619:                 }
 3620:                 $output .= '<td class="LC_left_item">'.
 3621:                            '<span class="LC_nobreak"><label>'.
 3622:                            '<input type="checkbox" name="'.$context.'" '.
 3623:                            'value="'.$types->[$i].'"'.$check.'/>'.
 3624:                            $usertypes->{$types->[$i]}.'</label></span></td>';
 3625:             }
 3626:         }
 3627:         $rem = @{$types}%($numinrow);
 3628:     }
 3629:     my $colsleft = $numinrow - $rem;
 3630:     if (($rem == 0) && (@{$types} > 0)) {
 3631:         $output .= '<tr>';
 3632:     }
 3633:     if ($colsleft > 1) {
 3634:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 3635:     } else {
 3636:         $output .= '<td class="LC_left_item">';
 3637:     }
 3638:     my $defcheck = ' ';
 3639:     if (ref($settings) eq 'HASH') {  
 3640:         if (ref($settings->{$context}) eq 'ARRAY') {
 3641:             if (grep(/^default$/,@{$settings->{$context}})) {
 3642:                 $defcheck = ' checked="checked" ';
 3643:             }
 3644:         } elsif ($context eq 'statustocreate') {
 3645:             $defcheck = ' checked="checked" ';
 3646:         }
 3647:     }
 3648:     $output .= '<span class="LC_nobreak"><label>'.
 3649:                '<input type="checkbox" name="'.$context.'" '.
 3650:                'value="default"'.$defcheck.'/>'.
 3651:                $othertitle.'</label></span></td>'.
 3652:                '</tr></table></td></tr>';
 3653:     return $output;
 3654: }
 3655: 
 3656: sub sorted_searchtitles {
 3657:     my %searchtitles = &Apache::lonlocal::texthash(
 3658:                          'uname' => 'username',
 3659:                          'lastname' => 'last name',
 3660:                          'lastfirst' => 'last name, first name',
 3661:                      );
 3662:     my @titleorder = ('uname','lastname','lastfirst');
 3663:     return (\%searchtitles,\@titleorder);
 3664: }
 3665: 
 3666: sub sorted_searchtypes {
 3667:     my %srchtypes_desc = (
 3668:                            exact    => 'is exact match',
 3669:                            contains => 'contains ..',
 3670:                            begins   => 'begins with ..',
 3671:                          );
 3672:     my @srchtypeorder = ('exact','begins','contains');
 3673:     return (\%srchtypes_desc,\@srchtypeorder);
 3674: }
 3675: 
 3676: sub usertype_update_row {
 3677:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
 3678:     my $datatable;
 3679:     my $numinrow = 4;
 3680:     foreach my $type (@{$types}) {
 3681:         if (defined($usertypes->{$type})) {
 3682:             $$rownums ++;
 3683:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
 3684:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
 3685:                           '</td><td class="LC_left_item"><table>';
 3686:             for (my $i=0; $i<@{$fields}; $i++) {
 3687:                 my $rem = $i%($numinrow);
 3688:                 if ($rem == 0) {
 3689:                     if ($i > 0) {
 3690:                         $datatable .= '</tr>';
 3691:                     }
 3692:                     $datatable .= '<tr>';
 3693:                 }
 3694:                 my $check = ' ';
 3695:                 if (ref($settings) eq 'HASH') {
 3696:                     if (ref($settings->{'fields'}) eq 'HASH') {
 3697:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
 3698:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
 3699:                                 $check = ' checked="checked" ';
 3700:                             }
 3701:                         }
 3702:                     }
 3703:                 }
 3704: 
 3705:                 if ($i == @{$fields}-1) {
 3706:                     my $colsleft = $numinrow - $rem;
 3707:                     if ($colsleft > 1) {
 3708:                         $datatable .= '<td colspan="'.$colsleft.'">';
 3709:                     } else {
 3710:                         $datatable .= '<td>';
 3711:                     }
 3712:                 } else {
 3713:                     $datatable .= '<td>';
 3714:                 }
 3715:                 $datatable .= '<span class="LC_nobreak"><label>'.
 3716:                               '<input type="checkbox" name="updateable_'.$type.
 3717:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
 3718:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
 3719:             }
 3720:             $datatable .= '</tr></table></td></tr>';
 3721:         }
 3722:     }
 3723:     return $datatable;
 3724: }
 3725: 
 3726: sub modify_login {
 3727:     my ($r,$dom,$confname,%domconfig) = @_;
 3728:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
 3729:     my %title = ( coursecatalog => 'Display course catalog',
 3730:                   adminmail => 'Display administrator E-mail address',
 3731:                   newuser => 'Link for visitors to create a user account',
 3732:                   loginheader => 'Log-in box header');
 3733:     my @offon = ('off','on');
 3734:     my %curr_loginvia;
 3735:     if (ref($domconfig{login}) eq 'HASH') {
 3736:         if (ref($domconfig{login}{loginvia}) eq 'HASH') {
 3737:             foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
 3738:                 $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
 3739:             }
 3740:         }
 3741:     }
 3742:     my %loginhash;
 3743:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
 3744:                                            \%domconfig,\%loginhash);
 3745:     my @toggles = ('coursecatalog','adminmail','newuser');
 3746:     foreach my $item (@toggles) {
 3747:         $loginhash{login}{$item} = $env{'form.'.$item};
 3748:     }
 3749:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
 3750:     if (ref($colchanges{'login'}) eq 'HASH') {  
 3751:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
 3752:                                          \%loginhash);
 3753:     }
 3754: 
 3755:     my %servers = &dom_servers($dom);
 3756:     my @loginvia_attribs = ('serverpath','custompath','exempt');
 3757:     if (keys(%servers) > 1) {
 3758:         foreach my $lonhost (keys(%servers)) {
 3759:             next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
 3760:             if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
 3761:                 if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
 3762:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
 3763:                 } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
 3764:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 3765:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 3766:                         $changes{'loginvia'}{$lonhost} = 1;
 3767:                     } else {
 3768:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
 3769:                         $changes{'loginvia'}{$lonhost} = 1;
 3770:                     }
 3771:                 } else {
 3772:                     if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 3773:                         $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 3774:                         $changes{'loginvia'}{$lonhost} = 1;
 3775:                     }
 3776:                 }
 3777:                 if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
 3778:                     foreach my $item (@loginvia_attribs) {
 3779:                         $loginhash{login}{loginvia}{$lonhost}{$item} = '';
 3780:                     }
 3781:                 } else {
 3782:                     foreach my $item (@loginvia_attribs) {
 3783:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 3784:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 3785:                             $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
 3786:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 3787:                                 $new = '/';
 3788:                             }
 3789:                         }
 3790:                         if (($item eq 'custompath') && 
 3791:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 3792:                             $new = '';
 3793:                         }
 3794:                         if ($new ne $curr_loginvia{$lonhost}{$item}) {
 3795:                             $changes{'loginvia'}{$lonhost} = 1;
 3796:                         }
 3797:                         if ($item eq 'exempt') {
 3798:                             $new =~ s/^\s+//;
 3799:                             $new =~ s/\s+$//;
 3800:                             my @poss_ips = split(/\s*[,:]\s*/,$new);
 3801:                             my @okips;
 3802:                             foreach my $ip (@poss_ips) {
 3803:                                 if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
 3804:                                     if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
 3805:                                         push(@okips,$ip); 
 3806:                                     }
 3807:                                 }
 3808:                             }
 3809:                             if (@okips > 0) {
 3810:                                 $new = join(',',@okips); 
 3811:                             } else {
 3812:                                 $new = ''; 
 3813:                             }
 3814:                         }
 3815: 
 3816:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 3817:                     }
 3818:                 }
 3819:             } else {
 3820:                 if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
 3821:                     $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
 3822:                     $changes{'loginvia'}{$lonhost} = 1;
 3823:                     foreach my $item (@loginvia_attribs) {
 3824:                         my $new = $env{'form.'.$lonhost.'_'.$item};
 3825:                         if (($item eq 'serverpath') && ($new eq 'custom')) {
 3826:                             if ($env{'form.'.$lonhost.'_custompath'} eq '') {
 3827:                                 $new = '/';
 3828:                             }
 3829:                         }
 3830:                         if (($item eq 'custompath') && 
 3831:                             ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
 3832:                             $new = '';
 3833:                         }
 3834:                         $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
 3835:                     }
 3836:                 }
 3837:             }
 3838:         }
 3839:     }
 3840: 
 3841:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
 3842:                                              $dom);
 3843:     if ($putresult eq 'ok') {
 3844:         my @toggles = ('coursecatalog','adminmail','newuser');
 3845:         my %defaultchecked = (
 3846:                     'coursecatalog' => 'on',
 3847:                     'adminmail'     => 'off',
 3848:                     'newuser'       => 'off',
 3849:         );
 3850:         if (ref($domconfig{'login'}) eq 'HASH') {
 3851:             foreach my $item (@toggles) {
 3852:                 if ($defaultchecked{$item} eq 'on') { 
 3853:                     if (($domconfig{'login'}{$item} eq '0') &&
 3854:                         ($env{'form.'.$item} eq '1')) {
 3855:                         $changes{$item} = 1;
 3856:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 3857:                               $domconfig{'login'}{$item} eq '1') &&
 3858:                              ($env{'form.'.$item} eq '0')) {
 3859:                         $changes{$item} = 1;
 3860:                     }
 3861:                 } elsif ($defaultchecked{$item} eq 'off') {
 3862:                     if (($domconfig{'login'}{$item} eq '1') &&
 3863:                         ($env{'form.'.$item} eq '0')) {
 3864:                         $changes{$item} = 1;
 3865:                     } elsif (($domconfig{'login'}{$item} eq '' ||
 3866:                               $domconfig{'login'}{$item} eq '0') &&
 3867:                              ($env{'form.'.$item} eq '1')) {
 3868:                         $changes{$item} = 1;
 3869:                     }
 3870:                 }
 3871:             }
 3872:         }
 3873:         if (keys(%changes) > 0 || $colchgtext) {
 3874:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 3875:             $resulttext = &mt('Changes made:').'<ul>';
 3876:             foreach my $item (sort(keys(%changes))) {
 3877:                 if ($item eq 'loginvia') {
 3878:                     if (ref($changes{$item}) eq 'HASH') {
 3879:                         $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
 3880:                         foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
 3881:                             if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
 3882:                                 if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
 3883:                                     my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
 3884:                                     $protocol = 'http' if ($protocol ne 'https');
 3885:                                     my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
 3886: 
 3887:                                     if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
 3888:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
 3889:                                     } else {
 3890:                                         $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'}; 
 3891:                                     }
 3892:                                     $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
 3893:                                     if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
 3894:                                         $resulttext .= '&nbsp;'.&mt('No redirection for clients from following IPs:').'&nbsp;'.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
 3895:                                     }
 3896:                                     $resulttext .= '</li>';
 3897:                                 } else {
 3898:                                     $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
 3899:                                 }
 3900:                             } else {
 3901:                                 $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
 3902:                             }
 3903:                         }
 3904:                         $resulttext .= '</ul></li>';
 3905:                     }
 3906:                 } else {
 3907:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 3908:                 }
 3909:             }
 3910:             $resulttext .= $colchgtext.'</ul>';
 3911:         } else {
 3912:             $resulttext = &mt('No changes made to log-in page settings');
 3913:         }
 3914:     } else {
 3915:         $resulttext = '<span class="LC_error">'.
 3916: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 3917:     }
 3918:     if ($errors) {
 3919:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 3920:                        $errors.'</ul>';
 3921:     }
 3922:     return $resulttext;
 3923: }
 3924: 
 3925: sub color_font_choices {
 3926:     my %choices =
 3927:         &Apache::lonlocal::texthash (
 3928:             img => "Header",
 3929:             bgs => "Background colors",
 3930:             links => "Link colors",
 3931:             images => "Images",
 3932:             font => "Font color",
 3933:             fontmenu => "Font Menu",
 3934:             pgbg => "Page",
 3935:             tabbg => "Header",
 3936:             sidebg => "Border",
 3937:             link => "Link",
 3938:             alink => "Active link",
 3939:             vlink => "Visited link",
 3940:         );
 3941:     return %choices;
 3942: }
 3943: 
 3944: sub modify_rolecolors {
 3945:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
 3946:     my ($resulttext,%rolehash);
 3947:     $rolehash{'rolecolors'} = {};
 3948:     if (ref($domconfig{'rolecolors'}) ne 'HASH') {
 3949:         if ($domconfig{'rolecolors'} eq '') {
 3950:             $domconfig{'rolecolors'} = {};
 3951:         }
 3952:     }
 3953:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 3954:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 3955:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 3956:                                              $dom);
 3957:     if ($putresult eq 'ok') {
 3958:         if (keys(%changes) > 0) {
 3959:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 3960:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 3961:                                              $rolehash{'rolecolors'});
 3962:         } else {
 3963:             $resulttext = &mt('No changes made to default color schemes');
 3964:         }
 3965:     } else {
 3966:         $resulttext = '<span class="LC_error">'.
 3967: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 3968:     }
 3969:     if ($errors) {
 3970:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 3971:                        $errors.'</ul>';
 3972:     }
 3973:     return $resulttext;
 3974: }
 3975: 
 3976: sub modify_colors {
 3977:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 3978:     my (%changes,%choices);
 3979:     my @bgs;
 3980:     my @links = ('link','alink','vlink');
 3981:     my @logintext;
 3982:     my @images;
 3983:     my $servadm = $r->dir_config('lonAdmEMail');
 3984:     my $errors;
 3985:     foreach my $role (@{$roles}) {
 3986:         if ($role eq 'login') {
 3987:             %choices = &login_choices();
 3988:             @logintext = ('textcol','bgcol');
 3989:         } else {
 3990:             %choices = &color_font_choices();
 3991:             $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
 3992:         }
 3993:         if ($role eq 'login') {
 3994:             @images = ('img','logo','domlogo','login');
 3995:             @bgs = ('pgbg','mainbg','sidebg');
 3996:         } else {
 3997:             @images = ('img');
 3998:             @bgs = ('pgbg','tabbg','sidebg'); 
 3999:         }
 4000:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 4001:         foreach my $item (@bgs,@links,@logintext) {
 4002:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 4003:         }
 4004:         my ($configuserok,$author_ok,$switchserver) = 
 4005:             &config_check($dom,$confname,$servadm);
 4006:         my ($width,$height) = &thumb_dimensions();
 4007:         if (ref($domconfig->{$role}) ne 'HASH') {
 4008:             $domconfig->{$role} = {};
 4009:         }
 4010:         foreach my $img (@images) {
 4011:             if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {  
 4012:                 if (defined($env{'form.login_showlogo_'.$img})) {
 4013:                     $confhash->{$role}{'showlogo'}{$img} = 1;
 4014:                 } else { 
 4015:                     $confhash->{$role}{'showlogo'}{$img} = 0;
 4016:                 }
 4017:             } 
 4018: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 4019: 		 && !defined($domconfig->{$role}{$img})
 4020: 		 && !$env{'form.'.$role.'_del_'.$img}
 4021: 		 && $env{'form.'.$role.'_import_'.$img}) {
 4022: 		# import the old configured image from the .tab setting
 4023: 		# if they haven't provided a new one 
 4024: 		$domconfig->{$role}{$img} = 
 4025: 		    $env{'form.'.$role.'_import_'.$img};
 4026: 	    }
 4027:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 4028:                 my $error;
 4029:                 if ($configuserok eq 'ok') {
 4030:                     if ($switchserver) {
 4031:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 4032:                     } else {
 4033:                         if ($author_ok eq 'ok') {
 4034:                             my ($result,$logourl) = 
 4035:                                 &publishlogo($r,'upload',$role.'_'.$img,
 4036:                                            $dom,$confname,$img,$width,$height);
 4037:                             if ($result eq 'ok') {
 4038:                                 $confhash->{$role}{$img} = $logourl;
 4039:                                 $changes{$role}{'images'}{$img} = 1;
 4040:                             } else {
 4041:                                 $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);
 4042:                             }
 4043:                         } else {
 4044:                             $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);
 4045:                         }
 4046:                     }
 4047:                 } else {
 4048:                     $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);
 4049:                 }
 4050:                 if ($error) {
 4051:                     &Apache::lonnet::logthis($error);
 4052:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 4053:                 }
 4054:             } elsif ($domconfig->{$role}{$img} ne '') {
 4055:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 4056:                     my $error;
 4057:                     if ($configuserok eq 'ok') {
 4058: # is confname an author?
 4059:                         if ($switchserver eq '') {
 4060:                             if ($author_ok eq 'ok') {
 4061:                                 my ($result,$logourl) = 
 4062:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 4063:                                             $dom,$confname,$img,$width,$height);
 4064:                                 if ($result eq 'ok') {
 4065:                                     $confhash->{$role}{$img} = $logourl;
 4066: 				    $changes{$role}{'images'}{$img} = 1;
 4067:                                 }
 4068:                             }
 4069:                         }
 4070:                     }
 4071:                 }
 4072:             }
 4073:         }
 4074:         if (ref($domconfig) eq 'HASH') {
 4075:             if (ref($domconfig->{$role}) eq 'HASH') {
 4076:                 foreach my $img (@images) {
 4077:                     if ($domconfig->{$role}{$img} ne '') {
 4078:                         if ($env{'form.'.$role.'_del_'.$img}) {
 4079:                             $confhash->{$role}{$img} = '';
 4080:                             $changes{$role}{'images'}{$img} = 1;
 4081:                         } else {
 4082:                             if ($confhash->{$role}{$img} eq '') {
 4083:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 4084:                             }
 4085:                         }
 4086:                     } else {
 4087:                         if ($env{'form.'.$role.'_del_'.$img}) {
 4088:                             $confhash->{$role}{$img} = '';
 4089:                             $changes{$role}{'images'}{$img} = 1;
 4090:                         } 
 4091:                     }
 4092:                     if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
 4093:                         if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
 4094:                             if ($confhash->{$role}{'showlogo'}{$img} ne 
 4095:                                 $domconfig->{$role}{'showlogo'}{$img}) {
 4096:                                 $changes{$role}{'showlogo'}{$img} = 1; 
 4097:                             }
 4098:                         } else {
 4099:                             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 4100:                                 $changes{$role}{'showlogo'}{$img} = 1;
 4101:                             }
 4102:                         }
 4103:                     }
 4104:                 }
 4105:                 if ($domconfig->{$role}{'font'} ne '') {
 4106:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 4107:                         $changes{$role}{'font'} = 1;
 4108:                     }
 4109:                 } else {
 4110:                     if ($confhash->{$role}{'font'}) {
 4111:                         $changes{$role}{'font'} = 1;
 4112:                     }
 4113:                 }
 4114:                 if ($role ne 'login') {
 4115:                     if ($domconfig->{$role}{'fontmenu'} ne '') {
 4116:                         if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
 4117:                             $changes{$role}{'fontmenu'} = 1;
 4118:                         }
 4119:                     } else {
 4120:                         if ($confhash->{$role}{'fontmenu'}) {
 4121:                             $changes{$role}{'fontmenu'} = 1;
 4122:                         }
 4123:                     }
 4124:                 }
 4125:                 foreach my $item (@bgs) {
 4126:                     if ($domconfig->{$role}{$item} ne '') {
 4127:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 4128:                             $changes{$role}{'bgs'}{$item} = 1;
 4129:                         } 
 4130:                     } else {
 4131:                         if ($confhash->{$role}{$item}) {
 4132:                             $changes{$role}{'bgs'}{$item} = 1;
 4133:                         }
 4134:                     }
 4135:                 }
 4136:                 foreach my $item (@links) {
 4137:                     if ($domconfig->{$role}{$item} ne '') {
 4138:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 4139:                             $changes{$role}{'links'}{$item} = 1;
 4140:                         }
 4141:                     } else {
 4142:                         if ($confhash->{$role}{$item}) {
 4143:                             $changes{$role}{'links'}{$item} = 1;
 4144:                         }
 4145:                     }
 4146:                 }
 4147:                 foreach my $item (@logintext) {
 4148:                     if ($domconfig->{$role}{$item} ne '') {
 4149:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 4150:                             $changes{$role}{'logintext'}{$item} = 1;
 4151:                         }
 4152:                     } else {
 4153:                         if ($confhash->{$role}{$item}) {
 4154:                             $changes{$role}{'logintext'}{$item} = 1;
 4155:                         }
 4156:                     }
 4157:                 }
 4158:             } else {
 4159:                 &default_change_checker($role,\@images,\@links,\@bgs,
 4160:                                         \@logintext,$confhash,\%changes); 
 4161:             }
 4162:         } else {
 4163:             &default_change_checker($role,\@images,\@links,\@bgs,
 4164:                                     \@logintext,$confhash,\%changes); 
 4165:         }
 4166:     }
 4167:     return ($errors,%changes);
 4168: }
 4169: 
 4170: sub config_check {
 4171:     my ($dom,$confname,$servadm) = @_;
 4172:     my ($configuserok,$author_ok,$switchserver,%currroles);
 4173:     my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 4174:     ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 4175:                                                    $confname,$servadm);
 4176:     if ($configuserok eq 'ok') {
 4177:         $switchserver = &check_switchserver($dom,$confname);
 4178:         if ($switchserver eq '') {
 4179:             $author_ok = &check_authorstatus($dom,$confname,%currroles);
 4180:         }
 4181:     }
 4182:     return ($configuserok,$author_ok,$switchserver);
 4183: }
 4184: 
 4185: sub default_change_checker {
 4186:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
 4187:     foreach my $item (@{$links}) {
 4188:         if ($confhash->{$role}{$item}) {
 4189:             $changes->{$role}{'links'}{$item} = 1;
 4190:         }
 4191:     }
 4192:     foreach my $item (@{$bgs}) {
 4193:         if ($confhash->{$role}{$item}) {
 4194:             $changes->{$role}{'bgs'}{$item} = 1;
 4195:         }
 4196:     }
 4197:     foreach my $item (@{$logintext}) {
 4198:         if ($confhash->{$role}{$item}) {
 4199:             $changes->{$role}{'logintext'}{$item} = 1;
 4200:         }
 4201:     }
 4202:     foreach my $img (@{$images}) {
 4203:         if ($env{'form.'.$role.'_del_'.$img}) {
 4204:             $confhash->{$role}{$img} = '';
 4205:             $changes->{$role}{'images'}{$img} = 1;
 4206:         }
 4207:         if ($role eq 'login') {
 4208:             if ($confhash->{$role}{'showlogo'}{$img} == 0) {
 4209:                 $changes->{$role}{'showlogo'}{$img} = 1;
 4210:             }
 4211:         }
 4212:     }
 4213:     if ($confhash->{$role}{'font'}) {
 4214:         $changes->{$role}{'font'} = 1;
 4215:     }
 4216: }
 4217: 
 4218: sub display_colorchgs {
 4219:     my ($dom,$changes,$roles,$confhash) = @_;
 4220:     my (%choices,$resulttext);
 4221:     if (!grep(/^login$/,@{$roles})) {
 4222:         $resulttext = &mt('Changes made:').'<br />';
 4223:     }
 4224:     foreach my $role (@{$roles}) {
 4225:         if ($role eq 'login') {
 4226:             %choices = &login_choices();
 4227:         } else {
 4228:             %choices = &color_font_choices();
 4229:         }
 4230:         if (ref($changes->{$role}) eq 'HASH') {
 4231:             if ($role ne 'login') {
 4232:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 4233:             }
 4234:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 4235:                 if ($role ne 'login') {
 4236:                     $resulttext .= '<ul>';
 4237:                 }
 4238:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 4239:                     if ($role ne 'login') {
 4240:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 4241:                     }
 4242:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 4243:                         if (($role eq 'login') && ($key eq 'showlogo')) {
 4244:                             if ($confhash->{$role}{$key}{$item}) {
 4245:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
 4246:                             } else {
 4247:                                 $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
 4248:                             }
 4249:                         } elsif ($confhash->{$role}{$item} eq '') {
 4250:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 4251:                         } else {
 4252:                             my $newitem = $confhash->{$role}{$item};
 4253:                             if ($key eq 'images') {
 4254:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 4255:                             }
 4256:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 4257:                         }
 4258:                     }
 4259:                     if ($role ne 'login') {
 4260:                         $resulttext .= '</ul></li>';
 4261:                     }
 4262:                 } else {
 4263:                     if ($confhash->{$role}{$key} eq '') {
 4264:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 4265:                     } else {
 4266:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 4267:                     }
 4268:                 }
 4269:                 if ($role ne 'login') {
 4270:                     $resulttext .= '</ul>';
 4271:                 }
 4272:             }
 4273:         }
 4274:     }
 4275:     return $resulttext;
 4276: }
 4277: 
 4278: sub thumb_dimensions {
 4279:     return ('200','50');
 4280: }
 4281: 
 4282: sub check_dimensions {
 4283:     my ($inputfile) = @_;
 4284:     my ($fullwidth,$fullheight);
 4285:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 4286:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 4287:             my $imageinfo = <PIPE>;
 4288:             if (!close(PIPE)) {
 4289:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 4290:             }
 4291:             chomp($imageinfo);
 4292:             my ($fullsize) = 
 4293:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
 4294:             if ($fullsize) {
 4295:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 4296:             }
 4297:         }
 4298:     }
 4299:     return ($fullwidth,$fullheight);
 4300: }
 4301: 
 4302: sub check_configuser {
 4303:     my ($uhome,$dom,$confname,$servadm) = @_;
 4304:     my ($configuserok,%currroles);
 4305:     if ($uhome eq 'no_host') {
 4306:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 4307:         my $configpass = &LONCAPA::Enrollment::create_password();
 4308:         $configuserok = 
 4309:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 4310:                              $configpass,'','','','','',undef,$servadm);
 4311:     } else {
 4312:         $configuserok = 'ok';
 4313:         %currroles = 
 4314:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 4315:     }
 4316:     return ($configuserok,%currroles);
 4317: }
 4318: 
 4319: sub check_authorstatus {
 4320:     my ($dom,$confname,%currroles) = @_;
 4321:     my $author_ok;
 4322:     if (!$currroles{':'.$dom.':au'}) {
 4323:         my $start = time;
 4324:         my $end = 0;
 4325:         $author_ok = 
 4326:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 4327:                                         'au',$end,$start,'','','domconfig');
 4328:     } else {
 4329:         $author_ok = 'ok';
 4330:     }
 4331:     return $author_ok;
 4332: }
 4333: 
 4334: sub publishlogo {
 4335:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
 4336:     my ($output,$fname,$logourl);
 4337:     if ($action eq 'upload') {
 4338:         $fname=$env{'form.'.$formname.'.filename'};
 4339:         chop($env{'form.'.$formname});
 4340:     } else {
 4341:         ($fname) = ($formname =~ /([^\/]+)$/);
 4342:     }
 4343:     if ($savefileas ne '') {
 4344:         $fname = $savefileas;
 4345:     }
 4346:     $fname=&Apache::lonnet::clean_filename($fname);
 4347: # See if there is anything left
 4348:     unless ($fname) { return ('error: no uploaded file'); }
 4349:     $fname="$subdir/$fname";
 4350:     my $filepath='/home/'.$confname.'/public_html';
 4351:     my ($fnamepath,$file,$fetchthumb);
 4352:     $file=$fname;
 4353:     if ($fname=~m|/|) {
 4354:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 4355:     }
 4356:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
 4357:     my $count;
 4358:     for ($count=4;$count<=$#parts;$count++) {
 4359:         $filepath.="/$parts[$count]";
 4360:         if ((-e $filepath)!=1) {
 4361:             mkdir($filepath,02770);
 4362:         }
 4363:     }
 4364:     # Check for bad extension and disallow upload
 4365:     if ($file=~/\.(\w+)$/ &&
 4366:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 4367:         $output = 
 4368:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
 4369:     } elsif ($file=~/\.(\w+)$/ &&
 4370:         !defined(&Apache::loncommon::fileembstyle($1))) {
 4371:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 4372:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 4373:         $output = &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 4374:     } elsif (-d "$filepath/$file") {
 4375:         $output = &mt('File name is a directory name - rename the file and re-upload');
 4376:     } else {
 4377:         my $source = $filepath.'/'.$file;
 4378:         my $logfile;
 4379:         if (!open($logfile,">>$source".'.log')) {
 4380:             return (&mt('No write permission to Construction Space'));
 4381:         }
 4382:         print $logfile
 4383: "\n================= Publish ".localtime()." ================\n".
 4384: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 4385: # Save the file
 4386:         if (!open(FH,'>'.$source)) {
 4387:             &Apache::lonnet::logthis('Failed to create '.$source);
 4388:             return (&mt('Failed to create file'));
 4389:         }
 4390:         if ($action eq 'upload') {
 4391:             if (!print FH ($env{'form.'.$formname})) {
 4392:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 4393:                 return (&mt('Failed to write file'));
 4394:             }
 4395:         } else {
 4396:             my $original = &Apache::lonnet::filelocation('',$formname);
 4397:             if(!copy($original,$source)) {
 4398:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 4399:                 return (&mt('Failed to write file'));
 4400:             }
 4401:         }
 4402:         close(FH);
 4403:         chmod(0660, $source); # Permissions to rw-rw---.
 4404: 
 4405:         my $docroot=$r->dir_config('lonDocRoot');
 4406:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 4407:         my $copyfile=$targetdir.'/'.$file;
 4408: 
 4409:         my @parts=split(/\//,$targetdir);
 4410:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 4411:         for (my $count=5;$count<=$#parts;$count++) {
 4412:             $path.="/$parts[$count]";
 4413:             if (!-e $path) {
 4414:                 print $logfile "\nCreating directory ".$path;
 4415:                 mkdir($path,02770);
 4416:             }
 4417:         }
 4418:         my $versionresult;
 4419:         if (-e $copyfile) {
 4420:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 4421:         } else {
 4422:             $versionresult = 'ok';
 4423:         }
 4424:         if ($versionresult eq 'ok') {
 4425:             if (copy($source,$copyfile)) {
 4426:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 4427:                 $output = 'ok';
 4428:                 &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 4429:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 4430:             } else {
 4431:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 4432:                 $output = &mt('Failed to copy file to RES space').", $!";
 4433:             }
 4434:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 4435:                 my $inputfile = $filepath.'/'.$file;
 4436:                 my $outfile = $filepath.'/'.'tn-'.$file;
 4437:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 4438:                 if ($fullwidth ne '' && $fullheight ne '') { 
 4439:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 4440:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 4441:                         system("convert -sample $thumbsize $inputfile $outfile");
 4442:                         chmod(0660, $filepath.'/tn-'.$file);
 4443:                         if (-e $outfile) {
 4444:                             my $copyfile=$targetdir.'/tn-'.$file;
 4445:                             if (copy($outfile,$copyfile)) {
 4446:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 4447:                                 &write_metadata($dom,$confname,$formname,
 4448:                                                 $targetdir,'tn-'.$file,$logfile);
 4449:                             } else {
 4450:                                 print $logfile "\nUnable to write ".$copyfile.
 4451:                                                ':'.$!."\n";
 4452:                             }
 4453:                         }
 4454:                     }
 4455:                 }
 4456:             }
 4457:         } else {
 4458:             $output = $versionresult;
 4459:         }
 4460:     }
 4461:     return ($output,$logourl);
 4462: }
 4463: 
 4464: sub logo_versioning {
 4465:     my ($targetdir,$file,$logfile) = @_;
 4466:     my $target = $targetdir.'/'.$file;
 4467:     my ($maxversion,$fn,$extn,$output);
 4468:     $maxversion = 0;
 4469:     if ($file =~ /^(.+)\.(\w+)$/) {
 4470:         $fn=$1;
 4471:         $extn=$2;
 4472:     }
 4473:     opendir(DIR,$targetdir);
 4474:     while (my $filename=readdir(DIR)) {
 4475:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 4476:             $maxversion=($1>$maxversion)?$1:$maxversion;
 4477:         }
 4478:     }
 4479:     $maxversion++;
 4480:     print $logfile "\nCreating old version ".$maxversion."\n";
 4481:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 4482:     if (copy($target,$copyfile)) {
 4483:         print $logfile "Copied old target to ".$copyfile."\n";
 4484:         $copyfile=$copyfile.'.meta';
 4485:         if (copy($target.'.meta',$copyfile)) {
 4486:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 4487:             $output = 'ok';
 4488:         } else {
 4489:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 4490:             $output = &mt('Failed to copy old meta').", $!, ";
 4491:         }
 4492:     } else {
 4493:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 4494:         $output = &mt('Failed to copy old target').", $!, ";
 4495:     }
 4496:     return $output;
 4497: }
 4498: 
 4499: sub write_metadata {
 4500:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 4501:     my (%metadatafields,%metadatakeys,$output);
 4502:     $metadatafields{'title'}=$formname;
 4503:     $metadatafields{'creationdate'}=time;
 4504:     $metadatafields{'lastrevisiondate'}=time;
 4505:     $metadatafields{'copyright'}='public';
 4506:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 4507:                                          $env{'user.domain'};
 4508:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 4509:     $metadatafields{'domain'}=$dom;
 4510:     {
 4511:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 4512:         my $mfh;
 4513:         unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 4514:             $output = &mt('Could not write metadata');
 4515:         }
 4516:         foreach (sort keys %metadatafields) {
 4517:             unless ($_=~/\./) {
 4518:                 my $unikey=$_;
 4519:                 $unikey=~/^([A-Za-z]+)/;
 4520:                 my $tag=$1;
 4521:                 $tag=~tr/A-Z/a-z/;
 4522:                 print $mfh "\n\<$tag";
 4523:                 foreach (split(/\,/,$metadatakeys{$unikey})) {
 4524:                     my $value=$metadatafields{$unikey.'.'.$_};
 4525:                     $value=~s/\"/\'\'/g;
 4526:                     print $mfh ' '.$_.'="'.$value.'"';
 4527:                 }
 4528:                 print $mfh '>'.
 4529:                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 4530:                         .'</'.$tag.'>';
 4531:             }
 4532:         }
 4533:         $output = 'ok';
 4534:         print $logfile "\nWrote metadata";
 4535:         close($mfh);
 4536:     }
 4537: }
 4538: 
 4539: sub check_switchserver {
 4540:     my ($dom,$confname) = @_;
 4541:     my ($allowed,$switchserver);
 4542:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 4543:     if ($home eq 'no_host') {
 4544:         $home = &Apache::lonnet::domain($dom,'primary');
 4545:     }
 4546:     my @ids=&Apache::lonnet::current_machine_ids();
 4547:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 4548:     if (!$allowed) {
 4549: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
 4550:     }
 4551:     return $switchserver;
 4552: }
 4553: 
 4554: sub modify_quotas {
 4555:     my ($dom,$action,%domconfig) = @_;
 4556:     my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
 4557:         %limithash,$toolregexp,%conditions,$resulttext,%changes);
 4558:     if ($action eq 'quotas') {
 4559:         $context = 'tools'; 
 4560:     } else { 
 4561:         $context = $action;
 4562:     }
 4563:     if ($context eq 'requestcourses') {
 4564:         @usertools = ('official','unofficial','community');
 4565:         @options =('norequest','approval','validate','autolimit');
 4566:         %validations = &Apache::lonnet::auto_courserequest_checks($dom);
 4567:         %titles = &courserequest_titles();
 4568:         $toolregexp = join('|',@usertools);
 4569:         %conditions = &courserequest_conditions();
 4570:     } else {
 4571:         @usertools = ('aboutme','blog','portfolio');
 4572:         %titles = &tool_titles();
 4573:     }
 4574:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 4575:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 4576:     foreach my $key (keys(%env)) {
 4577:         if ($context eq 'requestcourses') {
 4578:             if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
 4579:                 my $item = $1;
 4580:                 my $type = $2;
 4581:                 if ($type =~ /^limit_(.+)/) {
 4582:                     $limithash{$item}{$1} = $env{$key};
 4583:                 } else {
 4584:                     $confhash{$item}{$type} = $env{$key};
 4585:                 }
 4586:             }
 4587:         } else {
 4588:             if ($key =~ /^form\.quota_(.+)$/) {
 4589:                 $confhash{'defaultquota'}{$1} = $env{$key};
 4590:             }
 4591:             if ($key =~ /^form\.\Q$context\E_(.+)$/) {
 4592:                 @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
 4593:             }
 4594:         }
 4595:     }
 4596:     if ($context eq 'requestcourses') {
 4597:         my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
 4598:         @approvalnotify = sort(@approvalnotify);
 4599:         $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
 4600:         if (ref($domconfig{$action}) eq 'HASH') {
 4601:             if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
 4602:                 if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
 4603:                     $changes{'notify'}{'approval'} = 1;
 4604:                 }
 4605:             } else {
 4606:                 if ($domconfig{$action}{'notify'}{'approval'}) {
 4607:                     $changes{'notify'}{'approval'} = 1;
 4608:                 }
 4609:             }
 4610:         } else {
 4611:             if ($domconfig{$action}{'notify'}{'approval'}) {
 4612:                 $changes{'notify'}{'approval'} = 1;
 4613:             }
 4614:         }
 4615:     } else {
 4616:         $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
 4617:     }
 4618:     foreach my $item (@usertools) {
 4619:         foreach my $type (@{$types},'default','_LC_adv') {
 4620:             my $unset; 
 4621:             if ($context eq 'requestcourses') {
 4622:                 $unset = '0';
 4623:                 if ($type eq '_LC_adv') {
 4624:                     $unset = '';
 4625:                 }
 4626:                 if ($confhash{$item}{$type} eq 'autolimit') {
 4627:                     $confhash{$item}{$type} .= '=';
 4628:                     unless ($limithash{$item}{$type} =~ /\D/) {
 4629:                         $confhash{$item}{$type} .= $limithash{$item}{$type};
 4630:                     }
 4631:                 }
 4632:             } else {
 4633:                 if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
 4634:                     $confhash{$item}{$type} = 1;
 4635:                 } else {
 4636:                     $confhash{$item}{$type} = 0;
 4637:                 }
 4638:             }
 4639:             if (ref($domconfig{$action}) eq 'HASH') {
 4640:                 if (ref($domconfig{$action}{$item}) eq 'HASH') {
 4641:                     if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
 4642:                         $changes{$item}{$type} = 1;
 4643:                     }
 4644:                 } else {
 4645:                     if ($context eq 'requestcourses') {
 4646:                         if ($confhash{$item}{$type} ne $unset) {
 4647:                             $changes{$item}{$type} = 1;
 4648:                         }
 4649:                     } else {
 4650:                         if (!$confhash{$item}{$type}) {
 4651:                             $changes{$item}{$type} = 1;
 4652:                         }
 4653:                     }
 4654:                 }
 4655:             } else {
 4656:                 if ($context eq 'requestcourses') {
 4657:                     if ($confhash{$item}{$type} ne $unset) {
 4658:                         $changes{$item}{$type} = 1;
 4659:                     }
 4660:                 } else {
 4661:                     if (!$confhash{$item}{$type}) {
 4662:                         $changes{$item}{$type} = 1;
 4663:                     }
 4664:                 }
 4665:             }
 4666:         }
 4667:     }
 4668:     unless ($context eq 'requestcourses') {
 4669:         if (ref($domconfig{'quotas'}) eq 'HASH') {
 4670:             if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 4671:                 foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
 4672:                     if (exists($confhash{'defaultquota'}{$key})) {
 4673:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
 4674:                             $changes{'defaultquota'}{$key} = 1;
 4675:                         }
 4676:                     } else {
 4677:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
 4678:                     }
 4679:                 }
 4680:             } else {
 4681:                 foreach my $key (keys(%{$domconfig{'quotas'}})) {
 4682:                     if (exists($confhash{'defaultquota'}{$key})) {
 4683:                         if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
 4684:                             $changes{'defaultquota'}{$key} = 1;
 4685:                         }
 4686:                     } else {
 4687:                         $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
 4688:                     }
 4689:                 }
 4690:             }
 4691:         }
 4692:         if (ref($confhash{'defaultquota'}) eq 'HASH') {
 4693:             foreach my $key (keys(%{$confhash{'defaultquota'}})) {
 4694:                 if (ref($domconfig{'quotas'}) eq 'HASH') {
 4695:                     if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
 4696:                         if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
 4697:                             $changes{'defaultquota'}{$key} = 1;
 4698:                         }
 4699:                     } else {
 4700:                         if (!exists($domconfig{'quotas'}{$key})) {
 4701:                             $changes{'defaultquota'}{$key} = 1;
 4702:                         }
 4703:                     }
 4704:                 } else {
 4705:                     $changes{'defaultquota'}{$key} = 1;
 4706:                 }
 4707:             }
 4708:         }
 4709:     }
 4710: 
 4711:     foreach my $key (keys(%confhash)) {
 4712:         $domdefaults{$key} = $confhash{$key};
 4713:     }
 4714:    
 4715:     my %quotahash = (
 4716:                       $action => { %confhash }
 4717:                     );
 4718:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 4719:                                              $dom);
 4720:     if ($putresult eq 'ok') {
 4721:         if (keys(%changes) > 0) {
 4722:             my $cachetime = 24*60*60;
 4723:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 4724: 
 4725:             $resulttext = &mt('Changes made:').'<ul>';
 4726:             unless ($context eq 'requestcourses') {
 4727:                 if (ref($changes{'defaultquota'}) eq 'HASH') {
 4728:                     $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
 4729:                     foreach my $type (@{$types},'default') {
 4730:                         if (defined($changes{'defaultquota'}{$type})) {
 4731:                             my $typetitle = $usertypes->{$type};
 4732:                             if ($type eq 'default') {
 4733:                                 $typetitle = $othertitle;
 4734:                             }
 4735:                             $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
 4736:                         }
 4737:                     }
 4738:                     $resulttext .= '</ul></li>';
 4739:                 }
 4740:             }
 4741:             my %newenv;
 4742:             foreach my $item (@usertools) {
 4743:                 if (ref($changes{$item}) eq 'HASH') {
 4744:                     my $newacc = 
 4745:                         &Apache::lonnet::usertools_access($env{'user.name'},
 4746:                                                           $env{'user.domain'},
 4747:                                                           $item,'reload',$context);
 4748:                     if ($context eq 'requestcourses') {
 4749:                         if ($env{'environment.canrequest.'.$item} ne $newacc) {
 4750:                             $newenv{'environment.canrequest.'.$item} = $newacc;
 4751:                         }
 4752:                     } else {
 4753:                         if ($env{'environment.availabletools.'.$item} ne $newacc) { 
 4754:                             $newenv{'environment.availabletools.'.$item} = $newacc;
 4755:                         }
 4756:                     }
 4757:                     $resulttext .= '<li>'.$titles{$item}.'<ul>';
 4758:                     foreach my $type (@{$types},'default','_LC_adv') {
 4759:                         if ($changes{$item}{$type}) {
 4760:                             my $typetitle = $usertypes->{$type};
 4761:                             if ($type eq 'default') {
 4762:                                 $typetitle = $othertitle;
 4763:                             } elsif ($type eq '_LC_adv') {
 4764:                                 $typetitle = 'LON-CAPA Advanced Users'; 
 4765:                             }
 4766:                             if ($confhash{$item}{$type}) {
 4767:                                 if ($context eq 'requestcourses') {
 4768:                                     my $cond;
 4769:                                     if ($confhash{$item}{$type} =~ /^autolimit=(\d*)$/) {
 4770:                                         if ($1 eq '') {
 4771:                                             $cond = &mt('(Automatic processing of any request).');
 4772:                                         } else {
 4773:                                             $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
 4774:                                         }
 4775:                                     } else { 
 4776:                                         $cond = $conditions{$confhash{$item}{$type}};
 4777:                                     }
 4778:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
 4779:                                 } else {
 4780:                                     $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
 4781:                                 }
 4782:                             } else {
 4783:                                 if ($type eq '_LC_adv') {
 4784:                                     if ($confhash{$item}{$type} eq '0') {
 4785:                                         $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 4786:                                     } else { 
 4787:                                         $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
 4788:                                     }
 4789:                                 } else {
 4790:                                     $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
 4791:                                 }
 4792:                             }
 4793:                         }
 4794:                     }
 4795:                     $resulttext .= '</ul></li>';
 4796:                 }
 4797:             }
 4798:             if ($action eq 'requestcourses') {
 4799:                 if (ref($changes{'notify'}) eq 'HASH') {
 4800:                     if ($changes{'notify'}{'approval'}) {
 4801:                         if (ref($confhash{'notify'}) eq 'HASH') {
 4802:                             if ($confhash{'notify'}{'approval'}) {
 4803:                                 $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
 4804:                             } else {
 4805:                                 $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of course requests requiring approval.').'</li>';
 4806:                             }
 4807:                         }
 4808:                     }
 4809:                 }
 4810:             }
 4811:             $resulttext .= '</ul>';
 4812:             if (keys(%newenv)) {
 4813:                 &Apache::lonnet::appenv(\%newenv);
 4814:             }
 4815:         } else {
 4816:             if ($context eq 'requestcourses') {
 4817:                 $resulttext = &mt('No changes made to rights to request creation of courses.');
 4818:             } else {
 4819:                 $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
 4820:             }
 4821:         }
 4822:     } else {
 4823:         $resulttext = '<span class="LC_error">'.
 4824: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 4825:     }
 4826:     return $resulttext;
 4827: }
 4828: 
 4829: sub modify_autoenroll {
 4830:     my ($dom,%domconfig) = @_;
 4831:     my ($resulttext,%changes);
 4832:     my %currautoenroll;
 4833:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 4834:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 4835:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 4836:         }
 4837:     }
 4838:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 4839:     my %title = ( run => 'Auto-enrollment active',
 4840:                   sender => 'Sender for notification messages',
 4841:                   coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
 4842:     my @offon = ('off','on');
 4843:     my $sender_uname = $env{'form.sender_uname'};
 4844:     my $sender_domain = $env{'form.sender_domain'};
 4845:     if ($sender_domain eq '') {
 4846:         $sender_uname = '';
 4847:     } elsif ($sender_uname eq '') {
 4848:         $sender_domain = '';
 4849:     }
 4850:     my $coowners = $env{'form.autoassign_coowners'};
 4851:     my %autoenrollhash =  (
 4852:                        autoenroll => { 'run' => $env{'form.autoenroll_run'},
 4853:                                        'sender_uname' => $sender_uname,
 4854:                                        'sender_domain' => $sender_domain,
 4855:                                        'co-owners' => $coowners,
 4856:                                 }
 4857:                      );
 4858:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 4859:                                              $dom);
 4860:     if ($putresult eq 'ok') {
 4861:         if (exists($currautoenroll{'run'})) {
 4862:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 4863:                  $changes{'run'} = 1;
 4864:              }
 4865:         } elsif ($autorun) {
 4866:             if ($env{'form.autoenroll_run'} ne '1') {
 4867:                  $changes{'run'} = 1;
 4868:             }
 4869:         }
 4870:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 4871:             $changes{'sender'} = 1;
 4872:         }
 4873:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 4874:             $changes{'sender'} = 1;
 4875:         }
 4876:         if ($currautoenroll{'co-owners'} ne '') {
 4877:             if ($currautoenroll{'co-owners'} ne $coowners) {
 4878:                 $changes{'coowners'} = 1;
 4879:             }
 4880:         } elsif ($coowners) {
 4881:             $changes{'coowners'} = 1;
 4882:         }      
 4883:         if (keys(%changes) > 0) {
 4884:             $resulttext = &mt('Changes made:').'<ul>';
 4885:             if ($changes{'run'}) {
 4886:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 4887:             }
 4888:             if ($changes{'sender'}) {
 4889:                 if ($sender_uname eq '' || $sender_domain eq '') {
 4890:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 4891:                 } else {
 4892:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 4893:                 }
 4894:             }
 4895:             if ($changes{'coowners'}) {
 4896:                 $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
 4897:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 4898:             }
 4899:             $resulttext .= '</ul>';
 4900:         } else {
 4901:             $resulttext = &mt('No changes made to auto-enrollment settings');
 4902:         }
 4903:     } else {
 4904:         $resulttext = '<span class="LC_error">'.
 4905: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 4906:     }
 4907:     return $resulttext;
 4908: }
 4909: 
 4910: sub modify_autoupdate {
 4911:     my ($dom,%domconfig) = @_;
 4912:     my ($resulttext,%currautoupdate,%fields,%changes);
 4913:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 4914:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 4915:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 4916:         }
 4917:     }
 4918:     my @offon = ('off','on');
 4919:     my %title = &Apache::lonlocal::texthash (
 4920:                    run => 'Auto-update:',
 4921:                    classlists => 'Updates to user information in classlists?'
 4922:                 );
 4923:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 4924:     my %fieldtitles = &Apache::lonlocal::texthash (
 4925:                         id => 'Student/Employee ID',
 4926:                         permanentemail => 'E-mail address',
 4927:                         lastname => 'Last Name',
 4928:                         firstname => 'First Name',
 4929:                         middlename => 'Middle Name',
 4930:                         generation => 'Generation',
 4931:                       );
 4932:     my $othertitle = &mt('All users');
 4933:     if (keys(%{$usertypes}) >  0) {
 4934:         $othertitle = &mt('Other users');
 4935:     }
 4936:     foreach my $key (keys(%env)) {
 4937:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 4938:             my ($usertype,$item) = ($1,$2);
 4939:             if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
 4940:                 if ($usertype eq 'default') {   
 4941:                     push(@{$fields{$1}},$2);
 4942:                 } elsif (ref($types) eq 'ARRAY') {
 4943:                     if (grep(/^\Q$usertype\E$/,@{$types})) {
 4944:                         push(@{$fields{$1}},$2);
 4945:                     }
 4946:                 }
 4947:             }
 4948:         }
 4949:     }
 4950:     my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
 4951:     @lockablenames = sort(@lockablenames);
 4952:     if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
 4953:         my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 4954:         if (@changed) {
 4955:             $changes{'lockablenames'} = 1;
 4956:         }
 4957:     } else {
 4958:         if (@lockablenames) {
 4959:             $changes{'lockablenames'} = 1;
 4960:         }
 4961:     }
 4962:     my %updatehash = (
 4963:                       autoupdate => { run => $env{'form.autoupdate_run'},
 4964:                                       classlists => $env{'form.classlists'},
 4965:                                       fields => {%fields},
 4966:                                       lockablenames => \@lockablenames,
 4967:                                     }
 4968:                      );
 4969:     foreach my $key (keys(%currautoupdate)) {
 4970:         if (($key eq 'run') || ($key eq 'classlists')) {
 4971:             if (exists($updatehash{autoupdate}{$key})) {
 4972:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 4973:                     $changes{$key} = 1;
 4974:                 }
 4975:             }
 4976:         } elsif ($key eq 'fields') {
 4977:             if (ref($currautoupdate{$key}) eq 'HASH') {
 4978:                 foreach my $item (@{$types},'default') {
 4979:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 4980:                         my $change = 0;
 4981:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 4982:                             if (!exists($fields{$item})) {
 4983:                                 $change = 1;
 4984:                                 last;
 4985:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 4986:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
 4987:                                     $change = 1;
 4988:                                     last;
 4989:                                 }
 4990:                             }
 4991:                         }
 4992:                         if ($change) {
 4993:                             push(@{$changes{$key}},$item);
 4994:                         }
 4995:                     } 
 4996:                 }
 4997:             }
 4998:         } elsif ($key eq 'lockablenames') {
 4999:             if (ref($currautoupdate{$key}) eq 'ARRAY') {
 5000:                 my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
 5001:                 if (@changed) {
 5002:                     $changes{'lockablenames'} = 1;
 5003:                 }
 5004:             } else {
 5005:                 if (@lockablenames) {
 5006:                     $changes{'lockablenames'} = 1;
 5007:                 }
 5008:             }
 5009:         }
 5010:     }
 5011:     unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
 5012:         if (@lockablenames) {
 5013:             $changes{'lockablenames'} = 1;
 5014:         }
 5015:     }
 5016:     foreach my $item (@{$types},'default') {
 5017:         if (defined($fields{$item})) {
 5018:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
 5019:                 if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
 5020:                     my $change = 0;
 5021:                     if (ref($fields{$item}) eq 'ARRAY') {
 5022:                         foreach my $type (@{$fields{$item}}) {
 5023:                             if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
 5024:                                 $change = 1;
 5025:                                 last;
 5026:                             }
 5027:                         }
 5028:                     }
 5029:                     if ($change) {
 5030:                         push(@{$changes{'fields'}},$item);
 5031:                     }
 5032:                 } else {
 5033:                     push(@{$changes{'fields'}},$item);
 5034:                 }
 5035:             } else {
 5036:                 push(@{$changes{'fields'}},$item);
 5037:             }
 5038:         }
 5039:     }
 5040:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 5041:                                              $dom);
 5042:     if ($putresult eq 'ok') {
 5043:         if (keys(%changes) > 0) {
 5044:             $resulttext = &mt('Changes made:').'<ul>';
 5045:             foreach my $key (sort(keys(%changes))) {
 5046:                 if ($key eq 'lockablenames') {
 5047:                     $resulttext .= '<li>';
 5048:                     if (@lockablenames) {
 5049:                         $usertypes->{'default'} = $othertitle;
 5050:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
 5051:                                    join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
 5052:                     } else {
 5053:                         $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
 5054:                     }
 5055:                     $resulttext .= '</li>';
 5056:                 } elsif (ref($changes{$key}) eq 'ARRAY') {
 5057:                     foreach my $item (@{$changes{$key}}) {
 5058:                         my @newvalues;
 5059:                         foreach my $type (@{$fields{$item}}) {
 5060:                             push(@newvalues,$fieldtitles{$type});
 5061:                         }
 5062:                         my $newvaluestr;
 5063:                         if (@newvalues > 0) {
 5064:                             $newvaluestr = join(', ',@newvalues);
 5065:                         } else {
 5066:                             $newvaluestr = &mt('none');
 5067:                         }
 5068:                         if ($item eq 'default') {
 5069:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
 5070:                         } else {
 5071:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
 5072:                         }
 5073:                     }
 5074:                 } else {
 5075:                     my $newvalue;
 5076:                     if ($key eq 'run') {
 5077:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 5078:                     } else {
 5079:                         $newvalue = $offon[$env{'form.'.$key}];
 5080:                     }
 5081:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 5082:                 }
 5083:             }
 5084:             $resulttext .= '</ul>';
 5085:         } else {
 5086:             $resulttext = &mt('No changes made to autoupdates');
 5087:         }
 5088:     } else {
 5089:         $resulttext = '<span class="LC_error">'.
 5090: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 5091:     }
 5092:     return $resulttext;
 5093: }
 5094: 
 5095: sub modify_autocreate {
 5096:     my ($dom,%domconfig) = @_;
 5097:     my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
 5098:     if (ref($domconfig{'autocreate'}) eq 'HASH') {
 5099:         foreach my $key (keys(%{$domconfig{'autocreate'}})) {
 5100:             $currautocreate{$key} = $domconfig{'autocreate'}{$key};
 5101:         }
 5102:     }
 5103:     my %title= ( xml => 'Auto-creation of courses in XML course description files',
 5104:                  req => 'Auto-creation of validated requests for official courses',
 5105:                  xmldc => 'Identity of course creator of courses from XML files',
 5106:                );
 5107:     my @types = ('xml','req');
 5108:     foreach my $item (@types) {
 5109:         $newvals{$item} = $env{'form.autocreate_'.$item};
 5110:         $newvals{$item} =~ s/\D//g;
 5111:         $newvals{$item} = 0 if ($newvals{$item} eq '');
 5112:     }
 5113:     $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
 5114:     my %domcoords = &get_active_dcs($dom);
 5115:     unless (exists($domcoords{$newvals{'xmldc'}})) {
 5116:         $newvals{'xmldc'} = '';
 5117:     } 
 5118:     %autocreatehash =  (
 5119:                         autocreate => { xml => $newvals{'xml'},
 5120:                                         req => $newvals{'req'},
 5121:                                       }
 5122:                        );
 5123:     if ($newvals{'xmldc'} ne '') {
 5124:         $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
 5125:     }
 5126:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
 5127:                                              $dom);
 5128:     if ($putresult eq 'ok') {
 5129:         my @items = @types;
 5130:         if ($newvals{'xml'}) {
 5131:             push(@items,'xmldc');
 5132:         }
 5133:         foreach my $item (@items) {
 5134:             if (exists($currautocreate{$item})) {
 5135:                 if ($currautocreate{$item} ne $newvals{$item}) {
 5136:                     $changes{$item} = 1;
 5137:                 }
 5138:             } elsif ($newvals{$item}) {
 5139:                 $changes{$item} = 1;
 5140:             }
 5141:         }
 5142:         if (keys(%changes) > 0) {
 5143:             my @offon = ('off','on'); 
 5144:             $resulttext = &mt('Changes made:').'<ul>';
 5145:             foreach my $item (@types) {
 5146:                 if ($changes{$item}) {
 5147:                     my $newtxt = $offon[$newvals{$item}];
 5148:                     $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
 5149:                 }
 5150:             }
 5151:             if ($changes{'xmldc'}) {
 5152:                 my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
 5153:                 my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
 5154:                 $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>'; 
 5155:             }
 5156:             $resulttext .= '</ul>';
 5157:         } else {
 5158:             $resulttext = &mt('No changes made to auto-creation settings');
 5159:         }
 5160:     } else {
 5161:         $resulttext = '<span class="LC_error">'.
 5162:             &mt('An error occurred: [_1]',$putresult).'</span>';
 5163:     }
 5164:     return $resulttext;
 5165: }
 5166: 
 5167: sub modify_directorysrch {
 5168:     my ($dom,%domconfig) = @_;
 5169:     my ($resulttext,%changes);
 5170:     my %currdirsrch;
 5171:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
 5172:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
 5173:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
 5174:         }
 5175:     }
 5176:     my %title = ( available => 'Directory search available',
 5177:                   localonly => 'Other domains can search',
 5178:                   searchby => 'Search types',
 5179:                   searchtypes => 'Search latitude');
 5180:     my @offon = ('off','on');
 5181:     my @otherdoms = ('Yes','No');
 5182: 
 5183:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
 5184:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
 5185:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
 5186: 
 5187:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 5188:     if (keys(%{$usertypes}) == 0) {
 5189:         @cansearch = ('default');
 5190:     } else {
 5191:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
 5192:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
 5193:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
 5194:                     push(@{$changes{'cansearch'}},$type);
 5195:                 }
 5196:             }
 5197:             foreach my $type (@cansearch) {
 5198:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
 5199:                     push(@{$changes{'cansearch'}},$type);
 5200:                 }
 5201:             }
 5202:         } else {
 5203:             push(@{$changes{'cansearch'}},@cansearch);
 5204:         }
 5205:     }
 5206: 
 5207:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
 5208:         foreach my $by (@{$currdirsrch{'searchby'}}) {
 5209:             if (!grep(/^\Q$by\E$/,@searchby)) {
 5210:                 push(@{$changes{'searchby'}},$by);
 5211:             }
 5212:         }
 5213:         foreach my $by (@searchby) {
 5214:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
 5215:                 push(@{$changes{'searchby'}},$by);
 5216:             }
 5217:         }
 5218:     } else {
 5219:         push(@{$changes{'searchby'}},@searchby);
 5220:     }
 5221: 
 5222:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
 5223:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
 5224:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
 5225:                 push(@{$changes{'searchtypes'}},$type);
 5226:             }
 5227:         }
 5228:         foreach my $type (@searchtypes) {
 5229:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
 5230:                 push(@{$changes{'searchtypes'}},$type);
 5231:             }
 5232:         }
 5233:     } else {
 5234:         if (exists($currdirsrch{'searchtypes'})) {
 5235:             foreach my $type (@searchtypes) {  
 5236:                 if ($type ne $currdirsrch{'searchtypes'}) { 
 5237:                     push(@{$changes{'searchtypes'}},$type);
 5238:                 }
 5239:             }
 5240:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
 5241:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
 5242:             }   
 5243:         } else {
 5244:             push(@{$changes{'searchtypes'}},@searchtypes); 
 5245:         }
 5246:     }
 5247: 
 5248:     my %dirsrch_hash =  (
 5249:             directorysrch => { available => $env{'form.dirsrch_available'},
 5250:                                cansearch => \@cansearch,
 5251:                                localonly => $env{'form.dirsrch_localonly'},
 5252:                                searchby => \@searchby,
 5253:                                searchtypes => \@searchtypes,
 5254:                              }
 5255:             );
 5256:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
 5257:                                              $dom);
 5258:     if ($putresult eq 'ok') {
 5259:         if (exists($currdirsrch{'available'})) {
 5260:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
 5261:                  $changes{'available'} = 1;
 5262:              }
 5263:         } else {
 5264:             if ($env{'form.dirsrch_available'} eq '1') {
 5265:                 $changes{'available'} = 1;
 5266:             }
 5267:         }
 5268:         if (exists($currdirsrch{'localonly'})) {
 5269:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
 5270:                  $changes{'localonly'} = 1;
 5271:              }
 5272:         } else {
 5273:             if ($env{'form.dirsrch_localonly'} eq '1') {
 5274:                 $changes{'localonly'} = 1;
 5275:             }
 5276:         }
 5277:         if (keys(%changes) > 0) {
 5278:             $resulttext = &mt('Changes made:').'<ul>';
 5279:             if ($changes{'available'}) {
 5280:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
 5281:             }
 5282:             if ($changes{'localonly'}) {
 5283:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
 5284:             }
 5285: 
 5286:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
 5287:                 my $chgtext;
 5288:                 if (ref($usertypes) eq 'HASH') {
 5289:                     if (keys(%{$usertypes}) > 0) {
 5290:                         foreach my $type (@{$types}) {
 5291:                             if (grep(/^\Q$type\E$/,@cansearch)) {
 5292:                                 $chgtext .= $usertypes->{$type}.'; ';
 5293:                             }
 5294:                         }
 5295:                         if (grep(/^default$/,@cansearch)) {
 5296:                             $chgtext .= $othertitle;
 5297:                         } else {
 5298:                             $chgtext =~ s/\; $//;
 5299:                         }
 5300:                         $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>';
 5301:                     }
 5302:                 }
 5303:             }
 5304:             if (ref($changes{'searchby'}) eq 'ARRAY') {
 5305:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
 5306:                 my $chgtext;
 5307:                 foreach my $type (@{$titleorder}) {
 5308:                     if (grep(/^\Q$type\E$/,@searchby)) {
 5309:                         if (defined($searchtitles->{$type})) {
 5310:                             $chgtext .= $searchtitles->{$type}.'; ';
 5311:                         }
 5312:                     }
 5313:                 }
 5314:                 $chgtext =~ s/\; $//;
 5315:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
 5316:             }
 5317:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
 5318:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
 5319:                 my $chgtext;
 5320:                 foreach my $type (@{$srchtypeorder}) {
 5321:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
 5322:                         if (defined($srchtypes_desc->{$type})) {
 5323:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
 5324:                         }
 5325:                     }
 5326:                 }
 5327:                 $chgtext =~ s/\; $//;
 5328:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
 5329:             }
 5330:             $resulttext .= '</ul>';
 5331:         } else {
 5332:             $resulttext = &mt('No changes made to institution directory search settings');
 5333:         }
 5334:     } else {
 5335:         $resulttext = '<span class="LC_error">'.
 5336:                       &mt('An error occurred: [_1]',$putresult).'</span>';
 5337:     }
 5338:     return $resulttext;
 5339: }
 5340: 
 5341: sub modify_contacts {
 5342:     my ($dom,%domconfig) = @_;
 5343:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
 5344:     if (ref($domconfig{'contacts'}) eq 'HASH') {
 5345:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
 5346:             $currsetting{$key} = $domconfig{'contacts'}{$key};
 5347:         }
 5348:     }
 5349:     my (%others,%to,%bcc);
 5350:     my @contacts = ('supportemail','adminemail');
 5351:     my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
 5352:                     'requestsmail');
 5353:     foreach my $type (@mailings) {
 5354:         @{$newsetting{$type}} = 
 5355:             &Apache::loncommon::get_env_multiple('form.'.$type);
 5356:         foreach my $item (@contacts) {
 5357:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
 5358:                 $contacts_hash{contacts}{$type}{$item} = 1;
 5359:             } else {
 5360:                 $contacts_hash{contacts}{$type}{$item} = 0;
 5361:             }
 5362:         }  
 5363:         $others{$type} = $env{'form.'.$type.'_others'};
 5364:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
 5365:         if ($type eq 'helpdeskmail') {
 5366:             $bcc{$type} = $env{'form.'.$type.'_bcc'};
 5367:             $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
 5368:         }
 5369:     }
 5370:     foreach my $item (@contacts) {
 5371:         $to{$item} = $env{'form.'.$item};
 5372:         $contacts_hash{'contacts'}{$item} = $to{$item};
 5373:     }
 5374:     if (keys(%currsetting) > 0) {
 5375:         foreach my $item (@contacts) {
 5376:             if ($to{$item} ne $currsetting{$item}) {
 5377:                 $changes{$item} = 1;
 5378:             }
 5379:         }
 5380:         foreach my $type (@mailings) {
 5381:             foreach my $item (@contacts) {
 5382:                 if (ref($currsetting{$type}) eq 'HASH') {
 5383:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
 5384:                         push(@{$changes{$type}},$item);
 5385:                     }
 5386:                 } else {
 5387:                     push(@{$changes{$type}},@{$newsetting{$type}});
 5388:                 }
 5389:             }
 5390:             if ($others{$type} ne $currsetting{$type}{'others'}) {
 5391:                 push(@{$changes{$type}},'others');
 5392:             }
 5393:             if ($type eq 'helpdeskmail') {   
 5394:                 if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
 5395:                     push(@{$changes{$type}},'bcc'); 
 5396:                 }
 5397:             }
 5398:         }
 5399:     } else {
 5400:         my %default;
 5401:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 5402:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 5403:         $default{'errormail'} = 'adminemail';
 5404:         $default{'packagesmail'} = 'adminemail';
 5405:         $default{'helpdeskmail'} = 'supportemail';
 5406:         $default{'lonstatusmail'} = 'adminemail';
 5407:         $default{'requestsmail'} = 'adminemail';
 5408:         foreach my $item (@contacts) {
 5409:            if ($to{$item} ne $default{$item}) {
 5410:               $changes{$item} = 1;
 5411:            } 
 5412:         }
 5413:         foreach my $type (@mailings) {
 5414:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
 5415:                
 5416:                 push(@{$changes{$type}},@{$newsetting{$type}});
 5417:             }
 5418:             if ($others{$type} ne '') {
 5419:                 push(@{$changes{$type}},'others');
 5420:             }
 5421:             if ($type eq 'helpdeskmail') {
 5422:                 if ($bcc{$type} ne '') {
 5423:                     push(@{$changes{$type}},'bcc');
 5424:                 }
 5425:             }
 5426:         }
 5427:     }
 5428:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
 5429:                                              $dom);
 5430:     if ($putresult eq 'ok') {
 5431:         if (keys(%changes) > 0) {
 5432:             my ($titles,$short_titles)  = &contact_titles();
 5433:             $resulttext = &mt('Changes made:').'<ul>';
 5434:             foreach my $item (@contacts) {
 5435:                 if ($changes{$item}) {
 5436:                     $resulttext .= '<li>'.$titles->{$item}.
 5437:                                     &mt(' set to: ').
 5438:                                     '<span class="LC_cusr_emph">'.
 5439:                                     $to{$item}.'</span></li>';
 5440:                 }
 5441:             }
 5442:             foreach my $type (@mailings) {
 5443:                 if (ref($changes{$type}) eq 'ARRAY') {
 5444:                     $resulttext .= '<li>'.$titles->{$type}.': ';
 5445:                     my @text;
 5446:                     foreach my $item (@{$newsetting{$type}}) {
 5447:                         push(@text,$short_titles->{$item});
 5448:                     }
 5449:                     if ($others{$type} ne '') {
 5450:                         push(@text,$others{$type});
 5451:                     }
 5452:                     $resulttext .= '<span class="LC_cusr_emph">'.
 5453:                                    join(', ',@text).'</span>';
 5454:                     if ($type eq 'helpdeskmail') {
 5455:                         if ($bcc{$type} ne '') {
 5456:                             $resulttext .= '&nbsp;'.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
 5457:                         }
 5458:                     }
 5459:                     $resulttext .= '</li>';
 5460:                 }
 5461:             }
 5462:             $resulttext .= '</ul>';
 5463:         } else {
 5464:             $resulttext = &mt('No changes made to contact information');
 5465:         }
 5466:     } else {
 5467:         $resulttext = '<span class="LC_error">'.
 5468:             &mt('An error occurred: [_1].',$putresult).'</span>';
 5469:     }
 5470:     return $resulttext;
 5471: }
 5472: 
 5473: sub modify_usercreation {
 5474:     my ($dom,%domconfig) = @_;
 5475:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
 5476:     my $warningmsg;
 5477:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 5478:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 5479:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 5480:         }
 5481:     }
 5482:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
 5483:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
 5484:     my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
 5485:     my @contexts = ('author','course','requestcrs','selfcreate');
 5486:     foreach my $item(@contexts) {
 5487:         if ($item eq 'selfcreate') {
 5488:             @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
 5489:             my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 5490:             if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
 5491:                 if (ref($cancreate{$item}) eq 'ARRAY') { 
 5492:                     if (grep(/^login$/,@{$cancreate{$item}})) {
 5493:                         $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.');   
 5494:                     }
 5495:                 }
 5496:             }
 5497:         } else {
 5498:             $cancreate{$item} = $env{'form.can_createuser_'.$item};
 5499:         }
 5500:     }
 5501:     my ($othertitle,$usertypes,$types) = 
 5502:         &Apache::loncommon::sorted_inst_types($dom);
 5503:     if (ref($types) eq 'ARRAY') {
 5504:         if (@{$types} > 0) {
 5505:             @{$cancreate{'statustocreate'}} = 
 5506:                 &Apache::loncommon::get_env_multiple('form.statustocreate');
 5507:         } else {
 5508:             @{$cancreate{'statustocreate'}} = ();
 5509:         }
 5510:         push(@contexts,'statustocreate');
 5511:     }
 5512:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 5513:         foreach my $item (@contexts) {
 5514:             if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
 5515:                 if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 5516:                     foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
 5517:                         if (ref($cancreate{$item}) eq 'ARRAY') {
 5518:                             if (!grep(/^$curr$/,@{$cancreate{$item}})) {
 5519:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5520:                                     push(@{$changes{'cancreate'}},$item);
 5521:                                 }
 5522:                             }
 5523:                         }
 5524:                     }
 5525:                 } else {
 5526:                     if ($curr_usercreation{'cancreate'}{$item} eq '') {
 5527:                         if (@{$cancreate{$item}} > 0) {
 5528:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5529:                                 push(@{$changes{'cancreate'}},$item);
 5530:                             }
 5531:                         }
 5532:                     } else {
 5533:                         if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
 5534:                             if (@{$cancreate{$item}} < 3) {
 5535:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5536:                                     push(@{$changes{'cancreate'}},$item);
 5537:                                 }
 5538:                             }
 5539:                         } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
 5540:                             if (@{$cancreate{$item}} > 0) {
 5541:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5542:                                     push(@{$changes{'cancreate'}},$item);
 5543:                                 }
 5544:                             }
 5545:                         } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
 5546:                             if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5547:                                 push(@{$changes{'cancreate'}},$item);
 5548:                             }
 5549:                         }
 5550:                     }
 5551:                 }
 5552:                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5553:                     foreach my $type (@{$cancreate{$item}}) {
 5554:                         if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
 5555:                             if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
 5556:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5557:                                     push(@{$changes{'cancreate'}},$item);
 5558:                                 }
 5559:                             }
 5560:                         } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
 5561:                                  ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
 5562:                             if ($curr_usercreation{'cancreate'}{$item} ne $type) {
 5563:                                 if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
 5564:                                     push(@{$changes{'cancreate'}},$item);
 5565:                                 }
 5566:                             }
 5567:                         }
 5568:                     }
 5569:                 }
 5570:             } else {
 5571:                 if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
 5572:                     push(@{$changes{'cancreate'}},$item);
 5573:                 }
 5574:             }
 5575:         }
 5576:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
 5577:         foreach my $item (@contexts) {
 5578:             if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
 5579:                 if ($cancreate{$item} ne 'any') {
 5580:                     push(@{$changes{'cancreate'}},$item);
 5581:                 }
 5582:             } else {
 5583:                 if ($cancreate{$item} ne 'none') {
 5584:                     push(@{$changes{'cancreate'}},$item);
 5585:                 }
 5586:             }
 5587:         }
 5588:     } else {
 5589:         foreach my $item (@contexts)  {
 5590:             push(@{$changes{'cancreate'}},$item);
 5591:         }
 5592:     }
 5593: 
 5594:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
 5595:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
 5596:             if (!grep(/^\Q$type\E$/,@username_rule)) {
 5597:                 push(@{$changes{'username_rule'}},$type);
 5598:             }
 5599:         }
 5600:         foreach my $type (@username_rule) {
 5601:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
 5602:                 push(@{$changes{'username_rule'}},$type);
 5603:             }
 5604:         }
 5605:     } else {
 5606:         push(@{$changes{'username_rule'}},@username_rule);
 5607:     }
 5608: 
 5609:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
 5610:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
 5611:             if (!grep(/^\Q$type\E$/,@id_rule)) {
 5612:                 push(@{$changes{'id_rule'}},$type);
 5613:             }
 5614:         }
 5615:         foreach my $type (@id_rule) {
 5616:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
 5617:                 push(@{$changes{'id_rule'}},$type);
 5618:             }
 5619:         }
 5620:     } else {
 5621:         push(@{$changes{'id_rule'}},@id_rule);
 5622:     }
 5623: 
 5624:     if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
 5625:         foreach my $type (@{$curr_usercreation{'email_rule'}}) {
 5626:             if (!grep(/^\Q$type\E$/,@email_rule)) {
 5627:                 push(@{$changes{'email_rule'}},$type);
 5628:             }
 5629:         }
 5630:         foreach my $type (@email_rule) {
 5631:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
 5632:                 push(@{$changes{'email_rule'}},$type);
 5633:             }
 5634:         }
 5635:     } else {
 5636:         push(@{$changes{'email_rule'}},@email_rule);
 5637:     }
 5638: 
 5639:     my @authen_contexts = ('author','course','domain');
 5640:     my @authtypes = ('int','krb4','krb5','loc');
 5641:     my %authhash;
 5642:     foreach my $item (@authen_contexts) {
 5643:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
 5644:         foreach my $auth (@authtypes) {
 5645:             if (grep(/^\Q$auth\E$/,@authallowed)) {
 5646:                 $authhash{$item}{$auth} = 1;
 5647:             } else {
 5648:                 $authhash{$item}{$auth} = 0;
 5649:             }
 5650:         }
 5651:     }
 5652:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
 5653:         foreach my $item (@authen_contexts) {
 5654:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
 5655:                 foreach my $auth (@authtypes) {
 5656:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
 5657:                         push(@{$changes{'authtypes'}},$item);
 5658:                         last;
 5659:                     }
 5660:                 }
 5661:             }
 5662:         }
 5663:     } else {
 5664:         foreach my $item (@authen_contexts) {
 5665:             push(@{$changes{'authtypes'}},$item);
 5666:         }
 5667:     }
 5668: 
 5669:     my %usercreation_hash =  (
 5670:             usercreation => {
 5671:                               cancreate     => \%cancreate,
 5672:                               username_rule => \@username_rule,
 5673:                               id_rule       => \@id_rule,
 5674:                               email_rule    => \@email_rule,
 5675:                               authtypes     => \%authhash,
 5676:                             }
 5677:             );
 5678: 
 5679:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
 5680:                                              $dom);
 5681: 
 5682:     my %selfcreatetypes = (
 5683:                              sso   => 'users authenticated by institutional single sign on',
 5684:                              login => 'users authenticated by institutional log-in',
 5685:                              email => 'users who provide a valid e-mail address for use as the username',
 5686:                           );
 5687:     if ($putresult eq 'ok') {
 5688:         if (keys(%changes) > 0) {
 5689:             $resulttext = &mt('Changes made:').'<ul>';
 5690:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 5691:                 my %lt = &usercreation_types();
 5692:                 foreach my $type (@{$changes{'cancreate'}}) {
 5693:                     my $chgtext;
 5694:                     unless ($type eq 'statustocreate') {
 5695:                         $chgtext = $lt{$type}.', ';
 5696:                     }
 5697:                     if ($type eq 'selfcreate') {
 5698:                         if (@{$cancreate{$type}} == 0) {
 5699:                             $chgtext .= &mt('creation of a new user account is not permitted.');
 5700:                         } else {
 5701:                             $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
 5702:                             foreach my $case (@{$cancreate{$type}}) {
 5703:                                 $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
 5704:                             }
 5705:                             $chgtext .= '</ul>';
 5706:                             if (ref($cancreate{$type}) eq 'ARRAY') {
 5707:                                 if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
 5708:                                     if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
 5709:                                         if (@{$cancreate{'statustocreate'}} == 0) {
 5710:                                             $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
 5711:                                         }
 5712:                                     }
 5713:                                 }
 5714:                             }
 5715:                         }
 5716:                     } elsif ($type eq 'statustocreate') {
 5717:                         if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
 5718:                             (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
 5719:                             if (@{$cancreate{'selfcreate'}} > 0) {
 5720:                                 if (@{$cancreate{'statustocreate'}} == 0) {
 5721: 
 5722:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
 5723:                                     if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
 5724:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
 5725:                                     } 
 5726:                                 } elsif (ref($usertypes) eq 'HASH') {
 5727:                                     if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 5728:                                         $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
 5729:                                     } else {
 5730:                                         $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
 5731:                                     }
 5732:                                     $chgtext .= '<ul>';
 5733:                                     foreach my $case (@{$cancreate{$type}}) {
 5734:                                         if ($case eq 'default') {
 5735:                                             $chgtext .= '<li>'.$othertitle.'</li>';
 5736:                                         } else {
 5737:                                             $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
 5738:                                         }
 5739:                                     }
 5740:                                     $chgtext .= '</ul>';
 5741:                                     if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
 5742:                                         $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
 5743:                                     }
 5744:                                 }
 5745:                             } else {
 5746:                                 if (@{$cancreate{$type}} == 0) {
 5747:                                     $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
 5748:                                 } else {
 5749:                                     $chgtext .= &mt('Although institutional affiliations permitted to create accounts were changed, self creation of accounts is not currently permitted for any authentication types.');
 5750:                                 }
 5751:                             }
 5752:                         }
 5753:                     } else {
 5754:                         if ($cancreate{$type} eq 'none') {
 5755:                             $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
 5756:                         } elsif ($cancreate{$type} eq 'any') {
 5757:                             $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
 5758:                         } elsif ($cancreate{$type} eq 'official') {
 5759:                             $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
 5760:                         } elsif ($cancreate{$type} eq 'unofficial') {
 5761:                             $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
 5762:                         }
 5763:                     }
 5764:                     $resulttext .= '<li>'.$chgtext.'</li>';
 5765:                 }
 5766:             }
 5767:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
 5768:                 my ($rules,$ruleorder) = 
 5769:                     &Apache::lonnet::inst_userrules($dom,'username');
 5770:                 my $chgtext = '<ul>';
 5771:                 foreach my $type (@username_rule) {
 5772:                     if (ref($rules->{$type}) eq 'HASH') {
 5773:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
 5774:                     }
 5775:                 }
 5776:                 $chgtext .= '</ul>';
 5777:                 if (@username_rule > 0) {
 5778:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
 5779:                 } else {
 5780:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
 5781:                 }
 5782:             }
 5783:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
 5784:                 my ($idrules,$idruleorder) = 
 5785:                     &Apache::lonnet::inst_userrules($dom,'id');
 5786:                 my $chgtext = '<ul>';
 5787:                 foreach my $type (@id_rule) {
 5788:                     if (ref($idrules->{$type}) eq 'HASH') {
 5789:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
 5790:                     }
 5791:                 }
 5792:                 $chgtext .= '</ul>';
 5793:                 if (@id_rule > 0) {
 5794:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
 5795:                 } else {
 5796:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
 5797:                 }
 5798:             }
 5799:             if (ref($changes{'email_rule'}) eq 'ARRAY') {
 5800:                 my ($emailrules,$emailruleorder) =
 5801:                     &Apache::lonnet::inst_userrules($dom,'email');
 5802:                 my $chgtext = '<ul>';
 5803:                 foreach my $type (@email_rule) {
 5804:                     if (ref($emailrules->{$type}) eq 'HASH') {
 5805:                         $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
 5806:                     }
 5807:                 }
 5808:                 $chgtext .= '</ul>';
 5809:                 if (@email_rule > 0) {
 5810:                     $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
 5811:                 } else {
 5812:                     $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
 5813:                 }
 5814:             }
 5815: 
 5816:             my %authname = &authtype_names();
 5817:             my %context_title = &context_names();
 5818:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
 5819:                 my $chgtext = '<ul>';
 5820:                 foreach my $type (@{$changes{'authtypes'}}) {
 5821:                     my @allowed;
 5822:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
 5823:                     foreach my $auth (@authtypes) {
 5824:                         if ($authhash{$type}{$auth}) {
 5825:                             push(@allowed,$authname{$auth});
 5826:                         }
 5827:                     }
 5828:                     if (@allowed > 0) {
 5829:                         $chgtext .= join(', ',@allowed).'</li>';
 5830:                     } else {
 5831:                         $chgtext .= &mt('none').'</li>';
 5832:                     }
 5833:                 }
 5834:                 $chgtext .= '</ul>';
 5835:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
 5836:                 $resulttext .= '</li>';
 5837:             }
 5838:             $resulttext .= '</ul>';
 5839:         } else {
 5840:             $resulttext = &mt('No changes made to user creation settings');
 5841:         }
 5842:     } else {
 5843:         $resulttext = '<span class="LC_error">'.
 5844:             &mt('An error occurred: [_1]',$putresult).'</span>';
 5845:     }
 5846:     if ($warningmsg ne '') {
 5847:         $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
 5848:     }
 5849:     return $resulttext;
 5850: }
 5851: 
 5852: sub modify_usermodification {
 5853:     my ($dom,%domconfig) = @_;
 5854:     my ($resulttext,%curr_usermodification,%changes);
 5855:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 5856:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 5857:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
 5858:         }
 5859:     }
 5860:     my @contexts = ('author','course','selfcreate');
 5861:     my %context_title = (
 5862:                            author => 'In author context',
 5863:                            course => 'In course context',
 5864:                            selfcreate => 'When self creating account', 
 5865:                         );
 5866:     my @fields = ('lastname','firstname','middlename','generation',
 5867:                   'permanentemail','id');
 5868:     my %roles = (
 5869:                   author => ['ca','aa'],
 5870:                   course => ['st','ep','ta','in','cr'],
 5871:                 );
 5872:     my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
 5873:     if (ref($types) eq 'ARRAY') {
 5874:         push(@{$types},'default');
 5875:         $usertypes->{'default'} = $othertitle;
 5876:     }
 5877:     $roles{'selfcreate'} = $types;  
 5878:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 5879:     my %modifyhash;
 5880:     foreach my $context (@contexts) {
 5881:         foreach my $role (@{$roles{$context}}) {
 5882:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
 5883:             foreach my $item (@fields) {
 5884:                 if (grep(/^\Q$item\E$/,@modifiable)) {
 5885:                     $modifyhash{$context}{$role}{$item} = 1;
 5886:                 } else {
 5887:                     $modifyhash{$context}{$role}{$item} = 0;
 5888:                 }
 5889:             }
 5890:         }
 5891:         if (ref($curr_usermodification{$context}) eq 'HASH') {
 5892:             foreach my $role (@{$roles{$context}}) {
 5893:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
 5894:                     foreach my $field (@fields) {
 5895:                         if ($modifyhash{$context}{$role}{$field} ne 
 5896:                                 $curr_usermodification{$context}{$role}{$field}) {
 5897:                             push(@{$changes{$context}},$role);
 5898:                             last;
 5899:                         }
 5900:                     }
 5901:                 }
 5902:             }
 5903:         } else {
 5904:             foreach my $context (@contexts) {
 5905:                 foreach my $role (@{$roles{$context}}) {
 5906:                     push(@{$changes{$context}},$role);
 5907:                 }
 5908:             }
 5909:         }
 5910:     }
 5911:     my %usermodification_hash =  (
 5912:                                    usermodification => \%modifyhash,
 5913:                                  );
 5914:     my $putresult = &Apache::lonnet::put_dom('configuration',
 5915:                                              \%usermodification_hash,$dom);
 5916:     if ($putresult eq 'ok') {
 5917:         if (keys(%changes) > 0) {
 5918:             $resulttext = &mt('Changes made: ').'<ul>';
 5919:             foreach my $context (@contexts) {
 5920:                 if (ref($changes{$context}) eq 'ARRAY') {
 5921:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
 5922:                     if (ref($changes{$context}) eq 'ARRAY') {
 5923:                         foreach my $role (@{$changes{$context}}) {
 5924:                             my $rolename;
 5925:                             if ($context eq 'selfcreate') {
 5926:                                 $rolename = $role;
 5927:                                 if (ref($usertypes) eq 'HASH') {
 5928:                                     if ($usertypes->{$role} ne '') {
 5929:                                         $rolename = $usertypes->{$role};
 5930:                                     }
 5931:                                 }
 5932:                             } else {
 5933:                                 if ($role eq 'cr') {
 5934:                                     $rolename = &mt('Custom');
 5935:                                 } else {
 5936:                                     $rolename = &Apache::lonnet::plaintext($role);
 5937:                                 }
 5938:                             }
 5939:                             my @modifiable;
 5940:                             if ($context eq 'selfcreate') {
 5941:                                 $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): ');
 5942:                             } else {
 5943:                                 $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
 5944:                             }
 5945:                             foreach my $field (@fields) {
 5946:                                 if ($modifyhash{$context}{$role}{$field}) {
 5947:                                     push(@modifiable,$fieldtitles{$field});
 5948:                                 }
 5949:                             }
 5950:                             if (@modifiable > 0) {
 5951:                                 $resulttext .= join(', ',@modifiable);
 5952:                             } else {
 5953:                                 $resulttext .= &mt('none'); 
 5954:                             }
 5955:                             $resulttext .= '</li>';
 5956:                         }
 5957:                         $resulttext .= '</ul></li>';
 5958:                     }
 5959:                 }
 5960:             }
 5961:             $resulttext .= '</ul>';
 5962:         } else {
 5963:             $resulttext = &mt('No changes made to user modification settings');
 5964:         }
 5965:     } else {
 5966:         $resulttext = '<span class="LC_error">'.
 5967:             &mt('An error occurred: [_1]',$putresult).'</span>';
 5968:     }
 5969:     return $resulttext;
 5970: }
 5971: 
 5972: sub modify_defaults {
 5973:     my ($dom,$r) = @_;
 5974:     my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
 5975:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 5976:     my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def');
 5977:     my @authtypes = ('internal','krb4','krb5','localauth');
 5978:     foreach my $item (@items) {
 5979:         $newvalues{$item} = $env{'form.'.$item};
 5980:         if ($item eq 'auth_def') {
 5981:             if ($newvalues{$item} ne '') {
 5982:                 if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
 5983:                     push(@errors,$item);
 5984:                 }
 5985:             }
 5986:         } elsif ($item eq 'lang_def') {
 5987:             if ($newvalues{$item} ne '') {
 5988:                 if ($newvalues{$item} =~ /^(\w+)/) {
 5989:                     my $langcode = $1;
 5990:                     if ($langcode ne 'x_chef') {
 5991:                         if (code2language($langcode) eq '') {
 5992:                             push(@errors,$item);
 5993:                         }
 5994:                     }
 5995:                 } else {
 5996:                     push(@errors,$item);
 5997:                 }
 5998:             }
 5999:         } elsif ($item eq 'timezone_def') {
 6000:             if ($newvalues{$item} ne '') {
 6001:                 if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
 6002:                     push(@errors,$item);   
 6003:                 }
 6004:             }
 6005:         } elsif ($item eq 'datelocale_def') {
 6006:             if ($newvalues{$item} ne '') {
 6007:                 my @datelocale_ids = DateTime::Locale->ids();
 6008:                 if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
 6009:                     push(@errors,$item);
 6010:                 }
 6011:             }
 6012:         }
 6013:         if (grep(/^\Q$item\E$/,@errors)) {
 6014:             $newvalues{$item} = $domdefaults{$item};
 6015:         } elsif ($domdefaults{$item} ne $newvalues{$item}) {
 6016:             $changes{$item} = 1;
 6017:         }
 6018:         $domdefaults{$item} = $newvalues{$item};
 6019:     }
 6020:     my %defaults_hash = (
 6021:                          defaults => \%newvalues,
 6022:                         );
 6023:     my $title = &defaults_titles();
 6024:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
 6025:                                              $dom);
 6026:     if ($putresult eq 'ok') {
 6027:         if (keys(%changes) > 0) {
 6028:             $resulttext = &mt('Changes made:').'<ul>';
 6029:             my $version = $r->dir_config('lonVersion');
 6030:             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";
 6031:             foreach my $item (sort(keys(%changes))) {
 6032:                 my $value = $env{'form.'.$item};
 6033:                 if ($value eq '') {
 6034:                     $value = &mt('none');
 6035:                 } elsif ($item eq 'auth_def') {
 6036:                     my %authnames = &authtype_names();
 6037:                     my %shortauth = (
 6038:                              internal => 'int',
 6039:                              krb4 => 'krb4',
 6040:                              krb5 => 'krb5',
 6041:                              localauth  => 'loc',
 6042:                     );
 6043:                     $value = $authnames{$shortauth{$value}};
 6044:                 }
 6045:                 $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
 6046:                 $mailmsgtext .= "$title->{$item} set to $value\n";  
 6047:             }
 6048:             $resulttext .= '</ul>';
 6049:             $mailmsgtext .= "\n";
 6050:             my $cachetime = 24*60*60;
 6051:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 6052:             if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
 6053:                 my $sysmail = $r->dir_config('lonSysEMail');
 6054:                 &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
 6055:             }
 6056:         } else {
 6057:             $resulttext = &mt('No changes made to default authentication/language/timezone settings');
 6058:         }
 6059:     } else {
 6060:         $resulttext = '<span class="LC_error">'.
 6061:             &mt('An error occurred: [_1]',$putresult).'</span>';
 6062:     }
 6063:     if (@errors > 0) {
 6064:         $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
 6065:         foreach my $item (@errors) {
 6066:             $resulttext .= ' "'.$title->{$item}.'",';
 6067:         }
 6068:         $resulttext =~ s/,$//;
 6069:     }
 6070:     return $resulttext;
 6071: }
 6072: 
 6073: sub modify_scantron {
 6074:     my ($r,$dom,$confname,%domconfig) = @_;
 6075:     my ($resulttext,%confhash,%changes,$errors);
 6076:     my $custom = 'custom.tab';
 6077:     my $default = 'default.tab';
 6078:     my $servadm = $r->dir_config('lonAdmEMail');
 6079:     my ($configuserok,$author_ok,$switchserver) = 
 6080:         &config_check($dom,$confname,$servadm);
 6081:     if ($env{'form.scantronformat.filename'} ne '') {
 6082:         my $error;
 6083:         if ($configuserok eq 'ok') {
 6084:             if ($switchserver) {
 6085:                 $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
 6086:             } else {
 6087:                 if ($author_ok eq 'ok') {
 6088:                     my ($result,$scantronurl) =
 6089:                         &publishlogo($r,'upload','scantronformat',$dom,
 6090:                                      $confname,'scantron','','',$custom);
 6091:                     if ($result eq 'ok') {
 6092:                         $confhash{'scantron'}{'scantronformat'} = $scantronurl;
 6093:                         $changes{'scantronformat'} = 1;
 6094:                     } else {
 6095:                         $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
 6096:                     }
 6097:                 } else {
 6098:                     $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);
 6099:                 }
 6100:             }
 6101:         } else {
 6102:             $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);
 6103:         }
 6104:         if ($error) {
 6105:             &Apache::lonnet::logthis($error);
 6106:             $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 6107:         }
 6108:     }
 6109:     if (ref($domconfig{'scantron'}) eq 'HASH') {
 6110:         if ($domconfig{'scantron'}{'scantronformat'} ne '') {
 6111:             if ($env{'form.scantronformat_del'}) {
 6112:                 $confhash{'scantron'}{'scantronformat'} = '';
 6113:                 $changes{'scantronformat'} = 1;
 6114:             }
 6115:         }
 6116:     }
 6117:     if (keys(%confhash) > 0) {
 6118:         my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
 6119:                                                  $dom);
 6120:         if ($putresult eq 'ok') {
 6121:             if (keys(%changes) > 0) {
 6122:                 if (ref($confhash{'scantron'}) eq 'HASH') {
 6123:                     $resulttext = &mt('Changes made:').'<ul>';
 6124:                     if ($confhash{'scantron'}{'scantronformat'} eq '') {
 6125:                         $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
 6126:                     } else {
 6127:                         $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
 6128:                     }
 6129:                     $resulttext .= '</ul>';
 6130:                 } else {
 6131:                     $resulttext = &mt('Changes made to bubblesheet format file.');
 6132:                 }
 6133:                 $resulttext .= '</ul>';
 6134:                 &Apache::loncommon::devalidate_domconfig_cache($dom);
 6135:             } else {
 6136:                 $resulttext = &mt('No changes made to bubblesheet format file');
 6137:             }
 6138:         } else {
 6139:             $resulttext = '<span class="LC_error">'.
 6140:                 &mt('An error occurred: [_1]',$putresult).'</span>';
 6141:         }
 6142:     } else {
 6143:         $resulttext = &mt('No changes made to bubblesheet format file'); 
 6144:     }
 6145:     if ($errors) {
 6146:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 6147:                        $errors.'</ul>';
 6148:     }
 6149:     return $resulttext;
 6150: }
 6151: 
 6152: sub modify_coursecategories {
 6153:     my ($dom,%domconfig) = @_;
 6154:     my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
 6155:         $cathash);
 6156:     my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
 6157:     if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 6158:         $cathash = $domconfig{'coursecategories'}{'cats'};
 6159:         if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
 6160:             $changes{'togglecats'} = 1;
 6161:             $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
 6162:         }
 6163:         if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
 6164:             $changes{'categorize'} = 1;
 6165:             $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
 6166:         }
 6167:         if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
 6168:             $changes{'togglecatscomm'} = 1;
 6169:             $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
 6170:         }
 6171:         if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
 6172:             $changes{'categorizecomm'} = 1;
 6173:             $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
 6174:         }
 6175:     } else {
 6176:         $changes{'togglecats'} = 1;
 6177:         $changes{'categorize'} = 1;
 6178:         $changes{'togglecatscomm'} = 1;
 6179:         $changes{'categorizecomm'} = 1;
 6180:         $domconfig{'coursecategories'} = {
 6181:                                              togglecats => $env{'form.togglecats'},
 6182:                                              categorize => $env{'form.categorize'},
 6183:                                              togglecatscomm => $env{'form.togglecatscomm'},
 6184:                                              categorizecomm => $env{'form.categorizecomm'},
 6185:                                          };
 6186:     }
 6187:     if (ref($cathash) eq 'HASH') {
 6188:         if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '')  && ($env{'form.instcode'} == 0)) {
 6189:             push (@deletecategory,'instcode::0');
 6190:         }
 6191:         if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '')  && ($env{'form.communities'} == 0)) {
 6192:             push(@deletecategory,'communities::0');
 6193:         }
 6194:     }
 6195:     my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
 6196:     if (ref($cathash) eq 'HASH') {
 6197:         if (@deletecategory > 0) {
 6198:             #FIXME Need to remove category from all courses using a deleted category 
 6199:             &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
 6200:             foreach my $item (@deletecategory) {
 6201:                 if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
 6202:                     delete($domconfig{'coursecategories'}{'cats'}{$item});
 6203:                     $deletions{$item} = 1;
 6204:                     &recurse_cat_deletes($item,$cathash,\%deletions);
 6205:                 }
 6206:             }
 6207:         }
 6208:         foreach my $item (keys(%{$cathash})) {
 6209:             my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 6210:             if ($cathash->{$item} ne $env{'form.'.$item}) {
 6211:                 $reorderings{$item} = 1;
 6212:                 $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
 6213:             }
 6214:             if ($env{'form.addcategory_name_'.$item} ne '') {
 6215:                 my $newcat = $env{'form.addcategory_name_'.$item};
 6216:                 my $newdepth = $depth+1;
 6217:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 6218:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
 6219:                 $adds{$newitem} = 1; 
 6220:             }
 6221:             if ($env{'form.subcat_'.$item} ne '') {
 6222:                 my $newcat = $env{'form.subcat_'.$item};
 6223:                 my $newdepth = $depth+1;
 6224:                 my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
 6225:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
 6226:                 $adds{$newitem} = 1;
 6227:             }
 6228:         }
 6229:     }
 6230:     if ($env{'form.instcode'} eq '1') {
 6231:         if (ref($cathash) eq 'HASH') {
 6232:             my $newitem = 'instcode::0';
 6233:             if ($cathash->{$newitem} eq '') {  
 6234:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 6235:                 $adds{$newitem} = 1;
 6236:             }
 6237:         } else {
 6238:             my $newitem = 'instcode::0';
 6239:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
 6240:             $adds{$newitem} = 1;
 6241:         }
 6242:     }
 6243:     if ($env{'form.communities'} eq '1') {
 6244:         if (ref($cathash) eq 'HASH') {
 6245:             my $newitem = 'communities::0';
 6246:             if ($cathash->{$newitem} eq '') {
 6247:                 $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 6248:                 $adds{$newitem} = 1;
 6249:             }
 6250:         } else {
 6251:             my $newitem = 'communities::0';
 6252:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
 6253:             $adds{$newitem} = 1;
 6254:         }
 6255:     }
 6256:     if ($env{'form.addcategory_name'} ne '') {
 6257:         if (($env{'form.addcategory_name'} ne 'instcode') &&
 6258:             ($env{'form.addcategory_name'} ne 'communities')) {
 6259:             my $newitem = &escape($env{'form.addcategory_name'}).'::0';
 6260:             $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
 6261:             $adds{$newitem} = 1;
 6262:         }
 6263:     }
 6264:     my $putresult;
 6265:     if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 6266:         if (keys(%deletions) > 0) {
 6267:             foreach my $key (keys(%deletions)) {
 6268:                 if ($predelallitems{$key} ne '') {
 6269:                     $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
 6270:                 }
 6271:             }
 6272:         }
 6273:         my (@chkcats,@chktrails,%chkallitems);
 6274:         &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
 6275:         if (ref($chkcats[0]) eq 'ARRAY') {
 6276:             my $depth = 0;
 6277:             my $chg = 0;
 6278:             for (my $i=0; $i<@{$chkcats[0]}; $i++) {
 6279:                 my $name = $chkcats[0][$i];
 6280:                 my $item;
 6281:                 if ($name eq '') {
 6282:                     $chg ++;
 6283:                 } else {
 6284:                     $item = &escape($name).'::0';
 6285:                     if ($chg) {
 6286:                         $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
 6287:                     }
 6288:                     $depth ++; 
 6289:                     &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
 6290:                     $depth --;
 6291:                 }
 6292:             }
 6293:         }
 6294:     }
 6295:     if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 6296:         $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
 6297:         if ($putresult eq 'ok') {
 6298:             my %title = (
 6299:                          togglecats     => 'Show/Hide a course in catalog',
 6300:                          categorize     => 'Assign a category to a course',
 6301:                          togglecatscomm => 'Show/Hide a community in catalog',
 6302:                          categorizecomm => 'Assign a category to a community',
 6303:                         );
 6304:             my %level = (
 6305:                          dom  => 'set in Domain ("Modify Course/Community")',
 6306:                          crs  => 'set in Course ("Course Configuration")',
 6307:                          comm => 'set in Community ("Community Configuration")',
 6308:                         );
 6309:             $resulttext = &mt('Changes made:').'<ul>';
 6310:             if ($changes{'togglecats'}) {
 6311:                 $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>'; 
 6312:             }
 6313:             if ($changes{'categorize'}) {
 6314:                 $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
 6315:             }
 6316:             if ($changes{'togglecatscomm'}) {
 6317:                 $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
 6318:             }
 6319:             if ($changes{'categorizecomm'}) {
 6320:                 $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
 6321:             }
 6322:             if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
 6323:                 my $cathash;
 6324:                 if (ref($domconfig{'coursecategories'}) eq 'HASH') {
 6325:                     $cathash = $domconfig{'coursecategories'}{'cats'};
 6326:                 } else {
 6327:                     $cathash = {};
 6328:                 } 
 6329:                 my (@cats,@trails,%allitems);
 6330:                     &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
 6331:                 if (keys(%deletions) > 0) {
 6332:                     $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
 6333:                     foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) { 
 6334:                         $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
 6335:                     }
 6336:                     $resulttext .= '</ul></li>';
 6337:                 }
 6338:                 if (keys(%reorderings) > 0) {
 6339:                     my %sort_by_trail;
 6340:                     $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
 6341:                     foreach my $key (keys(%reorderings)) {
 6342:                         if ($allitems{$key} ne '') {
 6343:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 6344:                         }
 6345:                     }
 6346:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 6347:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 6348:                     }
 6349:                     $resulttext .= '</ul></li>';
 6350:                 }
 6351:                 if (keys(%adds) > 0) {
 6352:                     my %sort_by_trail;
 6353:                     $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
 6354:                     foreach my $key (keys(%adds)) {
 6355:                         if ($allitems{$key} ne '') {
 6356:                             $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
 6357:                         }
 6358:                     }
 6359:                     foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
 6360:                         $resulttext .= '<li>'.$trails[$trail].'</li>';
 6361:                     }
 6362:                     $resulttext .= '</ul></li>';
 6363:                 }
 6364:             }
 6365:             $resulttext .= '</ul>';
 6366:         } else {
 6367:             $resulttext = '<span class="LC_error">'.
 6368:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 6369:         }
 6370:     } else {
 6371:         $resulttext = &mt('No changes made to course and community categories');
 6372:     }
 6373:     return $resulttext;
 6374: }
 6375: 
 6376: sub modify_serverstatuses {
 6377:     my ($dom,%domconfig) = @_;
 6378:     my ($resulttext,%changes,%currserverstatus,%newserverstatus);
 6379:     if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
 6380:         %currserverstatus = %{$domconfig{'serverstatuses'}};
 6381:     }
 6382:     my @pages = &serverstatus_pages();
 6383:     foreach my $type (@pages) {
 6384:         $newserverstatus{$type}{'namedusers'} = '';
 6385:         $newserverstatus{$type}{'machines'} = '';
 6386:         if (defined($env{'form.'.$type.'_namedusers'})) {
 6387:             my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
 6388:             my @okusers;
 6389:             foreach my $user (@users) {
 6390:                 my ($uname,$udom) = split(/:/,$user);
 6391:                 if (($udom =~ /^$match_domain$/) &&   
 6392:                     (&Apache::lonnet::domain($udom)) &&
 6393:                     ($uname =~ /^$match_username$/)) {
 6394:                     if (!grep(/^\Q$user\E/,@okusers)) {
 6395:                         push(@okusers,$user);
 6396:                     }
 6397:                 }
 6398:             }
 6399:             if (@okusers > 0) {
 6400:                  @okusers = sort(@okusers);
 6401:                  $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
 6402:             }
 6403:         }
 6404:         if (defined($env{'form.'.$type.'_machines'})) {
 6405:             my @machines = split(/,/,$env{'form.'.$type.'_machines'});
 6406:             my @okmachines;
 6407:             foreach my $ip (@machines) {
 6408:                 my @parts = split(/\./,$ip);
 6409:                 next if (@parts < 4);
 6410:                 my $badip = 0;
 6411:                 for (my $i=0; $i<4; $i++) {
 6412:                     if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
 6413:                         $badip = 1;
 6414:                         last;
 6415:                     }
 6416:                 }
 6417:                 if (!$badip) {
 6418:                     push(@okmachines,$ip);     
 6419:                 }
 6420:             }
 6421:             @okmachines = sort(@okmachines);
 6422:             $newserverstatus{$type}{'machines'} = join(',',@okmachines);
 6423:         }
 6424:     }
 6425:     my %serverstatushash =  (
 6426:                                 serverstatuses => \%newserverstatus,
 6427:                             );
 6428:     my %changes;
 6429:     foreach my $type (@pages) {
 6430:         foreach my $setting ('namedusers','machines') {
 6431:             my (@current,@new);
 6432:             if (ref($currserverstatus{$type}) eq 'HASH') {
 6433:                 if ($currserverstatus{$type}{$setting} ne '') { 
 6434:                     @current = split(/,/,$currserverstatus{$type}{$setting});
 6435:                 }
 6436:             }
 6437:             if ($newserverstatus{$type}{$setting} ne '') {
 6438:                 @new = split(/,/,$newserverstatus{$type}{$setting});
 6439:             }
 6440:             if (@current > 0) {
 6441:                 if (@new > 0) {
 6442:                     foreach my $item (@current) {
 6443:                         if (!grep(/^\Q$item\E$/,@new)) {
 6444:                             $changes{$type}{$setting} = 1;
 6445:                             last;
 6446:                         }
 6447:                     }
 6448:                     foreach my $item (@new) {
 6449:                         if (!grep(/^\Q$item\E$/,@current)) {
 6450:                             $changes{$type}{$setting} = 1;
 6451:                             last;
 6452:                         }
 6453:                     }
 6454:                 } else {
 6455:                     $changes{$type}{$setting} = 1;
 6456:                 }
 6457:             } elsif (@new > 0) {
 6458:                 $changes{$type}{$setting} = 1;
 6459:             }
 6460:         }
 6461:     }
 6462:     if (keys(%changes) > 0) {
 6463:         my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
 6464:         my $putresult = &Apache::lonnet::put_dom('configuration',
 6465:                                                  \%serverstatushash,$dom);
 6466:         if ($putresult eq 'ok') {
 6467:             $resulttext .= &mt('Changes made:').'<ul>';
 6468:             foreach my $type (@pages) {
 6469:                 if (ref($changes{$type}) eq 'HASH') {
 6470:                     $resulttext .= '<li>'.$titles->{$type}.'<ul>';
 6471:                     if ($changes{$type}{'namedusers'}) {
 6472:                         if ($newserverstatus{$type}{'namedusers'} eq '') {
 6473:                             $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
 6474:                         } else {
 6475:                             $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
 6476:                         }
 6477:                     }
 6478:                     if ($changes{$type}{'machines'}) {
 6479:                         if ($newserverstatus{$type}{'machines'} eq '') {
 6480:                             $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
 6481:                         } else {
 6482:                             $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
 6483:                         }
 6484: 
 6485:                     }
 6486:                     $resulttext .= '</ul></li>';
 6487:                 }
 6488:             }
 6489:             $resulttext .= '</ul>';
 6490:         } else {
 6491:             $resulttext = '<span class="LC_error">'.
 6492:                           &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
 6493: 
 6494:         }
 6495:     } else {
 6496:         $resulttext = &mt('No changes made to access to server status pages');
 6497:     }
 6498:     return $resulttext;
 6499: }
 6500: 
 6501: sub modify_helpsettings {
 6502:     my ($r,$dom,$confname,%domconfig) = @_;
 6503:  	my ($resulttext,$errors,%changes,%helphash);
 6504:  	
 6505:  	my $customhelpfile  = $env{'form.loginhelpurl.filename'};
 6506:     my $defaulthelpfile = 'defaulthelp.html';
 6507:  	my $servadm = $r->dir_config('lonAdmEMail');
 6508:     my ($configuserok,$author_ok,$switchserver) = 
 6509:         &config_check($dom,$confname,$servadm);
 6510:  	
 6511:  	my %defaultchecked = ('submitbugs'	=> 'on');
 6512:  	my @offon = ('off','on');
 6513:     my %title = ( submitbugs     => 'Display link for users to submit a bug', 
 6514:     			  loginhelpurl  => 'Unauthenticated login help page set to custom file');
 6515:     			  
 6516:     my @toggles = ('submitbugs');
 6517: 
 6518:     $helphash{'helpsettings'} = {};
 6519:     
 6520:     if (ref($domconfig{'helpsettings'}) ne 'HASH') {
 6521:         if ($domconfig{'helpsettings'} eq '') {
 6522:             $domconfig{'helpsettings'} = {};
 6523:         }
 6524:     }
 6525:     
 6526:     if (ref($domconfig{'helpsettings'}) eq 'HASH') {
 6527:     	
 6528:         foreach my $item (@toggles) {
 6529:         	
 6530: 			if ($defaultchecked{$item} eq 'on') { 
 6531: 				if (($domconfig{'helpsettings'}{$item} eq '') &&
 6532: 					 ($env{'form.'.$item} eq '0')) {
 6533: 					$changes{$item} = 1;
 6534: 				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
 6535: 					$changes{$item} = 1;
 6536: 				}
 6537: 			} elsif ($defaultchecked{$item} eq 'off') {
 6538: 				if (($domconfig{'helpsettings'}{$item} eq '') &&
 6539: 					 ($env{'form.'.$item} eq '1')) {
 6540: 					$changes{$item} = 1;
 6541: 				} elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
 6542: 					$changes{$item} = 1;
 6543: 				}
 6544: 			}
 6545: 			$helphash{'helpsettings'}{$item} = $env{'form.'.$item};
 6546: 		}
 6547: 		
 6548: 		if ($customhelpfile ne '') {
 6549: 			my $error;
 6550: 			if ($configuserok eq 'ok') {
 6551: 				if ($switchserver) {
 6552: 					$error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
 6553: 				} else {
 6554: 					if ($author_ok eq 'ok') {
 6555: 						my ($result,$loginhelpurl) =
 6556: 							&publishlogo($r,'upload','loginhelpurl',$dom,
 6557: 										 $confname,'help','','',$customhelpfile);
 6558: 						if ($result eq 'ok') {
 6559: 							$helphash{'helpsettings'}{'loginhelpurl'} = $loginhelpurl;
 6560: 							$changes{'loginhelpurl'} = 1;
 6561: 						} else {
 6562: 							$error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customhelpfile,$result);
 6563: 						}
 6564: 					} else {
 6565: 						$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].",$customhelpfile,$confname,$dom,$author_ok);
 6566: 					}
 6567: 				}
 6568: 			} else {
 6569: 				$error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$customhelpfile,$confname,$dom,$configuserok);
 6570: 			}
 6571: 			if ($error) {
 6572: 				&Apache::lonnet::logthis($error);
 6573: 				$errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 6574: 			}
 6575: 		}
 6576: 		
 6577:         if ($domconfig{'helpsettings'}{'loginhelpurl'} ne '') {
 6578:             if ($env{'form.loginhelpurl_del'}) {
 6579:                 $helphash{'helpsettings'}{'loginhelpurl'} = '';
 6580:                 $changes{'loginhelpurl'} = 1;
 6581:             }
 6582:         }
 6583:     }
 6584:     
 6585:     
 6586:     my $putresult;
 6587:     
 6588:     if (keys(%changes) > 0) {
 6589:     	$putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
 6590:     } else {
 6591:     	$putresult = 'ok';
 6592:     }
 6593:                                              
 6594:     if ($putresult eq 'ok') {
 6595:         if (keys(%changes) > 0) {
 6596: 			$resulttext = &mt('Changes made:').'<ul>';
 6597: 			foreach my $item (sort(keys(%changes))) {
 6598: 				if ($item eq 'submitbugs') {
 6599: 					$resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 6600: 				}
 6601: 				if ($item eq 'loginhelpurl') {
 6602: 					if ($helphash{'helpsettings'}{'loginhelpurl'} eq '') {
 6603:                         $resulttext .= '<li>'.&mt('[_1] help file removed; [_2] file will be used for the unathorized help page in this domain.',$customhelpfile,$defaulthelpfile).'</li>';
 6604:                     } else {
 6605:                         $resulttext .= '<li>'.&mt("$title{$item} [_1]",$customhelpfile).'</li>';
 6606:                     }
 6607: 				}
 6608: 			}
 6609: 			$resulttext .= '</ul>';
 6610: 		} else {
 6611: 			$resulttext = &mt('No changes made to help settings');
 6612: 		}
 6613:     } else {
 6614:         $resulttext = '<span class="LC_error">'.
 6615: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 6616:     }
 6617:     if ($errors) {
 6618:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 6619:                        $errors.'</ul>';
 6620:     }
 6621:     return $resulttext;
 6622: }
 6623: 
 6624: sub modify_coursedefaults {
 6625:     my ($dom,%domconfig) = @_;
 6626:     my ($resulttext,$errors,%changes,%defaultshash);
 6627:     my %defaultchecked = ('canuse_pdfforms' => 'off');
 6628:     my @offon = ('off','on');
 6629:     my @toggles = ('canuse_pdfforms');
 6630: 
 6631:     $defaultshash{'coursedefaults'} = {};
 6632: 
 6633:     if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
 6634:         if ($domconfig{'coursedefaults'} eq '') {
 6635:             $domconfig{'coursedefaults'} = {};
 6636:         }
 6637:     }
 6638: 
 6639:     if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
 6640:         foreach my $item (@toggles) {
 6641:             if ($defaultchecked{$item} eq 'on') {
 6642:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
 6643:                     ($env{'form.'.$item} eq '0')) {
 6644:                     $changes{$item} = 1;
 6645:                 } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
 6646:                     $changes{$item} = 1;
 6647:                 }
 6648:             } elsif ($defaultchecked{$item} eq 'off') {
 6649:                 if (($domconfig{'coursedefaults'}{$item} eq '') &&
 6650:                     ($env{'form.'.$item} eq '1')) {
 6651:                     $changes{$item} = 1;
 6652:                 } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
 6653:                     $changes{$item} = 1;
 6654:                 }
 6655:             }
 6656:             $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
 6657:         }
 6658:     }
 6659:     my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
 6660:                                              $dom);
 6661:     if ($putresult eq 'ok') {
 6662:         if (keys(%changes) > 0) {
 6663:             if ($changes{'canuse_pdfforms'}) {
 6664:                 my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 6665:                 $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
 6666:                 my $cachetime = 24*60*60;
 6667:                 &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 6668:             }
 6669:             $resulttext = &mt('Changes made:').'<ul>';
 6670:             foreach my $item (sort(keys(%changes))) {
 6671:                 if ($item eq 'canuse_pdfforms') {
 6672:                     if ($env{'form.'.$item} eq '1') {
 6673:                         $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
 6674:                     } else {
 6675:                         $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
 6676:                     }
 6677:                 }
 6678:             }
 6679:             $resulttext .= '</ul>';
 6680:         } else {
 6681:             $resulttext = &mt('No changes made to course defaults');
 6682:         }
 6683:     } else {
 6684:         $resulttext = '<span class="LC_error">'.
 6685:             &mt('An error occurred: [_1]',$putresult).'</span>';
 6686:     }
 6687:     return $resulttext;
 6688: }
 6689: 
 6690: sub modify_usersessions {
 6691:     my ($dom,%domconfig) = @_;
 6692:     my @types = ('version','excludedomain','includedomain');
 6693:     my @prefixes = ('remote','hosted');
 6694:     my @lcversions = &Apache::lonnet::all_loncaparevs();
 6695:     my (%by_ip,%by_location,@intdoms);
 6696:     &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
 6697:     my @locations = sort(keys(%by_location));
 6698:     my (%defaultshash,%changes);
 6699:     foreach my $prefix (@prefixes) {
 6700:         $defaultshash{'usersessions'}{$prefix} = {};
 6701:     }
 6702:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
 6703:     my $resulttext;
 6704:     my %iphost = &Apache::lonnet::get_iphost();
 6705:     foreach my $prefix (@prefixes) {
 6706:         foreach my $type (@types) {
 6707:             my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
 6708:             if ($type eq 'version') {
 6709:                 my $value = $env{'form.'.$prefix.'_'.$type};
 6710:                 my $okvalue;
 6711:                 if ($value ne '') {
 6712:                     if (grep(/^\Q$value\E$/,@lcversions)) {
 6713:                         $okvalue = $value;
 6714:                     }
 6715:                 }
 6716:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
 6717:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
 6718:                         if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
 6719:                             if ($inuse == 0) {
 6720:                                 $changes{$prefix}{$type} = 1;
 6721:                             } else {
 6722:                                 if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
 6723:                                     $changes{$prefix}{$type} = 1;
 6724:                                 }
 6725:                                 if ($okvalue ne '') {
 6726:                                     $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 6727:                                 } 
 6728:                             }
 6729:                         } else {
 6730:                             if (($inuse == 1) && ($okvalue ne '')) {
 6731:                                 $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 6732:                                 $changes{$prefix}{$type} = 1;
 6733:                             }
 6734:                         }
 6735:                     } else {
 6736:                         if (($inuse == 1) && ($okvalue ne '')) {
 6737:                             $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 6738:                             $changes{$prefix}{$type} = 1;
 6739:                         }
 6740:                     }
 6741:                 } else {
 6742:                     if (($inuse == 1) && ($okvalue ne '')) {
 6743:                         $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
 6744:                         $changes{$prefix}{$type} = 1;
 6745:                     }
 6746:                 }
 6747:             } else {
 6748:                 my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
 6749:                 my @okvals;
 6750:                 foreach my $val (@vals) {
 6751:                     if ($val =~ /:/) {
 6752:                         my @items = split(/:/,$val);
 6753:                         foreach my $item (@items) {
 6754:                             if (ref($by_location{$item}) eq 'ARRAY') {
 6755:                                 push(@okvals,$item);
 6756:                             }
 6757:                         }
 6758:                     } else {
 6759:                         if (ref($by_location{$val}) eq 'ARRAY') {
 6760:                             push(@okvals,$val);
 6761:                         }
 6762:                     }
 6763:                 }
 6764:                 @okvals = sort(@okvals);
 6765:                 if (ref($domconfig{'usersessions'}) eq 'HASH') {
 6766:                     if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
 6767:                         if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
 6768:                             if ($inuse == 0) {
 6769:                                 $changes{$prefix}{$type} = 1; 
 6770:                             } else {
 6771:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 6772:                                 my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
 6773:                                 if (@changed > 0) {
 6774:                                     $changes{$prefix}{$type} = 1;
 6775:                                 }
 6776:                             }
 6777:                         } else {
 6778:                             if ($inuse == 1) {
 6779:                                 $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 6780:                                 $changes{$prefix}{$type} = 1;
 6781:                             }
 6782:                         } 
 6783:                     } else {
 6784:                         if ($inuse == 1) {
 6785:                             $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 6786:                             $changes{$prefix}{$type} = 1;
 6787:                         }
 6788:                     }
 6789:                 } else {
 6790:                     if ($inuse == 1) {
 6791:                         $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
 6792:                         $changes{$prefix}{$type} = 1;
 6793:                     }
 6794:                 }
 6795:             }
 6796:         }
 6797:     }
 6798:     if (keys(%changes) > 0) {
 6799:         my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
 6800:                                                  $dom);
 6801:         if ($putresult eq 'ok') {
 6802:             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
 6803:                 if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
 6804:                     $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
 6805:                 }
 6806:                 if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
 6807:                     $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
 6808:                 }
 6809:             }
 6810:             my $cachetime = 24*60*60;
 6811:             &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
 6812:             my %lt = &usersession_titles();
 6813:             $resulttext = &mt('Changes made:').'<ul>';
 6814:             foreach my $prefix (@prefixes) {
 6815:                 if (ref($changes{$prefix}) eq 'HASH') {
 6816:                     $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
 6817:                     foreach my $type (@types) {
 6818:                         if (defined($changes{$prefix}{$type})) {
 6819:                             my $newvalue;
 6820:                             if (ref($defaultshash{'usersessions'}) eq 'HASH') {
 6821:                                 if (ref($defaultshash{'usersessions'}{$prefix})) {
 6822:                                     if ($type eq 'version') {
 6823:                                         $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
 6824:                                     } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
 6825:                                         if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
 6826:                                             $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
 6827:                                         }
 6828:                                     }
 6829:                                 }
 6830:                             }
 6831:                             if ($newvalue eq '') {
 6832:                                 if ($type eq 'version') {
 6833:                                     $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
 6834:                                 } else {
 6835:                                     $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
 6836:                                 }
 6837:                             } else {
 6838:                                 if ($type eq 'version') {
 6839:                                     $newvalue .= ' '.&mt('(or later)'); 
 6840:                                 } 
 6841:                                 $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>'; 
 6842:                             }
 6843:                         }
 6844:                     }
 6845:                     $resulttext .= '</ul>';
 6846:                 }
 6847:             }
 6848:             $resulttext .= '</ul>';
 6849:         } else {
 6850:             $resulttext = '<span class="LC_error">'.
 6851:                           &mt('An error occurred: [_1]',$putresult).'</span>';
 6852:         }
 6853:     } else {
 6854:         $resulttext =  &mt('No changes made to settings for user session hosting.');
 6855:     }
 6856:     return $resulttext;
 6857: }
 6858: 
 6859: sub recurse_check {
 6860:     my ($chkcats,$categories,$depth,$name) = @_;
 6861:     if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
 6862:         my $chg = 0;
 6863:         for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
 6864:             my $category = $chkcats->[$depth]{$name}[$j];
 6865:             my $item;
 6866:             if ($category eq '') {
 6867:                 $chg ++;
 6868:             } else {
 6869:                 my $deeper = $depth + 1;
 6870:                 $item = &escape($category).':'.&escape($name).':'.$depth;
 6871:                 if ($chg) {
 6872:                     $categories->{$item} -= $chg;
 6873:                 }
 6874:                 &recurse_check($chkcats,$categories,$deeper,$category);
 6875:                 $deeper --;
 6876:             }
 6877:         }
 6878:     }
 6879:     return;
 6880: }
 6881: 
 6882: sub recurse_cat_deletes {
 6883:     my ($item,$coursecategories,$deletions) = @_;
 6884:     my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
 6885:     my $subdepth = $depth + 1;
 6886:     if (ref($coursecategories) eq 'HASH') {
 6887:         foreach my $subitem (keys(%{$coursecategories})) {
 6888:             my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
 6889:             if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
 6890:                 delete($coursecategories->{$subitem});
 6891:                 $deletions->{$subitem} = 1;
 6892:                 &recurse_cat_deletes($subitem,$coursecategories,$deletions);
 6893:             }  
 6894:         }
 6895:     }
 6896:     return;
 6897: }
 6898: 
 6899: sub dom_servers {
 6900:     my ($dom) = @_;
 6901:     my (%uniqservers,%servers);
 6902:     my $primaryserver = &Apache::lonnet::hostname(&Apache::lonnet::domain($dom,'primary'));
 6903:     my @machinedoms = &Apache::lonnet::machine_domains($primaryserver);
 6904:     foreach my $mdom (@machinedoms) {
 6905:         my %currservers = %servers;
 6906:         my %server = &Apache::lonnet::get_servers($mdom);
 6907:         %servers = (%currservers,%server);
 6908:     }
 6909:     my %by_hostname;
 6910:     foreach my $id (keys(%servers)) {
 6911:         push(@{$by_hostname{$servers{$id}}},$id);
 6912:     }
 6913:     foreach my $hostname (sort(keys(%by_hostname))) {
 6914:         if (@{$by_hostname{$hostname}} > 1) {
 6915:             my $match = 0;
 6916:             foreach my $id (@{$by_hostname{$hostname}}) {
 6917:                 if (&Apache::lonnet::host_domain($id) eq $dom) {
 6918:                     $uniqservers{$id} = $hostname;
 6919:                     $match = 1;
 6920:                 }
 6921:             }
 6922:             unless ($match) {
 6923:                 $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
 6924:             }
 6925:         } else {
 6926:             $uniqservers{$by_hostname{$hostname}[0]} = $hostname;
 6927:         }
 6928:     }
 6929:     return %uniqservers;
 6930: }
 6931: 
 6932: sub get_active_dcs {
 6933:     my ($dom) = @_;
 6934:     my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
 6935:     my %domcoords;
 6936:     my $numdcs = 0;
 6937:     my $now = time;
 6938:     foreach my $server (keys(%dompersonnel)) {
 6939:         foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
 6940:             my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
 6941:             my ($end,$start) = split(':',$dompersonnel{$server}{$user});
 6942:             if (($end eq '') || ($end == 0) || ($end > $now)) {
 6943:                 if ($start <= $now) {
 6944:                     $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
 6945:                 }
 6946:             }
 6947:         }
 6948:     }
 6949:     return %domcoords;
 6950: }
 6951: 
 6952: sub active_dc_picker {
 6953:     my ($dom,$curr_dc) = @_;
 6954:     my %domcoords = &get_active_dcs($dom); 
 6955:     my @dcs = sort(keys(%domcoords));
 6956:     my $numdcs = scalar(@dcs); 
 6957:     my $datatable;
 6958:     my $numinrow = 2;
 6959:     if ($numdcs > 1) {
 6960:         $datatable = '<table>';
 6961:         for (my $i=0; $i<@dcs; $i++) {
 6962:             my $rem = $i%($numinrow);
 6963:             if ($rem == 0) {
 6964:                 if ($i > 0) {
 6965:                     $datatable .= '</tr>';
 6966:                 }
 6967:                 $datatable .= '<tr>';
 6968:             }
 6969:             my $check = ' ';
 6970:             if ($curr_dc eq '') {
 6971:                 if (!$i) { 
 6972:                     $check = ' checked="checked" ';
 6973:                 }
 6974:             } elsif ($dcs[$i] eq $curr_dc) {
 6975:                 $check = ' checked="checked" ';
 6976:             }
 6977:             if ($i == @dcs - 1) {
 6978:                 my $colsleft = $numinrow - $rem;
 6979:                 if ($colsleft > 1) {
 6980:                     $datatable .= '<td colspan="'.$colsleft.'">';
 6981:                 } else {
 6982:                     $datatable .= '<td>';
 6983:                 }
 6984:             } else {
 6985:                 $datatable .= '<td>';
 6986:             }
 6987:             my ($dcname,$dcdom) = split(':',$dcs[$i]);
 6988:             $datatable .= '<span class="LC_nobreak"><label>'.
 6989:                           '<input type="radio" name="autocreate_xmldc"'.
 6990:                           ' value="'.$dcs[$i].'"'.$check.'/>'.
 6991:                           &Apache::loncommon::plainname($dcname,$dcdom).
 6992:                           '</label></span></td>';
 6993:         }
 6994:         $datatable .= '</tr></table>';
 6995:     } elsif (@dcs) {
 6996:         $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
 6997:                       $dcs[0].'" />';
 6998:     }
 6999:     return ($numdcs,$datatable);
 7000: }
 7001: 
 7002: sub usersession_titles {
 7003:     return &Apache::lonlocal::texthash(
 7004:                hosted => 'Hosting of sessions for users from other domains on servers in this domain',
 7005: 
 7006:                remote => 'Hosting of sessions for users in this domain on servers in other domains',
 7007:                version => 'LON-CAPA version requirement',
 7008:                excludedomain => 'Allow all, but exclude specific domains',
 7009:                includedomain => 'Deny all, but include specific domains',
 7010:            );
 7011: }
 7012: 
 7013: 1;

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