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

1.1       raeburn     1: # The LearningOnline Network with CAPA
                      2: # Handler to set domain-wide configuration settings
                      3: #
1.35    ! raeburn     4: # $Id: domainprefs.pm,v 1.34 2007/12/12 19:44:53 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: 
                     31: package Apache::domainprefs;
                     32: 
                     33: use strict;
                     34: use Apache::Constants qw(:common :http);
                     35: use Apache::lonnet;
                     36: use Apache::loncommon();
                     37: use Apache::lonhtmlcommon();
                     38: use Apache::lonlocal;
                     39: use LONCAPA();
1.6       raeburn    40: use LONCAPA::Enrollment;
1.9       raeburn    41: use File::Copy;
1.1       raeburn    42: 
                     43: sub handler {
                     44:     my $r=shift;
                     45:     if ($r->header_only) {
                     46:         &Apache::loncommon::content_type($r,'text/html');
                     47:         $r->send_http_header;
                     48:         return OK;
                     49:     }
                     50: 
                     51:     my $dom = $env{'request.role.domain'};
1.5       albertel   52:     my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1       raeburn    53:     if (&Apache::lonnet::allowed('mau',$dom)) {
                     54:         &Apache::loncommon::content_type($r,'text/html');
                     55:         $r->send_http_header;
                     56:     } else {
                     57:         $env{'user.error.msg'}=
                     58:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
                     59:         return HTTP_NOT_ACCEPTABLE;
                     60:     }
                     61:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                     62:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                     63:                                             ['phase']);
1.30      raeburn    64:     my $phase = 'pickactions';
1.3       raeburn    65:     if ( exists($env{'form.phase'}) ) {
                     66:         $phase = $env{'form.phase'};
                     67:     }
                     68:     my %domconfig =
1.6       raeburn    69:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.27      raeburn    70:                 'quotas','autoenroll','autoupdate','directorysrch',
1.33      raeburn    71:                 'usercreation','usermodification','contacts'],$dom);
1.30      raeburn    72:     my @prefs_order = ('rolecolors','login','quotas','autoenroll',
                     73:                        'autoupdate','directorysrch','contacts',
1.33      raeburn    74:                        'usercreation','usermodification');
1.30      raeburn    75:     my %prefs = (
                     76:         'rolecolors' =>
                     77:                    { text => 'Default color schemes',
                     78:                      help => 'Default_Color_Schemes',
                     79:                      header => [{col1 => 'Student Settings',
                     80:                                  col2 => '',},
                     81:                                 {col1 => 'Coordinator Settings',
                     82:                                  col2 => '',},
                     83:                                 {col1 => 'Author Settings',
                     84:                                  col2 => '',},
                     85:                                 {col1 => 'Administrator Settings',
                     86:                                  col2 => '',}],
                     87:                     },
                     88:         'login' =>  
                     89:                     { text => 'Log-in page options',
                     90:                       help => 'Domain_Log-in_Page',
                     91:                       header => [{col1 => 'Item',
                     92:                                   col2 => '',}],
                     93:                     },
                     94:         'quotas' => 
                     95:                     { text => 'Default quotas for user portfolios',
                     96:                       help => 'Default_User_Quota',
                     97:                       header => [{col1 => 'User type',
                     98:                                   col2 => 'Default quota'}],
                     99:                     },
                    100:         'autoenroll' =>
                    101:                    { text => 'Auto-enrollment settings',
                    102:                      help => 'Domain_Auto_Enrollment',
                    103:                      header => [{col1 => 'Configuration setting',
                    104:                                  col2 => 'Value(s)'}],
                    105:                    },
                    106:         'autoupdate' => 
                    107:                    { text => 'Auto-update settings',
                    108:                      help => 'Domain_Auto_Update',
                    109:                      header => [{col1 => 'Setting',
                    110:                                  col2 => 'Value',},
                    111:                                 {col1 => 'User Population',
                    112:                                  col2 => 'Updataeable user data'}],
                    113:                   },
                    114:         'directorysrch' => 
                    115:                   { text => 'Institutional directory searches',
                    116:                     help => 'Domain_Directory_Search',
                    117:                     header => [{col1 => 'Setting',
                    118:                                 col2 => 'Value',}],
                    119:                   },
                    120:         'contacts' =>
                    121:                   { text => 'Contact Information',
                    122:                     help => 'Domain_Contact_Information',
                    123:                     header => [{col1 => 'Setting',
                    124:                                 col2 => 'Value',}],
                    125:                   },
                    126: 
                    127:         'usercreation' => 
                    128:                   { text => 'User creation',
                    129:                     help => 'Domain_User_Creation',
1.34      raeburn   130:                     header => [{col1 => 'Format Rule Type',
                    131:                                 col2 => 'Format Rules in force'},
                    132:                                {col1 => 'User account creation',
                    133:                                 col2 => 'Usernames which may be created',},
1.30      raeburn   134:                                {col1 => 'Context',
                    135:                                 col2 => 'Assignable Authentication Types'}],
                    136:                   },
1.33      raeburn   137:         'usermodification' => 
                    138:                   { text => 'User modification',
                    139:                     help => 'Domain_User_Modification',
                    140:                     header => [{col1 => 'Target user has role',
                    141:                                 col2 => 'User information updateable in author context'},
                    142:                                {col1 => 'Target user has role',
                    143:                                 col2 => 'User information updateable in course context'}],
                    144:                   },
1.3       raeburn   145:     );
1.6       raeburn   146:     my @roles = ('student','coordinator','author','admin');
1.30      raeburn   147:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3       raeburn   148:     &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   149:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
                    150:       text=>"Pick functionality"});
1.9       raeburn   151:     my $confname = $dom.'-domainconfig';
1.3       raeburn   152:     if ($phase eq 'process') {
1.1       raeburn   153:         &Apache::lonhtmlcommon::add_breadcrumb
1.30      raeburn   154:           ({href=>"javascript:changePage(document.$phase,'display')",
                    155:             text=>"Domain Configuration"},
                    156:            {href=>"javascript:changePage(document.$phase,'$phase')",
1.3       raeburn   157:             text=>"Updated"});
                    158:         &print_header($r,$phase);
1.30      raeburn   159:         foreach my $item (@prefs_order) {
                    160:             if (grep(/^\Q$item\E$/,@actions)) {
                    161:                 $r->print('<h3>'.&mt($prefs{$item}{'text'}).'</h3>'.
                    162:                           &process_changes($r,$dom,$confname,$item,
                    163:                           \@roles,%domconfig));
                    164:             }
1.3       raeburn   165:         }
                    166:         $r->print('<p>');
1.30      raeburn   167:         &print_footer($r,$phase,'display','Back to configuration display',
                    168:                       \@actions);
1.3       raeburn   169:         $r->print('</p>');
1.30      raeburn   170:     } elsif ($phase eq 'display') {
                    171:         &Apache::lonhtmlcommon::add_breadcrumb
                    172:             ({href=>"javascript:changePage(document.$phase,'display')",
                    173:               text=>"Domain Configuration"});
                    174:         &print_header($r,$phase);
                    175:         if (@actions > 0) {
                    176:             my $rowsum = 0;
                    177:             my (%output,%rowtotal,@items);
                    178:             my $halfway = @actions/2;
                    179:             foreach my $item (@prefs_order) {
                    180:                 if (grep(/^\Q$item\E$/,@actions)) {
                    181:                     push(@items,$item);
                    182:                     ($output{$item},$rowtotal{$item}) = 
                    183:                         &print_config_box($r,$dom,$confname,$phase,
                    184:                                           $item,$prefs{$item},
                    185:                                           $domconfig{$item});
                    186:                     $rowsum += $rowtotal{$item};
                    187:                 }
                    188:             }
                    189:             my $colend;
                    190:             my $halfway = $rowsum/2;
                    191:             my $aggregate = 0;
                    192:             my $sumleft = 0;
                    193:             my $sumright = 0;
                    194:             my $crossover;
                    195:             for (my $i=0; $i<@items; $i++) {
                    196:                 $aggregate += $rowtotal{$items[$i]};
                    197:                 if ($aggregate > $halfway) {
                    198:                     $crossover = $i;
                    199:                     last;
                    200:                 }
                    201:             }
                    202:             for (my $i=0; $i<$crossover; $i++) {
                    203:                 $sumleft += $rowtotal{$items[$i]}; 
                    204:             }
                    205:             for (my $i=$crossover+1; $i<@items; $i++) {
                    206:                 $sumright += $rowtotal{$items[$i]};
                    207:             }
                    208:             if ((@items > 1) && ($env{'form.numcols'} == 2)) {
                    209:                 my $sumdiff = $sumright - $sumleft;
                    210:                 if ($sumdiff > 0) {
                    211:                     $colend = $crossover + 1;
                    212:                 } else {
                    213:                     $colend = $crossover;
                    214:                 }
                    215:             } else {
                    216:                 $colend = @items;
                    217:             }
                    218:             $r->print('<p><table class="LC_double_column"><tr><td class="LC_left_col">');
                    219:             for (my $i=0; $i<$colend; $i++) {
                    220:                 $r->print($output{$items[$i]});
                    221:             }
                    222:             $r->print('</td><td></td><td class="LC_right_col">');
                    223:             if ($colend < @items) {
                    224:                 for (my $i=$colend; $i<@items; $i++) { 
                    225:                     $r->print($output{$items[$i]});
                    226:                 }
                    227:             }
                    228:             $r->print('</td></tr></table></p>');
                    229:             $r->print(&print_footer($r,$phase,'process','Save',\@actions));
                    230:         } else {
                    231:             $r->print('<input type="hidden" name="phase" value="" />'.
                    232:                       '<input type="hidden" name="numcols" value="'.
                    233:                       $env{'form.numcols'}.'" />'."\n".
                    234:                       '<span clas="LC_error">'.&mt('No settings chosen').
                    235:                       '</span>');
                    236:         }
                    237:         $r->print('</form>');
                    238:         $r->print(&Apache::loncommon::end_page());
1.1       raeburn   239:     } else {
1.3       raeburn   240:         if ($phase eq '') {
1.30      raeburn   241:             $phase = 'pickactions';
1.1       raeburn   242:         }
1.30      raeburn   243:         my %helphash;
1.3       raeburn   244:         &print_header($r,$phase);
1.21      raeburn   245:         if (keys(%domconfig) == 0) {
                    246:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29      raeburn   247:             my @ids=&Apache::lonnet::current_machine_ids();
                    248:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21      raeburn   249:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
                    250:                 my @loginimages = ('img','logo','domlogo');
                    251:                 my $custom_img_count = 0;
                    252:                 foreach my $img (@loginimages) {
                    253:                     if ($designhash{$dom.'.login.'.$img} ne '') {
                    254:                         $custom_img_count ++;
                    255:                     }
                    256:                 }
                    257:                 foreach my $role (@roles) {
                    258:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    259:                         $custom_img_count ++;
                    260:                     }
                    261:                 }
                    262:                 if ($custom_img_count > 0) {
                    263:                     my $switch_server = &check_switchserver($dom,$confname);
1.29      raeburn   264:                     $r->print(
                    265:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
                    266:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
                    267:     &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 />'.
                    268:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
                    269:                     if ($switch_server) {
1.30      raeburn   270:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29      raeburn   271:                     }
1.21      raeburn   272:                     return OK;
                    273:                 }
                    274:             }
                    275:         }
1.30      raeburn   276:         $r->print('<h3>'.&mt('Functionality to display/modify').'</h3>');
                    277:         $r->print('<script type="text/javascript">'."\n".
                    278:               &Apache::loncommon::check_uncheck_jscript()."\n".
                    279:               '</script>'."\n".'<p><input type="button" value="check all" '.
                    280:               'onclick="javascript:checkAll(document.pickactions.actions)"'.
                    281:               ' />&nbsp;&nbsp;'.
                    282:               '<input type="button" value="uncheck all" '.
                    283:               'onclick="javascript:uncheckAll(document.pickactions.actions)"'.
                    284:               ' /></p>');
                    285:         foreach my $item (@prefs_order) {
                    286:             $r->print('<p><label><input type="checkbox" name="actions" value="'.$item.'" />&nbsp;'.$prefs{$item}->{'text'}.'</label></p>');
                    287:         }
                    288:         $r->print('<h3>'.&mt('Display options').'</h3>'."\n".
                    289:                   '<p><span class="LC_nobreak">'.&mt('Display using: ')."\n".
                    290:                   '<label><input type="radio" name="numcols" value="1">'.
                    291:                   &mt('one column').'</label>&nbsp;&nbsp;'.
                    292:                   '<input type="radio" name="numcols" value="2">'.
                    293:                   &mt('two columns').'</label></span></p>');
                    294:         $r->print(&print_footer($r,$phase,'display','Go'));
                    295:         $r->print('</form>');
                    296:         $r->print(&Apache::loncommon::end_page());
1.3       raeburn   297:     }
                    298:     return OK;
                    299: }
                    300: 
                    301: sub process_changes {
1.9       raeburn   302:     my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
1.3       raeburn   303:     my $output;
                    304:     if ($action eq 'login') {
1.9       raeburn   305:         $output = &modify_login($r,$dom,$confname,%domconfig);
1.6       raeburn   306:     } elsif ($action eq 'rolecolors') {
1.9       raeburn   307:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
                    308:                                      %domconfig);
1.3       raeburn   309:     } elsif ($action eq 'quotas') {
                    310:         $output = &modify_quotas($dom,%domconfig);
                    311:     } elsif ($action eq 'autoenroll') {
                    312:         $output = &modify_autoenroll($dom,%domconfig);
                    313:     } elsif ($action eq 'autoupdate') {
                    314:         $output = &modify_autoupdate($dom,%domconfig);
1.23      raeburn   315:     } elsif ($action eq 'directorysrch') {
                    316:         $output = &modify_directorysrch($dom,%domconfig);
1.27      raeburn   317:     } elsif ($action eq 'usercreation') {
1.28      raeburn   318:         $output = &modify_usercreation($dom,%domconfig);
1.33      raeburn   319:     } elsif ($action eq 'usermodification') {
                    320:         $output = &modify_usermodification($dom,%domconfig);
1.28      raeburn   321:     } elsif ($action eq 'contacts') {
                    322:         $output = &modify_contacts($dom,%domconfig);
1.3       raeburn   323:     }
                    324:     return $output;
                    325: }
                    326: 
                    327: sub print_config_box {
1.9       raeburn   328:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30      raeburn   329:     my $rowtotal = 0;
                    330:     my $output = 
                    331:          '<table class="LC_nested_outer">
1.3       raeburn   332:           <tr>
1.30      raeburn   333:            <th align="left"><span class="LC_nobreak">'.&mt($item->{text}).
                    334:            '&nbsp;</span></th></tr>';
1.22      raeburn   335: # 
                    336: # FIXME - put the help link back in when the help files exist
                    337: #           <th>'.&mt($item->{text}).'&nbsp;'.
                    338: #           &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
                    339: #          </tr>');
1.30      raeburn   340:     $rowtotal ++;
1.28      raeburn   341:     if (($action eq 'autoupdate') || ($action eq 'rolecolors') || 
1.33      raeburn   342:         ($action eq 'usercreation') || ($action eq 'usermodification')) {
1.6       raeburn   343:         my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
1.30      raeburn   344:         $output .= '
1.3       raeburn   345:           <tr>
                    346:            <td>
                    347:             <table class="LC_nested">
                    348:              <tr class="LC_info_row">
1.6       raeburn   349:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
1.3       raeburn   350:               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.30      raeburn   351:              </tr>';
                    352:              $rowtotal ++;
1.6       raeburn   353:         if ($action eq 'autoupdate') {
1.30      raeburn   354:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28      raeburn   355:         } elsif ($action eq 'usercreation') {
1.33      raeburn   356:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
                    357:         } elsif ($action eq 'usermodification') {
                    358:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.6       raeburn   359:         } else {
1.30      raeburn   360:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6       raeburn   361:         }
1.30      raeburn   362:         $output .= '
1.6       raeburn   363:            </table>
                    364:           </td>
                    365:          </tr>
                    366:          <tr>
                    367:            <td>
                    368:             <table class="LC_nested">
                    369:              <tr class="LC_info_row">
                    370:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
                    371:               <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
1.30      raeburn   372:              </tr>';
                    373:             $rowtotal ++;
1.6       raeburn   374:         if ($action eq 'autoupdate') {
1.30      raeburn   375:             $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
1.28      raeburn   376:         } elsif ($action eq 'usercreation') {
1.34      raeburn   377:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
                    378:            </table>
                    379:           </td>
                    380:          </tr>
                    381:          <tr>
                    382:            <td>
                    383:             <table class="LC_nested">
                    384:              <tr class="LC_info_row">
                    385:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
                    386:               <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>             </tr>'.
                    387:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
                    388:             $rowtotal ++;
1.33      raeburn   389:         } elsif ($action eq 'usermodification') {
                    390:             $output .= &print_usermodification('bottom',$dom,$settings,\$rowtotal);
1.6       raeburn   391:         } else {
1.30      raeburn   392:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6       raeburn   393:            </table>
                    394:           </td>
                    395:          </tr>
                    396:          <tr>
                    397:            <td>
                    398:             <table class="LC_nested">
                    399:              <tr class="LC_info_row">
                    400:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
                    401:               <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
1.3       raeburn   402:              </tr>'.
1.30      raeburn   403:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3       raeburn   404:            </table>
                    405:           </td>
                    406:          </tr>
                    407:          <tr>
                    408:            <td>
                    409:             <table class="LC_nested">
                    410:              <tr class="LC_info_row">
1.6       raeburn   411:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
                    412:               <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
1.3       raeburn   413:              </tr>'.
1.30      raeburn   414:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
                    415:             $rowtotal += 2;
1.6       raeburn   416:         }
1.3       raeburn   417:     } else {
1.30      raeburn   418:         $output .= '
1.3       raeburn   419:           <tr>
                    420:            <td>
                    421:             <table class="LC_nested">
1.30      raeburn   422:              <tr class="LC_info_row">';
1.24      raeburn   423:         if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30      raeburn   424:             $output .= '  
                    425:               <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>';
1.6       raeburn   426:         } else {
1.30      raeburn   427:             $output .= '
                    428:               <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>';
1.6       raeburn   429:         }
1.30      raeburn   430:         $output .= '
1.3       raeburn   431:               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
1.30      raeburn   432:              </tr>';
                    433:         $rowtotal ++;      
1.3       raeburn   434:         if ($action eq 'login') {
1.30      raeburn   435:             $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal);
1.3       raeburn   436:         } elsif ($action eq 'quotas') {
1.30      raeburn   437:             $output .= &print_quotas($dom,$settings,\$rowtotal);
1.3       raeburn   438:         } elsif ($action eq 'autoenroll') {
1.30      raeburn   439:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.23      raeburn   440:         } elsif ($action eq 'directorysrch') {
1.30      raeburn   441:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28      raeburn   442:         } elsif ($action eq 'contacts') {
1.30      raeburn   443:             $output .= &print_contacts($dom,$settings,\$rowtotal);
1.27      raeburn   444:         }
1.3       raeburn   445:     }
1.30      raeburn   446:     $output .= '
1.3       raeburn   447:    </table>
                    448:   </td>
                    449:  </tr>
