File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.138: download - view: text, annotated - select for diffs
Tue Jul 20 02:42:40 2010 UTC (13 years, 10 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_10_X, HEAD
- Control hosting of user sessions.
  - To accommodate multi-domain library servers, use internet domain names (e.g., msu.edu)
    instead of LON-CAPA domains in interface DC uses to set options for session hosting.

  - Provide mechanism to retrieve lonHostID for a hostname, so we can tell which
    domain determines session hosting config for external users on a multi-domain
    machine.

  - New routines in lonnet.pm:
     &get_server_homeID()  -- gets lonHostID for a hostname
     &internet_dom() -- gets internet domain name for a LON-CAPA Host ID
     &get_internet_names() -- gets internet domain names for all domains
                              for a server given one of the LC host IDs for the server.

   - New file in /home/httpd/lonTabs:
     - serverhomeIDs.tab (populated by loncron). : paired hostname:lonHostID

   - New subroutine in loncron: &write_serverhomeIDs() -- populates serverhomeIDs.tab
   - New subroutine in lond: &server_homeID_handler() -- returns LON-CAPA Host ID of server
   - New scalar in lond: $clienthomedom -- set to domain of LON-CAPA Host ID of client
   - New subroutine in domainprefs.pm: &build_location_hashes()
       -- used to set up options for session hosting as internet domain names
           - where two names (e.g., msu.edu, loncapa.org) are controlled by the same
             institution these will receive a single checkbox.

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

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