File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.102.2.16: download - view: text, annotated - select for diffs
Mon Feb 7 21:39:45 2011 UTC (13 years, 3 months ago) by raeburn
Branches: version_2_9_X
Diff to branchpoint 1.102: preferred, unified
- Backport 1.142.

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

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