File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.7: download - view: text, annotated - select for diffs
Thu Oct 29 14:57:18 2009 UTC (14 years, 7 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Accommodate Communities:
  - Wording variants: course -> community, Course -> Community,
                      Classlist -> Membership, Staff -> Facilitators,
                      Student -> Member, student -> member.
  - Role choices: co role instead of cc role for communities

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

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