File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.42: download - view: text, annotated - select for diffs
Fri Feb 15 17:02:31 2008 UTC (16 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Eliminate code duplication for login screen settings with radio button type selections.

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

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