File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.131: download - view: text, annotated - select for diffs
Fri Mar 12 15:01:36 2010 UTC (14 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Wording change - fix typo: "Updataeable" -> "Updateable"
- In &insttypes_row(), add a new row for default type, if all columns
  used in row for non-default types.
- Additional setting for Auto-updates.
  - Can allow user's to opt out of automatic name changes via a user preference
    for specified institutional affiliations.

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

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