1.30      raeburn   450: </table><br />';
                    451:     return ($output,$rowtotal);
1.1       raeburn   452: }
                    453: 
                    454: sub print_header {
1.3       raeburn   455:     my ($r,$phase) = @_;
1.30      raeburn   456:     my $alert = &mt('You must select at least one functionality type to display.'); 
1.6       raeburn   457:     my $js = '
1.1       raeburn   458: <script type="text/javascript">
                    459: function changePage(formname,newphase) {
                    460:     formname.phase.value = newphase;
1.30      raeburn   461:     numchecked = 0;
                    462:     if (formname == document.pickactions) {
                    463:         if (formname.actions.length > 0) {
                    464:             for (var i = 0; i <formname.actions.length; i++) {
                    465:                 if (formname.actions[i].checked) {
                    466:                     numchecked ++;
                    467:                 }
                    468:             }
                    469:         } else {
                    470:             if (formname.actions.checked) {
                    471:                 numchecked ++;
                    472:             }
                    473:         }
                    474:         if (numchecked > 0) {
                    475:             formname.submit();
                    476:         } else {
                    477:             alert("'.$alert.'");
                    478:             return;
                    479:         }
                    480:     }
1.1       raeburn   481:     formname.submit();
1.30      raeburn   482: }'."\n";
                    483:     if ($phase eq 'pickactions') {
                    484:         $js .= 
                    485:             &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox',numcols => 'radio',})."\n".
                    486:             &javascript_set_colnums();
                    487:     } elsif ($phase eq 'display') {
                    488:         $js .= &color_pick_js()."\n";
                    489:     }
1.31      raeburn   490:     $js .= &Apache::loncommon::viewport_size_js().'
1.1       raeburn   491: </script>
1.6       raeburn   492: ';
1.30      raeburn   493:     my $additem;
                    494:     if ($phase eq 'pickactions') {
                    495:         my %loaditems = (
1.31      raeburn   496:                     'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);setDisplayColumns();setFormElements(document.pickactions);",
1.30      raeburn   497:                         );
                    498:         $additem = {'add_entries' => \%loaditems,};
                    499:     } else {
                    500:         my %loaditems = (
1.31      raeburn   501:                     'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);",
1.30      raeburn   502:                         );
                    503:         $additem = {'add_entries' => \%loaditems,};
                    504:     }
1.2       albertel  505:     $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
1.30      raeburn   506:                                            $js,$additem));
1.3       raeburn   507:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
1.6       raeburn   508:     $r->print('
1.8       raeburn   509: <form name="parmform" action="">
1.6       raeburn   510: <input type="hidden" name="pres_marker" />
                    511: <input type="hidden" name="pres_type" />
                    512: <input type="hidden" name="pres_value" />
                    513: </form>
                    514: ');
                    515:     $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
                    516:               ' enctype="multipart/form-data">');
1.1       raeburn   517:     return;
                    518: }
                    519: 
                    520: sub print_footer {
1.30      raeburn   521:     my ($r,$phase,$newphase,$button_text,$actions) = @_;
1.3       raeburn   522:     $button_text = &mt($button_text);
1.30      raeburn   523:     $r->print('<input type="hidden" name="phase" value="" />'.
                    524:               '<input type="hidden" name="width" value="'.
                    525:               $env{'form.width'}.'" />'.
                    526:               '<input type="hidden" name="height" value="'.
                    527:               $env{'form.height'}.'" />');
                    528:     if (($phase eq 'display') || ($phase eq 'process')) {
                    529:         if (ref($actions) eq 'ARRAY') {
                    530:             foreach my $item (@{$actions}) {
                    531:                 $r->print('<input type="hidden" name="actions" value="'.$item.'" />')."\n";
                    532:             }
                    533:         }
                    534:         $r->print('<input type="hidden" name="numcols" value="'.$env{'form.numcols'}.'" />');
                    535:     }
1.3       raeburn   536:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
                    537:     if ($phase eq 'process') {
1.30      raeburn   538:         $r->print('<p><a href='.$dest.'>'.$button_text.'</a></p>');
1.3       raeburn   539:     } else {
1.30      raeburn   540:         my $onclick;
                    541:         if ($phase eq 'display') {
                    542:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
                    543:         } else {
                    544:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
                    545:         } 
                    546:         $r->print('<p><input type="button" name="store" value="'.
                    547:                   $button_text.'" onclick='.$onclick.' /></p>');
                    548:     }
                    549:     if ($phase eq 'process') {
                    550:         $r->print('</form>'.&Apache::loncommon::end_page());
1.3       raeburn   551:     }
1.1       raeburn   552:     return;
                    553: }
                    554: 
1.3       raeburn   555: sub print_login {
1.30      raeburn   556:     my ($dom,$confname,$phase,$settings,$rowtotal) = @_;
1.6       raeburn   557:     my %choices = &login_choices();
                    558:     my ($catalogon,$catalogoff,$adminmailon,$adminmailoff);
                    559:     $catalogon = ' checked="checked" ';
                    560:     $adminmailoff = ' checked="checked" ';
                    561:     my @images = ('img','logo','domlogo');
                    562:     my @bgs = ('pgbg','mainbg','sidebg');
                    563:     my @links = ('link','alink','vlink');
1.7       albertel  564:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn   565:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                    566:     my (%is_custom,%designs);
                    567:     my %defaults = (
                    568:                    font => $defaultdesign{'login.font'},
                    569:                    );
                    570:     foreach my $item (@images) {
                    571:         $defaults{$item} = $defaultdesign{'login.'.$item};
                    572:     }
                    573:     foreach my $item (@bgs) {
                    574:         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
                    575:     }
                    576:     foreach my $item (@links) {
                    577:         $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
                    578:     }
1.3       raeburn   579:     if (ref($settings) eq 'HASH') {
                    580:         if ($settings->{'coursecatalog'} eq '0') {
1.1       raeburn   581:             $catalogoff = $catalogon;
                    582:             $catalogon = ' ';
                    583:         }
1.3       raeburn   584:         if ($settings->{'adminmail'} eq '1') {
1.1       raeburn   585:             $adminmailon = $adminmailoff;
                    586:             $adminmailoff = ' ';
                    587:         }
1.6       raeburn   588:         foreach my $item (@images) {
                    589:             if ($settings->{$item} ne '') {
                    590:                 $designs{$item} = $settings->{$item};
                    591:                 $is_custom{$item} = 1;
                    592:             }
                    593:         }
                    594:         if ($settings->{'font'} ne '') {
                    595:             $designs{'font'} = $settings->{'font'};
                    596:             $is_custom{'font'} = 1;
                    597:         }
                    598:         foreach my $item (@bgs) {
                    599:             if ($settings->{$item} ne '') {
                    600:                 $designs{'bgs'}{$item} = $settings->{$item};
                    601:                 $is_custom{$item} = 1;
                    602:             }
                    603:         }
                    604:         foreach my $item (@links) {
                    605:             if ($settings->{$item} ne '') {
                    606:                 $designs{'links'}{$item} = $settings->{$item};
                    607:                 $is_custom{$item} = 1;
                    608:             }
                    609:         }
                    610:     } else {
                    611:         if ($designhash{$dom.'.login.font'} ne '') {
                    612:             $designs{'font'} = $designhash{$dom.'.login.font'};
                    613:             $is_custom{'font'} = 1;
                    614:         }
1.8       raeburn   615:         foreach my $item (@images) {
                    616:             if ($designhash{$dom.'.login.'.$item} ne '') {
                    617:                 $designs{$item} = $designhash{$dom.'.login.'.$item};
                    618:                 $is_custom{$item} = 1;
                    619:             }
                    620:         }
1.6       raeburn   621:         foreach my $item (@bgs) {
                    622:             if ($designhash{$dom.'.login.'.$item} ne '') {
                    623:                 $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
                    624:                 $is_custom{$item} = 1;
                    625:             }
                    626:         }
                    627:         foreach my $item (@links) {
                    628:             if ($designhash{$dom.'.login.'.$item} ne '') {
                    629:                 $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
                    630:                 $is_custom{$item} = 1;
                    631:             }
                    632:         }
1.1       raeburn   633:     }
1.6       raeburn   634:     my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
                    635:                                                   logo => 'Institution Logo',
                    636:                                                   domlogo => 'Domain Logo');
                    637:     my $itemcount = 1;
                    638:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.3       raeburn   639:     my $datatable = 
1.6       raeburn   640:         '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
                    641:         '</td><td>'.
1.8       raeburn   642:         '<span class="LC_nobreak"><label><input type="radio" name="coursecatalog"'.
                    643:         $catalogon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                    644:         '<label><input type="radio" name="coursecatalog"'.
                    645:         $catalogoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.6       raeburn   646:         '</tr>';
                    647:     $itemcount ++;
                    648:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                    649:     $datatable .= '<tr'.$css_class.'>'.
                    650:         '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
1.8       raeburn   651:         '<td><span class="LC_nobreak">'.
                    652:         '<label><input type="radio" name="adminmail"'.
                    653:         $adminmailon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                    654:         '<label><input type="radio" name="adminmail"'.
                    655:         $adminmailoff.'value="0" />'.&mt('No').'</label></span></td></tr>';
1.6       raeburn   656:     $itemcount ++;
1.30      raeburn   657:     $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn   658:     $datatable .= '</tr></table></td></tr>';
                    659:     return $datatable;
                    660: }
                    661: 
                    662: sub login_choices {
                    663:     my %choices =
                    664:         &Apache::lonlocal::texthash (
                    665:             coursecatalog => 'Display Course Catalog link?',
                    666:             adminmail => "Display Administrator's E-mail Address?",
                    667:             img => "Header",
                    668:             logo => "Main Logo",
                    669:             domlogo => "Domain Logo",
                    670:             bgs => "Background colors",
                    671:             links => "Link colors",
                    672:             font => "Font color",
                    673:             pgbg => "Page",
                    674:             mainbg => "Main panel",
                    675:             sidebg => "Side panel",
                    676:             link => "Link",
                    677:             alink => "Active link",
                    678:             vlink => "Visited link",
                    679:         );
                    680:     return %choices;
                    681: }
                    682: 
                    683: sub print_rolecolors {
1.30      raeburn   684:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6       raeburn   685:     my %choices = &color_font_choices();
                    686:     my @bgs = ('pgbg','tabbg','sidebg');
                    687:     my @links = ('link','alink','vlink');
                    688:     my @images = ('img');
                    689:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7       albertel  690:     my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6       raeburn   691:     my %defaultdesign = %Apache::loncommon::defaultdesign;
                    692:     my (%is_custom,%designs);
                    693:     my %defaults = (
                    694:                    img => $defaultdesign{$role.'.img'},
                    695:                    font => $defaultdesign{$role.'.font'},
                    696:                    );
                    697:     foreach my $item (@bgs) {
                    698:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
                    699:     }
                    700:     foreach my $item (@links) {
                    701:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
                    702:     }
                    703:     if (ref($settings) eq 'HASH') {
                    704:         if (ref($settings->{$role}) eq 'HASH') {
                    705:             if ($settings->{$role}->{'img'} ne '') {
                    706:                 $designs{'img'} = $settings->{$role}->{'img'};
                    707:                 $is_custom{'img'} = 1;
                    708:             }
                    709:             if ($settings->{$role}->{'font'} ne '') {
                    710:                 $designs{'font'} = $settings->{$role}->{'font'};
                    711:                 $is_custom{'font'} = 1;
                    712:             }
                    713:             foreach my $item (@bgs) {
                    714:                 if ($settings->{$role}->{$item} ne '') {
                    715:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
                    716:                     $is_custom{$item} = 1;
                    717:                 }
                    718:             }
                    719:             foreach my $item (@links) {
                    720:                 if ($settings->{$role}->{$item} ne '') {
                    721:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
                    722:                     $is_custom{$item} = 1;
                    723:                 }
                    724:             }
                    725:         }
                    726:     } else {
                    727:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
                    728:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
                    729:             $is_custom{'img'} = 1;
                    730:         }
                    731:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
                    732:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
                    733:             $is_custom{'font'} = 1;
                    734:         }
                    735:         foreach my $item (@bgs) {
                    736:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                    737:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                    738:                 $is_custom{$item} = 1;
                    739:             
                    740:             }
                    741:         }
                    742:         foreach my $item (@links) {
                    743:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
                    744:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
                    745:                 $is_custom{$item} = 1;
                    746:             }
                    747:         }
                    748:     }
                    749:     my $itemcount = 1;
1.30      raeburn   750:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6       raeburn   751:     $datatable .= '</tr></table></td></tr>';
                    752:     return $datatable;
                    753: }
                    754: 
                    755: sub display_color_options {
1.9       raeburn   756:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.30      raeburn   757:         $images,$bgs,$links,$alt_text,$rowtotal) = @_;
1.6       raeburn   758:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                    759:     my $datatable = '<tr'.$css_class.'>'.
                    760:         '<td>'.$choices->{'font'}.'</td>';
                    761:     if (!$is_custom->{'font'}) {
1.30      raeburn   762:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6       raeburn   763:     } else {
                    764:         $datatable .= '<td>&nbsp;</td>';
                    765:     }
                    766:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
1.8       raeburn   767:     $datatable .= '<td><span class="LC_nobreak">'.
1.6       raeburn   768:                   '<input type="text" size="10" name="'.$role.'_font"'.
1.8       raeburn   769:                   ' value="'.$designs->{'font'}.'" />&nbsp;'.$fontlink.
1.30      raeburn   770:                   '&nbsp;<span id="css_'.$role.'_font" style="background-color: '.
                    771:                   $designs->{'font'}.';">&nbsp;&nbsp;&nbsp;</span>'.
