File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.102: download - view: text, annotated - select for diffs
Tue Aug 11 23:24:29 2009 UTC (14 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_9_X, HEAD, GCI_2
- Configure which active Domain Coordinators receive a notification when a course request is made which requires approval. (Will also be notified when a DC approves or rejects the request).
- Configure e-mail addresses to receive e-mail when a course request is made which requires approval.

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

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