File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.6: download - view: text, annotated - select for diffs
Tue Apr 3 18:47:23 2007 UTC (17 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- domainprefs.pm
   - DCs can modify font colors, background colors and images for login page and also for defaults for different roles (student, coordinator, author, admin).
   - default settings (from /home/httpd/lonTabs/lonDomColors/default.tab) displayed if no custom choices made.
   - thumbnail images shown for both custom images and defaults
   - uploaded files stored in portfolio for domain config user (username: $dom-domainconfig), with indefinite public access permissions
   - $dom-domainconfig user created if not present

- loncommon.pm
  - Only default.tab file is now read from /home/httpd/lonTabs/lonDomColors.
  - defaults available in global hash: %Apache::loncommon::defaultdesign
  - &designparm() now gets custom settings for a specific domain from lonnet::get_domainconf($domain)
  - In &bodytag(), top frame rendering only uses $lonhttpdPort for images served from /adm, i.e., defaults.
  - Domain logo information now from config data from lonnet::get_domainconf($domain)

- lonlogin.pm
  - Display of Course Catalog link (default is display) and Server Administrator Email address (default is no display) now determined from domain configuration set for domain.

- lonnet.pm
  - get_domainconf() retrieves domain configuration.  Caching used (1800s lifetime).
      if configuration.db exists for primary library server in domain data from there,
          otherwise from /home/httpd/lonTabs/lonDomColors/$dom.tab (if one exists)
  - &get_dom() and &put_dom() can now take a fourth optional argument ($uhome) to allow domain data to be retrieved/stored in .db on specified host server ($uhome) in domain.
      Default is the primary library server in the domain.
  - &userfileupload() and &finishuserfileupload() can now accept to additional optional arguments (width and height in pixels for a thumbnail image to be stored for the uploaded file).
  - thumbnail is stored in same directory as full size image, and is named with a tn- prepended to the name of the full size image.
  - documentation updated for &get_dom and &put_dom().

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.6 2007/04/03 18:47:23 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#
   23: # /home/httpd/html/adm/gpl.txt
   24: #
   25: # http://www.lon-capa.org/
   26: #
   27: #
   28: ###############################################################
   29: ##############################################################
   30: 
   31: package Apache::domainprefs;
   32: 
   33: use strict;
   34: use Apache::Constants qw(:common :http);
   35: use Apache::lonnet;
   36: use Apache::loncommon();
   37: use Apache::lonhtmlcommon();
   38: use Apache::lonlocal;
   39: use LONCAPA();
   40: use LONCAPA::Enrollment;
   41: 
   42: sub handler {
   43:     my $r=shift;
   44:     if ($r->header_only) {
   45:         &Apache::loncommon::content_type($r,'text/html');
   46:         $r->send_http_header;
   47:         return OK;
   48:     }
   49: 
   50:     my $dom = $env{'request.role.domain'};
   51:     my $domdesc = &Apache::lonnet::domain($dom,'description');
   52:     if (&Apache::lonnet::allowed('mau',$dom)) {
   53:         &Apache::loncommon::content_type($r,'text/html');
   54:         $r->send_http_header;
   55:     } else {
   56:         $env{'user.error.msg'}=
   57:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
   58:         return HTTP_NOT_ACCEPTABLE;
   59:     }
   60:     &Apache::lonhtmlcommon::clear_breadcrumbs();
   61:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   62:                                             ['phase']);
   63:     my $phase = "display";
   64:     if ( exists($env{'form.phase'}) ) {
   65:         $phase = $env{'form.phase'};
   66:     }
   67:     my %domconfig =
   68:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
   69:                                'quotas','autoenroll','autoupdate'],$dom);
   70:     my @prefs = (
   71:       { text => 'Default color schemes',
   72:         help => 'Default_Color_Schemes',
   73:         action => 'rolecolors',
   74:         header => [{col1 => 'Student Settings',
   75:                     col2 => '',},
   76:                    {col1 => 'Coordinator Settings',
   77:                     col2 => '',},
   78:                    {col1 => 'Author Settings',
   79:                     col2 => '',},
   80:                    {col1 => 'Administrator Settings',
   81:                     col2 => '',}],
   82:         },
   83:       { text => 'Log-in page options',
   84:         help => 'Domain_Log-in_Page',
   85:         action => 'login',
   86:         header => [{col1 => 'Item',
   87:                     col2 => '',}],
   88:         },
   89:       { text => 'Default quotas for user portfolios',
   90:         help => 'Default_User_Quota',
   91:         action => 'quotas',
   92:         header => [{col1 => 'User type',
   93:                     col2 => 'Default quota'}],
   94:         },
   95:       { text => 'Auto-enrollment settings',
   96:         help => 'Domain_Auto_Enrollment',
   97:         action => 'autoenroll',
   98:         header => [{col1 => 'Configuration setting',
   99:                     col2 => 'Value(s)'}],
  100:         },
  101:       { text => 'Auto-update settings',
  102:         help => 'Domain_Auto_Update',
  103:         action => 'autoupdate',
  104:         header => [{col1 => 'Setting',
  105:                     col2 => 'Value',},
  106:                    {col1 => 'User Population',
  107:                     col2 => 'Updataeable user data'}],
  108:       },
  109:     );
  110:     my @roles = ('student','coordinator','author','admin');
  111:     &Apache::lonhtmlcommon::add_breadcrumb
  112:     ({href=>"javascript:changePage(document.$phase,'display')",
  113:       text=>"Domain Configuration"});
  114:     if ($phase eq 'process') {
  115:         &Apache::lonhtmlcommon::add_breadcrumb
  116:           ({href=>"javascript:changePage(document.$phase,'$phase')",
  117:             text=>"Updated"});
  118:         &print_header($r,$phase);
  119:         foreach my $item (@prefs) {
  120:             $r->print('<h3>'.&mt($item->{'text'}).'</h3>'.
  121:                    &process_changes($r,$dom,$item->{'action'},\@roles,%domconfig));
  122:         }
  123:         $r->print('<p>');
  124:         &print_footer($r,$phase,'display','Back to actions menu');
  125:         $r->print('</p>');
  126:     } else {
  127:         if ($phase eq '') {
  128:             $phase = 'display';
  129:         }
  130:         my %helphash;   
  131:         my $numprefs = @prefs;
  132:         &print_header($r,$phase);
  133:         $r->print('<table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
  134:         foreach my $item (@prefs) {
  135:             if ($item->{'action'} eq 'login') {
  136:                 $r->print('</td><td width="6%">&nbsp;</td><td align="left" valign="top" width="47%">');
  137:             }
  138:             &print_config_box($r,$dom,$phase,$item->{'action'},
  139:                               $item,$domconfig{$item->{'action'}});
  140:         }
  141:         $r->print('
  142:            </table>
  143:           </td>
  144:          </tr>
  145:         </table>
  146:       </td>
  147:     </tr>
  148:    </table>');
  149:         &print_footer($r,$phase,'process','Store changes');
  150:     }
  151:     return OK;
  152: }
  153: 
  154: sub process_changes {
  155:     my ($r,$dom,$action,$roles,%domconfig) = @_;
  156:     my $output;
  157:     if ($action eq 'login') {
  158:         $output = &modify_login($r,$dom,%domconfig);
  159:     } elsif ($action eq 'rolecolors') {
  160:         $output = &modify_rolecolors($r,$dom,$roles,%domconfig);
  161:     } elsif ($action eq 'quotas') {
  162:         $output = &modify_quotas($dom,%domconfig);
  163:     } elsif ($action eq 'autoenroll') {
  164:         $output = &modify_autoenroll($dom,%domconfig);
  165:     } elsif ($action eq 'autoupdate') {
  166:         $output = &modify_autoupdate($dom,%domconfig);
  167:     }
  168:     return $output;
  169: }
  170: 
  171: sub print_config_box {
  172:     my ($r,$dom,$phase,$action,$item,$settings) = @_;
  173:     $r->print('
  174:          <table class="LC_nested_outer">
  175:           <tr>
  176:            <th>'.&mt($item->{text}).'&nbsp;'.
  177:            &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
  178:           </tr>');
  179:     if (($action eq 'autoupdate') || ($action eq 'rolecolors')) {
  180:         my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
  181:         $r->print('
  182:           <tr>
  183:            <td>
  184:             <table class="LC_nested">
  185:              <tr class="LC_info_row">
  186:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
  187:               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
  188:              </tr>');
  189:         if ($action eq 'autoupdate') {
  190:             $r->print(&print_autoupdate('top',$dom,$settings));
  191:         } else {
  192:             $r->print(&print_rolecolors($phase,'student',$dom,$settings));
  193:         }
  194:         $r->print('
  195:            </table>
  196:           </td>
  197:          </tr>
  198:          <tr>
  199:            <td>
  200:             <table class="LC_nested">
  201:              <tr class="LC_info_row">
  202:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
  203:               <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
  204:              </tr>');
  205:         if ($action eq 'autoupdate') {
  206:             $r->print(&print_autoupdate('bottom',$dom,$settings));
  207:         } else {
  208:             $r->print(&print_rolecolors($phase,'coordinator',$dom,$settings).'
  209:            </table>
  210:           </td>
  211:          </tr>
  212:          <tr>
  213:            <td>
  214:             <table class="LC_nested">
  215:              <tr class="LC_info_row">
  216:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
  217:               <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
  218:              </tr>'.
  219:             &print_rolecolors($phase,'author',$dom,$settings).'
  220:            </table>
  221:           </td>
  222:          </tr>
  223:          <tr>
  224:            <td>
  225:             <table class="LC_nested">
  226:              <tr class="LC_info_row">
  227:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
  228:               <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
  229:              </tr>'.
  230:             &print_rolecolors($phase,'admin',$dom,$settings));
  231:         }
  232:     } else {
  233:         $r->print('
  234:           <tr>
  235:            <td>
  236:             <table class="LC_nested">
  237:              <tr class="LC_info_row">');
  238:         if ($action eq 'login') {
  239:             $r->print('  
  240:               <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>');
  241:         } else {
  242:             $r->print('
  243:               <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>');
  244:         }
  245:         $r->print('
  246:               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
  247:              </tr>');
  248:         if ($action eq 'login') {
  249:            $r->print(&print_login($dom,$phase,$settings));
  250:         } elsif ($action eq 'quotas') {
  251:            $r->print(&print_quotas($dom,$settings));
  252:         } elsif ($action eq 'autoenroll') {
  253:            $r->print(&print_autoenroll($dom,$settings));
  254:         }  
  255:     }
  256:     $r->print('
  257:    </table>
  258:   </td>
  259:  </tr>
  260: </table><br />');
  261:     return;
  262: }
  263: 
  264: sub print_header {
  265:     my ($r,$phase) = @_;
  266:     my $js = '
  267: <script type="text/javascript">
  268: function changePage(formname,newphase) {
  269:     formname.phase.value = newphase;
  270:     formname.submit();
  271: }
  272: '.
  273: &color_pick_js().'
  274: </script>
  275: ';
  276:     $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
  277:                                            $js));
  278:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
  279:     $r->print('
  280: <form name="parmform">
  281: <input type="hidden" name="pres_marker" />
  282: <input type="hidden" name="pres_type" />
  283: <input type="hidden" name="pres_value" />
  284: </form>
  285: ');
  286:     $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
  287:               ' enctype="multipart/form-data">');
  288:     return;
  289: }
  290: 
  291: sub print_footer {
  292:     my ($r,$phase,$newphase,$button_text) = @_;
  293:     $button_text = &mt($button_text);
  294:     $r->print('<input type="hidden" name="phase" value="" />');
  295:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  296:     if ($phase eq 'process') {
  297:         $r->print('<a href='.$dest.'>'.$button_text.'</a>');
  298:     } else {
  299:         $r->print('<input type="button" name="store" value="'.
  300:                   $button_text.'" onclick='.$dest.' />');
  301:     }
  302:     $r->print('</form>');
  303:     $r->print('<br />'.&Apache::loncommon::end_page());
  304:     return;
  305: }
  306: 
  307: sub print_login {
  308:     my ($dom,$phase,$settings) = @_;
  309:     my %choices = &login_choices();
  310:     my ($catalogon,$catalogoff,$adminmailon,$adminmailoff);
  311:     $catalogon = ' checked="checked" ';
  312:     $adminmailoff = ' checked="checked" ';
  313:     my @images = ('img','logo','domlogo');
  314:     my @bgs = ('pgbg','mainbg','sidebg');
  315:     my @links = ('link','alink','vlink');
  316:     my %designhash = &Apache::lonnet::get_domainconf($dom);
  317:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  318:     my (%is_custom,%designs);
  319:     my %defaults = (
  320:                    font => $defaultdesign{'login.font'},
  321:                    );
  322:     foreach my $item (@images) {
  323:         $defaults{$item} = $defaultdesign{'login.'.$item};
  324:     }
  325:     foreach my $item (@bgs) {
  326:         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
  327:     }
  328:     foreach my $item (@links) {
  329:         $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
  330:     }
  331:     if (ref($settings) eq 'HASH') {
  332:         if ($settings->{'coursecatalog'} eq '0') {
  333:             $catalogoff = $catalogon;
  334:             $catalogon = ' ';
  335:         }
  336:         if ($settings->{'adminmail'} eq '1') {
  337:             $adminmailon = $adminmailoff;
  338:             $adminmailoff = ' ';
  339:         }
  340:         foreach my $item (@images) {
  341:             if ($settings->{$item} ne '') {
  342:                 $designs{$item} = $settings->{$item};
  343:                 $is_custom{$item} = 1;
  344:             }
  345:         }
  346:         if ($settings->{'font'} ne '') {
  347:             $designs{'font'} = $settings->{'font'};
  348:             $is_custom{'font'} = 1;
  349:         }
  350:         foreach my $item (@bgs) {
  351:             if ($settings->{$item} ne '') {
  352:                 $designs{'bgs'}{$item} = $settings->{$item};
  353:                 $is_custom{$item} = 1;
  354:             }
  355:         }
  356:         foreach my $item (@links) {
  357:             if ($settings->{$item} ne '') {
  358:                 $designs{'links'}{$item} = $settings->{$item};
  359:                 $is_custom{$item} = 1;
  360:             }
  361:         }
  362:     } else {
  363:         $designs{'domlogo'} = '';
  364:         if (-e '/home/httpd/html/adm/lonDomLogos/'.$dom.'.gif') {
  365:             $designs{'domlogo'} = '/home/httpd/html/adm/lonDomLogos/'.$dom.'.gif';
  366:             $is_custom{'domlogo'} = 1;
  367:         }
  368:         if ($designhash{$dom.'.login.img'} ne '') {
  369:             $designs{'img'} = $designhash{$dom.'.login.img'};
  370:             $is_custom{'img'} = 1;
  371:         }
  372:         if ($designhash{$dom.'.login.logo'} ne '') {
  373:             $designs{'logo'} = $designhash{$dom.'.login.logo'};
  374:             $is_custom{'logo'} = 1;
  375:         }
  376:         if ($designhash{$dom.'.login.font'} ne '') {
  377:             $designs{'font'} = $designhash{$dom.'.login.font'};
  378:             $is_custom{'font'} = 1;
  379:         }
  380:         foreach my $item (@bgs) {
  381:             if ($designhash{$dom.'.login.'.$item} ne '') {
  382:                 $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
  383:                 $is_custom{$item} = 1;
  384:             }
  385:         }
  386:         foreach my $item (@links) {
  387:             if ($designhash{$dom.'.login.'.$item} ne '') {
  388:                 $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
  389:                 $is_custom{$item} = 1;
  390:             }
  391:         }
  392:     }
  393:     my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
  394:                                                   logo => 'Institution Logo',
  395:                                                   domlogo => 'Domain Logo');
  396:     my $itemcount = 1;
  397:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
  398:     my $datatable = 
  399:         '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
  400:         '</td><td>'.
  401:         '<nobr><input type="radio" name="coursecatalog"'.
  402:         $catalogon.' value="1" />'.&mt('Yes').'&nbsp;'.
  403:         '<input type="radio" name="coursecatalog"'.
  404:         $catalogoff.'value="0" />'.&mt('No').'</nobr></td>'.
  405:         '</tr>';
  406:     $itemcount ++;
  407:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  408:     $datatable .= '<tr'.$css_class.'>'.
  409:         '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
  410:         '<td><nobr>'.
  411:         '<input type="radio" name="adminmail"'.
  412:         $adminmailon.' value="1" />'.&mt('Yes').'&nbsp;'.
  413:         '<input type="radio" name="adminmail"'.
  414:         $adminmailoff.'value="0" />'.&mt('No').'</nobr></td>';
  415:     $itemcount ++;
  416:     $datatable .= &display_color_options($dom,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
  417:     $datatable .= '</tr></table></td></tr>';
  418:     return $datatable;
  419: }
  420: 
  421: sub login_choices {
  422:     my %choices =
  423:         &Apache::lonlocal::texthash (
  424:             coursecatalog => 'Display Course Catalog link?',
  425:             adminmail => "Display Administrator's E-mail Address?",
  426:             img => "Header",
  427:             logo => "Main Logo",
  428:             domlogo => "Domain Logo",
  429:             bgs => "Background colors",
  430:             links => "Link colors",
  431:             font => "Font color",
  432:             pgbg => "Page",
  433:             mainbg => "Main panel",
  434:             sidebg => "Side panel",
  435:             link => "Link",
  436:             alink => "Active link",
  437:             vlink => "Visited link",
  438:         );
  439:     return %choices;
  440: }
  441: 
  442: sub print_rolecolors {
  443:     my ($phase,$role,$dom,$settings) = @_;
  444:     my %choices = &color_font_choices();
  445:     my @bgs = ('pgbg','tabbg','sidebg');
  446:     my @links = ('link','alink','vlink');
  447:     my @images = ('img');
  448:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
  449:     my %designhash = &Apache::lonnet::get_domainconf($dom);
  450:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  451:     my (%is_custom,%designs);
  452:     my %defaults = (
  453:                    img => $defaultdesign{$role.'.img'},
  454:                    font => $defaultdesign{$role.'.font'},
  455:                    );
  456:     foreach my $item (@bgs) {
  457:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
  458:     }
  459:     foreach my $item (@links) {
  460:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
  461:     }
  462:     if (ref($settings) eq 'HASH') {
  463:         if (ref($settings->{$role}) eq 'HASH') {
  464:             if ($settings->{$role}->{'img'} ne '') {
  465:                 $designs{'img'} = $settings->{$role}->{'img'};
  466:                 $is_custom{'img'} = 1;
  467:             }
  468:             if ($settings->{$role}->{'font'} ne '') {
  469:                 $designs{'font'} = $settings->{$role}->{'font'};
  470:                 $is_custom{'font'} = 1;
  471:             }
  472:             foreach my $item (@bgs) {
  473:                 if ($settings->{$role}->{$item} ne '') {
  474:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
  475:                     $is_custom{$item} = 1;
  476:                 }
  477:             }
  478:             foreach my $item (@links) {
  479:                 if ($settings->{$role}->{$item} ne '') {
  480:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
  481:                     $is_custom{$item} = 1;
  482:                 }
  483:             }
  484:         }
  485:     } else {
  486:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  487:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
  488:             $is_custom{'img'} = 1;
  489:         }
  490:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
  491:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
  492:             $is_custom{'font'} = 1;
  493:         }
  494:         foreach my $item (@bgs) {
  495:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  496:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  497:                 $is_custom{$item} = 1;
  498:             
  499:             }
  500:         }
  501:         foreach my $item (@links) {
  502:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  503:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  504:                 $is_custom{$item} = 1;
  505:             }
  506:         }
  507:     }
  508:     my $itemcount = 1;
  509:     my $datatable = display_color_options($dom,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
  510:     $datatable .= '</tr></table></td></tr>';
  511:     return $datatable;
  512: }
  513: 
  514: sub display_color_options {
  515:     my ($dom,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
  516:         $images,$bgs,$links,$alt_text) = @_;
  517:     my $configuname = $dom.'-domainconfig';
  518:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
  519:     my $datatable = '<tr'.$css_class.'>'.
  520:         '<td>'.$choices->{'font'}.'</td>';
  521:     if (!$is_custom->{'font'}) {
  522:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;'.$defaults->{'font'}.'</td>';
  523:     } else {
  524:         $datatable .= '<td>&nbsp;</td>';
  525:     }
  526:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
  527:     $datatable .= '<td><nobr>'.
  528:                   '<input type="text" size="10" name="'.$role.'_font"'.
  529:                   ' value="'.$designs->{'font'}.'" />&nbsp'.$fontlink.
  530:                   '</nobr></td></tr>';
  531:     foreach my $img (@{$images}) {
  532:         $itemcount ++;
  533:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
  534:         $datatable .= '</tr><tr'.$css_class.'>'.
  535:                       '<td>'.$choices->{$img}.'</td>';
  536:         my $imgfile;
  537:         if ($designs->{$img} ne '') {
  538:             $imgfile = $designs->{$img};
  539:         } else {
  540:             $imgfile = $defaults->{$img};
  541:         }
  542:         if ($imgfile) {
  543:             my $showfile;
  544:             if ($imgfile =~ m-^(/uploaded/\Q$dom\E/\Q$configuname\E/portfolio.*)/([^/]+)$-) {
  545:                 my $urldir = $1;
  546:                 my $filename = $2;
  547:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
  548:                 if (@info) {
  549:                     my $thumbfile = 'tn-'.$filename;
  550:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
  551:                     if (@thumb) {
  552:                         $showfile = $urldir.'/'.$thumbfile;
  553:                     } else {
  554:                         $showfile = $imgfile;
  555:                     }
  556:                 } else {
  557:                     $showfile = '';
  558:                 }
  559:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
  560:                 my $imgdir = $1;
  561:                 my $filename = $2;
  562:                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
  563:                     $showfile = "/$imgdir/tn-".$filename;
  564:                 } else {
  565:                     my $input = "/home/httpd/html".$imgfile;
  566:                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
  567:                     if (!-e $output) {
  568:                         system("convert -sample 200x50 $input $output");
  569:                     }
  570:                     $showfile = '/'.$imgdir.'/tn-'.$filename;
  571:                 }
  572:             } 
  573:             if ($showfile) {
  574:                 $datatable.= '<td>';
  575:                 if (!$is_custom->{$img}) {
  576:                     $datatable .= &mt('Default in use:').'<br />';
  577:                 }
  578:                 $datatable.= '<img src="'.$showfile.'" alt="'.
  579:                              $alt_text->{$img}.'" /></td>';
  580:                 if ($is_custom->{$img}) {
  581:                     $datatable.='<td><nobr><input type="checkbox" name="'.$role.'_del_'.$img.'" value="1">'.
  582:                                 &mt('Delete?').'&nbsp;'.&mt('Replace:').'</nobr><br />';
  583:                 } else {
  584:                     $datatable.='<td valign="bottom">'.&mt('Upload:').'<br />';
  585:                 }
  586:             } else {
  587:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
  588:                               &mt('Upload:');
  589:             }
  590:         } else {
  591:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
  592:                           &mt('Upload:');
  593:         }
  594:         $datatable .= '&nbsp;<input type="file" name="'.$role.'_'.$img.'" /></nobr></td></tr>';
  595:     }
  596:     $itemcount ++;
  597:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  598:     $datatable .= '<tr'.$css_class.'>'.
  599:                   '<td>'.$choices->{'bgs'}.'</td>';
  600:     my $bgs_def;
  601:     foreach my $item (@{$bgs}) {
  602:         if (!$is_custom->{$item}) {
  603:             $bgs_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'bgs'}{$item}.'</td>';
  604:         }
  605:     }
  606:     if ($bgs_def) {
  607:         $datatable .= '<td>'.&mt('Default(s) in use').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
  608:     } else {
  609:         $datatable .= '<td>&nbsp;</td>';
  610:     }
  611:     $datatable .= '<td class="LC_right_item">'.
  612:                   '<table border="0"><tr>';
  613:     foreach my $item (@{$bgs}) {
  614:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
  615:         $datatable .= '<td align="center">'.$link;
  616:         if ($designs->{'bgs'}{$item}) {
  617:             $datatable .= '<span style="background-color:'.$designs->{'bgs'}{$item}.'width: 10px">&nbsp;</span>';
  618:         }
  619:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
  620:                       '" /></td>';
  621:     }
  622:     $datatable .= '</tr></table></td></tr>';
  623:     $itemcount ++;
  624:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  625:     $datatable .= '<tr'.$css_class.'>'.
  626:                   '<td>'.$choices->{'links'}.'</td>';
  627:     my $links_def;
  628:     foreach my $item (@{$links}) {
  629:         if (!$is_custom->{$item}) {
  630:             $links_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'links'}{$item}.'</td>';
  631:         }
  632:     }
  633:     if ($links_def) {
  634:         $datatable .= '<td>'.&mt('Default(s) in use').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
  635:     } else {
  636:         $datatable .= '<td>&nbsp;</td>';
  637:     }
  638:     $datatable .= '<td class="LC_right_item">'.
  639:                   '<table border="0"><tr>';
  640:     foreach my $item (@{$links}) {
  641:         $datatable .= '<td align="center">';
  642:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'links'}{$item});
  643:         if ($designs->{'links'}{$item}) {
  644:             $datatable.='<span style="color: '.$designs->{'links'}{$item}.';">'.
  645:                         $link.'</span>';
  646:         } else {
  647:             $datatable .= $link;
  648:         }
  649:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
  650:                       '" /></td>';
  651:     }
  652:     return $datatable;
  653: }
  654: 
  655: sub color_pick {
  656:     my ($phase,$role,$item,$desc,$curcol) = @_;
  657:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
  658:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
  659:                ');">'.$desc.'</a>';
  660:     return $link;
  661: }
  662: 
  663: sub color_pick_js {
  664:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  665:     my $output = <<"ENDCOL";
  666:     function pclose() {
  667:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
  668:         parmwin.close();
  669:     }
  670: 
  671:     $pjump_def
  672: 
  673:     function psub() {
  674:         pclose();
  675:         if (document.parmform.pres_marker.value!='') {
  676:             if (document.parmform.pres_type.value!='') {
  677:                 eval('document.display.'+
  678:                      document.parmform.pres_marker.value+
  679:                      '.value=document.parmform.pres_value.value;');
  680:             }
  681:         } else {
  682:             document.parmform.pres_value.value='';
  683:             document.parmform.pres_marker.value='';
  684:         }
  685:     }
  686: ENDCOL
  687:     return $output;
  688: }
  689: 
  690: sub print_quotas {
  691:     my ($dom,$settings) = @_;
  692:     my $datatable;
  693:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
  694:     my $othertitle = "All users";
  695:     my @types;
  696:     if (ref($order) eq 'ARRAY') {
  697:         @types = @{$order};
  698:     }
  699:     if (@types == 0) {
  700:         if (ref($usertypes) eq 'HASH') {
  701:             @types = sort(keys(%{$usertypes}));
  702:         }
  703:     }
  704:     my $typecount = 0;
  705:     my $css_class;
  706:     if (@types > 0) {
  707:         foreach my $type (@types) {
  708:             if (defined($usertypes->{$type})) {
  709:                 $typecount ++;
  710:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
  711:                 $datatable .= '<tr'.$css_class.'>'. 
  712:                               '<td>'.$usertypes->{$type}.'</td>'.
  713:                               '<td class="LC_right_item"><nobr>'.
  714:                               '<input type="text" name="quota_'.$type.
  715:                               '" value="'.$settings->{$type}.
  716:                               '" size="5" /> Mb</nobr></td></tr>';
  717:             }
  718:         }
  719:         $othertitle = "Other users";
  720:     }
  721:     my $defaultquota = '20';
  722:     if (ref($settings) eq 'HASH') {
  723:         if (defined($settings->{'default'})) {
  724:             $defaultquota = $settings->{'default'};
  725:         }
  726:     }
  727:     $typecount ++;
  728:     $css_class = $typecount%2?' class="LC_odd_row"':'';
  729:     $datatable .= '<tr'.$css_class.'>'.
  730:                   '<td>'.&mt($othertitle).'</td>'.
  731:                   '<td class="LC_right_item"><nobr>'.
  732:                   '<input type="text" name="default" value="'.
  733:                   $defaultquota.'" size="5" /> Mb</nobr></td></tr>';
  734:     return $datatable;
  735: }
  736: 
  737: sub print_autoenroll {
  738:     my ($dom,$settings) = @_;
  739:     my $defdom = $dom;
  740:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
  741:     my ($runon,$runoff);
  742:     if (ref($settings) eq 'HASH') {
  743:         if (exists($settings->{'run'})) {
  744:             if ($settings->{'run'} eq '0') {
  745:                 $runoff = ' checked="checked" ';
  746:                 $runon = ' ';
  747:             } else {
  748:                 $runon = ' checked="checked" ';
  749:                 $runoff = ' ';
  750:             }
  751:         } else {
  752:             if ($autorun) {
  753:                 $runon = ' checked="checked" ';
  754:                 $runoff = ' ';
  755:             } else {
  756:                 $runoff = ' checked="checked" ';
  757:                 $runon = ' ';
  758:             }
  759:         }
  760:         if (exists($settings->{'sender_domain'})) {
  761:             $defdom = $settings->{'sender_domain'};
  762:         }
  763:     }
  764:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
  765:     my $datatable='<tr class="LC_odd_row">'.
  766:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
  767:                   '<td class="LC_right_item"><nobr>'.
  768:                   '<input type="radio" name="autoenroll_run"'.
  769:                   $runon.' value="1" />'.&mt('Yes').'&nbsp;'.
  770:                   '<input type="radio" name="autoenroll_run"'.
  771:                   $runoff.'value="0" />'.&mt('No').'</nobr></td>'.
  772:                   '</tr><tr>'.
  773:                   '<td>'.&mt('Notification messages - sender').
  774:                   '</td><td class="LC_right_item"><nobr>'.
  775:                   &mt('username').':&nbsp;'.
  776:                   '<input type="text" name="sender_uname" value="'.
  777:                   $settings->{'sender_uname'}.
  778:                   '" size="10" />&nbsp;&nbsp;'.&mt('domain').
  779:                   ':&nbsp;'.$domform.'</nobr></td></tr>';
  780:     return $datatable;
  781: }
  782: 
  783: sub print_autoupdate {
  784:     my ($position,$dom,$settings) = @_;
  785:     my $datatable;
  786:     if ($position eq 'top') {
  787:         my $updateon = ' ';
  788:         my $updateoff = ' checked="checked" ';
  789:         my $classlistson = ' ';
  790:         my $classlistsoff = ' checked="checked" ';
  791:         if (ref($settings) eq 'HASH') {
  792:             if ($settings->{'run'} eq '1') {
  793:                 $updateon = $updateoff;
  794:                 $updateoff = ' ';
  795:             }
  796:             if ($settings->{'classlists'} eq '1') {
  797:                 $classlistson = $classlistsoff;
  798:                 $classlistsoff = ' ';
  799:             }
  800:         }
  801:         my %title = (
  802:                    run => 'Auto-update active?',
  803:                    classlists => 'Update information in classlists?',
  804:                     );
  805:         $datatable = '<tr class="LC_odd_row">'. 
  806:                   '<td>'.&mt($title{'run'}).'</td>'.
  807:                   '<td class="LC_right_item"><nobr>'.
  808:                   '<input type="radio" name="autoupdate_run"'.
  809:                   $updateon.' value="1" />'.&mt('Yes').'&nbsp;'.
  810:                   '<input type="radio" name="autoupdate_run"'.
  811:                   $updateoff.'value="0" />'.&mt('No').'</nobr></td>'.
  812:                   '</tr><tr>'.
  813:                   '<td>'.&mt($title{'classlists'}).'</td>'.
  814:                   '<td class="LC_right_item"><nobr>'.
  815:                   '<input type="radio" name="classlists"'.
  816:                   $classlistson.' value="1" />'.&mt('Yes').'&nbsp;'.
  817:                   '<input type="radio" name="classlists"'.
  818:                   $classlistsoff.'value="0" />'.&mt('No').'</nobr></td>'.
  819:                   '</tr>';
  820:     } else {
  821:         my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
  822:         my @types;
  823:         if (ref($order) eq 'ARRAY') {
  824:             @types = @{$order};
  825:         }
  826:         if (@types == 0) {
  827:             if (ref($usertypes) eq 'HASH') {
  828:                 @types = sort(keys(%{$usertypes}));
  829:             }
  830:         }
  831:         my $othertitle = &mt('All users');
  832:         if (keys(%{$usertypes}) > 0) {
  833:             $othertitle = &mt('Other users');
  834:         }
  835:         my @fields = ('lastname','firstname','middlename','gen','email','id');
  836:         my %fieldtitles = &Apache::lonlocal::texthash (
  837:                             id => 'Student/Employee ID',
  838:                             email => 'E-mail address',
  839:                             lastname => 'Last Name',
  840:                             firstname => 'First Name',
  841:                             middlename => 'Middle Name',
  842:                             gen => 'Generation',
  843:                       );
  844:         my $numrows = 0;
  845:         if (@types > 0) {
  846:             $datatable = 
  847:                 &usertype_update_row($settings,$usertypes,\%fieldtitles,
  848:                                      \@fields,\@types,\$numrows);
  849:         }
  850:         $datatable .= 
  851:             &usertype_update_row($settings,{'default' => $othertitle},
  852:                                  \%fieldtitles,\@fields,['default'],
  853:                                  \$numrows);
  854:     }
  855:     return $datatable;
  856: }
  857: 
  858: sub usertype_update_row {
  859:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
  860:     my $datatable;
  861:     my $numinrow = 4;
  862:     foreach my $type (@{$types}) {
  863:         if (defined($usertypes->{$type})) {
  864:             $$rownums ++;
  865:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
  866:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
  867:                           '</td><td class="LC_left_item"><table>';
  868:             for (my $i=0; $i<@{$fields}; $i++) {
  869:                 my $rem = $i%($numinrow);
  870:                 if ($rem == 0) {
  871:                     if ($i > 0) {
  872:                         $datatable .= '</tr>';
  873:                     }
  874:                     $datatable .= '<tr>';
  875:                 }
  876:                 my $check = ' ';
  877:                 if (ref($settings->{'fields'}) eq 'HASH') {
  878:                     if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
  879:                         if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
  880:                             $check = ' checked="checked" ';
  881:                         }
  882:                     }
  883:                 }
  884: 
  885:                 if ($i == @{$fields}-1) {
  886:                     my $colsleft = $numinrow - $rem;
  887:                     if ($colsleft > 1) {
  888:                         $datatable .= '<td colspan="'.$colsleft.'">';
  889:                     } else {
  890:                         $datatable .= '<td>';
  891:                     }
  892:                 } else {
  893:                     $datatable .= '<td>';
  894:                 }
  895:                 $datatable .= '<nobr><input type="checkbox" name="updateable_'.
  896:                               $type.'_'.$fields->[$i].'" '.
  897:                               '" value="1"'.$check.'/>'.
  898:                               $fieldtitles->{$fields->[$i]}.'</nobr></td>';
  899:             }
  900:             $datatable .= '</tr></table></td></tr>';
  901:         }
  902:     }
  903:     return $datatable;
  904: }
  905: 
  906: sub modify_login {
  907:     my ($r,$dom,%domconfig) = @_;
  908:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
  909:     my %title = ( coursecatalog => 'Display course catalog',
  910:                   adminmail => 'Display administrator E-mail address');
  911:     my @offon = ('off','on');
  912:     my %loginhash;
  913:     ($errors,%colchanges) = &modify_colors($r,$dom,['login'],\%domconfig,
  914:                                           \%loginhash);
  915:     $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
  916:     $loginhash{login}{adminmail} = $env{'form.adminmail'};
  917:     if (ref($colchanges{'login'}) eq 'HASH') {  
  918:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
  919:                                          \%loginhash);
  920:     }
  921:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
  922:                                              $dom);
  923:     if ($putresult eq 'ok') {
  924:         if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
  925:             ($env{'form.coursecatalog'} eq '1')) {
  926:             $changes{'coursecatalog'} = 1;
  927:         } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
  928:                  $domconfig{'login'}{'coursecatalog'} eq '1') &&
  929:                  ($env{'form.coursecatalog'} eq '0')) {
  930:             $changes{'coursecatalog'} = 1;
  931:         }
  932:         if (($domconfig{'login'}{'adminmail'} eq '1') &&
  933:                 ($env{'form.adminmail'} eq '0')) {
  934:             $changes{'adminmail'} = 1;
  935:         } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
  936:                  $domconfig{'login'}{'adminmail'} eq '0') &&
  937:                  ($env{'form.adminmail'} eq '1')) {
  938:             $changes{'adminmail'} = 1;
  939:         }
  940:         if (keys(%changes) > 0 || $colchgtext) {
  941:             $resulttext = &mt('Changes made:').'<ul>';
  942:             foreach my $item (sort(keys(%changes))) {
  943:                 $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
  944:             }
  945:             $resulttext .= $colchgtext.'</ul>';
  946:         } else {
  947:             $resulttext = &mt('No changes made to log-in page settings');
  948:         }
  949:     } else {
  950:         $resulttext = &mt('An error occurred: [_1]',$putresult);
  951:     }
  952:     if ($errors) {
  953:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
  954:                        $errors.'</ul>';
  955:     }
  956:     return $resulttext;
  957: }
  958: 
  959: sub color_font_choices {
  960:     my %choices =
  961:         &Apache::lonlocal::texthash (
  962:             img => "Header",
  963:             bgs => "Background colors",
  964:             links => "Link colors",
  965:             font => "Font color",
  966:             pgbg => "Page",
  967:             tabbg => "Header",
  968:             sidebg => "Border",
  969:             link => "Link",
  970:             alink => "Active link",
  971:             vlink => "Visited link",
  972:         );
  973:     return %choices;
  974: }
  975: 
  976: sub modify_rolecolors {
  977:     my ($r,$dom,$roles,%domconfig) = @_;
  978:     my ($resulttext,%rolehash);
  979:     $rolehash{'rolecolors'} = {};
  980:     my ($errors,%changes) = &modify_colors($r,$dom,$roles,
  981:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
  982:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
  983:                                              $dom);
  984:     if ($putresult eq 'ok') {
  985:         if (keys(%changes) > 0) {
  986:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
  987:                                              $rolehash{'rolecolors'});
  988:         } else {
  989:             $resulttext = &mt('No changes made to default color schemes');
  990:         }
  991:     } else {
  992:         $resulttext = &mt('An error occurred: [_1]',$putresult);
  993:     }
  994:     if ($errors) {
  995:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
  996:                        $errors.'</ul>';
  997:     }
  998:     return $resulttext;
  999: }
 1000: 
 1001: sub modify_colors {
 1002:     my ($r,$dom,$roles,$domconfig,$confhash) = @_;
 1003:     my %changes;
 1004:     my @bgs = ('pgbg','mainbg','sidebg');
 1005:     my @links = ('link','alink','vlink');
 1006:     my @images;
 1007:     my $configuname = $dom.'-domainconfig';
 1008:     my $servadm = $r->dir_config('lonAdmEMail');
 1009:     my $errors;
 1010:     foreach my $role (@{$roles}) {
 1011:         if ($role eq 'login') {
 1012:             @images = ('img','logo','domlogo');
 1013:         } else {
 1014:             @images = ('img');
 1015:         }
 1016:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 1017:         foreach my $item (@bgs,@links) {
 1018:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 1019:         }
 1020:         foreach my $img (@images) { 
 1021:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 1022:                 my $configuserok; 
 1023:                 if (&Apache::lonnet::homeserver($configuname,$dom) eq 'no_host') {
 1024:                     srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 1025:                     my $configpass = &LONCAPA::Enrollment::create_password();
 1026:                     $configuserok = &Apache::lonnet::modifyuser($dom,$configuname,'','internal',$configpass,'','','','','',undef,$servadm);
 1027:                 } else {
 1028:                     $configuserok = 'ok';
 1029:                 }
 1030:                 if ($configuserok eq 'ok') {
 1031:                     my $result = 
 1032:                       &Apache::lonnet::userfileupload($role.'_'.$img,'',
 1033:                         'portfolio/'.$img,'','','',$configuname,$dom,'200','50');
 1034:                     if ($result =~ m|(^/uploaded/.+)/([^/]+)$|) {
 1035:                         my $urldir = $1;
 1036:                         my $filename = $2; 
 1037:                         my $allowresult = &Apache::lonnet::make_public_indefinitely($result);
 1038:                         if ($allowresult eq 'ok') {
 1039:                             &Apache::lonnet::make_public_indefinitely($urldir.'/tn-'.$filename);
 1040:                             $confhash->{$role}{$img} = $result;
 1041:                             $changes{$role}{$img} = 1;
 1042:                         }
 1043:                     }
 1044:                 } else {
 1045:                     my $error = &mt("Upload of image [_1] for $role page(s) failed because a Domain Configuation user ([_2]) could not be created in domain: [_3].  Error was: [_4].",$img,$configuname,$dom,$configuserok);
 1046:                    &Apache::lonnet::logthis($error);
 1047:                    $errors .= '<li>'.$error.'</li>';
 1048:                 }
 1049:             }
 1050:         }
 1051:         if (ref($domconfig) eq 'HASH') {
 1052:             if (ref($domconfig->{$role}) eq 'HASH') {
 1053:                 foreach my $img (@images) {
 1054:                     if ($domconfig->{$role}{$img} ne '') {
 1055:                         if ($env{'form.'.$role.'_del_'.$img}) {
 1056:                             $confhash->{$role}{$img} = '';
 1057:                             $changes{$role}{$img} = 1;
 1058:                         } else {
 1059:                             $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 1060:                         }
 1061:                     } else {
 1062:                         if ($env{'form.'.$role.'_del_'.$img}) {
 1063:                             $confhash->{$role}{$img} = '';
 1064:                             $changes{$role}{$img} = 1;
 1065:                         } 
 1066:                     }
 1067:                 }  
 1068:                 if ($domconfig->{$role}{'font'} ne '') {
 1069:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 1070:                         $changes{$role}{'font'} = 1;
 1071:                     }
 1072:                 } else {
 1073:                     if ($confhash->{$role}{'font'}) {
 1074:                         $changes{$role}{'font'} = 1;
 1075:                     }
 1076:                 }
 1077:                 foreach my $item (@bgs) {
 1078:                     if ($domconfig->{$role}{$item} ne '') {
 1079:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 1080:                             $changes{$role}{'bgs'}{$item} = 1;
 1081:                         } 
 1082:                     } else {
 1083:                         if ($confhash->{$role}{$item}) {
 1084:                             $changes{$role}{'bgs'}{$item} = 1;
 1085:                         }
 1086:                     }
 1087:                 }
 1088:                 foreach my $item (@links) {
 1089:                     if ($domconfig->{$role}{$item} ne '') {
 1090:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 1091:                             $changes{$role}{'links'}{$item} = 1;
 1092:                         }
 1093:                     } else {
 1094:                         if ($confhash->{$role}{$item}) {
 1095:                             $changes{$role}{'links'}{$item} = 1;
 1096:                         }
 1097:                     }
 1098:                 }
 1099:             } else {
 1100:                 &default_change_checker($role,\@images,\@links,\@bgs,
 1101:                                         $confhash,\%changes); 
 1102:             }
 1103:         } else {
 1104:             &default_change_checker($role,\@images,\@links,\@bgs,
 1105:                                     $confhash,\%changes); 
 1106:         }
 1107:     }
 1108:     return ($errors,%changes);
 1109: }
 1110: 
 1111: sub default_change_checker {
 1112:     my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
 1113:     foreach my $item (@{$links}) {
 1114:         if ($confhash->{$role}{$item}) {
 1115:             $changes->{$role}{'links'}{$item} = 1;
 1116:         }
 1117:     }
 1118:     foreach my $item (@{$bgs}) {
 1119:         if ($confhash->{$role}{$item}) {
 1120:             $changes->{$role}{'bgs'}{$item} = 1;
 1121:         }
 1122:     }
 1123:     foreach my $img (@{$images}) {
 1124:         if ($env{'form.'.$role.'_del_'.$img}) {
 1125:             $confhash->{$role}{$img} = '';
 1126:             $changes->{$role}{$img} = 1;
 1127:         }
 1128:     }
 1129:     if ($confhash->{$role}{'font'}) {
 1130:         $changes->{$role}{'font'} = 1;
 1131:     }
 1132: } 
 1133: 
 1134: sub display_colorchgs {
 1135:     my ($dom,$changes,$roles,$confhash) = @_;
 1136:     my (%choices,$resulttext);
 1137:     &Apache::lonnet::devalidate_domconfig_cache($dom);
 1138:     if (!grep(/^login$/,@{$roles})) {
 1139:         $resulttext = &mt('Changes made:').'<br />';
 1140:     }
 1141:     foreach my $role (@{$roles}) {
 1142:         if ($role eq 'login') {
 1143:             %choices = &login_choices();
 1144:         } else {
 1145:             %choices = &color_font_choices();
 1146:         }
 1147:         if (ref($changes->{$role}) eq 'HASH') {
 1148:             if ($role ne 'login') {
 1149:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 1150:             }
 1151:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 1152:                 if ($role ne 'login') {
 1153:                     $resulttext .= '<ul>';
 1154:                 }
 1155:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 1156:                     if ($role ne 'login') {
 1157:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 1158:                     }
 1159:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 1160:                         if ($confhash->{$role}{$item} eq '') {
 1161:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 1162:                         } else {
 1163:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$confhash->{$role}{$item}).'</li>';
 1164:                         }
 1165:                     }
 1166:                     if ($role ne 'login') {
 1167:                         $resulttext .= '</ul></li>';
 1168:                     }
 1169:                 } else {
 1170:                     if ($confhash->{$role}{$key} eq '') {
 1171:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 1172:                     } else {
 1173:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 1174:                     }
 1175:                 }
 1176:                 if ($role ne 'login') {
 1177:                     $resulttext .= '</ul>';
 1178:                 }
 1179:             }
 1180:         }
 1181:     }
 1182:     return $resulttext;
 1183: }
 1184: 
 1185: sub modify_quotas {
 1186:     my ($dom,%domconfig) = @_;
 1187:     my ($resulttext,%changes);
 1188:     my ($usertypes,$order) = 
 1189:         &Apache::lonnet::retrieve_inst_usertypes($dom);
 1190:     my %formhash;
 1191:     foreach my $key (keys(%env)) {
 1192:         if ($key =~ /^form\.quota_(.+)$/) {
 1193:             $formhash{$1} = $env{$key};
 1194:         }
 1195:     }
 1196:     if (ref($domconfig{'quotas'}) eq 'HASH') {
 1197:         foreach my $key (keys(%{$domconfig{'quotas'}})) {
 1198:             if (exists($formhash{$key})) {
 1199:                 if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
 1200:                     $changes{$key} = 1;
 1201:                 }
 1202:             } else {
 1203:                 $formhash{$key} = $domconfig{'quotas'}{$key};
 1204:             }
 1205:         }
 1206:     }
 1207:     foreach my $key (keys(%formhash)) {
 1208:         if ($formhash{$key} ne '') {
 1209:             if (!exists($domconfig{'quotas'}{$key})) {
 1210:                 $changes{$key} = 1;
 1211:             }
 1212:         }
 1213:     }
 1214:     my %quotahash = (
 1215:                       quotas => {%formhash},
 1216:                     );
 1217:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 1218:                                              $dom);
 1219:     if ($putresult eq 'ok') {
 1220:         if (keys(%changes) > 0) {
 1221:             $resulttext = &mt('Changes made:').'<ul>';
 1222:             foreach my $item (sort(keys(%changes))) {
 1223:                 $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'</li>';
 1224:             }
 1225:             $resulttext .= '</ul>';
 1226:         } else {
 1227:             $resulttext = &mt('No changes made to default quotas');
 1228:         }
 1229:     } else {
 1230:         $resulttext = &mt('An error occurred: [_1]',$putresult);
 1231:     }
 1232:     return $resulttext;
 1233: }
 1234: 
 1235: sub modify_autoenroll {
 1236:     my ($dom,%domconfig) = @_;
 1237:     my ($resulttext,%changes);
 1238:     my %currautoenroll;
 1239:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 1240:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 1241:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 1242:         }
 1243:     }
 1244:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 1245:     my %title = ( run => 'Auto-enrollment active',
 1246:                   sender => 'Sender for notification messages');
 1247:     my @offon = ('off','on');
 1248:     my %autoenrollhash =  (
 1249:                        autoenroll => { run => $env{'form.autoenroll_run'},
 1250:                                        sender_uname => $env{'form.sender_uname'},
 1251:                                        sender_domain => $env{'form.sender_domain'},
 1252: 
 1253:                                 }
 1254:                      );
 1255:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 1256:                                              $dom);
 1257:     if ($putresult eq 'ok') {
 1258:         if (exists($currautoenroll{'run'})) {
 1259:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 1260:                  $changes{'run'} = 1;
 1261:              }
 1262:         } elsif ($autorun) {
 1263:             if ($env{'form.autoenroll_run'} ne '1') {
 1264:                 $changes{'run'} = 1;
 1265:             }
 1266:         }
 1267:         if (exists($currautoenroll{sender_uname})) {
 1268:             if ($currautoenroll{'sender_uname'} ne $env{'form.sender_uname'}) {
 1269:                 $changes{'sender'} = 1;
 1270:             }
 1271:         } else {
 1272:             $changes{'sender'} = 1;
 1273:         }
 1274:         if (exists($currautoenroll{sender_domain})) {
 1275:             if ($currautoenroll{'sender_domain'} ne $env{'form.sender_domain'}) {
 1276:                 $changes{'sender'} = 1;
 1277:             }
 1278:         } else {
 1279:             $changes{'sender'} = 1;
 1280:         }
 1281:         if (keys(%changes) > 0) {
 1282:             $resulttext = &mt('Changes made:').'<ul>';
 1283:             if ($changes{'run'}) {
 1284:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 1285:             }
 1286:             if ($changes{'sender'}) {
 1287:                 $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$env{'form.sender_uname'}.':'.$env{'form.sender_domain'}).'</li>';
 1288:             }
 1289:             $resulttext .= '</ul>';
 1290:         } else {
 1291:             $resulttext = &mt('No changes made to auto-enrollment settings');
 1292:         }
 1293:     } else {
 1294:         $resulttext = &mt('An error occurred: [_1]',$putresult);
 1295:     }
 1296:     return $resulttext;
 1297: }
 1298: 
 1299: sub modify_autoupdate {
 1300:     my ($dom,%domconfig) = @_;
 1301:     my ($resulttext,%currautoupdate,%fields,%changes);
 1302:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 1303:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 1304:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 1305:         }
 1306:     }
 1307:     my @offon = ('off','on');
 1308:     my %title = &Apache::lonlocal::texthash (
 1309:                    run => 'Auto-update:',
 1310:                    classlists => 'Updates to user information in classlists?'
 1311:                 );
 1312:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
 1313:     my %fieldtitles = &Apache::lonlocal::texthash (
 1314:                         id => 'Student/Employee ID',
 1315:                         email => 'E-mail address',
 1316:                         lastname => 'Last Name',
 1317:                         firstname => 'First Name',
 1318:                         middlename => 'Middle Name',
 1319:                         gen => 'Generation',
 1320:                       );
 1321:     my $othertitle = &mt('All users');
 1322:     if (keys(%{$usertypes}) >  0) {
 1323:         $othertitle = "Other users";
 1324:     }
 1325:     foreach my $key (keys(%env)) {
 1326:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 1327:             push(@{$fields{$1}},$2);
 1328:         }
 1329:     }
 1330:     my %updatehash = (
 1331:                       autoupdate => { run => $env{'form.autoupdate_run'},
 1332:                                       classlists => $env{'form.classlists'},
 1333:                                       fields => {%fields},
 1334:                                     }
 1335:                      );
 1336:     foreach my $key (keys(%currautoupdate)) {
 1337:         if (($key eq 'run') || ($key eq 'classlists')) {
 1338:             if (exists($updatehash{autoupdate}{$key})) {
 1339:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 1340:                     $changes{$key} = 1;
 1341:                 }
 1342:             }
 1343:         } elsif ($key eq 'fields') {
 1344:             if (ref($currautoupdate{$key}) eq 'HASH') {
 1345:                 foreach my $item (keys(%{$currautoupdate{$key}})) {
 1346:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 1347:                         my $change = 0;
 1348:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 1349:                             if (!exists($fields{$item})) {
 1350:                                 $change = 1;
 1351:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 1352:                                 if (!grep/^\Q$type\E$/,@{$fields{$item}}) {
 1353:                                     $change = 1;
 1354:                                 }
 1355:                             }
 1356:                         }
 1357:                         if ($change) {
 1358:                             push(@{$changes{$key}},$item);
 1359:                         }
 1360:                     }
 1361:                 }
 1362:             }
 1363:         }
 1364:     }
 1365:     foreach my $key (keys(%fields)) {
 1366:         if (ref($currautoupdate{'fields'}) eq 'HASH') {
 1367:             if (!exists($currautoupdate{'fields'}{$key})) {
 1368:                 push(@{$changes{'fields'}},$key);
 1369:             }
 1370:         } else {
 1371:             push(@{$changes{'fields'}},$key);
 1372:         }
 1373:     }
 1374:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 1375:                                              $dom);
 1376:     if ($putresult eq 'ok') {
 1377:         if (keys(%changes) > 0) {
 1378:             $resulttext = &mt('Changes made:').'<ul>';
 1379:             foreach my $key (sort(keys(%changes))) {
 1380:                 if (ref($changes{$key}) eq 'ARRAY') {
 1381:                     foreach my $item (@{$changes{$key}}) {
 1382:                         my @newvalues;
 1383:                         foreach my $type (@{$fields{$item}}) {
 1384:                             push(@newvalues,$fieldtitles{$type});
 1385:                         }
 1386:                         my $newvaluestr;
 1387:                         if (@newvalues > 0) {
 1388:                             $newvaluestr = join(', ',@newvalues);
 1389:                         } else {
 1390:                             $newvaluestr = &mt('none');
 1391:                         }
 1392:                         if ($item eq 'default') {
 1393:                             $resulttext .= '<li>'.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'</li>';
 1394:                         } else {
 1395:                             $resulttext .= '<li>'.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'</li>';
 1396:                         }
 1397:                     }
 1398:                 } else {
 1399:                     my $newvalue;
 1400:                     if ($key eq 'run') {
 1401:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 1402:                     } else {
 1403:                         $newvalue = $offon[$env{'form.'.$key}];
 1404:                     }
 1405:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 1406:                 }
 1407:             }
 1408:             $resulttext .= '</ul>';
 1409:         } else {
 1410:             $resulttext = &mt('No changes made to autoupdates');
 1411:         }
 1412:     } else {
 1413:         $resulttext = &mt('An error occurred: [_1]',$putresult);
 1414:     }
 1415:     return $resulttext;
 1416: }
 1417: 
 1418: 1;
 1419: 

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