1.8       raeburn   772:                   '</span></td></tr>';
1.9       raeburn   773:     my $switchserver = &check_switchserver($dom,$confname);
1.6       raeburn   774:     foreach my $img (@{$images}) {
1.18      albertel  775: 	$itemcount ++;
1.6       raeburn   776:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8       raeburn   777:         $datatable .= '<tr'.$css_class.'>'.
1.6       raeburn   778:                       '<td>'.$choices->{$img}.'</td>';
1.18      albertel  779:         my ($imgfile, $img_import);
1.6       raeburn   780:         if ($designs->{$img} ne '') {
                    781:             $imgfile = $designs->{$img};
1.18      albertel  782: 	    $img_import = ($imgfile =~ m{^/adm/});
1.6       raeburn   783:         } else {
                    784:             $imgfile = $defaults->{$img};
                    785:         }
                    786:         if ($imgfile) {
1.9       raeburn   787:             my ($showfile,$fullsize);
                    788:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6       raeburn   789:                 my $urldir = $1;
                    790:                 my $filename = $2;
                    791:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
                    792:                 if (@info) {
                    793:                     my $thumbfile = 'tn-'.$filename;
                    794:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
                    795:                     if (@thumb) {
                    796:                         $showfile = $urldir.'/'.$thumbfile;
                    797:                     } else {
                    798:                         $showfile = $imgfile;
                    799:                     }
                    800:                 } else {
                    801:                     $showfile = '';
                    802:                 }
                    803:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16      raeburn   804:                 $showfile = $imgfile;
1.6       raeburn   805:                 my $imgdir = $1;
                    806:                 my $filename = $2;
                    807:                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
                    808:                     $showfile = "/$imgdir/tn-".$filename;
                    809:                 } else {
                    810:                     my $input = "/home/httpd/html".$imgfile;
                    811:                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
                    812:                     if (!-e $output) {
1.9       raeburn   813:                         my ($width,$height) = &thumb_dimensions();
1.16      raeburn   814:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
                    815:                         if ($fullwidth ne '' && $fullheight ne '') {
                    816:                             if ($fullwidth > $width && $fullheight > $height) { 
                    817:                                 my $size = $width.'x'.$height;
                    818:                                 system("convert -sample $size $input $output");
                    819:                                 $showfile = '/'.$imgdir.'/tn-'.$filename;
                    820:                             }
                    821:                         }
1.6       raeburn   822:                     }
                    823:                 }
1.16      raeburn   824:             }
1.6       raeburn   825:             if ($showfile) {
1.9       raeburn   826:                 $showfile = &Apache::loncommon::lonhttpdurl($showfile);
                    827:                 $fullsize =  &Apache::loncommon::lonhttpdurl($imgfile);
1.6       raeburn   828:                 $datatable.= '<td>';
                    829:                 if (!$is_custom->{$img}) {
                    830:                     $datatable .= &mt('Default in use:').'<br />';
                    831:                 }
1.18      albertel  832: 		if ($img_import) {
                    833: 		    $datatable.= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
                    834: 		}
1.9       raeburn   835:                 $datatable.= '<a href="'.$fullsize.'" target="_blank"><img src="'.
                    836:                              $showfile.'" alt="'.$alt_text->{$img}.
                    837:                              '" border="0" /></a></td>';
1.6       raeburn   838:                 if ($is_custom->{$img}) {
1.8       raeburn   839:                     $datatable.='<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
                    840:                                 $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
                    841:                                 '</label>&nbsp;'.&mt('Replace:').'</span><br />';
1.6       raeburn   842:                 } else {
                    843:                     $datatable.='<td valign="bottom">'.&mt('Upload:').'<br />';
                    844:                 }
                    845:             } else {
                    846:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                    847:                               &mt('Upload:');
                    848:             }
                    849:         } else {
                    850:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
                    851:                           &mt('Upload:');
                    852:         }
1.9       raeburn   853:         if ($switchserver) {
                    854:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
                    855:         } else {
                    856:             $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
                    857:         }
                    858:         $datatable .= '</td></tr>';
1.6       raeburn   859:     }
                    860:     $itemcount ++;
                    861:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                    862:     $datatable .= '<tr'.$css_class.'>'.
                    863:                   '<td>'.$choices->{'bgs'}.'</td>';
                    864:     my $bgs_def;
                    865:     foreach my $item (@{$bgs}) {
                    866:         if (!$is_custom->{$item}) {
1.30      raeburn   867:             $bgs_def .= '<td>'.$choices->{$item}.'&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   868:         }
                    869:     }
                    870:     if ($bgs_def) {
1.8       raeburn   871:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6       raeburn   872:     } else {
                    873:         $datatable .= '<td>&nbsp;</td>';
                    874:     }
                    875:     $datatable .= '<td class="LC_right_item">'.
                    876:                   '<table border="0"><tr>';
                    877:     foreach my $item (@{$bgs}) {
                    878:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
                    879:         $datatable .= '<td align="center">'.$link;
                    880:         if ($designs->{'bgs'}{$item}) {
1.30      raeburn   881:             $datatable .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
1.6       raeburn   882:         }
                    883:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
1.30      raeburn   884:                       '" onblur = "javascript:document.display.css_'.$role.'_'.$item.'.style.background-color = document.display.'.$role.'_'.$item.'.value;"/></td>';
1.6       raeburn   885:     }
                    886:     $datatable .= '</tr></table></td></tr>';
                    887:     $itemcount ++;
                    888:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
                    889:     $datatable .= '<tr'.$css_class.'>'.
                    890:                   '<td>'.$choices->{'links'}.'</td>';
                    891:     my $links_def;
                    892:     foreach my $item (@{$links}) {
                    893:         if (!$is_custom->{$item}) {
1.30      raeburn   894:             $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   895:         }
                    896:     }
                    897:     if ($links_def) {
1.8       raeburn   898:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6       raeburn   899:     } else {
                    900:         $datatable .= '<td>&nbsp;</td>';
                    901:     }
                    902:     $datatable .= '<td class="LC_right_item">'.
                    903:                   '<table border="0"><tr>';
                    904:     foreach my $item (@{$links}) {
1.30      raeburn   905:         $datatable .= '<td align="center">'."\n".
                    906:                       &color_pick($phase,$role,$item,$choices->{$item},
                    907:                                   $designs->{'links'}{$item});
1.6       raeburn   908:         if ($designs->{'links'}{$item}) {
1.30      raeburn   909:             $datatable.='&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
1.6       raeburn   910:         }
                    911:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
                    912:                       '" /></td>';
                    913:     }
1.30      raeburn   914:     $$rowtotal += $itemcount;
1.3       raeburn   915:     return $datatable;
                    916: }
                    917: 
1.6       raeburn   918: sub color_pick {
                    919:     my ($phase,$role,$item,$desc,$curcol) = @_;
                    920:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
                    921:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
                    922:                ');">'.$desc.'</a>';
                    923:     return $link;
                    924: }
                    925: 
                    926: sub color_pick_js {
                    927:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
                    928:     my $output = <<"ENDCOL";
                    929:     function pclose() {
                    930:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
                    931:         parmwin.close();
                    932:     }
                    933: 
                    934:     $pjump_def
                    935: 
                    936:     function psub() {
                    937:         pclose();
                    938:         if (document.parmform.pres_marker.value!='') {
                    939:             if (document.parmform.pres_type.value!='') {
                    940:                 eval('document.display.'+
                    941:                      document.parmform.pres_marker.value+
                    942:                      '.value=document.parmform.pres_value.value;');
                    943:             }
                    944:         } else {
                    945:             document.parmform.pres_value.value='';
                    946:             document.parmform.pres_marker.value='';
                    947:         }
                    948:     }
                    949: ENDCOL
                    950:     return $output;
                    951: }
                    952: 
1.3       raeburn   953: sub print_quotas {
1.30      raeburn   954:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn   955:     my $datatable;
1.23      raeburn   956:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.3       raeburn   957:     my $typecount = 0;
                    958:     my $css_class;
1.26      raeburn   959:     if (ref($types) eq 'ARRAY') {
1.23      raeburn   960:         foreach my $type (@{$types}) {
1.3       raeburn   961:             if (defined($usertypes->{$type})) {
                    962:                 $typecount ++;
                    963:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
                    964:                 $datatable .= '<tr'.$css_class.'>'. 
                    965:                               '<td>'.$usertypes->{$type}.'</td>'.
1.8       raeburn   966:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn   967:                               '<input type="text" name="quota_'.$type.
                    968:                               '" value="'.$settings->{$type}.
1.8       raeburn   969:                               '" size="5" /> Mb</span></td></tr>';
1.3       raeburn   970:             }
                    971:         }
                    972:     }
                    973:     my $defaultquota = '20';
                    974:     if (ref($settings) eq 'HASH') {
                    975:         if (defined($settings->{'default'})) {
                    976:             $defaultquota = $settings->{'default'};
                    977:         }
                    978:     }
                    979:     $typecount ++;
                    980:     $css_class = $typecount%2?' class="LC_odd_row"':'';
                    981:     $datatable .= '<tr'.$css_class.'>'.
1.26      raeburn   982:                   '<td>'.$othertitle.'</td>'.
1.8       raeburn   983:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
1.15      raeburn   984:                   '<input type="text" name="defaultquota" value="'.
1.8       raeburn   985:                   $defaultquota.'" size="5" /> Mb</span></td></tr>';
1.30      raeburn   986:     $$rowtotal += $typecount;
1.3       raeburn   987:     return $datatable;
                    988: }
                    989: 
                    990: sub print_autoenroll {
1.30      raeburn   991:     my ($dom,$settings,$rowtotal) = @_;
1.3       raeburn   992:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.17      raeburn   993:     my ($defdom,$runon,$runoff);
1.3       raeburn   994:     if (ref($settings) eq 'HASH') {
                    995:         if (exists($settings->{'run'})) {
                    996:             if ($settings->{'run'} eq '0') {
                    997:                 $runoff = ' checked="checked" ';
                    998:                 $runon = ' ';
                    999:             } else {
                   1000:                 $runon = ' checked="checked" ';
                   1001:                 $runoff = ' ';
                   1002:             }
                   1003:         } else {
                   1004:             if ($autorun) {
                   1005:                 $runon = ' checked="checked" ';
                   1006:                 $runoff = ' ';
                   1007:             } else {
                   1008:                 $runoff = ' checked="checked" ';
                   1009:                 $runon = ' ';
                   1010:             }
                   1011:         }
                   1012:         if (exists($settings->{'sender_domain'})) {
                   1013:             $defdom = $settings->{'sender_domain'};
                   1014:         }
1.14      raeburn  1015:     } else {
                   1016:         if ($autorun) {
                   1017:             $runon = ' checked="checked" ';
                   1018:             $runoff = ' ';
                   1019:         } else {
                   1020:             $runoff = ' checked="checked" ';
                   1021:             $runon = ' ';
                   1022:         }
1.3       raeburn  1023:     }
                   1024:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
                   1025:     my $datatable='<tr class="LC_odd_row">'.
                   1026:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8       raeburn  1027:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  1028:                   '<input type="radio" name="autoenroll_run"'.
1.8       raeburn  1029:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1030:                   '<label><input type="radio" name="autoenroll_run"'.
1.14      raeburn  1031:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  1032:                   '</tr><tr>'.
                   1033:                   '<td>'.&mt('Notification messages - sender').
1.8       raeburn  1034:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3       raeburn  1035:                   &mt('username').':&nbsp;'.
                   1036:                   '<input type="text" name="sender_uname" value="'.
                   1037:                   $settings->{'sender_uname'}.
                   1038:                   '" size="10" />&nbsp;&nbsp;'.&mt('domain').
1.8       raeburn  1039:                   ':&nbsp;'.$domform.'</span></td></tr>';
1.30      raeburn  1040:     $$rowtotal += 2;
1.3       raeburn  1041:     return $datatable;
                   1042: }
                   1043: 
                   1044: sub print_autoupdate {
1.30      raeburn  1045:     my ($position,$dom,$settings,$rowtotal) = @_;
1.3       raeburn  1046:     my $datatable;
                   1047:     if ($position eq 'top') {
                   1048:         my $updateon = ' ';
                   1049:         my $updateoff = ' checked="checked" ';
                   1050:         my $classlistson = ' ';
                   1051:         my $classlistsoff = ' checked="checked" ';
                   1052:         if (ref($settings) eq 'HASH') {
                   1053:             if ($settings->{'run'} eq '1') {
                   1054:                 $updateon = $updateoff;
                   1055:                 $updateoff = ' ';
                   1056:             }
                   1057:             if ($settings->{'classlists'} eq '1') {
                   1058:                 $classlistson = $classlistsoff;
                   1059:                 $classlistsoff = ' ';
                   1060:             }
                   1061:         }
                   1062:         my %title = (
                   1063:                    run => 'Auto-update active?',
                   1064:                    classlists => 'Update information in classlists?',
                   1065:                     );
                   1066:         $datatable = '<tr class="LC_odd_row">'. 
                   1067:                   '<td>'.&mt($title{'run'}).'</td>'.
1.8       raeburn  1068:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3       raeburn  1069:                   '<input type="radio" name="autoupdate_run"'.
1.8       raeburn  1070:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1071:                   '<label><input type="radio" name="autoupdate_run"'.
                   1072:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  1073:                   '</tr><tr>'.
                   1074:                   '<td>'.&mt($title{'classlists'}).'</td>'.
1.8       raeburn  1075:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
                   1076:                   '<label><input type="radio" name="classlists"'.
                   1077:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1078:                   '<label><input type="radio" name="classlists"'.
                   1079:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3       raeburn  1080:                   '</tr>';
1.30      raeburn  1081:         $$rowtotal += 2;
1.3       raeburn  1082:     } else {
1.23      raeburn  1083:         my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.20      raeburn  1084:         my @fields = ('lastname','firstname','middlename','gen',
                   1085:                       'permanentemail','id');
1.33      raeburn  1086:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3       raeburn  1087:         my $numrows = 0;
1.26      raeburn  1088:         if (ref($types) eq 'ARRAY') {
                   1089:             if (@{$types} > 0) {
                   1090:                 $datatable = 
                   1091:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
                   1092:                                          \@fields,$types,\$numrows);
1.30      raeburn  1093:                     $$rowtotal += @{$types}; 
1.26      raeburn  1094:             }
1.3       raeburn  1095:         }
                   1096:         $datatable .= 
                   1097:             &usertype_update_row($settings,{'default' => $othertitle},
                   1098:                                  \%fieldtitles,\@fields,['default'],
                   1099:                                  \$numrows);
1.30      raeburn  1100:         $$rowtotal ++;     
1.3       raeburn  1101:     }
                   1102:     return $datatable;
                   1103: }
                   1104: 
1.23      raeburn  1105: sub print_directorysrch {
1.30      raeburn  1106:     my ($dom,$settings,$rowtotal) = @_;
1.23      raeburn  1107:     my $srchon = ' ';
                   1108:     my $srchoff = ' checked="checked" ';
1.25      raeburn  1109:     my ($exacton,$containson,$beginson);
1.24      raeburn  1110:     my $localon = ' ';
                   1111:     my $localoff = ' checked="checked" ';
1.23      raeburn  1112:     if (ref($settings) eq 'HASH') {
                   1113:         if ($settings->{'available'} eq '1') {
                   1114:             $srchon = $srchoff;
                   1115:             $srchoff = ' ';
                   1116:         }
1.24      raeburn  1117:         if ($settings->{'localonly'} eq '1') {
                   1118:             $localon = $localoff;
                   1119:             $localoff = ' ';
                   1120:         }
1.25      raeburn  1121:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
                   1122:             foreach my $type (@{$settings->{'searchtypes'}}) {
                   1123:                 if ($type eq 'exact') {
                   1124:                     $exacton = ' checked="checked" ';
                   1125:                 } elsif ($type eq 'contains') {
                   1126:                     $containson = ' checked="checked" ';
                   1127:                 } elsif ($type eq 'begins') {
                   1128:                     $beginson = ' checked="checked" ';
                   1129:                 }
                   1130:             }
                   1131:         } else {
                   1132:             if ($settings->{'searchtypes'} eq 'exact') {
                   1133:                 $exacton = ' checked="checked" ';
                   1134:             } elsif ($settings->{'searchtypes'} eq 'contains') {
                   1135:                 $containson = ' checked="checked" ';
                   1136:             } elsif ($settings->{'searchtypes'} eq 'specify') {
                   1137:                 $exacton = ' checked="checked" ';
                   1138:                 $containson = ' checked="checked" ';
                   1139:             }
1.23      raeburn  1140:         }
                   1141:     }
                   1142:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   1143:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
                   1144: 
                   1145:     my $numinrow = 4;
1.26      raeburn  1146:     my $cansrchrow = 0;
1.23      raeburn  1147:     my $datatable='<tr class="LC_odd_row">'.
1.30      raeburn  1148:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23      raeburn  1149:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   1150:                   '<input type="radio" name="dirsrch_available"'.
                   1151:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
                   1152:                   '<label><input type="radio" name="dirsrch_available"'.
                   1153:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
                   1154:                   '</tr><tr>'.
1.30      raeburn  1155:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24      raeburn  1156:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
                   1157:                   '<input type="radio" name="dirsrch_localonly"'.
                   1158:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
                   1159:                   '<label><input type="radio" name="dirsrch_localonly"'.
                   1160:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25      raeburn  1161:                   '</tr>';
1.30      raeburn  1162:     $$rowtotal += 2;
1.26      raeburn  1163:     if (ref($usertypes) eq 'HASH') {
                   1164:         if (keys(%{$usertypes}) > 0) {
                   1165:             $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
                   1166:                                                $numinrow,$othertitle);
                   1167:             $cansrchrow = 1;
                   1168:         }
                   1169:     }
                   1170:     if ($cansrchrow) {
1.30      raeburn  1171:         $$rowtotal ++;
1.26      raeburn  1172:         $datatable .= '<tr>';
                   1173:     } else {
                   1174:         $datatable .= '<tr class="LC_odd_row">';
                   1175:     }
