File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.138.2.8: download - view: text, annotated - select for diffs
Thu Mar 10 23:39:22 2011 UTC (13 years, 2 months ago) by raeburn
Branches: version_2_10_X
CVS tags: version_2_10_0
- Backport 1.143.

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

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