File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.123.2.4: download - view: text, annotated - select for diffs
Mon Dec 6 17:50:40 2010 UTC (13 years, 6 months ago) by raeburn
Branches: GCI_3
- Customization for GCI_3.
  - Language codes need to be three characters or less.

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

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