1.30      raeburn  1176:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
                   1177:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25      raeburn  1178:     foreach my $title (@{$titleorder}) {
                   1179:         if (defined($searchtitles->{$title})) {
                   1180:             my $check = ' ';
                   1181:             if (ref($settings->{'searchby'}) eq 'ARRAY') {
                   1182:                 if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
                   1183:                     $check = ' checked="checked" ';
                   1184:                 }
                   1185:             }
                   1186:             $datatable .= '<td class="LC_left_item">'.
                   1187:                           '<span class="LC_nobreak"><label>'.
                   1188:                           '<input type="checkbox" name="searchby" '.
                   1189:                           'value="'.$title.'"'.$check.'/>'.
                   1190:                           $searchtitles->{$title}.'</label></span></td>';
                   1191:         }
                   1192:     }
1.26      raeburn  1193:     $datatable .= '</tr></table></td></tr>';
1.30      raeburn  1194:     $$rowtotal ++;
1.26      raeburn  1195:     if ($cansrchrow) {
                   1196:         $datatable .= '<tr class="LC_odd_row">';
                   1197:     } else {
                   1198:         $datatable .= '<tr>';
                   1199:     }
1.30      raeburn  1200:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
1.26      raeburn  1201:                   '<td class="LC_left_item" colspan="2">'.
1.25      raeburn  1202:                   '<span class="LC_nobreak"><label>'.
                   1203:                   '<input type="checkbox" name="searchtypes" '.
                   1204:                   $exacton.' value="exact" />'.&mt('Exact match').
                   1205:                   '</label>&nbsp;'.
                   1206:                   '<label><input type="checkbox" name="searchtypes" '.
                   1207:                   $beginson.' value="begins" />'.&mt('Begins with').
                   1208:                   '</label>&nbsp;'.
                   1209:                   '<label><input type="checkbox" name="searchtypes" '.
                   1210:                   $containson.' value="contains" />'.&mt('Contains').
                   1211:                   '</label></span></td></tr>';
1.30      raeburn  1212:     $$rowtotal ++;
1.25      raeburn  1213:     return $datatable;
                   1214: }
                   1215: 
1.28      raeburn  1216: sub print_contacts {
1.30      raeburn  1217:     my ($dom,$settings,$rowtotal) = @_;
1.28      raeburn  1218:     my $datatable;
                   1219:     my @contacts = ('adminemail','supportemail');
                   1220:     my (%checked,%to,%otheremails);
                   1221:     my @mailings = ('errormail','packagesmail','helpdeskmail');
                   1222:     foreach my $type (@mailings) {
                   1223:         $otheremails{$type} = '';
                   1224:     }
                   1225:     if (ref($settings) eq 'HASH') {
                   1226:         foreach my $item (@contacts) {
                   1227:             if (exists($settings->{$item})) {
                   1228:                 $to{$item} = $settings->{$item};
                   1229:             }
                   1230:         }
                   1231:         foreach my $type (@mailings) {
                   1232:             if (exists($settings->{$type})) {
                   1233:                 if (ref($settings->{$type}) eq 'HASH') {
                   1234:                     foreach my $item (@contacts) {
                   1235:                         if ($settings->{$type}{$item}) {
                   1236:                             $checked{$type}{$item} = ' checked="checked" ';
                   1237:                         }
                   1238:                     }
                   1239:                     $otheremails{$type} = $settings->{$type}{'others'};
                   1240:                 }
                   1241:             }
                   1242:         }
                   1243:     } else {
                   1244:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   1245:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   1246:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
                   1247:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
                   1248:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" '; 
                   1249:     }
                   1250:     my ($titles,$short_titles) = &contact_titles();
                   1251:     my $rownum = 0;
                   1252:     my $css_class;
                   1253:     foreach my $item (@contacts) {
                   1254:         if ($rownum%2) {
                   1255:             $css_class = '';
                   1256:         } else {
                   1257:             $css_class = ' class="LC_odd_row" ';
                   1258:         }
1.30      raeburn  1259:         $datatable .= '<tr'.$css_class.'>'. 
                   1260:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
                   1261:                   '</span></td><td class="LC_right_item">'.
1.28      raeburn  1262:                   '<input type="text" name="'.$item.'" value="'.
                   1263:                   $to{$item}.'" /></td></tr>';
                   1264:         $rownum ++;
                   1265:     }
                   1266:     foreach my $type (@mailings) {
                   1267:         if ($rownum%2) {
                   1268:             $css_class = '';
                   1269:         } else {
                   1270:             $css_class = ' class="LC_odd_row" ';
                   1271:         }
                   1272:         $datatable .= '<tr'.$css_class.'>'.
1.30      raeburn  1273:                       '<td><span class="LC_nobreak">'.
                   1274:                       $titles->{$type}.': </span></td>'.
1.28      raeburn  1275:                       '<td class="LC_left_item">'.
                   1276:                       '<span class="LC_nobreak">';
                   1277:         foreach my $item (@contacts) {
                   1278:             $datatable .= '<label>'.
                   1279:                           '<input type="checkbox" name="'.$type.'"'.
                   1280:                           $checked{$type}{$item}.
                   1281:                           ' value="'.$item.'" />'.$short_titles->{$item}.
                   1282:                           '</label>&nbsp;';
                   1283:         }
                   1284:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
                   1285:                       '<input type="text" name="'.$type.'_others" '.
                   1286:                       'value="'.$otheremails{$type}.'"  />'.
                   1287:                       '</td></tr>'."\n";
                   1288:         $rownum ++;
                   1289:     }
1.30      raeburn  1290:     $$rowtotal += $rownum;
1.28      raeburn  1291:     return $datatable;
                   1292: }
                   1293: 
                   1294: sub contact_titles {
                   1295:     my %titles = &Apache::lonlocal::texthash (
                   1296:                    'supportemail' => 'Support E-mail address',
                   1297:                    'adminemail'    => 'Default Server Admin E-mail address',
                   1298:                    'errormail'    => 'Error reports to be e-mailed to',
                   1299:                    'packagesmail' => 'Package update alerts to be e-mailed to',
                   1300:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
                   1301:                  );
                   1302:     my %short_titles = &Apache::lonlocal::texthash (
                   1303:                            adminemail   => 'Admin E-mail address',
                   1304:                            supportemail => 'Support E-mail',
                   1305:                        );   
                   1306:     return (\%titles,\%short_titles);
                   1307: }
                   1308: 
1.27      raeburn  1309: sub print_usercreation {
1.30      raeburn  1310:     my ($position,$dom,$settings,$rowtotal) = @_;
1.27      raeburn  1311:     my $numinrow = 4;
1.28      raeburn  1312:     my $datatable;
                   1313:     if ($position eq 'top') {
1.30      raeburn  1314:         $$rowtotal ++;
1.34      raeburn  1315:         my $rowcount = 0;
1.32      raeburn  1316:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28      raeburn  1317:         if (ref($rules) eq 'HASH') {
                   1318:             if (keys(%{$rules}) > 0) {
1.32      raeburn  1319:                 $datatable .= &user_formats_row('username',$settings,$rules,
                   1320:                                                 $ruleorder,$numinrow,$rowcount);
1.30      raeburn  1321:                 $$rowtotal ++;
1.32      raeburn  1322:                 $rowcount ++;
                   1323:             }
                   1324:         }
                   1325:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
                   1326:         if (ref($idrules) eq 'HASH') {
                   1327:             if (keys(%{$idrules}) > 0) {
                   1328:                 $datatable .= &user_formats_row('id',$settings,$idrules,
                   1329:                                                 $idruleorder,$numinrow,$rowcount);
                   1330:                 $$rowtotal ++;
                   1331:                 $rowcount ++;
1.28      raeburn  1332:             }
                   1333:         }
1.34      raeburn  1334:     } elsif ($position eq 'middle') {
                   1335:         my @creators = ('author','course');
                   1336:         my %lt = &usercreation_types();
                   1337:         my %checked;
                   1338:         if (ref($settings) eq 'HASH') {
                   1339:             if (ref($settings->{'cancreate'}) eq 'HASH') {
                   1340:                 foreach my $item (@creators) {
                   1341:                     $checked{$item} = $settings->{'cancreate'}{$item};
                   1342:                 }
                   1343:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
                   1344:                 foreach my $item (@creators) {
                   1345:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
                   1346:                         $checked{$item} = 'none';
                   1347:                     }
                   1348:                 }
                   1349:             }
                   1350:         }
                   1351:         my $rownum = 0;
                   1352:         foreach my $item (@creators) {
                   1353:             $rownum ++;
                   1354:             if ($checked{$item} eq '') {
                   1355:                 $checked{$item} = 'any';
                   1356:             }
                   1357:             my $css_class;
                   1358:             if ($rownum%2) {
                   1359:                 $css_class = '';
                   1360:             } else {
                   1361:                 $css_class = ' class="LC_odd_row" ';
                   1362:             }
                   1363:             $datatable .= '<tr'.$css_class.'>'.
                   1364:                          '<td><span class="LC_nobreak">'.$lt{$item}.
                   1365:                          '</span></td><td align="right">';
                   1366:             foreach my $option ('any','official','unofficial','none') {
                   1367:                 my $check = ' ';
                   1368:                 if ($checked{$item} eq $option) {
                   1369:                     $check = ' checked="checked" ';
                   1370:                 } 
                   1371:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1372:                               '<input type="radio" name="can_createuser_'.
                   1373:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
                   1374:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
                   1375:             }
                   1376:             $datatable .= '</td></tr>';
                   1377:         }
1.28      raeburn  1378:     } else {
                   1379:         my @contexts = ('author','course','domain');
                   1380:         my @authtypes = ('int','krb4','krb5','loc');
                   1381:         my %checked;
                   1382:         if (ref($settings) eq 'HASH') {
                   1383:             if (ref($settings->{'authtypes'}) eq 'HASH') {
                   1384:                 foreach my $item (@contexts) {
                   1385:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
                   1386:                         foreach my $auth (@authtypes) {
                   1387:                             if ($settings->{'authtypes'}{$item}{$auth}) {
                   1388:                                 $checked{$item}{$auth} = ' checked="checked" ';
                   1389:                             }
                   1390:                         }
                   1391:                     }
                   1392:                 }
1.27      raeburn  1393:             }
1.35    ! raeburn  1394:         } else {
        !          1395:             foreach my $item (@contexts) {
        !          1396:                 foreach my $type (@authtypes) {
        !          1397:                     $checked{$item}{$auth} = ' checked="checked" ';
        !          1398:                 }
        !          1399:             }
1.27      raeburn  1400:         }
1.28      raeburn  1401:         my %title = &context_names();
                   1402:         my %authname = &authtype_names();
                   1403:         my $rownum = 0;
                   1404:         my $css_class; 
                   1405:         foreach my $item (@contexts) {
                   1406:             if ($rownum%2) {
                   1407:                 $css_class = '';
                   1408:             } else {
                   1409:                 $css_class = ' class="LC_odd_row" ';
                   1410:             }
1.30      raeburn  1411:             $datatable .=   '<tr'.$css_class.'>'.
1.28      raeburn  1412:                             '<td>'.$title{$item}.
                   1413:                             '</td><td class="LC_left_item">'.
                   1414:                             '<span class="LC_nobreak">';
                   1415:             foreach my $auth (@authtypes) {
                   1416:                 $datatable .= '<label>'. 
                   1417:                               '<input type="checkbox" name="'.$item.'_auth" '.
                   1418:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
                   1419:                               $authname{$auth}.'</label>&nbsp;';
                   1420:             }
                   1421:             $datatable .= '</span></td></tr>';
                   1422:             $rownum ++;
1.27      raeburn  1423:         }
1.30      raeburn  1424:         $$rowtotal += $rownum;
1.27      raeburn  1425:     }
                   1426:     return $datatable;
                   1427: }
                   1428: 
1.32      raeburn  1429: sub user_formats_row {
                   1430:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
                   1431:     my $output;
                   1432:     my %text = (
                   1433:                    'username' => 'new usernames',
                   1434:                    'id'       => 'IDs',
                   1435:                );
                   1436:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   1437:     $output = '<tr '.$css_class.'>'.
                   1438:               '<td><span class="LC_nobreak">'.
                   1439:               &mt("Format rules to check for $text{$type}: ").
                   1440:               '</span></td>'.
                   1441:               '<td class="LC_left_item" colspan="2"><table>';
1.27      raeburn  1442:     my $rem;
                   1443:     if (ref($ruleorder) eq 'ARRAY') {
                   1444:         for (my $i=0; $i<@{$ruleorder}; $i++) {
                   1445:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
                   1446:                 my $rem = $i%($numinrow);
                   1447:                 if ($rem == 0) {
                   1448:                     if ($i > 0) {
                   1449:                         $output .= '</tr>';
                   1450:                     }
                   1451:                     $output .= '<tr>';
                   1452:                 }
                   1453:                 my $check = ' ';
1.32      raeburn  1454:                 if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
                   1455:                     if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
1.27      raeburn  1456:                         $check = ' checked="checked" ';
                   1457:                     }
                   1458:                 }
                   1459:                 $output .= '<td class="LC_left_item">'.
                   1460:                            '<span class="LC_nobreak"><label>'.
1.32      raeburn  1461:                            '<input type="checkbox" name="'.$type.'_rule" '.
1.27      raeburn  1462:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
                   1463:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
                   1464:             }
                   1465:         }
                   1466:         $rem = @{$ruleorder}%($numinrow);
                   1467:     }
                   1468:     my $colsleft = $numinrow - $rem;
                   1469:     if ($colsleft > 1 ) {
                   1470:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   1471:                    '&nbsp;</td>';
                   1472:     } elsif ($colsleft == 1) {
                   1473:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   1474:     }
                   1475:     $output .= '</tr></table></td></tr>';
                   1476:     return $output;
                   1477: }
                   1478: 
1.34      raeburn  1479: sub usercreation_types {
                   1480:     my %lt = &Apache::lonlocal::texthash (
                   1481:                     author     => 'When adding a co-author',
                   1482:                     course     => 'When adding a user to a course',
                   1483:                     any        => 'Any',
                   1484:                     official   => 'Institutional only ',
                   1485:                     unofficial => 'Non-institutional only',
                   1486:                     none       => 'None',
                   1487:     );
                   1488:     return %lt;
                   1489: } 
                   1490: 
1.28      raeburn  1491: sub authtype_names {
                   1492:     my %lt = &Apache::lonlocal::texthash(
                   1493:                       int    => 'Internal',
                   1494:                       krb4   => 'Kerberos 4',
                   1495:                       krb5   => 'Kerberos 5',
                   1496:                       loc    => 'Local',
                   1497:                   );
                   1498:     return %lt;
                   1499: }
                   1500: 
                   1501: sub context_names {
                   1502:     my %context_title = &Apache::lonlocal::texthash(
                   1503:        author => 'Creating users when an Author',
                   1504:        course => 'Creating users when in a course',
                   1505:        domain => 'Creating users when a Domain Coordinator',
                   1506:     );
                   1507:     return %context_title;
                   1508: }
                   1509: 
1.33      raeburn  1510: sub print_usermodification {
                   1511:     my ($position,$dom,$settings,$rowtotal) = @_;
                   1512:     my $numinrow = 4;
                   1513:     my ($context,$datatable,$rowcount);
                   1514:     if ($position eq 'top') {
                   1515:         $rowcount = 0;
                   1516:         $context = 'author'; 
                   1517:         foreach my $role ('ca','aa') {
                   1518:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   1519:                                                    $numinrow,$rowcount);
                   1520:             $$rowtotal ++;
                   1521:             $rowcount ++;
                   1522:         }
                   1523:     } else {
                   1524:         $context = 'course';
                   1525:         $rowcount = 0;
                   1526:         foreach my $role ('st','ep','ta','in','cr') {
                   1527:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
                   1528:                                                    $numinrow,$rowcount);
                   1529:             $$rowtotal ++;
                   1530:             $rowcount ++;
                   1531:         }
                   1532:     }
                   1533:     return $datatable;
                   1534: }
                   1535: 
                   1536: sub modifiable_userdata_row {
                   1537:     my ($context,$role,$settings,$numinrow,$rowcount) = @_;
                   1538:     my $rolename;
                   1539:     if ($role eq 'cr') {
                   1540:         $rolename = &mt('Custom role');
                   1541:     } else {
                   1542:         $rolename = &Apache::lonnet::plaintext($role);
                   1543:     }
                   1544:     my @fields = ('lastname','firstname','middlename','generation',
                   1545:                   'permanentemail','id');
                   1546:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   1547:     my $output;
                   1548:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
                   1549:     $output = '<tr '.$css_class.'>'.
                   1550:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
                   1551:               '<td class="LC_left_item" colspan="2"><table>';
                   1552:     my $rem;
                   1553:     my %checks;
                   1554:     if (ref($settings) eq 'HASH') {
                   1555:         if (ref($settings->{$context}) eq 'HASH') {
                   1556:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
                   1557:                 foreach my $field (@fields) {
                   1558:                     if ($settings->{$context}->{$role}->{$field}) {
                   1559:                         $checks{$field} = ' checked="checked" ';
                   1560:                     }
                   1561:                 }
                   1562:             }
                   1563:         }
                   1564:     }
                   1565:     for (my $i=0; $i<@fields; $i++) {
                   1566:         my $rem = $i%($numinrow);
                   1567:         if ($rem == 0) {
                   1568:             if ($i > 0) {
                   1569:                 $output .= '</tr>';
                   1570:             }
                   1571:             $output .= '<tr>';
                   1572:         }
                   1573:         my $check = ' ';
                   1574:         if (exists($checks{$fields[$i]})) {
                   1575:             $check = $checks{$fields[$i]}
                   1576:         } else {
                   1577:             if ($role eq 'st') {
                   1578:                 if (ref($settings) ne 'HASH') {
                   1579:                     $check = ' checked="checked" '; 
                   1580:                 }
                   1581:             }
                   1582:         }
                   1583:         $output .= '<td class="LC_left_item">'.
                   1584:                    '<span class="LC_nobreak"><label>'.
                   1585:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
                   1586:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
                   1587:                    '</label></span></td>';
                   1588:         $rem = @fields%($numinrow);
                   1589:     }
                   1590:     my $colsleft = $numinrow - $rem;
                   1591:     if ($colsleft > 1 ) {
                   1592:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
                   1593:                    '&nbsp;</td>';
                   1594:     } elsif ($colsleft == 1) {
                   1595:         $output .= '<td class="LC_left_item">&nbsp;</td>';
                   1596:     }
                   1597:     $output .= '</tr></table></td></tr>';
                   1598:     return $output;
                   1599: }
