File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.102.2.6: download - view: text, annotated - select for diffs
Sat Jan 2 21:50:54 2010 UTC (14 years, 6 months ago) by raeburn
Branches: version_2_9_X
Diff to branchpoint 1.102: preferred, unified
- Backport 1.116, 1.120, 1.124.

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

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