File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.25: download - view: text, annotated - select for diffs
Sun Aug 26 15:31:03 2007 UTC (16 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_5_X, version_2_5_2, version_2_5_1, HEAD
searchtype of "begins with" can be set for institutional searches in domain configuration.
searchtype information now stored as a reference to an array instead of scalar in domain settings hash.

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

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