Annotation of loncom/interface/domainprefs.pm, revision 1.102.4.2

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

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