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

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

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