File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.6: download - view: text, annotated - select for diffs
Sun Aug 23 17:21:22 2009 UTC (14 years, 9 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_8_99_0, HEAD, GCI_2
- xhtml.

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

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