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