1.28      raeburn  1600: 
1.25      raeburn  1601: sub users_cansearch_row {
                   1602:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
                   1603:     my $output =  '<tr class="LC_odd_row">'.
1.24      raeburn  1604:                   '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
                   1605:                   '</td><td class="LC_left_item" colspan="2"><table>';
1.26      raeburn  1606:     my $rem;
                   1607:     if (ref($types) eq 'ARRAY') {
                   1608:         for (my $i=0; $i<@{$types}; $i++) {
                   1609:             if (defined($usertypes->{$types->[$i]})) {
                   1610:                 my $rem = $i%($numinrow);
                   1611:                 if ($rem == 0) {
                   1612:                     if ($i > 0) {
                   1613:                         $output .= '</tr>';
                   1614:                     }
                   1615:                     $output .= '<tr>';
1.23      raeburn  1616:                 }
1.26      raeburn  1617:                 my $check = ' ';
                   1618:                 if (ref($settings->{'cansearch'}) eq 'ARRAY') {
                   1619:                     if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
                   1620:                         $check = ' checked="checked" ';
                   1621:                     }
1.23      raeburn  1622:                 }
1.26      raeburn  1623:                 $output .= '<td class="LC_left_item">'.
                   1624:                            '<span class="LC_nobreak"><label>'.
                   1625:                            '<input type="checkbox" name="cansearch" '.
                   1626:                            'value="'.$types->[$i].'"'.$check.'/>'.
                   1627:                            $usertypes->{$types->[$i]}.'</label></span></td>';
1.23      raeburn  1628:             }
                   1629:         }
1.26      raeburn  1630:        
                   1631:         $rem = @{$types}%($numinrow);
1.23      raeburn  1632:     }
                   1633:     my $colsleft = $numinrow - $rem;
                   1634:     if ($colsleft > 1) {
1.25      raeburn  1635:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23      raeburn  1636:     } else {
1.25      raeburn  1637:         $output .= '<td class="LC_left_item">';
1.23      raeburn  1638:     }
                   1639:     my $defcheck = ' ';
                   1640:     if (ref($settings->{'cansearch'}) eq 'ARRAY') {
1.26      raeburn  1641:         if (grep(/^default$/,@{$settings->{'cansearch'}})) {
                   1642:             $defcheck = ' checked="checked" ';
                   1643:         }
1.23      raeburn  1644:     }
1.25      raeburn  1645:     $output .= '<span class="LC_nobreak"><label>'.
                   1646:                '<input type="checkbox" name="cansearch" '.
                   1647:                'value="default"'.$defcheck.'/>'.
                   1648:                $othertitle.'</label></span></td>'.
                   1649:                '</tr></table></td></tr>';
                   1650:     return $output;
1.23      raeburn  1651: }
                   1652: 
                   1653: sub sorted_inst_types {
                   1654:     my ($dom) = @_;
                   1655:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
1.26      raeburn  1656:     my $othertitle = &mt('All users');
1.23      raeburn  1657:     my @types;
                   1658:     if (ref($order) eq 'ARRAY') {
                   1659:         @types = @{$order};
                   1660:     }
                   1661:     if (@types == 0) {
                   1662:         if (ref($usertypes) eq 'HASH') {
                   1663:             @types = sort(keys(%{$usertypes}));
                   1664:         }
                   1665:     }
                   1666:     if (keys(%{$usertypes}) > 0) {
                   1667:         $othertitle = &mt('Other users');
                   1668:     }
                   1669:     return ($othertitle,$usertypes,\@types);
                   1670: }
                   1671: 
                   1672: sub sorted_searchtitles {
                   1673:     my %searchtitles = &Apache::lonlocal::texthash(
                   1674:                          'uname' => 'username',
                   1675:                          'lastname' => 'last name',
                   1676:                          'lastfirst' => 'last name, first name',
                   1677:                      );
                   1678:     my @titleorder = ('uname','lastname','lastfirst');
                   1679:     return (\%searchtitles,\@titleorder);
                   1680: }
                   1681: 
1.25      raeburn  1682: sub sorted_searchtypes {
                   1683:     my %srchtypes_desc = (
                   1684:                            exact    => 'is exact match',
                   1685:                            contains => 'contains ..',
                   1686:                            begins   => 'begins with ..',
                   1687:                          );
                   1688:     my @srchtypeorder = ('exact','begins','contains');
                   1689:     return (\%srchtypes_desc,\@srchtypeorder);
                   1690: }
                   1691: 
1.3       raeburn  1692: sub usertype_update_row {
                   1693:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
                   1694:     my $datatable;
                   1695:     my $numinrow = 4;
                   1696:     foreach my $type (@{$types}) {
                   1697:         if (defined($usertypes->{$type})) {
                   1698:             $$rownums ++;
                   1699:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
                   1700:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
                   1701:                           '</td><td class="LC_left_item"><table>';
                   1702:             for (my $i=0; $i<@{$fields}; $i++) {
                   1703:                 my $rem = $i%($numinrow);
                   1704:                 if ($rem == 0) {
                   1705:                     if ($i > 0) {
                   1706:                         $datatable .= '</tr>';
                   1707:                     }
                   1708:                     $datatable .= '<tr>';
                   1709:                 }
                   1710:                 my $check = ' ';
                   1711:                 if (ref($settings->{'fields'}) eq 'HASH') {
                   1712:                     if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
                   1713:                         if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
                   1714:                             $check = ' checked="checked" ';
                   1715:                         }
                   1716:                     }
                   1717:                 }
                   1718: 
                   1719:                 if ($i == @{$fields}-1) {
                   1720:                     my $colsleft = $numinrow - $rem;
                   1721:                     if ($colsleft > 1) {
                   1722:                         $datatable .= '<td colspan="'.$colsleft.'">';
                   1723:                     } else {
                   1724:                         $datatable .= '<td>';
                   1725:                     }
                   1726:                 } else {
                   1727:                     $datatable .= '<td>';
                   1728:                 }
1.8       raeburn  1729:                 $datatable .= '<span class="LC_nobreak"><label>'.
                   1730:                               '<input type="checkbox" name="updateable_'.$type.
                   1731:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
                   1732:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3       raeburn  1733:             }
                   1734:             $datatable .= '</tr></table></td></tr>';
                   1735:         }
                   1736:     }
                   1737:     return $datatable;
1.1       raeburn  1738: }
                   1739: 
                   1740: sub modify_login {
1.9       raeburn  1741:     my ($r,$dom,$confname,%domconfig) = @_;
1.6       raeburn  1742:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
1.1       raeburn  1743:     my %title = ( coursecatalog => 'Display course catalog',
                   1744:                   adminmail => 'Display administrator E-mail address');
1.3       raeburn  1745:     my @offon = ('off','on');
1.6       raeburn  1746:     my %loginhash;
1.9       raeburn  1747:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
                   1748:                                            \%domconfig,\%loginhash);
1.6       raeburn  1749:     $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
                   1750:     $loginhash{login}{adminmail} = $env{'form.adminmail'};
                   1751:     if (ref($colchanges{'login'}) eq 'HASH') {  
                   1752:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
                   1753:                                          \%loginhash);
                   1754:     }
1.1       raeburn  1755:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
                   1756:                                              $dom);
                   1757:     if ($putresult eq 'ok') {
1.3       raeburn  1758:         if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
1.1       raeburn  1759:             ($env{'form.coursecatalog'} eq '1')) {
                   1760:             $changes{'coursecatalog'} = 1;
1.3       raeburn  1761:         } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
                   1762:                  $domconfig{'login'}{'coursecatalog'} eq '1') &&
1.1       raeburn  1763:                  ($env{'form.coursecatalog'} eq '0')) {
                   1764:             $changes{'coursecatalog'} = 1;
                   1765:         }
1.3       raeburn  1766:         if (($domconfig{'login'}{'adminmail'} eq '1') &&
1.1       raeburn  1767:                 ($env{'form.adminmail'} eq '0')) {
                   1768:             $changes{'adminmail'} = 1;
                   1769:         } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
                   1770:                  $domconfig{'login'}{'adminmail'} eq '0') &&
                   1771:                  ($env{'form.adminmail'} eq '1')) {
                   1772:             $changes{'adminmail'} = 1;
                   1773:         }
1.6       raeburn  1774:         if (keys(%changes) > 0 || $colchgtext) {
1.1       raeburn  1775:             $resulttext = &mt('Changes made:').'<ul>';
                   1776:             foreach my $item (sort(keys(%changes))) {
                   1777:                 $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
                   1778:             }
1.6       raeburn  1779:             $resulttext .= $colchgtext.'</ul>';
1.1       raeburn  1780:         } else {
                   1781:             $resulttext = &mt('No changes made to log-in page settings');
                   1782:         }
                   1783:     } else {
1.11      albertel 1784:         $resulttext = '<span class="LC_error">'.
                   1785: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  1786:     }
1.6       raeburn  1787:     if ($errors) {
1.9       raeburn  1788:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6       raeburn  1789:                        $errors.'</ul>';
                   1790:     }
                   1791:     return $resulttext;
                   1792: }
                   1793: 
                   1794: sub color_font_choices {
                   1795:     my %choices =
                   1796:         &Apache::lonlocal::texthash (
                   1797:             img => "Header",
                   1798:             bgs => "Background colors",
                   1799:             links => "Link colors",
                   1800:             font => "Font color",
                   1801:             pgbg => "Page",
                   1802:             tabbg => "Header",
                   1803:             sidebg => "Border",
                   1804:             link => "Link",
                   1805:             alink => "Active link",
                   1806:             vlink => "Visited link",
                   1807:         );
                   1808:     return %choices;
                   1809: }
                   1810: 
                   1811: sub modify_rolecolors {
1.9       raeburn  1812:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6       raeburn  1813:     my ($resulttext,%rolehash);
                   1814:     $rolehash{'rolecolors'} = {};
1.9       raeburn  1815:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6       raeburn  1816:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
                   1817:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
                   1818:                                              $dom);
                   1819:     if ($putresult eq 'ok') {
                   1820:         if (keys(%changes) > 0) {
                   1821:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
                   1822:                                              $rolehash{'rolecolors'});
                   1823:         } else {
                   1824:             $resulttext = &mt('No changes made to default color schemes');
                   1825:         }
                   1826:     } else {
1.11      albertel 1827:         $resulttext = '<span class="LC_error">'.
                   1828: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.6       raeburn  1829:     }
                   1830:     if ($errors) {
                   1831:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
                   1832:                        $errors.'</ul>';
                   1833:     }
                   1834:     return $resulttext;
                   1835: }
                   1836: 
                   1837: sub modify_colors {
1.9       raeburn  1838:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12      raeburn  1839:     my (%changes,%choices);
1.6       raeburn  1840:     my @bgs = ('pgbg','mainbg','sidebg');
                   1841:     my @links = ('link','alink','vlink');
                   1842:     my @images;
                   1843:     my $servadm = $r->dir_config('lonAdmEMail');
                   1844:     my $errors;
                   1845:     foreach my $role (@{$roles}) {
                   1846:         if ($role eq 'login') {
1.12      raeburn  1847:             %choices = &login_choices();
                   1848:         } else {
                   1849:             %choices = &color_font_choices();
                   1850:         }
                   1851:         if ($role eq 'login') {
1.6       raeburn  1852:             @images = ('img','logo','domlogo');
                   1853:         } else {
                   1854:             @images = ('img');
                   1855:         }
                   1856:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
                   1857:         foreach my $item (@bgs,@links) {
                   1858:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
                   1859:         }
1.9       raeburn  1860:         my ($configuserok,$author_ok,$switchserver,%currroles);
                   1861:         my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
                   1862:         ($configuserok,%currroles) = &check_configuser($uhome,$dom,
                   1863:                                                        $confname,$servadm);
                   1864:         if ($configuserok eq 'ok') {
                   1865:             $switchserver = &check_switchserver($dom,$confname);
                   1866:             if ($switchserver eq '') {
                   1867:                 $author_ok = &check_authorstatus($dom,$confname,%currroles);
                   1868:             }
                   1869:         }
                   1870:         my ($width,$height) = &thumb_dimensions();
1.8       raeburn  1871:         foreach my $img (@images) {
1.18      albertel 1872: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
                   1873: 		 && !defined($domconfig->{$role}{$img})
                   1874: 		 && !$env{'form.'.$role.'_del_'.$img}
                   1875: 		 && $env{'form.'.$role.'_import_'.$img}) {
                   1876: 		# import the old configured image from the .tab setting
                   1877: 		# if they haven't provided a new one 
                   1878: 		$domconfig->{$role}{$img} = 
                   1879: 		    $env{'form.'.$role.'_import_'.$img};
                   1880: 	    }
1.6       raeburn  1881:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9       raeburn  1882:                 my $error;
1.6       raeburn  1883:                 if ($configuserok eq 'ok') {
1.9       raeburn  1884:                     if ($switchserver) {
1.12      raeburn  1885:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9       raeburn  1886:                     } else {
                   1887:                         if ($author_ok eq 'ok') {
                   1888:                             my ($result,$logourl) = 
                   1889:                                 &publishlogo($r,'upload',$role.'_'.$img,
                   1890:                                            $dom,$confname,$img,$width,$height);
                   1891:                             if ($result eq 'ok') {
                   1892:                                 $confhash->{$role}{$img} = $logourl;
1.12      raeburn  1893:                                 $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  1894:                             } else {
1.12      raeburn  1895:                                 $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  1896:                             }
                   1897:                         } else {
1.12      raeburn  1898:                             $error = &mt("Upload of [_1] image for $role page(s) failed because an author role could not be assigned to a Domain Configuation user ([_2]) in domain: [_3].  Error was: [_4].",$choices{$img},$confname,$dom,$author_ok);
1.6       raeburn  1899:                         }
                   1900:                     }
                   1901:                 } else {
1.12      raeburn  1902:                     $error = &mt("Upload of [_1] image for $role page(s) failed because a Domain Configuation user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$choices{$img},$confname,$dom,$configuserok);
1.9       raeburn  1903:                 }
                   1904:                 if ($error) {
1.8       raeburn  1905:                     &Apache::lonnet::logthis($error);
1.11      albertel 1906:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8       raeburn  1907:                 }
                   1908:             } elsif ($domconfig->{$role}{$img} ne '') {
1.9       raeburn  1909:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
                   1910:                     my $error;
                   1911:                     if ($configuserok eq 'ok') {
                   1912: # is confname an author?
                   1913:                         if ($switchserver eq '') {
                   1914:                             if ($author_ok eq 'ok') {
                   1915:                                 my ($result,$logourl) = 
                   1916:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
                   1917:                                             $dom,$confname,$img,$width,$height);
                   1918:                                 if ($result eq 'ok') {
                   1919:                                     $confhash->{$role}{$img} = $logourl;
1.18      albertel 1920: 				    $changes{$role}{'images'}{$img} = 1;
1.9       raeburn  1921:                                 }
                   1922:                             }
                   1923:                         }
                   1924:                     }
1.6       raeburn  1925:                 }
                   1926:             }
                   1927:         }
                   1928:         if (ref($domconfig) eq 'HASH') {
                   1929:             if (ref($domconfig->{$role}) eq 'HASH') {
                   1930:                 foreach my $img (@images) {
                   1931:                     if ($domconfig->{$role}{$img} ne '') {
                   1932:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   1933:                             $confhash->{$role}{$img} = '';
1.12      raeburn  1934:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  1935:                         } else {
1.9       raeburn  1936:                             if ($confhash->{$role}{$img} eq '') {
                   1937:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
                   1938:                             }
1.6       raeburn  1939:                         }
                   1940:                     } else {
                   1941:                         if ($env{'form.'.$role.'_del_'.$img}) {
                   1942:                             $confhash->{$role}{$img} = '';
1.12      raeburn  1943:                             $changes{$role}{'images'}{$img} = 1;
1.6       raeburn  1944:                         } 
                   1945:                     }
                   1946:                 }  
                   1947:                 if ($domconfig->{$role}{'font'} ne '') {
                   1948:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
                   1949:                         $changes{$role}{'font'} = 1;
                   1950:                     }
                   1951:                 } else {
                   1952:                     if ($confhash->{$role}{'font'}) {
                   1953:                         $changes{$role}{'font'} = 1;
                   1954:                     }
                   1955:                 }
                   1956:                 foreach my $item (@bgs) {
                   1957:                     if ($domconfig->{$role}{$item} ne '') {
                   1958:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   1959:                             $changes{$role}{'bgs'}{$item} = 1;
                   1960:                         } 
                   1961:                     } else {
                   1962:                         if ($confhash->{$role}{$item}) {
                   1963:                             $changes{$role}{'bgs'}{$item} = 1;
                   1964:                         }
                   1965:                     }
                   1966:                 }
                   1967:                 foreach my $item (@links) {
                   1968:                     if ($domconfig->{$role}{$item} ne '') {
                   1969:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
                   1970:                             $changes{$role}{'links'}{$item} = 1;
                   1971:                         }
                   1972:                     } else {
                   1973:                         if ($confhash->{$role}{$item}) {
                   1974:                             $changes{$role}{'links'}{$item} = 1;
                   1975:                         }
                   1976:                     }
                   1977:                 }
                   1978:             } else {
                   1979:                 &default_change_checker($role,\@images,\@links,\@bgs,
                   1980:                                         $confhash,\%changes); 
                   1981:             }
                   1982:         } else {
                   1983:             &default_change_checker($role,\@images,\@links,\@bgs,
                   1984:                                     $confhash,\%changes); 
                   1985:         }
                   1986:     }
                   1987:     return ($errors,%changes);
                   1988: }
                   1989: 
                   1990: sub default_change_checker {
                   1991:     my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
                   1992:     foreach my $item (@{$links}) {
                   1993:         if ($confhash->{$role}{$item}) {
                   1994:             $changes->{$role}{'links'}{$item} = 1;
                   1995:         }
                   1996:     }
                   1997:     foreach my $item (@{$bgs}) {
                   1998:         if ($confhash->{$role}{$item}) {
                   1999:             $changes->{$role}{'bgs'}{$item} = 1;
                   2000:         }
                   2001:     }
                   2002:     foreach my $img (@{$images}) {
                   2003:         if ($env{'form.'.$role.'_del_'.$img}) {
                   2004:             $confhash->{$role}{$img} = '';
1.12      raeburn  2005:             $changes->{$role}{'images'}{$img} = 1;
1.6       raeburn  2006:         }
                   2007:     }
                   2008:     if ($confhash->{$role}{'font'}) {
                   2009:         $changes->{$role}{'font'} = 1;
                   2010:     }
                   2011: } 
                   2012: 
                   2013: sub display_colorchgs {
                   2014:     my ($dom,$changes,$roles,$confhash) = @_;
                   2015:     my (%choices,$resulttext);
1.7       albertel 2016:     &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6       raeburn  2017:     if (!grep(/^login$/,@{$roles})) {
                   2018:         $resulttext = &mt('Changes made:').'<br />';
                   2019:     }
                   2020:     foreach my $role (@{$roles}) {
                   2021:         if ($role eq 'login') {
                   2022:             %choices = &login_choices();
                   2023:         } else {
                   2024:             %choices = &color_font_choices();
                   2025:         }
                   2026:         if (ref($changes->{$role}) eq 'HASH') {
                   2027:             if ($role ne 'login') {
                   2028:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
                   2029:             }
                   2030:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
                   2031:                 if ($role ne 'login') {
                   2032:                     $resulttext .= '<ul>';
                   2033:                 }
                   2034:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
                   2035:                     if ($role ne 'login') {
                   2036:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
                   2037:                     }
                   2038:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
                   2039:                         if ($confhash->{$role}{$item} eq '') {
                   2040:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
                   2041:                         } else {
1.12      raeburn  2042:                             my $newitem = $confhash->{$role}{$item};
                   2043:                             if ($key eq 'images') {
                   2044:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
                   2045:                             }
                   2046:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6       raeburn  2047:                         }
                   2048:                     }
                   2049:                     if ($role ne 'login') {
                   2050:                         $resulttext .= '</ul></li>';
                   2051:                     }
                   2052:                 } else {
                   2053:                     if ($confhash->{$role}{$key} eq '') {
                   2054:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
                   2055:                     } else {
                   2056:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
                   2057:                     }
                   2058:                 }
                   2059:                 if ($role ne 'login') {
                   2060:                     $resulttext .= '</ul>';
                   2061:                 }
                   2062:             }
                   2063:         }
                   2064:     }
