File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.102.2.13: download - view: text, annotated - select for diffs
Fri Mar 26 16:25:38 2010 UTC (14 years, 2 months ago) by raeburn
Branches: version_2_9_X
Diff to branchpoint 1.102: preferred, unified
- Course default for PDFForms fixed as "No" for all domains in 2.9.

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

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