File:  [LON-CAPA] / loncom / interface / domainprefs.pm
Revision 1.3: download - view: text, annotated - select for diffs
Thu Mar 1 18:03:18 2007 UTC (17 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Modify display to show all domain configuration settings on a single page (styled similarly to What's New? Page).  Help files needed for help links.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: domainprefs.pm,v 1.3 2007/03/01 18:03:18 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: 
   41: sub handler {
   42:     my $r=shift;
   43:     if ($r->header_only) {
   44:         &Apache::loncommon::content_type($r,'text/html');
   45:         $r->send_http_header;
   46:         return OK;
   47:     }
   48: 
   49:     my $dom = $env{'request.role.domain'};
   50:     my $domdesc = $Apache::lonnet::domaindescription{$dom};
   51:     if (&Apache::lonnet::allowed('mau',$dom)) {
   52:         &Apache::loncommon::content_type($r,'text/html');
   53:         $r->send_http_header;
   54:     } else {
   55:         $env{'user.error.msg'}=
   56:         "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
   57:         return HTTP_NOT_ACCEPTABLE;
   58:     }
   59:     &Apache::lonhtmlcommon::clear_breadcrumbs();
   60:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
   61:                                             ['phase']);
   62:     my $phase = "display";
   63:     if ( exists($env{'form.phase'}) ) {
   64:         $phase = $env{'form.phase'};
   65:     }
   66:     my %domconfig =
   67:       &Apache::lonnet::get_dom('configuration',['login','quotas',
   68:                                'autoenroll','autoupdate'],$dom);
   69: 
   70:     my @prefs = (
   71:       { text => 'Log-in page options',
   72:         help => 'Domain_Log-in_Page',
   73:         action => 'login',
   74:         header => [{col1 => 'Item',
   75:                     col2 => 'Selection',}],
   76:         },
   77:       { text => 'Default quotas for user portfolios',
   78:         help => 'Default_User_Quota',
   79:         action => 'quotas',
   80:         header => [{col1 => 'User type',
   81:                     col2 => 'Default quota'}],
   82:         },
   83:       { text => 'Auto-enrollment settings',
   84:         help => 'Domain_Auto_Enrollment',
   85:         action => 'autoenroll',
   86:         header => [{col1 => 'Configuration setting',
   87:                     col2 => 'Value(s)'}],
   88:         },
   89:       { text => 'Auto-update settings',
   90:         help => 'Domain_Auto_Update',
   91:         action => 'autoupdate',
   92:         header => [{col1 => 'Setting',
   93:                     col2 => 'Value',},
   94:                    {col1 => 'User Population',
   95:                     col2 => 'Updataeable user data'}],
   96:       },
   97:     );
   98:     &Apache::lonhtmlcommon::add_breadcrumb
   99:     ({href=>"javascript:changePage(document.$phase,'display')",
  100:       text=>"Domain Configuration"});
  101:     if ($phase eq 'process') {
  102:         &Apache::lonhtmlcommon::add_breadcrumb
  103:           ({href=>"javascript:changePage(document.$phase,'$phase')",
  104:             text=>"Updated"});
  105:         &print_header($r,$phase);
  106:         foreach my $item (@prefs) {
  107:             $r->print('<h3>'.&mt($item->{'text'}).'</h3>'.
  108:                    &process_changes($dom,$item->{'action'},%domconfig));
  109:         }
  110:         $r->print('<p>');
  111:         &print_footer($r,$phase,'display','Back to actions menu');
  112:         $r->print('</p>');
  113:     } else {
  114:         if ($phase eq '') {
  115:             $phase = 'display';
  116:         }
  117:         my %helphash;   
  118:         my $numprefs = @prefs;
  119:         &print_header($r,$phase);
  120:         $r->print('<table border="0" width="100%" cellpadding="2" cellspacing="4"><tr><td align="left" valign="top" width="45%">');
  121:         foreach my $item (@prefs) {
  122:             if ($item->{'action'} eq 'autoupdate') {
  123:                 $r->print('</td><td width="6%">&nbsp;</td><td align="left" valign="top" width="47%">');
  124:             }
  125:             &print_config_box($r,$dom,$item->{'action'},$item,
  126:                               $domconfig{$item->{'action'}});
  127:         }
  128:         $r->print('
  129:            </table>
  130:           </td>
  131:          </tr>
  132:         </table>
  133:       </td>
  134:     </tr>
  135:    </table>');
  136:         &print_footer($r,$phase,'process','Store changes');
  137:     }
  138:     return OK;
  139: }
  140: 
  141: sub process_changes {
  142:     my ($dom,$action,%domconfig) = @_;
  143:     my $output;
  144:     if ($action eq 'login') {
  145:         $output = &modify_login($dom,%domconfig);
  146:     } elsif ($action eq 'quotas') {
  147:         $output = &modify_quotas($dom,%domconfig);
  148:     } elsif ($action eq 'autoenroll') {
  149:         $output = &modify_autoenroll($dom,%domconfig);
  150:     } elsif ($action eq 'autoupdate') {
  151:         $output = &modify_autoupdate($dom,%domconfig);
  152:     }
  153:     return $output;
  154: }
  155: 
  156: sub print_config_box {
  157:     my ($r,$dom,$action,$item,$settings) = @_;
  158:     $r->print('
  159:          <table class="LC_nested_outer">
  160:           <tr>
  161:            <th>'.&mt($item->{text}).'&nbsp;'.
  162:            &Apache::loncommon::help_open_topic($item->{'help'}).'</th>
  163:           </tr>');
  164:     if ($action eq 'autoupdate') {
  165:         $r->print('
  166:           <tr>
  167:            <td>
  168:             <table class="LC_nested">
  169:              <tr class="LC_info_row">
  170:               <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>
  171:               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
  172:              </tr>'.
  173:         &print_autoupdate('top',$dom,$settings).'
  174:            </table>
  175:           </td>
  176:          </tr>
  177:          <tr>
  178:            <td>
  179:             <table class="LC_nested">
  180:              <tr class="LC_info_row">
  181:               <td class="LC_left_item">'.$item->{'header'}->[1]->{'col1'}.'</td>
  182:               <td class="LC_right_item">'.$item->{'header'}->[1]->{'col2'}.'</td>
  183:              </tr>'.
  184:         &print_autoupdate('bottom',$dom,$settings));
  185:     } else {
  186:         $r->print('
  187:           <tr>
  188:            <td>
  189:             <table class="LC_nested">
  190:              <tr class="LC_info_row">
  191:               <td class="LC_left_item">'.$item->{'header'}->[0]->{'col1'}.'</td>
  192:               <td class="LC_right_item">'.$item->{'header'}->[0]->{'col2'}.'</td>
  193:              </tr>');
  194:         if ($action eq 'login') {
  195:            $r->print(&print_login($settings));
  196:         } elsif ($action eq 'quotas') {
  197:            $r->print(&print_quotas($dom,$settings));
  198:         } elsif ($action eq 'autoenroll') {
  199:            $r->print(&print_autoenroll($dom,$settings));
  200:         }  
  201:     }
  202:     $r->print('
  203:    </table>
  204:   </td>
  205:  </tr>
  206: </table><br />');
  207:     return;
  208: }
  209: 
  210: sub print_header {
  211:     my ($r,$phase) = @_;
  212:     my $js = qq|
  213: <script type="text/javascript">
  214: function changePage(formname,newphase) {
  215:     formname.phase.value = newphase;
  216:     formname.submit();
  217: }
  218: </script>
  219: |;
  220:     $r->print(&Apache::loncommon::start_page('View/Modify Domain Settings',
  221:                                            $js));
  222:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Domain Settings'));
  223:     $r->print('<form method="post" name="'.$phase.'" action="/adm/domainprefs">');
  224:     return;
  225: }
  226: 
  227: sub print_footer {
  228:     my ($r,$phase,$newphase,$button_text) = @_;
  229:     $button_text = &mt($button_text);
  230:     $r->print('<input type="hidden" name="phase" value="" />');
  231:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  232:     if ($phase eq 'process') {
  233:         $r->print('<a href='.$dest.'>'.$button_text.'</a>');
  234:     } else {
  235:         $r->print('<input type="button" name="store" value="'.
  236:                   $button_text.'" onclick='.$dest.' />');
  237:     }
  238:     $r->print('</form>');
  239:     $r->print('<br />'.&Apache::loncommon::end_page());
  240:     return;
  241: }
  242: 
  243: sub print_login {
  244:     my ($settings) = @_;
  245:     my $catalogon = ' checked="checked" ';
  246:     my $catalogoff;
  247:     my $adminmailon = ' ';
  248:     my $adminmailoff = ' checked="checked" ';
  249:     if (ref($settings) eq 'HASH') {
  250:         if ($settings->{'coursecatalog'} eq '0') {
  251:             $catalogoff = $catalogon;
  252:             $catalogon = ' ';
  253:         }
  254:         if ($settings->{'adminmail'} eq '1') {
  255:             $adminmailon = $adminmailoff;
  256:             $adminmailoff = ' ';
  257:         }
  258:     }
  259:     my %choices = 
  260:         &Apache::lonlocal::texthash(
  261:             coursecatalog => 'Display Course Catalog link?',
  262:             adminmail => "Display Administrator's E-mail Address?"
  263:         );
  264:     my $datatable = 
  265:         '<tr class="LC_odd_row"><td>'.$choices{'coursecatalog'}.
  266:         '</td><td class="LC_right_item">'.
  267:         '<nobr><input type="radio" name="coursecatalog"'.
  268:         $catalogon.' value="1" />'.&mt('Yes').'&nbsp;'.
  269:         '<input type="radio" name="coursecatalog"'.
  270:         $catalogoff.'value="0" />'.&mt('No').'</nobr></td>'.
  271:         '</tr><tr>'.
  272:         '<td>'.$choices{'adminmail'}.'</td>'.
  273:         '<td class="LC_right_item"><nobr>'.
  274:         '<input type="radio" name="adminmail"'.
  275:         $adminmailon.' value="1" />'.&mt('Yes').'&nbsp;'.
  276:         '<input type="radio" name="adminmail"'.
  277:         $adminmailoff.'value="0" />'.&mt('No').'</nobr></td>'.
  278:         '</tr>';
  279:     return $datatable;
  280: }
  281: 
  282: sub print_quotas {
  283:     my ($dom,$settings) = @_;
  284:     my $datatable;
  285:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
  286:     my $othertitle = "All users";
  287:     my @types;
  288:     if (ref($order) eq 'ARRAY') {
  289:         @types = @{$order};
  290:     }
  291:     if (@types == 0) {
  292:         if (ref($usertypes) eq 'HASH') {
  293:             @types = sort(keys(%{$usertypes}));
  294:         }
  295:     }
  296:     my $typecount = 0;
  297:     my $css_class;
  298:     if (@types > 0) {
  299:         foreach my $type (@types) {
  300:             if (defined($usertypes->{$type})) {
  301:                 $typecount ++;
  302:                 $css_class = $typecount%2?' class="LC_odd_row"':'';
  303:                 $datatable .= '<tr'.$css_class.'>'. 
  304:                               '<td>'.$usertypes->{$type}.'</td>'.
  305:                               '<td class="LC_right_item"><nobr>'.
  306:                               '<input type="text" name="quota_'.$type.
  307:                               '" value="'.$settings->{$type}.
  308:                               '" size="5" /> Mb</nobr></td></tr>';
  309:             }
  310:         }
  311:         $othertitle = "Other users";
  312:     }
  313:     my $defaultquota = '20';
  314:     if (ref($settings) eq 'HASH') {
  315:         if (defined($settings->{'default'})) {
  316:             $defaultquota = $settings->{'default'};
  317:         }
  318:     }
  319:     $typecount ++;
  320:     $css_class = $typecount%2?' class="LC_odd_row"':'';
  321:     $datatable .= '<tr'.$css_class.'>'.
  322:                   '<td>'.&mt($othertitle).'</td>'.
  323:                   '<td class="LC_right_item"><nobr>'.
  324:                   '<input type="text" name="default" value="'.
  325:                   $defaultquota.'" size="5" /> Mb</nobr></td></tr>';
  326:     return $datatable;
  327: }
  328: 
  329: sub print_autoenroll {
  330:     my ($dom,$settings) = @_;
  331:     my $defdom = $dom;
  332:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
  333:     my ($runon,$runoff);
  334:     if (ref($settings) eq 'HASH') {
  335:         if (exists($settings->{'run'})) {
  336:             if ($settings->{'run'} eq '0') {
  337:                 $runoff = ' checked="checked" ';
  338:                 $runon = ' ';
  339:             } else {
  340:                 $runon = ' checked="checked" ';
  341:                 $runoff = ' ';
  342:             }
  343:         } else {
  344:             if ($autorun) {
  345:                 $runon = ' checked="checked" ';
  346:                 $runoff = ' ';
  347:             } else {
  348:                 $runoff = ' checked="checked" ';
  349:                 $runon = ' ';
  350:             }
  351:         }
  352:         if (exists($settings->{'sender_domain'})) {
  353:             $defdom = $settings->{'sender_domain'};
  354:         }
  355:     }
  356:     my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
  357:     my $datatable='<tr class="LC_odd_row">'.
  358:                   '<td>'.&mt('Auto-enrollment active?').'</td>'.
  359:                   '<td class="LC_right_item"><nobr>'.
  360:                   '<input type="radio" name="autoenroll_run"'.
  361:                   $runon.' value="1" />'.&mt('Yes').'&nbsp;'.
  362:                   '<input type="radio" name="autoenroll_run"'.
  363:                   $runoff.'value="0" />'.&mt('No').'</nobr></td>'.
  364:                   '</tr><tr>'.
  365:                   '<td>'.&mt('Notification messages - sender').
  366:                   '</td><td class="LC_right_item"><nobr>'.
  367:                   &mt('username').':&nbsp;'.
  368:                   '<input type="text" name="sender_uname" value="'.
  369:                   $settings->{'sender_uname'}.
  370:                   '" size="10" />&nbsp;&nbsp;'.&mt('domain').
  371:                   ':&nbsp;'.$domform.'</nobr></td></tr>';
  372:     return $datatable;
  373: }
  374: 
  375: sub print_autoupdate {
  376:     my ($position,$dom,$settings) = @_;
  377:     my $datatable;
  378:     if ($position eq 'top') {
  379:         my $updateon = ' ';
  380:         my $updateoff = ' checked="checked" ';
  381:         my $classlistson = ' ';
  382:         my $classlistsoff = ' checked="checked" ';
  383:         if (ref($settings) eq 'HASH') {
  384:             if ($settings->{'run'} eq '1') {
  385:                 $updateon = $updateoff;
  386:                 $updateoff = ' ';
  387:             }
  388:             if ($settings->{'classlists'} eq '1') {
  389:                 $classlistson = $classlistsoff;
  390:                 $classlistsoff = ' ';
  391:             }
  392:         }
  393:         my %title = (
  394:                    run => 'Auto-update active?',
  395:                    classlists => 'Update information in classlists?',
  396:                     );
  397:         $datatable = '<tr class="LC_odd_row">'. 
  398:                   '<td>'.&mt($title{'run'}).'</td>'.
  399:                   '<td class="LC_right_item"><nobr>'.
  400:                   '<input type="radio" name="autoupdate_run"'.
  401:                   $updateon.' value="1" />'.&mt('Yes').'&nbsp;'.
  402:                   '<input type="radio" name="autoupdate_run"'.
  403:                   $updateoff.'value="0" />'.&mt('No').'</nobr></td>'.
  404:                   '</tr><tr>'.
  405:                   '<td>'.&mt($title{'classlists'}).'</td>'.
  406:                   '<td class="LC_right_item"><nobr>'.
  407:                   '<input type="radio" name="classlists"'.
  408:                   $classlistson.' value="1" />'.&mt('Yes').'&nbsp;'.
  409:                   '<input type="radio" name="classlists"'.
  410:                   $classlistsoff.'value="0" />'.&mt('No').'</nobr></td>'.
  411:                   '</tr>';
  412:     } else {
  413:         my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
  414:         my @types;
  415:         if (ref($order) eq 'ARRAY') {
  416:             @types = @{$order};
  417:         }
  418:         if (@types == 0) {
  419:             if (ref($usertypes) eq 'HASH') {
  420:                 @types = sort(keys(%{$usertypes}));
  421:             }
  422:         }
  423:         my $othertitle = &mt('All users');
  424:         if (keys(%{$usertypes}) > 0) {
  425:             $othertitle = &mt('Other users');
  426:         }
  427:         my @fields = ('lastname','firstname','middlename','gen','email','id');
  428:         my %fieldtitles = &Apache::lonlocal::texthash (
  429:                             id => 'Student/Employee ID',
  430:                             email => 'E-mail address',
  431:                             lastname => 'Last Name',
  432:                             firstname => 'First Name',
  433:                             middlename => 'Middle Name',
  434:                             gen => 'Generation',
  435:                       );
  436:         my $numrows = 0;
  437:         if (@types > 0) {
  438:             $datatable = 
  439:                 &usertype_update_row($settings,$usertypes,\%fieldtitles,
  440:                                      \@fields,\@types,\$numrows);
  441:         }
  442:         $datatable .= 
  443:             &usertype_update_row($settings,{'default' => $othertitle},
  444:                                  \%fieldtitles,\@fields,['default'],
  445:                                  \$numrows);
  446:     }
  447:     return $datatable;
  448: }
  449: 
  450: sub usertype_update_row {
  451:     my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
  452:     my $datatable;
  453:     my $numinrow = 4;
  454:     foreach my $type (@{$types}) {
  455:         if (defined($usertypes->{$type})) {
  456:             $$rownums ++;
  457:             my $css_class = $$rownums%2?' class="LC_odd_row"':'';
  458:             $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
  459:                           '</td><td class="LC_left_item"><table>';
  460:             for (my $i=0; $i<@{$fields}; $i++) {
  461:                 my $rem = $i%($numinrow);
  462:                 if ($rem == 0) {
  463:                     if ($i > 0) {
  464:                         $datatable .= '</tr>';
  465:                     }
  466:                     $datatable .= '<tr>';
  467:                 }
  468:                 my $check = ' ';
  469:                 if (ref($settings->{'fields'}) eq 'HASH') {
  470:                     if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
  471:                         if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
  472:                             $check = ' checked="checked" ';
  473:                         }
  474:                     }
  475:                 }
  476: 
  477:                 if ($i == @{$fields}-1) {
  478:                     my $colsleft = $numinrow - $rem;
  479:                     if ($colsleft > 1) {
  480:                         $datatable .= '<td colspan="'.$colsleft.'">';
  481:                     } else {
  482:                         $datatable .= '<td>';
  483:                     }
  484:                 } else {
  485:                     $datatable .= '<td>';
  486:                 }
  487:                 $datatable .= '<nobr><input type="checkbox" name="updateable_'.
  488:                               $type.'_'.$fields->[$i].'" '.
  489:                               '" value="1"'.$check.'/>'.
  490:                               $fieldtitles->{$fields->[$i]}.'</nobr></td>';
  491:             }
  492:             $datatable .= '</tr></table></td></tr>';
  493:         }
  494:     }
  495:     return $datatable;
  496: }
  497: 
  498: sub modify_login {
  499:     my ($dom,%domconfig) = @_;
  500:     my ($resulttext,%changes);
  501:     my %title = ( coursecatalog => 'Display course catalog',
  502:                   adminmail => 'Display administrator E-mail address');
  503:     my @offon = ('off','on');
  504:     my %loginhash =  (
  505:                        login => { coursecatalog => $env{'form.coursecatalog'},                                  adminmail => $env{'form.adminmail'},
  506:                                 }
  507:                      );
  508:     my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
  509:                                              $dom);
  510:     if ($putresult eq 'ok') {
  511:         if (($domconfig{'login'}{'coursecatalog'} eq '0') &&
  512:             ($env{'form.coursecatalog'} eq '1')) {
  513:             $changes{'coursecatalog'} = 1;
  514:         } elsif (($domconfig{'login'}{'coursecatalog'} eq '' ||
  515:                  $domconfig{'login'}{'coursecatalog'} eq '1') &&
  516:                  ($env{'form.coursecatalog'} eq '0')) {
  517:             $changes{'coursecatalog'} = 1;
  518:         }
  519:         if (($domconfig{'login'}{'adminmail'} eq '1') &&
  520:                 ($env{'form.adminmail'} eq '0')) {
  521:             $changes{'adminmail'} = 1;
  522:         } elsif (($domconfig{'login'}{'adminmail'} eq '' ||
  523:                  $domconfig{'login'}{'adminmail'} eq '0') &&
  524:                  ($env{'form.adminmail'} eq '1')) {
  525:             $changes{'adminmail'} = 1;
  526:         }
  527:         if (keys(%changes) > 0) {
  528:             $resulttext = &mt('Changes made:').'<ul>';
  529:             foreach my $item (sort(keys(%changes))) {
  530:                 $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
  531:             }
  532:             $resulttext .= '</ul>';
  533:         } else {
  534:             $resulttext = &mt('No changes made to log-in page settings');
  535:         }
  536:     } else {
  537:         $resulttext = &mt('An error occurred: [_1]',$putresult);
  538:     }
  539:     return $resulttext;
  540: }
  541: 
  542: sub modify_quotas {
  543:     my ($dom,%domconfig) = @_;
  544:     my ($resulttext,%changes);
  545:     my ($usertypes,$order) = 
  546:         &Apache::lonnet::retrieve_inst_usertypes($dom);
  547:     my %formhash;
  548:     foreach my $key (keys(%env)) {
  549:         if ($key =~ /^form\.quota_(.+)$/) {
  550:             $formhash{$1} = $env{$key};
  551:         }
  552:     }
  553:     if (ref($domconfig{'quotas'}) eq 'HASH') {
  554:         foreach my $key (keys(%{$domconfig{'quotas'}})) {
  555:             if (exists($formhash{$key})) {
  556:                 if ($formhash{$key} ne $domconfig{'quotas'}{$key}) {
  557:                     $changes{$key} = 1;
  558:                 }
  559:             } else {
  560:                 $formhash{$key} = $domconfig{'quotas'}{$key};
  561:             }
  562:         }
  563:     }
  564:     foreach my $key (keys(%formhash)) {
  565:         if ($formhash{$key} ne '') {
  566:             if (!exists($domconfig{'quotas'}{$key})) {
  567:                 $changes{$key} = 1;
  568:             }
  569:         }
  570:     }
  571:     my %quotahash = (
  572:                       quotas => {%formhash},
  573:                     );
  574:     my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
  575:                                              $dom);
  576:     if ($putresult eq 'ok') {
  577:         if (keys(%changes) > 0) {
  578:             $resulttext = &mt('Changes made:').'<ul>';
  579:             foreach my $item (sort(keys(%changes))) {
  580:                 $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$usertypes->{$item},$formhash{$item}).'</li>';
  581:             }
  582:             $resulttext .= '</ul>';
  583:         } else {
  584:             $resulttext = &mt('No changes made to default quotas');
  585:         }
  586:     } else {
  587:         $resulttext = &mt('An error occurred: [_1]',$putresult);
  588:     }
  589:     return $resulttext;
  590: }
  591: 
  592: sub modify_autoenroll {
  593:     my ($dom,%domconfig) = @_;
  594:     my ($resulttext,%changes);
  595:     my %currautoenroll;
  596:     if (ref($domconfig{'autoenroll'}) eq 'HASH') {
  597:         foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
  598:             $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
  599:         }
  600:     }
  601:     my $autorun = &Apache::lonnet::auto_run(undef,$dom),
  602:     my %title = ( run => 'Auto-enrollment active',
  603:                   sender => 'Sender for notification messages');
  604:     my @offon = ('off','on');
  605:     my %autoenrollhash =  (
  606:                        autoenroll => { run => $env{'form.autoenroll_run'},
  607:                                        sender_uname => $env{'form.sender_uname'},
  608:                                        sender_domain => $env{'form.sender_domain'},
  609: 
  610:                                 }
  611:                      );
  612:     my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,                                             $dom);
  613:     if ($putresult eq 'ok') {
  614:         if (exists($currautoenroll{'run'})) {
  615:              if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
  616:                  $changes{'run'} = 1;
  617:              }
  618:         } elsif ($autorun) {
  619:             if ($env{'form.autoenroll_run'} ne '1') {
  620:                 $changes{'run'} = 1;
  621:             }
  622:         }
  623:         if (exists($currautoenroll{sender_uname})) {
  624:             if ($currautoenroll{'sender_uname'} ne $env{'form.sender_uname'}) {
  625:                 $changes{'sender'} = 1;
  626:             }
  627:         } else {
  628:             $changes{'sender'} = 1;
  629:         }
  630:         if (exists($currautoenroll{sender_domain})) {
  631:             if ($currautoenroll{'sender_domain'} ne $env{'form.sender_domain'}) {
  632:                 $changes{'sender'} = 1;
  633:             }
  634:         } else {
  635:             $changes{'sender'} = 1;
  636:         }
  637:         if (keys(%changes) > 0) {
  638:             $resulttext = &mt('Changes made:').'<ul>';
  639:             if ($changes{'run'}) {
  640:                 $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
  641:             }
  642:             if ($changes{'sender'}) {
  643:                 $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$env{'form.sender_uname'}.':'.$env{'form.sender_domain'}).'</li>';
  644:             }
  645:             $resulttext .= '</ul>';
  646:         } else {
  647:             $resulttext = &mt('No changes made to auto-enrollment settings');
  648:         }
  649:     } else {
  650:         $resulttext = &mt('An error occurred: [_1]',$putresult);
  651:     }
  652:     return $resulttext;
  653: }
  654: 
  655: sub modify_autoupdate {
  656:     my ($dom,%domconfig) = @_;
  657:     my ($resulttext,%currautoupdate,%fields,%changes);
  658:     if (ref($domconfig{'autoupdate'}) eq 'HASH') {
  659:         foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
  660:             $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
  661:         }
  662:     }
  663:     my @offon = ('off','on');
  664:     my %title = &Apache::lonlocal::texthash (
  665:                    run => 'Auto-update:',
  666:                    classlists => 'Updates to user information in classlists?'
  667:                 );
  668:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
  669:     my %fieldtitles = &Apache::lonlocal::texthash (
  670:                         id => 'Student/Employee ID',
  671:                         email => 'E-mail address',
  672:                         lastname => 'Last Name',
  673:                         firstname => 'First Name',
  674:                         middlename => 'Middle Name',
  675:                         gen => 'Generation',
  676:                       );
  677:     my $othertitle = &mt('All users');
  678:     if (keys(%{$usertypes}) >  0) {
  679:         $othertitle = "Other users";
  680:     }
  681:     foreach my $key (keys(%env)) {
  682:         if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
  683:             push(@{$fields{$1}},$2);
  684:         }
  685:     }
  686:     my %updatehash = (
  687:                       autoupdate => { run => $env{'form.autoupdate_run'},
  688:                                       classlists => $env{'form.classlists'},
  689:                                       fields => {%fields},
  690:                                     }
  691:                      );
  692:     foreach my $key (keys(%currautoupdate)) {
  693:         if (($key eq 'run') || ($key eq 'classlists')) {
  694:             if (exists($updatehash{autoupdate}{$key})) {
  695:                 if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
  696:                     $changes{$key} = 1;
  697:                 }
  698:             }
  699:         } elsif ($key eq 'fields') {
  700:             if (ref($currautoupdate{$key}) eq 'HASH') {
  701:                 foreach my $item (keys(%{$currautoupdate{$key}})) {
  702:                     if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
  703:                         my $change = 0;
  704:                         foreach my $type (@{$currautoupdate{$key}{$item}}) {
  705:                             if (!exists($fields{$item})) {
  706:                                 $change = 1;
  707:                             } elsif (ref($fields{$item}) eq 'ARRAY') {
  708:                                 if (!grep/^\Q$type\E$/,@{$fields{$item}}) {
  709:                                     $change = 1;
  710:                                 }
  711:                             }
  712:                         }
  713:                         if ($change) {
  714:                             push(@{$changes{$key}},$item);
  715:                         }
  716:                     }
  717:                 }
  718:             }
  719:         }
  720:     }
  721:     foreach my $key (keys(%fields)) {
  722:         if (ref($currautoupdate{'fields'}) eq 'HASH') {
  723:             if (!exists($currautoupdate{'fields'}{$key})) {
  724:                 push(@{$changes{'fields'}},$key);
  725:             }
  726:         } else {
  727:             push(@{$changes{'fields'}},$key);
  728:         }
  729:     }
  730:     my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
  731:                                              $dom);
  732:     if ($putresult eq 'ok') {
  733:         if (keys(%changes) > 0) {
  734:             $resulttext = &mt('Changes made:').'<ul>';
  735:             foreach my $key (sort(keys(%changes))) {
  736:                 if (ref($changes{$key}) eq 'ARRAY') {
  737:                     foreach my $item (@{$changes{$key}}) {
  738:                         my @newvalues;
  739:                         foreach my $type (@{$fields{$item}}) {
  740:                             push(@newvalues,$fieldtitles{$type});
  741:                         }
  742:                         my $newvaluestr;
  743:                         if (@newvalues > 0) {
  744:                             $newvaluestr = join(', ',@newvalues);
  745:                         } else {
  746:                             $newvaluestr = &mt('none');
  747:                         }  
  748:                         if ($item eq 'default') {
  749:                             $resulttext .= '<li>'.&mt("Updates for $othertitle set to: [_1]",$newvaluestr).'</li>';
  750:                         } else {
  751:                             $resulttext .= '<li>'.&mt("Updates for [_1] set to: [_2]",$usertypes->{$item},$newvaluestr).'</li>';
  752:                         }
  753:                     }
  754:                 } else {
  755:                     my $newvalue;
  756:                     if ($key eq 'run') {
  757:                         $newvalue = $offon[$env{'form.autoupdate_run'}];
  758:                     } else {
  759:                         $newvalue = $offon[$env{'form.'.$key}];
  760:                     }
  761:                     $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
  762:                 }
  763:             }
  764:             $resulttext .= '</ul>';
  765:         } else {
  766:             $resulttext = &mt('No changes made to autoupdates');
  767:         }
  768:     } else {
  769:         $resulttext = &mt('An error occurred: [_1]',$putresult);
  770:     }
  771:     return $resulttext;
  772: }
  773: 
  774: 1;
  775: 

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