1.3       raeburn  2065:     return $resulttext;
1.1       raeburn  2066: }
                   2067: 
1.9       raeburn  2068: sub thumb_dimensions {
                   2069:     return ('200','50');
                   2070: }
                   2071: 
1.16      raeburn  2072: sub check_dimensions {
                   2073:     my ($inputfile) = @_;
                   2074:     my ($fullwidth,$fullheight);
                   2075:     if ($inputfile =~ m|^[/\w.\-]+$|) {
                   2076:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
                   2077:             my $imageinfo = <PIPE>;
                   2078:             if (!close(PIPE)) {
                   2079:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
                   2080:             }
                   2081:             chomp($imageinfo);
                   2082:             my ($fullsize) = 
1.21      raeburn  2083:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16      raeburn  2084:             if ($fullsize) {
                   2085:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
                   2086:             }
                   2087:         }
                   2088:     }
                   2089:     return ($fullwidth,$fullheight);
                   2090: }
                   2091: 
1.9       raeburn  2092: sub check_configuser {
                   2093:     my ($uhome,$dom,$confname,$servadm) = @_;
                   2094:     my ($configuserok,%currroles);
                   2095:     if ($uhome eq 'no_host') {
                   2096:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
                   2097:         my $configpass = &LONCAPA::Enrollment::create_password();
                   2098:         $configuserok = 
                   2099:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
                   2100:                              $configpass,'','','','','',undef,$servadm);
                   2101:     } else {
                   2102:         $configuserok = 'ok';
                   2103:         %currroles = 
                   2104:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
                   2105:     }
                   2106:     return ($configuserok,%currroles);
                   2107: }
                   2108: 
                   2109: sub check_authorstatus {
                   2110:     my ($dom,$confname,%currroles) = @_;
                   2111:     my $author_ok;
                   2112:     if (!$currroles{':'.$dom.':au'}) {
                   2113:         my $start = time;
                   2114:         my $end = 0;
                   2115:         $author_ok = 
                   2116:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
                   2117:                                         'au',$end,$start);
                   2118:     } else {
                   2119:         $author_ok = 'ok';
                   2120:     }
                   2121:     return $author_ok;
                   2122: }
                   2123: 
                   2124: sub publishlogo {
                   2125:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
                   2126:     my ($output,$fname,$logourl);
                   2127:     if ($action eq 'upload') {
                   2128:         $fname=$env{'form.'.$formname.'.filename'};
                   2129:         chop($env{'form.'.$formname});
                   2130:     } else {
                   2131:         ($fname) = ($formname =~ /([^\/]+)$/);
                   2132:     }
                   2133:     $fname=&Apache::lonnet::clean_filename($fname);
                   2134: # See if there is anything left
                   2135:     unless ($fname) { return ('error: no uploaded file'); }
                   2136:     $fname="$subdir/$fname";
                   2137:     my $filepath='/home/'.$confname.'/public_html';
                   2138:     my ($fnamepath,$file,$fetchthumb);
                   2139:     $file=$fname;
                   2140:     if ($fname=~m|/|) {
                   2141:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
                   2142:     }
                   2143:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
                   2144:     my $count;
                   2145:     for ($count=4;$count<=$#parts;$count++) {
                   2146:         $filepath.="/$parts[$count]";
                   2147:         if ((-e $filepath)!=1) {
                   2148:             mkdir($filepath,02770);
                   2149:         }
                   2150:     }
                   2151:     # Check for bad extension and disallow upload
                   2152:     if ($file=~/\.(\w+)$/ &&
                   2153:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   2154:         $output = 
                   2155:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
                   2156:     } elsif ($file=~/\.(\w+)$/ &&
                   2157:         !defined(&Apache::loncommon::fileembstyle($1))) {
                   2158:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   2159:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
                   2160:         $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   2161:     } elsif (-d "$filepath/$file") {
                   2162:         $output = &mt('File name is a directory name - rename the file and re-upload');
                   2163:     } else {
                   2164:         my $source = $filepath.'/'.$file;
                   2165:         my $logfile;
                   2166:         if (!open($logfile,">>$source".'.log')) {
                   2167:             return (&mt('No write permission to Construction Space'));
                   2168:         }
                   2169:         print $logfile
                   2170: "\n================= Publish ".localtime()." ================\n".
                   2171: $env{'user.name'}.':'.$env{'user.domain'}."\n";
                   2172: # Save the file
                   2173:         if (!open(FH,'>'.$source)) {
                   2174:             &Apache::lonnet::logthis('Failed to create '.$source);
                   2175:             return (&mt('Failed to create file'));
                   2176:         }
                   2177:         if ($action eq 'upload') {
                   2178:             if (!print FH ($env{'form.'.$formname})) {
                   2179:                 &Apache::lonnet::logthis('Failed to write to '.$source);
                   2180:                 return (&mt('Failed to write file'));
                   2181:             }
                   2182:         } else {
                   2183:             my $original = &Apache::lonnet::filelocation('',$formname);
                   2184:             if(!copy($original,$source)) {
                   2185:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
                   2186:                 return (&mt('Failed to write file'));
                   2187:             }
                   2188:         }
                   2189:         close(FH);
                   2190:         chmod(0660, $source); # Permissions to rw-rw---.
                   2191: 
                   2192:         my $docroot=$r->dir_config('lonDocRoot');
                   2193:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
                   2194:         my $copyfile=$targetdir.'/'.$file;
                   2195: 
                   2196:         my @parts=split(/\//,$targetdir);
                   2197:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
                   2198:         for (my $count=5;$count<=$#parts;$count++) {
                   2199:             $path.="/$parts[$count]";
                   2200:             if (!-e $path) {
                   2201:                 print $logfile "\nCreating directory ".$path;
                   2202:                 mkdir($path,02770);
                   2203:             }
                   2204:         }
                   2205:         my $versionresult;
                   2206:         if (-e $copyfile) {
                   2207:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
                   2208:         } else {
                   2209:             $versionresult = 'ok';
                   2210:         }
                   2211:         if ($versionresult eq 'ok') {
                   2212:             if (copy($source,$copyfile)) {
                   2213:                 print $logfile "\nCopied original source to ".$copyfile."\n";
                   2214:                 $output = 'ok';
                   2215:                 &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
                   2216:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
                   2217:             } else {
                   2218:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
                   2219:                 $output = &mt('Failed to copy file to RES space').", $!";
                   2220:             }
                   2221:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
                   2222:                 my $inputfile = $filepath.'/'.$file;
                   2223:                 my $outfile = $filepath.'/'.'tn-'.$file;
1.16      raeburn  2224:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
                   2225:                 if ($fullwidth ne '' && $fullheight ne '') { 
                   2226:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
                   2227:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
                   2228:                         system("convert -sample $thumbsize $inputfile $outfile");
                   2229:                         chmod(0660, $filepath.'/tn-'.$file);
                   2230:                         if (-e $outfile) {
                   2231:                             my $copyfile=$targetdir.'/tn-'.$file;
                   2232:                             if (copy($outfile,$copyfile)) {
                   2233:                                 print $logfile "\nCopied source to ".$copyfile."\n";
                   2234:                                 &write_metadata($dom,$confname,$formname,
                   2235:                                                 $targetdir,'tn-'.$file,$logfile);
                   2236:                             } else {
                   2237:                                 print $logfile "\nUnable to write ".$copyfile.
                   2238:                                                ':'.$!."\n";
                   2239:                             }
                   2240:                         }
1.9       raeburn  2241:                     }
                   2242:                 }
                   2243:             }
                   2244:         } else {
                   2245:             $output = $versionresult;
                   2246:         }
                   2247:     }
                   2248:     return ($output,$logourl);
                   2249: }
                   2250: 
                   2251: sub logo_versioning {
                   2252:     my ($targetdir,$file,$logfile) = @_;
                   2253:     my $target = $targetdir.'/'.$file;
                   2254:     my ($maxversion,$fn,$extn,$output);
                   2255:     $maxversion = 0;
                   2256:     if ($file =~ /^(.+)\.(\w+)$/) {
                   2257:         $fn=$1;
                   2258:         $extn=$2;
                   2259:     }
                   2260:     opendir(DIR,$targetdir);
                   2261:     while (my $filename=readdir(DIR)) {
                   2262:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
                   2263:             $maxversion=($1>$maxversion)?$1:$maxversion;
                   2264:         }
                   2265:     }
                   2266:     $maxversion++;
                   2267:     print $logfile "\nCreating old version ".$maxversion."\n";
                   2268:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
                   2269:     if (copy($target,$copyfile)) {
                   2270:         print $logfile "Copied old target to ".$copyfile."\n";
                   2271:         $copyfile=$copyfile.'.meta';
                   2272:         if (copy($target.'.meta',$copyfile)) {
                   2273:             print $logfile "Copied old target metadata to ".$copyfile."\n";
                   2274:             $output = 'ok';
                   2275:         } else {
                   2276:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
                   2277:             $output = &mt('Failed to copy old meta').", $!, ";
                   2278:         }
                   2279:     } else {
                   2280:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
                   2281:         $output = &mt('Failed to copy old target').", $!, ";
                   2282:     }
                   2283:     return $output;
                   2284: }
                   2285: 
                   2286: sub write_metadata {
                   2287:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
                   2288:     my (%metadatafields,%metadatakeys,$output);
                   2289:     $metadatafields{'title'}=$formname;
                   2290:     $metadatafields{'creationdate'}=time;
                   2291:     $metadatafields{'lastrevisiondate'}=time;
                   2292:     $metadatafields{'copyright'}='public';
                   2293:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
                   2294:                                          $env{'user.domain'};
                   2295:     $metadatafields{'authorspace'}=$confname.':'.$dom;
                   2296:     $metadatafields{'domain'}=$dom;
                   2297:     {
                   2298:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
                   2299:         my $mfh;
                   2300:         unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
                   2301:             $output = &mt('Could not write metadata');
                   2302:         }
                   2303:         foreach (sort keys %metadatafields) {
                   2304:             unless ($_=~/\./) {
                   2305:                 my $unikey=$_;
                   2306:                 $unikey=~/^([A-Za-z]+)/;
                   2307:                 my $tag=$1;
                   2308:                 $tag=~tr/A-Z/a-z/;
                   2309:                 print $mfh "\n\<$tag";
                   2310:                 foreach (split(/\,/,$metadatakeys{$unikey})) {
                   2311:                     my $value=$metadatafields{$unikey.'.'.$_};
                   2312:                     $value=~s/\"/\'\'/g;
                   2313:                     print $mfh ' '.$_.'="'.$value.'"';
                   2314:                 }
                   2315:                 print $mfh '>'.
                   2316:                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
                   2317:                         .'</'.$tag.'>';
                   2318:             }
                   2319:         }
                   2320:         $output = 'ok';
                   2321:         print $logfile "\nWrote metadata";
                   2322:         close($mfh);
                   2323:     }
                   2324: }
                   2325: 
                   2326: sub check_switchserver {
                   2327:     my ($dom,$confname) = @_;
                   2328:     my ($allowed,$switchserver);
                   2329:     my $home = &Apache::lonnet::homeserver($confname,$dom);
                   2330:     if ($home eq 'no_host') {
                   2331:         $home = &Apache::lonnet::domain($dom,'primary');
                   2332:     }
                   2333:     my @ids=&Apache::lonnet::current_machine_ids();
1.10      albertel 2334:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
                   2335:     if (!$allowed) {
                   2336: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9       raeburn  2337:     }
                   2338:     return $switchserver;
                   2339: }
                   2340: 
1.30      raeburn  2341: sub javascript_set_colnums {
                   2342:     return <<END;
                   2343: function setDisplayColumns() {
                   2344:     if (document.pickactions.width.value > 1100) {
                   2345:         document.pickactions.numcols[1].checked = true;
                   2346:     } else {
                   2347:         document.pickactions.numcols[0].checked = true;
                   2348:     }
                   2349: }
                   2350: END
                   2351: }
                   2352: 
