File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.118: download - view: text, annotated - select for diffs
Tue Nov 10 19:12:11 2009 UTC (14 years, 7 months ago) by jms
Branches: MAIN
CVS tags: HEAD
New "Help Settings" page added to Domain Settings, with ability to turn the "Submit a bug" link on or off in the help menu

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

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