File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.23: download - view: text, annotated - select for diffs
Fri Dec 7 16:12:18 2012 UTC (11 years, 5 months ago) by bisitz
Branches: MAIN
CVS tags: HEAD
Consistent layout: actionbox

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

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