File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.2: download - view: text, annotated - select for diffs
Wed Apr 22 12:42:16 2009 UTC (15 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- domainprefs.pm
 - Current values are passed to &process_changes() as a reference to a hash.

- lonconfigsettings
 - &print_header() takes an additional (optional) fourth arg - $jscript.
 - in course context: courseprefs::process_changes() used to process changes.
                      courseprefs::print_config_box(): sixth arg: $values hash ref.

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: lonconfigsettings.pm,v 1.2 2009/04/22 12:42:16 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) = ('Set Course Environment','Course Environment');
   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 (($phase eq 'display') || ($phase eq 'process')) {
  128:         if (ref($actions) eq 'ARRAY') {
  129:             foreach my $item (@{$actions}) {
  130:                 $r->print('<input type="hidden" name="actions" value="'.$item.'" />')."\n";
  131:             }
  132:         }
  133:         $r->print('<input type="hidden" name="numcols" value="'.$env{'form.numcols'}.'" />');
  134:     }
  135:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  136:     if ($phase eq 'process') {
  137:         $r->print('<p><a href='.$dest.'>'.$button_text.'</a></p>');
  138:     } else {
  139:         my $onclick;
  140:         if ($phase eq 'display') {
  141:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  142:         } else {
  143:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  144:         }
  145:         $r->print('<p><input type="button" name="store" value="'.
  146:                   $button_text.'" onclick='.$onclick.' /></p>');
  147:     }
  148:     if ($phase eq 'process') {
  149:         $r->print('</form>'.&Apache::loncommon::end_page());
  150:     }
  151:     return;
  152: }
  153: 
  154: sub make_changes {
  155:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles) = @_;
  156:     my %brcrumtext = &get_crumb_text();
  157:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  158:     &Apache::lonhtmlcommon::add_breadcrumb
  159:       ({href=>"javascript:changePage(document.$phase,'display')",
  160:         text=>$brcrumtext{$context}},
  161:        {href=>"javascript:changePage(document.$phase,'$phase')",
  162:         text=>"Updated"});
  163:     &print_header($r,$phase,$context);
  164:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && 
  165:         (ref($prefs) eq 'HASH')) {
  166:         foreach my $item (@{$prefs_order}) {
  167:             if (grep(/^\Q$item\E$/,@actions)) {
  168:                 $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>');
  169:                 if ($context eq 'domain') {
  170:                     $r->print(&Apache::domainprefs::process_changes($r,$dom,$confname,$item,$roles,$values));
  171:                 } else {
  172:                     $r->print(&Apache::courseprefs::process_changes($r,$dom,$item,$values));
  173:                 }
  174:             }
  175:         }
  176:     }
  177:     $r->print('<p>');
  178:     &print_footer($r,$phase,'display','Back to configuration display',\@actions);
  179:     $r->print('</p>');
  180: }
  181: 
  182: sub display_settings {
  183:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript) = @_;
  184:     my %brcrumtext = &get_crumb_text();
  185:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  186:     &Apache::lonhtmlcommon::add_breadcrumb
  187:         ({href=>"javascript:changePage(document.$phase,'display')",
  188:           text=>"Course Settings"});
  189:     &print_header($r,$phase,$context,$jscript);
  190:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) { 
  191:         if (@actions > 0) {
  192:             my $rowsum = 0;
  193:             my (%output,%rowtotal,@items);
  194:             my $halfway = @actions/2;
  195:             foreach my $item (@{$prefs_order}) {
  196:                 if (grep(/^\Q$item\E$/,@actions)) {
  197:                     push(@items,$item);
  198:                     if ($context eq 'domain') {
  199:                         ($output{$item},$rowtotal{$item}) =
  200:                             &Apache::domainprefs::print_config_box($r,$dom,$confname,
  201:                                 $phase,$item,$prefs->{$item},$values->{$item});
  202:                     } else {
  203:                         ($output{$item},$rowtotal{$item}) =
  204:                             &Apache::courseprefs::print_config_box($r,$dom,$phase,
  205:                                 $item,$prefs->{$item},$values);
  206:                     }
  207:                     $rowsum += $rowtotal{$item};
  208:                 }
  209:             }
  210:             my $colend;
  211:             my $halfway = $rowsum/2;
  212:             my $aggregate = 0;
  213:             my $sumleft = 0;
  214:             my $sumright = 0;
  215:             my $crossover;
  216:             for (my $i=0; $i<@items; $i++) {
  217:                 $aggregate += $rowtotal{$items[$i]};
  218:                 if ($aggregate > $halfway) {
  219:                     $crossover = $i;
  220:                     last;
  221:                 }
  222:             }
  223:             for (my $i=0; $i<$crossover; $i++) {
  224:                 $sumleft += $rowtotal{$items[$i]};
  225:             }
  226:             for (my $i=$crossover+1; $i<@items; $i++) {
  227:                 $sumright += $rowtotal{$items[$i]};
  228:             }
  229:             if ((@items > 1) && ($env{'form.numcols'} == 2)) {
  230:                 my $sumdiff = $sumright - $sumleft;
  231:                 if ($sumdiff > 0) {
  232:                     $colend = $crossover + 1;
  233:                 } else {
  234:                     $colend = $crossover;
  235:                 }
  236:             } else {
  237:                 $colend = @items;
  238:             }
  239:             $r->print('<p><table class="LC_double_column"><tr><td class="LC_left_col">');            for (my $i=0; $i<$colend; $i++) {
  240:                 $r->print($output{$items[$i]});
  241:             }
  242:             $r->print('</td><td></td><td class="LC_right_col">');
  243:             if ($colend < @items) {
  244:                 for (my $i=$colend; $i<@items; $i++) {
  245:                     $r->print($output{$items[$i]});
  246:                 }
  247:             }
  248:             $r->print('</td></tr></table></p>');
  249:             $r->print(&print_footer($r,$phase,'process','Save',\@actions));
  250:         } else {
  251:             $r->print('<input type="hidden" name="phase" value="" />'.
  252:                   '<input type="hidden" name="numcols" value="'.
  253:                   $env{'form.numcols'}.'" />'."\n".
  254:                   '<span class="LC_error">'.&mt('No settings chosen').
  255:                   '</span>');
  256:         }
  257:         $r->print('</form>');
  258:     }
  259:     $r->print(&Apache::loncommon::end_page());
  260:     return;
  261: }
  262: 
  263: sub display_choices {
  264:     my ($r,$phase,$context,$prefs_order,$prefs) = @_;
  265:     if ($phase eq '') {
  266:         $phase = 'pickactions';
  267:     }
  268:     my %helphash;
  269:     &print_header($r,$phase,$context);
  270:     $r->print('<h3>'.&mt('Functionality to display/modify').'</h3>');
  271:     $r->print('<script type="text/javascript">'."\n".
  272:               &Apache::loncommon::check_uncheck_jscript()."\n".
  273:               '</script>'."\n".'<p><input type="button" value="'.&mt('check all').'" '.
  274:               'onclick="javascript:checkAll(document.pickactions.actions)"'.
  275:               ' />'.('&nbsp;'x2).
  276:               '<input type="button" value="'.&mt('uncheck all').'" '.
  277:               'onclick="javascript:uncheckAll(document.pickactions.actions)"'.
  278:               ' /></p><div class="LC_left_float">');
  279:     my ($numitems,$midpoint,$seconddiv,$count);
  280:     if (ref($prefs_order) eq 'ARRAY') {
  281:         $numitems = @{$prefs_order};
  282:     }
  283:     $midpoint = int($numitems/2);
  284:     if ($numitems%2) {
  285:         $midpoint ++;
  286:     }
  287:     $count = 0;
  288:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
  289:         foreach my $item (@{$prefs_order}) {
  290:             $r->print('<h4>'.
  291:                       &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
  292:                       '<label><input type="checkbox" name="actions" value="'.$item.
  293:                       '" />&nbsp;'.&mt($prefs->{$item}->{'text'}).'</label></h4>');
  294:             $count ++;
  295:             if ((!$seconddiv) && ($count >= $midpoint)) {
  296:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  297:                 $seconddiv = 1;
  298:             }
  299:         }
  300:         $r->print('</div><div class="LC_clear_float_footer"></div><h3>'.
  301:                   &mt('Display options').'</h3>'."\n".
  302:                   '<p><span class="LC_nobreak">'.&mt('Display using: ')."\n".
  303:                   '<label><input type="radio" name="numcols" value="1" />'.
  304:                   &mt('one column').'</label>&nbsp;&nbsp;<label>'.
  305:                   '<input type="radio" name="numcols" value="2" />'.
  306:                   &mt('two columns').'</label></span></p>');
  307:     }
  308:     $r->print(&print_footer($r,$phase,'display','Go'));
  309:     $r->print('</form>');
  310:     $r->print(&Apache::loncommon::end_page());
  311:     return;
  312: }
  313: 
  314: sub javascript_set_colnums {
  315:     return <<END;
  316: function setDisplayColumns() {
  317:     if (document.pickactions.width.value > 1100) {
  318:         document.pickactions.numcols[1].checked = true;
  319:     } else {
  320:         document.pickactions.numcols[0].checked = true;
  321:     }
  322: }
  323: END
  324: }
  325: 
  326: sub color_pick_js {
  327:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  328:     my $output = <<"ENDCOL";
  329:     function pclose() {
  330:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
  331:         parmwin.close();
  332:     }
  333: 
  334:     $pjump_def
  335: 
  336:     function psub() {
  337:         pclose();
  338:         if (document.parmform.pres_marker.value!='') {
  339:             if (document.parmform.pres_type.value!='') {
  340:                 eval('document.display.'+
  341:                      document.parmform.pres_marker.value+
  342:                      '.value=document.parmform.pres_value.value;');
  343:             }
  344:         } else {
  345:             document.parmform.pres_value.value='';
  346:             document.parmform.pres_marker.value='';
  347:         }
  348:     }
  349: 
  350:     function get_id (span_id) {
  351:         if (document.getElementById) {
  352:             return document.getElementById(span_id);
  353:         }
  354:         if (document.all) {
  355:             return document.all[span_id];
  356:         }
  357:         return false;
  358:     }
  359: 
  360:     function colchg_span (span_id_str,new_color_item) {
  361:         var span_ref = get_id(span_id_str);
  362:         if (span_ref.style) { span_ref = span_ref.style; }
  363:         span_ref.background = new_color_item.value;
  364:         span_ref.backgroundColor = new_color_item.value;
  365:         span_ref.bgColor = new_color_item.value;
  366:     }
  367: 
  368: ENDCOL
  369:     return $output;
  370: }
  371: 
  372: sub get_crumb_text {
  373:     my %brcrumbtext = (
  374:                        domain => 'Domain Settings',
  375:                        course => 'Course Settings',
  376:                      );
  377:     return %brcrumbtext;
  378: }
  379: 
  380: 1;

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