Annotation of loncom/interface/lonconfigsettings.pm, revision 1.9
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.9 ! faziophi 4: # $Id: lonconfigsettings.pm,v 1.8 2009/11/23 21:45:18 raeburn 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) {
215: $r->print(&Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
1.7 raeburn 216: $prefs,$values,\%changes,$crstype));
1.4 raeburn 217: } else {
1.7 raeburn 218: if ($crstype eq 'Community') {
219: $r->print(&mt("No changes made to community configuration."));
220: } else {
221: $r->print(&mt("No changes made to course configuration."));
222: }
1.4 raeburn 223: }
224: if (keys(%disallowed) > 0) {
225: $r->print('<p>');
226: foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
227: if (ref($disallowed{$item}) eq 'HASH') {
228: if (keys(%{$disallowed{$item}}) > 0) {
229: $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
1.7 raeburn 230: $prefs,$crstype));
1.4 raeburn 231: }
232: }
233: }
234: $r->print('</p>');
235: }
236: }
1.1 raeburn 237: $r->print('<p>');
1.4 raeburn 238: my $footer_text = 'Back to configuration display';
239: if ($context eq 'course') {
240: $footer_text = 'Back to display/edit settings';
241: }
242: &print_footer($r,$phase,'display',$footer_text,\@actions);
1.1 raeburn 243: $r->print('</p>');
244: }
245:
246: sub display_settings {
1.3 raeburn 247: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
1.7 raeburn 248: $allitems,$crstype) = @_;
1.1 raeburn 249: my %brcrumtext = &get_crumb_text();
250: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
251: &Apache::lonhtmlcommon::add_breadcrumb
252: ({href=>"javascript:changePage(document.$phase,'display')",
1.4 raeburn 253: text=>"Display/Edit Settings"});
1.2 raeburn 254: &print_header($r,$phase,$context,$jscript);
1.1 raeburn 255: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) {
256: if (@actions > 0) {
257: my $rowsum = 0;
258: my (%output,%rowtotal,@items);
259: my $halfway = @actions/2;
260: foreach my $item (@{$prefs_order}) {
261: if (grep(/^\Q$item\E$/,@actions)) {
262: push(@items,$item);
263: if ($context eq 'domain') {
264: ($output{$item},$rowtotal{$item}) =
265: &Apache::domainprefs::print_config_box($r,$dom,$confname,
266: $phase,$item,$prefs->{$item},$values->{$item});
267: } else {
268: ($output{$item},$rowtotal{$item}) =
269: &Apache::courseprefs::print_config_box($r,$dom,$phase,
1.7 raeburn 270: $item,$prefs->{$item},$values,$allitems,$crstype);
1.1 raeburn 271: }
272: $rowsum += $rowtotal{$item};
273: }
274: }
275: my $colend;
276: my $halfway = $rowsum/2;
277: my $aggregate = 0;
278: my $sumleft = 0;
279: my $sumright = 0;
280: my $crossover;
281: for (my $i=0; $i<@items; $i++) {
282: $aggregate += $rowtotal{$items[$i]};
283: if ($aggregate > $halfway) {
284: $crossover = $i;
285: last;
286: }
287: }
288: for (my $i=0; $i<$crossover; $i++) {
289: $sumleft += $rowtotal{$items[$i]};
290: }
291: for (my $i=$crossover+1; $i<@items; $i++) {
292: $sumright += $rowtotal{$items[$i]};
293: }
294: if ((@items > 1) && ($env{'form.numcols'} == 2)) {
295: my $sumdiff = $sumright - $sumleft;
296: if ($sumdiff > 0) {
297: $colend = $crossover + 1;
298: } else {
299: $colend = $crossover;
300: }
301: } else {
302: $colend = @items;
303: }
1.9 ! faziophi 304: if ($context ne 'course') {
! 305: $r->print('<p><table class="LC_double_column"><tr><td class="LC_left_col">');
! 306: }
! 307: else {
! 308: $r->print('<div id="prefs" style="max-width:900px;margin: 10px auto 10px auto;">');
! 309: }
! 310: for (my $i=0; $i<$colend; $i++) {
1.1 raeburn 311: $r->print($output{$items[$i]});
312: }
1.9 ! faziophi 313: if ($context ne 'course') {
! 314: $r->print('</td><td></td><td class="LC_right_col">');
! 315: }
1.1 raeburn 316: if ($colend < @items) {
317: for (my $i=$colend; $i<@items; $i++) {
318: $r->print($output{$items[$i]});
319: }
320: }
1.9 ! faziophi 321: if ($context ne 'course') {
! 322: $r->print('</td></tr></table></p>');
! 323: }
! 324: else {
! 325: $r->print('</div>');
! 326: }
! 327: $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions));
1.1 raeburn 328: } else {
329: $r->print('<input type="hidden" name="phase" value="" />'.
330: '<input type="hidden" name="numcols" value="'.
331: $env{'form.numcols'}.'" />'."\n".
332: '<span class="LC_error">'.&mt('No settings chosen').
333: '</span>');
334: }
335: $r->print('</form>');
336: }
1.9 ! faziophi 337: if ($context eq 'course') {
! 338: $r->print('
! 339: <script type="text/javascript">
! 340: $(document).ready(function(){
! 341: $("#prefs").accordion({
! 342: autoHeight: false
! 343: });
! 344: $("#prefs td.LC_left_item").css("text-align", "right");
! 345: $("#prefs td.LC_left_item").css("width", "40%");
! 346: $("#prefs td.LC_left_item").css("padding-right", "10px");
! 347: $("#prefs td.LC_right_item").css("text-align", "left");
! 348: $("#prefs td.LC_right_item").css("width", "60%");
! 349: });
! 350: </script>
! 351: ');
! 352: }
1.1 raeburn 353: $r->print(&Apache::loncommon::end_page());
354: return;
355: }
356:
357: sub display_choices {
358: my ($r,$phase,$context,$prefs_order,$prefs) = @_;
359: if ($phase eq '') {
360: $phase = 'pickactions';
361: }
362: my %helphash;
363: &print_header($r,$phase,$context);
1.5 raeburn 364: $r->print('<h3>'.&mt('Settings to display/modify').'</h3>');
1.1 raeburn 365: $r->print('<script type="text/javascript">'."\n".
1.6 raeburn 366: '// <![CDATA['."\n".
1.1 raeburn 367: &Apache::loncommon::check_uncheck_jscript()."\n".
1.6 raeburn 368: '// ]]>'."\n".
1.1 raeburn 369: '</script>'."\n".'<p><input type="button" value="'.&mt('check all').'" '.
370: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
371: ' />'.(' 'x2).
372: '<input type="button" value="'.&mt('uncheck all').'" '.
373: 'onclick="javascript:uncheckAll(document.pickactions.actions)"'.
374: ' /></p><div class="LC_left_float">');
375: my ($numitems,$midpoint,$seconddiv,$count);
376: if (ref($prefs_order) eq 'ARRAY') {
377: $numitems = @{$prefs_order};
378: }
379: $midpoint = int($numitems/2);
380: if ($numitems%2) {
381: $midpoint ++;
382: }
383: $count = 0;
384: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
385: foreach my $item (@{$prefs_order}) {
386: $r->print('<h4>'.
387: &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
388: '<label><input type="checkbox" name="actions" value="'.$item.
389: '" /> '.&mt($prefs->{$item}->{'text'}).'</label></h4>');
390: $count ++;
391: if ((!$seconddiv) && ($count >= $midpoint)) {
392: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
393: $seconddiv = 1;
394: }
395: }
396: $r->print('</div><div class="LC_clear_float_footer"></div><h3>'.
397: &mt('Display options').'</h3>'."\n".
398: '<p><span class="LC_nobreak">'.&mt('Display using: ')."\n".
399: '<label><input type="radio" name="numcols" value="1" />'.
400: &mt('one column').'</label> <label>'.
401: '<input type="radio" name="numcols" value="2" />'.
402: &mt('two columns').'</label></span></p>');
403: }
404: $r->print(&print_footer($r,$phase,'display','Go'));
405: $r->print('</form>');
406: $r->print(&Apache::loncommon::end_page());
407: return;
408: }
409:
410: sub javascript_set_colnums {
411: return <<END;
412: function setDisplayColumns() {
413: if (document.pickactions.width.value > 1100) {
414: document.pickactions.numcols[1].checked = true;
415: } else {
416: document.pickactions.numcols[0].checked = true;
417: }
418: }
419: END
420: }
421:
422: sub color_pick_js {
423: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
424: my $output = <<"ENDCOL";
425: function pclose() {
426: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
427: parmwin.close();
428: }
429:
430: $pjump_def
431:
432: function psub() {
433: pclose();
434: if (document.parmform.pres_marker.value!='') {
435: if (document.parmform.pres_type.value!='') {
436: eval('document.display.'+
437: document.parmform.pres_marker.value+
438: '.value=document.parmform.pres_value.value;');
439: }
440: } else {
441: document.parmform.pres_value.value='';
442: document.parmform.pres_marker.value='';
443: }
444: }
445:
446: function get_id (span_id) {
447: if (document.getElementById) {
448: return document.getElementById(span_id);
449: }
450: if (document.all) {
451: return document.all[span_id];
452: }
453: return false;
454: }
455:
456: function colchg_span (span_id_str,new_color_item) {
457: var span_ref = get_id(span_id_str);
458: if (span_ref.style) { span_ref = span_ref.style; }
459: span_ref.background = new_color_item.value;
460: span_ref.backgroundColor = new_color_item.value;
461: span_ref.bgColor = new_color_item.value;
462: }
463:
464: ENDCOL
465: return $output;
466: }
467:
468: sub get_crumb_text {
469: my %brcrumbtext = (
470: domain => 'Domain Settings',
1.4 raeburn 471: course => 'Display/Edit Settings',
1.1 raeburn 472: );
473: return %brcrumbtext;
474: }
475:
476: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>