1.1       raeburn  2353: sub modify_quotas {
1.3       raeburn  2354:     my ($dom,%domconfig) = @_;
1.1       raeburn  2355:     my ($resulttext,%changes);
1.26      raeburn  2356:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1       raeburn  2357:     my %formhash;
                   2358:     foreach my $key (keys(%env)) {
                   2359:         if ($key =~ /^form\.quota_(.+)$/) {
                   2360:             $formhash{$1} = $env{$key};
                   2361:         }
                   2362:     }
1.15      raeburn  2363:     $formhash{'default'} = $env{'form.defaultquota'};
1.1       raeburn  2364:     if (ref($domconfig{'quotas'}) eq 'HASH') {
                   2365:         foreach my $key (keys(%{$domconfig{'quotas'}})) {
                   2366:             if (exists($formhash{$key})) {
                   2367:                 if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
                   2368:                     $changes{$key} = 1;
                   2369:                 }
                   2370:             } else {
                   2371:                 $formhash{$key} = $domconfig{'quotas'}{$key};
                   2372:             }
                   2373:         }
                   2374:     }
                   2375:     foreach my $key (keys(%formhash)) {
                   2376:         if ($formhash{$key} ne '') {
1.3       raeburn  2377:             if (!exists($domconfig{'quotas'}{$key})) {
1.1       raeburn  2378:                 $changes{$key} = 1;
                   2379:             }
                   2380:         }
                   2381:     }
                   2382:     my %quotahash = (
1.3       raeburn  2383:                       quotas => {%formhash},
1.1       raeburn  2384:                     );
                   2385:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
                   2386:                                              $dom);
                   2387:     if ($putresult eq 'ok') {
                   2388:         if (keys(%changes) > 0) {
                   2389:             $resulttext = &mt('Changes made:').'<ul>';
1.26      raeburn  2390:             foreach my $type (@{$types},'default') {
                   2391:                 if (defined($changes{$type})) { 
                   2392:                     my $typetitle = $usertypes->{$type};
                   2393:                     if ($type eq 'default') {
                   2394:                         $typetitle = $othertitle;
                   2395:                     }
                   2396:                     $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
                   2397:                 }
1.1       raeburn  2398:             }
                   2399:             $resulttext .= '</ul>';
                   2400:         } else {
                   2401:             $resulttext = &mt('No changes made to default quotas');
                   2402:         }
                   2403:     } else {
1.11      albertel 2404:         $resulttext = '<span class="LC_error">'.
                   2405: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  2406:     }
1.3       raeburn  2407:     return $resulttext;
1.1       raeburn  2408: }
                   2409: 
1.3       raeburn  2410: sub modify_autoenroll {
                   2411:     my ($dom,%domconfig) = @_;
1.1       raeburn  2412:     my ($resulttext,%changes);
                   2413:     my %currautoenroll;
                   2414:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   2415:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
                   2416:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
                   2417:         }
                   2418:     }
                   2419:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
                   2420:     my %title = ( run => 'Auto-enrollment active',
                   2421:                   sender => 'Sender for notification messages');
                   2422:     my @offon = ('off','on');
1.17      raeburn  2423:     my $sender_uname = $env{'form.sender_uname'};
                   2424:     my $sender_domain = $env{'form.sender_domain'};
                   2425:     if ($sender_domain eq '') {
                   2426:         $sender_uname = '';
                   2427:     } elsif ($sender_uname eq '') {
                   2428:         $sender_domain = '';
                   2429:     }
1.1       raeburn  2430:     my %autoenrollhash =  (
                   2431:                        autoenroll => { run => $env{'form.autoenroll_run'},
1.17      raeburn  2432:                                        sender_uname => $sender_uname,
                   2433:                                        sender_domain => $sender_domain,
1.1       raeburn  2434: 
                   2435:                                 }
                   2436:                      );
1.4       raeburn  2437:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
                   2438:                                              $dom);
1.1       raeburn  2439:     if ($putresult eq 'ok') {
                   2440:         if (exists($currautoenroll{'run'})) {
                   2441:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
                   2442:                  $changes{'run'} = 1;
                   2443:              }
                   2444:         } elsif ($autorun) {
                   2445:             if ($env{'form.autoenroll_run'} ne '1') {
1.23      raeburn  2446:                  $changes{'run'} = 1;
1.1       raeburn  2447:             }
                   2448:         }
1.17      raeburn  2449:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1       raeburn  2450:             $changes{'sender'} = 1;
                   2451:         }
1.17      raeburn  2452:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1       raeburn  2453:             $changes{'sender'} = 1;
                   2454:         }
                   2455:         if (keys(%changes) > 0) {
                   2456:             $resulttext = &mt('Changes made:').'<ul>';
1.3       raeburn  2457:             if ($changes{'run'}) {
1.1       raeburn  2458:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
                   2459:             }
                   2460:             if ($changes{'sender'}) {
1.17      raeburn  2461:                 if ($sender_uname eq '' || $sender_domain eq '') {
                   2462:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
                   2463:                 } else {
                   2464:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
                   2465:                 }
1.1       raeburn  2466:             }
                   2467:             $resulttext .= '</ul>';
                   2468:         } else {
                   2469:             $resulttext = &mt('No changes made to auto-enrollment settings');
                   2470:         }
                   2471:     } else {
1.11      albertel 2472:         $resulttext = '<span class="LC_error">'.
                   2473: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  2474:     }
1.3       raeburn  2475:     return $resulttext;
1.1       raeburn  2476: }
                   2477: 
                   2478: sub modify_autoupdate {
1.3       raeburn  2479:     my ($dom,%domconfig) = @_;
1.1       raeburn  2480:     my ($resulttext,%currautoupdate,%fields,%changes);
                   2481:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
                   2482:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
                   2483:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
                   2484:         }
                   2485:     }
                   2486:     my @offon = ('off','on');
                   2487:     my %title = &Apache::lonlocal::texthash (
                   2488:                    run => 'Auto-update:',
                   2489:                    classlists => 'Updates to user information in classlists?'
                   2490:                 );
1.26      raeburn  2491:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
1.1       raeburn  2492:     my %fieldtitles = &Apache::lonlocal::texthash (
                   2493:                         id => 'Student/Employee ID',
1.20      raeburn  2494:                         permanentemail => 'E-mail address',
1.1       raeburn  2495:                         lastname => 'Last Name',
                   2496:                         firstname => 'First Name',
                   2497:                         middlename => 'Middle Name',
                   2498:                         gen => 'Generation',
                   2499:                       );
                   2500:     my $othertitle = &mt('All users');
                   2501:     if (keys(%{$usertypes}) >  0) {
1.26      raeburn  2502:         $othertitle = &mt('Other users');
1.1       raeburn  2503:     }
                   2504:     foreach my $key (keys(%env)) {
                   2505:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
                   2506:             push(@{$fields{$1}},$2);
                   2507:         }
                   2508:     }
                   2509:     my %updatehash = (
                   2510:                       autoupdate => { run => $env{'form.autoupdate_run'},
                   2511:                                       classlists => $env{'form.classlists'},
                   2512:                                       fields => {%fields},
                   2513:                                     }
                   2514:                      );
                   2515:     foreach my $key (keys(%currautoupdate)) {
                   2516:         if (($key eq 'run') || ($key eq 'classlists')) {
                   2517:             if (exists($updatehash{autoupdate}{$key})) {
                   2518:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
                   2519:                     $changes{$key} = 1;
                   2520:                 }
                   2521:             }
                   2522:         } elsif ($key eq 'fields') {
                   2523:             if (ref($currautoupdate{$key}) eq 'HASH') {
1.26      raeburn  2524:                 foreach my $item (@{$types},'default') {
1.1       raeburn  2525:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
                   2526:                         my $change = 0;
                   2527:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
                   2528:                             if (!exists($fields{$item})) {
                   2529:                                 $change = 1;
                   2530:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26      raeburn  2531:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1       raeburn  2532:                                     $change = 1;
                   2533:                                 }
                   2534:                             }
                   2535:                         }
                   2536:                         if ($change) {
                   2537:                             push(@{$changes{$key}},$item);
                   2538:                         }
1.26      raeburn  2539:                     } 
1.1       raeburn  2540:                 }
                   2541:             }
                   2542:         }
                   2543:     }
1.26      raeburn  2544:     foreach my $item (@{$types},'default') {
                   2545:         if (defined($fields{$item})) {
                   2546:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
                   2547:                 if (!exists($currautoupdate{'fields'}{$item})) {
                   2548:                     push(@{$changes{'fields'}},$item);
                   2549:                 }
                   2550:             } else {
                   2551:                 push(@{$changes{'fields'}},$item);
1.1       raeburn  2552:             }
                   2553:         }
                   2554:     }
                   2555:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
                   2556:                                              $dom);
                   2557:     if ($putresult eq 'ok') {
                   2558:         if (keys(%changes) > 0) {
                   2559:             $resulttext = &mt('Changes made:').'<ul>';
                   2560:             foreach my $key (sort(keys(%changes))) {
                   2561:                 if (ref($changes{$key}) eq 'ARRAY') {
                   2562:                     foreach my $item (@{$changes{$key}}) {
                   2563:                         my @newvalues;
                   2564:                         foreach my $type (@{$fields{$item}}) {
                   2565:                             push(@newvalues,$fieldtitles{$type});
                   2566:                         }
1.3       raeburn  2567:                         my $newvaluestr;
                   2568:                         if (@newvalues > 0) {
                   2569:                             $newvaluestr = join(', ',@newvalues);
                   2570:                         } else {
                   2571:                             $newvaluestr = &mt('none');
1.6       raeburn  2572:                         }
1.1       raeburn  2573:                         if ($item eq 'default') {
1.26      raeburn  2574:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1       raeburn  2575:                         } else {
1.26      raeburn  2576:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1       raeburn  2577:                         }
                   2578:                     }
                   2579:                 } else {
                   2580:                     my $newvalue;
                   2581:                     if ($key eq 'run') {
                   2582:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
                   2583:                     } else {
                   2584:                         $newvalue = $offon[$env{'form.'.$key}];
1.3       raeburn  2585:                     }
1.1       raeburn  2586:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
                   2587:                 }
                   2588:             }
                   2589:             $resulttext .= '</ul>';
                   2590:         } else {
1.3       raeburn  2591:             $resulttext = &mt('No changes made to autoupdates');
1.1       raeburn  2592:         }
                   2593:     } else {
1.11      albertel 2594:         $resulttext = '<span class="LC_error">'.
                   2595: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
1.1       raeburn  2596:     }
1.3       raeburn  2597:     return $resulttext;
1.1       raeburn  2598: }
                   2599: 
1.23      raeburn  2600: sub modify_directorysrch {
                   2601:     my ($dom,%domconfig) = @_;
                   2602:     my ($resulttext,%changes);
                   2603:     my %currdirsrch;
                   2604:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
                   2605:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
                   2606:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
                   2607:         }
                   2608:     }
                   2609:     my %title = ( available => 'Directory search available',
1.24      raeburn  2610:                   localonly => 'Other domains can search',
1.23      raeburn  2611:                   searchby => 'Search types',
                   2612:                   searchtypes => 'Search latitude');
                   2613:     my @offon = ('off','on');
1.24      raeburn  2614:     my @otherdoms = ('Yes','No');
1.23      raeburn  2615: 
1.25      raeburn  2616:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
1.23      raeburn  2617:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
                   2618:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
                   2619: 
1.26      raeburn  2620:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
                   2621:     if (keys(%{$usertypes}) == 0) {
                   2622:         @cansearch = ('default');
                   2623:     } else {
                   2624:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
                   2625:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
                   2626:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
                   2627:                     push(@{$changes{'cansearch'}},$type);
                   2628:                 }
1.23      raeburn  2629:             }
1.26      raeburn  2630:             foreach my $type (@cansearch) {
                   2631:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
                   2632:                     push(@{$changes{'cansearch'}},$type);
                   2633:                 }
1.23      raeburn  2634:             }
1.26      raeburn  2635:         } else {
                   2636:             push(@{$changes{'cansearch'}},@cansearch);
1.23      raeburn  2637:         }
                   2638:     }
                   2639: 
                   2640:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
                   2641:         foreach my $by (@{$currdirsrch{'searchby'}}) {
                   2642:             if (!grep(/^\Q$by\E$/,@searchby)) {
                   2643:                 push(@{$changes{'searchby'}},$by);
                   2644:             }
                   2645:         }
                   2646:         foreach my $by (@searchby) {
                   2647:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
                   2648:                 push(@{$changes{'searchby'}},$by);
                   2649:             }
                   2650:         }
                   2651:     } else {
                   2652:         push(@{$changes{'searchby'}},@searchby);
                   2653:     }
1.25      raeburn  2654: 
                   2655:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
                   2656:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
                   2657:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
                   2658:                 push(@{$changes{'searchtypes'}},$type);
                   2659:             }
                   2660:         }
                   2661:         foreach my $type (@searchtypes) {
                   2662:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
                   2663:                 push(@{$changes{'searchtypes'}},$type);
                   2664:             }
                   2665:         }
                   2666:     } else {
                   2667:         if (exists($currdirsrch{'searchtypes'})) {
                   2668:             foreach my $type (@searchtypes) {  
                   2669:                 if ($type ne $currdirsrch{'searchtypes'}) { 
                   2670:                     push(@{$changes{'searchtypes'}},$type);
                   2671:                 }
                   2672:             }
                   2673:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
                   2674:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
                   2675:             }   
                   2676:         } else {
                   2677:             push(@{$changes{'searchtypes'}},@searchtypes); 
                   2678:         }
                   2679:     }
                   2680: 
1.23      raeburn  2681:     my %dirsrch_hash =  (
                   2682:             directorysrch => { available => $env{'form.dirsrch_available'},
                   2683:                                cansearch => \@cansearch,
1.24      raeburn  2684:                                localonly => $env{'form.dirsrch_localonly'},
1.23      raeburn  2685:                                searchby => \@searchby,
1.25      raeburn  2686:                                searchtypes => \@searchtypes,
1.23      raeburn  2687:                              }
                   2688:             );
                   2689:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
                   2690:                                              $dom);
                   2691:     if ($putresult eq 'ok') {
                   2692:         if (exists($currdirsrch{'available'})) {
                   2693:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
                   2694:                  $changes{'available'} = 1;
                   2695:              }
                   2696:         } else {
                   2697:             if ($env{'form.dirsrch_available'} eq '1') {
                   2698:                 $changes{'available'} = 1;
                   2699:             }
                   2700:         }
1.24      raeburn  2701:         if (exists($currdirsrch{'localonly'})) {
                   2702:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
                   2703:                  $changes{'localonly'} = 1;
                   2704:              }
                   2705:         } else {
                   2706:             if ($env{'form.dirsrch_localonly'} eq '1') {
                   2707:                 $changes{'localonly'} = 1;
                   2708:             }
                   2709:         }
1.23      raeburn  2710:         if (keys(%changes) > 0) {
                   2711:             $resulttext = &mt('Changes made:').'<ul>';
                   2712:             if ($changes{'available'}) {
                   2713:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
                   2714:             }
1.24      raeburn  2715:             if ($changes{'localonly'}) {
                   2716:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
                   2717:             }
                   2718: 
1.23      raeburn  2719:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
                   2720:                 my $chgtext;
1.26      raeburn  2721:                 if (ref($usertypes) eq 'HASH') {
                   2722:                     if (keys(%{$usertypes}) > 0) {
                   2723:                         foreach my $type (@{$types}) {
                   2724:                             if (grep(/^\Q$type\E$/,@cansearch)) {
                   2725:                                 $chgtext .= $usertypes->{$type}.'; ';
                   2726:                             }
                   2727:                         }
                   2728:                         if (grep(/^default$/,@cansearch)) {
                   2729:                             $chgtext .= $othertitle;
                   2730:                         } else {
                   2731:                             $chgtext =~ s/\; $//;
                   2732:                         }
                   2733:                         $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  2734:                     }
                   2735:                 }
                   2736:             }
                   2737:             if (ref($changes{'searchby'}) eq 'ARRAY') {
                   2738:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
                   2739:                 my $chgtext;
                   2740:                 foreach my $type (@{$titleorder}) {
                   2741:                     if (grep(/^\Q$type\E$/,@searchby)) {
                   2742:                         if (defined($searchtitles->{$type})) {
                   2743:                             $chgtext .= $searchtitles->{$type}.'; ';
                   2744:                         }
                   2745:                     }
                   2746:                 }
                   2747:                 $chgtext =~ s/\; $//;
                   2748:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
                   2749:             }
1.25      raeburn  2750:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
                   2751:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
                   2752:                 my $chgtext;
                   2753:                 foreach my $type (@{$srchtypeorder}) {
                   2754:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
                   2755:                         if (defined($srchtypes_desc->{$type})) {
                   2756:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
                   2757:                         }
                   2758:                     }
                   2759:                 }
                   2760:                 $chgtext =~ s/\; $//;
                   2761:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23      raeburn  2762:             }
                   2763:             $resulttext .= '</ul>';
                   2764:         } else {
                   2765:             $resulttext = &mt('No changes made to institution directory search settings');
                   2766:         }
                   2767:     } else {
                   2768:         $resulttext = '<span class="LC_error">'.
1.27      raeburn  2769:                       &mt('An error occurred: [_1]',$putresult).'</span>';
                   2770:     }
                   2771:     return $resulttext;
                   2772: }
                   2773: 
