File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.10: download - view: text, annotated - select for diffs
Tue Apr 10 21:40:12 2007 UTC (17 years, 1 month ago) by albertel
Branches: MAIN
CVS tags: HEAD
- if didn't need to be in the loop

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.10 2007/04/10 21:40:12 albertel 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 = "display";
   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'],$dom);
   71:     my @prefs = (
   72:       { text => 'Default color schemes',
   73:         help => 'Default_Color_Schemes',
   74:         action => 'rolecolors',
   75:         header => [{col1 => 'Student Settings',
   76:                     col2 => '',},
   77:                    {col1 => 'Coordinator Settings',
   78:                     col2 => '',},
   79:                    {col1 => 'Author Settings',
   80:                     col2 => '',},
   81:                    {col1 => 'Administrator Settings',
   82:                     col2 => '',}],
   83:         },
   84:       { text => 'Log-in page options',
   85:         help => 'Domain_Log-in_Page',
   86:         action => 'login',
   87:         header => [{col1 => 'Item',
   88:                     col2 => '',}],
   89:         },
   90:       { text => 'Default quotas for user portfolios',
   91:         help => 'Default_User_Quota',
   92:         action => 'quotas',
   93:         header => [{col1 => 'User type',
   94:                     col2 => 'Default quota'}],
   95:         },
   96:       { text => 'Auto-enrollment settings',
   97:         help => 'Domain_Auto_Enrollment',
   98:         action => 'autoenroll',
   99:         header => [{col1 => 'Configuration setting',
  100:                     col2 => 'Value(s)'}],
  101:         },
  102:       { text => 'Auto-update settings',
  103:         help => 'Domain_Auto_Update',
  104:         action => 'autoupdate',
  105:         header => [{col1 => 'Setting',
  106:                     col2 => 'Value',},
  107:                    {col1 => 'User Population',
  108:                     col2 => 'Updataeable user data'}],
  109:       },
  110:     );
  111:     my @roles = ('student','coordinator','author','admin');
  112:     &Apache::lonhtmlcommon::add_breadcrumb
  113:     ({href=>"javascript:changePage(document.$phase,'display')",
  114:       text=>"Domain Configuration"});
  115:     my $confname = $dom.'-domainconfig';
  116:     if ($phase eq 'process') {
  117:         &Apache::lonhtmlcommon::add_breadcrumb
  118:           ({href=>"javascript:changePage(document.$phase,'$phase')",
  119:             text=>"Updated"});
  120:         &print_header($r,$phase);
  121:         foreach my $item (@prefs) {
  122:             $r->print('<h3>'.&mt($item->{'text'}).'</h3>'.
  123:                       &process_changes($r,$dom,$confname,
  124:                         $item->{'action'},\@roles,%domconfig));
  125:         }
  126:         $r->print('<p>');
  127:         &print_footer($r,$phase,'display','Back to actions menu');
  128:         $r->print('</p>');
  129:     } else {
  130:         if ($phase eq '') {
  131:             $phase = 'display';
  132:         }
  133:         my %helphash;   
  134:         my $numprefs = @prefs;
  135:         &print_header($r,$phase);
  136:         $r->print('<table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
  137:         foreach my $item (@prefs) {
  138:             if ($item->{'action'} eq 'login') {
  139:                 $r->print('</td><td width="6%">&nbsp;</td><td align="left" valign="top" width="47%">');
  140:             }
  141:             &print_config_box($r,$dom,$confname,$phase,$item->{'action'},
  142:                               $item,$domconfig{$item->{'action'}});
  143:         }
  144:         $r->print('
  145:       </td>
  146:     </tr>
  147:    </table>');
  148:         &print_footer($r,$phase,'process','Store changes');
  149:     }
  150:     return OK;
  151: }
  152: 
  153: sub process_changes {
  154:     my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
  155:     my $output;
  156:     if ($action eq 'login') {
  157:         $output = &modify_login($r,$dom,$confname,%domconfig);
  158:     } elsif ($action eq 'rolecolors') {
  159:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
  160:                                      %domconfig);
  161:     } elsif ($action eq 'quotas') {
  162:         $output = &modify_quotas($dom,%domconfig);
  163:     } elsif ($action eq 'autoenroll') {
  164:         $output = &modify_autoenroll($dom,%domconfig);
  165:     } elsif ($action eq 'autoupdate') {
  166:         $output = &modify_autoupdate($dom,%domconfig);
  167:     }
  168:     return $output;
  169: }
  170: 
  171: sub print_config_box {
  172:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
  173:     $r->print('
  174:          <table class="LC_nested_outer">
  175:           <tr>
  176:            <th>'.&mt($item->{text}).'&nbsp;'.
  177:            &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
  178:           </tr>');
  179:     if (($action eq 'autoupdate') || ($action eq 'rolecolors')) {
  180:         my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
  181:         $r->print('
  182:           <tr>
  183:            <td>
  184:             <table class="LC_nested">
  185:              <tr class="LC_info_row">
  186:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
  187:               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
  188:              </tr>');
  189:         if ($action eq 'autoupdate') {
  190:             $r->print(&print_autoupdate('top',$dom,$settings));
  191:         } else {
  192:             $r->print(&print_rolecolors($phase,'student',$dom,$confname,$settings));
  193:         }
  194:         $r->print('
  195:            </table>
  196:           </td>
  197:          </tr>
  198:          <tr>
  199:            <td>
  200:             <table class="LC_nested">
  201:              <tr class="LC_info_row">
  202:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
  203:               <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
  204:              </tr>');
  205:         if ($action eq 'autoupdate') {
  206:             $r->print(&print_autoupdate('bottom',$dom,$settings));
  207:         } else {
  208:             $r->print(&print_rolecolors($phase,'coordinator',$dom,$confname,$settings).'
  209:            </table>
  210:           </td>
  211:          </tr>
  212:          <tr>
  213:            <td>
  214:             <table class="LC_nested">
  215:              <tr class="LC_info_row">
  216:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
  217:               <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
  218:              </tr>'.
  219:             &print_rolecolors($phase,'author',$dom,$confname,$settings).'
  220:            </table>
  221:           </td>
  222:          </tr>
  223:          <tr>
  224:            <td>
  225:             <table class="LC_nested">
  226:              <tr class="LC_info_row">
  227:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
  228:               <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
  229:              </tr>'.
  230:             &print_rolecolors($phase,'admin',$dom,$confname,$settings));
  231:         }
  232:     } else {
  233:         $r->print('
  234:           <tr>
  235:            <td>
  236:             <table class="LC_nested">
  237:              <tr class="LC_info_row">');
  238:         if ($action eq 'login') {
  239:             $r->print('  
  240:               <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>');
  241:         } else {
  242:             $r->print('
  243:               <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>');
  244:         }
  245:         $r->print('
  246:               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
  247:              </tr>');
  248:         if ($action eq 'login') {
  249:            $r->print(&print_login($dom,$confname,$phase,$settings));
  250:         } elsif ($action eq 'quotas') {
  251:            $r->print(&print_quotas($dom,$settings));
  252:         } elsif ($action eq 'autoenroll') {
  253:            $r->print(&print_autoenroll($dom,$settings));
  254:         }  
  255:     }
  256:     $r->print('
  257:    </table>
  258:   </td>
  259:  </tr>
  260: </table><br />');
  261:     return;
  262: }
  263: 
  264: sub print_header {
  265:     my ($r,$phase) = @_;
  266:     my $js = '
  267: <script type="text/javascript">
  268: function changePage(formname,newphase) {
  269:     formname.phase.value = newphase;
  270:     formname.submit();
  271: }
  272: '.
  273: &color_pick_js().'
  274: </script>
  275: ';
  276:     $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
  277:                                            $js));
  278:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
  279:     $r->print('
  280: <form name="parmform" action="">
  281: <input type="hidden" name="pres_marker" />
  282: <input type="hidden" name="pres_type" />
  283: <input type="hidden" name="pres_value" />
  284: </form>
  285: ');
  286:     $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
  287:               ' enctype="multipart/form-data">');
  288:     return;
  289: }
  290: 
  291: sub print_footer {
  292:     my ($r,$phase,$newphase,$button_text) = @_;
  293:     $button_text = &mt($button_text);
  294:     $r->print('<input type="hidden" name="phase" value="" />');
  295:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  296:     if ($phase eq 'process') {
  297:         $r->print('<a href='.$dest.'>'.$button_text.'</a>');
  298:     } else {
  299:         $r->print('<input type="button" name="store" value="'.
  300:                   $button_text.'" onclick='.$dest.' />');
  301:     }
  302:     $r->print('</form>');
  303:     $r->print('<br />'.&Apache::loncommon::end_page());
  304:     return;
  305: }
  306: 
  307: sub print_login {
  308:     my ($dom,$confname,$phase,$settings) = @_;
  309:     my %choices = &login_choices();
  310:     my ($catalogon,$catalogoff,$adminmailon,$adminmailoff);
  311:     $catalogon = ' checked="checked" ';
  312:     $adminmailoff = ' checked="checked" ';
  313:     my @images = ('img','logo','domlogo');
  314:     my @bgs = ('pgbg','mainbg','sidebg');
  315:     my @links = ('link','alink','vlink');
  316:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  317:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  318:     my (%is_custom,%designs);
  319:     my %defaults = (
  320:                    font => $defaultdesign{'login.font'},
  321:                    );
  322:     foreach my $item (@images) {
  323:         $defaults{$item} = $defaultdesign{'login.'.$item};
  324:     }
  325:     foreach my $item (@bgs) {
  326:         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
  327:     }
  328:     foreach my $item (@links) {
  329:         $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
  330:     }
  331:     if (ref($settings) eq 'HASH') {
  332:         if ($settings->{'coursecatalog'} eq '0') {
  333:             $catalogoff = $catalogon;
  334:             $catalogon = ' ';
  335:         }
  336:         if ($settings->{'adminmail'} eq '1') {
  337:             $adminmailon = $adminmailoff;
  338:             $adminmailoff = ' ';
  339:         }
  340:         foreach my $item (@images) {
  341:             if ($settings->{$item} ne '') {
  342:                 $designs{$item} = $settings->{$item};
  343:                 $is_custom{$item} = 1;
  344:             }
  345:         }
  346:         if ($settings->{'font'} ne '') {
  347:             $designs{'font'} = $settings->{'font'};
  348:             $is_custom{'font'} = 1;
  349:         }
  350:         foreach my $item (@bgs) {
  351:             if ($settings->{$item} ne '') {
  352:                 $designs{'bgs'}{$item} = $settings->{$item};
  353:                 $is_custom{$item} = 1;
  354:             }
  355:         }
  356:         foreach my $item (@links) {
  357:             if ($settings->{$item} ne '') {
  358:                 $designs{'links'}{$item} = $settings->{$item};
  359:                 $is_custom{$item} = 1;
  360:             }
  361:         }
  362:     } else {
  363:         if ($designhash{$dom.'.login.font'} ne '') {
  364:             $designs{'font'} = $designhash{$dom.'.login.font'};
  365:             $is_custom{'font'} = 1;
  366:         }
  367:         foreach my $item (@images) {
  368:             if ($designhash{$dom.'.login.'.$item} ne '') {
  369:                 $designs{$item} = $designhash{$dom.'.login.'.$item};
  370:                 $is_custom{$item} = 1;
  371:             }
  372:         }
  373:         foreach my $item (@bgs) {
  374:             if ($designhash{$dom.'.login.'.$item} ne '') {
  375:                 $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
  376:                 $is_custom{$item} = 1;
  377:             }
  378:         }
  379:         foreach my $item (@links) {
  380:             if ($designhash{$dom.'.login.'.$item} ne '') {
  381:                 $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
  382:                 $is_custom{$item} = 1;
  383:             }
  384:         }
  385:     }
  386:     my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
  387:                                                   logo => 'Institution Logo',
  388:                                                   domlogo => 'Domain Logo');
  389:     my $itemcount = 1;
  390:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
  391:     my $datatable = 
  392:         '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
  393:         '</td><td>'.
  394:         '<span class="LC_nobreak"><label><input type="radio" name="coursecatalog"'.
  395:         $catalogon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  396:         '<label><input type="radio" name="coursecatalog"'.
  397:         $catalogoff.'value="0" />'.&mt('No').'</label></span></td>'.
  398:         '</tr>';
  399:     $itemcount ++;
  400:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  401:     $datatable .= '<tr'.$css_class.'>'.
  402:         '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
  403:         '<td><span class="LC_nobreak">'.
  404:         '<label><input type="radio" name="adminmail"'.
  405:         $adminmailon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  406:         '<label><input type="radio" name="adminmail"'.
  407:         $adminmailoff.'value="0" />'.&mt('No').'</label></span></td></tr>';
  408:     $itemcount ++;
  409:     $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
  410:     $datatable .= '</tr></table></td></tr>';
  411:     return $datatable;
  412: }
  413: 
  414: sub login_choices {
  415:     my %choices =
  416:         &Apache::lonlocal::texthash (
  417:             coursecatalog => 'Display Course Catalog link?',
  418:             adminmail => "Display Administrator's E-mail Address?",
  419:             img => "Header",
  420:             logo => "Main Logo",
  421:             domlogo => "Domain Logo",
  422:             bgs => "Background colors",
  423:             links => "Link colors",
  424:             font => "Font color",
  425:             pgbg => "Page",
  426:             mainbg => "Main panel",
  427:             sidebg => "Side panel",
  428:             link => "Link",
  429:             alink => "Active link",
  430:             vlink => "Visited link",
  431:         );
  432:     return %choices;
  433: }
  434: 
  435: sub print_rolecolors {
  436:     my ($phase,$role,$dom,$confname,$settings) = @_;
  437:     my %choices = &color_font_choices();
  438:     my @bgs = ('pgbg','tabbg','sidebg');
  439:     my @links = ('link','alink','vlink');
  440:     my @images = ('img');
  441:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
  442:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  443:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  444:     my (%is_custom,%designs);
  445:     my %defaults = (
  446:                    img => $defaultdesign{$role.'.img'},
  447:                    font => $defaultdesign{$role.'.font'},
  448:                    );
  449:     foreach my $item (@bgs) {
  450:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
  451:     }
  452:     foreach my $item (@links) {
  453:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
  454:     }
  455:     if (ref($settings) eq 'HASH') {
  456:         if (ref($settings->{$role}) eq 'HASH') {
  457:             if ($settings->{$role}->{'img'} ne '') {
  458:                 $designs{'img'} = $settings->{$role}->{'img'};
  459:                 $is_custom{'img'} = 1;
  460:             }
  461:             if ($settings->{$role}->{'font'} ne '') {
  462:                 $designs{'font'} = $settings->{$role}->{'font'};
  463:                 $is_custom{'font'} = 1;
  464:             }
  465:             foreach my $item (@bgs) {
  466:                 if ($settings->{$role}->{$item} ne '') {
  467:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
  468:                     $is_custom{$item} = 1;
  469:                 }
  470:             }
  471:             foreach my $item (@links) {
  472:                 if ($settings->{$role}->{$item} ne '') {
  473:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
  474:                     $is_custom{$item} = 1;
  475:                 }
  476:             }
  477:         }
  478:     } else {
  479:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  480:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
  481:             $is_custom{'img'} = 1;
  482:         }
  483:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
  484:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
  485:             $is_custom{'font'} = 1;
  486:         }
  487:         foreach my $item (@bgs) {
  488:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  489:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  490:                 $is_custom{$item} = 1;
  491:             
  492:             }
  493:         }
  494:         foreach my $item (@links) {
  495:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  496:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  497:                 $is_custom{$item} = 1;
  498:             }
  499:         }
  500:     }
  501:     my $itemcount = 1;
  502:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
  503:     $datatable .= '</tr></table></td></tr>';
  504:     return $datatable;
  505: }
  506: 
  507: sub display_color_options {
  508:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
  509:         $images,$bgs,$links,$alt_text) = @_;
  510:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
  511:     my $datatable = '<tr'.$css_class.'>'.
  512:         '<td>'.$choices->{'font'}.'</td>';
  513:     if (!$is_custom->{'font'}) {
  514:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;'.$defaults->{'font'}.'</td>';
  515:     } else {
  516:         $datatable .= '<td>&nbsp;</td>';
  517:     }
  518:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
  519:     $datatable .= '<td><span class="LC_nobreak">'.
  520:                   '<input type="text" size="10" name="'.$role.'_font"'.
  521:                   ' value="'.$designs->{'font'}.'" />&nbsp;'.$fontlink.
  522:                   '</span></td></tr>';
  523:     my $switchserver = &check_switchserver($dom,$confname);
  524:     foreach my $img (@{$images}) {
  525:         $itemcount ++;
  526:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
  527:         $datatable .= '<tr'.$css_class.'>'.
  528:                       '<td>'.$choices->{$img}.'</td>';
  529:         my $imgfile;
  530:         if ($designs->{$img} ne '') {
  531:             $imgfile = $designs->{$img};
  532:         } else {
  533:             $imgfile = $defaults->{$img};
  534:         }
  535:         if ($imgfile) {
  536:             my ($showfile,$fullsize);
  537:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
  538:                 my $urldir = $1;
  539:                 my $filename = $2;
  540:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
  541:                 if (@info) {
  542:                     my $thumbfile = 'tn-'.$filename;
  543:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
  544:                     if (@thumb) {
  545:                         $showfile = $urldir.'/'.$thumbfile;
  546:                     } else {
  547:                         $showfile = $imgfile;
  548:                     }
  549:                 } else {
  550:                     $showfile = '';
  551:                 }
  552:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
  553:                 my $imgdir = $1;
  554:                 my $filename = $2;
  555:                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
  556:                     $showfile = "/$imgdir/tn-".$filename;
  557:                 } else {
  558:                     my $input = "/home/httpd/html".$imgfile;
  559:                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
  560:                     if (!-e $output) {
  561:                         my ($width,$height) = &thumb_dimensions();
  562:                         my $size = $width.'x'.$height;
  563:                         system("convert -sample $size $input $output");
  564:                     }
  565:                     $showfile = '/'.$imgdir.'/tn-'.$filename;
  566:                 }
  567:             } 
  568:             if ($showfile) {
  569:                 $showfile = &Apache::loncommon::lonhttpdurl($showfile);
  570:                 $fullsize =  &Apache::loncommon::lonhttpdurl($imgfile);
  571:                 $datatable.= '<td>';
  572:                 if (!$is_custom->{$img}) {
  573:                     $datatable .= &mt('Default in use:').'<br />';
  574:                 }
  575:                 $datatable.= '<a href="'.$fullsize.'" target="_blank"><img src="'.
  576:                              $showfile.'" alt="'.$alt_text->{$img}.
  577:                              '" border="0" /></a></td>';
  578:                 if ($is_custom->{$img}) {
  579:                     $datatable.='<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
  580:                                 $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
  581:                                 '</label>&nbsp;'.&mt('Replace:').'</span><br />';
  582:                 } else {
  583:                     $datatable.='<td valign="bottom">'.&mt('Upload:').'<br />';
  584:                 }
  585:             } else {
  586:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
  587:                               &mt('Upload:');
  588:             }
  589:         } else {
  590:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
  591:                           &mt('Upload:');
  592:         }
  593:         if ($switchserver) {
  594:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
  595:         } else {
  596:             $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
  597:         }
  598:         $datatable .= '</td></tr>';
  599:     }
  600:     $itemcount ++;
  601:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  602:     $datatable .= '<tr'.$css_class.'>'.
  603:                   '<td>'.$choices->{'bgs'}.'</td>';
  604:     my $bgs_def;
  605:     foreach my $item (@{$bgs}) {
  606:         if (!$is_custom->{$item}) {
  607:             $bgs_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'bgs'}{$item}.'</td>';
  608:         }
  609:     }
  610:     if ($bgs_def) {
  611:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
  612:     } else {
  613:         $datatable .= '<td>&nbsp;</td>';
  614:     }
  615:     $datatable .= '<td class="LC_right_item">'.
  616:                   '<table border="0"><tr>';
  617:     foreach my $item (@{$bgs}) {
  618:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
  619:         $datatable .= '<td align="center">'.$link;
  620:         if ($designs->{'bgs'}{$item}) {
  621:             $datatable .= '<span style="background-color:'.$designs->{'bgs'}{$item}.'width: 10px">&nbsp;</span>';
  622:         }
  623:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
  624:                       '" /></td>';
  625:     }
  626:     $datatable .= '</tr></table></td></tr>';
  627:     $itemcount ++;
  628:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  629:     $datatable .= '<tr'.$css_class.'>'.
  630:                   '<td>'.$choices->{'links'}.'</td>';
  631:     my $links_def;
  632:     foreach my $item (@{$links}) {
  633:         if (!$is_custom->{$item}) {
  634:             $links_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'links'}{$item}.'</td>';
  635:         }
  636:     }
  637:     if ($links_def) {
  638:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
  639:     } else {
  640:         $datatable .= '<td>&nbsp;</td>';
  641:     }
  642:     $datatable .= '<td class="LC_right_item">'.
  643:                   '<table border="0"><tr>';
  644:     foreach my $item (@{$links}) {
  645:         $datatable .= '<td align="center">';
  646:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'links'}{$item});
  647:         if ($designs->{'links'}{$item}) {
  648:             $datatable.='<span style="color: '.$designs->{'links'}{$item}.';">'.
  649:                         $link.'</span>';
  650:         } else {
  651:             $datatable .= $link;
  652:         }
  653:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
  654:                       '" /></td>';
  655:     }
  656:     return $datatable;
  657: }
  658: 
  659: sub color_pick {
  660:     my ($phase,$role,$item,$desc,$curcol) = @_;
  661:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
  662:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
  663:                ');">'.$desc.'</a>';
  664:     return $link;
  665: }
  666: 
  667: sub color_pick_js {
  668:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  669:     my $output = <<"ENDCOL";
  670:     function pclose() {
  671:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
  672:         parmwin.close();
  673:     }
  674: 
  675:     $pjump_def
  676: 
  677:     function psub() {
  678:         pclose();
  679:         if (document.parmform.pres_marker.value!='') {
  680:             if (document.parmform.pres_type.value!='') {
  681:                 eval('document.display.'+
  682:                      document.parmform.pres_marker.value+
  683:                      '.value=document.parmform.pres_value.value;');
  684:             }
  685:         } else {
  686:             document.parmform.pres_value.value='';
  687:             document.parmform.pres_marker.value='';
  688:         }
  689:     }
  690: ENDCOL
  691:     return $output;
  692: }
  693: 
  694: sub print_quotas {
  695:     my ($dom,$settings) = @_;
  696:     my $datatable;
  697:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
  698:     my $othertitle = "All users";
  699:     my @types;
  700:     if (ref($order) eq 'ARRAY') {
  701:         @types = @{$order};
  702:     }
  703:     if (@types == 0) {
  704:         if (ref($usertypes) eq 'HASH') {
  705:             @types = sort(keys(%{$usertypes}));
  706:         }
  707:     }
  708:     my $typecount = 0;
  709:     my $css_class;
  710:     if (@types > 0) {
  711:         foreach my $type (@types) {
  712:             if (defined($usertypes->{$type})) {
  713:                 $typecount ++;
  714:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
  715:                 $datatable .= '<tr'.$css_class.'>'. 
  716:                               '<td>'.$usertypes->{$type}.'</td>'.
  717:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
  718:                               '<input type="text" name="quota_'.$type.
  719:                               '" value="'.$settings->{$type}.
  720:                               '" size="5" /> Mb</span></td></tr>';
  721:             }
  722:         }
  723:         $othertitle = "Other users";
  724:     }
  725:     my $defaultquota = '20';
  726:     if (ref($settings) eq 'HASH') {
  727:         if (defined($settings->{'default'})) {
  728:             $defaultquota = $settings->{'default'};
  729:         }
  730:     }
  731:     $typecount ++;
  732:     $css_class = $typecount%2?' class="LC_odd_row"':'';
  733:     $datatable .= '<tr'.$css_class.'>'.
  734:                   '<td>'.&mt($othertitle).'</td>'.
  735:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
  736:                   '<input type="text" name="default" value="'.
  737:                   $defaultquota.'" size="5" /> Mb</span></td></tr>';
  738:     return $datatable;
  739: }
  740: 
  741: sub print_autoenroll {
  742:     my ($dom,$settings) = @_;
  743:     my $defdom = $dom;
  744:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
  745:     my ($runon,$runoff);
  746:     if (ref($settings) eq 'HASH') {
  747:         if (exists($settings->{'run'})) {
  748:             if ($settings->{'run'} eq '0') {
  749:                 $runoff = ' checked="checked" ';
  750:                 $runon = ' ';
  751:             } else {
  752:                 $runon = ' checked="checked" ';
  753:                 $runoff = ' ';
  754:             }
  755:         } else {
  756:             if ($autorun) {
  757:                 $runon = ' checked="checked" ';
  758:                 $runoff = ' ';
  759:             } else {
  760:                 $runoff = ' checked="checked" ';
  761:                 $runon = ' ';
  762:             }
  763:         }
  764:         if (exists($settings->{'sender_domain'})) {
  765:             $defdom = $settings->{'sender_domain'};
  766:         }
  767:     }
  768:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
  769:     my $datatable='<tr class="LC_odd_row">'.
  770:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
  771:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
  772:                   '<input type="radio" name="autoenroll_run"'.
  773:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  774:                   '<label><input type="radio" name="autoenroll_run"'.
  775:                   $runoff.'value="0" />'.&mt('No').'</label></span></td>'.
  776:                   '</tr><tr>'.
  777:                   '<td>'.&mt('Notification messages - sender').
  778:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
  779:                   &mt('username').':&nbsp;'.
  780:                   '<input type="text" name="sender_uname" value="'.
  781:                   $settings->{'sender_uname'}.
  782:                   '" size="10" />&nbsp;&nbsp;'.&mt('domain').
  783:                   ':&nbsp;'.$domform.'</span></td></tr>';
  784:     return $datatable;
  785: }
  786: 
  787: sub print_autoupdate {
  788:     my ($position,$dom,$settings) = @_;
  789:     my $datatable;
  790:     if ($position eq 'top') {
  791:         my $updateon = ' ';
  792:         my $updateoff = ' checked="checked" ';
  793:         my $classlistson = ' ';
  794:         my $classlistsoff = ' checked="checked" ';
  795:         if (ref($settings) eq 'HASH') {
  796:             if ($settings->{'run'} eq '1') {
  797:                 $updateon = $updateoff;
  798:                 $updateoff = ' ';
  799:             }
  800:             if ($settings->{'classlists'} eq '1') {
  801:                 $classlistson = $classlistsoff;
  802:                 $classlistsoff = ' ';
  803:             }
  804:         }
  805:         my %title = (
  806:                    run => 'Auto-update active?',
  807:                    classlists => 'Update information in classlists?',
  808:                     );
  809:         $datatable = '<tr class="LC_odd_row">'. 
  810:                   '<td>'.&mt($title{'run'}).'</td>'.
  811:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
  812:                   '<input type="radio" name="autoupdate_run"'.
  813:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  814:                   '<label><input type="radio" name="autoupdate_run"'.
  815:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
  816:                   '</tr><tr>'.
  817:                   '<td>'.&mt($title{'classlists'}).'</td>'.
  818:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
  819:                   '<label><input type="radio" name="classlists"'.
  820:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  821:                   '<label><input type="radio" name="classlists"'.
  822:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
  823:                   '</tr>';
  824:     } else {
  825:         my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
  826:         my @types;
  827:         if (ref($order) eq 'ARRAY') {
  828:             @types = @{$order};
  829:         }
  830:         if (@types == 0) {
  831:             if (ref($usertypes) eq 'HASH') {
  832:                 @types = sort(keys(%{$usertypes}));
  833:             }
  834:         }
  835:         my $othertitle = &mt('All users');
  836:         if (keys(%{$usertypes}) > 0) {
  837:             $othertitle = &mt('Other users');
  838:         }
  839:         my @fields = ('lastname','firstname','middlename','gen','email','id');
  840:         my %fieldtitles = &Apache::lonlocal::texthash (
  841:                             id => 'Student/Employee ID',
  842:                             email => 'E-mail address',
  843:                             lastname => 'Last Name',
  844:                             firstname => 'First Name',
  845:                             middlename => 'Middle Name',
  846:                             gen => 'Generation',
  847:                       );
  848:         my $numrows = 0;
  849:         if (@types > 0) {
  850:             $datatable = 
  851:                 &usertype_update_row($settings,$usertypes,\%fieldtitles,
  852:                                      \@fields,\@types,\$numrows);
  853:         }
  854:         $datatable .= 
  855:             &usertype_update_row($settings,{'default' => $othertitle},
  856:                                  \%fieldtitles,\@fields,['default'],
  857:                                  \$numrows);
  858:     }
  859:     return $datatable;
  860: }
  861: 
  862: sub usertype_update_row {
  863:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
  864:     my $datatable;
  865:     my $numinrow = 4;
  866:     foreach my $type (@{$types}) {
  867:         if (defined($usertypes->{$type})) {
  868:             $$rownums ++;
  869:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
  870:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
  871:                           '</td><td class="LC_left_item"><table>';
  872:             for (my $i=0; $i<@{$fields}; $i++) {
  873:                 my $rem = $i%($numinrow);
  874:                 if ($rem == 0) {
  875:                     if ($i > 0) {
  876:                         $datatable .= '</tr>';
  877:                     }
  878:                     $datatable .= '<tr>';
  879:                 }
  880:                 my $check = ' ';
  881:                 if (ref($settings->{'fields'}) eq 'HASH') {
  882:                     if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
  883:                         if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
  884:                             $check = ' checked="checked" ';
  885:                         }
  886:                     }
  887:                 }
  888: 
  889:                 if ($i == @{$fields}-1) {
  890:                     my $colsleft = $numinrow - $rem;
  891:                     if ($colsleft > 1) {
  892:                         $datatable .= '<td colspan="'.$colsleft.'">';
  893:                     } else {
  894:                         $datatable .= '<td>';
  895:                     }
  896:                 } else {
  897:                     $datatable .= '<td>';
  898:                 }
  899:                 $datatable .= '<span class="LC_nobreak"><label>'.
  900:                               '<input type="checkbox" name="updateable_'.$type.
  901:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
  902:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
  903:             }
  904:             $datatable .= '</tr></table></td></tr>';
  905:         }
  906:     }
  907:     return $datatable;
  908: }
  909: 
  910: sub modify_login {
  911:     my ($r,$dom,$confname,%domconfig) = @_;
  912:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
  913:     my %title = ( coursecatalog => 'Display course catalog',
  914:                   adminmail => 'Display administrator E-mail address');
  915:     my @offon = ('off','on');
  916:     my %loginhash;
  917:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
  918:                                            \%domconfig,\%loginhash);
  919:     $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
  920:     $loginhash{login}{adminmail} = $env{'form.adminmail'};
  921:     if (ref($colchanges{'login'}) eq 'HASH') {  
  922:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
  923:                                          \%loginhash);
  924:     }
  925:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
  926:                                              $dom);
  927:     if ($putresult eq 'ok') {
  928:         if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
  929:             ($env{'form.coursecatalog'} eq '1')) {
  930:             $changes{'coursecatalog'} = 1;
  931:         } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
  932:                  $domconfig{'login'}{'coursecatalog'} eq '1') &&
  933:                  ($env{'form.coursecatalog'} eq '0')) {
  934:             $changes{'coursecatalog'} = 1;
  935:         }
  936:         if (($domconfig{'login'}{'adminmail'} eq '1') &&
  937:                 ($env{'form.adminmail'} eq '0')) {
  938:             $changes{'adminmail'} = 1;
  939:         } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
  940:                  $domconfig{'login'}{'adminmail'} eq '0') &&
  941:                  ($env{'form.adminmail'} eq '1')) {
  942:             $changes{'adminmail'} = 1;
  943:         }
  944:         if (keys(%changes) > 0 || $colchgtext) {
  945:             $resulttext = &mt('Changes made:').'<ul>';
  946:             foreach my $item (sort(keys(%changes))) {
  947:                 $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
  948:             }
  949:             $resulttext .= $colchgtext.'</ul>';
  950:         } else {
  951:             $resulttext = &mt('No changes made to log-in page settings');
  952:         }
  953:     } else {
  954:         $resulttext = &mt('An error occurred: [_1]',$putresult);
  955:     }
  956:     if ($errors) {
  957:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
  958:                        $errors.'</ul>';
  959:     }
  960:     return $resulttext;
  961: }
  962: 
  963: sub color_font_choices {
  964:     my %choices =
  965:         &Apache::lonlocal::texthash (
  966:             img => "Header",
  967:             bgs => "Background colors",
  968:             links => "Link colors",
  969:             font => "Font color",
  970:             pgbg => "Page",
  971:             tabbg => "Header",
  972:             sidebg => "Border",
  973:             link => "Link",
  974:             alink => "Active link",
  975:             vlink => "Visited link",
  976:         );
  977:     return %choices;
  978: }
  979: 
  980: sub modify_rolecolors {
  981:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
  982:     my ($resulttext,%rolehash);
  983:     $rolehash{'rolecolors'} = {};
  984:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
  985:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
  986:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
  987:                                              $dom);
  988:     if ($putresult eq 'ok') {
  989:         if (keys(%changes) > 0) {
  990:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
  991:                                              $rolehash{'rolecolors'});
  992:         } else {
  993:             $resulttext = &mt('No changes made to default color schemes');
  994:         }
  995:     } else {
  996:         $resulttext = &mt('An error occurred: [_1]',$putresult);
  997:     }
  998:     if ($errors) {
  999:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 1000:                        $errors.'</ul>';
 1001:     }
 1002:     return $resulttext;
 1003: }
 1004: 
 1005: sub modify_colors {
 1006:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 1007:     my %changes;
 1008:     my @bgs = ('pgbg','mainbg','sidebg');
 1009:     my @links = ('link','alink','vlink');
 1010:     my @images;
 1011:     my $servadm = $r->dir_config('lonAdmEMail');
 1012:     my $errors;
 1013:     foreach my $role (@{$roles}) {
 1014:         if ($role eq 'login') {
 1015:             @images = ('img','logo','domlogo');
 1016:         } else {
 1017:             @images = ('img');
 1018:         }
 1019:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 1020:         foreach my $item (@bgs,@links) {
 1021:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 1022:         }
 1023:         my ($configuserok,$author_ok,$switchserver,%currroles);
 1024:         my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 1025:         ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 1026:                                                        $confname,$servadm);
 1027:         if ($configuserok eq 'ok') {
 1028:             $switchserver = &check_switchserver($dom,$confname);
 1029:             if ($switchserver eq '') {
 1030:                 $author_ok = &check_authorstatus($dom,$confname,%currroles);
 1031:             }
 1032:         }
 1033:         my ($width,$height) = &thumb_dimensions();
 1034:         foreach my $img (@images) {
 1035:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 1036:                 my $error;
 1037:                 if ($configuserok eq 'ok') {
 1038:                     if ($switchserver) {
 1039:                         $error = &mt("Upload of image [_1] for $role page(s) is not permitted to this server: [_2]",$img,$switchserver);
 1040:                     } else {
 1041:                         if ($author_ok eq 'ok') {
 1042:                             my ($result,$logourl) = 
 1043:                                 &publishlogo($r,'upload',$role.'_'.$img,
 1044:                                            $dom,$confname,$img,$width,$height);
 1045:                             if ($result eq 'ok') {
 1046:                                 $confhash->{$role}{$img} = $logourl;
 1047:                                 $changes{$role}{$img} = 1;
 1048:                             } else {
 1049:                                 $error = &mt("Upload of image [_1] for $role page(s) failed because an error occurred publshing the file in RES space. Error was: [_2].",$img,$result);
 1050:                             }
 1051:                         } else {
 1052:                             $error = &mt("Upload of image [_1] 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].",$img,$confname,$dom,$author_ok);
 1053:                         }
 1054:                     }
 1055:                 } else {
 1056:                     $error = &mt("Upload of image [_1] for $role page(s) failed because a Domain Configuation user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$img,$confname,$dom,$configuserok);
 1057:                 }
 1058:                 if ($error) {
 1059:                     &Apache::lonnet::logthis($error);
 1060:                     $errors .= '<li>'.$error.'</li>';
 1061:                 }
 1062:             } elsif ($domconfig->{$role}{$img} ne '') {
 1063:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 1064:                     my $error;
 1065:                     if ($configuserok eq 'ok') {
 1066: # is confname an author?
 1067:                         if ($switchserver eq '') {
 1068:                             if ($author_ok eq 'ok') {
 1069:                                 my ($result,$logourl) = 
 1070:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 1071:                                             $dom,$confname,$img,$width,$height);
 1072:                                 if ($result eq 'ok') {
 1073:                                     $confhash->{$role}{$img} = $logourl;
 1074:                                 }
 1075:                             }
 1076:                         }
 1077:                     }
 1078:                 }
 1079:             }
 1080:         }
 1081:         if (ref($domconfig) eq 'HASH') {
 1082:             if (ref($domconfig->{$role}) eq 'HASH') {
 1083:                 foreach my $img (@images) {
 1084:                     if ($domconfig->{$role}{$img} ne '') {
 1085:                         if ($env{'form.'.$role.'_del_'.$img}) {
 1086:                             $confhash->{$role}{$img} = '';
 1087:                             $changes{$role}{$img} = 1;
 1088:                         } else {
 1089:                             if ($confhash->{$role}{$img} eq '') {
 1090:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 1091:                             }
 1092:                         }
 1093:                     } else {
 1094:                         if ($env{'form.'.$role.'_del_'.$img}) {
 1095:                             $confhash->{$role}{$img} = '';
 1096:                             $changes{$role}{$img} = 1;
 1097:                         } 
 1098:                     }
 1099:                 }  
 1100:                 if ($domconfig->{$role}{'font'} ne '') {
 1101:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 1102:                         $changes{$role}{'font'} = 1;
 1103:                     }
 1104:                 } else {
 1105:                     if ($confhash->{$role}{'font'}) {
 1106:                         $changes{$role}{'font'} = 1;
 1107:                     }
 1108:                 }
 1109:                 foreach my $item (@bgs) {
 1110:                     if ($domconfig->{$role}{$item} ne '') {
 1111:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 1112:                             $changes{$role}{'bgs'}{$item} = 1;
 1113:                         } 
 1114:                     } else {
 1115:                         if ($confhash->{$role}{$item}) {
 1116:                             $changes{$role}{'bgs'}{$item} = 1;
 1117:                         }
 1118:                     }
 1119:                 }
 1120:                 foreach my $item (@links) {
 1121:                     if ($domconfig->{$role}{$item} ne '') {
 1122:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 1123:                             $changes{$role}{'links'}{$item} = 1;
 1124:                         }
 1125:                     } else {
 1126:                         if ($confhash->{$role}{$item}) {
 1127:                             $changes{$role}{'links'}{$item} = 1;
 1128:                         }
 1129:                     }
 1130:                 }
 1131:             } else {
 1132:                 &default_change_checker($role,\@images,\@links,\@bgs,
 1133:                                         $confhash,\%changes); 
 1134:             }
 1135:         } else {
 1136:             &default_change_checker($role,\@images,\@links,\@bgs,
 1137:                                     $confhash,\%changes); 
 1138:         }
 1139:     }
 1140:     return ($errors,%changes);
 1141: }
 1142: 
 1143: sub default_change_checker {
 1144:     my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
 1145:     foreach my $item (@{$links}) {
 1146:         if ($confhash->{$role}{$item}) {
 1147:             $changes->{$role}{'links'}{$item} = 1;
 1148:         }
 1149:     }
 1150:     foreach my $item (@{$bgs}) {
 1151:         if ($confhash->{$role}{$item}) {
 1152:             $changes->{$role}{'bgs'}{$item} = 1;
 1153:         }
 1154:     }
 1155:     foreach my $img (@{$images}) {
 1156:         if ($env{'form.'.$role.'_del_'.$img}) {
 1157:             $confhash->{$role}{$img} = '';
 1158:             $changes->{$role}{$img} = 1;
 1159:         }
 1160:     }
 1161:     if ($confhash->{$role}{'font'}) {
 1162:         $changes->{$role}{'font'} = 1;
 1163:     }
 1164: } 
 1165: 
 1166: sub display_colorchgs {
 1167:     my ($dom,$changes,$roles,$confhash) = @_;
 1168:     my (%choices,$resulttext);
 1169:     &Apache::loncommon::devalidate_domconfig_cache($dom);
 1170:     if (!grep(/^login$/,@{$roles})) {
 1171:         $resulttext = &mt('Changes made:').'<br />';
 1172:     }
 1173:     foreach my $role (@{$roles}) {
 1174:         if ($role eq 'login') {
 1175:             %choices = &login_choices();
 1176:         } else {
 1177:             %choices = &color_font_choices();
 1178:         }
 1179:         if (ref($changes->{$role}) eq 'HASH') {
 1180:             if ($role ne 'login') {
 1181:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 1182:             }
 1183:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 1184:                 if ($role ne 'login') {
 1185:                     $resulttext .= '<ul>';
 1186:                 }
 1187:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 1188:                     if ($role ne 'login') {
 1189:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 1190:                     }
 1191:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 1192:                         if ($confhash->{$role}{$item} eq '') {
 1193:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 1194:                         } else {
 1195:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$confhash->{$role}{$item}).'</li>';
 1196:                         }
 1197:                     }
 1198:                     if ($role ne 'login') {
 1199:                         $resulttext .= '</ul></li>';
 1200:                     }
 1201:                 } else {
 1202:                     if ($confhash->{$role}{$key} eq '') {
 1203:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 1204:                     } else {
 1205:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 1206:                     }
 1207:                 }
 1208:                 if ($role ne 'login') {
 1209:                     $resulttext .= '</ul>';
 1210:                 }
 1211:             }
 1212:         }
 1213:     }
 1214:     return $resulttext;
 1215: }
 1216: 
 1217: sub thumb_dimensions {
 1218:     return ('200','50');
 1219: }
 1220: 
 1221: sub check_configuser {
 1222:     my ($uhome,$dom,$confname,$servadm) = @_;
 1223:     my ($configuserok,%currroles);
 1224:     if ($uhome eq 'no_host') {
 1225:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 1226:         my $configpass = &LONCAPA::Enrollment::create_password();
 1227:         $configuserok = 
 1228:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 1229:                              $configpass,'','','','','',undef,$servadm);
 1230:     } else {
 1231:         $configuserok = 'ok';
 1232:         %currroles = 
 1233:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 1234:     }
 1235:     return ($configuserok,%currroles);
 1236: }
 1237: 
 1238: sub check_authorstatus {
 1239:     my ($dom,$confname,%currroles) = @_;
 1240:     my $author_ok;
 1241:     if (!$currroles{':'.$dom.':au'}) {
 1242:         my $start = time;
 1243:         my $end = 0;
 1244:         $author_ok = 
 1245:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 1246:                                         'au',$end,$start);
 1247:     } else {
 1248:         $author_ok = 'ok';
 1249:     }
 1250:     return $author_ok;
 1251: }
 1252: 
 1253: sub publishlogo {
 1254:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
 1255:     my ($output,$fname,$logourl);
 1256:     if ($action eq 'upload') {
 1257:         $fname=$env{'form.'.$formname.'.filename'};
 1258:         chop($env{'form.'.$formname});
 1259:     } else {
 1260:         ($fname) = ($formname =~ /([^\/]+)$/);
 1261:     }
 1262:     $fname=&Apache::lonnet::clean_filename($fname);
 1263: # See if there is anything left
 1264:     unless ($fname) { return ('error: no uploaded file'); }
 1265:     $fname="$subdir/$fname";
 1266:     my $filepath='/home/'.$confname.'/public_html';
 1267:     my ($fnamepath,$file,$fetchthumb);
 1268:     $file=$fname;
 1269:     if ($fname=~m|/|) {
 1270:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 1271:     }
 1272:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
 1273:     my $count;
 1274:     for ($count=4;$count<=$#parts;$count++) {
 1275:         $filepath.="/$parts[$count]";
 1276:         if ((-e $filepath)!=1) {
 1277:             mkdir($filepath,02770);
 1278:         }
 1279:     }
 1280:     # Check for bad extension and disallow upload
 1281:     if ($file=~/\.(\w+)$/ &&
 1282:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 1283:         $output = 
 1284:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
 1285:     } elsif ($file=~/\.(\w+)$/ &&
 1286:         !defined(&Apache::loncommon::fileembstyle($1))) {
 1287:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 1288:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 1289:         $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 1290:     } elsif (-d "$filepath/$file") {
 1291:         $output = &mt('File name is a directory name - rename the file and re-upload');
 1292:     } else {
 1293:         my $source = $filepath.'/'.$file;
 1294:         my $logfile;
 1295:         if (!open($logfile,">>$source".'.log')) {
 1296:             return (&mt('No write permission to Construction Space'));
 1297:         }
 1298:         print $logfile
 1299: "\n================= Publish ".localtime()." ================\n".
 1300: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 1301: # Save the file
 1302:         if (!open(FH,'>'.$source)) {
 1303:             &Apache::lonnet::logthis('Failed to create '.$source);
 1304:             return (&mt('Failed to create file'));
 1305:         }
 1306:         if ($action eq 'upload') {
 1307:             if (!print FH ($env{'form.'.$formname})) {
 1308:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 1309:                 return (&mt('Failed to write file'));
 1310:             }
 1311:         } else {
 1312:             my $original = &Apache::lonnet::filelocation('',$formname);
 1313:             if(!copy($original,$source)) {
 1314:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 1315:                 return (&mt('Failed to write file'));
 1316:             }
 1317:         }
 1318:         close(FH);
 1319:         chmod(0660, $source); # Permissions to rw-rw---.
 1320: 
 1321:         my $docroot=$r->dir_config('lonDocRoot');
 1322:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 1323:         my $copyfile=$targetdir.'/'.$file;
 1324: 
 1325:         my @parts=split(/\//,$targetdir);
 1326:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 1327:         for (my $count=5;$count<=$#parts;$count++) {
 1328:             $path.="/$parts[$count]";
 1329:             if (!-e $path) {
 1330:                 print $logfile "\nCreating directory ".$path;
 1331:                 mkdir($path,02770);
 1332:             }
 1333:         }
 1334:         my $versionresult;
 1335:         if (-e $copyfile) {
 1336:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 1337:         } else {
 1338:             $versionresult = 'ok';
 1339:         }
 1340:         if ($versionresult eq 'ok') {
 1341:             if (copy($source,$copyfile)) {
 1342:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 1343:                 $output = 'ok';
 1344:                 &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 1345:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 1346:             } else {
 1347:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 1348:                 $output = &mt('Failed to copy file to RES space').", $!";
 1349:             }
 1350:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 1351:                 my $inputfile = $filepath.'/'.$file;
 1352:                 my $outfile = $filepath.'/'.'tn-'.$file;
 1353:                 my $thumbsize = $thumbwidth.'x'.$thumbheight;
 1354:                 system("convert -sample $thumbsize $inputfile $outfile");
 1355:                 chmod(0660, $filepath.'/tn-'.$file);
 1356:                 if (-e $outfile) {
 1357:                     my $copyfile=$targetdir.'/tn-'.$file;
 1358:                     if (copy($outfile,$copyfile)) {
 1359:                         print $logfile "\nCopied source to ".$copyfile."\n";
 1360:                         &write_metadata($dom,$confname,$formname,$targetdir,
 1361:                                         'tn-'.$file,$logfile);
 1362:                     } else {
 1363:                         print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 1364:                     }
 1365:                 }
 1366:             }
 1367:         } else {
 1368:             $output = $versionresult;
 1369:         }
 1370:     }
 1371:     return ($output,$logourl);
 1372: }
 1373: 
 1374: sub logo_versioning {
 1375:     my ($targetdir,$file,$logfile) = @_;
 1376:     my $target = $targetdir.'/'.$file;
 1377:     my ($maxversion,$fn,$extn,$output);
 1378:     $maxversion = 0;
 1379:     if ($file =~ /^(.+)\.(\w+)$/) {
 1380:         $fn=$1;
 1381:         $extn=$2;
 1382:     }
 1383:     opendir(DIR,$targetdir);
 1384:     while (my $filename=readdir(DIR)) {
 1385:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 1386:             $maxversion=($1>$maxversion)?$1:$maxversion;
 1387:         }
 1388:     }
 1389:     $maxversion++;
 1390:     print $logfile "\nCreating old version ".$maxversion."\n";
 1391:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 1392:     if (copy($target,$copyfile)) {
 1393:         print $logfile "Copied old target to ".$copyfile."\n";
 1394:         $copyfile=$copyfile.'.meta';
 1395:         if (copy($target.'.meta',$copyfile)) {
 1396:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 1397:             $output = 'ok';
 1398:         } else {
 1399:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 1400:             $output = &mt('Failed to copy old meta').", $!, ";
 1401:         }
 1402:     } else {
 1403:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 1404:         $output = &mt('Failed to copy old target').", $!, ";
 1405:     }
 1406:     return $output;
 1407: }
 1408: 
 1409: sub write_metadata {
 1410:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 1411:     my (%metadatafields,%metadatakeys,$output);
 1412:     $metadatafields{'title'}=$formname;
 1413:     $metadatafields{'creationdate'}=time;
 1414:     $metadatafields{'lastrevisiondate'}=time;
 1415:     $metadatafields{'copyright'}='public';
 1416:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 1417:                                          $env{'user.domain'};
 1418:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 1419:     $metadatafields{'domain'}=$dom;
 1420:     {
 1421:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 1422:         my $mfh;
 1423:         unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 1424:             $output = &mt('Could not write metadata');
 1425:         }
 1426:         foreach (sort keys %metadatafields) {
 1427:             unless ($_=~/\./) {
 1428:                 my $unikey=$_;
 1429:                 $unikey=~/^([A-Za-z]+)/;
 1430:                 my $tag=$1;
 1431:                 $tag=~tr/A-Z/a-z/;
 1432:                 print $mfh "\n\<$tag";
 1433:                 foreach (split(/\,/,$metadatakeys{$unikey})) {
 1434:                     my $value=$metadatafields{$unikey.'.'.$_};
 1435:                     $value=~s/\"/\'\'/g;
 1436:                     print $mfh ' '.$_.'="'.$value.'"';
 1437:                 }
 1438:                 print $mfh '>'.
 1439:                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 1440:                         .'</'.$tag.'>';
 1441:             }
 1442:         }
 1443:         $output = 'ok';
 1444:         print $logfile "\nWrote metadata";
 1445:         close($mfh);
 1446:     }
 1447: }
 1448: 
 1449: sub check_switchserver {
 1450:     my ($dom,$confname) = @_;
 1451:     my ($allowed,$switchserver);
 1452:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 1453:     if ($home eq 'no_host') {
 1454:         $home = &Apache::lonnet::domain($dom,'primary');
 1455:     }
 1456:     my @ids=&Apache::lonnet::current_machine_ids();
 1457:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1458:     if (!$allowed) {
 1459: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
 1460:     }
 1461:     return $switchserver;
 1462: }
 1463: 
 1464: sub modify_quotas {
 1465:     my ($dom,%domconfig) = @_;
 1466:     my ($resulttext,%changes);
 1467:     my ($usertypes,$order) = 
 1468:         &Apache::lonnet::retrieve_inst_usertypes($dom);
 1469:     my %formhash;
 1470:     foreach my $key (keys(%env)) {
 1471:         if ($key =~ /^form\.quota_(.+)$/) {
 1472:             $formhash{$1} = $env{$key};
 1473:         }
 1474:     }
 1475:     if (ref($domconfig{'quotas'}) eq 'HASH') {
 1476:         foreach my $key (keys(%{$domconfig{'quotas'}})) {
 1477:             if (exists($formhash{$key})) {
 1478:                 if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
 1479:                     $changes{$key} = 1;
 1480:                 }
 1481:             } else {
 1482:                 $formhash{$key} = $domconfig{'quotas'}{$key};
 1483:             }
 1484:         }
 1485:     }
 1486:     foreach my $key (keys(%formhash)) {
 1487:         if ($formhash{$key} ne '') {
 1488:             if (!exists($domconfig{'quotas'}{$key})) {
 1489:                 $changes{$key} = 1;
 1490:             }
 1491:         }
 1492:     }
 1493:     my %quotahash = (
 1494:                       quotas => {%formhash},
 1495:                     );
 1496:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 1497:                                              $dom);
 1498:     if ($putresult eq 'ok') {
 1499:         if (keys(%changes) > 0) {
 1500:             $resulttext = &mt('Changes made:').'<ul>';
 1501:             foreach my $item (sort(keys(%changes))) {
 1502:                 $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'</li>';
 1503:             }
 1504:             $resulttext .= '</ul>';
 1505:         } else {
 1506:             $resulttext = &mt('No changes made to default quotas');
 1507:         }
 1508:     } else {
 1509:         $resulttext = &mt('An error occurred: [_1]',$putresult);
 1510:     }
 1511:     return $resulttext;
 1512: }
 1513: 
 1514: sub modify_autoenroll {
 1515:     my ($dom,%domconfig) = @_;
 1516:     my ($resulttext,%changes);
 1517:     my %currautoenroll;
 1518:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 1519:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 1520:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 1521:         }
 1522:     }
 1523:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 1524:     my %title = ( run => 'Auto-enrollment active',
 1525:                   sender => 'Sender for notification messages');
 1526:     my @offon = ('off','on');
 1527:     my %autoenrollhash =  (
 1528:                        autoenroll => { run => $env{'form.autoenroll_run'},
 1529:                                        sender_uname => $env{'form.sender_uname'},
 1530:                                        sender_domain => $env{'form.sender_domain'},
 1531: 
 1532:                                 }
 1533:                      );
 1534:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 1535:                                              $dom);
 1536:     if ($putresult eq 'ok') {
 1537:         if (exists($currautoenroll{'run'})) {
 1538:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 1539:                  $changes{'run'} = 1;
 1540:              }
 1541:         } elsif ($autorun) {
 1542:             if ($env{'form.autoenroll_run'} ne '1') {
 1543:                 $changes{'run'} = 1;
 1544:             }
 1545:         }
 1546:         if (exists($currautoenroll{sender_uname})) {
 1547:             if ($currautoenroll{'sender_uname'} ne $env{'form.sender_uname'}) {
 1548:                 $changes{'sender'} = 1;
 1549:             }
 1550:         } else {
 1551:             $changes{'sender'} = 1;
 1552:         }
 1553:         if (exists($currautoenroll{sender_domain})) {
 1554:             if ($currautoenroll{'sender_domain'} ne $env{'form.sender_domain'}) {
 1555:                 $changes{'sender'} = 1;
 1556:             }
 1557:         } else {
 1558:             $changes{'sender'} = 1;
 1559:         }
 1560:         if (keys(%changes) > 0) {
 1561:             $resulttext = &mt('Changes made:').'<ul>';
 1562:             if ($changes{'run'}) {
 1563:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 1564:             }
 1565:             if ($changes{'sender'}) {
 1566:                 $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$env{'form.sender_uname'}.':'.$env{'form.sender_domain'}).'</li>';
 1567:             }
 1568:             $resulttext .= '</ul>';
 1569:         } else {
 1570:             $resulttext = &mt('No changes made to auto-enrollment settings');
 1571:         }
 1572:     } else {
 1573:         $resulttext = &mt('An error occurred: [_1]',$putresult);
 1574:     }
 1575:     return $resulttext;
 1576: }
 1577: 
 1578: sub modify_autoupdate {
 1579:     my ($dom,%domconfig) = @_;
 1580:     my ($resulttext,%currautoupdate,%fields,%changes);
 1581:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 1582:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 1583:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 1584:         }
 1585:     }
 1586:     my @offon = ('off','on');
 1587:     my %title = &Apache::lonlocal::texthash (
 1588:                    run => 'Auto-update:',
 1589:                    classlists => 'Updates to user information in classlists?'
 1590:                 );
 1591:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
 1592:     my %fieldtitles = &Apache::lonlocal::texthash (
 1593:                         id => 'Student/Employee ID',
 1594:                         email => 'E-mail address',
 1595:                         lastname => 'Last Name',
 1596:                         firstname => 'First Name',
 1597:                         middlename => 'Middle Name',
 1598:                         gen => 'Generation',
 1599:                       );
 1600:     my $othertitle = &mt('All users');
 1601:     if (keys(%{$usertypes}) >  0) {
 1602:         $othertitle = "Other users";
 1603:     }
 1604:     foreach my $key (keys(%env)) {
 1605:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 1606:             push(@{$fields{$1}},$2);
 1607:         }
 1608:     }
 1609:     my %updatehash = (
 1610:                       autoupdate => { run => $env{'form.autoupdate_run'},
 1611:                                       classlists => $env{'form.classlists'},
 1612:                                       fields => {%fields},
 1613:                                     }
 1614:                      );
 1615:     foreach my $key (keys(%currautoupdate)) {
 1616:         if (($key eq 'run') || ($key eq 'classlists')) {
 1617:             if (exists($updatehash{autoupdate}{$key})) {
 1618:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 1619:                     $changes{$key} = 1;
 1620:                 }
 1621:             }
 1622:         } elsif ($key eq 'fields') {
 1623:             if (ref($currautoupdate{$key}) eq 'HASH') {
 1624:                 foreach my $item (keys(%{$currautoupdate{$key}})) {
 1625:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 1626:                         my $change = 0;
 1627:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 1628:                             if (!exists($fields{$item})) {
 1629:                                 $change = 1;
 1630:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 1631:                                 if (!grep/^\Q$type\E$/,@{$fields{$item}}) {
 1632:                                     $change = 1;
 1633:                                 }
 1634:                             }
 1635:                         }
 1636:                         if ($change) {
 1637:                             push(@{$changes{$key}},$item);
 1638:                         }
 1639:                     }
 1640:                 }
 1641:             }
 1642:         }
 1643:     }
 1644:     foreach my $key (keys(%fields)) {
 1645:         if (ref($currautoupdate{'fields'}) eq 'HASH') {
 1646:             if (!exists($currautoupdate{'fields'}{$key})) {
 1647:                 push(@{$changes{'fields'}},$key);
 1648:             }
 1649:         } else {
 1650:             push(@{$changes{'fields'}},$key);
 1651:         }
 1652:     }
 1653:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 1654:                                              $dom);
 1655:     if ($putresult eq 'ok') {
 1656:         if (keys(%changes) > 0) {
 1657:             $resulttext = &mt('Changes made:').'<ul>';
 1658:             foreach my $key (sort(keys(%changes))) {
 1659:                 if (ref($changes{$key}) eq 'ARRAY') {
 1660:                     foreach my $item (@{$changes{$key}}) {
 1661:                         my @newvalues;
 1662:                         foreach my $type (@{$fields{$item}}) {
 1663:                             push(@newvalues,$fieldtitles{$type});
 1664:                         }
 1665:                         my $newvaluestr;
 1666:                         if (@newvalues > 0) {
 1667:                             $newvaluestr = join(', ',@newvalues);
 1668:                         } else {
 1669:                             $newvaluestr = &mt('none');
 1670:                         }
 1671:                         if ($item eq 'default') {
 1672:                             $resulttext .= '<li>'.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'</li>';
 1673:                         } else {
 1674:                             $resulttext .= '<li>'.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'</li>';
 1675:                         }
 1676:                     }
 1677:                 } else {
 1678:                     my $newvalue;
 1679:                     if ($key eq 'run') {
 1680:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 1681:                     } else {
 1682:                         $newvalue = $offon[$env{'form.'.$key}];
 1683:                     }
 1684:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 1685:                 }
 1686:             }
 1687:             $resulttext .= '</ul>';
 1688:         } else {
 1689:             $resulttext = &mt('No changes made to autoupdates');
 1690:         }
 1691:     } else {
 1692:         $resulttext = &mt('An error occurred: [_1]',$putresult);
 1693:     }
 1694:     return $resulttext;
 1695: }
 1696: 
 1697: 1;
 1698: 

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