File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.5: download - view: text, annotated - select for diffs
Sun May 17 00:54:38 2009 UTC (15 years ago) by raeburn
Branches: MAIN
CVS tags: bz5969, bz2851, HEAD, BZ5971-printing-apage
- Include "Parameter Manager" in breadcrumb trail, if course configuration accessed from there.
- Wording change: Functionality -> Settings.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: lonconfigsettings.pm,v 1.5 2009/05/17 00:54:38 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::lonconfigsettings;
   32: 
   33: use strict;
   34: use Apache::lonnet;
   35: use Apache::loncommon();
   36: use Apache::lonhtmlcommon();
   37: use Apache::lonlocal;
   38: 
   39: sub print_header {
   40:     my ($r,$phase,$context,$jscript) = @_;
   41:     my ($pagetitle,$brcrumtitle,$action);
   42:     if ($context eq 'domain') {
   43:         ($pagetitle, $brcrumtitle) = ('View/Modify Domain Settings','Domain Settings');
   44:         $action = '/adm/domainprefs';
   45:     } else {
   46:         ($pagetitle, $brcrumtitle) = ('Course Configuration','Course Configuration');
   47:         $action = '/adm/courseprefs';
   48:     }
   49:     my $alert = &mt('You must select at least one functionality type to display.');
   50:     my $js = '
   51: <script type="text/javascript">
   52: function changePage(formname,newphase) {
   53:     formname.phase.value = newphase;
   54:     numchecked = 0;
   55:     if (formname == document.pickactions) {
   56:         if (formname.actions.length > 0) {
   57:             for (var i = 0; i<formname.actions.length; i++) {
   58:                 if (formname.actions[i].checked) {
   59:                     numchecked ++;
   60:                 }
   61:             }
   62:         } else {
   63:             if (formname.actions.checked) {
   64:                 numchecked ++;
   65:             }
   66:         }
   67:         if (numchecked > 0) {
   68:             formname.submit();
   69:         } else {
   70:             alert("'.$alert.'");
   71:             return;
   72:         }
   73:     }
   74:     formname.submit();
   75: }'."\n";
   76:     if ($phase eq 'pickactions') {
   77:         $js .=
   78:             &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox',numcols => 'radio',})."\n".
   79:             &javascript_set_colnums();
   80:     } elsif ($phase eq 'display') {
   81:         $js .= &color_pick_js()."\n";
   82:     }
   83:     $js .= &Apache::loncommon::viewport_size_js().'
   84: </script>
   85: ';
   86:     if ($jscript) {
   87:         $js .= "
   88: 
   89: $jscript
   90: 
   91: ";
   92:     }
   93:     my $additem;
   94:     if ($phase eq 'pickactions') {
   95:         my %loaditems = (
   96:                     'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);setDisplayColumns();setFormElements(document.pickactions);",
   97:                         );
   98:         $additem = {'add_entries' => \%loaditems,};
   99:     } else {
  100:         my %loaditems = (
  101:                     'onload' => "javascript:getViewportDims(document.$phase.width,document.$phase.height);",
  102:                         );
  103:         $additem = {'add_entries' => \%loaditems,};
  104:     }
  105:     $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
  106:     $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
  107:     $r->print('
  108: <form name="parmform" action="">
  109: <input type="hidden" name="pres_marker" />
  110: <input type="hidden" name="pres_type" />
  111: <input type="hidden" name="pres_value" />
  112: </form>
  113: ');
  114:     $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
  115:               ' enctype="multipart/form-data">');
  116:     return;
  117: }
  118: 
  119: sub print_footer {
  120:     my ($r,$phase,$newphase,$button_text,$actions) = @_;
  121:     $button_text = &mt($button_text);
  122:     $r->print('<input type="hidden" name="phase" value="" />'.
  123:               '<input type="hidden" name="width" value="'.
  124:               $env{'form.width'}.'" />'.
  125:               '<input type="hidden" name="height" value="'.
  126:               $env{'form.height'}.'" />');
  127:     if (defined($env{'form.origin'})) {
  128:         $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
  129:     }
  130:     if (($phase eq 'display') || ($phase eq 'process')) {
  131:         if (ref($actions) eq 'ARRAY') {
  132:             foreach my $item (@{$actions}) {
  133:                 $r->print('<input type="hidden" name="actions" value="'.$item.'" />')."\n";
  134:             }
  135:         }
  136:         $r->print('<input type="hidden" name="numcols" value="'.$env{'form.numcols'}.'" />');
  137:     }
  138:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  139:     if ($phase eq 'process') {
  140:         $r->print('<p><a href='.$dest.'>'.$button_text.'</a></p>');
  141:     } else {
  142:         my $onclick;
  143:         if ($phase eq 'display') {
  144:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  145:         } else {
  146:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  147:         }
  148:         $r->print('<p><input type="button" name="store" value="'.
  149:                   $button_text.'" onclick='.$onclick.' /></p>');
  150:     }
  151:     if ($phase eq 'process') {
  152:         $r->print('</form>'.&Apache::loncommon::end_page());
  153:     }
  154:     return;
  155: }
  156: 
  157: sub make_changes {
  158:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,$allitems) = @_;
  159:     my %brcrumtext = &get_crumb_text();
  160:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  161:     my ($numchanged,%changes,%disallowed);
  162:     &Apache::lonhtmlcommon::add_breadcrumb
  163:       ({href=>"javascript:changePage(document.$phase,'display')",
  164:         text=>$brcrumtext{$context}},
  165:        {href=>"javascript:changePage(document.$phase,'$phase')",
  166:         text=>"Updated"});
  167:     &print_header($r,$phase,$context);
  168:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && 
  169:         (ref($prefs) eq 'HASH')) {
  170:         foreach my $item (@{$prefs_order}) {
  171:             if (grep(/^\Q$item\E$/,@actions)) {
  172:                 if ($context eq 'domain') {
  173:                     $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
  174:                               &Apache::domainprefs::process_changes($r,$dom,
  175:                                           $confname,$item,$roles,$values,));
  176:                 } else {
  177:                     $changes{$item} = {};
  178:                     &Apache::courseprefs::process_changes($dom,$item,$values,
  179:                                                           $prefs->{$item},$changes{$item},
  180:                                                           $allitems,\%disallowed);
  181:                     if (keys(%{$changes{$item}}) > 0) {
  182:                         $numchanged ++;
  183:                     }
  184:                 }
  185:             }
  186:         }
  187:     }
  188:     if ($context eq 'course') {
  189:         if ($numchanged) {
  190:             $r->print(&Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
  191:                                                           $prefs,$values,\%changes));
  192:         } else {
  193:             $r->print(&mt('No changes made to course configuration.'));
  194:         }
  195:         if (keys(%disallowed) > 0) {
  196:             $r->print('<p>');
  197:             foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
  198:                 if (ref($disallowed{$item}) eq 'HASH') {
  199:                     if (keys(%{$disallowed{$item}}) > 0) {
  200:                         $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
  201:                                                                            $prefs));
  202:                     }
  203:                 }
  204:             }
  205:             $r->print('</p>');
  206:         }
  207:     }
  208:     $r->print('<p>');
  209:     my $footer_text = 'Back to configuration display';
  210:     if ($context eq 'course') {
  211:         $footer_text = 'Back to display/edit settings'; 
  212:     }
  213:     &print_footer($r,$phase,'display',$footer_text,\@actions);
  214:     $r->print('</p>');
  215: }
  216: 
  217: sub display_settings {
  218:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
  219:         $allitems) = @_;
  220:     my %brcrumtext = &get_crumb_text();
  221:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  222:     &Apache::lonhtmlcommon::add_breadcrumb
  223:         ({href=>"javascript:changePage(document.$phase,'display')",
  224:           text=>"Display/Edit Settings"});
  225:     &print_header($r,$phase,$context,$jscript);
  226:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) { 
  227:         if (@actions > 0) {
  228:             my $rowsum = 0;
  229:             my (%output,%rowtotal,@items);
  230:             my $halfway = @actions/2;
  231:             foreach my $item (@{$prefs_order}) {
  232:                 if (grep(/^\Q$item\E$/,@actions)) {
  233:                     push(@items,$item);
  234:                     if ($context eq 'domain') {
  235:                         ($output{$item},$rowtotal{$item}) =
  236:                             &Apache::domainprefs::print_config_box($r,$dom,$confname,
  237:                                 $phase,$item,$prefs->{$item},$values->{$item});
  238:                     } else {
  239:                         ($output{$item},$rowtotal{$item}) =
  240:                             &Apache::courseprefs::print_config_box($r,$dom,$phase,
  241:                                 $item,$prefs->{$item},$values,$allitems);
  242:                     }
  243:                     $rowsum += $rowtotal{$item};
  244:                 }
  245:             }
  246:             my $colend;
  247:             my $halfway = $rowsum/2;
  248:             my $aggregate = 0;
  249:             my $sumleft = 0;
  250:             my $sumright = 0;
  251:             my $crossover;
  252:             for (my $i=0; $i<@items; $i++) {
  253:                 $aggregate += $rowtotal{$items[$i]};
  254:                 if ($aggregate > $halfway) {
  255:                     $crossover = $i;
  256:                     last;
  257:                 }
  258:             }
  259:             for (my $i=0; $i<$crossover; $i++) {
  260:                 $sumleft += $rowtotal{$items[$i]};
  261:             }
  262:             for (my $i=$crossover+1; $i<@items; $i++) {
  263:                 $sumright += $rowtotal{$items[$i]};
  264:             }
  265:             if ((@items > 1) && ($env{'form.numcols'} == 2)) {
  266:                 my $sumdiff = $sumright - $sumleft;
  267:                 if ($sumdiff > 0) {
  268:                     $colend = $crossover + 1;
  269:                 } else {
  270:                     $colend = $crossover;
  271:                 }
  272:             } else {
  273:                 $colend = @items;
  274:             }
  275:             $r->print('<p><table class="LC_double_column"><tr><td class="LC_left_col">');            for (my $i=0; $i<$colend; $i++) {
  276:                 $r->print($output{$items[$i]});
  277:             }
  278:             $r->print('</td><td></td><td class="LC_right_col">');
  279:             if ($colend < @items) {
  280:                 for (my $i=$colend; $i<@items; $i++) {
  281:                     $r->print($output{$items[$i]});
  282:                 }
  283:             }
  284:             $r->print('</td></tr></table></p>');
  285:             $r->print(&print_footer($r,$phase,'process','Save',\@actions));
  286:         } else {
  287:             $r->print('<input type="hidden" name="phase" value="" />'.
  288:                   '<input type="hidden" name="numcols" value="'.
  289:                   $env{'form.numcols'}.'" />'."\n".
  290:                   '<span class="LC_error">'.&mt('No settings chosen').
  291:                   '</span>');
  292:         }
  293:         $r->print('</form>');
  294:     }
  295:     $r->print(&Apache::loncommon::end_page());
  296:     return;
  297: }
  298: 
  299: sub display_choices {
  300:     my ($r,$phase,$context,$prefs_order,$prefs) = @_;
  301:     if ($phase eq '') {
  302:         $phase = 'pickactions';
  303:     }
  304:     my %helphash;
  305:     &print_header($r,$phase,$context);
  306:     $r->print('<h3>'.&mt('Settings to display/modify').'</h3>');
  307:     $r->print('<script type="text/javascript">'."\n".
  308:               &Apache::loncommon::check_uncheck_jscript()."\n".
  309:               '</script>'."\n".'<p><input type="button" value="'.&mt('check all').'" '.
  310:               'onclick="javascript:checkAll(document.pickactions.actions)"'.
  311:               ' />'.('&nbsp;'x2).
  312:               '<input type="button" value="'.&mt('uncheck all').'" '.
  313:               'onclick="javascript:uncheckAll(document.pickactions.actions)"'.
  314:               ' /></p><div class="LC_left_float">');
  315:     my ($numitems,$midpoint,$seconddiv,$count);
  316:     if (ref($prefs_order) eq 'ARRAY') {
  317:         $numitems = @{$prefs_order};
  318:     }
  319:     $midpoint = int($numitems/2);
  320:     if ($numitems%2) {
  321:         $midpoint ++;
  322:     }
  323:     $count = 0;
  324:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
  325:         foreach my $item (@{$prefs_order}) {
  326:             $r->print('<h4>'.
  327:                       &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
  328:                       '<label><input type="checkbox" name="actions" value="'.$item.
  329:                       '" />&nbsp;'.&mt($prefs->{$item}->{'text'}).'</label></h4>');
  330:             $count ++;
  331:             if ((!$seconddiv) && ($count >= $midpoint)) {
  332:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  333:                 $seconddiv = 1;
  334:             }
  335:         }
  336:         $r->print('</div><div class="LC_clear_float_footer"></div><h3>'.
  337:                   &mt('Display options').'</h3>'."\n".
  338:                   '<p><span class="LC_nobreak">'.&mt('Display using: ')."\n".
  339:                   '<label><input type="radio" name="numcols" value="1" />'.
  340:                   &mt('one column').'</label>&nbsp;&nbsp;<label>'.
  341:                   '<input type="radio" name="numcols" value="2" />'.
  342:                   &mt('two columns').'</label></span></p>');
  343:     }
  344:     $r->print(&print_footer($r,$phase,'display','Go'));
  345:     $r->print('</form>');
  346:     $r->print(&Apache::loncommon::end_page());
  347:     return;
  348: }
  349: 
  350: sub javascript_set_colnums {
  351:     return <<END;
  352: function setDisplayColumns() {
  353:     if (document.pickactions.width.value > 1100) {
  354:         document.pickactions.numcols[1].checked = true;
  355:     } else {
  356:         document.pickactions.numcols[0].checked = true;
  357:     }
  358: }
  359: END
  360: }
  361: 
  362: sub color_pick_js {
  363:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  364:     my $output = <<"ENDCOL";
  365:     function pclose() {
  366:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
  367:         parmwin.close();
  368:     }
  369: 
  370:     $pjump_def
  371: 
  372:     function psub() {
  373:         pclose();
  374:         if (document.parmform.pres_marker.value!='') {
  375:             if (document.parmform.pres_type.value!='') {
  376:                 eval('document.display.'+
  377:                      document.parmform.pres_marker.value+
  378:                      '.value=document.parmform.pres_value.value;');
  379:             }
  380:         } else {
  381:             document.parmform.pres_value.value='';
  382:             document.parmform.pres_marker.value='';
  383:         }
  384:     }
  385: 
  386:     function get_id (span_id) {
  387:         if (document.getElementById) {
  388:             return document.getElementById(span_id);
  389:         }
  390:         if (document.all) {
  391:             return document.all[span_id];
  392:         }
  393:         return false;
  394:     }
  395: 
  396:     function colchg_span (span_id_str,new_color_item) {
  397:         var span_ref = get_id(span_id_str);
  398:         if (span_ref.style) { span_ref = span_ref.style; }
  399:         span_ref.background = new_color_item.value;
  400:         span_ref.backgroundColor = new_color_item.value;
  401:         span_ref.bgColor = new_color_item.value;
  402:     }
  403: 
  404: ENDCOL
  405:     return $output;
  406: }
  407: 
  408: sub get_crumb_text {
  409:     my %brcrumbtext = (
  410:                        domain => 'Domain Settings',
  411:                        course => 'Display/Edit Settings',
  412:                      );
  413:     return %brcrumbtext;
  414: }
  415: 
  416: 1;

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