File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.138.2.6: download - view: text, annotated - select for diffs
Thu Dec 30 18:53:08 2010 UTC (13 years, 4 months ago) by raeburn
Branches: version_2_10_X
CVS tags: version_2_10_0_RC2
- Typo in 1.138.2.5 backport of 1.141.

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

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