File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.20: download - view: text, annotated - select for diffs
Mon Jun 4 14:14:27 2007 UTC (16 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
permanentemail replaces email to conform with usage in user's environment.db

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.20 2007/06/04 14:14:27 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 = "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','Save 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, $img_import);
  530:         if ($designs->{$img} ne '') {
  531:             $imgfile = $designs->{$img};
  532: 	    $img_import = ($imgfile =~ m{^/adm/});
  533:         } else {
  534:             $imgfile = $defaults->{$img};
  535:         }
  536:         if ($imgfile) {
  537:             my ($showfile,$fullsize);
  538:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
  539:                 my $urldir = $1;
  540:                 my $filename = $2;
  541:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
  542:                 if (@info) {
  543:                     my $thumbfile = 'tn-'.$filename;
  544:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
  545:                     if (@thumb) {
  546:                         $showfile = $urldir.'/'.$thumbfile;
  547:                     } else {
  548:                         $showfile = $imgfile;
  549:                     }
  550:                 } else {
  551:                     $showfile = '';
  552:                 }
  553:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
  554:                 $showfile = $imgfile;
  555:                 my $imgdir = $1;
  556:                 my $filename = $2;
  557:                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
  558:                     $showfile = "/$imgdir/tn-".$filename;
  559:                 } else {
  560:                     my $input = "/home/httpd/html".$imgfile;
  561:                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
  562:                     if (!-e $output) {
  563:                         my ($width,$height) = &thumb_dimensions();
  564:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
  565:                         if ($fullwidth ne '' && $fullheight ne '') {
  566:                             if ($fullwidth > $width && $fullheight > $height) { 
  567:                                 my $size = $width.'x'.$height;
  568:                                 system("convert -sample $size $input $output");
  569:                                 $showfile = '/'.$imgdir.'/tn-'.$filename;
  570:                             }
  571:                         }
  572:                     }
  573:                 }
  574:             }
  575:             if ($showfile) {
  576:                 $showfile = &Apache::loncommon::lonhttpdurl($showfile);
  577:                 $fullsize =  &Apache::loncommon::lonhttpdurl($imgfile);
  578:                 $datatable.= '<td>';
  579:                 if (!$is_custom->{$img}) {
  580:                     $datatable .= &mt('Default in use:').'<br />';
  581:                 }
  582: 		if ($img_import) {
  583: 		    $datatable.= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
  584: 		}
  585:                 $datatable.= '<a href="'.$fullsize.'" target="_blank"><img src="'.
  586:                              $showfile.'" alt="'.$alt_text->{$img}.
  587:                              '" border="0" /></a></td>';
  588:                 if ($is_custom->{$img}) {
  589:                     $datatable.='<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
  590:                                 $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
  591:                                 '</label>&nbsp;'.&mt('Replace:').'</span><br />';
  592:                 } else {
  593:                     $datatable.='<td valign="bottom">'.&mt('Upload:').'<br />';
  594:                 }
  595:             } else {
  596:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
  597:                               &mt('Upload:');
  598:             }
  599:         } else {
  600:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
  601:                           &mt('Upload:');
  602:         }
  603:         if ($switchserver) {
  604:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
  605:         } else {
  606:             $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
  607:         }
  608:         $datatable .= '</td></tr>';
  609:     }
  610:     $itemcount ++;
  611:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  612:     $datatable .= '<tr'.$css_class.'>'.
  613:                   '<td>'.$choices->{'bgs'}.'</td>';
  614:     my $bgs_def;
  615:     foreach my $item (@{$bgs}) {
  616:         if (!$is_custom->{$item}) {
  617:             $bgs_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'bgs'}{$item}.'</td>';
  618:         }
  619:     }
  620:     if ($bgs_def) {
  621:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
  622:     } else {
  623:         $datatable .= '<td>&nbsp;</td>';
  624:     }
  625:     $datatable .= '<td class="LC_right_item">'.
  626:                   '<table border="0"><tr>';
  627:     foreach my $item (@{$bgs}) {
  628:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
  629:         $datatable .= '<td align="center">'.$link;
  630:         if ($designs->{'bgs'}{$item}) {
  631:             $datatable .= '<span style="background-color:'.$designs->{'bgs'}{$item}.'width: 10px">&nbsp;</span>';
  632:         }
  633:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
  634:                       '" /></td>';
  635:     }
  636:     $datatable .= '</tr></table></td></tr>';
  637:     $itemcount ++;
  638:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  639:     $datatable .= '<tr'.$css_class.'>'.
  640:                   '<td>'.$choices->{'links'}.'</td>';
  641:     my $links_def;
  642:     foreach my $item (@{$links}) {
  643:         if (!$is_custom->{$item}) {
  644:             $links_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'links'}{$item}.'</td>';
  645:         }
  646:     }
  647:     if ($links_def) {
  648:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
  649:     } else {
  650:         $datatable .= '<td>&nbsp;</td>';
  651:     }
  652:     $datatable .= '<td class="LC_right_item">'.
  653:                   '<table border="0"><tr>';
  654:     foreach my $item (@{$links}) {
  655:         $datatable .= '<td align="center">';
  656:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'links'}{$item});
  657:         if ($designs->{'links'}{$item}) {
  658:             $datatable.='<span style="color: '.$designs->{'links'}{$item}.';">'.
  659:                         $link.'</span>';
  660:         } else {
  661:             $datatable .= $link;
  662:         }
  663:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
  664:                       '" /></td>';
  665:     }
  666:     return $datatable;
  667: }
  668: 
  669: sub color_pick {
  670:     my ($phase,$role,$item,$desc,$curcol) = @_;
  671:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
  672:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
  673:                ');">'.$desc.'</a>';
  674:     return $link;
  675: }
  676: 
  677: sub color_pick_js {
  678:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  679:     my $output = <<"ENDCOL";
  680:     function pclose() {
  681:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
  682:         parmwin.close();
  683:     }
  684: 
  685:     $pjump_def
  686: 
  687:     function psub() {
  688:         pclose();
  689:         if (document.parmform.pres_marker.value!='') {
  690:             if (document.parmform.pres_type.value!='') {
  691:                 eval('document.display.'+
  692:                      document.parmform.pres_marker.value+
  693:                      '.value=document.parmform.pres_value.value;');
  694:             }
  695:         } else {
  696:             document.parmform.pres_value.value='';
  697:             document.parmform.pres_marker.value='';
  698:         }
  699:     }
  700: ENDCOL
  701:     return $output;
  702: }
  703: 
  704: sub print_quotas {
  705:     my ($dom,$settings) = @_;
  706:     my $datatable;
  707:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
  708:     my $othertitle = "All users";
  709:     my @types;
  710:     if (ref($order) eq 'ARRAY') {
  711:         @types = @{$order};
  712:     }
  713:     if (@types == 0) {
  714:         if (ref($usertypes) eq 'HASH') {
  715:             @types = sort(keys(%{$usertypes}));
  716:         }
  717:     }
  718:     my $typecount = 0;
  719:     my $css_class;
  720:     if (@types > 0) {
  721:         foreach my $type (@types) {
  722:             if (defined($usertypes->{$type})) {
  723:                 $typecount ++;
  724:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
  725:                 $datatable .= '<tr'.$css_class.'>'. 
  726:                               '<td>'.$usertypes->{$type}.'</td>'.
  727:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
  728:                               '<input type="text" name="quota_'.$type.
  729:                               '" value="'.$settings->{$type}.
  730:                               '" size="5" /> Mb</span></td></tr>';
  731:             }
  732:         }
  733:         $othertitle = "Other users";
  734:     }
  735:     my $defaultquota = '20';
  736:     if (ref($settings) eq 'HASH') {
  737:         if (defined($settings->{'default'})) {
  738:             $defaultquota = $settings->{'default'};
  739:         }
  740:     }
  741:     $typecount ++;
  742:     $css_class = $typecount%2?' class="LC_odd_row"':'';
  743:     $datatable .= '<tr'.$css_class.'>'.
  744:                   '<td>'.&mt($othertitle).'</td>'.
  745:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
  746:                   '<input type="text" name="defaultquota" value="'.
  747:                   $defaultquota.'" size="5" /> Mb</span></td></tr>';
  748:     return $datatable;
  749: }
  750: 
  751: sub print_autoenroll {
  752:     my ($dom,$settings) = @_;
  753:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
  754:     my ($defdom,$runon,$runoff);
  755:     if (ref($settings) eq 'HASH') {
  756:         if (exists($settings->{'run'})) {
  757:             if ($settings->{'run'} eq '0') {
  758:                 $runoff = ' checked="checked" ';
  759:                 $runon = ' ';
  760:             } else {
  761:                 $runon = ' checked="checked" ';
  762:                 $runoff = ' ';
  763:             }
  764:         } else {
  765:             if ($autorun) {
  766:                 $runon = ' checked="checked" ';
  767:                 $runoff = ' ';
  768:             } else {
  769:                 $runoff = ' checked="checked" ';
  770:                 $runon = ' ';
  771:             }
  772:         }
  773:         if (exists($settings->{'sender_domain'})) {
  774:             $defdom = $settings->{'sender_domain'};
  775:         }
  776:     } else {
  777:         if ($autorun) {
  778:             $runon = ' checked="checked" ';
  779:             $runoff = ' ';
  780:         } else {
  781:             $runoff = ' checked="checked" ';
  782:             $runon = ' ';
  783:         }
  784:     }
  785:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
  786:     my $datatable='<tr class="LC_odd_row">'.
  787:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
  788:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
  789:                   '<input type="radio" name="autoenroll_run"'.
  790:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  791:                   '<label><input type="radio" name="autoenroll_run"'.
  792:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
  793:                   '</tr><tr>'.
  794:                   '<td>'.&mt('Notification messages - sender').
  795:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
  796:                   &mt('username').':&nbsp;'.
  797:                   '<input type="text" name="sender_uname" value="'.
  798:                   $settings->{'sender_uname'}.
  799:                   '" size="10" />&nbsp;&nbsp;'.&mt('domain').
  800:                   ':&nbsp;'.$domform.'</span></td></tr>';
  801:     return $datatable;
  802: }
  803: 
  804: sub print_autoupdate {
  805:     my ($position,$dom,$settings) = @_;
  806:     my $datatable;
  807:     if ($position eq 'top') {
  808:         my $updateon = ' ';
  809:         my $updateoff = ' checked="checked" ';
  810:         my $classlistson = ' ';
  811:         my $classlistsoff = ' checked="checked" ';
  812:         if (ref($settings) eq 'HASH') {
  813:             if ($settings->{'run'} eq '1') {
  814:                 $updateon = $updateoff;
  815:                 $updateoff = ' ';
  816:             }
  817:             if ($settings->{'classlists'} eq '1') {
  818:                 $classlistson = $classlistsoff;
  819:                 $classlistsoff = ' ';
  820:             }
  821:         }
  822:         my %title = (
  823:                    run => 'Auto-update active?',
  824:                    classlists => 'Update information in classlists?',
  825:                     );
  826:         $datatable = '<tr class="LC_odd_row">'. 
  827:                   '<td>'.&mt($title{'run'}).'</td>'.
  828:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
  829:                   '<input type="radio" name="autoupdate_run"'.
  830:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  831:                   '<label><input type="radio" name="autoupdate_run"'.
  832:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
  833:                   '</tr><tr>'.
  834:                   '<td>'.&mt($title{'classlists'}).'</td>'.
  835:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
  836:                   '<label><input type="radio" name="classlists"'.
  837:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  838:                   '<label><input type="radio" name="classlists"'.
  839:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
  840:                   '</tr>';
  841:     } else {
  842:         my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
  843:         my @types;
  844:         if (ref($order) eq 'ARRAY') {
  845:             @types = @{$order};
  846:         }
  847:         if (@types == 0) {
  848:             if (ref($usertypes) eq 'HASH') {
  849:                 @types = sort(keys(%{$usertypes}));
  850:             }
  851:         }
  852:         my $othertitle = &mt('All users');
  853:         if (keys(%{$usertypes}) > 0) {
  854:             $othertitle = &mt('Other users');
  855:         }
  856:         my @fields = ('lastname','firstname','middlename','gen',
  857:                       'permanentemail','id');
  858:         my %fieldtitles = &Apache::lonlocal::texthash (
  859:                             id => 'Student/Employee ID',
  860:                             permanentemail => 'E-mail address',
  861:                             lastname => 'Last Name',
  862:                             firstname => 'First Name',
  863:                             middlename => 'Middle Name',
  864:                             gen => 'Generation',
  865:                       );
  866:         my $numrows = 0;
  867:         if (@types > 0) {
  868:             $datatable = 
  869:                 &usertype_update_row($settings,$usertypes,\%fieldtitles,
  870:                                      \@fields,\@types,\$numrows);
  871:         }
  872:         $datatable .= 
  873:             &usertype_update_row($settings,{'default' => $othertitle},
  874:                                  \%fieldtitles,\@fields,['default'],
  875:                                  \$numrows);
  876:     }
  877:     return $datatable;
  878: }
  879: 
  880: sub usertype_update_row {
  881:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
  882:     my $datatable;
  883:     my $numinrow = 4;
  884:     foreach my $type (@{$types}) {
  885:         if (defined($usertypes->{$type})) {
  886:             $$rownums ++;
  887:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
  888:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
  889:                           '</td><td class="LC_left_item"><table>';
  890:             for (my $i=0; $i<@{$fields}; $i++) {
  891:                 my $rem = $i%($numinrow);
  892:                 if ($rem == 0) {
  893:                     if ($i > 0) {
  894:                         $datatable .= '</tr>';
  895:                     }
  896:                     $datatable .= '<tr>';
  897:                 }
  898:                 my $check = ' ';
  899:                 if (ref($settings->{'fields'}) eq 'HASH') {
  900:                     if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
  901:                         if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
  902:                             $check = ' checked="checked" ';
  903:                         }
  904:                     }
  905:                 }
  906: 
  907:                 if ($i == @{$fields}-1) {
  908:                     my $colsleft = $numinrow - $rem;
  909:                     if ($colsleft > 1) {
  910:                         $datatable .= '<td colspan="'.$colsleft.'">';
  911:                     } else {
  912:                         $datatable .= '<td>';
  913:                     }
  914:                 } else {
  915:                     $datatable .= '<td>';
  916:                 }
  917:                 $datatable .= '<span class="LC_nobreak"><label>'.
  918:                               '<input type="checkbox" name="updateable_'.$type.
  919:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
  920:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
  921:             }
  922:             $datatable .= '</tr></table></td></tr>';
  923:         }
  924:     }
  925:     return $datatable;
  926: }
  927: 
  928: sub modify_login {
  929:     my ($r,$dom,$confname,%domconfig) = @_;
  930:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
  931:     my %title = ( coursecatalog => 'Display course catalog',
  932:                   adminmail => 'Display administrator E-mail address');
  933:     my @offon = ('off','on');
  934:     my %loginhash;
  935:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
  936:                                            \%domconfig,\%loginhash);
  937:     $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
  938:     $loginhash{login}{adminmail} = $env{'form.adminmail'};
  939:     if (ref($colchanges{'login'}) eq 'HASH') {  
  940:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
  941:                                          \%loginhash);
  942:     }
  943:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
  944:                                              $dom);
  945:     if ($putresult eq 'ok') {
  946:         if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
  947:             ($env{'form.coursecatalog'} eq '1')) {
  948:             $changes{'coursecatalog'} = 1;
  949:         } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
  950:                  $domconfig{'login'}{'coursecatalog'} eq '1') &&
  951:                  ($env{'form.coursecatalog'} eq '0')) {
  952:             $changes{'coursecatalog'} = 1;
  953:         }
  954:         if (($domconfig{'login'}{'adminmail'} eq '1') &&
  955:                 ($env{'form.adminmail'} eq '0')) {
  956:             $changes{'adminmail'} = 1;
  957:         } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
  958:                  $domconfig{'login'}{'adminmail'} eq '0') &&
  959:                  ($env{'form.adminmail'} eq '1')) {
  960:             $changes{'adminmail'} = 1;
  961:         }
  962:         if (keys(%changes) > 0 || $colchgtext) {
  963:             $resulttext = &mt('Changes made:').'<ul>';
  964:             foreach my $item (sort(keys(%changes))) {
  965:                 $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
  966:             }
  967:             $resulttext .= $colchgtext.'</ul>';
  968:         } else {
  969:             $resulttext = &mt('No changes made to log-in page settings');
  970:         }
  971:     } else {
  972:         $resulttext = '<span class="LC_error">'.
  973: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
  974:     }
  975:     if ($errors) {
  976:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
  977:                        $errors.'</ul>';
  978:     }
  979:     return $resulttext;
  980: }
  981: 
  982: sub color_font_choices {
  983:     my %choices =
  984:         &Apache::lonlocal::texthash (
  985:             img => "Header",
  986:             bgs => "Background colors",
  987:             links => "Link colors",
  988:             font => "Font color",
  989:             pgbg => "Page",
  990:             tabbg => "Header",
  991:             sidebg => "Border",
  992:             link => "Link",
  993:             alink => "Active link",
  994:             vlink => "Visited link",
  995:         );
  996:     return %choices;
  997: }
  998: 
  999: sub modify_rolecolors {
 1000:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
 1001:     my ($resulttext,%rolehash);
 1002:     $rolehash{'rolecolors'} = {};
 1003:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 1004:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 1005:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 1006:                                              $dom);
 1007:     if ($putresult eq 'ok') {
 1008:         if (keys(%changes) > 0) {
 1009:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 1010:                                              $rolehash{'rolecolors'});
 1011:         } else {
 1012:             $resulttext = &mt('No changes made to default color schemes');
 1013:         }
 1014:     } else {
 1015:         $resulttext = '<span class="LC_error">'.
 1016: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 1017:     }
 1018:     if ($errors) {
 1019:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 1020:                        $errors.'</ul>';
 1021:     }
 1022:     return $resulttext;
 1023: }
 1024: 
 1025: sub modify_colors {
 1026:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 1027:     my (%changes,%choices);
 1028:     my @bgs = ('pgbg','mainbg','sidebg');
 1029:     my @links = ('link','alink','vlink');
 1030:     my @images;
 1031:     my $servadm = $r->dir_config('lonAdmEMail');
 1032:     my $errors;
 1033:     foreach my $role (@{$roles}) {
 1034:         if ($role eq 'login') {
 1035:             %choices = &login_choices();
 1036:         } else {
 1037:             %choices = &color_font_choices();
 1038:         }
 1039:         if ($role eq 'login') {
 1040:             @images = ('img','logo','domlogo');
 1041:         } else {
 1042:             @images = ('img');
 1043:         }
 1044:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 1045:         foreach my $item (@bgs,@links) {
 1046:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 1047:         }
 1048:         my ($configuserok,$author_ok,$switchserver,%currroles);
 1049:         my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 1050:         ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 1051:                                                        $confname,$servadm);
 1052:         if ($configuserok eq 'ok') {
 1053:             $switchserver = &check_switchserver($dom,$confname);
 1054:             if ($switchserver eq '') {
 1055:                 $author_ok = &check_authorstatus($dom,$confname,%currroles);
 1056:             }
 1057:         }
 1058:         my ($width,$height) = &thumb_dimensions();
 1059:         foreach my $img (@images) {
 1060: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 1061: 		 && !defined($domconfig->{$role}{$img})
 1062: 		 && !$env{'form.'.$role.'_del_'.$img}
 1063: 		 && $env{'form.'.$role.'_import_'.$img}) {
 1064: 		# import the old configured image from the .tab setting
 1065: 		# if they haven't provided a new one 
 1066: 		$domconfig->{$role}{$img} = 
 1067: 		    $env{'form.'.$role.'_import_'.$img};
 1068: 	    }
 1069:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 1070:                 my $error;
 1071:                 if ($configuserok eq 'ok') {
 1072:                     if ($switchserver) {
 1073:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 1074:                     } else {
 1075:                         if ($author_ok eq 'ok') {
 1076:                             my ($result,$logourl) = 
 1077:                                 &publishlogo($r,'upload',$role.'_'.$img,
 1078:                                            $dom,$confname,$img,$width,$height);
 1079:                             if ($result eq 'ok') {
 1080:                                 $confhash->{$role}{$img} = $logourl;
 1081:                                 $changes{$role}{'images'}{$img} = 1;
 1082:                             } else {
 1083:                                 $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);
 1084:                             }
 1085:                         } else {
 1086:                             $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);
 1087:                         }
 1088:                     }
 1089:                 } else {
 1090:                     $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);
 1091:                 }
 1092:                 if ($error) {
 1093:                     &Apache::lonnet::logthis($error);
 1094:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 1095:                 }
 1096:             } elsif ($domconfig->{$role}{$img} ne '') {
 1097:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 1098:                     my $error;
 1099:                     if ($configuserok eq 'ok') {
 1100: # is confname an author?
 1101:                         if ($switchserver eq '') {
 1102:                             if ($author_ok eq 'ok') {
 1103:                                 my ($result,$logourl) = 
 1104:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 1105:                                             $dom,$confname,$img,$width,$height);
 1106:                                 if ($result eq 'ok') {
 1107:                                     $confhash->{$role}{$img} = $logourl;
 1108: 				    $changes{$role}{'images'}{$img} = 1;
 1109:                                 }
 1110:                             }
 1111:                         }
 1112:                     }
 1113:                 }
 1114:             }
 1115:         }
 1116:         if (ref($domconfig) eq 'HASH') {
 1117:             if (ref($domconfig->{$role}) eq 'HASH') {
 1118:                 foreach my $img (@images) {
 1119:                     if ($domconfig->{$role}{$img} ne '') {
 1120:                         if ($env{'form.'.$role.'_del_'.$img}) {
 1121:                             $confhash->{$role}{$img} = '';
 1122:                             $changes{$role}{'images'}{$img} = 1;
 1123:                         } else {
 1124:                             if ($confhash->{$role}{$img} eq '') {
 1125:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 1126:                             }
 1127:                         }
 1128:                     } else {
 1129:                         if ($env{'form.'.$role.'_del_'.$img}) {
 1130:                             $confhash->{$role}{$img} = '';
 1131:                             $changes{$role}{'images'}{$img} = 1;
 1132:                         } 
 1133:                     }
 1134:                 }  
 1135:                 if ($domconfig->{$role}{'font'} ne '') {
 1136:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 1137:                         $changes{$role}{'font'} = 1;
 1138:                     }
 1139:                 } else {
 1140:                     if ($confhash->{$role}{'font'}) {
 1141:                         $changes{$role}{'font'} = 1;
 1142:                     }
 1143:                 }
 1144:                 foreach my $item (@bgs) {
 1145:                     if ($domconfig->{$role}{$item} ne '') {
 1146:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 1147:                             $changes{$role}{'bgs'}{$item} = 1;
 1148:                         } 
 1149:                     } else {
 1150:                         if ($confhash->{$role}{$item}) {
 1151:                             $changes{$role}{'bgs'}{$item} = 1;
 1152:                         }
 1153:                     }
 1154:                 }
 1155:                 foreach my $item (@links) {
 1156:                     if ($domconfig->{$role}{$item} ne '') {
 1157:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 1158:                             $changes{$role}{'links'}{$item} = 1;
 1159:                         }
 1160:                     } else {
 1161:                         if ($confhash->{$role}{$item}) {
 1162:                             $changes{$role}{'links'}{$item} = 1;
 1163:                         }
 1164:                     }
 1165:                 }
 1166:             } else {
 1167:                 &default_change_checker($role,\@images,\@links,\@bgs,
 1168:                                         $confhash,\%changes); 
 1169:             }
 1170:         } else {
 1171:             &default_change_checker($role,\@images,\@links,\@bgs,
 1172:                                     $confhash,\%changes); 
 1173:         }
 1174:     }
 1175:     return ($errors,%changes);
 1176: }
 1177: 
 1178: sub default_change_checker {
 1179:     my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
 1180:     foreach my $item (@{$links}) {
 1181:         if ($confhash->{$role}{$item}) {
 1182:             $changes->{$role}{'links'}{$item} = 1;
 1183:         }
 1184:     }
 1185:     foreach my $item (@{$bgs}) {
 1186:         if ($confhash->{$role}{$item}) {
 1187:             $changes->{$role}{'bgs'}{$item} = 1;
 1188:         }
 1189:     }
 1190:     foreach my $img (@{$images}) {
 1191:         if ($env{'form.'.$role.'_del_'.$img}) {
 1192:             $confhash->{$role}{$img} = '';
 1193:             $changes->{$role}{'images'}{$img} = 1;
 1194:         }
 1195:     }
 1196:     if ($confhash->{$role}{'font'}) {
 1197:         $changes->{$role}{'font'} = 1;
 1198:     }
 1199: } 
 1200: 
 1201: sub display_colorchgs {
 1202:     my ($dom,$changes,$roles,$confhash) = @_;
 1203:     my (%choices,$resulttext);
 1204:     &Apache::loncommon::devalidate_domconfig_cache($dom);
 1205:     if (!grep(/^login$/,@{$roles})) {
 1206:         $resulttext = &mt('Changes made:').'<br />';
 1207:     }
 1208:     foreach my $role (@{$roles}) {
 1209:         if ($role eq 'login') {
 1210:             %choices = &login_choices();
 1211:         } else {
 1212:             %choices = &color_font_choices();
 1213:         }
 1214:         if (ref($changes->{$role}) eq 'HASH') {
 1215:             if ($role ne 'login') {
 1216:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 1217:             }
 1218:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 1219:                 if ($role ne 'login') {
 1220:                     $resulttext .= '<ul>';
 1221:                 }
 1222:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 1223:                     if ($role ne 'login') {
 1224:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 1225:                     }
 1226:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 1227:                         if ($confhash->{$role}{$item} eq '') {
 1228:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 1229:                         } else {
 1230:                             my $newitem = $confhash->{$role}{$item};
 1231:                             if ($key eq 'images') {
 1232:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 1233:                             }
 1234:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 1235:                         }
 1236:                     }
 1237:                     if ($role ne 'login') {
 1238:                         $resulttext .= '</ul></li>';
 1239:                     }
 1240:                 } else {
 1241:                     if ($confhash->{$role}{$key} eq '') {
 1242:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 1243:                     } else {
 1244:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 1245:                     }
 1246:                 }
 1247:                 if ($role ne 'login') {
 1248:                     $resulttext .= '</ul>';
 1249:                 }
 1250:             }
 1251:         }
 1252:     }
 1253:     return $resulttext;
 1254: }
 1255: 
 1256: sub thumb_dimensions {
 1257:     return ('200','50');
 1258: }
 1259: 
 1260: sub check_dimensions {
 1261:     my ($inputfile) = @_;
 1262:     my ($fullwidth,$fullheight);
 1263:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 1264:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 1265:             my $imageinfo = <PIPE>;
 1266:             if (!close(PIPE)) {
 1267:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 1268:             }
 1269:             chomp($imageinfo);
 1270:             my ($fullsize) = 
 1271:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)\s+/);
 1272:             if ($fullsize) {
 1273:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 1274:             }
 1275:         }
 1276:     }
 1277:     return ($fullwidth,$fullheight);
 1278: }
 1279: 
 1280: sub check_configuser {
 1281:     my ($uhome,$dom,$confname,$servadm) = @_;
 1282:     my ($configuserok,%currroles);
 1283:     if ($uhome eq 'no_host') {
 1284:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 1285:         my $configpass = &LONCAPA::Enrollment::create_password();
 1286:         $configuserok = 
 1287:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 1288:                              $configpass,'','','','','',undef,$servadm);
 1289:     } else {
 1290:         $configuserok = 'ok';
 1291:         %currroles = 
 1292:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 1293:     }
 1294:     return ($configuserok,%currroles);
 1295: }
 1296: 
 1297: sub check_authorstatus {
 1298:     my ($dom,$confname,%currroles) = @_;
 1299:     my $author_ok;
 1300:     if (!$currroles{':'.$dom.':au'}) {
 1301:         my $start = time;
 1302:         my $end = 0;
 1303:         $author_ok = 
 1304:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 1305:                                         'au',$end,$start);
 1306:     } else {
 1307:         $author_ok = 'ok';
 1308:     }
 1309:     return $author_ok;
 1310: }
 1311: 
 1312: sub publishlogo {
 1313:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
 1314:     my ($output,$fname,$logourl);
 1315:     if ($action eq 'upload') {
 1316:         $fname=$env{'form.'.$formname.'.filename'};
 1317:         chop($env{'form.'.$formname});
 1318:     } else {
 1319:         ($fname) = ($formname =~ /([^\/]+)$/);
 1320:     }
 1321:     $fname=&Apache::lonnet::clean_filename($fname);
 1322: # See if there is anything left
 1323:     unless ($fname) { return ('error: no uploaded file'); }
 1324:     $fname="$subdir/$fname";
 1325:     my $filepath='/home/'.$confname.'/public_html';
 1326:     my ($fnamepath,$file,$fetchthumb);
 1327:     $file=$fname;
 1328:     if ($fname=~m|/|) {
 1329:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 1330:     }
 1331:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
 1332:     my $count;
 1333:     for ($count=4;$count<=$#parts;$count++) {
 1334:         $filepath.="/$parts[$count]";
 1335:         if ((-e $filepath)!=1) {
 1336:             mkdir($filepath,02770);
 1337:         }
 1338:     }
 1339:     # Check for bad extension and disallow upload
 1340:     if ($file=~/\.(\w+)$/ &&
 1341:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 1342:         $output = 
 1343:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
 1344:     } elsif ($file=~/\.(\w+)$/ &&
 1345:         !defined(&Apache::loncommon::fileembstyle($1))) {
 1346:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 1347:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 1348:         $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 1349:     } elsif (-d "$filepath/$file") {
 1350:         $output = &mt('File name is a directory name - rename the file and re-upload');
 1351:     } else {
 1352:         my $source = $filepath.'/'.$file;
 1353:         my $logfile;
 1354:         if (!open($logfile,">>$source".'.log')) {
 1355:             return (&mt('No write permission to Construction Space'));
 1356:         }
 1357:         print $logfile
 1358: "\n================= Publish ".localtime()." ================\n".
 1359: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 1360: # Save the file
 1361:         if (!open(FH,'>'.$source)) {
 1362:             &Apache::lonnet::logthis('Failed to create '.$source);
 1363:             return (&mt('Failed to create file'));
 1364:         }
 1365:         if ($action eq 'upload') {
 1366:             if (!print FH ($env{'form.'.$formname})) {
 1367:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 1368:                 return (&mt('Failed to write file'));
 1369:             }
 1370:         } else {
 1371:             my $original = &Apache::lonnet::filelocation('',$formname);
 1372:             if(!copy($original,$source)) {
 1373:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 1374:                 return (&mt('Failed to write file'));
 1375:             }
 1376:         }
 1377:         close(FH);
 1378:         chmod(0660, $source); # Permissions to rw-rw---.
 1379: 
 1380:         my $docroot=$r->dir_config('lonDocRoot');
 1381:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 1382:         my $copyfile=$targetdir.'/'.$file;
 1383: 
 1384:         my @parts=split(/\//,$targetdir);
 1385:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 1386:         for (my $count=5;$count<=$#parts;$count++) {
 1387:             $path.="/$parts[$count]";
 1388:             if (!-e $path) {
 1389:                 print $logfile "\nCreating directory ".$path;
 1390:                 mkdir($path,02770);
 1391:             }
 1392:         }
 1393:         my $versionresult;
 1394:         if (-e $copyfile) {
 1395:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 1396:         } else {
 1397:             $versionresult = 'ok';
 1398:         }
 1399:         if ($versionresult eq 'ok') {
 1400:             if (copy($source,$copyfile)) {
 1401:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 1402:                 $output = 'ok';
 1403:                 &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 1404:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 1405:             } else {
 1406:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 1407:                 $output = &mt('Failed to copy file to RES space').", $!";
 1408:             }
 1409:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 1410:                 my $inputfile = $filepath.'/'.$file;
 1411:                 my $outfile = $filepath.'/'.'tn-'.$file;
 1412:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 1413:                 if ($fullwidth ne '' && $fullheight ne '') { 
 1414:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 1415:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 1416:                         system("convert -sample $thumbsize $inputfile $outfile");
 1417:                         chmod(0660, $filepath.'/tn-'.$file);
 1418:                         if (-e $outfile) {
 1419:                             my $copyfile=$targetdir.'/tn-'.$file;
 1420:                             if (copy($outfile,$copyfile)) {
 1421:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 1422:                                 &write_metadata($dom,$confname,$formname,
 1423:                                                 $targetdir,'tn-'.$file,$logfile);
 1424:                             } else {
 1425:                                 print $logfile "\nUnable to write ".$copyfile.
 1426:                                                ':'.$!."\n";
 1427:                             }
 1428:                         }
 1429:                     }
 1430:                 }
 1431:             }
 1432:         } else {
 1433:             $output = $versionresult;
 1434:         }
 1435:     }
 1436:     return ($output,$logourl);
 1437: }
 1438: 
 1439: sub logo_versioning {
 1440:     my ($targetdir,$file,$logfile) = @_;
 1441:     my $target = $targetdir.'/'.$file;
 1442:     my ($maxversion,$fn,$extn,$output);
 1443:     $maxversion = 0;
 1444:     if ($file =~ /^(.+)\.(\w+)$/) {
 1445:         $fn=$1;
 1446:         $extn=$2;
 1447:     }
 1448:     opendir(DIR,$targetdir);
 1449:     while (my $filename=readdir(DIR)) {
 1450:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 1451:             $maxversion=($1>$maxversion)?$1:$maxversion;
 1452:         }
 1453:     }
 1454:     $maxversion++;
 1455:     print $logfile "\nCreating old version ".$maxversion."\n";
 1456:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 1457:     if (copy($target,$copyfile)) {
 1458:         print $logfile "Copied old target to ".$copyfile."\n";
 1459:         $copyfile=$copyfile.'.meta';
 1460:         if (copy($target.'.meta',$copyfile)) {
 1461:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 1462:             $output = 'ok';
 1463:         } else {
 1464:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 1465:             $output = &mt('Failed to copy old meta').", $!, ";
 1466:         }
 1467:     } else {
 1468:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 1469:         $output = &mt('Failed to copy old target').", $!, ";
 1470:     }
 1471:     return $output;
 1472: }
 1473: 
 1474: sub write_metadata {
 1475:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 1476:     my (%metadatafields,%metadatakeys,$output);
 1477:     $metadatafields{'title'}=$formname;
 1478:     $metadatafields{'creationdate'}=time;
 1479:     $metadatafields{'lastrevisiondate'}=time;
 1480:     $metadatafields{'copyright'}='public';
 1481:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 1482:                                          $env{'user.domain'};
 1483:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 1484:     $metadatafields{'domain'}=$dom;
 1485:     {
 1486:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 1487:         my $mfh;
 1488:         unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 1489:             $output = &mt('Could not write metadata');
 1490:         }
 1491:         foreach (sort keys %metadatafields) {
 1492:             unless ($_=~/\./) {
 1493:                 my $unikey=$_;
 1494:                 $unikey=~/^([A-Za-z]+)/;
 1495:                 my $tag=$1;
 1496:                 $tag=~tr/A-Z/a-z/;
 1497:                 print $mfh "\n\<$tag";
 1498:                 foreach (split(/\,/,$metadatakeys{$unikey})) {
 1499:                     my $value=$metadatafields{$unikey.'.'.$_};
 1500:                     $value=~s/\"/\'\'/g;
 1501:                     print $mfh ' '.$_.'="'.$value.'"';
 1502:                 }
 1503:                 print $mfh '>'.
 1504:                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 1505:                         .'</'.$tag.'>';
 1506:             }
 1507:         }
 1508:         $output = 'ok';
 1509:         print $logfile "\nWrote metadata";
 1510:         close($mfh);
 1511:     }
 1512: }
 1513: 
 1514: sub check_switchserver {
 1515:     my ($dom,$confname) = @_;
 1516:     my ($allowed,$switchserver);
 1517:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 1518:     if ($home eq 'no_host') {
 1519:         $home = &Apache::lonnet::domain($dom,'primary');
 1520:     }
 1521:     my @ids=&Apache::lonnet::current_machine_ids();
 1522:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 1523:     if (!$allowed) {
 1524: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
 1525:     }
 1526:     return $switchserver;
 1527: }
 1528: 
 1529: sub modify_quotas {
 1530:     my ($dom,%domconfig) = @_;
 1531:     my ($resulttext,%changes);
 1532:     my ($usertypes,$order) = 
 1533:         &Apache::lonnet::retrieve_inst_usertypes($dom);
 1534:     my %formhash;
 1535:     foreach my $key (keys(%env)) {
 1536:         if ($key =~ /^form\.quota_(.+)$/) {
 1537:             $formhash{$1} = $env{$key};
 1538:         }
 1539:     }
 1540:     $formhash{'default'} = $env{'form.defaultquota'};
 1541:     if (ref($domconfig{'quotas'}) eq 'HASH') {
 1542:         foreach my $key (keys(%{$domconfig{'quotas'}})) {
 1543:             if (exists($formhash{$key})) {
 1544:                 if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
 1545:                     $changes{$key} = 1;
 1546:                 }
 1547:             } else {
 1548:                 $formhash{$key} = $domconfig{'quotas'}{$key};
 1549:             }
 1550:         }
 1551:     }
 1552:     foreach my $key (keys(%formhash)) {
 1553:         if ($formhash{$key} ne '') {
 1554:             if (!exists($domconfig{'quotas'}{$key})) {
 1555:                 $changes{$key} = 1;
 1556:             }
 1557:         }
 1558:     }
 1559:     my %quotahash = (
 1560:                       quotas => {%formhash},
 1561:                     );
 1562:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 1563:                                              $dom);
 1564:     if ($putresult eq 'ok') {
 1565:         if (keys(%changes) > 0) {
 1566:             $resulttext = &mt('Changes made:').'<ul>';
 1567:             foreach my $item (sort(keys(%changes))) {
 1568:                 $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'</li>';
 1569:             }
 1570:             $resulttext .= '</ul>';
 1571:         } else {
 1572:             $resulttext = &mt('No changes made to default quotas');
 1573:         }
 1574:     } else {
 1575:         $resulttext = '<span class="LC_error">'.
 1576: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 1577:     }
 1578:     return $resulttext;
 1579: }
 1580: 
 1581: sub modify_autoenroll {
 1582:     my ($dom,%domconfig) = @_;
 1583:     my ($resulttext,%changes);
 1584:     my %currautoenroll;
 1585:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 1586:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 1587:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 1588:         }
 1589:     }
 1590:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 1591:     my %title = ( run => 'Auto-enrollment active',
 1592:                   sender => 'Sender for notification messages');
 1593:     my @offon = ('off','on');
 1594:     my $sender_uname = $env{'form.sender_uname'};
 1595:     my $sender_domain = $env{'form.sender_domain'};
 1596:     if ($sender_domain eq '') {
 1597:         $sender_uname = '';
 1598:     } elsif ($sender_uname eq '') {
 1599:         $sender_domain = '';
 1600:     }
 1601:     my %autoenrollhash =  (
 1602:                        autoenroll => { run => $env{'form.autoenroll_run'},
 1603:                                        sender_uname => $sender_uname,
 1604:                                        sender_domain => $sender_domain,
 1605: 
 1606:                                 }
 1607:                      );
 1608:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 1609:                                              $dom);
 1610:     if ($putresult eq 'ok') {
 1611:         if (exists($currautoenroll{'run'})) {
 1612:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 1613:                  $changes{'run'} = 1;
 1614:              }
 1615:         } elsif ($autorun) {
 1616:             if ($env{'form.autoenroll_run'} ne '1') {
 1617:                 $changes{'run'} = 1;
 1618:             }
 1619:         }
 1620:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 1621:             $changes{'sender'} = 1;
 1622:         }
 1623:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 1624:             $changes{'sender'} = 1;
 1625:         }
 1626:         if (keys(%changes) > 0) {
 1627:             $resulttext = &mt('Changes made:').'<ul>';
 1628:             if ($changes{'run'}) {
 1629:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 1630:             }
 1631:             if ($changes{'sender'}) {
 1632:                 if ($sender_uname eq '' || $sender_domain eq '') {
 1633:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 1634:                 } else {
 1635:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 1636:                 }
 1637:             }
 1638:             $resulttext .= '</ul>';
 1639:         } else {
 1640:             $resulttext = &mt('No changes made to auto-enrollment settings');
 1641:         }
 1642:     } else {
 1643:         $resulttext = '<span class="LC_error">'.
 1644: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 1645:     }
 1646:     return $resulttext;
 1647: }
 1648: 
 1649: sub modify_autoupdate {
 1650:     my ($dom,%domconfig) = @_;
 1651:     my ($resulttext,%currautoupdate,%fields,%changes);
 1652:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 1653:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 1654:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 1655:         }
 1656:     }
 1657:     my @offon = ('off','on');
 1658:     my %title = &Apache::lonlocal::texthash (
 1659:                    run => 'Auto-update:',
 1660:                    classlists => 'Updates to user information in classlists?'
 1661:                 );
 1662:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
 1663:     my %fieldtitles = &Apache::lonlocal::texthash (
 1664:                         id => 'Student/Employee ID',
 1665:                         permanentemail => 'E-mail address',
 1666:                         lastname => 'Last Name',
 1667:                         firstname => 'First Name',
 1668:                         middlename => 'Middle Name',
 1669:                         gen => 'Generation',
 1670:                       );
 1671:     my $othertitle = &mt('All users');
 1672:     if (keys(%{$usertypes}) >  0) {
 1673:         $othertitle = "Other users";
 1674:     }
 1675:     foreach my $key (keys(%env)) {
 1676:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 1677:             push(@{$fields{$1}},$2);
 1678:         }
 1679:     }
 1680:     my %updatehash = (
 1681:                       autoupdate => { run => $env{'form.autoupdate_run'},
 1682:                                       classlists => $env{'form.classlists'},
 1683:                                       fields => {%fields},
 1684:                                     }
 1685:                      );
 1686:     foreach my $key (keys(%currautoupdate)) {
 1687:         if (($key eq 'run') || ($key eq 'classlists')) {
 1688:             if (exists($updatehash{autoupdate}{$key})) {
 1689:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 1690:                     $changes{$key} = 1;
 1691:                 }
 1692:             }
 1693:         } elsif ($key eq 'fields') {
 1694:             if (ref($currautoupdate{$key}) eq 'HASH') {
 1695:                 foreach my $item (keys(%{$currautoupdate{$key}})) {
 1696:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 1697:                         my $change = 0;
 1698:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 1699:                             if (!exists($fields{$item})) {
 1700:                                 $change = 1;
 1701:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 1702:                                 if (!grep/^\Q$type\E$/,@{$fields{$item}}) {
 1703:                                     $change = 1;
 1704:                                 }
 1705:                             }
 1706:                         }
 1707:                         if ($change) {
 1708:                             push(@{$changes{$key}},$item);
 1709:                         }
 1710:                     }
 1711:                 }
 1712:             }
 1713:         }
 1714:     }
 1715:     foreach my $key (keys(%fields)) {
 1716:         if (ref($currautoupdate{'fields'}) eq 'HASH') {
 1717:             if (!exists($currautoupdate{'fields'}{$key})) {
 1718:                 push(@{$changes{'fields'}},$key);
 1719:             }
 1720:         } else {
 1721:             push(@{$changes{'fields'}},$key);
 1722:         }
 1723:     }
 1724:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 1725:                                              $dom);
 1726:     if ($putresult eq 'ok') {
 1727:         if (keys(%changes) > 0) {
 1728:             $resulttext = &mt('Changes made:').'<ul>';
 1729:             foreach my $key (sort(keys(%changes))) {
 1730:                 if (ref($changes{$key}) eq 'ARRAY') {
 1731:                     foreach my $item (@{$changes{$key}}) {
 1732:                         my @newvalues;
 1733:                         foreach my $type (@{$fields{$item}}) {
 1734:                             push(@newvalues,$fieldtitles{$type});
 1735:                         }
 1736:                         my $newvaluestr;
 1737:                         if (@newvalues > 0) {
 1738:                             $newvaluestr = join(', ',@newvalues);
 1739:                         } else {
 1740:                             $newvaluestr = &mt('none');
 1741:                         }
 1742:                         if ($item eq 'default') {
 1743:                             $resulttext .= '<li>'.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'</li>';
 1744:                         } else {
 1745:                             $resulttext .= '<li>'.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'</li>';
 1746:                         }
 1747:                     }
 1748:                 } else {
 1749:                     my $newvalue;
 1750:                     if ($key eq 'run') {
 1751:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 1752:                     } else {
 1753:                         $newvalue = $offon[$env{'form.'.$key}];
 1754:                     }
 1755:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 1756:                 }
 1757:             }
 1758:             $resulttext .= '</ul>';
 1759:         } else {
 1760:             $resulttext = &mt('No changes made to autoupdates');
 1761:         }
 1762:     } else {
 1763:         $resulttext = '<span class="LC_error">'.
 1764: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 1765:     }
 1766:     return $resulttext;
 1767: }
 1768: 
 1769: 1;
 1770: 

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