File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.142: download - view: text, annotated - select for diffs
Mon Feb 7 21:04:09 2011 UTC (13 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Eliminate duplicate declarations.

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

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