File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.110: download - view: text, annotated - select for diffs
Tue Oct 6 18:10:25 2009 UTC (14 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Log-in page option.
  - If domain has more than one server, can choose to replace
    log-in page on one or more servers with redirect to a different server in the domain.
    e.g., redirect s1-s8 at msu to lonbalancer server (s9).
  - default is to show regular log-in page.

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

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