File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.102.2.10: download - view: text, annotated - select for diffs
Wed Mar 10 17:26:05 2010 UTC (14 years, 3 months ago) by raeburn
Branches: version_2_9_X
Diff to branchpoint 1.102: preferred, unified
- Backport 1.117, 1.119, 1.128.

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

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