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

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

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