File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.30: download - view: text, annotated - select for diffs
Wed Sep 26 12:42:32 2007 UTC (16 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
lonhtmlcommon.pm
- javascript to get dimensions of user's browser window.

domainprefs.pm
- show background colors, font colors
- add page to selection functionality to display/edit
  - choice of one or two column format
  - in two-column format, balance items between two columns

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

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