File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.41: download - view: text, annotated - select for diffs
Wed Jan 16 20:42:48 2008 UTC (16 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_6_X, version_2_6_3, version_2_6_2, version_2_6_1, HEAD
Bug 5577.

domainprefs.pm
- On log-in page, log-in box can use either an image or text.  DC can choose which of these to use, and override default image and text color and background.
- javascript functions - colchg_span() and get_id() added to support dhtml-driven change of colors in square boxes used for legend for background colors, when new colors are chosen from the color picker
- &Apache::loncommon::devalidate_domconfig_cache() called in more cases when configuration changes have been made for a domain.

lonlogin.pm
- replace html tags for start end end of page with loncommon::start_page() and loncommon::end_page()
- log-in box can use either an image (e.g., userauthentication.gif) or text (configurable by DC via "Domain Configuration")

loncommon.pm
-  &designparm() will retrieve settings for log-in box header on log-in page: image, text color, and background color.
- &endbodytag() can take an optional argument (a ref to a hash) which if key of noredirectlink is true in the hash will suppress display of a 'Continue' link in the case where the $env{'internal.head.redirect'} exists.

default.tab
- new parameters added for default log-in box header - a default image, and default colors for text and background.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.41 2008/01/16 20:42:48 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA#
   23: # /home/httpd/html/adm/gpl.txt
   24: #
   25: # http://www.lon-capa.org/
   26: #
   27: #
   28: ###############################################################
   29: ##############################################################
   30: 
   31: package Apache::domainprefs;
   32: 
   33: use strict;
   34: use Apache::Constants qw(:common :http);
   35: use Apache::lonnet;
   36: use Apache::loncommon();
   37: use Apache::lonhtmlcommon();
   38: use Apache::lonlocal;
   39: use LONCAPA();
   40: use LONCAPA::Enrollment;
   41: use File::Copy;
   42: 
   43: sub handler {
   44:     my $r=shift;
   45:     if ($r->header_only) {
   46:         &Apache::loncommon::content_type($r,'text/html');
   47:         $r->send_http_header;
   48:         return OK;
   49:     }
   50: 
   51:     my $dom = $env{'request.role.domain'};
   52:     my $domdesc = &Apache::lonnet::domain($dom,'description');
   53:     if (&Apache::lonnet::allowed('mau',$dom)) {
   54:         &Apache::loncommon::content_type($r,'text/html');
   55:         $r->send_http_header;
   56:     } else {
   57:         $env{'user.error.msg'}=
   58:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
   59:         return HTTP_NOT_ACCEPTABLE;
   60:     }
   61:     &Apache::lonhtmlcommon::clear_breadcrumbs();
   62:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   63:                                             ['phase']);
   64:     my $phase = 'pickactions';
   65:     if ( exists($env{'form.phase'}) ) {
   66:         $phase = $env{'form.phase'};
   67:     }
   68:     my %domconfig =
   69:       &Apache::lonnet::get_dom('configuration',['login','rolecolors',
   70:                 'quotas','autoenroll','autoupdate','directorysrch',
   71:                 'usercreation','usermodification','contacts'],$dom);
   72:     my @prefs_order = ('rolecolors','login','quotas','autoenroll',
   73:                        'autoupdate','directorysrch','contacts',
   74:                        'usercreation','usermodification');
   75:     my %prefs = (
   76:         'rolecolors' =>
   77:                    { text => 'Default color schemes',
   78:                      help => 'Default_Color_Schemes',
   79:                      header => [{col1 => 'Student Settings',
   80:                                  col2 => '',},
   81:                                 {col1 => 'Coordinator Settings',
   82:                                  col2 => '',},
   83:                                 {col1 => 'Author Settings',
   84:                                  col2 => '',},
   85:                                 {col1 => 'Administrator Settings',
   86:                                  col2 => '',}],
   87:                     },
   88:         'login' =>  
   89:                     { text => 'Log-in page options',
   90:                       help => 'Domain_Log-in_Page',
   91:                       header => [{col1 => 'Item',
   92:                                   col2 => '',}],
   93:                     },
   94:         'quotas' => 
   95:                     { text => 'Default quotas for user portfolios',
   96:                       help => 'Default_User_Quota',
   97:                       header => [{col1 => 'User type',
   98:                                   col2 => 'Default quota'}],
   99:                     },
  100:         'autoenroll' =>
  101:                    { text => 'Auto-enrollment settings',
  102:                      help => 'Domain_Auto_Enrollment',
  103:                      header => [{col1 => 'Configuration setting',
  104:                                  col2 => 'Value(s)'}],
  105:                    },
  106:         'autoupdate' => 
  107:                    { text => 'Auto-update settings',
  108:                      help => 'Domain_Auto_Update',
  109:                      header => [{col1 => 'Setting',
  110:                                  col2 => 'Value',},
  111:                                 {col1 => 'User Population',
  112:                                  col2 => 'Updataeable user data'}],
  113:                   },
  114:         'directorysrch' => 
  115:                   { text => 'Institutional directory searches',
  116:                     help => 'Domain_Directory_Search',
  117:                     header => [{col1 => 'Setting',
  118:                                 col2 => 'Value',}],
  119:                   },
  120:         'contacts' =>
  121:                   { text => 'Contact Information',
  122:                     help => 'Domain_Contact_Information',
  123:                     header => [{col1 => 'Setting',
  124:                                 col2 => 'Value',}],
  125:                   },
  126: 
  127:         'usercreation' => 
  128:                   { text => 'User creation',
  129:                     help => 'Domain_User_Creation',
  130:                     header => [{col1 => 'Format Rule Type',
  131:                                 col2 => 'Format Rules in force'},
  132:                                {col1 => 'User account creation',
  133:                                 col2 => 'Usernames which may be created',},
  134:                                {col1 => 'Context',
  135:                                 col2 => 'Assignable Authentication Types'}],
  136:                   },
  137:         'usermodification' => 
  138:                   { text => 'User modification',
  139:                     help => 'Domain_User_Modification',
  140:                     header => [{col1 => 'Target user has role',
  141:                                 col2 => 'User information updateable in author context'},
  142:                                {col1 => 'Target user has role',
  143:                                 col2 => 'User information updateable in course context'}],
  144:                   },
  145:     );
  146:     my @roles = ('student','coordinator','author','admin');
  147:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  148:     &Apache::lonhtmlcommon::add_breadcrumb
  149:     ({href=>"javascript:changePage(document.$phase,'pickactions')",
  150:       text=>"Pick functionality"});
  151:     my $confname = $dom.'-domainconfig';
  152:     if ($phase eq 'process') {
  153:         &Apache::lonhtmlcommon::add_breadcrumb
  154:           ({href=>"javascript:changePage(document.$phase,'display')",
  155:             text=>"Domain Configuration"},
  156:            {href=>"javascript:changePage(document.$phase,'$phase')",
  157:             text=>"Updated"});
  158:         &print_header($r,$phase);
  159:         foreach my $item (@prefs_order) {
  160:             if (grep(/^\Q$item\E$/,@actions)) {
  161:                 $r->print('<h3>'.&mt($prefs{$item}{'text'}).'</h3>'.
  162:                           &process_changes($r,$dom,$confname,$item,
  163:                           \@roles,%domconfig));
  164:             }
  165:         }
  166:         $r->print('<p>');
  167:         &print_footer($r,$phase,'display','Back to configuration display',
  168:                       \@actions);
  169:         $r->print('</p>');
  170:     } elsif ($phase eq 'display') {
  171:         &Apache::lonhtmlcommon::add_breadcrumb
  172:             ({href=>"javascript:changePage(document.$phase,'display')",
  173:               text=>"Domain Configuration"});
  174:         &print_header($r,$phase);
  175:         if (@actions > 0) {
  176:             my $rowsum = 0;
  177:             my (%output,%rowtotal,@items);
  178:             my $halfway = @actions/2;
  179:             foreach my $item (@prefs_order) {
  180:                 if (grep(/^\Q$item\E$/,@actions)) {
  181:                     push(@items,$item);
  182:                     ($output{$item},$rowtotal{$item}) = 
  183:                         &print_config_box($r,$dom,$confname,$phase,
  184:                                           $item,$prefs{$item},
  185:                                           $domconfig{$item});
  186:                     $rowsum += $rowtotal{$item};
  187:                 }
  188:             }
  189:             my $colend;
  190:             my $halfway = $rowsum/2;
  191:             my $aggregate = 0;
  192:             my $sumleft = 0;
  193:             my $sumright = 0;
  194:             my $crossover;
  195:             for (my $i=0; $i<@items; $i++) {
  196:                 $aggregate += $rowtotal{$items[$i]};
  197:                 if ($aggregate > $halfway) {
  198:                     $crossover = $i;
  199:                     last;
  200:                 }
  201:             }
  202:             for (my $i=0; $i<$crossover; $i++) {
  203:                 $sumleft += $rowtotal{$items[$i]}; 
  204:             }
  205:             for (my $i=$crossover+1; $i<@items; $i++) {
  206:                 $sumright += $rowtotal{$items[$i]};
  207:             }
  208:             if ((@items > 1) && ($env{'form.numcols'} == 2)) {
  209:                 my $sumdiff = $sumright - $sumleft;
  210:                 if ($sumdiff > 0) {
  211:                     $colend = $crossover + 1;
  212:                 } else {
  213:                     $colend = $crossover;
  214:                 }
  215:             } else {
  216:                 $colend = @items;
  217:             }
  218:             $r->print('<p><table class="LC_double_column"><tr><td class="LC_left_col">');
  219:             for (my $i=0; $i<$colend; $i++) {
  220:                 $r->print($output{$items[$i]});
  221:             }
  222:             $r->print('</td><td></td><td class="LC_right_col">');
  223:             if ($colend < @items) {
  224:                 for (my $i=$colend; $i<@items; $i++) { 
  225:                     $r->print($output{$items[$i]});
  226:                 }
  227:             }
  228:             $r->print('</td></tr></table></p>');
  229:             $r->print(&print_footer($r,$phase,'process','Save',\@actions));
  230:         } else {
  231:             $r->print('<input type="hidden" name="phase" value="" />'.
  232:                       '<input type="hidden" name="numcols" value="'.
  233:                       $env{'form.numcols'}.'" />'."\n".
  234:                       '<span clas="LC_error">'.&mt('No settings chosen').
  235:                       '</span>');
  236:         }
  237:         $r->print('</form>');
  238:         $r->print(&Apache::loncommon::end_page());
  239:     } else {
  240:         if ($phase eq '') {
  241:             $phase = 'pickactions';
  242:         }
  243:         my %helphash;
  244:         &print_header($r,$phase);
  245:         if (keys(%domconfig) == 0) {
  246:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
  247:             my @ids=&Apache::lonnet::current_machine_ids();
  248:             if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
  249:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
  250:                 my @loginimages = ('img','logo','domlogo','login');
  251:                 my $custom_img_count = 0;
  252:                 foreach my $img (@loginimages) {
  253:                     if ($designhash{$dom.'.login.'.$img} ne '') {
  254:                         $custom_img_count ++;
  255:                     }
  256:                 }
  257:                 foreach my $role (@roles) {
  258:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  259:                         $custom_img_count ++;
  260:                     }
  261:                 }
  262:                 if ($custom_img_count > 0) {
  263:                     my $switch_server = &check_switchserver($dom,$confname);
  264:                     $r->print(
  265:     &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
  266:     &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
  267:     &mt("Thereafter, (with a Domain Coordinator role selected in the domain) you will be able to update settings when logged in to any server in the LON-CAPA network.").'<br />'.
  268:     &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
  269:                     if ($switch_server) {
  270:                         $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
  271:                     }
  272:                     return OK;
  273:                 }
  274:             }
  275:         }
  276:         $r->print('<h3>'.&mt('Functionality to display/modify').'</h3>');
  277:         $r->print('<script type="text/javascript">'."\n".
  278:               &Apache::loncommon::check_uncheck_jscript()."\n".
  279:               '</script>'."\n".'<p><input type="button" value="check all" '.
  280:               'onclick="javascript:checkAll(document.pickactions.actions)"'.
  281:               ' />&nbsp;&nbsp;'.
  282:               '<input type="button" value="uncheck all" '.
  283:               'onclick="javascript:uncheckAll(document.pickactions.actions)"'.
  284:               ' /></p><div class="LC_left_float">');
  285:         my ($numitems,$midpoint,$seconddiv,$count); 
  286:         $numitems = @prefs_order;
  287:         $midpoint = int($numitems/2);
  288:         if ($numitems%2) {
  289:             $midpoint ++;
  290:         }
  291:         $count = 0;
  292:         foreach my $item (@prefs_order) {
  293:             $r->print('<h4><label><input type="checkbox" name="actions" value="'.$item.'" />&nbsp;'.$prefs{$item}->{'text'}.'</label></h4>');
  294:             $count ++;
  295:             if ((!$seconddiv) && ($count >= $midpoint)) {
  296:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  297:                 $seconddiv = 1;
  298:             }
  299:         }
  300:         $r->print('</div><div class="LC_clear_float_footer"></div><h3>'.
  301:                   &mt('Display options').'</h3>'."\n".
  302:                   '<p><span class="LC_nobreak">'.&mt('Display using: ')."\n".
  303:                   '<label><input type="radio" name="numcols" value="1">'.
  304:                   &mt('one column').'</label>&nbsp;&nbsp;'.
  305:                   '<input type="radio" name="numcols" value="2">'.
  306:                   &mt('two columns').'</label></span></p>');
  307:         $r->print(&print_footer($r,$phase,'display','Go'));
  308:         $r->print('</form>');
  309:         $r->print(&Apache::loncommon::end_page());
  310:     }
  311:     return OK;
  312: }
  313: 
  314: sub process_changes {
  315:     my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
  316:     my $output;
  317:     if ($action eq 'login') {
  318:         $output = &modify_login($r,$dom,$confname,%domconfig);
  319:     } elsif ($action eq 'rolecolors') {
  320:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
  321:                                      %domconfig);
  322:     } elsif ($action eq 'quotas') {
  323:         $output = &modify_quotas($dom,%domconfig);
  324:     } elsif ($action eq 'autoenroll') {
  325:         $output = &modify_autoenroll($dom,%domconfig);
  326:     } elsif ($action eq 'autoupdate') {
  327:         $output = &modify_autoupdate($dom,%domconfig);
  328:     } elsif ($action eq 'directorysrch') {
  329:         $output = &modify_directorysrch($dom,%domconfig);
  330:     } elsif ($action eq 'usercreation') {
  331:         $output = &modify_usercreation($dom,%domconfig);
  332:     } elsif ($action eq 'usermodification') {
  333:         $output = &modify_usermodification($dom,%domconfig);
  334:     } elsif ($action eq 'contacts') {
  335:         $output = &modify_contacts($dom,%domconfig);
  336:     }
  337:     return $output;
  338: }
  339: 
  340: sub print_config_box {
  341:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
  342:     my $rowtotal = 0;
  343:     my $output = 
  344:          '<table class="LC_nested_outer">
  345:           <tr>
  346:            <th align="left"><span class="LC_nobreak">'.&mt($item->{text}).
  347:            '&nbsp;</span></th></tr>';
  348: # 
  349: # FIXME - put the help link back in when the help files exist
  350: #           <th>'.&mt($item->{text}).'&nbsp;'.
  351: #           &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
  352: #          </tr>');
  353:     $rowtotal ++;
  354:     if (($action eq 'autoupdate') || ($action eq 'rolecolors') || 
  355:         ($action eq 'usercreation') || ($action eq 'usermodification')) {
  356:         my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
  357:         $output .= '
  358:           <tr>
  359:            <td>
  360:             <table class="LC_nested">
  361:              <tr class="LC_info_row">
  362:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
  363:               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
  364:              </tr>';
  365:              $rowtotal ++;
  366:         if ($action eq 'autoupdate') {
  367:             $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
  368:         } elsif ($action eq 'usercreation') {
  369:             $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
  370:         } elsif ($action eq 'usermodification') {
  371:             $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
  372:         } else {
  373:             $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
  374:         }
  375:         $output .= '
  376:            </table>
  377:           </td>
  378:          </tr>
  379:          <tr>
  380:            <td>
  381:             <table class="LC_nested">
  382:              <tr class="LC_info_row">
  383:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
  384:               <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
  385:              </tr>';
  386:             $rowtotal ++;
  387:         if ($action eq 'autoupdate') {
  388:             $output .= &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
  389:         } elsif ($action eq 'usercreation') {
  390:             $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
  391:            </table>
  392:           </td>
  393:          </tr>
  394:          <tr>
  395:            <td>
  396:             <table class="LC_nested">
  397:              <tr class="LC_info_row">
  398:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
  399:               <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>             </tr>'.
  400:             &print_usercreation('bottom',$dom,$settings,\$rowtotal);
  401:             $rowtotal ++;
  402:         } elsif ($action eq 'usermodification') {
  403:             $output .= &print_usermodification('bottom',$dom,$settings,\$rowtotal);
  404:         } else {
  405:             $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
  406:            </table>
  407:           </td>
  408:          </tr>
  409:          <tr>
  410:            <td>
  411:             <table class="LC_nested">
  412:              <tr class="LC_info_row">
  413:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
  414:               <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
  415:              </tr>'.
  416:             &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
  417:            </table>
  418:           </td>
  419:          </tr>
  420:          <tr>
  421:            <td>
  422:             <table class="LC_nested">
  423:              <tr class="LC_info_row">
  424:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
  425:               <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
  426:              </tr>'.
  427:             &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
  428:             $rowtotal += 2;
  429:         }
  430:     } else {
  431:         $output .= '
  432:           <tr>
  433:            <td>
  434:             <table class="LC_nested">
  435:              <tr class="LC_info_row">';
  436:         if (($action eq 'login') || ($action eq 'directorysrch')) {
  437:             $output .= '  
  438:               <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>';
  439:         } else {
  440:             $output .= '
  441:               <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>';
  442:         }
  443:         $output .= '
  444:               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
  445:              </tr>';
  446:         $rowtotal ++;      
  447:         if ($action eq 'login') {
  448:             $output .= &print_login($dom,$confname,$phase,$settings,\$rowtotal);
  449:         } elsif ($action eq 'quotas') {
  450:             $output .= &print_quotas($dom,$settings,\$rowtotal);
  451:         } elsif ($action eq 'autoenroll') {
  452:             $output .= &print_autoenroll($dom,$settings,\$rowtotal);
  453:         } elsif ($action eq 'directorysrch') {
  454:             $output .= &print_directorysrch($dom,$settings,\$rowtotal);
  455:         } elsif ($action eq 'contacts') {
  456:             $output .= &print_contacts($dom,$settings,\$rowtotal);
  457:         }
  458:     }
  459:     $output .= '
  460:    </table>
  461:   </td>
  462:  </tr>
  463: </table><br />';
  464:     return ($output,$rowtotal);
  465: }
  466: 
  467: sub print_header {
  468:     my ($r,$phase) = @_;
  469:     my $alert = &mt('You must select at least one functionality type to display.'); 
  470:     my $js = '
  471: <script type="text/javascript">
  472: function changePage(formname,newphase) {
  473:     formname.phase.value = newphase;
  474:     numchecked = 0;
  475:     if (formname == document.pickactions) {
  476:         if (formname.actions.length > 0) {
  477:             for (var i = 0; i <formname.actions.length; i++) {
  478:                 if (formname.actions[i].checked) {
  479:                     numchecked ++;
  480:                 }
  481:             }
  482:         } else {
  483:             if (formname.actions.checked) {
  484:                 numchecked ++;
  485:             }
  486:         }
  487:         if (numchecked > 0) {
  488:             formname.submit();
  489:         } else {
  490:             alert("'.$alert.'");
  491:             return;
  492:         }
  493:     }
  494:     formname.submit();
  495: }'."\n";
  496:     if ($phase eq 'pickactions') {
  497:         $js .= 
  498:             &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox',numcols => 'radio',})."\n".
  499:             &javascript_set_colnums();
  500:     } elsif ($phase eq 'display') {
  501:         $js .= &color_pick_js()."\n";
  502:     }
  503:     $js .= &Apache::loncommon::viewport_size_js().'
  504: </script>
  505: ';
  506:     my $additem;
  507:     if ($phase eq 'pickactions') {
  508:         my %loaditems = (
  509:                     'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);setDisplayColumns();setFormElements(document.pickactions);",
  510:                         );
  511:         $additem = {'add_entries' => \%loaditems,};
  512:     } else {
  513:         my %loaditems = (
  514:                     'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);",
  515:                         );
  516:         $additem = {'add_entries' => \%loaditems,};
  517:     }
  518:     $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
  519:                                            $js,$additem));
  520:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
  521:     $r->print('
  522: <form name="parmform" action="">
  523: <input type="hidden" name="pres_marker" />
  524: <input type="hidden" name="pres_type" />
  525: <input type="hidden" name="pres_value" />
  526: </form>
  527: ');
  528:     $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
  529:               ' enctype="multipart/form-data">');
  530:     return;
  531: }
  532: 
  533: sub print_footer {
  534:     my ($r,$phase,$newphase,$button_text,$actions) = @_;
  535:     $button_text = &mt($button_text);
  536:     $r->print('<input type="hidden" name="phase" value="" />'.
  537:               '<input type="hidden" name="width" value="'.
  538:               $env{'form.width'}.'" />'.
  539:               '<input type="hidden" name="height" value="'.
  540:               $env{'form.height'}.'" />');
  541:     if (($phase eq 'display') || ($phase eq 'process')) {
  542:         if (ref($actions) eq 'ARRAY') {
  543:             foreach my $item (@{$actions}) {
  544:                 $r->print('<input type="hidden" name="actions" value="'.$item.'" />')."\n";
  545:             }
  546:         }
  547:         $r->print('<input type="hidden" name="numcols" value="'.$env{'form.numcols'}.'" />');
  548:     }
  549:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  550:     if ($phase eq 'process') {
  551:         $r->print('<p><a href='.$dest.'>'.$button_text.'</a></p>');
  552:     } else {
  553:         my $onclick;
  554:         if ($phase eq 'display') {
  555:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  556:         } else {
  557:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  558:         } 
  559:         $r->print('<p><input type="button" name="store" value="'.
  560:                   $button_text.'" onclick='.$onclick.' /></p>');
  561:     }
  562:     if ($phase eq 'process') {
  563:         $r->print('</form>'.&Apache::loncommon::end_page());
  564:     }
  565:     return;
  566: }
  567: 
  568: sub print_login {
  569:     my ($dom,$confname,$phase,$settings,$rowtotal) = @_;
  570:     my %choices = &login_choices();
  571:     my ($catalogon,$catalogoff,$adminmailon,$adminmailoff,$loginheader);
  572:     $catalogon = ' checked="checked" ';
  573:     $adminmailoff = ' checked="checked" ';
  574:     $loginheader = 'image';
  575:     my @images = ('img','logo','domlogo','login');
  576:     my @logintext = ('textcol','bgcol');
  577:     my @bgs = ('pgbg','mainbg','sidebg');
  578:     my @links = ('link','alink','vlink');
  579:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  580:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  581:     my (%is_custom,%designs);
  582:     my %defaults = (
  583:                    font => $defaultdesign{'login.font'},
  584:                    );
  585:     foreach my $item (@images) {
  586:         $defaults{$item} = $defaultdesign{'login.'.$item};
  587:     }
  588:     foreach my $item (@bgs) {
  589:         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
  590:     }
  591:     foreach my $item (@logintext) {
  592:         $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
  593:     }
  594:     foreach my $item (@links) {
  595:         $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
  596:     }
  597:     if (ref($settings) eq 'HASH') {
  598:         if ($settings->{'coursecatalog'} eq '0') {
  599:             $catalogoff = $catalogon;
  600:             $catalogon = ' ';
  601:         }
  602:         if ($settings->{'adminmail'} eq '1') {
  603:             $adminmailon = $adminmailoff;
  604:             $adminmailoff = ' ';
  605:         }
  606:         foreach my $item (@images) {
  607:             if ($settings->{$item} ne '') {
  608:                 $designs{$item} = $settings->{$item};
  609:                 $is_custom{$item} = 1;
  610:             }
  611:         }
  612:         foreach my $item (@logintext) {
  613:             if ($settings->{$item} ne '') {
  614:                 $designs{'logintext'}{$item} = $settings->{$item};
  615:                 $is_custom{$item} = 1;
  616:             }
  617:         }
  618:         if ($settings->{'loginheader'} ne '') {
  619:             $loginheader = $settings->{'loginheader'};
  620:         }
  621:         if ($settings->{'font'} ne '') {
  622:             $designs{'font'} = $settings->{'font'};
  623:             $is_custom{'font'} = 1;
  624:         }
  625:         foreach my $item (@bgs) {
  626:             if ($settings->{$item} ne '') {
  627:                 $designs{'bgs'}{$item} = $settings->{$item};
  628:                 $is_custom{$item} = 1;
  629:             }
  630:         }
  631:         foreach my $item (@links) {
  632:             if ($settings->{$item} ne '') {
  633:                 $designs{'links'}{$item} = $settings->{$item};
  634:                 $is_custom{$item} = 1;
  635:             }
  636:         }
  637:     } else {
  638:         if ($designhash{$dom.'.login.font'} ne '') {
  639:             $designs{'font'} = $designhash{$dom.'.login.font'};
  640:             $is_custom{'font'} = 1;
  641:         }
  642:         foreach my $item (@images) {
  643:             if ($designhash{$dom.'.login.'.$item} ne '') {
  644:                 $designs{$item} = $designhash{$dom.'.login.'.$item};
  645:                 $is_custom{$item} = 1;
  646:             }
  647:         }
  648:         foreach my $item (@bgs) {
  649:             if ($designhash{$dom.'.login.'.$item} ne '') {
  650:                 $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
  651:                 $is_custom{$item} = 1;
  652:             }
  653:         }
  654:         foreach my $item (@links) {
  655:             if ($designhash{$dom.'.login.'.$item} ne '') {
  656:                 $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
  657:                 $is_custom{$item} = 1;
  658:             }
  659:         }
  660:     }
  661:     my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
  662:                                                   logo => 'Institution Logo',
  663:                                                   domlogo => 'Domain Logo',
  664:                                                   login => 'Login box');
  665:     my $itemcount = 1;
  666:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
  667:     my $datatable = 
  668:         '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
  669:         '</td><td>'.
  670:         '<span class="LC_nobreak"><label><input type="radio" name="coursecatalog"'.
  671:         $catalogon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  672:         '<label><input type="radio" name="coursecatalog"'.
  673:         $catalogoff.'value="0" />'.&mt('No').'</label></span></td>'.
  674:         '</tr>';
  675:     $itemcount ++;
  676:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  677:     $datatable .= '<tr'.$css_class.'>'.
  678:         '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
  679:         '<td><span class="LC_nobreak">'.
  680:         '<label><input type="radio" name="adminmail"'.
  681:         $adminmailon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  682:         '<label><input type="radio" name="adminmail"'.
  683:         $adminmailoff.'value="0" />'.&mt('No').'</label></span></td></tr>';
  684:     $itemcount ++;
  685:     $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext,$loginheader);
  686:     $datatable .= '</tr></table></td></tr>';
  687:     return $datatable;
  688: }
  689: 
  690: sub login_choices {
  691:     my %choices =
  692:         &Apache::lonlocal::texthash (
  693:             coursecatalog => 'Display Course Catalog link?',
  694:             adminmail => "Display Administrator's E-mail Address?",
  695:             img => "Header",
  696:             logo => "Main Logo",
  697:             domlogo => "Domain Logo",
  698:             login => "Log-in Header", 
  699:             textcol => "Text color",
  700:             bgcol   => "Box color",
  701:             bgs => "Background colors",
  702:             links => "Link colors",
  703:             font => "Font color",
  704:             pgbg => "Page",
  705:             mainbg => "Main panel",
  706:             sidebg => "Side panel",
  707:             link => "Link",
  708:             alink => "Active link",
  709:             vlink => "Visited link",
  710:         );
  711:     return %choices;
  712: }
  713: 
  714: sub print_rolecolors {
  715:     my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
  716:     my %choices = &color_font_choices();
  717:     my @bgs = ('pgbg','tabbg','sidebg');
  718:     my @links = ('link','alink','vlink');
  719:     my @images = ('img');
  720:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
  721:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  722:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  723:     my (%is_custom,%designs);
  724:     my %defaults = (
  725:                    img => $defaultdesign{$role.'.img'},
  726:                    font => $defaultdesign{$role.'.font'},
  727:                    );
  728:     foreach my $item (@bgs) {
  729:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
  730:     }
  731:     foreach my $item (@links) {
  732:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
  733:     }
  734:     if (ref($settings) eq 'HASH') {
  735:         if (ref($settings->{$role}) eq 'HASH') {
  736:             if ($settings->{$role}->{'img'} ne '') {
  737:                 $designs{'img'} = $settings->{$role}->{'img'};
  738:                 $is_custom{'img'} = 1;
  739:             }
  740:             if ($settings->{$role}->{'font'} ne '') {
  741:                 $designs{'font'} = $settings->{$role}->{'font'};
  742:                 $is_custom{'font'} = 1;
  743:             }
  744:             foreach my $item (@bgs) {
  745:                 if ($settings->{$role}->{$item} ne '') {
  746:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
  747:                     $is_custom{$item} = 1;
  748:                 }
  749:             }
  750:             foreach my $item (@links) {
  751:                 if ($settings->{$role}->{$item} ne '') {
  752:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
  753:                     $is_custom{$item} = 1;
  754:                 }
  755:             }
  756:         }
  757:     } else {
  758:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  759:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
  760:             $is_custom{'img'} = 1;
  761:         }
  762:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
  763:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
  764:             $is_custom{'font'} = 1;
  765:         }
  766:         foreach my $item (@bgs) {
  767:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  768:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  769:                 $is_custom{$item} = 1;
  770:             
  771:             }
  772:         }
  773:         foreach my $item (@links) {
  774:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  775:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  776:                 $is_custom{$item} = 1;
  777:             }
  778:         }
  779:     }
  780:     my $itemcount = 1;
  781:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
  782:     $datatable .= '</tr></table></td></tr>';
  783:     return $datatable;
  784: }
  785: 
  786: sub display_color_options {
  787:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
  788:         $images,$bgs,$links,$alt_text,$rowtotal,$logintext,$loginheader) = @_;
  789:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
  790:     my $datatable = '<tr'.$css_class.'>'.
  791:         '<td>'.$choices->{'font'}.'</td>';
  792:     if (!$is_custom->{'font'}) {
  793:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;<span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
  794:     } else {
  795:         $datatable .= '<td>&nbsp;</td>';
  796:     }
  797:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
  798:     $datatable .= '<td><span class="LC_nobreak">'.
  799:                   '<input type="text" size="10" name="'.$role.'_font"'.
  800:                   ' value="'.$designs->{'font'}.'" />&nbsp;'.$fontlink.
  801:                   '&nbsp;<span id="css_'.$role.'_font" style="background-color: '.
  802:                   $designs->{'font'}.';">&nbsp;&nbsp;&nbsp;</span>'.
  803:                   '</span></td></tr>';
  804:     my $switchserver = &check_switchserver($dom,$confname);
  805:     foreach my $img (@{$images}) {
  806: 	$itemcount ++;
  807:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
  808:         $datatable .= '<tr'.$css_class.'>'.
  809:                       '<td>'.$choices->{$img}.'</td>';
  810:         my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
  811:         if ($designs->{$img} ne '') {
  812:             $imgfile = $designs->{$img};
  813: 	    $img_import = ($imgfile =~ m{^/adm/});
  814:         } else {
  815:             $imgfile = $defaults->{$img};
  816:         }
  817:         if ($img eq 'login') {
  818:             $login_hdr_pick = &login_header_options($img,$role,$defaults,$is_custom,$choices,
  819:                                                     $loginheader);
  820:             $logincolors =
  821:                 &login_text_colors($img,$role,$logintext,$phase,$choices,$designs);
  822:         }
  823:         if ($imgfile) {
  824:             my ($showfile,$fullsize);
  825:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
  826:                 my $urldir = $1;
  827:                 my $filename = $2;
  828:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
  829:                 if (@info) {
  830:                     my $thumbfile = 'tn-'.$filename;
  831:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
  832:                     if (@thumb) {
  833:                         $showfile = $urldir.'/'.$thumbfile;
  834:                     } else {
  835:                         $showfile = $imgfile;
  836:                     }
  837:                 } else {
  838:                     $showfile = '';
  839:                 }
  840:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
  841:                 $showfile = $imgfile;
  842:                 my $imgdir = $1;
  843:                 my $filename = $2;
  844:                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
  845:                     $showfile = "/$imgdir/tn-".$filename;
  846:                 } else {
  847:                     my $input = "/home/httpd/html".$imgfile;
  848:                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
  849:                     if (!-e $output) {
  850:                         my ($width,$height) = &thumb_dimensions();
  851:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
  852:                         if ($fullwidth ne '' && $fullheight ne '') {
  853:                             if ($fullwidth > $width && $fullheight > $height) { 
  854:                                 my $size = $width.'x'.$height;
  855:                                 system("convert -sample $size $input $output");
  856:                                 $showfile = '/'.$imgdir.'/tn-'.$filename;
  857:                             }
  858:                         }
  859:                     }
  860:                 }
  861:             }
  862:             if ($showfile) {
  863:                 if ($showfile =~ m{^/(adm|res)/}) {
  864:                     if ($showfile =~ m{^/res/}) {
  865:                         my $local_showfile =
  866:                             &Apache::lonnet::filelocation('',$showfile);
  867:                         &Apache::lonnet::repcopy($local_showfile);
  868:                     }
  869:                     $showfile = &Apache::loncommon::lonhttpdurl($showfile);
  870:                 }
  871:                 if ($imgfile) {
  872:                     if ($imgfile  =~ m{^/(adm|res)/}) {
  873:                         if ($imgfile =~ m{^/res/}) {
  874:                             my $local_imgfile =
  875:                                 &Apache::lonnet::filelocation('',$imgfile);
  876:                             &Apache::lonnet::repcopy($local_imgfile);
  877:                         }
  878:                         $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
  879:                     } else {
  880:                         $fullsize = $imgfile;
  881:                     }
  882:                 }
  883:                 $datatable .= '<td>';
  884:                 if ($img eq 'login') {
  885:                     $datatable .= $login_hdr_pick;    
  886:                 }
  887:                 $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
  888:                                              $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
  889:             } else {
  890:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
  891:                               &mt('Upload:');
  892:             }
  893:         } else {
  894:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
  895:                           &mt('Upload:');
  896:         }
  897:         if ($switchserver) {
  898:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
  899:         } else {
  900:             $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
  901:         }
  902:         $datatable .= '</td></tr>';
  903:     }
  904:     $itemcount ++;
  905:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  906:     $datatable .= '<tr'.$css_class.'>'.
  907:                   '<td>'.$choices->{'bgs'}.'</td>';
  908:     my $bgs_def;
  909:     foreach my $item (@{$bgs}) {
  910:         if (!$is_custom->{$item}) {
  911:             $bgs_def .= '<td>'.$choices->{$item}.'&nbsp;<span id="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span><br />'.$defaults->{'bgs'}{$item}.'</td>';
  912:         }
  913:     }
  914:     if ($bgs_def) {
  915:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
  916:     } else {
  917:         $datatable .= '<td>&nbsp;</td>';
  918:     }
  919:     $datatable .= '<td class="LC_right_item">'.
  920:                   '<table border="0"><tr>';
  921:     foreach my $item (@{$bgs}) {
  922:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
  923:         $datatable .= '<td align="center">'.$link;
  924:         if ($designs->{'bgs'}{$item}) {
  925:             $datatable .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'bgs'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
  926:         }
  927:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
  928:                       '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
  929:     }
  930:     $datatable .= '</tr></table></td></tr>';
  931:     $itemcount ++;
  932:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  933:     $datatable .= '<tr'.$css_class.'>'.
  934:                   '<td>'.$choices->{'links'}.'</td>';
  935:     my $links_def;
  936:     foreach my $item (@{$links}) {
  937:         if (!$is_custom->{$item}) {
  938:             $links_def .= '<td>'.$choices->{$item}.'<br /><span id="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
  939:         }
  940:     }
  941:     if ($links_def) {
  942:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
  943:     } else {
  944:         $datatable .= '<td>&nbsp;</td>';
  945:     }
  946:     $datatable .= '<td class="LC_right_item">'.
  947:                   '<table border="0"><tr>';
  948:     foreach my $item (@{$links}) {
  949:         $datatable .= '<td align="center">'."\n".
  950:                       &color_pick($phase,$role,$item,$choices->{$item},
  951:                                   $designs->{'links'}{$item});
  952:         if ($designs->{'links'}{$item}) {
  953:             $datatable.='&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'links'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
  954:         }
  955:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
  956:                       '" /></td>';
  957:     }
  958:     $$rowtotal += $itemcount;
  959:     return $datatable;
  960: }
  961: 
  962: sub login_header_options  {
  963:     my ($img,$role,$defaults,$is_custom,$choices,$loginheader) = @_;
  964:     my $image_checked = ' checked="checked" ';
  965:     my $text_checked = ' ';
  966:     if ($loginheader eq 'text') {
  967:         $image_checked = ' ';
  968:         $text_checked = ' checked="checked" ';
  969:     }
  970:     my $output = '<span class="LC_nobreak"><label><input type="radio" name="'.
  971:               'loginheader" value="image" '.$image_checked.'/>'.
  972:               &mt('use image').'</label>&nbsp;&nbsp;&nbsp;'.
  973:               '<label><input type="radio" name="loginheader" value="text"'.
  974:               $text_checked.'/>'.&mt('use text').'</label><br />'."\n";
  975:     if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
  976:         $output .= &mt('Text default(s)').':<br />';
  977:         if (!$is_custom->{'textcol'}) {
  978:             $output .= $choices->{'textcol'}.':&nbsp;'.$defaults->{'logintext'}{'textcol'}.
  979:                        '&nbsp;&nbsp;&nbsp;';
  980:         }
  981:         if (!$is_custom->{'bgcol'}) {
  982:             $output .= $choices->{'bgcol'}.':&nbsp;'.
  983:                        '<span id="css_'.$role.'_font" style="background-color: '.
  984:                        $defaults->{'logintext'}{'bgcol'}.';">&nbsp;&nbsp;&nbsp;</span>';
  985:         }
  986:         $output .= '<br />';
  987:     }
  988:     $output .='<br />';
  989:     return $output;
  990: }
  991: 
  992: sub login_text_colors {
  993:     my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
  994:     my $color_menu = '<table border="0"><tr>';
  995:     foreach my $item (@{$logintext}) {
  996:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
  997:         $color_menu .= '<td align="center">'.$link;
  998:         if ($designs->{'logintext'}{$item}) {
  999:             $color_menu .= '&nbsp;<span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';">&nbsp;&nbsp;&nbsp;</span>';
 1000:         }
 1001:         $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
 1002:                        $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
 1003:                        '<td>&nbsp;</td>';
 1004:     }
 1005:     $color_menu .= '</tr></table><br />';
 1006:     return $color_menu;
 1007: }
 1008: 
 1009: sub image_changes {
 1010:     my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
 1011:     my $output;
 1012:     if (!$is_custom) {
 1013:         if ($img eq 'login') {
 1014:             $output .= &mt('Default image:').'<br />';
 1015:         } else {
 1016:             $output .= &mt('Default in use:').'<br />';
 1017:         }
 1018:     }
 1019:     if ($img_import) {
 1020:         $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
 1021:     }
 1022:     $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
 1023:                $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
 1024:     if ($is_custom) {
 1025:         $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
 1026:                    '<input type="checkbox" name="'.
 1027:                    $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
 1028:                    '</label>&nbsp;'.&mt('Replace:').'</span><br />';
 1029:     } else {
 1030:         $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
 1031:     }
 1032:     return $output;
 1033: }
 1034: 
 1035: sub color_pick {
 1036:     my ($phase,$role,$item,$desc,$curcol) = @_;
 1037:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
 1038:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
 1039:                ');">'.$desc.'</a>';
 1040:     return $link;
 1041: }
 1042: 
 1043: sub color_pick_js {
 1044:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
 1045:     my $output = <<"ENDCOL";
 1046:     function pclose() {
 1047:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
 1048:         parmwin.close();
 1049:     }
 1050: 
 1051:     $pjump_def
 1052: 
 1053:     function psub() {
 1054:         pclose();
 1055:         if (document.parmform.pres_marker.value!='') {
 1056:             if (document.parmform.pres_type.value!='') {
 1057:                 eval('document.display.'+
 1058:                      document.parmform.pres_marker.value+
 1059:                      '.value=document.parmform.pres_value.value;');
 1060:             }
 1061:         } else {
 1062:             document.parmform.pres_value.value='';
 1063:             document.parmform.pres_marker.value='';
 1064:         }
 1065:     }
 1066: 
 1067:     function get_id (span_id) {
 1068: 	if (document.getElementById) {
 1069:             return document.getElementById(span_id);
 1070:         }
 1071: 	if (document.all) {
 1072:             return document.all[span_id];
 1073:         } 
 1074: 	return false;
 1075:     }
 1076: 
 1077:     function colchg_span (span_id_str,new_color_item) {
 1078: 	var span_ref = get_id(span_id_str);
 1079: 	if (span_ref.style) { span_ref = span_ref.style; }
 1080: 	span_ref.background = new_color_item.value;
 1081: 	span_ref.backgroundColor = new_color_item.value;
 1082: 	span_ref.bgColor = new_color_item.value;
 1083:     }
 1084: 
 1085: ENDCOL
 1086:     return $output;
 1087: }
 1088: 
 1089: sub print_quotas {
 1090:     my ($dom,$settings,$rowtotal) = @_;
 1091:     my $datatable;
 1092:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
 1093:     my $typecount = 0;
 1094:     my $css_class;
 1095:     if (ref($types) eq 'ARRAY') {
 1096:         foreach my $type (@{$types}) {
 1097:             if (defined($usertypes->{$type})) {
 1098:                 $typecount ++;
 1099:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
 1100:                 $datatable .= '<tr'.$css_class.'>'. 
 1101:                               '<td>'.$usertypes->{$type}.'</td>'.
 1102:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
 1103:                               '<input type="text" name="quota_'.$type.
 1104:                               '" value="'.$settings->{$type}.
 1105:                               '" size="5" /> Mb</span></td></tr>';
 1106:             }
 1107:         }
 1108:     }
 1109:     my $defaultquota = '20';
 1110:     if (ref($settings) eq 'HASH') {
 1111:         if (defined($settings->{'default'})) {
 1112:             $defaultquota = $settings->{'default'};
 1113:         }
 1114:     }
 1115:     $typecount ++;
 1116:     $css_class = $typecount%2?' class="LC_odd_row"':'';
 1117:     $datatable .= '<tr'.$css_class.'>'.
 1118:                   '<td>'.$othertitle.'</td>'.
 1119:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 1120:                   '<input type="text" name="defaultquota" value="'.
 1121:                   $defaultquota.'" size="5" /> Mb</span></td></tr>';
 1122:     $$rowtotal += $typecount;
 1123:     return $datatable;
 1124: }
 1125: 
 1126: sub print_autoenroll {
 1127:     my ($dom,$settings,$rowtotal) = @_;
 1128:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 1129:     my ($defdom,$runon,$runoff);
 1130:     if (ref($settings) eq 'HASH') {
 1131:         if (exists($settings->{'run'})) {
 1132:             if ($settings->{'run'} eq '0') {
 1133:                 $runoff = ' checked="checked" ';
 1134:                 $runon = ' ';
 1135:             } else {
 1136:                 $runon = ' checked="checked" ';
 1137:                 $runoff = ' ';
 1138:             }
 1139:         } else {
 1140:             if ($autorun) {
 1141:                 $runon = ' checked="checked" ';
 1142:                 $runoff = ' ';
 1143:             } else {
 1144:                 $runoff = ' checked="checked" ';
 1145:                 $runon = ' ';
 1146:             }
 1147:         }
 1148:         if (exists($settings->{'sender_domain'})) {
 1149:             $defdom = $settings->{'sender_domain'};
 1150:         }
 1151:     } else {
 1152:         if ($autorun) {
 1153:             $runon = ' checked="checked" ';
 1154:             $runoff = ' ';
 1155:         } else {
 1156:             $runoff = ' checked="checked" ';
 1157:             $runon = ' ';
 1158:         }
 1159:     }
 1160:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
 1161:     my $notif_sender;
 1162:     if (ref($settings) eq 'HASH') {
 1163:         $notif_sender = $settings->{'sender_uname'};
 1164:     }
 1165:     my $datatable='<tr class="LC_odd_row">'.
 1166:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
 1167:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1168:                   '<input type="radio" name="autoenroll_run"'.
 1169:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1170:                   '<label><input type="radio" name="autoenroll_run"'.
 1171:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1172:                   '</tr><tr>'.
 1173:                   '<td>'.&mt('Notification messages - sender').
 1174:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
 1175:                   &mt('username').':&nbsp;'.
 1176:                   '<input type="text" name="sender_uname" value="'.
 1177:                   $notif_sender.'" size="10" />&nbsp;&nbsp;'.&mt('domain').
 1178:                   ':&nbsp;'.$domform.'</span></td></tr>';
 1179:     $$rowtotal += 2;
 1180:     return $datatable;
 1181: }
 1182: 
 1183: sub print_autoupdate {
 1184:     my ($position,$dom,$settings,$rowtotal) = @_;
 1185:     my $datatable;
 1186:     if ($position eq 'top') {
 1187:         my $updateon = ' ';
 1188:         my $updateoff = ' checked="checked" ';
 1189:         my $classlistson = ' ';
 1190:         my $classlistsoff = ' checked="checked" ';
 1191:         if (ref($settings) eq 'HASH') {
 1192:             if ($settings->{'run'} eq '1') {
 1193:                 $updateon = $updateoff;
 1194:                 $updateoff = ' ';
 1195:             }
 1196:             if ($settings->{'classlists'} eq '1') {
 1197:                 $classlistson = $classlistsoff;
 1198:                 $classlistsoff = ' ';
 1199:             }
 1200:         }
 1201:         my %title = (
 1202:                    run => 'Auto-update active?',
 1203:                    classlists => 'Update information in classlists?',
 1204:                     );
 1205:         $datatable = '<tr class="LC_odd_row">'. 
 1206:                   '<td>'.&mt($title{'run'}).'</td>'.
 1207:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1208:                   '<input type="radio" name="autoupdate_run"'.
 1209:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1210:                   '<label><input type="radio" name="autoupdate_run"'.
 1211:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
 1212:                   '</tr><tr>'.
 1213:                   '<td>'.&mt($title{'classlists'}).'</td>'.
 1214:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
 1215:                   '<label><input type="radio" name="classlists"'.
 1216:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1217:                   '<label><input type="radio" name="classlists"'.
 1218:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
 1219:                   '</tr>';
 1220:         $$rowtotal += 2;
 1221:     } else {
 1222:         my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
 1223:         my @fields = ('lastname','firstname','middlename','gen',
 1224:                       'permanentemail','id');
 1225:         my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 1226:         my $numrows = 0;
 1227:         if (ref($types) eq 'ARRAY') {
 1228:             if (@{$types} > 0) {
 1229:                 $datatable = 
 1230:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
 1231:                                          \@fields,$types,\$numrows);
 1232:                     $$rowtotal += @{$types}; 
 1233:             }
 1234:         }
 1235:         $datatable .= 
 1236:             &usertype_update_row($settings,{'default' => $othertitle},
 1237:                                  \%fieldtitles,\@fields,['default'],
 1238:                                  \$numrows);
 1239:         $$rowtotal ++;     
 1240:     }
 1241:     return $datatable;
 1242: }
 1243: 
 1244: sub print_directorysrch {
 1245:     my ($dom,$settings,$rowtotal) = @_;
 1246:     my $srchon = ' ';
 1247:     my $srchoff = ' checked="checked" ';
 1248:     my ($exacton,$containson,$beginson);
 1249:     my $localon = ' ';
 1250:     my $localoff = ' checked="checked" ';
 1251:     if (ref($settings) eq 'HASH') {
 1252:         if ($settings->{'available'} eq '1') {
 1253:             $srchon = $srchoff;
 1254:             $srchoff = ' ';
 1255:         }
 1256:         if ($settings->{'localonly'} eq '1') {
 1257:             $localon = $localoff;
 1258:             $localoff = ' ';
 1259:         }
 1260:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
 1261:             foreach my $type (@{$settings->{'searchtypes'}}) {
 1262:                 if ($type eq 'exact') {
 1263:                     $exacton = ' checked="checked" ';
 1264:                 } elsif ($type eq 'contains') {
 1265:                     $containson = ' checked="checked" ';
 1266:                 } elsif ($type eq 'begins') {
 1267:                     $beginson = ' checked="checked" ';
 1268:                 }
 1269:             }
 1270:         } else {
 1271:             if ($settings->{'searchtypes'} eq 'exact') {
 1272:                 $exacton = ' checked="checked" ';
 1273:             } elsif ($settings->{'searchtypes'} eq 'contains') {
 1274:                 $containson = ' checked="checked" ';
 1275:             } elsif ($settings->{'searchtypes'} eq 'specify') {
 1276:                 $exacton = ' checked="checked" ';
 1277:                 $containson = ' checked="checked" ';
 1278:             }
 1279:         }
 1280:     }
 1281:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
 1282:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
 1283: 
 1284:     my $numinrow = 4;
 1285:     my $cansrchrow = 0;
 1286:     my $datatable='<tr class="LC_odd_row">'.
 1287:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
 1288:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1289:                   '<input type="radio" name="dirsrch_available"'.
 1290:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
 1291:                   '<label><input type="radio" name="dirsrch_available"'.
 1292:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
 1293:                   '</tr><tr>'.
 1294:                   '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
 1295:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
 1296:                   '<input type="radio" name="dirsrch_localonly"'.
 1297:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
 1298:                   '<label><input type="radio" name="dirsrch_localonly"'.
 1299:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
 1300:                   '</tr>';
 1301:     $$rowtotal += 2;
 1302:     if (ref($usertypes) eq 'HASH') {
 1303:         if (keys(%{$usertypes}) > 0) {
 1304:             $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
 1305:                                                $numinrow,$othertitle);
 1306:             $cansrchrow = 1;
 1307:         }
 1308:     }
 1309:     if ($cansrchrow) {
 1310:         $$rowtotal ++;
 1311:         $datatable .= '<tr>';
 1312:     } else {
 1313:         $datatable .= '<tr class="LC_odd_row">';
 1314:     }
 1315:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
 1316:                   '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
 1317:     foreach my $title (@{$titleorder}) {
 1318:         if (defined($searchtitles->{$title})) {
 1319:             my $check = ' ';
 1320:             if (ref($settings) eq 'HASH') { 
 1321:                 if (ref($settings->{'searchby'}) eq 'ARRAY') {
 1322:                     if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
 1323:                         $check = ' checked="checked" ';
 1324:                     }
 1325:                 }
 1326:             }
 1327:             $datatable .= '<td class="LC_left_item">'.
 1328:                           '<span class="LC_nobreak"><label>'.
 1329:                           '<input type="checkbox" name="searchby" '.
 1330:                           'value="'.$title.'"'.$check.'/>'.
 1331:                           $searchtitles->{$title}.'</label></span></td>';
 1332:         }
 1333:     }
 1334:     $datatable .= '</tr></table></td></tr>';
 1335:     $$rowtotal ++;
 1336:     if ($cansrchrow) {
 1337:         $datatable .= '<tr class="LC_odd_row">';
 1338:     } else {
 1339:         $datatable .= '<tr>';
 1340:     }
 1341:     $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.   
 1342:                   '<td class="LC_left_item" colspan="2">'.
 1343:                   '<span class="LC_nobreak"><label>'.
 1344:                   '<input type="checkbox" name="searchtypes" '.
 1345:                   $exacton.' value="exact" />'.&mt('Exact match').
 1346:                   '</label>&nbsp;'.
 1347:                   '<label><input type="checkbox" name="searchtypes" '.
 1348:                   $beginson.' value="begins" />'.&mt('Begins with').
 1349:                   '</label>&nbsp;'.
 1350:                   '<label><input type="checkbox" name="searchtypes" '.
 1351:                   $containson.' value="contains" />'.&mt('Contains').
 1352:                   '</label></span></td></tr>';
 1353:     $$rowtotal ++;
 1354:     return $datatable;
 1355: }
 1356: 
 1357: sub print_contacts {
 1358:     my ($dom,$settings,$rowtotal) = @_;
 1359:     my $datatable;
 1360:     my @contacts = ('adminemail','supportemail');
 1361:     my (%checked,%to,%otheremails);
 1362:     my @mailings = ('errormail','packagesmail','helpdeskmail');
 1363:     foreach my $type (@mailings) {
 1364:         $otheremails{$type} = '';
 1365:     }
 1366:     if (ref($settings) eq 'HASH') {
 1367:         foreach my $item (@contacts) {
 1368:             if (exists($settings->{$item})) {
 1369:                 $to{$item} = $settings->{$item};
 1370:             }
 1371:         }
 1372:         foreach my $type (@mailings) {
 1373:             if (exists($settings->{$type})) {
 1374:                 if (ref($settings->{$type}) eq 'HASH') {
 1375:                     foreach my $item (@contacts) {
 1376:                         if ($settings->{$type}{$item}) {
 1377:                             $checked{$type}{$item} = ' checked="checked" ';
 1378:                         }
 1379:                     }
 1380:                     $otheremails{$type} = $settings->{$type}{'others'};
 1381:                 }
 1382:             }
 1383:         }
 1384:     } else {
 1385:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 1386:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 1387:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
 1388:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
 1389:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" '; 
 1390:     }
 1391:     my ($titles,$short_titles) = &contact_titles();
 1392:     my $rownum = 0;
 1393:     my $css_class;
 1394:     foreach my $item (@contacts) {
 1395:         if ($rownum%2) {
 1396:             $css_class = '';
 1397:         } else {
 1398:             $css_class = ' class="LC_odd_row" ';
 1399:         }
 1400:         $datatable .= '<tr'.$css_class.'>'. 
 1401:                   '<td><span class="LC_nobreak">'.$titles->{$item}.
 1402:                   '</span></td><td class="LC_right_item">'.
 1403:                   '<input type="text" name="'.$item.'" value="'.
 1404:                   $to{$item}.'" /></td></tr>';
 1405:         $rownum ++;
 1406:     }
 1407:     foreach my $type (@mailings) {
 1408:         if ($rownum%2) {
 1409:             $css_class = '';
 1410:         } else {
 1411:             $css_class = ' class="LC_odd_row" ';
 1412:         }
 1413:         $datatable .= '<tr'.$css_class.'>'.
 1414:                       '<td><span class="LC_nobreak">'.
 1415:                       $titles->{$type}.': </span></td>'.
 1416:                       '<td class="LC_left_item">'.
 1417:                       '<span class="LC_nobreak">';
 1418:         foreach my $item (@contacts) {
 1419:             $datatable .= '<label>'.
 1420:                           '<input type="checkbox" name="'.$type.'"'.
 1421:                           $checked{$type}{$item}.
 1422:                           ' value="'.$item.'" />'.$short_titles->{$item}.
 1423:                           '</label>&nbsp;';
 1424:         }
 1425:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
 1426:                       '<input type="text" name="'.$type.'_others" '.
 1427:                       'value="'.$otheremails{$type}.'"  />'.
 1428:                       '</td></tr>'."\n";
 1429:         $rownum ++;
 1430:     }
 1431:     $$rowtotal += $rownum;
 1432:     return $datatable;
 1433: }
 1434: 
 1435: sub contact_titles {
 1436:     my %titles = &Apache::lonlocal::texthash (
 1437:                    'supportemail' => 'Support E-mail address',
 1438:                    'adminemail'    => 'Default Server Admin E-mail address',
 1439:                    'errormail'    => 'Error reports to be e-mailed to',
 1440:                    'packagesmail' => 'Package update alerts to be e-mailed to',
 1441:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
 1442:                  );
 1443:     my %short_titles = &Apache::lonlocal::texthash (
 1444:                            adminemail   => 'Admin E-mail address',
 1445:                            supportemail => 'Support E-mail',
 1446:                        );   
 1447:     return (\%titles,\%short_titles);
 1448: }
 1449: 
 1450: sub print_usercreation {
 1451:     my ($position,$dom,$settings,$rowtotal) = @_;
 1452:     my $numinrow = 4;
 1453:     my $datatable;
 1454:     if ($position eq 'top') {
 1455:         $$rowtotal ++;
 1456:         my $rowcount = 0;
 1457:         my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
 1458:         if (ref($rules) eq 'HASH') {
 1459:             if (keys(%{$rules}) > 0) {
 1460:                 $datatable .= &user_formats_row('username',$settings,$rules,
 1461:                                                 $ruleorder,$numinrow,$rowcount);
 1462:                 $$rowtotal ++;
 1463:                 $rowcount ++;
 1464:             }
 1465:         }
 1466:         my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
 1467:         if (ref($idrules) eq 'HASH') {
 1468:             if (keys(%{$idrules}) > 0) {
 1469:                 $datatable .= &user_formats_row('id',$settings,$idrules,
 1470:                                                 $idruleorder,$numinrow,$rowcount);
 1471:                 $$rowtotal ++;
 1472:                 $rowcount ++;
 1473:             }
 1474:         }
 1475:         if ($rowcount == 0) {
 1476:             $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';  
 1477:             $$rowtotal ++;
 1478:             $rowcount ++;
 1479:         }
 1480:     } elsif ($position eq 'middle') {
 1481:         my @creators = ('author','course');
 1482:         my ($rules,$ruleorder) =
 1483:             &Apache::lonnet::inst_userrules($dom,'username');
 1484:         my %lt = &usercreation_types();
 1485:         my %checked;
 1486:         if (ref($settings) eq 'HASH') {
 1487:             if (ref($settings->{'cancreate'}) eq 'HASH') {
 1488:                 foreach my $item (@creators) {
 1489:                     $checked{$item} = $settings->{'cancreate'}{$item};
 1490:                 }
 1491:             } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
 1492:                 foreach my $item (@creators) {
 1493:                     if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
 1494:                         $checked{$item} = 'none';
 1495:                     }
 1496:                 }
 1497:             }
 1498:         }
 1499:         my $rownum = 0;
 1500:         foreach my $item (@creators) {
 1501:             $rownum ++;
 1502:             if ($checked{$item} eq '') {
 1503:                 $checked{$item} = 'any';
 1504:             }
 1505:             my $css_class;
 1506:             if ($rownum%2) {
 1507:                 $css_class = '';
 1508:             } else {
 1509:                 $css_class = ' class="LC_odd_row" ';
 1510:             }
 1511:             $datatable .= '<tr'.$css_class.'>'.
 1512:                          '<td><span class="LC_nobreak">'.$lt{$item}.
 1513:                          '</span></td><td align="right">';
 1514:             my @options = ('any');
 1515:             if (ref($rules) eq 'HASH') {
 1516:                 if (keys(%{$rules}) > 0) {
 1517:                     push(@options,('official','unofficial'));
 1518:                 }
 1519:             }
 1520:             push(@options,'none');
 1521:             foreach my $option (@options) {
 1522:                 my $check = ' ';
 1523:                 if ($checked{$item} eq $option) {
 1524:                     $check = ' checked="checked" ';
 1525:                 } 
 1526:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1527:                               '<input type="radio" name="can_createuser_'.
 1528:                               $item.'" value="'.$option.'"'.$check.'/>&nbsp;'.
 1529:                               $lt{$option}.'</label>&nbsp;&nbsp;</span>';
 1530:             }
 1531:             $datatable .= '</td></tr>';
 1532:         }
 1533:     } else {
 1534:         my @contexts = ('author','course','domain');
 1535:         my @authtypes = ('int','krb4','krb5','loc');
 1536:         my %checked;
 1537:         if (ref($settings) eq 'HASH') {
 1538:             if (ref($settings->{'authtypes'}) eq 'HASH') {
 1539:                 foreach my $item (@contexts) {
 1540:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
 1541:                         foreach my $auth (@authtypes) {
 1542:                             if ($settings->{'authtypes'}{$item}{$auth}) {
 1543:                                 $checked{$item}{$auth} = ' checked="checked" ';
 1544:                             }
 1545:                         }
 1546:                     }
 1547:                 }
 1548:             }
 1549:         } else {
 1550:             foreach my $item (@contexts) {
 1551:                 foreach my $auth (@authtypes) {
 1552:                     $checked{$item}{$auth} = ' checked="checked" ';
 1553:                 }
 1554:             }
 1555:         }
 1556:         my %title = &context_names();
 1557:         my %authname = &authtype_names();
 1558:         my $rownum = 0;
 1559:         my $css_class; 
 1560:         foreach my $item (@contexts) {
 1561:             if ($rownum%2) {
 1562:                 $css_class = '';
 1563:             } else {
 1564:                 $css_class = ' class="LC_odd_row" ';
 1565:             }
 1566:             $datatable .=   '<tr'.$css_class.'>'.
 1567:                             '<td>'.$title{$item}.
 1568:                             '</td><td class="LC_left_item">'.
 1569:                             '<span class="LC_nobreak">';
 1570:             foreach my $auth (@authtypes) {
 1571:                 $datatable .= '<label>'. 
 1572:                               '<input type="checkbox" name="'.$item.'_auth" '.
 1573:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
 1574:                               $authname{$auth}.'</label>&nbsp;';
 1575:             }
 1576:             $datatable .= '</span></td></tr>';
 1577:             $rownum ++;
 1578:         }
 1579:         $$rowtotal += $rownum;
 1580:     }
 1581:     return $datatable;
 1582: }
 1583: 
 1584: sub user_formats_row {
 1585:     my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
 1586:     my $output;
 1587:     my %text = (
 1588:                    'username' => 'new usernames',
 1589:                    'id'       => 'IDs',
 1590:                );
 1591:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 1592:     $output = '<tr '.$css_class.'>'.
 1593:               '<td><span class="LC_nobreak">'.
 1594:               &mt("Format rules to check for $text{$type}: ").
 1595:               '</span></td>'.
 1596:               '<td class="LC_left_item" colspan="2"><table>';
 1597:     my $rem;
 1598:     if (ref($ruleorder) eq 'ARRAY') {
 1599:         for (my $i=0; $i<@{$ruleorder}; $i++) {
 1600:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
 1601:                 my $rem = $i%($numinrow);
 1602:                 if ($rem == 0) {
 1603:                     if ($i > 0) {
 1604:                         $output .= '</tr>';
 1605:                     }
 1606:                     $output .= '<tr>';
 1607:                 }
 1608:                 my $check = ' ';
 1609:                 if (ref($settings) eq 'HASH') {
 1610:                     if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
 1611:                         if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
 1612:                             $check = ' checked="checked" ';
 1613:                         }
 1614:                     }
 1615:                 }
 1616:                 $output .= '<td class="LC_left_item">'.
 1617:                            '<span class="LC_nobreak"><label>'.
 1618:                            '<input type="checkbox" name="'.$type.'_rule" '.
 1619:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
 1620:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
 1621:             }
 1622:         }
 1623:         $rem = @{$ruleorder}%($numinrow);
 1624:     }
 1625:     my $colsleft = $numinrow - $rem;
 1626:     if ($colsleft > 1 ) {
 1627:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 1628:                    '&nbsp;</td>';
 1629:     } elsif ($colsleft == 1) {
 1630:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 1631:     }
 1632:     $output .= '</tr></table></td></tr>';
 1633:     return $output;
 1634: }
 1635: 
 1636: sub usercreation_types {
 1637:     my %lt = &Apache::lonlocal::texthash (
 1638:                     author     => 'When adding a co-author',
 1639:                     course     => 'When adding a user to a course',
 1640:                     any        => 'Any',
 1641:                     official   => 'Institutional only ',
 1642:                     unofficial => 'Non-institutional only',
 1643:                     none       => 'None',
 1644:     );
 1645:     return %lt;
 1646: } 
 1647: 
 1648: sub authtype_names {
 1649:     my %lt = &Apache::lonlocal::texthash(
 1650:                       int    => 'Internal',
 1651:                       krb4   => 'Kerberos 4',
 1652:                       krb5   => 'Kerberos 5',
 1653:                       loc    => 'Local',
 1654:                   );
 1655:     return %lt;
 1656: }
 1657: 
 1658: sub context_names {
 1659:     my %context_title = &Apache::lonlocal::texthash(
 1660:        author => 'Creating users when an Author',
 1661:        course => 'Creating users when in a course',
 1662:        domain => 'Creating users when a Domain Coordinator',
 1663:     );
 1664:     return %context_title;
 1665: }
 1666: 
 1667: sub print_usermodification {
 1668:     my ($position,$dom,$settings,$rowtotal) = @_;
 1669:     my $numinrow = 4;
 1670:     my ($context,$datatable,$rowcount);
 1671:     if ($position eq 'top') {
 1672:         $rowcount = 0;
 1673:         $context = 'author'; 
 1674:         foreach my $role ('ca','aa') {
 1675:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 1676:                                                    $numinrow,$rowcount);
 1677:             $$rowtotal ++;
 1678:             $rowcount ++;
 1679:         }
 1680:     } else {
 1681:         $context = 'course';
 1682:         $rowcount = 0;
 1683:         foreach my $role ('st','ep','ta','in','cr') {
 1684:             $datatable .= &modifiable_userdata_row($context,$role,$settings,
 1685:                                                    $numinrow,$rowcount);
 1686:             $$rowtotal ++;
 1687:             $rowcount ++;
 1688:         }
 1689:     }
 1690:     return $datatable;
 1691: }
 1692: 
 1693: sub modifiable_userdata_row {
 1694:     my ($context,$role,$settings,$numinrow,$rowcount) = @_;
 1695:     my $rolename;
 1696:     if ($role eq 'cr') {
 1697:         $rolename = &mt('Custom role');
 1698:     } else {
 1699:         $rolename = &Apache::lonnet::plaintext($role);
 1700:     }
 1701:     my @fields = ('lastname','firstname','middlename','generation',
 1702:                   'permanentemail','id');
 1703:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 1704:     my $output;
 1705:     my $css_class = $rowcount%2?' class="LC_odd_row"':'';
 1706:     $output = '<tr '.$css_class.'>'.
 1707:               '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
 1708:               '<td class="LC_left_item" colspan="2"><table>';
 1709:     my $rem;
 1710:     my %checks;
 1711:     if (ref($settings) eq 'HASH') {
 1712:         if (ref($settings->{$context}) eq 'HASH') {
 1713:             if (ref($settings->{$context}->{$role}) eq 'HASH') {
 1714:                 foreach my $field (@fields) {
 1715:                     if ($settings->{$context}->{$role}->{$field}) {
 1716:                         $checks{$field} = ' checked="checked" ';
 1717:                     }
 1718:                 }
 1719:             }
 1720:         }
 1721:     }
 1722:     for (my $i=0; $i<@fields; $i++) {
 1723:         my $rem = $i%($numinrow);
 1724:         if ($rem == 0) {
 1725:             if ($i > 0) {
 1726:                 $output .= '</tr>';
 1727:             }
 1728:             $output .= '<tr>';
 1729:         }
 1730:         my $check = ' ';
 1731:         if (exists($checks{$fields[$i]})) {
 1732:             $check = $checks{$fields[$i]}
 1733:         } else {
 1734:             if ($role eq 'st') {
 1735:                 if (ref($settings) ne 'HASH') {
 1736:                     $check = ' checked="checked" '; 
 1737:                 }
 1738:             }
 1739:         }
 1740:         $output .= '<td class="LC_left_item">'.
 1741:                    '<span class="LC_nobreak"><label>'.
 1742:                    '<input type="checkbox" name="canmodify_'.$role.'" '.
 1743:                    'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
 1744:                    '</label></span></td>';
 1745:         $rem = @fields%($numinrow);
 1746:     }
 1747:     my $colsleft = $numinrow - $rem;
 1748:     if ($colsleft > 1 ) {
 1749:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 1750:                    '&nbsp;</td>';
 1751:     } elsif ($colsleft == 1) {
 1752:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 1753:     }
 1754:     $output .= '</tr></table></td></tr>';
 1755:     return $output;
 1756: }
 1757: 
 1758: sub users_cansearch_row {
 1759:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
 1760:     my $output =  '<tr class="LC_odd_row">'.
 1761:                   '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
 1762:                   '</td><td class="LC_left_item" colspan="2"><table>';
 1763:     my $rem;
 1764:     if (ref($types) eq 'ARRAY') {
 1765:         for (my $i=0; $i<@{$types}; $i++) {
 1766:             if (defined($usertypes->{$types->[$i]})) {
 1767:                 my $rem = $i%($numinrow);
 1768:                 if ($rem == 0) {
 1769:                     if ($i > 0) {
 1770:                         $output .= '</tr>';
 1771:                     }
 1772:                     $output .= '<tr>';
 1773:                 }
 1774:                 my $check = ' ';
 1775:                 if (ref($settings->{'cansearch'}) eq 'ARRAY') {
 1776:                     if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
 1777:                         $check = ' checked="checked" ';
 1778:                     }
 1779:                 }
 1780:                 $output .= '<td class="LC_left_item">'.
 1781:                            '<span class="LC_nobreak"><label>'.
 1782:                            '<input type="checkbox" name="cansearch" '.
 1783:                            'value="'.$types->[$i].'"'.$check.'/>'.
 1784:                            $usertypes->{$types->[$i]}.'</label></span></td>';
 1785:             }
 1786:         }
 1787:        
 1788:         $rem = @{$types}%($numinrow);
 1789:     }
 1790:     my $colsleft = $numinrow - $rem;
 1791:     if ($colsleft > 1) {
 1792:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 1793:     } else {
 1794:         $output .= '<td class="LC_left_item">';
 1795:     }
 1796:     my $defcheck = ' ';
 1797:     if (ref($settings->{'cansearch'}) eq 'ARRAY') {
 1798:         if (grep(/^default$/,@{$settings->{'cansearch'}})) {
 1799:             $defcheck = ' checked="checked" ';
 1800:         }
 1801:     }
 1802:     $output .= '<span class="LC_nobreak"><label>'.
 1803:                '<input type="checkbox" name="cansearch" '.
 1804:                'value="default"'.$defcheck.'/>'.
 1805:                $othertitle.'</label></span></td>'.
 1806:                '</tr></table></td></tr>';
 1807:     return $output;
 1808: }
 1809: 
 1810: sub sorted_inst_types {
 1811:     my ($dom) = @_;
 1812:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
 1813:     my $othertitle = &mt('All users');
 1814:     my @types;
 1815:     if (ref($order) eq 'ARRAY') {
 1816:         @types = @{$order};
 1817:     }
 1818:     if (@types == 0) {
 1819:         if (ref($usertypes) eq 'HASH') {
 1820:             @types = sort(keys(%{$usertypes}));
 1821:         }
 1822:     }
 1823:     if (keys(%{$usertypes}) > 0) {
 1824:         $othertitle = &mt('Other users');
 1825:     }
 1826:     return ($othertitle,$usertypes,\@types);
 1827: }
 1828: 
 1829: sub sorted_searchtitles {
 1830:     my %searchtitles = &Apache::lonlocal::texthash(
 1831:                          'uname' => 'username',
 1832:                          'lastname' => 'last name',
 1833:                          'lastfirst' => 'last name, first name',
 1834:                      );
 1835:     my @titleorder = ('uname','lastname','lastfirst');
 1836:     return (\%searchtitles,\@titleorder);
 1837: }
 1838: 
 1839: sub sorted_searchtypes {
 1840:     my %srchtypes_desc = (
 1841:                            exact    => 'is exact match',
 1842:                            contains => 'contains ..',
 1843:                            begins   => 'begins with ..',
 1844:                          );
 1845:     my @srchtypeorder = ('exact','begins','contains');
 1846:     return (\%srchtypes_desc,\@srchtypeorder);
 1847: }
 1848: 
 1849: sub usertype_update_row {
 1850:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
 1851:     my $datatable;
 1852:     my $numinrow = 4;
 1853:     foreach my $type (@{$types}) {
 1854:         if (defined($usertypes->{$type})) {
 1855:             $$rownums ++;
 1856:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
 1857:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
 1858:                           '</td><td class="LC_left_item"><table>';
 1859:             for (my $i=0; $i<@{$fields}; $i++) {
 1860:                 my $rem = $i%($numinrow);
 1861:                 if ($rem == 0) {
 1862:                     if ($i > 0) {
 1863:                         $datatable .= '</tr>';
 1864:                     }
 1865:                     $datatable .= '<tr>';
 1866:                 }
 1867:                 my $check = ' ';
 1868:                 if (ref($settings) eq 'HASH') {
 1869:                     if (ref($settings->{'fields'}) eq 'HASH') {
 1870:                         if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
 1871:                             if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
 1872:                                 $check = ' checked="checked" ';
 1873:                             }
 1874:                         }
 1875:                     }
 1876:                 }
 1877: 
 1878:                 if ($i == @{$fields}-1) {
 1879:                     my $colsleft = $numinrow - $rem;
 1880:                     if ($colsleft > 1) {
 1881:                         $datatable .= '<td colspan="'.$colsleft.'">';
 1882:                     } else {
 1883:                         $datatable .= '<td>';
 1884:                     }
 1885:                 } else {
 1886:                     $datatable .= '<td>';
 1887:                 }
 1888:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1889:                               '<input type="checkbox" name="updateable_'.$type.
 1890:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
 1891:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
 1892:             }
 1893:             $datatable .= '</tr></table></td></tr>';
 1894:         }
 1895:     }
 1896:     return $datatable;
 1897: }
 1898: 
 1899: sub modify_login {
 1900:     my ($r,$dom,$confname,%domconfig) = @_;
 1901:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
 1902:     my %title = ( coursecatalog => 'Display course catalog',
 1903:                   adminmail => 'Display administrator E-mail address',
 1904:                   loginheader => 'Log-in box header');
 1905:     my @offon = ('off','on');
 1906:     my %loginhash;
 1907:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
 1908:                                            \%domconfig,\%loginhash);
 1909:     $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
 1910:     $loginhash{login}{adminmail} = $env{'form.adminmail'};
 1911:     $loginhash{login}{loginheader} = $env{'form.loginheader'};
 1912:     if (ref($colchanges{'login'}) eq 'HASH') {  
 1913:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
 1914:                                          \%loginhash);
 1915:     }
 1916:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
 1917:                                              $dom);
 1918:     if ($putresult eq 'ok') {
 1919:         if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
 1920:             ($env{'form.coursecatalog'} eq '1')) {
 1921:             $changes{'coursecatalog'} = 1;
 1922:         } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
 1923:                  $domconfig{'login'}{'coursecatalog'} eq '1') &&
 1924:                  ($env{'form.coursecatalog'} eq '0')) {
 1925:             $changes{'coursecatalog'} = 1;
 1926:         }
 1927:         if (($domconfig{'login'}{'adminmail'} eq '1') &&
 1928:                 ($env{'form.adminmail'} eq '0')) {
 1929:             $changes{'adminmail'} = 1;
 1930:         } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
 1931:                  $domconfig{'login'}{'adminmail'} eq '0') &&
 1932:                  ($env{'form.adminmail'} eq '1')) {
 1933:             $changes{'adminmail'} = 1;
 1934:         }
 1935:         if (($domconfig{'login'}{'loginheader'} eq 'text') && 
 1936:             ($env{'form.loginheader'} eq 'image')) {
 1937:             $changes{'loginheader'} = 1;
 1938:         } elsif (($domconfig{'login'}{'loginheader'} eq '' ||
 1939:                   $domconfig{'login'}{'loginheader'} eq 'image') &&
 1940:                  ($env{'form.loginheader'} eq 'text')) {
 1941:             $changes{'loginheader'} = 1;
 1942:         }
 1943:         if (keys(%changes) > 0 || $colchgtext) {
 1944:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 1945:             $resulttext = &mt('Changes made:').'<ul>';
 1946:             foreach my $item (sort(keys(%changes))) {
 1947:                 if ($item eq 'loginheader') {
 1948:                     $resulttext .= '<li>'.&mt("$title{$item} set to $env{'form.loginheader'}").'</li>';
 1949:                 } else {
 1950:                     $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 1951:                 }
 1952:             }
 1953:             $resulttext .= $colchgtext.'</ul>';
 1954:         } else {
 1955:             $resulttext = &mt('No changes made to log-in page settings');
 1956:         }
 1957:     } else {
 1958:         $resulttext = '<span class="LC_error">'.
 1959: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 1960:     }
 1961:     if ($errors) {
 1962:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 1963:                        $errors.'</ul>';
 1964:     }
 1965:     return $resulttext;
 1966: }
 1967: 
 1968: sub color_font_choices {
 1969:     my %choices =
 1970:         &Apache::lonlocal::texthash (
 1971:             img => "Header",
 1972:             bgs => "Background colors",
 1973:             links => "Link colors",
 1974:             font => "Font color",
 1975:             pgbg => "Page",
 1976:             tabbg => "Header",
 1977:             sidebg => "Border",
 1978:             link => "Link",
 1979:             alink => "Active link",
 1980:             vlink => "Visited link",
 1981:         );
 1982:     return %choices;
 1983: }
 1984: 
 1985: sub modify_rolecolors {
 1986:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
 1987:     my ($resulttext,%rolehash);
 1988:     $rolehash{'rolecolors'} = {};
 1989:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 1990:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 1991:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 1992:                                              $dom);
 1993:     if ($putresult eq 'ok') {
 1994:         if (keys(%changes) > 0) {
 1995:             &Apache::loncommon::devalidate_domconfig_cache($dom);
 1996:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 1997:                                              $rolehash{'rolecolors'});
 1998:         } else {
 1999:             $resulttext = &mt('No changes made to default color schemes');
 2000:         }
 2001:     } else {
 2002:         $resulttext = '<span class="LC_error">'.
 2003: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 2004:     }
 2005:     if ($errors) {
 2006:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 2007:                        $errors.'</ul>';
 2008:     }
 2009:     return $resulttext;
 2010: }
 2011: 
 2012: sub modify_colors {
 2013:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 2014:     my (%changes,%choices);
 2015:     my @bgs = ('pgbg','mainbg','sidebg');
 2016:     my @links = ('link','alink','vlink');
 2017:     my @logintext;
 2018:     my @images;
 2019:     my $servadm = $r->dir_config('lonAdmEMail');
 2020:     my $errors;
 2021:     foreach my $role (@{$roles}) {
 2022:         if ($role eq 'login') {
 2023:             %choices = &login_choices();
 2024:             @logintext = ('textcol','bgcol');
 2025:         } else {
 2026:             %choices = &color_font_choices();
 2027:         }
 2028:         if ($role eq 'login') {
 2029:             @images = ('img','logo','domlogo','login');
 2030:         } else {
 2031:             @images = ('img');
 2032:         }
 2033:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 2034:         foreach my $item (@bgs,@links,@logintext) {
 2035:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 2036:         }
 2037:         my ($configuserok,$author_ok,$switchserver,%currroles);
 2038:         my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 2039:         ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 2040:                                                        $confname,$servadm);
 2041:         if ($configuserok eq 'ok') {
 2042:             $switchserver = &check_switchserver($dom,$confname);
 2043:             if ($switchserver eq '') {
 2044:                 $author_ok = &check_authorstatus($dom,$confname,%currroles);
 2045:             }
 2046:         }
 2047:         my ($width,$height) = &thumb_dimensions();
 2048:         if (ref($domconfig->{$role}) ne 'HASH') {
 2049:             $domconfig->{$role} = {};
 2050:         }
 2051:         foreach my $img (@images) {
 2052: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 2053: 		 && !defined($domconfig->{$role}{$img})
 2054: 		 && !$env{'form.'.$role.'_del_'.$img}
 2055: 		 && $env{'form.'.$role.'_import_'.$img}) {
 2056: 		# import the old configured image from the .tab setting
 2057: 		# if they haven't provided a new one 
 2058: 		$domconfig->{$role}{$img} = 
 2059: 		    $env{'form.'.$role.'_import_'.$img};
 2060: 	    }
 2061:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 2062:                 my $error;
 2063:                 if ($configuserok eq 'ok') {
 2064:                     if ($switchserver) {
 2065:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 2066:                     } else {
 2067:                         if ($author_ok eq 'ok') {
 2068:                             my ($result,$logourl) = 
 2069:                                 &publishlogo($r,'upload',$role.'_'.$img,
 2070:                                            $dom,$confname,$img,$width,$height);
 2071:                             if ($result eq 'ok') {
 2072:                                 $confhash->{$role}{$img} = $logourl;
 2073:                                 $changes{$role}{'images'}{$img} = 1;
 2074:                             } else {
 2075:                                 $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);
 2076:                             }
 2077:                         } else {
 2078:                             $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);
 2079:                         }
 2080:                     }
 2081:                 } else {
 2082:                     $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);
 2083:                 }
 2084:                 if ($error) {
 2085:                     &Apache::lonnet::logthis($error);
 2086:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 2087:                 }
 2088:             } elsif ($domconfig->{$role}{$img} ne '') {
 2089:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 2090:                     my $error;
 2091:                     if ($configuserok eq 'ok') {
 2092: # is confname an author?
 2093:                         if ($switchserver eq '') {
 2094:                             if ($author_ok eq 'ok') {
 2095:                                 my ($result,$logourl) = 
 2096:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 2097:                                             $dom,$confname,$img,$width,$height);
 2098:                                 if ($result eq 'ok') {
 2099:                                     $confhash->{$role}{$img} = $logourl;
 2100: 				    $changes{$role}{'images'}{$img} = 1;
 2101:                                 }
 2102:                             }
 2103:                         }
 2104:                     }
 2105:                 }
 2106:             }
 2107:         }
 2108:         if (ref($domconfig) eq 'HASH') {
 2109:             if (ref($domconfig->{$role}) eq 'HASH') {
 2110:                 foreach my $img (@images) {
 2111:                     if ($domconfig->{$role}{$img} ne '') {
 2112:                         if ($env{'form.'.$role.'_del_'.$img}) {
 2113:                             $confhash->{$role}{$img} = '';
 2114:                             $changes{$role}{'images'}{$img} = 1;
 2115:                         } else {
 2116:                             if ($confhash->{$role}{$img} eq '') {
 2117:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 2118:                             }
 2119:                         }
 2120:                     } else {
 2121:                         if ($env{'form.'.$role.'_del_'.$img}) {
 2122:                             $confhash->{$role}{$img} = '';
 2123:                             $changes{$role}{'images'}{$img} = 1;
 2124:                         } 
 2125:                     }
 2126:                 }  
 2127:                 if ($domconfig->{$role}{'font'} ne '') {
 2128:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 2129:                         $changes{$role}{'font'} = 1;
 2130:                     }
 2131:                 } else {
 2132:                     if ($confhash->{$role}{'font'}) {
 2133:                         $changes{$role}{'font'} = 1;
 2134:                     }
 2135:                 }
 2136:                 foreach my $item (@bgs) {
 2137:                     if ($domconfig->{$role}{$item} ne '') {
 2138:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 2139:                             $changes{$role}{'bgs'}{$item} = 1;
 2140:                         } 
 2141:                     } else {
 2142:                         if ($confhash->{$role}{$item}) {
 2143:                             $changes{$role}{'bgs'}{$item} = 1;
 2144:                         }
 2145:                     }
 2146:                 }
 2147:                 foreach my $item (@links) {
 2148:                     if ($domconfig->{$role}{$item} ne '') {
 2149:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 2150:                             $changes{$role}{'links'}{$item} = 1;
 2151:                         }
 2152:                     } else {
 2153:                         if ($confhash->{$role}{$item}) {
 2154:                             $changes{$role}{'links'}{$item} = 1;
 2155:                         }
 2156:                     }
 2157:                 }
 2158:                 foreach my $item (@logintext) {
 2159:                     if ($domconfig->{$role}{$item} ne '') {
 2160:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 2161:                             $changes{$role}{'logintext'}{$item} = 1;
 2162:                         }
 2163:                     } else {
 2164:                         if ($confhash->{$role}{$item}) {
 2165:                             $changes{$role}{'logintext'}{$item} = 1;
 2166:                         }
 2167:                     }
 2168:                 }
 2169:             } else {
 2170:                 &default_change_checker($role,\@images,\@links,\@bgs,
 2171:                                         \@logintext,$confhash,\%changes); 
 2172:             }
 2173:         } else {
 2174:             &default_change_checker($role,\@images,\@links,\@bgs,
 2175:                                     \@logintext,$confhash,\%changes); 
 2176:         }
 2177:     }
 2178:     return ($errors,%changes);
 2179: }
 2180: 
 2181: sub default_change_checker {
 2182:     my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
 2183:     foreach my $item (@{$links}) {
 2184:         if ($confhash->{$role}{$item}) {
 2185:             $changes->{$role}{'links'}{$item} = 1;
 2186:         }
 2187:     }
 2188:     foreach my $item (@{$bgs}) {
 2189:         if ($confhash->{$role}{$item}) {
 2190:             $changes->{$role}{'bgs'}{$item} = 1;
 2191:         }
 2192:     }
 2193:     foreach my $item (@{$logintext}) {
 2194:         if ($confhash->{$role}{$item}) {
 2195:             $changes->{$role}{'logintext'}{$item} = 1;
 2196:         }
 2197:     }
 2198:     foreach my $img (@{$images}) {
 2199:         if ($env{'form.'.$role.'_del_'.$img}) {
 2200:             $confhash->{$role}{$img} = '';
 2201:             $changes->{$role}{'images'}{$img} = 1;
 2202:         }
 2203:     }
 2204:     if ($confhash->{$role}{'font'}) {
 2205:         $changes->{$role}{'font'} = 1;
 2206:     }
 2207: } 
 2208: 
 2209: sub display_colorchgs {
 2210:     my ($dom,$changes,$roles,$confhash) = @_;
 2211:     my (%choices,$resulttext);
 2212:     if (!grep(/^login$/,@{$roles})) {
 2213:         $resulttext = &mt('Changes made:').'<br />';
 2214:     }
 2215:     foreach my $role (@{$roles}) {
 2216:         if ($role eq 'login') {
 2217:             %choices = &login_choices();
 2218:         } else {
 2219:             %choices = &color_font_choices();
 2220:         }
 2221:         if (ref($changes->{$role}) eq 'HASH') {
 2222:             if ($role ne 'login') {
 2223:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 2224:             }
 2225:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 2226:                 if ($role ne 'login') {
 2227:                     $resulttext .= '<ul>';
 2228:                 }
 2229:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 2230:                     if ($role ne 'login') {
 2231:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 2232:                     }
 2233:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 2234:                         if ($confhash->{$role}{$item} eq '') {
 2235:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 2236:                         } else {
 2237:                             my $newitem = $confhash->{$role}{$item};
 2238:                             if ($key eq 'images') {
 2239:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 2240:                             }
 2241:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 2242:                         }
 2243:                     }
 2244:                     if ($role ne 'login') {
 2245:                         $resulttext .= '</ul></li>';
 2246:                     }
 2247:                 } else {
 2248:                     if ($confhash->{$role}{$key} eq '') {
 2249:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 2250:                     } else {
 2251:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 2252:                     }
 2253:                 }
 2254:                 if ($role ne 'login') {
 2255:                     $resulttext .= '</ul>';
 2256:                 }
 2257:             }
 2258:         }
 2259:     }
 2260:     return $resulttext;
 2261: }
 2262: 
 2263: sub thumb_dimensions {
 2264:     return ('200','50');
 2265: }
 2266: 
 2267: sub check_dimensions {
 2268:     my ($inputfile) = @_;
 2269:     my ($fullwidth,$fullheight);
 2270:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 2271:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 2272:             my $imageinfo = <PIPE>;
 2273:             if (!close(PIPE)) {
 2274:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 2275:             }
 2276:             chomp($imageinfo);
 2277:             my ($fullsize) = 
 2278:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
 2279:             if ($fullsize) {
 2280:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 2281:             }
 2282:         }
 2283:     }
 2284:     return ($fullwidth,$fullheight);
 2285: }
 2286: 
 2287: sub check_configuser {
 2288:     my ($uhome,$dom,$confname,$servadm) = @_;
 2289:     my ($configuserok,%currroles);
 2290:     if ($uhome eq 'no_host') {
 2291:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 2292:         my $configpass = &LONCAPA::Enrollment::create_password();
 2293:         $configuserok = 
 2294:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 2295:                              $configpass,'','','','','',undef,$servadm);
 2296:     } else {
 2297:         $configuserok = 'ok';
 2298:         %currroles = 
 2299:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 2300:     }
 2301:     return ($configuserok,%currroles);
 2302: }
 2303: 
 2304: sub check_authorstatus {
 2305:     my ($dom,$confname,%currroles) = @_;
 2306:     my $author_ok;
 2307:     if (!$currroles{':'.$dom.':au'}) {
 2308:         my $start = time;
 2309:         my $end = 0;
 2310:         $author_ok = 
 2311:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 2312:                                         'au',$end,$start);
 2313:     } else {
 2314:         $author_ok = 'ok';
 2315:     }
 2316:     return $author_ok;
 2317: }
 2318: 
 2319: sub publishlogo {
 2320:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
 2321:     my ($output,$fname,$logourl);
 2322:     if ($action eq 'upload') {
 2323:         $fname=$env{'form.'.$formname.'.filename'};
 2324:         chop($env{'form.'.$formname});
 2325:     } else {
 2326:         ($fname) = ($formname =~ /([^\/]+)$/);
 2327:     }
 2328:     $fname=&Apache::lonnet::clean_filename($fname);
 2329: # See if there is anything left
 2330:     unless ($fname) { return ('error: no uploaded file'); }
 2331:     $fname="$subdir/$fname";
 2332:     my $filepath='/home/'.$confname.'/public_html';
 2333:     my ($fnamepath,$file,$fetchthumb);
 2334:     $file=$fname;
 2335:     if ($fname=~m|/|) {
 2336:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 2337:     }
 2338:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
 2339:     my $count;
 2340:     for ($count=4;$count<=$#parts;$count++) {
 2341:         $filepath.="/$parts[$count]";
 2342:         if ((-e $filepath)!=1) {
 2343:             mkdir($filepath,02770);
 2344:         }
 2345:     }
 2346:     # Check for bad extension and disallow upload
 2347:     if ($file=~/\.(\w+)$/ &&
 2348:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 2349:         $output = 
 2350:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
 2351:     } elsif ($file=~/\.(\w+)$/ &&
 2352:         !defined(&Apache::loncommon::fileembstyle($1))) {
 2353:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 2354:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 2355:         $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 2356:     } elsif (-d "$filepath/$file") {
 2357:         $output = &mt('File name is a directory name - rename the file and re-upload');
 2358:     } else {
 2359:         my $source = $filepath.'/'.$file;
 2360:         my $logfile;
 2361:         if (!open($logfile,">>$source".'.log')) {
 2362:             return (&mt('No write permission to Construction Space'));
 2363:         }
 2364:         print $logfile
 2365: "\n================= Publish ".localtime()." ================\n".
 2366: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 2367: # Save the file
 2368:         if (!open(FH,'>'.$source)) {
 2369:             &Apache::lonnet::logthis('Failed to create '.$source);
 2370:             return (&mt('Failed to create file'));
 2371:         }
 2372:         if ($action eq 'upload') {
 2373:             if (!print FH ($env{'form.'.$formname})) {
 2374:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 2375:                 return (&mt('Failed to write file'));
 2376:             }
 2377:         } else {
 2378:             my $original = &Apache::lonnet::filelocation('',$formname);
 2379:             if(!copy($original,$source)) {
 2380:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 2381:                 return (&mt('Failed to write file'));
 2382:             }
 2383:         }
 2384:         close(FH);
 2385:         chmod(0660, $source); # Permissions to rw-rw---.
 2386: 
 2387:         my $docroot=$r->dir_config('lonDocRoot');
 2388:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 2389:         my $copyfile=$targetdir.'/'.$file;
 2390: 
 2391:         my @parts=split(/\//,$targetdir);
 2392:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 2393:         for (my $count=5;$count<=$#parts;$count++) {
 2394:             $path.="/$parts[$count]";
 2395:             if (!-e $path) {
 2396:                 print $logfile "\nCreating directory ".$path;
 2397:                 mkdir($path,02770);
 2398:             }
 2399:         }
 2400:         my $versionresult;
 2401:         if (-e $copyfile) {
 2402:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 2403:         } else {
 2404:             $versionresult = 'ok';
 2405:         }
 2406:         if ($versionresult eq 'ok') {
 2407:             if (copy($source,$copyfile)) {
 2408:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 2409:                 $output = 'ok';
 2410:                 &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 2411:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 2412:             } else {
 2413:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 2414:                 $output = &mt('Failed to copy file to RES space').", $!";
 2415:             }
 2416:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 2417:                 my $inputfile = $filepath.'/'.$file;
 2418:                 my $outfile = $filepath.'/'.'tn-'.$file;
 2419:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 2420:                 if ($fullwidth ne '' && $fullheight ne '') { 
 2421:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 2422:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 2423:                         system("convert -sample $thumbsize $inputfile $outfile");
 2424:                         chmod(0660, $filepath.'/tn-'.$file);
 2425:                         if (-e $outfile) {
 2426:                             my $copyfile=$targetdir.'/tn-'.$file;
 2427:                             if (copy($outfile,$copyfile)) {
 2428:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 2429:                                 &write_metadata($dom,$confname,$formname,
 2430:                                                 $targetdir,'tn-'.$file,$logfile);
 2431:                             } else {
 2432:                                 print $logfile "\nUnable to write ".$copyfile.
 2433:                                                ':'.$!."\n";
 2434:                             }
 2435:                         }
 2436:                     }
 2437:                 }
 2438:             }
 2439:         } else {
 2440:             $output = $versionresult;
 2441:         }
 2442:     }
 2443:     return ($output,$logourl);
 2444: }
 2445: 
 2446: sub logo_versioning {
 2447:     my ($targetdir,$file,$logfile) = @_;
 2448:     my $target = $targetdir.'/'.$file;
 2449:     my ($maxversion,$fn,$extn,$output);
 2450:     $maxversion = 0;
 2451:     if ($file =~ /^(.+)\.(\w+)$/) {
 2452:         $fn=$1;
 2453:         $extn=$2;
 2454:     }
 2455:     opendir(DIR,$targetdir);
 2456:     while (my $filename=readdir(DIR)) {
 2457:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 2458:             $maxversion=($1>$maxversion)?$1:$maxversion;
 2459:         }
 2460:     }
 2461:     $maxversion++;
 2462:     print $logfile "\nCreating old version ".$maxversion."\n";
 2463:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 2464:     if (copy($target,$copyfile)) {
 2465:         print $logfile "Copied old target to ".$copyfile."\n";
 2466:         $copyfile=$copyfile.'.meta';
 2467:         if (copy($target.'.meta',$copyfile)) {
 2468:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 2469:             $output = 'ok';
 2470:         } else {
 2471:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 2472:             $output = &mt('Failed to copy old meta').", $!, ";
 2473:         }
 2474:     } else {
 2475:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 2476:         $output = &mt('Failed to copy old target').", $!, ";
 2477:     }
 2478:     return $output;
 2479: }
 2480: 
 2481: sub write_metadata {
 2482:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 2483:     my (%metadatafields,%metadatakeys,$output);
 2484:     $metadatafields{'title'}=$formname;
 2485:     $metadatafields{'creationdate'}=time;
 2486:     $metadatafields{'lastrevisiondate'}=time;
 2487:     $metadatafields{'copyright'}='public';
 2488:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 2489:                                          $env{'user.domain'};
 2490:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 2491:     $metadatafields{'domain'}=$dom;
 2492:     {
 2493:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 2494:         my $mfh;
 2495:         unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 2496:             $output = &mt('Could not write metadata');
 2497:         }
 2498:         foreach (sort keys %metadatafields) {
 2499:             unless ($_=~/\./) {
 2500:                 my $unikey=$_;
 2501:                 $unikey=~/^([A-Za-z]+)/;
 2502:                 my $tag=$1;
 2503:                 $tag=~tr/A-Z/a-z/;
 2504:                 print $mfh "\n\<$tag";
 2505:                 foreach (split(/\,/,$metadatakeys{$unikey})) {
 2506:                     my $value=$metadatafields{$unikey.'.'.$_};
 2507:                     $value=~s/\"/\'\'/g;
 2508:                     print $mfh ' '.$_.'="'.$value.'"';
 2509:                 }
 2510:                 print $mfh '>'.
 2511:                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 2512:                         .'</'.$tag.'>';
 2513:             }
 2514:         }
 2515:         $output = 'ok';
 2516:         print $logfile "\nWrote metadata";
 2517:         close($mfh);
 2518:     }
 2519: }
 2520: 
 2521: sub check_switchserver {
 2522:     my ($dom,$confname) = @_;
 2523:     my ($allowed,$switchserver);
 2524:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 2525:     if ($home eq 'no_host') {
 2526:         $home = &Apache::lonnet::domain($dom,'primary');
 2527:     }
 2528:     my @ids=&Apache::lonnet::current_machine_ids();
 2529:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 2530:     if (!$allowed) {
 2531: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
 2532:     }
 2533:     return $switchserver;
 2534: }
 2535: 
 2536: sub javascript_set_colnums {
 2537:     return <<END;
 2538: function setDisplayColumns() {
 2539:     if (document.pickactions.width.value > 1100) {
 2540:         document.pickactions.numcols[1].checked = true;
 2541:     } else {
 2542:         document.pickactions.numcols[0].checked = true;
 2543:     }
 2544: }
 2545: END
 2546: }
 2547: 
 2548: sub modify_quotas {
 2549:     my ($dom,%domconfig) = @_;
 2550:     my ($resulttext,%changes);
 2551:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
 2552:     my %formhash;
 2553:     foreach my $key (keys(%env)) {
 2554:         if ($key =~ /^form\.quota_(.+)$/) {
 2555:             $formhash{$1} = $env{$key};
 2556:         }
 2557:     }
 2558:     $formhash{'default'} = $env{'form.defaultquota'};
 2559:     if (ref($domconfig{'quotas'}) eq 'HASH') {
 2560:         foreach my $key (keys(%{$domconfig{'quotas'}})) {
 2561:             if (exists($formhash{$key})) {
 2562:                 if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
 2563:                     $changes{$key} = 1;
 2564:                 }
 2565:             } else {
 2566:                 $formhash{$key} = $domconfig{'quotas'}{$key};
 2567:             }
 2568:         }
 2569:     }
 2570:     foreach my $key (keys(%formhash)) {
 2571:         if ($formhash{$key} ne '') {
 2572:             if (!exists($domconfig{'quotas'}{$key})) {
 2573:                 $changes{$key} = 1;
 2574:             }
 2575:         }
 2576:     }
 2577:     my %quotahash = (
 2578:                       quotas => {%formhash},
 2579:                     );
 2580:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 2581:                                              $dom);
 2582:     if ($putresult eq 'ok') {
 2583:         if (keys(%changes) > 0) {
 2584:             $resulttext = &mt('Changes made:').'<ul>';
 2585:             foreach my $type (@{$types},'default') {
 2586:                 if (defined($changes{$type})) { 
 2587:                     my $typetitle = $usertypes->{$type};
 2588:                     if ($type eq 'default') {
 2589:                         $typetitle = $othertitle;
 2590:                     }
 2591:                     $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
 2592:                 }
 2593:             }
 2594:             $resulttext .= '</ul>';
 2595:         } else {
 2596:             $resulttext = &mt('No changes made to default quotas');
 2597:         }
 2598:     } else {
 2599:         $resulttext = '<span class="LC_error">'.
 2600: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 2601:     }
 2602:     return $resulttext;
 2603: }
 2604: 
 2605: sub modify_autoenroll {
 2606:     my ($dom,%domconfig) = @_;
 2607:     my ($resulttext,%changes);
 2608:     my %currautoenroll;
 2609:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 2610:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 2611:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 2612:         }
 2613:     }
 2614:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 2615:     my %title = ( run => 'Auto-enrollment active',
 2616:                   sender => 'Sender for notification messages');
 2617:     my @offon = ('off','on');
 2618:     my $sender_uname = $env{'form.sender_uname'};
 2619:     my $sender_domain = $env{'form.sender_domain'};
 2620:     if ($sender_domain eq '') {
 2621:         $sender_uname = '';
 2622:     } elsif ($sender_uname eq '') {
 2623:         $sender_domain = '';
 2624:     }
 2625:     my %autoenrollhash =  (
 2626:                        autoenroll => { run => $env{'form.autoenroll_run'},
 2627:                                        sender_uname => $sender_uname,
 2628:                                        sender_domain => $sender_domain,
 2629: 
 2630:                                 }
 2631:                      );
 2632:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 2633:                                              $dom);
 2634:     if ($putresult eq 'ok') {
 2635:         if (exists($currautoenroll{'run'})) {
 2636:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 2637:                  $changes{'run'} = 1;
 2638:              }
 2639:         } elsif ($autorun) {
 2640:             if ($env{'form.autoenroll_run'} ne '1') {
 2641:                  $changes{'run'} = 1;
 2642:             }
 2643:         }
 2644:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 2645:             $changes{'sender'} = 1;
 2646:         }
 2647:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 2648:             $changes{'sender'} = 1;
 2649:         }
 2650:         if (keys(%changes) > 0) {
 2651:             $resulttext = &mt('Changes made:').'<ul>';
 2652:             if ($changes{'run'}) {
 2653:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 2654:             }
 2655:             if ($changes{'sender'}) {
 2656:                 if ($sender_uname eq '' || $sender_domain eq '') {
 2657:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 2658:                 } else {
 2659:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 2660:                 }
 2661:             }
 2662:             $resulttext .= '</ul>';
 2663:         } else {
 2664:             $resulttext = &mt('No changes made to auto-enrollment settings');
 2665:         }
 2666:     } else {
 2667:         $resulttext = '<span class="LC_error">'.
 2668: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 2669:     }
 2670:     return $resulttext;
 2671: }
 2672: 
 2673: sub modify_autoupdate {
 2674:     my ($dom,%domconfig) = @_;
 2675:     my ($resulttext,%currautoupdate,%fields,%changes);
 2676:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 2677:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 2678:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 2679:         }
 2680:     }
 2681:     my @offon = ('off','on');
 2682:     my %title = &Apache::lonlocal::texthash (
 2683:                    run => 'Auto-update:',
 2684:                    classlists => 'Updates to user information in classlists?'
 2685:                 );
 2686:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
 2687:     my %fieldtitles = &Apache::lonlocal::texthash (
 2688:                         id => 'Student/Employee ID',
 2689:                         permanentemail => 'E-mail address',
 2690:                         lastname => 'Last Name',
 2691:                         firstname => 'First Name',
 2692:                         middlename => 'Middle Name',
 2693:                         gen => 'Generation',
 2694:                       );
 2695:     my $othertitle = &mt('All users');
 2696:     if (keys(%{$usertypes}) >  0) {
 2697:         $othertitle = &mt('Other users');
 2698:     }
 2699:     foreach my $key (keys(%env)) {
 2700:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 2701:             push(@{$fields{$1}},$2);
 2702:         }
 2703:     }
 2704:     my %updatehash = (
 2705:                       autoupdate => { run => $env{'form.autoupdate_run'},
 2706:                                       classlists => $env{'form.classlists'},
 2707:                                       fields => {%fields},
 2708:                                     }
 2709:                      );
 2710:     foreach my $key (keys(%currautoupdate)) {
 2711:         if (($key eq 'run') || ($key eq 'classlists')) {
 2712:             if (exists($updatehash{autoupdate}{$key})) {
 2713:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 2714:                     $changes{$key} = 1;
 2715:                 }
 2716:             }
 2717:         } elsif ($key eq 'fields') {
 2718:             if (ref($currautoupdate{$key}) eq 'HASH') {
 2719:                 foreach my $item (@{$types},'default') {
 2720:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 2721:                         my $change = 0;
 2722:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 2723:                             if (!exists($fields{$item})) {
 2724:                                 $change = 1;
 2725:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 2726:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
 2727:                                     $change = 1;
 2728:                                 }
 2729:                             }
 2730:                         }
 2731:                         if ($change) {
 2732:                             push(@{$changes{$key}},$item);
 2733:                         }
 2734:                     } 
 2735:                 }
 2736:             }
 2737:         }
 2738:     }
 2739:     foreach my $item (@{$types},'default') {
 2740:         if (defined($fields{$item})) {
 2741:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
 2742:                 if (!exists($currautoupdate{'fields'}{$item})) {
 2743:                     push(@{$changes{'fields'}},$item);
 2744:                 }
 2745:             } else {
 2746:                 push(@{$changes{'fields'}},$item);
 2747:             }
 2748:         }
 2749:     }
 2750:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 2751:                                              $dom);
 2752:     if ($putresult eq 'ok') {
 2753:         if (keys(%changes) > 0) {
 2754:             $resulttext = &mt('Changes made:').'<ul>';
 2755:             foreach my $key (sort(keys(%changes))) {
 2756:                 if (ref($changes{$key}) eq 'ARRAY') {
 2757:                     foreach my $item (@{$changes{$key}}) {
 2758:                         my @newvalues;
 2759:                         foreach my $type (@{$fields{$item}}) {
 2760:                             push(@newvalues,$fieldtitles{$type});
 2761:                         }
 2762:                         my $newvaluestr;
 2763:                         if (@newvalues > 0) {
 2764:                             $newvaluestr = join(', ',@newvalues);
 2765:                         } else {
 2766:                             $newvaluestr = &mt('none');
 2767:                         }
 2768:                         if ($item eq 'default') {
 2769:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
 2770:                         } else {
 2771:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
 2772:                         }
 2773:                     }
 2774:                 } else {
 2775:                     my $newvalue;
 2776:                     if ($key eq 'run') {
 2777:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 2778:                     } else {
 2779:                         $newvalue = $offon[$env{'form.'.$key}];
 2780:                     }
 2781:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 2782:                 }
 2783:             }
 2784:             $resulttext .= '</ul>';
 2785:         } else {
 2786:             $resulttext = &mt('No changes made to autoupdates');
 2787:         }
 2788:     } else {
 2789:         $resulttext = '<span class="LC_error">'.
 2790: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 2791:     }
 2792:     return $resulttext;
 2793: }
 2794: 
 2795: sub modify_directorysrch {
 2796:     my ($dom,%domconfig) = @_;
 2797:     my ($resulttext,%changes);
 2798:     my %currdirsrch;
 2799:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
 2800:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
 2801:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
 2802:         }
 2803:     }
 2804:     my %title = ( available => 'Directory search available',
 2805:                   localonly => 'Other domains can search',
 2806:                   searchby => 'Search types',
 2807:                   searchtypes => 'Search latitude');
 2808:     my @offon = ('off','on');
 2809:     my @otherdoms = ('Yes','No');
 2810: 
 2811:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
 2812:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
 2813:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
 2814: 
 2815:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
 2816:     if (keys(%{$usertypes}) == 0) {
 2817:         @cansearch = ('default');
 2818:     } else {
 2819:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
 2820:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
 2821:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
 2822:                     push(@{$changes{'cansearch'}},$type);
 2823:                 }
 2824:             }
 2825:             foreach my $type (@cansearch) {
 2826:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
 2827:                     push(@{$changes{'cansearch'}},$type);
 2828:                 }
 2829:             }
 2830:         } else {
 2831:             push(@{$changes{'cansearch'}},@cansearch);
 2832:         }
 2833:     }
 2834: 
 2835:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
 2836:         foreach my $by (@{$currdirsrch{'searchby'}}) {
 2837:             if (!grep(/^\Q$by\E$/,@searchby)) {
 2838:                 push(@{$changes{'searchby'}},$by);
 2839:             }
 2840:         }
 2841:         foreach my $by (@searchby) {
 2842:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
 2843:                 push(@{$changes{'searchby'}},$by);
 2844:             }
 2845:         }
 2846:     } else {
 2847:         push(@{$changes{'searchby'}},@searchby);
 2848:     }
 2849: 
 2850:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
 2851:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
 2852:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
 2853:                 push(@{$changes{'searchtypes'}},$type);
 2854:             }
 2855:         }
 2856:         foreach my $type (@searchtypes) {
 2857:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
 2858:                 push(@{$changes{'searchtypes'}},$type);
 2859:             }
 2860:         }
 2861:     } else {
 2862:         if (exists($currdirsrch{'searchtypes'})) {
 2863:             foreach my $type (@searchtypes) {  
 2864:                 if ($type ne $currdirsrch{'searchtypes'}) { 
 2865:                     push(@{$changes{'searchtypes'}},$type);
 2866:                 }
 2867:             }
 2868:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
 2869:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
 2870:             }   
 2871:         } else {
 2872:             push(@{$changes{'searchtypes'}},@searchtypes); 
 2873:         }
 2874:     }
 2875: 
 2876:     my %dirsrch_hash =  (
 2877:             directorysrch => { available => $env{'form.dirsrch_available'},
 2878:                                cansearch => \@cansearch,
 2879:                                localonly => $env{'form.dirsrch_localonly'},
 2880:                                searchby => \@searchby,
 2881:                                searchtypes => \@searchtypes,
 2882:                              }
 2883:             );
 2884:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
 2885:                                              $dom);
 2886:     if ($putresult eq 'ok') {
 2887:         if (exists($currdirsrch{'available'})) {
 2888:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
 2889:                  $changes{'available'} = 1;
 2890:              }
 2891:         } else {
 2892:             if ($env{'form.dirsrch_available'} eq '1') {
 2893:                 $changes{'available'} = 1;
 2894:             }
 2895:         }
 2896:         if (exists($currdirsrch{'localonly'})) {
 2897:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
 2898:                  $changes{'localonly'} = 1;
 2899:              }
 2900:         } else {
 2901:             if ($env{'form.dirsrch_localonly'} eq '1') {
 2902:                 $changes{'localonly'} = 1;
 2903:             }
 2904:         }
 2905:         if (keys(%changes) > 0) {
 2906:             $resulttext = &mt('Changes made:').'<ul>';
 2907:             if ($changes{'available'}) {
 2908:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
 2909:             }
 2910:             if ($changes{'localonly'}) {
 2911:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
 2912:             }
 2913: 
 2914:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
 2915:                 my $chgtext;
 2916:                 if (ref($usertypes) eq 'HASH') {
 2917:                     if (keys(%{$usertypes}) > 0) {
 2918:                         foreach my $type (@{$types}) {
 2919:                             if (grep(/^\Q$type\E$/,@cansearch)) {
 2920:                                 $chgtext .= $usertypes->{$type}.'; ';
 2921:                             }
 2922:                         }
 2923:                         if (grep(/^default$/,@cansearch)) {
 2924:                             $chgtext .= $othertitle;
 2925:                         } else {
 2926:                             $chgtext =~ s/\; $//;
 2927:                         }
 2928:                         $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
 2929:                     }
 2930:                 }
 2931:             }
 2932:             if (ref($changes{'searchby'}) eq 'ARRAY') {
 2933:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
 2934:                 my $chgtext;
 2935:                 foreach my $type (@{$titleorder}) {
 2936:                     if (grep(/^\Q$type\E$/,@searchby)) {
 2937:                         if (defined($searchtitles->{$type})) {
 2938:                             $chgtext .= $searchtitles->{$type}.'; ';
 2939:                         }
 2940:                     }
 2941:                 }
 2942:                 $chgtext =~ s/\; $//;
 2943:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
 2944:             }
 2945:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
 2946:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
 2947:                 my $chgtext;
 2948:                 foreach my $type (@{$srchtypeorder}) {
 2949:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
 2950:                         if (defined($srchtypes_desc->{$type})) {
 2951:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
 2952:                         }
 2953:                     }
 2954:                 }
 2955:                 $chgtext =~ s/\; $//;
 2956:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
 2957:             }
 2958:             $resulttext .= '</ul>';
 2959:         } else {
 2960:             $resulttext = &mt('No changes made to institution directory search settings');
 2961:         }
 2962:     } else {
 2963:         $resulttext = '<span class="LC_error">'.
 2964:                       &mt('An error occurred: [_1]',$putresult).'</span>';
 2965:     }
 2966:     return $resulttext;
 2967: }
 2968: 
 2969: sub modify_contacts {
 2970:     my ($dom,%domconfig) = @_;
 2971:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
 2972:     if (ref($domconfig{'contacts'}) eq 'HASH') {
 2973:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
 2974:             $currsetting{$key} = $domconfig{'contacts'}{$key};
 2975:         }
 2976:     }
 2977:     my (%others,%to);
 2978:     my @contacts = ('supportemail','adminemail');
 2979:     my @mailings = ('errormail','packagesmail','helpdeskmail');
 2980:     foreach my $type (@mailings) {
 2981:         @{$newsetting{$type}} = 
 2982:             &Apache::loncommon::get_env_multiple('form.'.$type);
 2983:         foreach my $item (@contacts) {
 2984:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
 2985:                 $contacts_hash{contacts}{$type}{$item} = 1;
 2986:             } else {
 2987:                 $contacts_hash{contacts}{$type}{$item} = 0;
 2988:             }
 2989:         }  
 2990:         $others{$type} = $env{'form.'.$type.'_others'};
 2991:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
 2992:     }
 2993:     foreach my $item (@contacts) {
 2994:         $to{$item} = $env{'form.'.$item};
 2995:         $contacts_hash{'contacts'}{$item} = $to{$item};
 2996:     }
 2997:     if (keys(%currsetting) > 0) {
 2998:         foreach my $item (@contacts) {
 2999:             if ($to{$item} ne $currsetting{$item}) {
 3000:                 $changes{$item} = 1;
 3001:             }
 3002:         }
 3003:         foreach my $type (@mailings) {
 3004:             foreach my $item (@contacts) {
 3005:                 if (ref($currsetting{$type}) eq 'HASH') {
 3006:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
 3007:                         push(@{$changes{$type}},$item);
 3008:                     }
 3009:                 } else {
 3010:                     push(@{$changes{$type}},@{$newsetting{$type}});
 3011:                 }
 3012:             }
 3013:             if ($others{$type} ne $currsetting{$type}{'others'}) {
 3014:                 push(@{$changes{$type}},'others');
 3015:             }
 3016:         }
 3017:     } else {
 3018:         my %default;
 3019:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 3020:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 3021:         $default{'errormail'} = 'adminemail';
 3022:         $default{'packagesmail'} = 'adminemail';
 3023:         $default{'helpdeskmail'} = 'supportemail';
 3024:         foreach my $item (@contacts) {
 3025:            if ($to{$item} ne $default{$item}) {
 3026:               $changes{$item} = 1;
 3027:            } 
 3028:         }
 3029:         foreach my $type (@mailings) {
 3030:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
 3031:                
 3032:                 push(@{$changes{$type}},@{$newsetting{$type}});
 3033:             }
 3034:             if ($others{$type} ne '') {
 3035:                 push(@{$changes{$type}},'others');
 3036:             } 
 3037:         }
 3038:     }
 3039:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
 3040:                                              $dom);
 3041:     if ($putresult eq 'ok') {
 3042:         if (keys(%changes) > 0) {
 3043:             my ($titles,$short_titles)  = &contact_titles();
 3044:             $resulttext = &mt('Changes made:').'<ul>';
 3045:             foreach my $item (@contacts) {
 3046:                 if ($changes{$item}) {
 3047:                     $resulttext .= '<li>'.$titles->{$item}.
 3048:                                     &mt(' set to: ').
 3049:                                     '<span class="LC_cusr_emph">'.
 3050:                                     $to{$item}.'</span></li>';
 3051:                 }
 3052:             }
 3053:             foreach my $type (@mailings) {
 3054:                 if (ref($changes{$type}) eq 'ARRAY') {
 3055:                     $resulttext .= '<li>'.$titles->{$type}.': ';
 3056:                     my @text;
 3057:                     foreach my $item (@{$newsetting{$type}}) {
 3058:                         push(@text,$short_titles->{$item});
 3059:                     }
 3060:                     if ($others{$type} ne '') {
 3061:                         push(@text,$others{$type});
 3062:                     }
 3063:                     $resulttext .= '<span class="LC_cusr_emph">'.
 3064:                                    join(', ',@text).'</span></li>';
 3065:                 }
 3066:             }
 3067:             $resulttext .= '</ul>';
 3068:         } else {
 3069:             $resulttext = &mt('No changes made to contact information');
 3070:         }
 3071:     } else {
 3072:         $resulttext = '<span class="LC_error">'.
 3073:             &mt('An error occurred: [_1].',$putresult).'</span>';
 3074:     }
 3075:     return $resulttext;
 3076: }
 3077: 
 3078: sub modify_usercreation {
 3079:     my ($dom,%domconfig) = @_;
 3080:     my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
 3081:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 3082:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 3083:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 3084:         }
 3085:     }
 3086:     my %title = &Apache::lonlocal::texthash (
 3087:                    author => 'adding co-authors/assistant authors',
 3088:                    course => 'adding users to a course',
 3089:                 );
 3090:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
 3091:     my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
 3092:     my @contexts = ('author','course');
 3093:     foreach my $item(@contexts) {
 3094:         $cancreate{$item} = $env{'form.can_createuser_'.$item};
 3095:     }
 3096:     if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
 3097:         foreach my $item (@contexts) {
 3098:             if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
 3099:                 push(@{$changes{'cancreate'}},$item);
 3100:             } 
 3101:         }
 3102:     } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
 3103:         foreach my $item (@contexts) {
 3104:             if (grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
 3105:                 if ($cancreate{$item} ne 'any') {
 3106:                     push(@{$changes{'cancreate'}},$item);
 3107:                 }
 3108:             } else {
 3109:                 if ($cancreate{$item} ne 'none') {
 3110:                     push(@{$changes{'cancreate'}},$item);
 3111:                 }
 3112:             }
 3113:         }
 3114:     } else {
 3115:         foreach my $item ('author','course') {
 3116:             push(@{$changes{'cancreate'}},$item);
 3117:         }
 3118:     }
 3119: 
 3120:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
 3121:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
 3122:             if (!grep(/^\Q$type\E$/,@username_rule)) {
 3123:                 push(@{$changes{'username_rule'}},$type);
 3124:             }
 3125:         }
 3126:         foreach my $type (@username_rule) {
 3127:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
 3128:                 push(@{$changes{'username_rule'}},$type);
 3129:             }
 3130:         }
 3131:     } else {
 3132:         push(@{$changes{'username_rule'}},@username_rule);
 3133:     }
 3134: 
 3135:     if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
 3136:         foreach my $type (@{$curr_usercreation{'id_rule'}}) {
 3137:             if (!grep(/^\Q$type\E$/,@id_rule)) {
 3138:                 push(@{$changes{'id_rule'}},$type);
 3139:             }
 3140:         }
 3141:         foreach my $type (@id_rule) {
 3142:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
 3143:                 push(@{$changes{'id_rule'}},$type);
 3144:             }
 3145:         }
 3146:     } else {
 3147:         push(@{$changes{'id_rule'}},@id_rule);
 3148:     }
 3149: 
 3150:     my @contexts = ('author','course','domain');
 3151:     my @authtypes = ('int','krb4','krb5','loc');
 3152:     my %authhash;
 3153:     foreach my $item (@contexts) {
 3154:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
 3155:         foreach my $auth (@authtypes) {
 3156:             if (grep(/^\Q$auth\E$/,@authallowed)) {
 3157:                 $authhash{$item}{$auth} = 1;
 3158:             } else {
 3159:                 $authhash{$item}{$auth} = 0;
 3160:             }
 3161:         }
 3162:     }
 3163:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
 3164:         foreach my $item (@contexts) {
 3165:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
 3166:                 foreach my $auth (@authtypes) {
 3167:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
 3168:                         push(@{$changes{'authtypes'}},$item);
 3169:                         last;
 3170:                     }
 3171:                 }
 3172:             }
 3173:         }
 3174:     } else {
 3175:         foreach my $item (@contexts) {
 3176:             push(@{$changes{'authtypes'}},$item);
 3177:         }
 3178:     }
 3179: 
 3180:     my %usercreation_hash =  (
 3181:             usercreation => {
 3182:                               cancreate     => \%cancreate,
 3183:                               username_rule => \@username_rule,
 3184:                               id_rule       => \@id_rule,
 3185:                               authtypes     => \%authhash,
 3186:                             }
 3187:             );
 3188: 
 3189:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
 3190:                                              $dom);
 3191:     if ($putresult eq 'ok') {
 3192:         if (keys(%changes) > 0) {
 3193:             $resulttext = &mt('Changes made:').'<ul>';
 3194:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 3195:                 my %lt = &usercreation_types();
 3196:                 foreach my $type (@{$changes{'cancreate'}}) {
 3197:                     my $chgtext; 
 3198:                     if ($cancreate{$type} eq 'none') {
 3199:                         $chgtext = $lt{$type}.' '.&mt('creation of new users is not permitted, except by a Domain Coordinator.');
 3200:                     } elsif ($cancreate{$type} eq 'any') {
 3201:                         $chgtext = $lt{$type}.' '.&mt('creation of new users is permitted for both institutional and non-institutional usernames.'); 
 3202:                     } elsif ($cancreate{$type} eq 'official') {
 3203:                         $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for institutional usernames.',$lt{$type});
 3204:                     } elsif ($cancreate{$type} eq 'unofficial') {
 3205:                         $chgtext = $lt{$type}.' '.&mt('creation of new users is only permitted for non-institutional usernames.',$lt{$type});
 3206:                     }
 3207:                     $resulttext .= '<li>'.$chgtext.'</li>';
 3208:                 }
 3209:             }
 3210:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
 3211:                 my ($rules,$ruleorder) = 
 3212:                     &Apache::lonnet::inst_userrules($dom,'username');
 3213:                 my $chgtext = '<ul>';
 3214:                 foreach my $type (@username_rule) {
 3215:                     if (ref($rules->{$type}) eq 'HASH') {
 3216:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
 3217:                     }
 3218:                 }
 3219:                 $chgtext .= '</ul>';
 3220:                 if (@username_rule > 0) {
 3221:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
 3222:                 } else {
 3223:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
 3224:                 }
 3225:             }
 3226:             if (ref($changes{'id_rule'}) eq 'ARRAY') {
 3227:                 my ($idrules,$idruleorder) = 
 3228:                     &Apache::lonnet::inst_userrules($dom,'id');
 3229:                 my $chgtext = '<ul>';
 3230:                 foreach my $type (@id_rule) {
 3231:                     if (ref($idrules->{$type}) eq 'HASH') {
 3232:                         $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
 3233:                     }
 3234:                 }
 3235:                 $chgtext .= '</ul>';
 3236:                 if (@id_rule > 0) {
 3237:                     $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
 3238:                 } else {
 3239:                     $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
 3240:                 }
 3241:             }
 3242:             my %authname = &authtype_names();
 3243:             my %context_title = &context_names();
 3244:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
 3245:                 my $chgtext = '<ul>';
 3246:                 foreach my $type (@{$changes{'authtypes'}}) {
 3247:                     my @allowed;
 3248:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
 3249:                     foreach my $auth (@authtypes) {
 3250:                         if ($authhash{$type}{$auth}) {
 3251:                             push(@allowed,$authname{$auth});
 3252:                         }
 3253:                     }
 3254:                     $chgtext .= join(', ',@allowed).'</li>';
 3255:                 }
 3256:                 $chgtext .= '</ul>';
 3257:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
 3258:                 $resulttext .= '</li>';
 3259:             }
 3260:             $resulttext .= '</ul>';
 3261:         } else {
 3262:             $resulttext = &mt('No changes made to user creation settings');
 3263:         }
 3264:     } else {
 3265:         $resulttext = '<span class="LC_error">'.
 3266:             &mt('An error occurred: [_1]',$putresult).'</span>';
 3267:     }
 3268:     return $resulttext;
 3269: }
 3270: 
 3271: sub modify_usermodification {
 3272:     my ($dom,%domconfig) = @_;
 3273:     my ($resulttext,%curr_usermodification,%changes);
 3274:     if (ref($domconfig{'usermodification'}) eq 'HASH') {
 3275:         foreach my $key (keys(%{$domconfig{'usermodification'}})) {
 3276:             $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
 3277:         }
 3278:     }
 3279:     my @contexts = ('author','course');
 3280:     my %context_title = (
 3281:                            author => 'In author context',
 3282:                            course => 'In course context',
 3283:                         );
 3284:     my @fields = ('lastname','firstname','middlename','generation',
 3285:                   'permanentemail','id');
 3286:     my %roles = (
 3287:                   author => ['ca','aa'],
 3288:                   course => ['st','ep','ta','in','cr'],
 3289:                 );
 3290:     my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
 3291:     my %modifyhash;
 3292:     foreach my $context (@contexts) {
 3293:         foreach my $role (@{$roles{$context}}) {
 3294:             my @modifiable =  &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
 3295:             foreach my $item (@fields) {
 3296:                 if (grep(/^\Q$item\E$/,@modifiable)) {
 3297:                     $modifyhash{$context}{$role}{$item} = 1;
 3298:                 } else {
 3299:                     $modifyhash{$context}{$role}{$item} = 0;
 3300:                 }
 3301:             }
 3302:         }
 3303:         if (ref($curr_usermodification{$context}) eq 'HASH') {
 3304:             foreach my $role (@{$roles{$context}}) {
 3305:                 if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
 3306:                     foreach my $field (@fields) {
 3307:                         if ($modifyhash{$context}{$role}{$field} ne 
 3308:                                 $curr_usermodification{$context}{$role}{$field}) {
 3309:                             push(@{$changes{$context}},$role);
 3310:                             last;
 3311:                         }
 3312:                     }
 3313:                 }
 3314:             }
 3315:         } else {
 3316:             foreach my $context (@contexts) {
 3317:                 foreach my $role (@{$roles{$context}}) {
 3318:                     push(@{$changes{$context}},$role);
 3319:                 }
 3320:             }
 3321:         }
 3322:     }
 3323:     my %usermodification_hash =  (
 3324:                                    usermodification => \%modifyhash,
 3325:                                  );
 3326:     my $putresult = &Apache::lonnet::put_dom('configuration',
 3327:                                              \%usermodification_hash,$dom);
 3328:     if ($putresult eq 'ok') {
 3329:         if (keys(%changes) > 0) {
 3330:             $resulttext = &mt('Changes made: ').'<ul>';
 3331:             foreach my $context (@contexts) {
 3332:                 if (ref($changes{$context}) eq 'ARRAY') {
 3333:                     $resulttext .= '<li>'.$context_title{$context}.':<ul>';
 3334:                     if (ref($changes{$context}) eq 'ARRAY') {
 3335:                         foreach my $role (@{$changes{$context}}) {
 3336:                             my $rolename;
 3337:                             if ($role eq 'cr') {
 3338:                                 $rolename = &mt('Custom');
 3339:                             } else {
 3340:                                 $rolename = &Apache::lonnet::plaintext($role);
 3341:                             }
 3342:                             my @modifiable;
 3343:                             $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
 3344:                             foreach my $field (@fields) {
 3345:                                 if ($modifyhash{$context}{$role}{$field}) {
 3346:                                     push(@modifiable,$fieldtitles{$field});
 3347:                                 }
 3348:                             }
 3349:                             if (@modifiable > 0) {
 3350:                                 $resulttext .= join(', ',@modifiable);
 3351:                             } else {
 3352:                                 $resulttext .= &mt('none'); 
 3353:                             }
 3354:                             $resulttext .= '</li>';
 3355:                         }
 3356:                         $resulttext .= '</ul></li>';
 3357:                     }
 3358:                 }
 3359:             }
 3360:             $resulttext .= '</ul>';
 3361:         } else {
 3362:             $resulttext = &mt('No changes made to user modification settings');
 3363:         }
 3364:     } else {
 3365:         $resulttext = '<span class="LC_error">'.
 3366:             &mt('An error occurred: [_1]',$putresult).'</span>';
 3367:     }
 3368:     return $resulttext;
 3369: }
 3370: 
 3371: 1;

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