File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.28: download - view: text, annotated - select for diffs
Sun Sep 16 17:26:56 2007 UTC (16 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Add ability to set/modify e-mail addresse(es) used for:
 - support e-mail (target used for form data captured" by "Ask helpdesk"
 - package updates (target used by CHECKRPMS)
 - error report forms (form data captured when an ISE occurs and use submits error report).
 - additional e-mail addresses besides default Admin E-mail address and Support E-mail Address can be specified.

Add ability to specify which authentication types are selectable when new users are added, in different contexts:
 - as an author adding co-author/assistant author
 - adding users to a course
 - as a Domain Coordinator adding users to a domain.

Filesystem authentication not included in possible selections (phasing this out as an option for new users).

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.28 2007/09/16 17:26:56 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 = "display";
   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','contacts'],$dom);
   72:     my @prefs = (
   73:       { text => 'Default color schemes',
   74:         help => 'Default_Color_Schemes',
   75:         action => 'rolecolors',
   76:         header => [{col1 => 'Student Settings',
   77:                     col2 => '',},
   78:                    {col1 => 'Coordinator Settings',
   79:                     col2 => '',},
   80:                    {col1 => 'Author Settings',
   81:                     col2 => '',},
   82:                    {col1 => 'Administrator Settings',
   83:                     col2 => '',}],
   84:         },
   85:       { text => 'Log-in page options',
   86:         help => 'Domain_Log-in_Page',
   87:         action => 'login',
   88:         header => [{col1 => 'Item',
   89:                     col2 => '',}],
   90:         },
   91:       { text => 'Default quotas for user portfolios',
   92:         help => 'Default_User_Quota',
   93:         action => 'quotas',
   94:         header => [{col1 => 'User type',
   95:                     col2 => 'Default quota'}],
   96:         },
   97:       { text => 'Auto-enrollment settings',
   98:         help => 'Domain_Auto_Enrollment',
   99:         action => 'autoenroll',
  100:         header => [{col1 => 'Configuration setting',
  101:                     col2 => 'Value(s)'}],
  102:         },
  103:       { text => 'Auto-update settings',
  104:         help => 'Domain_Auto_Update',
  105:         action => 'autoupdate',
  106:         header => [{col1 => 'Setting',
  107:                     col2 => 'Value',},
  108:                    {col1 => 'User Population',
  109:                     col2 => 'Updataeable user data'}],
  110:         },
  111:       { text => 'Institutional directory searches',
  112:         help => 'Domain_Directory_Search',
  113:         action => 'directorysrch',
  114:         header => [{col1 => 'Setting',
  115:                     col2 => 'Value',}],
  116:         },
  117:       { text => 'Contact Information',
  118:         help => 'Domain_Contact_Information',
  119:         action => 'contacts',
  120:         header => [{col1 => 'Setting',
  121:                     col2 => 'Value',}],
  122:         },
  123: 
  124:       { text => 'User creation',
  125:         help => 'Domain_User_Creation',
  126:         action => 'usercreation',
  127:         header => [{col1 => 'Setting',
  128:                     col2 => 'Value',},
  129:                    {col1 => 'Context',
  130:                     col2 => 'Assignable Authentication Types'}],
  131:         },
  132:     );
  133:     my @roles = ('student','coordinator','author','admin');
  134:     &Apache::lonhtmlcommon::add_breadcrumb
  135:     ({href=>"javascript:changePage(document.$phase,'display')",
  136:       text=>"Domain Configuration"});
  137:     my $confname = $dom.'-domainconfig';
  138:     if ($phase eq 'process') {
  139:         &Apache::lonhtmlcommon::add_breadcrumb
  140:           ({href=>"javascript:changePage(document.$phase,'$phase')",
  141:             text=>"Updated"});
  142:         &print_header($r,$phase);
  143:         foreach my $item (@prefs) {
  144:             $r->print('<h3>'.&mt($item->{'text'}).'</h3>'.
  145:                       &process_changes($r,$dom,$confname,
  146:                         $item->{'action'},\@roles,%domconfig));
  147:         }
  148:         $r->print('<p>');
  149:         &print_footer($r,$phase,'display','Back to actions menu');
  150:         $r->print('</p>');
  151:     } else {
  152:         if ($phase eq '') {
  153:             $phase = 'display';
  154:         }
  155:         my %helphash;   
  156:         my $numprefs = @prefs;
  157:         &print_header($r,$phase);
  158:         if (keys(%domconfig) == 0) {
  159:             my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
  160:             my $perlvarref = &LONCAPA::Configuration::read_conf('loncapa.conf');
  161:             my $hostid = $perlvarref->{'lonHostID'};
  162:             if ($hostid ne $primarylibserv) {
  163:                 my %designhash = &Apache::loncommon::get_domainconf($dom);
  164:                 my @loginimages = ('img','logo','domlogo');
  165:                 my $custom_img_count = 0;
  166:                 foreach my $img (@loginimages) {
  167:                     if ($designhash{$dom.'.login.'.$img} ne '') {
  168:                         $custom_img_count ++;
  169:                     }
  170:                 }
  171:                 foreach my $role (@roles) {
  172:                     if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  173:                         $custom_img_count ++;
  174:                     }
  175:                 }
  176:                 if ($custom_img_count > 0) {
  177:                     my $switch_server = &check_switchserver($dom,$confname);
  178:                     $r->print(&mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.&mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.&mt("Thereafter, you will be able to update settings from this screen when logged in to any server in the LON-CAPA network (with a Domain Coordinator role selected in the domain), although you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />'.$switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
  179:                     return OK;
  180:                 }
  181:             }
  182:         }
  183:         $r->print('<table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
  184:         foreach my $item (@prefs) {
  185:             if ($item->{'action'} eq 'login') {
  186:                 $r->print('</td><td width="6%">&nbsp;</td><td align="left" valign="top" width="47%">');
  187:             }
  188:             &print_config_box($r,$dom,$confname,$phase,$item->{'action'},
  189:                               $item,$domconfig{$item->{'action'}});
  190:         }
  191:         $r->print('
  192:       </td>
  193:     </tr>
  194:    </table>');
  195:         &print_footer($r,$phase,'process','Save changes');
  196:     }
  197:     return OK;
  198: }
  199: 
  200: sub process_changes {
  201:     my ($r,$dom,$confname,$action,$roles,%domconfig) = @_;
  202:     my $output;
  203:     if ($action eq 'login') {
  204:         $output = &modify_login($r,$dom,$confname,%domconfig);
  205:     } elsif ($action eq 'rolecolors') {
  206:         $output = &modify_rolecolors($r,$dom,$confname,$roles,
  207:                                      %domconfig);
  208:     } elsif ($action eq 'quotas') {
  209:         $output = &modify_quotas($dom,%domconfig);
  210:     } elsif ($action eq 'autoenroll') {
  211:         $output = &modify_autoenroll($dom,%domconfig);
  212:     } elsif ($action eq 'autoupdate') {
  213:         $output = &modify_autoupdate($dom,%domconfig);
  214:     } elsif ($action eq 'directorysrch') {
  215:         $output = &modify_directorysrch($dom,%domconfig);
  216:     } elsif ($action eq 'usercreation') {
  217:         $output = &modify_usercreation($dom,%domconfig);
  218:     } elsif ($action eq 'contacts') {
  219:         $output = &modify_contacts($dom,%domconfig);
  220:     }
  221:     return $output;
  222: }
  223: 
  224: sub print_config_box {
  225:     my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
  226:     $r->print('
  227:          <table class="LC_nested_outer">
  228:           <tr>
  229:            <th>'.&mt($item->{text}).'&nbsp;</th></tr>');
  230: # 
  231: # FIXME - put the help link back in when the help files exist
  232: #           <th>'.&mt($item->{text}).'&nbsp;'.
  233: #           &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
  234: #          </tr>');
  235:     if (($action eq 'autoupdate') || ($action eq 'rolecolors') || 
  236:         ($action eq 'usercreation')) {
  237:         my $colspan = ($action eq 'rolecolors')?' colspan="2"':'';
  238:         $r->print('
  239:           <tr>
  240:            <td>
  241:             <table class="LC_nested">
  242:              <tr class="LC_info_row">
  243:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[0]->{'col1'}.'</td>
  244:               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
  245:              </tr>');
  246:         if ($action eq 'autoupdate') {
  247:             $r->print(&print_autoupdate('top',$dom,$settings));
  248:         } elsif ($action eq 'usercreation') {
  249:             $r->print(&print_usercreation('top',$dom,$settings)); 
  250:         } else {
  251:             $r->print(&print_rolecolors($phase,'student',$dom,$confname,$settings));
  252:         }
  253:         $r->print('
  254:            </table>
  255:           </td>
  256:          </tr>
  257:          <tr>
  258:            <td>
  259:             <table class="LC_nested">
  260:              <tr class="LC_info_row">
  261:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[1]->{'col1'}.'</td>
  262:               <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
  263:              </tr>');
  264:         if ($action eq 'autoupdate') {
  265:             $r->print(&print_autoupdate('bottom',$dom,$settings));
  266:         } elsif ($action eq 'usercreation') {
  267:             $r->print(&print_usercreation('bottom',$dom,$settings));
  268:         } else {
  269:             $r->print(&print_rolecolors($phase,'coordinator',$dom,$confname,$settings).'
  270:            </table>
  271:           </td>
  272:          </tr>
  273:          <tr>
  274:            <td>
  275:             <table class="LC_nested">
  276:              <tr class="LC_info_row">
  277:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[2]->{'col1'}.'</td>
  278:               <td class="LC_right_item">'.$item->{'header'}->[2]->{'col2'}.'</td>
  279:              </tr>'.
  280:             &print_rolecolors($phase,'author',$dom,$confname,$settings).'
  281:            </table>
  282:           </td>
  283:          </tr>
  284:          <tr>
  285:            <td>
  286:             <table class="LC_nested">
  287:              <tr class="LC_info_row">
  288:               <td class="LC_left_item"'.$colspan.'>'.$item->{'header'}->[3]->{'col1'}.'</td>
  289:               <td class="LC_right_item">'.$item->{'header'}->[3]->{'col2'}.'</td>
  290:              </tr>'.
  291:             &print_rolecolors($phase,'admin',$dom,$confname,$settings));
  292:         }
  293:     } else {
  294:         $r->print('
  295:           <tr>
  296:            <td>
  297:             <table class="LC_nested">
  298:              <tr class="LC_info_row">');
  299:         if (($action eq 'login') || ($action eq 'directorysrch')) {
  300:             $r->print('  
  301:               <td class="LC_left_item" colspan="2">'.$item->{'header'}->[0]->{'col1'}.'</td>');
  302:         } else {
  303:             $r->print('
  304:               <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>');
  305:         }
  306:         $r->print('
  307:               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
  308:              </tr>');
  309:         if ($action eq 'login') {
  310:             $r->print(&print_login($dom,$confname,$phase,$settings));
  311:         } elsif ($action eq 'quotas') {
  312:             $r->print(&print_quotas($dom,$settings));
  313:         } elsif ($action eq 'autoenroll') {
  314:             $r->print(&print_autoenroll($dom,$settings));
  315:         } elsif ($action eq 'directorysrch') {
  316:             $r->print(&print_directorysrch($dom,$settings));
  317:         } elsif ($action eq 'contacts') {
  318:             $r->print(&print_contacts($dom,$settings));
  319:         }
  320:     }
  321:     $r->print('
  322:    </table>
  323:   </td>
  324:  </tr>
  325: </table><br />');
  326:     return;
  327: }
  328: 
  329: sub print_header {
  330:     my ($r,$phase) = @_;
  331:     my $js = '
  332: <script type="text/javascript">
  333: function changePage(formname,newphase) {
  334:     formname.phase.value = newphase;
  335:     formname.submit();
  336: }
  337: '.
  338: &color_pick_js().'
  339: </script>
  340: ';
  341:     $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
  342:                                            $js));
  343:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
  344:     $r->print('
  345: <form name="parmform" action="">
  346: <input type="hidden" name="pres_marker" />
  347: <input type="hidden" name="pres_type" />
  348: <input type="hidden" name="pres_value" />
  349: </form>
  350: ');
  351:     $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs"'.
  352:               ' enctype="multipart/form-data">');
  353:     return;
  354: }
  355: 
  356: sub print_footer {
  357:     my ($r,$phase,$newphase,$button_text) = @_;
  358:     $button_text = &mt($button_text);
  359:     $r->print('<input type="hidden" name="phase" value="" />');
  360:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  361:     if ($phase eq 'process') {
  362:         $r->print('<a href='.$dest.'>'.$button_text.'</a>');
  363:     } else {
  364:         $r->print('<input type="button" name="store" value="'.
  365:                   $button_text.'" onclick='.$dest.' />');
  366:     }
  367:     $r->print('</form>');
  368:     $r->print('<br />'.&Apache::loncommon::end_page());
  369:     return;
  370: }
  371: 
  372: sub print_login {
  373:     my ($dom,$confname,$phase,$settings) = @_;
  374:     my %choices = &login_choices();
  375:     my ($catalogon,$catalogoff,$adminmailon,$adminmailoff);
  376:     $catalogon = ' checked="checked" ';
  377:     $adminmailoff = ' checked="checked" ';
  378:     my @images = ('img','logo','domlogo');
  379:     my @bgs = ('pgbg','mainbg','sidebg');
  380:     my @links = ('link','alink','vlink');
  381:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  382:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  383:     my (%is_custom,%designs);
  384:     my %defaults = (
  385:                    font => $defaultdesign{'login.font'},
  386:                    );
  387:     foreach my $item (@images) {
  388:         $defaults{$item} = $defaultdesign{'login.'.$item};
  389:     }
  390:     foreach my $item (@bgs) {
  391:         $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
  392:     }
  393:     foreach my $item (@links) {
  394:         $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
  395:     }
  396:     if (ref($settings) eq 'HASH') {
  397:         if ($settings->{'coursecatalog'} eq '0') {
  398:             $catalogoff = $catalogon;
  399:             $catalogon = ' ';
  400:         }
  401:         if ($settings->{'adminmail'} eq '1') {
  402:             $adminmailon = $adminmailoff;
  403:             $adminmailoff = ' ';
  404:         }
  405:         foreach my $item (@images) {
  406:             if ($settings->{$item} ne '') {
  407:                 $designs{$item} = $settings->{$item};
  408:                 $is_custom{$item} = 1;
  409:             }
  410:         }
  411:         if ($settings->{'font'} ne '') {
  412:             $designs{'font'} = $settings->{'font'};
  413:             $is_custom{'font'} = 1;
  414:         }
  415:         foreach my $item (@bgs) {
  416:             if ($settings->{$item} ne '') {
  417:                 $designs{'bgs'}{$item} = $settings->{$item};
  418:                 $is_custom{$item} = 1;
  419:             }
  420:         }
  421:         foreach my $item (@links) {
  422:             if ($settings->{$item} ne '') {
  423:                 $designs{'links'}{$item} = $settings->{$item};
  424:                 $is_custom{$item} = 1;
  425:             }
  426:         }
  427:     } else {
  428:         if ($designhash{$dom.'.login.font'} ne '') {
  429:             $designs{'font'} = $designhash{$dom.'.login.font'};
  430:             $is_custom{'font'} = 1;
  431:         }
  432:         foreach my $item (@images) {
  433:             if ($designhash{$dom.'.login.'.$item} ne '') {
  434:                 $designs{$item} = $designhash{$dom.'.login.'.$item};
  435:                 $is_custom{$item} = 1;
  436:             }
  437:         }
  438:         foreach my $item (@bgs) {
  439:             if ($designhash{$dom.'.login.'.$item} ne '') {
  440:                 $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
  441:                 $is_custom{$item} = 1;
  442:             }
  443:         }
  444:         foreach my $item (@links) {
  445:             if ($designhash{$dom.'.login.'.$item} ne '') {
  446:                 $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
  447:                 $is_custom{$item} = 1;
  448:             }
  449:         }
  450:     }
  451:     my %alt_text = &Apache::lonlocal::texthash  ( img => 'Log-in banner',
  452:                                                   logo => 'Institution Logo',
  453:                                                   domlogo => 'Domain Logo');
  454:     my $itemcount = 1;
  455:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
  456:     my $datatable = 
  457:         '<tr'.$css_class.'><td colspan="2">'.$choices{'coursecatalog'}.
  458:         '</td><td>'.
  459:         '<span class="LC_nobreak"><label><input type="radio" name="coursecatalog"'.
  460:         $catalogon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  461:         '<label><input type="radio" name="coursecatalog"'.
  462:         $catalogoff.'value="0" />'.&mt('No').'</label></span></td>'.
  463:         '</tr>';
  464:     $itemcount ++;
  465:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  466:     $datatable .= '<tr'.$css_class.'>'.
  467:         '<td colspan="2">'.$choices{'adminmail'}.'</td>'.
  468:         '<td><span class="LC_nobreak">'.
  469:         '<label><input type="radio" name="adminmail"'.
  470:         $adminmailon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  471:         '<label><input type="radio" name="adminmail"'.
  472:         $adminmailoff.'value="0" />'.&mt('No').'</label></span></td></tr>';
  473:     $itemcount ++;
  474:     $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
  475:     $datatable .= '</tr></table></td></tr>';
  476:     return $datatable;
  477: }
  478: 
  479: sub login_choices {
  480:     my %choices =
  481:         &Apache::lonlocal::texthash (
  482:             coursecatalog => 'Display Course Catalog link?',
  483:             adminmail => "Display Administrator's E-mail Address?",
  484:             img => "Header",
  485:             logo => "Main Logo",
  486:             domlogo => "Domain Logo",
  487:             bgs => "Background colors",
  488:             links => "Link colors",
  489:             font => "Font color",
  490:             pgbg => "Page",
  491:             mainbg => "Main panel",
  492:             sidebg => "Side panel",
  493:             link => "Link",
  494:             alink => "Active link",
  495:             vlink => "Visited link",
  496:         );
  497:     return %choices;
  498: }
  499: 
  500: sub print_rolecolors {
  501:     my ($phase,$role,$dom,$confname,$settings) = @_;
  502:     my %choices = &color_font_choices();
  503:     my @bgs = ('pgbg','tabbg','sidebg');
  504:     my @links = ('link','alink','vlink');
  505:     my @images = ('img');
  506:     my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
  507:     my %designhash = &Apache::loncommon::get_domainconf($dom);
  508:     my %defaultdesign = %Apache::loncommon::defaultdesign;
  509:     my (%is_custom,%designs);
  510:     my %defaults = (
  511:                    img => $defaultdesign{$role.'.img'},
  512:                    font => $defaultdesign{$role.'.font'},
  513:                    );
  514:     foreach my $item (@bgs) {
  515:         $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
  516:     }
  517:     foreach my $item (@links) {
  518:         $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
  519:     }
  520:     if (ref($settings) eq 'HASH') {
  521:         if (ref($settings->{$role}) eq 'HASH') {
  522:             if ($settings->{$role}->{'img'} ne '') {
  523:                 $designs{'img'} = $settings->{$role}->{'img'};
  524:                 $is_custom{'img'} = 1;
  525:             }
  526:             if ($settings->{$role}->{'font'} ne '') {
  527:                 $designs{'font'} = $settings->{$role}->{'font'};
  528:                 $is_custom{'font'} = 1;
  529:             }
  530:             foreach my $item (@bgs) {
  531:                 if ($settings->{$role}->{$item} ne '') {
  532:                     $designs{'bgs'}{$item} = $settings->{$role}->{$item};
  533:                     $is_custom{$item} = 1;
  534:                 }
  535:             }
  536:             foreach my $item (@links) {
  537:                 if ($settings->{$role}->{$item} ne '') {
  538:                     $designs{'links'}{$item} = $settings->{$role}->{$item};
  539:                     $is_custom{$item} = 1;
  540:                 }
  541:             }
  542:         }
  543:     } else {
  544:         if ($designhash{$dom.'.'.$role.'.img'} ne '') {
  545:             $designs{img} = $designhash{$dom.'.'.$role.'.img'};
  546:             $is_custom{'img'} = 1;
  547:         }
  548:         if ($designhash{$dom.'.'.$role.'.font'} ne '') {
  549:             $designs{font} = $designhash{$dom.'.'.$role.'.font'};
  550:             $is_custom{'font'} = 1;
  551:         }
  552:         foreach my $item (@bgs) {
  553:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  554:                 $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  555:                 $is_custom{$item} = 1;
  556:             
  557:             }
  558:         }
  559:         foreach my $item (@links) {
  560:             if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
  561:                 $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
  562:                 $is_custom{$item} = 1;
  563:             }
  564:         }
  565:     }
  566:     my $itemcount = 1;
  567:     my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text);
  568:     $datatable .= '</tr></table></td></tr>';
  569:     return $datatable;
  570: }
  571: 
  572: sub display_color_options {
  573:     my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
  574:         $images,$bgs,$links,$alt_text) = @_;
  575:     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
  576:     my $datatable = '<tr'.$css_class.'>'.
  577:         '<td>'.$choices->{'font'}.'</td>';
  578:     if (!$is_custom->{'font'}) {
  579:         $datatable .=  '<td>'.&mt('Default in use:').'&nbsp;'.$defaults->{'font'}.'</td>';
  580:     } else {
  581:         $datatable .= '<td>&nbsp;</td>';
  582:     }
  583:     my $fontlink = &color_pick($phase,$role,'font',$choices->{'font'},$designs->{'font'});
  584:     $datatable .= '<td><span class="LC_nobreak">'.
  585:                   '<input type="text" size="10" name="'.$role.'_font"'.
  586:                   ' value="'.$designs->{'font'}.'" />&nbsp;'.$fontlink.
  587:                   '</span></td></tr>';
  588:     my $switchserver = &check_switchserver($dom,$confname);
  589:     foreach my $img (@{$images}) {
  590: 	$itemcount ++;
  591:         $css_class = $itemcount%2?' class="LC_odd_row"':'';
  592:         $datatable .= '<tr'.$css_class.'>'.
  593:                       '<td>'.$choices->{$img}.'</td>';
  594:         my ($imgfile, $img_import);
  595:         if ($designs->{$img} ne '') {
  596:             $imgfile = $designs->{$img};
  597: 	    $img_import = ($imgfile =~ m{^/adm/});
  598:         } else {
  599:             $imgfile = $defaults->{$img};
  600:         }
  601:         if ($imgfile) {
  602:             my ($showfile,$fullsize);
  603:             if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
  604:                 my $urldir = $1;
  605:                 my $filename = $2;
  606:                 my @info = &Apache::lonnet::stat_file($designs->{$img});
  607:                 if (@info) {
  608:                     my $thumbfile = 'tn-'.$filename;
  609:                     my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
  610:                     if (@thumb) {
  611:                         $showfile = $urldir.'/'.$thumbfile;
  612:                     } else {
  613:                         $showfile = $imgfile;
  614:                     }
  615:                 } else {
  616:                     $showfile = '';
  617:                 }
  618:             } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
  619:                 $showfile = $imgfile;
  620:                 my $imgdir = $1;
  621:                 my $filename = $2;
  622:                 if (-e "/home/httpd/html/$imgdir/tn-".$filename) {
  623:                     $showfile = "/$imgdir/tn-".$filename;
  624:                 } else {
  625:                     my $input = "/home/httpd/html".$imgfile;
  626:                     my $output = '/home/httpd/html/'.$imgdir.'/tn-'.$filename;
  627:                     if (!-e $output) {
  628:                         my ($width,$height) = &thumb_dimensions();
  629:                         my ($fullwidth,$fullheight) = &check_dimensions($input);
  630:                         if ($fullwidth ne '' && $fullheight ne '') {
  631:                             if ($fullwidth > $width && $fullheight > $height) { 
  632:                                 my $size = $width.'x'.$height;
  633:                                 system("convert -sample $size $input $output");
  634:                                 $showfile = '/'.$imgdir.'/tn-'.$filename;
  635:                             }
  636:                         }
  637:                     }
  638:                 }
  639:             }
  640:             if ($showfile) {
  641:                 $showfile = &Apache::loncommon::lonhttpdurl($showfile);
  642:                 $fullsize =  &Apache::loncommon::lonhttpdurl($imgfile);
  643:                 $datatable.= '<td>';
  644:                 if (!$is_custom->{$img}) {
  645:                     $datatable .= &mt('Default in use:').'<br />';
  646:                 }
  647: 		if ($img_import) {
  648: 		    $datatable.= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
  649: 		}
  650:                 $datatable.= '<a href="'.$fullsize.'" target="_blank"><img src="'.
  651:                              $showfile.'" alt="'.$alt_text->{$img}.
  652:                              '" border="0" /></a></td>';
  653:                 if ($is_custom->{$img}) {
  654:                     $datatable.='<td><span class="LC_nobreak"><label><input type="checkbox" name="'.
  655:                                 $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
  656:                                 '</label>&nbsp;'.&mt('Replace:').'</span><br />';
  657:                 } else {
  658:                     $datatable.='<td valign="bottom">'.&mt('Upload:').'<br />';
  659:                 }
  660:             } else {
  661:                 $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
  662:                               &mt('Upload:');
  663:             }
  664:         } else {
  665:             $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
  666:                           &mt('Upload:');
  667:         }
  668:         if ($switchserver) {
  669:             $datatable .= &mt('Upload to library server: [_1]',$switchserver);
  670:         } else {
  671:             $datatable .='&nbsp;<input type="file" name="'.$role.'_'.$img.'" />';
  672:         }
  673:         $datatable .= '</td></tr>';
  674:     }
  675:     $itemcount ++;
  676:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  677:     $datatable .= '<tr'.$css_class.'>'.
  678:                   '<td>'.$choices->{'bgs'}.'</td>';
  679:     my $bgs_def;
  680:     foreach my $item (@{$bgs}) {
  681:         if (!$is_custom->{$item}) {
  682:             $bgs_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'bgs'}{$item}.'</td>';
  683:         }
  684:     }
  685:     if ($bgs_def) {
  686:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
  687:     } else {
  688:         $datatable .= '<td>&nbsp;</td>';
  689:     }
  690:     $datatable .= '<td class="LC_right_item">'.
  691:                   '<table border="0"><tr>';
  692:     foreach my $item (@{$bgs}) {
  693:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
  694:         $datatable .= '<td align="center">'.$link;
  695:         if ($designs->{'bgs'}{$item}) {
  696:             $datatable .= '<span style="background-color:'.$designs->{'bgs'}{$item}.'width: 10px">&nbsp;</span>';
  697:         }
  698:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'bgs'}{$item}.
  699:                       '" /></td>';
  700:     }
  701:     $datatable .= '</tr></table></td></tr>';
  702:     $itemcount ++;
  703:     $css_class = $itemcount%2?' class="LC_odd_row"':'';
  704:     $datatable .= '<tr'.$css_class.'>'.
  705:                   '<td>'.$choices->{'links'}.'</td>';
  706:     my $links_def;
  707:     foreach my $item (@{$links}) {
  708:         if (!$is_custom->{$item}) {
  709:             $links_def .= '<td>'.$choices->{$item}.'<br />'.$defaults->{'links'}{$item}.'</td>';
  710:         }
  711:     }
  712:     if ($links_def) {
  713:         $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
  714:     } else {
  715:         $datatable .= '<td>&nbsp;</td>';
  716:     }
  717:     $datatable .= '<td class="LC_right_item">'.
  718:                   '<table border="0"><tr>';
  719:     foreach my $item (@{$links}) {
  720:         $datatable .= '<td align="center">';
  721:         my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'links'}{$item});
  722:         if ($designs->{'links'}{$item}) {
  723:             $datatable.='<span style="color: '.$designs->{'links'}{$item}.';">'.
  724:                         $link.'</span>';
  725:         } else {
  726:             $datatable .= $link;
  727:         }
  728:         $datatable .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.$designs->{'links'}{$item}.
  729:                       '" /></td>';
  730:     }
  731:     return $datatable;
  732: }
  733: 
  734: sub color_pick {
  735:     my ($phase,$role,$item,$desc,$curcol) = @_;
  736:     my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
  737:                "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
  738:                ');">'.$desc.'</a>';
  739:     return $link;
  740: }
  741: 
  742: sub color_pick_js {
  743:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  744:     my $output = <<"ENDCOL";
  745:     function pclose() {
  746:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
  747:         parmwin.close();
  748:     }
  749: 
  750:     $pjump_def
  751: 
  752:     function psub() {
  753:         pclose();
  754:         if (document.parmform.pres_marker.value!='') {
  755:             if (document.parmform.pres_type.value!='') {
  756:                 eval('document.display.'+
  757:                      document.parmform.pres_marker.value+
  758:                      '.value=document.parmform.pres_value.value;');
  759:             }
  760:         } else {
  761:             document.parmform.pres_value.value='';
  762:             document.parmform.pres_marker.value='';
  763:         }
  764:     }
  765: ENDCOL
  766:     return $output;
  767: }
  768: 
  769: sub print_quotas {
  770:     my ($dom,$settings) = @_;
  771:     my $datatable;
  772:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
  773:     my $typecount = 0;
  774:     my $css_class;
  775:     if (ref($types) eq 'ARRAY') {
  776:         foreach my $type (@{$types}) {
  777:             if (defined($usertypes->{$type})) {
  778:                 $typecount ++;
  779:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
  780:                 $datatable .= '<tr'.$css_class.'>'. 
  781:                               '<td>'.$usertypes->{$type}.'</td>'.
  782:                               '<td class="LC_right_item"><span class="LC_nobreak">'.
  783:                               '<input type="text" name="quota_'.$type.
  784:                               '" value="'.$settings->{$type}.
  785:                               '" size="5" /> Mb</span></td></tr>';
  786:             }
  787:         }
  788:     }
  789:     my $defaultquota = '20';
  790:     if (ref($settings) eq 'HASH') {
  791:         if (defined($settings->{'default'})) {
  792:             $defaultquota = $settings->{'default'};
  793:         }
  794:     }
  795:     $typecount ++;
  796:     $css_class = $typecount%2?' class="LC_odd_row"':'';
  797:     $datatable .= '<tr'.$css_class.'>'.
  798:                   '<td>'.$othertitle.'</td>'.
  799:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
  800:                   '<input type="text" name="defaultquota" value="'.
  801:                   $defaultquota.'" size="5" /> Mb</span></td></tr>';
  802:     return $datatable;
  803: }
  804: 
  805: sub print_autoenroll {
  806:     my ($dom,$settings) = @_;
  807:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
  808:     my ($defdom,$runon,$runoff);
  809:     if (ref($settings) eq 'HASH') {
  810:         if (exists($settings->{'run'})) {
  811:             if ($settings->{'run'} eq '0') {
  812:                 $runoff = ' checked="checked" ';
  813:                 $runon = ' ';
  814:             } else {
  815:                 $runon = ' checked="checked" ';
  816:                 $runoff = ' ';
  817:             }
  818:         } else {
  819:             if ($autorun) {
  820:                 $runon = ' checked="checked" ';
  821:                 $runoff = ' ';
  822:             } else {
  823:                 $runoff = ' checked="checked" ';
  824:                 $runon = ' ';
  825:             }
  826:         }
  827:         if (exists($settings->{'sender_domain'})) {
  828:             $defdom = $settings->{'sender_domain'};
  829:         }
  830:     } else {
  831:         if ($autorun) {
  832:             $runon = ' checked="checked" ';
  833:             $runoff = ' ';
  834:         } else {
  835:             $runoff = ' checked="checked" ';
  836:             $runon = ' ';
  837:         }
  838:     }
  839:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
  840:     my $datatable='<tr class="LC_odd_row">'.
  841:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
  842:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
  843:                   '<input type="radio" name="autoenroll_run"'.
  844:                   $runon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  845:                   '<label><input type="radio" name="autoenroll_run"'.
  846:                   $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
  847:                   '</tr><tr>'.
  848:                   '<td>'.&mt('Notification messages - sender').
  849:                   '</td><td class="LC_right_item"><span class="LC_nobreak">'.
  850:                   &mt('username').':&nbsp;'.
  851:                   '<input type="text" name="sender_uname" value="'.
  852:                   $settings->{'sender_uname'}.
  853:                   '" size="10" />&nbsp;&nbsp;'.&mt('domain').
  854:                   ':&nbsp;'.$domform.'</span></td></tr>';
  855:     return $datatable;
  856: }
  857: 
  858: sub print_autoupdate {
  859:     my ($position,$dom,$settings) = @_;
  860:     my $datatable;
  861:     if ($position eq 'top') {
  862:         my $updateon = ' ';
  863:         my $updateoff = ' checked="checked" ';
  864:         my $classlistson = ' ';
  865:         my $classlistsoff = ' checked="checked" ';
  866:         if (ref($settings) eq 'HASH') {
  867:             if ($settings->{'run'} eq '1') {
  868:                 $updateon = $updateoff;
  869:                 $updateoff = ' ';
  870:             }
  871:             if ($settings->{'classlists'} eq '1') {
  872:                 $classlistson = $classlistsoff;
  873:                 $classlistsoff = ' ';
  874:             }
  875:         }
  876:         my %title = (
  877:                    run => 'Auto-update active?',
  878:                    classlists => 'Update information in classlists?',
  879:                     );
  880:         $datatable = '<tr class="LC_odd_row">'. 
  881:                   '<td>'.&mt($title{'run'}).'</td>'.
  882:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
  883:                   '<input type="radio" name="autoupdate_run"'.
  884:                   $updateon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  885:                   '<label><input type="radio" name="autoupdate_run"'.
  886:                   $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
  887:                   '</tr><tr>'.
  888:                   '<td>'.&mt($title{'classlists'}).'</td>'.
  889:                   '<td class="LC_right_item"><span class="LC_nobreak">'.
  890:                   '<label><input type="radio" name="classlists"'.
  891:                   $classlistson.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  892:                   '<label><input type="radio" name="classlists"'.
  893:                   $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
  894:                   '</tr>';
  895:     } else {
  896:         my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
  897:         my @fields = ('lastname','firstname','middlename','gen',
  898:                       'permanentemail','id');
  899:         my %fieldtitles = &Apache::lonlocal::texthash (
  900:                             id => 'Student/Employee ID',
  901:                             permanentemail => 'E-mail address',
  902:                             lastname => 'Last Name',
  903:                             firstname => 'First Name',
  904:                             middlename => 'Middle Name',
  905:                             gen => 'Generation',
  906:                       );
  907:         my $numrows = 0;
  908:         if (ref($types) eq 'ARRAY') {
  909:             if (@{$types} > 0) {
  910:                 $datatable = 
  911:                     &usertype_update_row($settings,$usertypes,\%fieldtitles,
  912:                                          \@fields,$types,\$numrows);
  913:             }
  914:         }
  915:         $datatable .= 
  916:             &usertype_update_row($settings,{'default' => $othertitle},
  917:                                  \%fieldtitles,\@fields,['default'],
  918:                                  \$numrows);
  919:     }
  920:     return $datatable;
  921: }
  922: 
  923: sub print_directorysrch {
  924:     my ($dom,$settings) = @_;
  925:     my $srchon = ' ';
  926:     my $srchoff = ' checked="checked" ';
  927:     my ($exacton,$containson,$beginson);
  928:     my $localon = ' ';
  929:     my $localoff = ' checked="checked" ';
  930:     if (ref($settings) eq 'HASH') {
  931:         if ($settings->{'available'} eq '1') {
  932:             $srchon = $srchoff;
  933:             $srchoff = ' ';
  934:         }
  935:         if ($settings->{'localonly'} eq '1') {
  936:             $localon = $localoff;
  937:             $localoff = ' ';
  938:         }
  939:         if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
  940:             foreach my $type (@{$settings->{'searchtypes'}}) {
  941:                 if ($type eq 'exact') {
  942:                     $exacton = ' checked="checked" ';
  943:                 } elsif ($type eq 'contains') {
  944:                     $containson = ' checked="checked" ';
  945:                 } elsif ($type eq 'begins') {
  946:                     $beginson = ' checked="checked" ';
  947:                 }
  948:             }
  949:         } else {
  950:             if ($settings->{'searchtypes'} eq 'exact') {
  951:                 $exacton = ' checked="checked" ';
  952:             } elsif ($settings->{'searchtypes'} eq 'contains') {
  953:                 $containson = ' checked="checked" ';
  954:             } elsif ($settings->{'searchtypes'} eq 'specify') {
  955:                 $exacton = ' checked="checked" ';
  956:                 $containson = ' checked="checked" ';
  957:             }
  958:         }
  959:     }
  960:     my ($searchtitles,$titleorder) = &sorted_searchtitles();
  961:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
  962: 
  963:     my $numinrow = 4;
  964:     my $cansrchrow = 0;
  965:     my $datatable='<tr class="LC_odd_row">'.
  966:                   '<td colspan="2">'.&mt('Directory search available?').'</td>'.
  967:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
  968:                   '<input type="radio" name="dirsrch_available"'.
  969:                   $srchon.' value="1" />'.&mt('Yes').'</label>&nbsp;'.
  970:                   '<label><input type="radio" name="dirsrch_available"'.
  971:                   $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
  972:                   '</tr><tr>'.
  973:                   '<td colspan="2">'.&mt('Other domains can search?').'</td>'.
  974:                   '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
  975:                   '<input type="radio" name="dirsrch_localonly"'.
  976:                   $localoff.' value="0" />'.&mt('Yes').'</label>&nbsp;'.
  977:                   '<label><input type="radio" name="dirsrch_localonly"'.
  978:                   $localon.' value="1" />'.&mt('No').'</label></span></td>'.
  979:                   '</tr>';
  980:     if (ref($usertypes) eq 'HASH') {
  981:         if (keys(%{$usertypes}) > 0) {
  982:             $datatable .= &users_cansearch_row($settings,$types,$usertypes,$dom,
  983:                                                $numinrow,$othertitle);
  984:             $cansrchrow = 1;
  985:         }
  986:     }
  987:     if ($cansrchrow) {
  988:         $datatable .= '<tr>';
  989:     } else {
  990:         $datatable .= '<tr class="LC_odd_row">';
  991:     }
  992:     $datatable .= '<td>'.&mt('Supported search methods').
  993:                   '</td><td class="LC_left_item" colspan="2"><table><tr>';
  994:     foreach my $title (@{$titleorder}) {
  995:         if (defined($searchtitles->{$title})) {
  996:             my $check = ' ';
  997:             if (ref($settings->{'searchby'}) eq 'ARRAY') {
  998:                 if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
  999:                     $check = ' checked="checked" ';
 1000:                 }
 1001:             }
 1002:             $datatable .= '<td class="LC_left_item">'.
 1003:                           '<span class="LC_nobreak"><label>'.
 1004:                           '<input type="checkbox" name="searchby" '.
 1005:                           'value="'.$title.'"'.$check.'/>'.
 1006:                           $searchtitles->{$title}.'</label></span></td>';
 1007:         }
 1008:     }
 1009:     $datatable .= '</tr></table></td></tr>';
 1010:     if ($cansrchrow) {
 1011:         $datatable .= '<tr class="LC_odd_row">';
 1012:     } else {
 1013:         $datatable .= '<tr>';
 1014:     }
 1015:     $datatable .= '<td>'.&mt('Search latitude').'</td>'.   
 1016:                   '<td class="LC_left_item" colspan="2">'.
 1017:                   '<span class="LC_nobreak"><label>'.
 1018:                   '<input type="checkbox" name="searchtypes" '.
 1019:                   $exacton.' value="exact" />'.&mt('Exact match').
 1020:                   '</label>&nbsp;'.
 1021:                   '<label><input type="checkbox" name="searchtypes" '.
 1022:                   $beginson.' value="begins" />'.&mt('Begins with').
 1023:                   '</label>&nbsp;'.
 1024:                   '<label><input type="checkbox" name="searchtypes" '.
 1025:                   $containson.' value="contains" />'.&mt('Contains').
 1026:                   '</label></span></td></tr>';
 1027:     return $datatable;
 1028: }
 1029: 
 1030: sub print_contacts {
 1031:     my ($dom,$settings) = @_;
 1032:     my $datatable;
 1033:     my @contacts = ('adminemail','supportemail');
 1034:     my (%checked,%to,%otheremails);
 1035:     my @mailings = ('errormail','packagesmail','helpdeskmail');
 1036:     foreach my $type (@mailings) {
 1037:         $otheremails{$type} = '';
 1038:     }
 1039:     if (ref($settings) eq 'HASH') {
 1040:         foreach my $item (@contacts) {
 1041:             if (exists($settings->{$item})) {
 1042:                 $to{$item} = $settings->{$item};
 1043:             }
 1044:         }
 1045:         foreach my $type (@mailings) {
 1046:             if (exists($settings->{$type})) {
 1047:                 if (ref($settings->{$type}) eq 'HASH') {
 1048:                     foreach my $item (@contacts) {
 1049:                         if ($settings->{$type}{$item}) {
 1050:                             $checked{$type}{$item} = ' checked="checked" ';
 1051:                         }
 1052:                     }
 1053:                     $otheremails{$type} = $settings->{$type}{'others'};
 1054:                 }
 1055:             }
 1056:         }
 1057:     } else {
 1058:         $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 1059:         $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 1060:         $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
 1061:         $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
 1062:         $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" '; 
 1063:     }
 1064:     my ($titles,$short_titles) = &contact_titles();
 1065:     my $rownum = 0;
 1066:     my $css_class;
 1067:     foreach my $item (@contacts) {
 1068:         if ($rownum%2) {
 1069:             $css_class = '';
 1070:         } else {
 1071:             $css_class = ' class="LC_odd_row" ';
 1072:         }
 1073:         $datatable .= '<tr'.$css_class.' ">'. 
 1074:                   '<td>'.$titles->{$item}.'</td>'.
 1075:                   '<td class="LC_right_item">'.
 1076:                   '<input type="text" name="'.$item.'" value="'.
 1077:                   $to{$item}.'" /></td></tr>';
 1078:         $rownum ++;
 1079:     }
 1080:     foreach my $type (@mailings) {
 1081:         if ($rownum%2) {
 1082:             $css_class = '';
 1083:         } else {
 1084:             $css_class = ' class="LC_odd_row" ';
 1085:         }
 1086:         $datatable .= '<tr'.$css_class.'>'.
 1087:                       '<td>'.$titles->{$type}.': </td>'.
 1088:                       '<td class="LC_left_item">'.
 1089:                       '<span class="LC_nobreak">';
 1090:         foreach my $item (@contacts) {
 1091:             $datatable .= '<label>'.
 1092:                           '<input type="checkbox" name="'.$type.'"'.
 1093:                           $checked{$type}{$item}.
 1094:                           ' value="'.$item.'" />'.$short_titles->{$item}.
 1095:                           '</label>&nbsp;';
 1096:         }
 1097:         $datatable .= '</span><br />'.&mt('Others').':&nbsp;&nbsp;'.
 1098:                       '<input type="text" name="'.$type.'_others" '.
 1099:                       'value="'.$otheremails{$type}.'"  />'.
 1100:                       '</td></tr>'."\n";
 1101:         $rownum ++;
 1102:     }
 1103:     return $datatable;
 1104: }
 1105: 
 1106: sub contact_titles {
 1107:     my %titles = &Apache::lonlocal::texthash (
 1108:                    'supportemail' => 'Support E-mail address',
 1109:                    'adminemail'    => 'Default Server Admin E-mail address',
 1110:                    'errormail'    => 'Error reports to be e-mailed to',
 1111:                    'packagesmail' => 'Package update alerts to be e-mailed to',
 1112:                    'helpdeskmail' => 'Helpdesk requests to be e-mailed to'
 1113:                  );
 1114:     my %short_titles = &Apache::lonlocal::texthash (
 1115:                            adminemail   => 'Admin E-mail address',
 1116:                            supportemail => 'Support E-mail',
 1117:                        );   
 1118:     return (\%titles,\%short_titles);
 1119: }
 1120: 
 1121: sub print_usercreation {
 1122:     my ($position,$dom,$settings) = @_;
 1123:     my $numinrow = 4;
 1124:     my $rowcount = 0;
 1125:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom);
 1126:     my $datatable;
 1127:     my %lt = &Apache::lonlocal::texthash (
 1128:                         nondc => 'User creation other than by Domain Coordinator: ',
 1129:                         author => 'When adding a co-author/assistant author',
 1130:                         course => 'When adding users to a course',
 1131:     );
 1132:     if ($position eq 'top') {
 1133:         my %checked;
 1134:         if (ref($settings) eq 'HASH') {
 1135:             if (ref($settings->{'cancreate'}) eq 'ARRAY') {
 1136:                 foreach my $item (@{$settings->{'cancreate'}}) {
 1137:                     $checked{$item} = ' checked="checked" ';
 1138:                 }
 1139:             }
 1140:         }
 1141:         $datatable = '<tr class="LC_odd_row">'.
 1142:                      '<td>'.$lt{'nondc'}.'</td>'.
 1143:                      '<td class="LC_left_item"><table>';
 1144:         foreach my $item ('author','course') {
 1145:             $datatable .= '<tr><td><span class="LC_nobreak"><label>'.
 1146:                           '<input type="checkbox" name="can_createuser" '.
 1147:                           $checked{$item}.' value="'.$item.'" />'.
 1148:                           $lt{$item}.'</label><span></td></tr>';
 1149:         }
 1150:         $datatable .= '</table></td></tr>';
 1151:         $rowcount ++;
 1152:         if (ref($rules) eq 'HASH') {
 1153:             if (keys(%{$rules}) > 0) {
 1154:                 $datatable .= &username_formats_row($settings,$rules,
 1155:                                                     $ruleorder,$numinrow);
 1156:                 $rowcount ++;
 1157:             }
 1158:         }
 1159:     } else {
 1160:         my @contexts = ('author','course','domain');
 1161:         my @authtypes = ('int','krb4','krb5','loc');
 1162:         my %checked;
 1163:         if (ref($settings) eq 'HASH') {
 1164:             if (ref($settings->{'authtypes'}) eq 'HASH') {
 1165:                 foreach my $item (@contexts) {
 1166:                     if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
 1167:                         foreach my $auth (@authtypes) {
 1168:                             if ($settings->{'authtypes'}{$item}{$auth}) {
 1169:                                 $checked{$item}{$auth} = ' checked="checked" ';
 1170:                             }
 1171:                         }
 1172:                     }
 1173:                 }
 1174:             }
 1175:         }
 1176:         my @authtypes = ('int','krb4','krb5','loc');
 1177:         my %title = &context_names();
 1178:         my %authname = &authtype_names();
 1179:         my $rownum = 0;
 1180:         my $css_class; 
 1181:         foreach my $item (@contexts) {
 1182:             if ($rownum%2) {
 1183:                 $css_class = '';
 1184:             } else {
 1185:                 $css_class = ' class="LC_odd_row" ';
 1186:             }
 1187:             $datatable .=   '<tr'.$css_class.'">'.
 1188:                             '<td>'.$title{$item}.
 1189:                             '</td><td class="LC_left_item">'.
 1190:                             '<span class="LC_nobreak">';
 1191:             foreach my $auth (@authtypes) {
 1192:                 $datatable .= '<label>'. 
 1193:                               '<input type="checkbox" name="'.$item.'_auth" '.
 1194:                               $checked{$item}{$auth}.' value="'.$auth.'" />'.
 1195:                               $authname{$auth}.'</label>&nbsp;';
 1196:             }
 1197:             $datatable .= '</span></td></tr>';
 1198:             $rownum ++;
 1199:         }
 1200:     }
 1201:     return $datatable;
 1202: }
 1203: 
 1204: sub username_formats_row {
 1205:     my ($settings,$rules,$ruleorder,$numinrow) = @_;
 1206:     my $output =  '<tr>'.
 1207:                   '<td>'.&mt('Format rules to check for new usernames: ').
 1208:                   '</td><td class="LC_left_item" colspan="2"><table>';
 1209:     my $rem;
 1210:     if (ref($ruleorder) eq 'ARRAY') {
 1211:         for (my $i=0; $i<@{$ruleorder}; $i++) {
 1212:             if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
 1213:                 my $rem = $i%($numinrow);
 1214:                 if ($rem == 0) {
 1215:                     if ($i > 0) {
 1216:                         $output .= '</tr>';
 1217:                     }
 1218:                     $output .= '<tr>';
 1219:                 }
 1220:                 my $check = ' ';
 1221:                 if (ref($settings->{'username_rule'}) eq 'ARRAY') {
 1222:                     if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{'username_rule'}})) {
 1223:                         $check = ' checked="checked" ';
 1224:                     }
 1225:                 }
 1226:                 $output .= '<td class="LC_left_item">'.
 1227:                            '<span class="LC_nobreak"><label>'.
 1228:                            '<input type="checkbox" name="username_rule" '.
 1229:                            'value="'.$ruleorder->[$i].'"'.$check.'/>'.
 1230:                            $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
 1231:             }
 1232:         }
 1233:         $rem = @{$ruleorder}%($numinrow);
 1234:     }
 1235:     my $colsleft = $numinrow - $rem;
 1236:     if ($colsleft > 1 ) {
 1237:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
 1238:                    '&nbsp;</td>';
 1239:     } elsif ($colsleft == 1) {
 1240:         $output .= '<td class="LC_left_item">&nbsp;</td>';
 1241:     }
 1242:     $output .= '</tr></table></td></tr>';
 1243:     return $output;
 1244: }
 1245: 
 1246: sub authtype_names {
 1247:     my %lt = &Apache::lonlocal::texthash(
 1248:                       int    => 'Internal',
 1249:                       krb4   => 'Kerberos 4',
 1250:                       krb5   => 'Kerberos 5',
 1251:                       loc    => 'Local',
 1252:                   );
 1253:     return %lt;
 1254: }
 1255: 
 1256: sub context_names {
 1257:     my %context_title = &Apache::lonlocal::texthash(
 1258:        author => 'Creating users when an Author',
 1259:        course => 'Creating users when in a course',
 1260:        domain => 'Creating users when a Domain Coordinator',
 1261:     );
 1262:     return %context_title;
 1263: }
 1264: 
 1265: 
 1266: sub users_cansearch_row {
 1267:     my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle) = @_;
 1268:     my $output =  '<tr class="LC_odd_row">'.
 1269:                   '<td>'.&mt('Users allowed to search').' ('.$dom.')'.
 1270:                   '</td><td class="LC_left_item" colspan="2"><table>';
 1271:     my $rem;
 1272:     if (ref($types) eq 'ARRAY') {
 1273:         for (my $i=0; $i<@{$types}; $i++) {
 1274:             if (defined($usertypes->{$types->[$i]})) {
 1275:                 my $rem = $i%($numinrow);
 1276:                 if ($rem == 0) {
 1277:                     if ($i > 0) {
 1278:                         $output .= '</tr>';
 1279:                     }
 1280:                     $output .= '<tr>';
 1281:                 }
 1282:                 my $check = ' ';
 1283:                 if (ref($settings->{'cansearch'}) eq 'ARRAY') {
 1284:                     if (grep(/^\Q$types->[$i]\E$/,@{$settings->{'cansearch'}})) {
 1285:                         $check = ' checked="checked" ';
 1286:                     }
 1287:                 }
 1288:                 $output .= '<td class="LC_left_item">'.
 1289:                            '<span class="LC_nobreak"><label>'.
 1290:                            '<input type="checkbox" name="cansearch" '.
 1291:                            'value="'.$types->[$i].'"'.$check.'/>'.
 1292:                            $usertypes->{$types->[$i]}.'</label></span></td>';
 1293:             }
 1294:         }
 1295:        
 1296:         $rem = @{$types}%($numinrow);
 1297:     }
 1298:     my $colsleft = $numinrow - $rem;
 1299:     if ($colsleft > 1) {
 1300:         $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
 1301:     } else {
 1302:         $output .= '<td class="LC_left_item">';
 1303:     }
 1304:     my $defcheck = ' ';
 1305:     if (ref($settings->{'cansearch'}) eq 'ARRAY') {
 1306:         if (grep(/^default$/,@{$settings->{'cansearch'}})) {
 1307:             $defcheck = ' checked="checked" ';
 1308:         }
 1309:     }
 1310:     $output .= '<span class="LC_nobreak"><label>'.
 1311:                '<input type="checkbox" name="cansearch" '.
 1312:                'value="default"'.$defcheck.'/>'.
 1313:                $othertitle.'</label></span></td>'.
 1314:                '</tr></table></td></tr>';
 1315:     return $output;
 1316: }
 1317: 
 1318: sub sorted_inst_types {
 1319:     my ($dom) = @_;
 1320:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
 1321:     my $othertitle = &mt('All users');
 1322:     my @types;
 1323:     if (ref($order) eq 'ARRAY') {
 1324:         @types = @{$order};
 1325:     }
 1326:     if (@types == 0) {
 1327:         if (ref($usertypes) eq 'HASH') {
 1328:             @types = sort(keys(%{$usertypes}));
 1329:         }
 1330:     }
 1331:     if (keys(%{$usertypes}) > 0) {
 1332:         $othertitle = &mt('Other users');
 1333:     }
 1334:     return ($othertitle,$usertypes,\@types);
 1335: }
 1336: 
 1337: sub sorted_searchtitles {
 1338:     my %searchtitles = &Apache::lonlocal::texthash(
 1339:                          'uname' => 'username',
 1340:                          'lastname' => 'last name',
 1341:                          'lastfirst' => 'last name, first name',
 1342:                      );
 1343:     my @titleorder = ('uname','lastname','lastfirst');
 1344:     return (\%searchtitles,\@titleorder);
 1345: }
 1346: 
 1347: sub sorted_searchtypes {
 1348:     my %srchtypes_desc = (
 1349:                            exact    => 'is exact match',
 1350:                            contains => 'contains ..',
 1351:                            begins   => 'begins with ..',
 1352:                          );
 1353:     my @srchtypeorder = ('exact','begins','contains');
 1354:     return (\%srchtypes_desc,\@srchtypeorder);
 1355: }
 1356: 
 1357: sub usertype_update_row {
 1358:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
 1359:     my $datatable;
 1360:     my $numinrow = 4;
 1361:     foreach my $type (@{$types}) {
 1362:         if (defined($usertypes->{$type})) {
 1363:             $$rownums ++;
 1364:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
 1365:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
 1366:                           '</td><td class="LC_left_item"><table>';
 1367:             for (my $i=0; $i<@{$fields}; $i++) {
 1368:                 my $rem = $i%($numinrow);
 1369:                 if ($rem == 0) {
 1370:                     if ($i > 0) {
 1371:                         $datatable .= '</tr>';
 1372:                     }
 1373:                     $datatable .= '<tr>';
 1374:                 }
 1375:                 my $check = ' ';
 1376:                 if (ref($settings->{'fields'}) eq 'HASH') {
 1377:                     if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
 1378:                         if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
 1379:                             $check = ' checked="checked" ';
 1380:                         }
 1381:                     }
 1382:                 }
 1383: 
 1384:                 if ($i == @{$fields}-1) {
 1385:                     my $colsleft = $numinrow - $rem;
 1386:                     if ($colsleft > 1) {
 1387:                         $datatable .= '<td colspan="'.$colsleft.'">';
 1388:                     } else {
 1389:                         $datatable .= '<td>';
 1390:                     }
 1391:                 } else {
 1392:                     $datatable .= '<td>';
 1393:                 }
 1394:                 $datatable .= '<span class="LC_nobreak"><label>'.
 1395:                               '<input type="checkbox" name="updateable_'.$type.
 1396:                               '_'.$fields->[$i].'" value="1"'.$check.'/>'.
 1397:                               $fieldtitles->{$fields->[$i]}.'</label></span></td>';
 1398:             }
 1399:             $datatable .= '</tr></table></td></tr>';
 1400:         }
 1401:     }
 1402:     return $datatable;
 1403: }
 1404: 
 1405: sub modify_login {
 1406:     my ($r,$dom,$confname,%domconfig) = @_;
 1407:     my ($resulttext,$errors,$colchgtext,%changes,%colchanges);
 1408:     my %title = ( coursecatalog => 'Display course catalog',
 1409:                   adminmail => 'Display administrator E-mail address');
 1410:     my @offon = ('off','on');
 1411:     my %loginhash;
 1412:     ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
 1413:                                            \%domconfig,\%loginhash);
 1414:     $loginhash{login}{coursecatalog} = $env{'form.coursecatalog'};
 1415:     $loginhash{login}{adminmail} = $env{'form.adminmail'};
 1416:     if (ref($colchanges{'login'}) eq 'HASH') {  
 1417:         $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
 1418:                                          \%loginhash);
 1419:     }
 1420:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
 1421:                                              $dom);
 1422:     if ($putresult eq 'ok') {
 1423:         if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
 1424:             ($env{'form.coursecatalog'} eq '1')) {
 1425:             $changes{'coursecatalog'} = 1;
 1426:         } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
 1427:                  $domconfig{'login'}{'coursecatalog'} eq '1') &&
 1428:                  ($env{'form.coursecatalog'} eq '0')) {
 1429:             $changes{'coursecatalog'} = 1;
 1430:         }
 1431:         if (($domconfig{'login'}{'adminmail'} eq '1') &&
 1432:                 ($env{'form.adminmail'} eq '0')) {
 1433:             $changes{'adminmail'} = 1;
 1434:         } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
 1435:                  $domconfig{'login'}{'adminmail'} eq '0') &&
 1436:                  ($env{'form.adminmail'} eq '1')) {
 1437:             $changes{'adminmail'} = 1;
 1438:         }
 1439:         if (keys(%changes) > 0 || $colchgtext) {
 1440:             $resulttext = &mt('Changes made:').'<ul>';
 1441:             foreach my $item (sort(keys(%changes))) {
 1442:                 $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
 1443:             }
 1444:             $resulttext .= $colchgtext.'</ul>';
 1445:         } else {
 1446:             $resulttext = &mt('No changes made to log-in page settings');
 1447:         }
 1448:     } else {
 1449:         $resulttext = '<span class="LC_error">'.
 1450: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 1451:     }
 1452:     if ($errors) {
 1453:         $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
 1454:                        $errors.'</ul>';
 1455:     }
 1456:     return $resulttext;
 1457: }
 1458: 
 1459: sub color_font_choices {
 1460:     my %choices =
 1461:         &Apache::lonlocal::texthash (
 1462:             img => "Header",
 1463:             bgs => "Background colors",
 1464:             links => "Link colors",
 1465:             font => "Font color",
 1466:             pgbg => "Page",
 1467:             tabbg => "Header",
 1468:             sidebg => "Border",
 1469:             link => "Link",
 1470:             alink => "Active link",
 1471:             vlink => "Visited link",
 1472:         );
 1473:     return %choices;
 1474: }
 1475: 
 1476: sub modify_rolecolors {
 1477:     my ($r,$dom,$confname,$roles,%domconfig) = @_;
 1478:     my ($resulttext,%rolehash);
 1479:     $rolehash{'rolecolors'} = {};
 1480:     my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
 1481:                          $domconfig{'rolecolors'},$rolehash{'rolecolors'});
 1482:     my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
 1483:                                              $dom);
 1484:     if ($putresult eq 'ok') {
 1485:         if (keys(%changes) > 0) {
 1486:             $resulttext = &display_colorchgs($dom,\%changes,$roles,
 1487:                                              $rolehash{'rolecolors'});
 1488:         } else {
 1489:             $resulttext = &mt('No changes made to default color schemes');
 1490:         }
 1491:     } else {
 1492:         $resulttext = '<span class="LC_error">'.
 1493: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 1494:     }
 1495:     if ($errors) {
 1496:         $resulttext .= &mt('The following errors occurred: ').'<ul>'.
 1497:                        $errors.'</ul>';
 1498:     }
 1499:     return $resulttext;
 1500: }
 1501: 
 1502: sub modify_colors {
 1503:     my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
 1504:     my (%changes,%choices);
 1505:     my @bgs = ('pgbg','mainbg','sidebg');
 1506:     my @links = ('link','alink','vlink');
 1507:     my @images;
 1508:     my $servadm = $r->dir_config('lonAdmEMail');
 1509:     my $errors;
 1510:     foreach my $role (@{$roles}) {
 1511:         if ($role eq 'login') {
 1512:             %choices = &login_choices();
 1513:         } else {
 1514:             %choices = &color_font_choices();
 1515:         }
 1516:         if ($role eq 'login') {
 1517:             @images = ('img','logo','domlogo');
 1518:         } else {
 1519:             @images = ('img');
 1520:         }
 1521:         $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
 1522:         foreach my $item (@bgs,@links) {
 1523:             $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
 1524:         }
 1525:         my ($configuserok,$author_ok,$switchserver,%currroles);
 1526:         my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
 1527:         ($configuserok,%currroles) = &check_configuser($uhome,$dom,
 1528:                                                        $confname,$servadm);
 1529:         if ($configuserok eq 'ok') {
 1530:             $switchserver = &check_switchserver($dom,$confname);
 1531:             if ($switchserver eq '') {
 1532:                 $author_ok = &check_authorstatus($dom,$confname,%currroles);
 1533:             }
 1534:         }
 1535:         my ($width,$height) = &thumb_dimensions();
 1536:         foreach my $img (@images) {
 1537: 	    if ( ! $env{'form.'.$role.'_'.$img.'.filename'} 
 1538: 		 && !defined($domconfig->{$role}{$img})
 1539: 		 && !$env{'form.'.$role.'_del_'.$img}
 1540: 		 && $env{'form.'.$role.'_import_'.$img}) {
 1541: 		# import the old configured image from the .tab setting
 1542: 		# if they haven't provided a new one 
 1543: 		$domconfig->{$role}{$img} = 
 1544: 		    $env{'form.'.$role.'_import_'.$img};
 1545: 	    }
 1546:             if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
 1547:                 my $error;
 1548:                 if ($configuserok eq 'ok') {
 1549:                     if ($switchserver) {
 1550:                         $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
 1551:                     } else {
 1552:                         if ($author_ok eq 'ok') {
 1553:                             my ($result,$logourl) = 
 1554:                                 &publishlogo($r,'upload',$role.'_'.$img,
 1555:                                            $dom,$confname,$img,$width,$height);
 1556:                             if ($result eq 'ok') {
 1557:                                 $confhash->{$role}{$img} = $logourl;
 1558:                                 $changes{$role}{'images'}{$img} = 1;
 1559:                             } else {
 1560:                                 $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);
 1561:                             }
 1562:                         } else {
 1563:                             $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);
 1564:                         }
 1565:                     }
 1566:                 } else {
 1567:                     $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);
 1568:                 }
 1569:                 if ($error) {
 1570:                     &Apache::lonnet::logthis($error);
 1571:                     $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
 1572:                 }
 1573:             } elsif ($domconfig->{$role}{$img} ne '') {
 1574:                 if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
 1575:                     my $error;
 1576:                     if ($configuserok eq 'ok') {
 1577: # is confname an author?
 1578:                         if ($switchserver eq '') {
 1579:                             if ($author_ok eq 'ok') {
 1580:                                 my ($result,$logourl) = 
 1581:                                &publishlogo($r,'copy',$domconfig->{$role}{$img},
 1582:                                             $dom,$confname,$img,$width,$height);
 1583:                                 if ($result eq 'ok') {
 1584:                                     $confhash->{$role}{$img} = $logourl;
 1585: 				    $changes{$role}{'images'}{$img} = 1;
 1586:                                 }
 1587:                             }
 1588:                         }
 1589:                     }
 1590:                 }
 1591:             }
 1592:         }
 1593:         if (ref($domconfig) eq 'HASH') {
 1594:             if (ref($domconfig->{$role}) eq 'HASH') {
 1595:                 foreach my $img (@images) {
 1596:                     if ($domconfig->{$role}{$img} ne '') {
 1597:                         if ($env{'form.'.$role.'_del_'.$img}) {
 1598:                             $confhash->{$role}{$img} = '';
 1599:                             $changes{$role}{'images'}{$img} = 1;
 1600:                         } else {
 1601:                             if ($confhash->{$role}{$img} eq '') {
 1602:                                 $confhash->{$role}{$img} = $domconfig->{$role}{$img};
 1603:                             }
 1604:                         }
 1605:                     } else {
 1606:                         if ($env{'form.'.$role.'_del_'.$img}) {
 1607:                             $confhash->{$role}{$img} = '';
 1608:                             $changes{$role}{'images'}{$img} = 1;
 1609:                         } 
 1610:                     }
 1611:                 }  
 1612:                 if ($domconfig->{$role}{'font'} ne '') {
 1613:                     if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
 1614:                         $changes{$role}{'font'} = 1;
 1615:                     }
 1616:                 } else {
 1617:                     if ($confhash->{$role}{'font'}) {
 1618:                         $changes{$role}{'font'} = 1;
 1619:                     }
 1620:                 }
 1621:                 foreach my $item (@bgs) {
 1622:                     if ($domconfig->{$role}{$item} ne '') {
 1623:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 1624:                             $changes{$role}{'bgs'}{$item} = 1;
 1625:                         } 
 1626:                     } else {
 1627:                         if ($confhash->{$role}{$item}) {
 1628:                             $changes{$role}{'bgs'}{$item} = 1;
 1629:                         }
 1630:                     }
 1631:                 }
 1632:                 foreach my $item (@links) {
 1633:                     if ($domconfig->{$role}{$item} ne '') {
 1634:                         if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
 1635:                             $changes{$role}{'links'}{$item} = 1;
 1636:                         }
 1637:                     } else {
 1638:                         if ($confhash->{$role}{$item}) {
 1639:                             $changes{$role}{'links'}{$item} = 1;
 1640:                         }
 1641:                     }
 1642:                 }
 1643:             } else {
 1644:                 &default_change_checker($role,\@images,\@links,\@bgs,
 1645:                                         $confhash,\%changes); 
 1646:             }
 1647:         } else {
 1648:             &default_change_checker($role,\@images,\@links,\@bgs,
 1649:                                     $confhash,\%changes); 
 1650:         }
 1651:     }
 1652:     return ($errors,%changes);
 1653: }
 1654: 
 1655: sub default_change_checker {
 1656:     my ($role,$images,$links,$bgs,$confhash,$changes) = @_;
 1657:     foreach my $item (@{$links}) {
 1658:         if ($confhash->{$role}{$item}) {
 1659:             $changes->{$role}{'links'}{$item} = 1;
 1660:         }
 1661:     }
 1662:     foreach my $item (@{$bgs}) {
 1663:         if ($confhash->{$role}{$item}) {
 1664:             $changes->{$role}{'bgs'}{$item} = 1;
 1665:         }
 1666:     }
 1667:     foreach my $img (@{$images}) {
 1668:         if ($env{'form.'.$role.'_del_'.$img}) {
 1669:             $confhash->{$role}{$img} = '';
 1670:             $changes->{$role}{'images'}{$img} = 1;
 1671:         }
 1672:     }
 1673:     if ($confhash->{$role}{'font'}) {
 1674:         $changes->{$role}{'font'} = 1;
 1675:     }
 1676: } 
 1677: 
 1678: sub display_colorchgs {
 1679:     my ($dom,$changes,$roles,$confhash) = @_;
 1680:     my (%choices,$resulttext);
 1681:     &Apache::loncommon::devalidate_domconfig_cache($dom);
 1682:     if (!grep(/^login$/,@{$roles})) {
 1683:         $resulttext = &mt('Changes made:').'<br />';
 1684:     }
 1685:     foreach my $role (@{$roles}) {
 1686:         if ($role eq 'login') {
 1687:             %choices = &login_choices();
 1688:         } else {
 1689:             %choices = &color_font_choices();
 1690:         }
 1691:         if (ref($changes->{$role}) eq 'HASH') {
 1692:             if ($role ne 'login') {
 1693:                 $resulttext .= '<h4>'.&mt($role).'</h4>';
 1694:             }
 1695:             foreach my $key (sort(keys(%{$changes->{$role}}))) {
 1696:                 if ($role ne 'login') {
 1697:                     $resulttext .= '<ul>';
 1698:                 }
 1699:                 if (ref($changes->{$role}{$key}) eq 'HASH') {
 1700:                     if ($role ne 'login') {
 1701:                         $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
 1702:                     }
 1703:                     foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
 1704:                         if ($confhash->{$role}{$item} eq '') {
 1705:                             $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
 1706:                         } else {
 1707:                             my $newitem = $confhash->{$role}{$item};
 1708:                             if ($key eq 'images') {
 1709:                                 $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
 1710:                             }
 1711:                             $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
 1712:                         }
 1713:                     }
 1714:                     if ($role ne 'login') {
 1715:                         $resulttext .= '</ul></li>';
 1716:                     }
 1717:                 } else {
 1718:                     if ($confhash->{$role}{$key} eq '') {
 1719:                         $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
 1720:                     } else {
 1721:                         $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
 1722:                     }
 1723:                 }
 1724:                 if ($role ne 'login') {
 1725:                     $resulttext .= '</ul>';
 1726:                 }
 1727:             }
 1728:         }
 1729:     }
 1730:     return $resulttext;
 1731: }
 1732: 
 1733: sub thumb_dimensions {
 1734:     return ('200','50');
 1735: }
 1736: 
 1737: sub check_dimensions {
 1738:     my ($inputfile) = @_;
 1739:     my ($fullwidth,$fullheight);
 1740:     if ($inputfile =~ m|^[/\w.\-]+$|) {
 1741:         if (open(PIPE,"identify $inputfile 2>&1 |")) {
 1742:             my $imageinfo = <PIPE>;
 1743:             if (!close(PIPE)) {
 1744:                 &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
 1745:             }
 1746:             chomp($imageinfo);
 1747:             my ($fullsize) = 
 1748:                 ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
 1749:             if ($fullsize) {
 1750:                 ($fullwidth,$fullheight) = split(/x/,$fullsize);
 1751:             }
 1752:         }
 1753:     }
 1754:     return ($fullwidth,$fullheight);
 1755: }
 1756: 
 1757: sub check_configuser {
 1758:     my ($uhome,$dom,$confname,$servadm) = @_;
 1759:     my ($configuserok,%currroles);
 1760:     if ($uhome eq 'no_host') {
 1761:         srand( time() ^ ($$ + ($$ << 15))  ); # Seed rand.
 1762:         my $configpass = &LONCAPA::Enrollment::create_password();
 1763:         $configuserok = 
 1764:             &Apache::lonnet::modifyuser($dom,$confname,'','internal',
 1765:                              $configpass,'','','','','',undef,$servadm);
 1766:     } else {
 1767:         $configuserok = 'ok';
 1768:         %currroles = 
 1769:             &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
 1770:     }
 1771:     return ($configuserok,%currroles);
 1772: }
 1773: 
 1774: sub check_authorstatus {
 1775:     my ($dom,$confname,%currroles) = @_;
 1776:     my $author_ok;
 1777:     if (!$currroles{':'.$dom.':au'}) {
 1778:         my $start = time;
 1779:         my $end = 0;
 1780:         $author_ok = 
 1781:             &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
 1782:                                         'au',$end,$start);
 1783:     } else {
 1784:         $author_ok = 'ok';
 1785:     }
 1786:     return $author_ok;
 1787: }
 1788: 
 1789: sub publishlogo {
 1790:     my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight) = @_;
 1791:     my ($output,$fname,$logourl);
 1792:     if ($action eq 'upload') {
 1793:         $fname=$env{'form.'.$formname.'.filename'};
 1794:         chop($env{'form.'.$formname});
 1795:     } else {
 1796:         ($fname) = ($formname =~ /([^\/]+)$/);
 1797:     }
 1798:     $fname=&Apache::lonnet::clean_filename($fname);
 1799: # See if there is anything left
 1800:     unless ($fname) { return ('error: no uploaded file'); }
 1801:     $fname="$subdir/$fname";
 1802:     my $filepath='/home/'.$confname.'/public_html';
 1803:     my ($fnamepath,$file,$fetchthumb);
 1804:     $file=$fname;
 1805:     if ($fname=~m|/|) {
 1806:         ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
 1807:     }
 1808:     my @parts=split(/\//,$filepath.'/'.$fnamepath);
 1809:     my $count;
 1810:     for ($count=4;$count<=$#parts;$count++) {
 1811:         $filepath.="/$parts[$count]";
 1812:         if ((-e $filepath)!=1) {
 1813:             mkdir($filepath,02770);
 1814:         }
 1815:     }
 1816:     # Check for bad extension and disallow upload
 1817:     if ($file=~/\.(\w+)$/ &&
 1818:         (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
 1819:         $output = 
 1820:             &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1); 
 1821:     } elsif ($file=~/\.(\w+)$/ &&
 1822:         !defined(&Apache::loncommon::fileembstyle($1))) {
 1823:         $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
 1824:     } elsif ($file=~/\.(\d+)\.(\w+)$/) {
 1825:         $output = &mt('File name not allowed a rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
 1826:     } elsif (-d "$filepath/$file") {
 1827:         $output = &mt('File name is a directory name - rename the file and re-upload');
 1828:     } else {
 1829:         my $source = $filepath.'/'.$file;
 1830:         my $logfile;
 1831:         if (!open($logfile,">>$source".'.log')) {
 1832:             return (&mt('No write permission to Construction Space'));
 1833:         }
 1834:         print $logfile
 1835: "\n================= Publish ".localtime()." ================\n".
 1836: $env{'user.name'}.':'.$env{'user.domain'}."\n";
 1837: # Save the file
 1838:         if (!open(FH,'>'.$source)) {
 1839:             &Apache::lonnet::logthis('Failed to create '.$source);
 1840:             return (&mt('Failed to create file'));
 1841:         }
 1842:         if ($action eq 'upload') {
 1843:             if (!print FH ($env{'form.'.$formname})) {
 1844:                 &Apache::lonnet::logthis('Failed to write to '.$source);
 1845:                 return (&mt('Failed to write file'));
 1846:             }
 1847:         } else {
 1848:             my $original = &Apache::lonnet::filelocation('',$formname);
 1849:             if(!copy($original,$source)) {
 1850:                 &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
 1851:                 return (&mt('Failed to write file'));
 1852:             }
 1853:         }
 1854:         close(FH);
 1855:         chmod(0660, $source); # Permissions to rw-rw---.
 1856: 
 1857:         my $docroot=$r->dir_config('lonDocRoot');
 1858:         my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
 1859:         my $copyfile=$targetdir.'/'.$file;
 1860: 
 1861:         my @parts=split(/\//,$targetdir);
 1862:         my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
 1863:         for (my $count=5;$count<=$#parts;$count++) {
 1864:             $path.="/$parts[$count]";
 1865:             if (!-e $path) {
 1866:                 print $logfile "\nCreating directory ".$path;
 1867:                 mkdir($path,02770);
 1868:             }
 1869:         }
 1870:         my $versionresult;
 1871:         if (-e $copyfile) {
 1872:             $versionresult = &logo_versioning($targetdir,$file,$logfile);
 1873:         } else {
 1874:             $versionresult = 'ok';
 1875:         }
 1876:         if ($versionresult eq 'ok') {
 1877:             if (copy($source,$copyfile)) {
 1878:                 print $logfile "\nCopied original source to ".$copyfile."\n";
 1879:                 $output = 'ok';
 1880:                 &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
 1881:                 $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
 1882:             } else {
 1883:                 print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
 1884:                 $output = &mt('Failed to copy file to RES space').", $!";
 1885:             }
 1886:             if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
 1887:                 my $inputfile = $filepath.'/'.$file;
 1888:                 my $outfile = $filepath.'/'.'tn-'.$file;
 1889:                 my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
 1890:                 if ($fullwidth ne '' && $fullheight ne '') { 
 1891:                     if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
 1892:                         my $thumbsize = $thumbwidth.'x'.$thumbheight;
 1893:                         system("convert -sample $thumbsize $inputfile $outfile");
 1894:                         chmod(0660, $filepath.'/tn-'.$file);
 1895:                         if (-e $outfile) {
 1896:                             my $copyfile=$targetdir.'/tn-'.$file;
 1897:                             if (copy($outfile,$copyfile)) {
 1898:                                 print $logfile "\nCopied source to ".$copyfile."\n";
 1899:                                 &write_metadata($dom,$confname,$formname,
 1900:                                                 $targetdir,'tn-'.$file,$logfile);
 1901:                             } else {
 1902:                                 print $logfile "\nUnable to write ".$copyfile.
 1903:                                                ':'.$!."\n";
 1904:                             }
 1905:                         }
 1906:                     }
 1907:                 }
 1908:             }
 1909:         } else {
 1910:             $output = $versionresult;
 1911:         }
 1912:     }
 1913:     return ($output,$logourl);
 1914: }
 1915: 
 1916: sub logo_versioning {
 1917:     my ($targetdir,$file,$logfile) = @_;
 1918:     my $target = $targetdir.'/'.$file;
 1919:     my ($maxversion,$fn,$extn,$output);
 1920:     $maxversion = 0;
 1921:     if ($file =~ /^(.+)\.(\w+)$/) {
 1922:         $fn=$1;
 1923:         $extn=$2;
 1924:     }
 1925:     opendir(DIR,$targetdir);
 1926:     while (my $filename=readdir(DIR)) {
 1927:         if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
 1928:             $maxversion=($1>$maxversion)?$1:$maxversion;
 1929:         }
 1930:     }
 1931:     $maxversion++;
 1932:     print $logfile "\nCreating old version ".$maxversion."\n";
 1933:     my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
 1934:     if (copy($target,$copyfile)) {
 1935:         print $logfile "Copied old target to ".$copyfile."\n";
 1936:         $copyfile=$copyfile.'.meta';
 1937:         if (copy($target.'.meta',$copyfile)) {
 1938:             print $logfile "Copied old target metadata to ".$copyfile."\n";
 1939:             $output = 'ok';
 1940:         } else {
 1941:             print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
 1942:             $output = &mt('Failed to copy old meta').", $!, ";
 1943:         }
 1944:     } else {
 1945:         print $logfile "Unable to write ".$copyfile.':'.$!."\n";
 1946:         $output = &mt('Failed to copy old target').", $!, ";
 1947:     }
 1948:     return $output;
 1949: }
 1950: 
 1951: sub write_metadata {
 1952:     my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
 1953:     my (%metadatafields,%metadatakeys,$output);
 1954:     $metadatafields{'title'}=$formname;
 1955:     $metadatafields{'creationdate'}=time;
 1956:     $metadatafields{'lastrevisiondate'}=time;
 1957:     $metadatafields{'copyright'}='public';
 1958:     $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
 1959:                                          $env{'user.domain'};
 1960:     $metadatafields{'authorspace'}=$confname.':'.$dom;
 1961:     $metadatafields{'domain'}=$dom;
 1962:     {
 1963:         print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
 1964:         my $mfh;
 1965:         unless (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
 1966:             $output = &mt('Could not write metadata');
 1967:         }
 1968:         foreach (sort keys %metadatafields) {
 1969:             unless ($_=~/\./) {
 1970:                 my $unikey=$_;
 1971:                 $unikey=~/^([A-Za-z]+)/;
 1972:                 my $tag=$1;
 1973:                 $tag=~tr/A-Z/a-z/;
 1974:                 print $mfh "\n\<$tag";
 1975:                 foreach (split(/\,/,$metadatakeys{$unikey})) {
 1976:                     my $value=$metadatafields{$unikey.'.'.$_};
 1977:                     $value=~s/\"/\'\'/g;
 1978:                     print $mfh ' '.$_.'="'.$value.'"';
 1979:                 }
 1980:                 print $mfh '>'.
 1981:                     &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
 1982:                         .'</'.$tag.'>';
 1983:             }
 1984:         }
 1985:         $output = 'ok';
 1986:         print $logfile "\nWrote metadata";
 1987:         close($mfh);
 1988:     }
 1989: }
 1990: 
 1991: sub check_switchserver {
 1992:     my ($dom,$confname) = @_;
 1993:     my ($allowed,$switchserver);
 1994:     my $home = &Apache::lonnet::homeserver($confname,$dom);
 1995:     if ($home eq 'no_host') {
 1996:         $home = &Apache::lonnet::domain($dom,'primary');
 1997:     }
 1998:     my @ids=&Apache::lonnet::current_machine_ids();
 1999:     foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
 2000:     if (!$allowed) {
 2001: 	$switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
 2002:     }
 2003:     return $switchserver;
 2004: }
 2005: 
 2006: sub modify_quotas {
 2007:     my ($dom,%domconfig) = @_;
 2008:     my ($resulttext,%changes);
 2009:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
 2010:     my %formhash;
 2011:     foreach my $key (keys(%env)) {
 2012:         if ($key =~ /^form\.quota_(.+)$/) {
 2013:             $formhash{$1} = $env{$key};
 2014:         }
 2015:     }
 2016:     $formhash{'default'} = $env{'form.defaultquota'};
 2017:     if (ref($domconfig{'quotas'}) eq 'HASH') {
 2018:         foreach my $key (keys(%{$domconfig{'quotas'}})) {
 2019:             if (exists($formhash{$key})) {
 2020:                 if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
 2021:                     $changes{$key} = 1;
 2022:                 }
 2023:             } else {
 2024:                 $formhash{$key} = $domconfig{'quotas'}{$key};
 2025:             }
 2026:         }
 2027:     }
 2028:     foreach my $key (keys(%formhash)) {
 2029:         if ($formhash{$key} ne '') {
 2030:             if (!exists($domconfig{'quotas'}{$key})) {
 2031:                 $changes{$key} = 1;
 2032:             }
 2033:         }
 2034:     }
 2035:     my %quotahash = (
 2036:                       quotas => {%formhash},
 2037:                     );
 2038:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
 2039:                                              $dom);
 2040:     if ($putresult eq 'ok') {
 2041:         if (keys(%changes) > 0) {
 2042:             $resulttext = &mt('Changes made:').'<ul>';
 2043:             foreach my $type (@{$types},'default') {
 2044:                 if (defined($changes{$type})) { 
 2045:                     my $typetitle = $usertypes->{$type};
 2046:                     if ($type eq 'default') {
 2047:                         $typetitle = $othertitle;
 2048:                     }
 2049:                     $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$formhash{$type}).'</li>';
 2050:                 }
 2051:             }
 2052:             $resulttext .= '</ul>';
 2053:         } else {
 2054:             $resulttext = &mt('No changes made to default quotas');
 2055:         }
 2056:     } else {
 2057:         $resulttext = '<span class="LC_error">'.
 2058: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 2059:     }
 2060:     return $resulttext;
 2061: }
 2062: 
 2063: sub modify_autoenroll {
 2064:     my ($dom,%domconfig) = @_;
 2065:     my ($resulttext,%changes);
 2066:     my %currautoenroll;
 2067:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
 2068:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
 2069:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
 2070:         }
 2071:     }
 2072:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
 2073:     my %title = ( run => 'Auto-enrollment active',
 2074:                   sender => 'Sender for notification messages');
 2075:     my @offon = ('off','on');
 2076:     my $sender_uname = $env{'form.sender_uname'};
 2077:     my $sender_domain = $env{'form.sender_domain'};
 2078:     if ($sender_domain eq '') {
 2079:         $sender_uname = '';
 2080:     } elsif ($sender_uname eq '') {
 2081:         $sender_domain = '';
 2082:     }
 2083:     my %autoenrollhash =  (
 2084:                        autoenroll => { run => $env{'form.autoenroll_run'},
 2085:                                        sender_uname => $sender_uname,
 2086:                                        sender_domain => $sender_domain,
 2087: 
 2088:                                 }
 2089:                      );
 2090:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
 2091:                                              $dom);
 2092:     if ($putresult eq 'ok') {
 2093:         if (exists($currautoenroll{'run'})) {
 2094:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
 2095:                  $changes{'run'} = 1;
 2096:              }
 2097:         } elsif ($autorun) {
 2098:             if ($env{'form.autoenroll_run'} ne '1') {
 2099:                  $changes{'run'} = 1;
 2100:             }
 2101:         }
 2102:         if ($currautoenroll{'sender_uname'} ne $sender_uname) {
 2103:             $changes{'sender'} = 1;
 2104:         }
 2105:         if ($currautoenroll{'sender_domain'} ne $sender_domain) {
 2106:             $changes{'sender'} = 1;
 2107:         }
 2108:         if (keys(%changes) > 0) {
 2109:             $resulttext = &mt('Changes made:').'<ul>';
 2110:             if ($changes{'run'}) {
 2111:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
 2112:             }
 2113:             if ($changes{'sender'}) {
 2114:                 if ($sender_uname eq '' || $sender_domain eq '') {
 2115:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
 2116:                 } else {
 2117:                     $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
 2118:                 }
 2119:             }
 2120:             $resulttext .= '</ul>';
 2121:         } else {
 2122:             $resulttext = &mt('No changes made to auto-enrollment settings');
 2123:         }
 2124:     } else {
 2125:         $resulttext = '<span class="LC_error">'.
 2126: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 2127:     }
 2128:     return $resulttext;
 2129: }
 2130: 
 2131: sub modify_autoupdate {
 2132:     my ($dom,%domconfig) = @_;
 2133:     my ($resulttext,%currautoupdate,%fields,%changes);
 2134:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
 2135:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
 2136:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
 2137:         }
 2138:     }
 2139:     my @offon = ('off','on');
 2140:     my %title = &Apache::lonlocal::texthash (
 2141:                    run => 'Auto-update:',
 2142:                    classlists => 'Updates to user information in classlists?'
 2143:                 );
 2144:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
 2145:     my %fieldtitles = &Apache::lonlocal::texthash (
 2146:                         id => 'Student/Employee ID',
 2147:                         permanentemail => 'E-mail address',
 2148:                         lastname => 'Last Name',
 2149:                         firstname => 'First Name',
 2150:                         middlename => 'Middle Name',
 2151:                         gen => 'Generation',
 2152:                       );
 2153:     my $othertitle = &mt('All users');
 2154:     if (keys(%{$usertypes}) >  0) {
 2155:         $othertitle = &mt('Other users');
 2156:     }
 2157:     foreach my $key (keys(%env)) {
 2158:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
 2159:             push(@{$fields{$1}},$2);
 2160:         }
 2161:     }
 2162:     my %updatehash = (
 2163:                       autoupdate => { run => $env{'form.autoupdate_run'},
 2164:                                       classlists => $env{'form.classlists'},
 2165:                                       fields => {%fields},
 2166:                                     }
 2167:                      );
 2168:     foreach my $key (keys(%currautoupdate)) {
 2169:         if (($key eq 'run') || ($key eq 'classlists')) {
 2170:             if (exists($updatehash{autoupdate}{$key})) {
 2171:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
 2172:                     $changes{$key} = 1;
 2173:                 }
 2174:             }
 2175:         } elsif ($key eq 'fields') {
 2176:             if (ref($currautoupdate{$key}) eq 'HASH') {
 2177:                 foreach my $item (@{$types},'default') {
 2178:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
 2179:                         my $change = 0;
 2180:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
 2181:                             if (!exists($fields{$item})) {
 2182:                                 $change = 1;
 2183:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
 2184:                                 if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
 2185:                                     $change = 1;
 2186:                                 }
 2187:                             }
 2188:                         }
 2189:                         if ($change) {
 2190:                             push(@{$changes{$key}},$item);
 2191:                         }
 2192:                     } 
 2193:                 }
 2194:             }
 2195:         }
 2196:     }
 2197:     foreach my $item (@{$types},'default') {
 2198:         if (defined($fields{$item})) {
 2199:             if (ref($currautoupdate{'fields'}) eq 'HASH') {
 2200:                 if (!exists($currautoupdate{'fields'}{$item})) {
 2201:                     push(@{$changes{'fields'}},$item);
 2202:                 }
 2203:             } else {
 2204:                 push(@{$changes{'fields'}},$item);
 2205:             }
 2206:         }
 2207:     }
 2208:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
 2209:                                              $dom);
 2210:     if ($putresult eq 'ok') {
 2211:         if (keys(%changes) > 0) {
 2212:             $resulttext = &mt('Changes made:').'<ul>';
 2213:             foreach my $key (sort(keys(%changes))) {
 2214:                 if (ref($changes{$key}) eq 'ARRAY') {
 2215:                     foreach my $item (@{$changes{$key}}) {
 2216:                         my @newvalues;
 2217:                         foreach my $type (@{$fields{$item}}) {
 2218:                             push(@newvalues,$fieldtitles{$type});
 2219:                         }
 2220:                         my $newvaluestr;
 2221:                         if (@newvalues > 0) {
 2222:                             $newvaluestr = join(', ',@newvalues);
 2223:                         } else {
 2224:                             $newvaluestr = &mt('none');
 2225:                         }
 2226:                         if ($item eq 'default') {
 2227:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
 2228:                         } else {
 2229:                             $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
 2230:                         }
 2231:                     }
 2232:                 } else {
 2233:                     my $newvalue;
 2234:                     if ($key eq 'run') {
 2235:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
 2236:                     } else {
 2237:                         $newvalue = $offon[$env{'form.'.$key}];
 2238:                     }
 2239:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
 2240:                 }
 2241:             }
 2242:             $resulttext .= '</ul>';
 2243:         } else {
 2244:             $resulttext = &mt('No changes made to autoupdates');
 2245:         }
 2246:     } else {
 2247:         $resulttext = '<span class="LC_error">'.
 2248: 	    &mt('An error occurred: [_1]',$putresult).'</span>';
 2249:     }
 2250:     return $resulttext;
 2251: }
 2252: 
 2253: sub modify_directorysrch {
 2254:     my ($dom,%domconfig) = @_;
 2255:     my ($resulttext,%changes);
 2256:     my %currdirsrch;
 2257:     if (ref($domconfig{'directorysrch'}) eq 'HASH') {
 2258:         foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
 2259:             $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
 2260:         }
 2261:     }
 2262:     my %title = ( available => 'Directory search available',
 2263:                   localonly => 'Other domains can search',
 2264:                   searchby => 'Search types',
 2265:                   searchtypes => 'Search latitude');
 2266:     my @offon = ('off','on');
 2267:     my @otherdoms = ('Yes','No');
 2268: 
 2269:     my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');  
 2270:     my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
 2271:     my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
 2272: 
 2273:     my ($othertitle,$usertypes,$types) = &sorted_inst_types($dom);
 2274:     if (keys(%{$usertypes}) == 0) {
 2275:         @cansearch = ('default');
 2276:     } else {
 2277:         if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
 2278:             foreach my $type (@{$currdirsrch{'cansearch'}}) {
 2279:                 if (!grep(/^\Q$type\E$/,@cansearch)) {
 2280:                     push(@{$changes{'cansearch'}},$type);
 2281:                 }
 2282:             }
 2283:             foreach my $type (@cansearch) {
 2284:                 if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
 2285:                     push(@{$changes{'cansearch'}},$type);
 2286:                 }
 2287:             }
 2288:         } else {
 2289:             push(@{$changes{'cansearch'}},@cansearch);
 2290:         }
 2291:     }
 2292: 
 2293:     if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
 2294:         foreach my $by (@{$currdirsrch{'searchby'}}) {
 2295:             if (!grep(/^\Q$by\E$/,@searchby)) {
 2296:                 push(@{$changes{'searchby'}},$by);
 2297:             }
 2298:         }
 2299:         foreach my $by (@searchby) {
 2300:             if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
 2301:                 push(@{$changes{'searchby'}},$by);
 2302:             }
 2303:         }
 2304:     } else {
 2305:         push(@{$changes{'searchby'}},@searchby);
 2306:     }
 2307: 
 2308:     if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
 2309:         foreach my $type (@{$currdirsrch{'searchtypes'}}) {
 2310:             if (!grep(/^\Q$type\E$/,@searchtypes)) {
 2311:                 push(@{$changes{'searchtypes'}},$type);
 2312:             }
 2313:         }
 2314:         foreach my $type (@searchtypes) {
 2315:             if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
 2316:                 push(@{$changes{'searchtypes'}},$type);
 2317:             }
 2318:         }
 2319:     } else {
 2320:         if (exists($currdirsrch{'searchtypes'})) {
 2321:             foreach my $type (@searchtypes) {  
 2322:                 if ($type ne $currdirsrch{'searchtypes'}) { 
 2323:                     push(@{$changes{'searchtypes'}},$type);
 2324:                 }
 2325:             }
 2326:             if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
 2327:                 push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
 2328:             }   
 2329:         } else {
 2330:             push(@{$changes{'searchtypes'}},@searchtypes); 
 2331:         }
 2332:     }
 2333: 
 2334:     my %dirsrch_hash =  (
 2335:             directorysrch => { available => $env{'form.dirsrch_available'},
 2336:                                cansearch => \@cansearch,
 2337:                                localonly => $env{'form.dirsrch_localonly'},
 2338:                                searchby => \@searchby,
 2339:                                searchtypes => \@searchtypes,
 2340:                              }
 2341:             );
 2342:     my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
 2343:                                              $dom);
 2344:     if ($putresult eq 'ok') {
 2345:         if (exists($currdirsrch{'available'})) {
 2346:              if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
 2347:                  $changes{'available'} = 1;
 2348:              }
 2349:         } else {
 2350:             if ($env{'form.dirsrch_available'} eq '1') {
 2351:                 $changes{'available'} = 1;
 2352:             }
 2353:         }
 2354:         if (exists($currdirsrch{'localonly'})) {
 2355:              if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
 2356:                  $changes{'localonly'} = 1;
 2357:              }
 2358:         } else {
 2359:             if ($env{'form.dirsrch_localonly'} eq '1') {
 2360:                 $changes{'localonly'} = 1;
 2361:             }
 2362:         }
 2363:         if (keys(%changes) > 0) {
 2364:             $resulttext = &mt('Changes made:').'<ul>';
 2365:             if ($changes{'available'}) {
 2366:                 $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
 2367:             }
 2368:             if ($changes{'localonly'}) {
 2369:                 $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
 2370:             }
 2371: 
 2372:             if (ref($changes{'cansearch'}) eq 'ARRAY') {
 2373:                 my $chgtext;
 2374:                 if (ref($usertypes) eq 'HASH') {
 2375:                     if (keys(%{$usertypes}) > 0) {
 2376:                         foreach my $type (@{$types}) {
 2377:                             if (grep(/^\Q$type\E$/,@cansearch)) {
 2378:                                 $chgtext .= $usertypes->{$type}.'; ';
 2379:                             }
 2380:                         }
 2381:                         if (grep(/^default$/,@cansearch)) {
 2382:                             $chgtext .= $othertitle;
 2383:                         } else {
 2384:                             $chgtext =~ s/\; $//;
 2385:                         }
 2386:                         $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>';
 2387:                     }
 2388:                 }
 2389:             }
 2390:             if (ref($changes{'searchby'}) eq 'ARRAY') {
 2391:                 my ($searchtitles,$titleorder) = &sorted_searchtitles();
 2392:                 my $chgtext;
 2393:                 foreach my $type (@{$titleorder}) {
 2394:                     if (grep(/^\Q$type\E$/,@searchby)) {
 2395:                         if (defined($searchtitles->{$type})) {
 2396:                             $chgtext .= $searchtitles->{$type}.'; ';
 2397:                         }
 2398:                     }
 2399:                 }
 2400:                 $chgtext =~ s/\; $//;
 2401:                 $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
 2402:             }
 2403:             if (ref($changes{'searchtypes'}) eq 'ARRAY') {
 2404:                 my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes(); 
 2405:                 my $chgtext;
 2406:                 foreach my $type (@{$srchtypeorder}) {
 2407:                     if (grep(/^\Q$type\E$/,@searchtypes)) {
 2408:                         if (defined($srchtypes_desc->{$type})) {
 2409:                             $chgtext .= $srchtypes_desc->{$type}.'; ';
 2410:                         }
 2411:                     }
 2412:                 }
 2413:                 $chgtext =~ s/\; $//;
 2414:                 $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
 2415:             }
 2416:             $resulttext .= '</ul>';
 2417:         } else {
 2418:             $resulttext = &mt('No changes made to institution directory search settings');
 2419:         }
 2420:     } else {
 2421:         $resulttext = '<span class="LC_error">'.
 2422:                       &mt('An error occurred: [_1]',$putresult).'</span>';
 2423:     }
 2424:     return $resulttext;
 2425: }
 2426: 
 2427: sub modify_contacts {
 2428:     my ($dom,%domconfig) = @_;
 2429:     my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
 2430:     if (ref($domconfig{'contacts'}) eq 'HASH') {
 2431:         foreach my $key (keys(%{$domconfig{'contacts'}})) {
 2432:             $currsetting{$key} = $domconfig{'contacts'}{$key};
 2433:         }
 2434:     }
 2435:     my (%others,%to);
 2436:     my @contacts = ('supportemail','adminemail');
 2437:     my @mailings = ('errormail','packagesmail','helpdeskmail');
 2438:     foreach my $type (@mailings) {
 2439:         @{$newsetting{$type}} = 
 2440:             &Apache::loncommon::get_env_multiple('form.'.$type);
 2441:         foreach my $item (@contacts) {
 2442:             if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
 2443:                 $contacts_hash{contacts}{$type}{$item} = 1;
 2444:             } else {
 2445:                 $contacts_hash{contacts}{$type}{$item} = 0;
 2446:             }
 2447:         }  
 2448:         $others{$type} = $env{'form.'.$type.'_others'};
 2449:         $contacts_hash{contacts}{$type}{'others'} = $others{$type};
 2450:     }
 2451:     foreach my $item (@contacts) {
 2452:         $to{$item} = $env{'form.'.$item};
 2453:         $contacts_hash{'contacts'}{$item} = $to{$item};
 2454:     }
 2455:     if (keys(%currsetting) > 0) {
 2456:         foreach my $item (@contacts) {
 2457:             if ($to{$item} ne $currsetting{$item}) {
 2458:                 $changes{$item} = 1;
 2459:             }
 2460:         }
 2461:         foreach my $type (@mailings) {
 2462:             foreach my $item (@contacts) {
 2463:                 if (ref($currsetting{$type}) eq 'HASH') {
 2464:                     if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
 2465:                         push(@{$changes{$type}},$item);
 2466:                     }
 2467:                 } else {
 2468:                     push(@{$changes{$type}},@{$newsetting{$type}});
 2469:                 }
 2470:             }
 2471:             if ($others{$type} ne $currsetting{$type}{'others'}) {
 2472:                 push(@{$changes{$type}},'others');
 2473:             }
 2474:         }
 2475:     } else {
 2476:         my %default;
 2477:         $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
 2478:         $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
 2479:         $default{'errormail'} = 'adminemail';
 2480:         $default{'packagesmail'} = 'adminemail';
 2481:         $default{'helpdeskmail'} = 'supportemail';
 2482:         foreach my $item (@contacts) {
 2483:            if ($to{$item} ne $default{$item}) {
 2484:               $changes{$item} = 1;
 2485:            } 
 2486:         }
 2487:         foreach my $type (@mailings) {
 2488:             if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
 2489:                
 2490:                 push(@{$changes{$type}},@{$newsetting{$type}});
 2491:             }
 2492:             if ($others{$type} ne '') {
 2493:                 push(@{$changes{$type}},'others');
 2494:             } 
 2495:         }
 2496:     }
 2497:     my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
 2498:                                              $dom);
 2499:     if ($putresult eq 'ok') {
 2500:         if (keys(%changes) > 0) {
 2501:             my ($titles,$short_titles)  = &contact_titles();
 2502:             $resulttext = &mt('Changes made:').'<ul>';
 2503:             foreach my $item (@contacts) {
 2504:                 if ($changes{$item}) {
 2505:                     $resulttext .= '<li>'.$titles->{$item}.
 2506:                                     &mt(' set to: ').
 2507:                                     '<span class="LC_cusr_emph">'.
 2508:                                     $to{$item}.'</span></li>';
 2509:                 }
 2510:             }
 2511:             foreach my $type (@mailings) {
 2512:                 if (ref($changes{$type}) eq 'ARRAY') {
 2513:                     $resulttext .= '<li>'.$titles->{$type}.': ';
 2514:                     my @text;
 2515:                     foreach my $item (@{$newsetting{$type}}) {
 2516:                         push(@text,$short_titles->{$item});
 2517:                     }
 2518:                     if ($others{$type} ne '') {
 2519:                         push(@text,$others{$type});
 2520:                     }
 2521:                     $resulttext .= '<span class="LC_cusr_emph">'.
 2522:                                    join(', ',@text).'</span></li>';
 2523:                 }
 2524:             }
 2525:             $resulttext .= '</ul>';
 2526:         } else {
 2527:             $resulttext = &mt('No changes made to contact information.');
 2528:         }
 2529:     } else {
 2530:         $resulttext = '<span class="LC_error">'.
 2531:             &mt('An error occurred: [_1].',$putresult).'</span>';
 2532:     }
 2533:     return $resulttext;
 2534: }
 2535: 
 2536: sub modify_usercreation {
 2537:     my ($dom,%domconfig) = @_;
 2538:     my ($resulttext,%curr_usercreation,%changes,%authallowed);
 2539:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
 2540:         foreach my $key (keys(%{$domconfig{'usercreation'}})) {
 2541:             $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
 2542:         }
 2543:     }
 2544:     my %title = &Apache::lonlocal::texthash (
 2545:                    author => 'adding co-authors/assistant authors',
 2546:                    course => 'adding users to a course',
 2547:                 );
 2548:     my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
 2549:     my @cancreate = &Apache::loncommon::get_env_multiple('form.can_createuser');
 2550:     if (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
 2551:         foreach my $type (@{$curr_usercreation{'cancreate'}}) {
 2552:             if (!grep(/^\Q$type\E$/,@cancreate)) {
 2553:                 push(@{$changes{'cancreate'}},$type);
 2554:             }
 2555:         }
 2556:         foreach my $type (@cancreate) {
 2557:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'cancreate'}})) {
 2558:                 push(@{$changes{'cancreate'}},$type);
 2559:             }
 2560:         }
 2561:     } else {
 2562:         push(@{$changes{'cancreate'}},@cancreate);
 2563:     }
 2564:     if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
 2565:         foreach my $type (@{$curr_usercreation{'username_rule'}}) {
 2566:             if (!grep(/^\Q$type\E$/,@username_rule)) {
 2567:                 push(@{$changes{'username_rule'}},$type);
 2568:             }
 2569:         }
 2570:         foreach my $type (@username_rule) {
 2571:             if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
 2572:                 push(@{$changes{'username_rule'}},$type);
 2573:             }
 2574:         }
 2575:     } else {
 2576:         push(@{$changes{'username_rule'}},@username_rule);
 2577:     }
 2578: 
 2579:     my @contexts = ('author','course','domain');
 2580:     my @authtypes = ('int','krb4','krb5','loc');
 2581:     my %authhash;
 2582:     foreach my $item (@contexts) {
 2583:         my @authallowed =  &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
 2584:         foreach my $auth (@authtypes) {
 2585:             if (grep(/^\Q$auth\E$/,@authallowed)) {
 2586:                 $authhash{$item}{$auth} = 1;
 2587:             } else {
 2588:                 $authhash{$item}{$auth} = 0;
 2589:             }
 2590:         }
 2591:     }
 2592:     if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
 2593:         foreach my $item (@contexts) {
 2594:             if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
 2595:                 foreach my $auth (@authtypes) {
 2596:                     if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
 2597:                         push(@{$changes{'authtypes'}},$item);
 2598:                         last;
 2599:                     }
 2600:                 }
 2601:             }
 2602:         }
 2603:     } else {
 2604:         foreach my $item (@contexts) {
 2605:             push(@{$changes{'authtypes'}},$item);
 2606:         }
 2607:     }
 2608: 
 2609:     my %usercreation_hash =  (
 2610:             usercreation => {
 2611:                               cancreate     => \@cancreate,
 2612:                               username_rule => \@username_rule,
 2613:                               authtypes      => \%authhash,
 2614:                             }
 2615:             );
 2616: 
 2617:     my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
 2618:                                              $dom);
 2619:     if ($putresult eq 'ok') {
 2620:         if (keys(%changes) > 0) {
 2621:             $resulttext = &mt('Changes made:').'<ul>';
 2622:             if (ref($changes{'cancreate'}) eq 'ARRAY') {
 2623:                 my $chgtext = '<ul>';
 2624:                 foreach my $type (@cancreate) {
 2625:                     $chgtext .= '<li>'.$title{$type}.'</li>';
 2626:                 }
 2627:                 $chgtext .= '</ul>';
 2628:                 if (@cancreate > 0) {
 2629:                     $resulttext .= '<li>'.&mt('Creation of new users is permitted by a Domain Coordinator, and also by other users when: ').$chgtext.'</li>';
 2630:                 } else {
 2631:                     $resulttext .= '<li>'.&mt("Creation of new users is now only allowed when the user's role is Domain Coordinator.").'</li>';
 2632:                 }
 2633:             }
 2634:             if (ref($changes{'username_rule'}) eq 'ARRAY') {
 2635:                 my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom);
 2636:                 my $chgtext = '<ul>';
 2637:                 foreach my $type (@username_rule) {
 2638:                     if (ref($rules->{$type}) eq 'HASH') {
 2639:                         $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
 2640:                     }
 2641:                 }
 2642:                 $chgtext .= '</ul>';
 2643:                 if (@username_rule > 0) {
 2644:                     $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';     
 2645:                 } else {
 2646:                     $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>'; 
 2647:                 }
 2648:             }
 2649:             my %authname = &authtype_names();
 2650:             my %context_title = &context_names();
 2651:             if (ref($changes{'authtypes'}) eq 'ARRAY') {
 2652:                 my @unchanged;
 2653:                 my $chgtext = '<ul>';
 2654:                 foreach my $type (@{$changes{'authtypes'}}) {
 2655:                     my @allowed;
 2656:                     $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
 2657:                     foreach my $auth (@authtypes) {
 2658:                         if ($authhash{$type}{$auth}) {
 2659:                             push(@allowed,$authname{$auth});
 2660:                         }
 2661:                     }
 2662:                     $chgtext .= join(', ',@allowed).'</li>';
 2663:                 }
 2664:                 $chgtext .= '</ul>';
 2665:                 $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
 2666:                 $resulttext .= '</li>';
 2667:             }
 2668:             $resulttext .= '</ul>';
 2669:         } else {
 2670:             $resulttext = &mt('No changes made to user creation settings');
 2671:         }
 2672:     } else {
 2673:         $resulttext = '<span class="LC_error">'.
 2674:             &mt('An error occurred: [_1]',$putresult).'</span>';
 2675:     }
 2676:     return $resulttext;
 2677: }
 2678: 
 2679: 1;

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