File:  [LON-CAPA] / loncom / interface / lonconfigsettings.pm
Revision 1.17: download - view: text, annotated - select for diffs
Thu Jan 13 22:49:47 2011 UTC (13 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
For 3.0: Settings

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

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