File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.101: download - view: text, annotated - select for diffs
Sat Aug 8 00:36:00 2009 UTC (14 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: bz2851, HEAD
Course Requests within LON-CAPA.

- Start on documentation for domainprefs.pm

- Domain setting for course requests for each instituional affiliate type (and
also default, and _LC_adv) for each course type (official, unofficial and
community) can now be one of:
  0, approve, validate, autolimit=N (where N is blank, or a positive integer.

- Custom course request settings set for an individual user in the user's domain
can also be one of: approve, validate, autolimit=N for the three course types

- A user's environment setting for course requests in external domains (modifiable
by a DC in a domain other than the user's home domain) can also be one of the
three.

0: course requests not allowed for the specific affiliation/course type.
approve - requests queued and must be approved by DC in course's domain before
processing.

validate: institutional validation (e.g., check requestor is instructor
of record) before course will be created.

autolimit: requests will be processed autoatically up to a limit of N requests
for the course type for that requestor.
- If N is undefined, there is no limit to the number of course requests which a
course owner may submit for automatic processing.

lonnet.pm
- auto_courserequest_checks() placeholder.

Work in progress.

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

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