File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.121: download - view: text, annotated - select for diffs
Mon Nov 30 06:23:32 2009 UTC (14 years, 6 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6121.
  - Display of "Upload PDF Forms" in Main Menu in a course/community
    controlled by domain default or course configuration.
courseprefs.pm
  - lonnet::delenv() used to update current user's session when a
    course environment setting is deleted.
domainprefs.pm
  - code moved from &print_helpsettings() to &radiobutton_prefs()
    to facilitate reuse in course defaults menu (canuse_pdfforms).
lonnet.pm
  - canuse_pdfforms domain default cached in domdefaults.
Work in progess.

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

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