File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.44: download - view: text, annotated - select for diffs
Fri Feb 29 19:07:06 2008 UTC (16 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Move &sorted_inst_types() to loncommon.pm for broader use.
- Change "othertitle" to be used when in course context.

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

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