File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.18: download - view: text, annotated - select for diffs
Thu Mar 31 15:35:54 2011 UTC (13 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- No "Course Settings" and "Content and Problem Settings" tabs
  when module is used in domain context (for Domain Configuration -- DC roles).

    1: # The LearningOnline Network with CAPA
    2: # Handler to set domain-wide configuration settings
    3: #
    4: # $Id: lonconfigsettings.pm,v 1.18 2011/03/31 15:35:54 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: use Apache::lonparmset();
   39: 
   40: sub print_header {
   41:     my ($r,$phase,$context,$jscript) = @_;
   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 .=
   98:             &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
   99:     } elsif ($phase eq 'display') {
  100:         $js .= &color_pick_js()."\n";
  101:     }
  102:     $js .= &Apache::loncommon::viewport_size_js().'
  103: 
  104: // ]]>
  105: </script>
  106: ';
  107:     if ($jscript) {
  108:         $js .= "
  109: 
  110: $jscript
  111: 
  112: ";
  113:     }
  114:     my $additem;
  115:     if ($phase eq 'pickactions') {
  116:         my %loaditems = (
  117:                     'onload' => "setFormElements(document.pickactions);",
  118:                         );
  119:         $additem = {'add_entries' => \%loaditems,};
  120:     }
  121:     $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
  122:     $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
  123:     if ($context eq 'course') {
  124:         &Apache::lonparmset::startSettingsScreen($r,'coursepref');
  125:     }
  126:     $r->print('
  127: <form name="parmform" action="">
  128: <input type="hidden" name="pres_marker" />
  129: <input type="hidden" name="pres_type" />
  130: <input type="hidden" name="pres_value" />
  131: </form>
  132: ');
  133:     $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
  134:               ' enctype="multipart/form-data">');
  135:     return;
  136: }
  137: 
  138: sub print_footer {
  139:     my ($r,$context,$phase,$newphase,$button_text,$actions) = @_;
  140:     $button_text = &mt($button_text);
  141:     $r->print('<input type="hidden" name="phase" value="" />');
  142:     if (defined($env{'form.origin'})) {
  143:         $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
  144:     }
  145:     if (($phase eq 'display') || ($phase eq 'process')) {
  146:         if (ref($actions) eq 'ARRAY') {
  147:             foreach my $item (@{$actions}) {
  148:                 $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
  149:             }
  150:         }
  151:     }
  152:     my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  153:     if ($phase eq 'process') {
  154:         $r->print('<p><a href='.$dest.'>'.$button_text.'</a></p>');
  155:     } else {
  156:         my $onclick;
  157:         if ($phase eq 'display') {
  158:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  159:         } else {
  160:             $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
  161:         }
  162:         $r->print('<p><input type="button" name="store" value="'.
  163:                   $button_text.'" onclick='.$onclick.' /></p>');
  164:     }
  165:     if ($phase eq 'process') {
  166:         $r->print('</form>');
  167:         if ($context eq 'course') {
  168:             &Apache::lonparmset::endSettingsScreen($r);
  169:         }
  170:         $r->print(&Apache::loncommon::end_page());
  171:     }
  172:     return;
  173: }
  174: 
  175: sub make_changes {
  176:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,$allitems) = @_;
  177:     my %brcrumtext = &get_crumb_text();
  178:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  179:     my ($numchanged,%changes,%disallowed);
  180:     &Apache::lonhtmlcommon::add_breadcrumb
  181:       ({href=>"javascript:changePage(document.$phase,'display')",
  182:         text=>$brcrumtext{$context}},
  183:        {href=>"javascript:changePage(document.$phase,'$phase')",
  184:         text=>"Updated"});
  185:     &print_header($r,$phase,$context);
  186:     my $crstype;
  187:     if ($context eq 'course') {
  188:         $crstype = &Apache::loncommon::course_type();
  189:     }
  190:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && 
  191:         (ref($prefs) eq 'HASH')) {
  192:         foreach my $item (@{$prefs_order}) {
  193:             if (grep(/^\Q$item\E$/,@actions)) {
  194:                 if ($context eq 'domain') {
  195:                     $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
  196:                               &Apache::domainprefs::process_changes($r,$dom,
  197:                                           $confname,$item,$roles,$values));
  198:                 } else {
  199:                     $changes{$item} = {};
  200:                     &Apache::courseprefs::process_changes($dom,$item,$values,
  201:                                                           $prefs->{$item},$changes{$item},
  202:                                                           $allitems,\%disallowed,$crstype);
  203:                     if (keys(%{$changes{$item}}) > 0) {
  204:                         $numchanged ++;
  205:                     }
  206:                 }
  207:             }
  208:         }
  209:     }
  210:     if ($context eq 'course') {
  211:         if ($numchanged) {
  212:             my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
  213:                                                           $prefs,$values,\%changes,$crstype);
  214:             $r->print(&Apache::loncommon::confirmwrapper($message));
  215:         } else {
  216:             if ($crstype eq 'Community') {
  217:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
  218:             } else {
  219:                 $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
  220:             }
  221:         }
  222:         if (keys(%disallowed) > 0) {
  223:             $r->print('<p>');
  224:             foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
  225:                 if (ref($disallowed{$item}) eq 'HASH') {
  226:                     if (keys(%{$disallowed{$item}}) > 0) {
  227:                         $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
  228:                                                                            $prefs,$crstype));
  229:                     }
  230:                 }
  231:             }
  232:             $r->print('</p>');
  233:         }
  234:     }
  235:     $r->print('<p>');
  236:     my $footer_text = 'Back to configuration display';
  237:     if ($context eq 'course') {
  238:         $footer_text = 'Back to display/edit settings'; 
  239:     }
  240:     &print_footer($r,$context,$phase,'display',$footer_text,\@actions);
  241:     $r->print('</p>');
  242: }
  243: 
  244: sub display_settings {
  245:     my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
  246:         $allitems,$crstype) = @_;
  247:     my %brcrumtext = &get_crumb_text();
  248:     my @actions = &Apache::loncommon::get_env_multiple('form.actions');
  249:     &Apache::lonhtmlcommon::add_breadcrumb
  250:         ({href=>"javascript:changePage(document.$phase,'display')",
  251:           text=>"Display/Edit Settings"});
  252:     &print_header($r,$phase,$context,$jscript);
  253:     my $divwidth = 900;
  254:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) { 
  255:         if (@actions > 0) {
  256:             my $rowsum = 0;
  257:             my (%output,%rowtotal,@items);
  258:             foreach my $item (@{$prefs_order}) {
  259:                 if (grep(/^\Q$item\E$/,@actions)) {
  260:                     push(@items,$item);
  261:                     if ($context eq 'domain') {
  262:                         if ($item eq 'usersessions') {
  263:                             $r->print('<script type="text/javascript">'."\n".
  264:                                       '// <![CDATA['."\n".
  265:                                       &Apache::loncommon::check_uncheck_jscript()."\n".
  266:                                       '// ]]>'."\n".
  267:                                       '</script>'."\n");
  268:                         }
  269:                         ($output{$item},$rowtotal{$item}) =
  270:                             &Apache::domainprefs::print_config_box($r,$dom,$confname,
  271:                                 $phase,$item,$prefs->{$item},$values->{$item});
  272:                     } else {
  273:                         ($output{$item},$rowtotal{$item}) =
  274:                             &Apache::courseprefs::print_config_box($r,$dom,$phase,
  275:                                 $item,$prefs->{$item},$values,$allitems,$crstype);
  276:                     }
  277:                     $rowsum += $rowtotal{$item};
  278:                 }
  279:             }
  280:             $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
  281:             for (my $i=0; $i<@items; $i++) {
  282:                 $r->print($output{$items[$i]});
  283:             }
  284:             $r->print('</div>');
  285:             $r->print(&print_footer($r,$context,$phase,'process','Save Changes',\@actions));
  286:         } else {
  287:             $r->print('<input type="hidden" name="phase" value="" />'.
  288:                       '<span class="LC_error">'.&mt('No settings chosen').
  289:                       '</span>');
  290:         }
  291:         $r->print('</form>');
  292:     }
  293:     if ($context eq 'course') {
  294:     	$r->print('
  295: <script type="text/javascript">
  296: 	$(document).ready(function(){
  297: 		$("#prefs").accordion({
  298: 			autoHeight: false
  299: 		});
  300: 		if ($(".LC_nested tr.advanced").get(0)) {
  301: 			$(".LC_nested tr.advanced").each(function() {
  302: 				$(this).hide();
  303: 				p = $(this).parents("div.ui-accordion-content")
  304: 				if (p.find(".LC_advanced_toggle").length) {
  305: 					return;
  306: 				}
  307: 				p.prepend("<span class=\'LC_advanced_toggle\'><input type=\"checkbox\"/>Show advanced options</span>");
  308: 			});
  309: 			$(".LC_advanced_toggle input").change(function() {
  310: 				if($(this).is(":checked")) {
  311: 					$(this).parents("div.ui-accordion-content").find("tr.advanced").fadeIn("normal");
  312: 				} else {
  313: 					$(this).parents("div.ui-accordion-content").find("tr.advanced").fadeOut("normal");		
  314: 				}
  315: 			});
  316: 		}
  317: 	});
  318: </script>
  319: ');
  320:     }
  321:     $r->print(&Apache::loncommon::end_page());
  322:     return;
  323: }
  324: 
  325: sub display_choices {
  326:     my ($r,$phase,$context,$prefs_order,$prefs) = @_;
  327:     if ($phase eq '') {
  328:         $phase = 'pickactions';
  329:     }
  330:     my %helphash;
  331:     &print_header($r,$phase,$context);
  332:     $r->print('<script type="text/javascript">'."\n".
  333:               '// <![CDATA['."\n".
  334:               &Apache::loncommon::check_uncheck_jscript()."\n".
  335:               '// ]]>'."\n".
  336:               '</script>'."\n");
  337:     $r->print('<h3>'.&mt('Settings to display/modify').'</h3>'.
  338:               '<div><input type="button" value="'.&mt('check all').'" '.
  339:               'onclick="javascript:checkAll(document.pickactions.actions)"'.
  340:               ' />'.('&nbsp;'x2).
  341:               '<input type="button" value="'.&mt('uncheck all').'" '.
  342:               'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
  343:               "\n".
  344:               '</div><div class="LC_left_float">');
  345:     my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
  346:     if (ref($prefs_order) eq 'ARRAY') {
  347:         $numitems = @{$prefs_order};
  348:     }
  349:     my $numcols = 3;
  350:     $maxincol = int($numitems/$numcols);
  351:     if ($numitems%$numcols) {
  352:         $maxincol ++;
  353:     }
  354:     $firstthird = $maxincol;
  355:     $secondthird = $firstthird + $maxincol;
  356:     $count = 0;
  357:     if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
  358:         foreach my $item (@{$prefs_order}) {
  359:             $r->print('<h4>'.
  360:                       &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
  361:                       '<label><input type="checkbox" name="actions" value="'.$item.
  362:                       '" />&nbsp;'.&mt($prefs->{$item}->{'text'}).'</label></h4>');
  363:             $count ++;
  364:             if ((!$seconddiv) && ($count >= $firstthird)) {
  365:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  366:                 $seconddiv = 1;
  367:             }
  368:             if ((!$thirddiv) && ($count >= $secondthird)) {
  369:                 $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
  370:                 $thirddiv = 1;
  371:             }
  372:         }
  373:         $r->print('</div><br clear="all" />');
  374:     }
  375:     $r->print(&print_footer($r,$context,$phase,'display','Display'));
  376:     $r->print('</form>');
  377:     $r->print(&Apache::loncommon::end_page());
  378:     return;
  379: }
  380: 
  381: sub color_pick_js {
  382:     my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
  383:     my $output = <<"ENDCOL";
  384:     function pclose() {
  385:         parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
  386:         parmwin.close();
  387:     }
  388: 
  389:     $pjump_def
  390: 
  391:     function psub() {
  392:         pclose();
  393:         if (document.parmform.pres_marker.value!='') {
  394:             if (document.parmform.pres_type.value!='') {
  395:                 eval('document.display.'+
  396:                      document.parmform.pres_marker.value+
  397:                      '.value=document.parmform.pres_value.value;');
  398:             }
  399:         } else {
  400:             document.parmform.pres_value.value='';
  401:             document.parmform.pres_marker.value='';
  402:         }
  403:     }
  404: 
  405:     function get_id (span_id) {
  406:         if (document.getElementById) {
  407:             return document.getElementById(span_id);
  408:         }
  409:         if (document.all) {
  410:             return document.all[span_id];
  411:         }
  412:         return false;
  413:     }
  414: 
  415:     function colchg_span (span_id_str,new_color_item) {
  416:         var span_ref = get_id(span_id_str);
  417:         if (span_ref.style) { span_ref = span_ref.style; }
  418:         span_ref.background = new_color_item.value;
  419:         span_ref.backgroundColor = new_color_item.value;
  420:         span_ref.bgColor = new_color_item.value;
  421:     }
  422: 
  423: ENDCOL
  424:     return $output;
  425: }
  426: 
  427: sub get_crumb_text {
  428:     my %brcrumbtext = (
  429:                        domain => 'Domain Settings',
  430:                        course => 'Display/Edit Settings',
  431:                      );
  432:     return %brcrumbtext;
  433: }
  434: 
  435: 1;

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