File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.140: download - view: text, annotated - select for diffs
Tue Oct 5 18:42:45 2010 UTC (13 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Special message in domain configuration display
  for "Hosting of users from other domains" where the cluster has only
  one institution (e.g., standalone cluster).

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

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