File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.3: download - view: text, annotated - select for diffs
Sun Apr 26 00:09:53 2009 UTC (15 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- &display_settings() takes additional (optional) arg - $allitems.
- $allitems is passed as additional arg in call to &courseprefs::print_config_box().

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

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