File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.4: download - view: text, annotated - select for diffs
Tue May 12 21:20:42 2009 UTC (15 years ago) by raeburn
Branches: MAIN
CVS tags: HEAD, BZ5434-fox
Usability improvements for course configuration screen.

lonconfigsettings.pm
- Wording change in breadcrumbs: "Display/Edit Settings" replaces "Course Settings".
- Changes in args passed to courseprefs::process_changes().
- Added call to courseprefs::store_changes to save to environment.db
- Added call to courseprefs::display_disallowed().

courseprefs.pm
- Moved code to generate array of names of all course configuration settings to &get_allitems() routine to facilitate reuse.
- Text descriptions of config settings moved to hash within entry for each category.
- Hash ref $disallowed passed as additional arg to process_changes() to accumulate requested changes that are not permitted.
- &process_changes() routine used to populate %changes hash with settings that have changed (and their new values).
- &check_clone() used to check requested cloners have valid username/domain.
- &store_changes() used to populate %storehash with change settings so they can be written to environment.db and also generates output to show what has been changed.
- Ability to create (new) custom course setting added tp print_other().
- Replace use of &Apache::lonnet::privileged() with retrieval of &Apache::lonnet::get_domain_roles() for dc roles.
- &get_lang_choices() routine added to retrieve hash of supported languages.
- &cloners_javascript() added to provide update_cloners() javascript function which will toggle radio buttons appropriately for any domain, any user from specified domain etc.
- &update_env() to append certain course config changes to current %env, and also update nohist_courseids.db
- &display_disallowed() to display information about requested setting changes which did not occur because they were disallowed.
- course environment settings are deleted from environment.db if they are changed to undef.
- Work in progess - logging (and logging interface) still needed.

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

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