1.28      raeburn  2774: sub modify_contacts {
                   2775:     my ($dom,%domconfig) = @_;
                   2776:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
                   2777:     if (ref($domconfig{'contacts'}) eq 'HASH') {
                   2778:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
                   2779:             $currsetting{$key} = $domconfig{'contacts'}{$key};
                   2780:         }
                   2781:     }
                   2782:     my (%others,%to);
                   2783:     my @contacts = ('supportemail','adminemail');
                   2784:     my @mailings = ('errormail','packagesmail','helpdeskmail');
                   2785:     foreach my $type (@mailings) {
                   2786:         @{$newsetting{$type}} = 
                   2787:             &Apache::loncommon::get_env_multiple('form.'.$type);
                   2788:         foreach my $item (@contacts) {
                   2789:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
                   2790:                 $contacts_hash{contacts}{$type}{$item} = 1;
                   2791:             } else {
                   2792:                 $contacts_hash{contacts}{$type}{$item} = 0;
                   2793:             }
                   2794:         }  
                   2795:         $others{$type} = $env{'form.'.$type.'_others'};
                   2796:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
                   2797:     }
                   2798:     foreach my $item (@contacts) {
                   2799:         $to{$item} = $env{'form.'.$item};
                   2800:         $contacts_hash{'contacts'}{$item} = $to{$item};
                   2801:     }
                   2802:     if (keys(%currsetting) > 0) {
                   2803:         foreach my $item (@contacts) {
                   2804:             if ($to{$item} ne $currsetting{$item}) {
                   2805:                 $changes{$item} = 1;
                   2806:             }
                   2807:         }
                   2808:         foreach my $type (@mailings) {
                   2809:             foreach my $item (@contacts) {
                   2810:                 if (ref($currsetting{$type}) eq 'HASH') {
                   2811:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
                   2812:                         push(@{$changes{$type}},$item);
                   2813:                     }
                   2814:                 } else {
                   2815:                     push(@{$changes{$type}},@{$newsetting{$type}});
                   2816:                 }
                   2817:             }
                   2818:             if ($others{$type} ne $currsetting{$type}{'others'}) {
                   2819:                 push(@{$changes{$type}},'others');
                   2820:             }
                   2821:         }
                   2822:     } else {
                   2823:         my %default;
                   2824:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
                   2825:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
                   2826:         $default{'errormail'} = 'adminemail';
                   2827:         $default{'packagesmail'} = 'adminemail';
                   2828:         $default{'helpdeskmail'} = 'supportemail';
                   2829:         foreach my $item (@contacts) {
                   2830:            if ($to{$item} ne $default{$item}) {
                   2831:               $changes{$item} = 1;
                   2832:            } 
                   2833:         }
                   2834:         foreach my $type (@mailings) {
                   2835:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
                   2836:                
                   2837:                 push(@{$changes{$type}},@{$newsetting{$type}});
                   2838:             }
                   2839:             if ($others{$type} ne '') {
                   2840:                 push(@{$changes{$type}},'others');
                   2841:             } 
                   2842:         }
                   2843:     }
                   2844:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
                   2845:                                              $dom);
                   2846:     if ($putresult eq 'ok') {
                   2847:         if (keys(%changes) > 0) {
                   2848:             my ($titles,$short_titles)  = &contact_titles();
                   2849:             $resulttext = &mt('Changes made:').'<ul>';
                   2850:             foreach my $item (@contacts) {
                   2851:                 if ($changes{$item}) {
                   2852:                     $resulttext .= '<li>'.$titles->{$item}.
                   2853:                                     &mt(' set to: ').
                   2854:                                     '<span class="LC_cusr_emph">'.
                   2855:                                     $to{$item}.'</span></li>';
                   2856:                 }
                   2857:             }
                   2858:             foreach my $type (@mailings) {
                   2859:                 if (ref($changes{$type}) eq 'ARRAY') {
                   2860:                     $resulttext .= '<li>'.$titles->{$type}.': ';
                   2861:                     my @text;
                   2862:                     foreach my $item (@{$newsetting{$type}}) {
                   2863:                         push(@text,$short_titles->{$item});
                   2864:                     }
                   2865:                     if ($others{$type} ne '') {
                   2866:                         push(@text,$others{$type});
                   2867:                     }
                   2868:                     $resulttext .= '<span class="LC_cusr_emph">'.
                   2869:                                    join(', ',@text).'</span></li>';
                   2870:                 }
                   2871:             }
                   2872:             $resulttext .= '</ul>';
                   2873:         } else {
1.34      raeburn  2874:             $resulttext = &mt('No changes made to contact information');
1.28      raeburn  2875:         }
                   2876:     } else {
                   2877:         $resulttext = '<span class="LC_error">'.
                   2878:             &mt('An error occurred: [_1].',$putresult).'</span>';
                   2879:     }
                   2880:     return $resulttext;
                   2881: }
                   2882: 
                   2883: sub modify_usercreation {
1.27      raeburn  2884:     my ($dom,%domconfig) = @_;
1.34      raeburn  2885:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.27      raeburn  2886:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2887:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
                   2888:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
                   2889:         }
                   2890:     }
                   2891:     my %title = &Apache::lonlocal::texthash (
                   2892:                    author => 'adding co-authors/assistant authors',
                   2893:                    course => 'adding users to a course',
                   2894:                 );
                   2895:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32      raeburn  2896:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.34      raeburn  2897:     my @contexts = ('author','course');
                   2898:     foreach my $item(@contexts) {
                   2899:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
                   2900:     }
                   2901:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
                   2902:         foreach my $item (@contexts) {
                   2903:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
                   2904:                 push(@{$changes{'cancreate'}},$item);
                   2905:             } 
1.27      raeburn  2906:         }
1.34      raeburn  2907:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
                   2908:         foreach my $item (@contexts) {
                   2909:             if (grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
                   2910:                 if ($cancreate{$item} ne 'any') {
                   2911:                     push(@{$changes{'cancreate'}},$item);
                   2912:                 }
                   2913:             } else {
                   2914:                 if ($cancreate{$item} ne 'none') {
                   2915:                     push(@{$changes{'cancreate'}},$item);
                   2916:                 }
1.27      raeburn  2917:             }
                   2918:         }
                   2919:     } else {
1.34      raeburn  2920:         foreach my $item ('author','course') {
                   2921:             push(@{$changes{'cancreate'}},$item);
                   2922:         }
1.27      raeburn  2923:     }
1.34      raeburn  2924: 
1.27      raeburn  2925:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
                   2926:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
                   2927:             if (!grep(/^\Q$type\E$/,@username_rule)) {
                   2928:                 push(@{$changes{'username_rule'}},$type);
                   2929:             }
                   2930:         }
                   2931:         foreach my $type (@username_rule) {
                   2932:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
                   2933:                 push(@{$changes{'username_rule'}},$type);
                   2934:             }
                   2935:         }
                   2936:     } else {
                   2937:         push(@{$changes{'username_rule'}},@username_rule);
                   2938:     }
                   2939: 
1.32      raeburn  2940:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
                   2941:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
                   2942:             if (!grep(/^\Q$type\E$/,@id_rule)) {
                   2943:                 push(@{$changes{'id_rule'}},$type);
                   2944:             }
                   2945:         }
                   2946:         foreach my $type (@id_rule) {
                   2947:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
                   2948:                 push(@{$changes{'id_rule'}},$type);
                   2949:             }
                   2950:         }
                   2951:     } else {
                   2952:         push(@{$changes{'id_rule'}},@id_rule);
                   2953:     }
                   2954: 
1.28      raeburn  2955:     my @contexts = ('author','course','domain');
                   2956:     my @authtypes = ('int','krb4','krb5','loc');
                   2957:     my %authhash;
                   2958:     foreach my $item (@contexts) {
                   2959:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
                   2960:         foreach my $auth (@authtypes) {
                   2961:             if (grep(/^\Q$auth\E$/,@authallowed)) {
                   2962:                 $authhash{$item}{$auth} = 1;
                   2963:             } else {
                   2964:                 $authhash{$item}{$auth} = 0;
                   2965:             }
                   2966:         }
                   2967:     }
                   2968:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
                   2969:         foreach my $item (@contexts) {
                   2970:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
                   2971:                 foreach my $auth (@authtypes) {
                   2972:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
                   2973:                         push(@{$changes{'authtypes'}},$item);
                   2974:                         last;
                   2975:                     }
                   2976:                 }
                   2977:             }
                   2978:         }
                   2979:     } else {
                   2980:         foreach my $item (@contexts) {
                   2981:             push(@{$changes{'authtypes'}},$item);
                   2982:         }
                   2983:     }
                   2984: 
1.27      raeburn  2985:     my %usercreation_hash =  (
1.28      raeburn  2986:             usercreation => {
1.34      raeburn  2987:                               cancreate     => \%cancreate,
1.27      raeburn  2988:                               username_rule => \@username_rule,
1.32      raeburn  2989:                               id_rule       => \@id_rule,
                   2990:                               authtypes     => \%authhash,
1.27      raeburn  2991:                             }
                   2992:             );
                   2993: 
                   2994:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
                   2995:                                              $dom);
                   2996:     if ($putresult eq 'ok') {
                   2997:         if (keys(%changes) > 0) {
                   2998:             $resulttext = &mt('Changes made:').'<ul>';
                   2999:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34      raeburn  3000:                 my %lt = &usercreation_types();
                   3001:                 foreach my $type (@{$changes{'cancreate'}}) {
                   3002:                     my $chgtext; 
                   3003:                     if ($cancreate{$type} eq 'none') {
                   3004:                         $chgtext = $lt{$type}.' '.&mt('creation of new users is not permitted, except by a Domain Coordinator.');
                   3005:                     } elsif ($cancreate{$type} eq 'any') {
                   3006:                         $chgtext = $lt{$type}.' '.&mt('creation of new users is permitted for both institutional and non-institutional usernames.'); 
                   3007:                     } elsif ($cancreate{$type} eq 'official') {
                   3008:                         $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for institutional usernames.',$lt{$type});
                   3009:                     } elsif ($cancreate{$type} eq 'unofficial') {
                   3010:                         $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for non-institutional usernames.',$lt{$type});
                   3011:                     }
                   3012:                     $resulttext .= '<li>'.$chgtext.'</li>';
1.27      raeburn  3013:                 }
                   3014:             }
                   3015:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32      raeburn  3016:                 my ($rules,$ruleorder) = 
                   3017:                     &Apache::lonnet::inst_userrules($dom,'username');
1.27      raeburn  3018:                 my $chgtext = '<ul>';
                   3019:                 foreach my $type (@username_rule) {
                   3020:                     if (ref($rules->{$type}) eq 'HASH') {
                   3021:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
                   3022:                     }
                   3023:                 }
                   3024:                 $chgtext .= '</ul>';
                   3025:                 if (@username_rule > 0) {
                   3026:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
                   3027:                 } else {
1.28      raeburn  3028:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
1.27      raeburn  3029:                 }
                   3030:             }
1.32      raeburn  3031:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
                   3032:                 my ($idrules,$idruleorder) = 
                   3033:                     &Apache::lonnet::inst_userrules($dom,'id');
                   3034:                 my $chgtext = '<ul>';
                   3035:                 foreach my $type (@id_rule) {
                   3036:                     if (ref($idrules->{$type}) eq 'HASH') {
                   3037:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
                   3038:                     }
                   3039:                 }
                   3040:                 $chgtext .= '</ul>';
                   3041:                 if (@id_rule > 0) {
                   3042:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
                   3043:                 } else {
                   3044:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
                   3045:                 }
                   3046:             }
1.28      raeburn  3047:             my %authname = &authtype_names();
                   3048:             my %context_title = &context_names();
                   3049:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
                   3050:                 my $chgtext = '<ul>';
                   3051:                 foreach my $type (@{$changes{'authtypes'}}) {
                   3052:                     my @allowed;
                   3053:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
                   3054:                     foreach my $auth (@authtypes) {
                   3055:                         if ($authhash{$type}{$auth}) {
                   3056:                             push(@allowed,$authname{$auth});
                   3057:                         }
                   3058:                     }
                   3059:                     $chgtext .= join(', ',@allowed).'</li>';
                   3060:                 }
                   3061:                 $chgtext .= '</ul>';
                   3062:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
                   3063:                 $resulttext .= '</li>';
                   3064:             }
1.27      raeburn  3065:             $resulttext .= '</ul>';
                   3066:         } else {
1.28      raeburn  3067:             $resulttext = &mt('No changes made to user creation settings');
1.27      raeburn  3068:         }
                   3069:     } else {
                   3070:         $resulttext = '<span class="LC_error">'.
1.23      raeburn  3071:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   3072:     }
                   3073:     return $resulttext;
                   3074: }
                   3075: 
1.33      raeburn  3076: sub modify_usermodification {
                   3077:     my ($dom,%domconfig) = @_;
                   3078:     my ($resulttext,%curr_usermodification,%changes);
                   3079:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
                   3080:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
                   3081:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
                   3082:         }
                   3083:     }
                   3084:     my @contexts = ('author','course');
                   3085:     my %context_title = (
                   3086:                            author => 'In author context',
                   3087:                            course => 'In course context',
                   3088:                         );
                   3089:     my @fields = ('lastname','firstname','middlename','generation',
                   3090:                   'permanentemail','id');
                   3091:     my %roles = (
                   3092:                   author => ['ca','aa'],
                   3093:                   course => ['st','ep','ta','in','cr'],
                   3094:                 );
                   3095:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
                   3096:     my %modifyhash;
                   3097:     foreach my $context (@contexts) {
                   3098:         foreach my $role (@{$roles{$context}}) {
                   3099:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
                   3100:             foreach my $item (@fields) {
                   3101:                 if (grep(/^\Q$item\E$/,@modifiable)) {
                   3102:                     $modifyhash{$context}{$role}{$item} = 1;
                   3103:                 } else {
                   3104:                     $modifyhash{$context}{$role}{$item} = 0;
                   3105:                 }
                   3106:             }
                   3107:         }
                   3108:         if (ref($curr_usermodification{$context}) eq 'HASH') {
                   3109:             foreach my $role (@{$roles{$context}}) {
                   3110:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
                   3111:                     foreach my $field (@fields) {
                   3112:                         if ($modifyhash{$context}{$role}{$field} ne 
                   3113:                                 $curr_usermodification{$context}{$role}{$field}) {
                   3114:                             push(@{$changes{$context}},$role);
                   3115:                             last;
                   3116:                         }
                   3117:                     }
                   3118:                 }
                   3119:             }
                   3120:         } else {
                   3121:             foreach my $context (@contexts) {
                   3122:                 foreach my $role (@{$roles{$context}}) {
                   3123:                     push(@{$changes{$context}},$role);
                   3124:                 }
                   3125:             }
                   3126:         }
                   3127:     }
                   3128:     my %usermodification_hash =  (
                   3129:                                    usermodification => \%modifyhash,
                   3130:                                  );
                   3131:     my $putresult = &Apache::lonnet::put_dom('configuration',
                   3132:                                              \%usermodification_hash,$dom);
                   3133:     if ($putresult eq 'ok') {
                   3134:         if (keys(%changes) > 0) {
                   3135:             $resulttext = &mt('Changes made: ').'<ul>';
                   3136:             foreach my $context (@contexts) {
                   3137:                 if (ref($changes{$context}) eq 'ARRAY') {
                   3138:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
                   3139:                     if (ref($changes{$context}) eq 'ARRAY') {
                   3140:                         foreach my $role (@{$changes{$context}}) {
                   3141:                             my $rolename;
                   3142:                             if ($role eq 'cr') {
                   3143:                                 $rolename = &mt('Custom');
                   3144:                             } else {
                   3145:                                 $rolename = &Apache::lonnet::plaintext($role);
                   3146:                             }
                   3147:                             my @modifiable;
                   3148:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
                   3149:                             foreach my $field (@fields) {
                   3150:                                 if ($modifyhash{$context}{$role}{$field}) {
                   3151:                                     push(@modifiable,$fieldtitles{$field});
                   3152:                                 }
                   3153:                             }
                   3154:                             if (@modifiable > 0) {
                   3155:                                 $resulttext .= join(', ',@modifiable);
                   3156:                             } else {
                   3157:                                 $resulttext .= &mt('none'); 
                   3158:                             }
                   3159:                             $resulttext .= '</li>';
                   3160:                         }
                   3161:                         $resulttext .= '</ul></li>';
                   3162:                     }
                   3163:                 }
                   3164:             }
                   3165:             $resulttext .= '</ul>';
                   3166:         } else {
                   3167:             $resulttext = &mt('No changes made to user modification settings');
                   3168:         }
                   3169:     } else {
                   3170:         $resulttext = '<span class="LC_error">'.
                   3171:             &mt('An error occurred: [_1]',$putresult).'</span>';
                   3172:     }
                   3173:     return $resulttext;
                   3174: }
                   3175: 
1.3       raeburn  3176: 1;

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