File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.135: download - view: text, annotated - select for diffs
Fri May 21 15:54:44 2010 UTC (14 years ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Bug 6271, Bug 5577:
Get rid of user authentication image on login page (always use text version)
including all corresponding configuration settings.
Although the user interface is cleaned up and functional, the internal domain configuration cleanup could be improved.

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

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