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

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

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