Annotation of loncom/interface/lonconfigsettings.pm, revision 1.8
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.8 ! raeburn 4: # $Id: lonconfigsettings.pm,v 1.7 2009/10/29 14:57: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: }
304: $r->print('<p><table class="LC_double_column"><tr><td class="LC_left_col">'); for (my $i=0; $i<$colend; $i++) {
305: $r->print($output{$items[$i]});
306: }
307: $r->print('</td><td></td><td class="LC_right_col">');
308: if ($colend < @items) {
309: for (my $i=$colend; $i<@items; $i++) {
310: $r->print($output{$items[$i]});
311: }
312: }
313: $r->print('</td></tr></table></p>');
314: $r->print(&print_footer($r,$phase,'process','Save',\@actions));
315: } else {
316: $r->print('<input type="hidden" name="phase" value="" />'.
317: '<input type="hidden" name="numcols" value="'.
318: $env{'form.numcols'}.'" />'."\n".
319: '<span class="LC_error">'.&mt('No settings chosen').
320: '</span>');
321: }
322: $r->print('</form>');
323: }
324: $r->print(&Apache::loncommon::end_page());
325: return;
326: }
327:
328: sub display_choices {
329: my ($r,$phase,$context,$prefs_order,$prefs) = @_;
330: if ($phase eq '') {
331: $phase = 'pickactions';
332: }
333: my %helphash;
334: &print_header($r,$phase,$context);
1.5 raeburn 335: $r->print('<h3>'.&mt('Settings to display/modify').'</h3>');
1.1 raeburn 336: $r->print('<script type="text/javascript">'."\n".
1.6 raeburn 337: '// <![CDATA['."\n".
1.1 raeburn 338: &Apache::loncommon::check_uncheck_jscript()."\n".
1.6 raeburn 339: '// ]]>'."\n".
1.1 raeburn 340: '</script>'."\n".'<p><input type="button" value="'.&mt('check all').'" '.
341: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
342: ' />'.(' 'x2).
343: '<input type="button" value="'.&mt('uncheck all').'" '.
344: 'onclick="javascript:uncheckAll(document.pickactions.actions)"'.
345: ' /></p><div class="LC_left_float">');
346: my ($numitems,$midpoint,$seconddiv,$count);
347: if (ref($prefs_order) eq 'ARRAY') {
348: $numitems = @{$prefs_order};
349: }
350: $midpoint = int($numitems/2);
351: if ($numitems%2) {
352: $midpoint ++;
353: }
354: $count = 0;
355: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
356: foreach my $item (@{$prefs_order}) {
357: $r->print('<h4>'.
358: &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
359: '<label><input type="checkbox" name="actions" value="'.$item.
360: '" /> '.&mt($prefs->{$item}->{'text'}).'</label></h4>');
361: $count ++;
362: if ((!$seconddiv) && ($count >= $midpoint)) {
363: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
364: $seconddiv = 1;
365: }
366: }
367: $r->print('</div><div class="LC_clear_float_footer"></div><h3>'.
368: &mt('Display options').'</h3>'."\n".
369: '<p><span class="LC_nobreak">'.&mt('Display using: ')."\n".
370: '<label><input type="radio" name="numcols" value="1" />'.
371: &mt('one column').'</label> <label>'.
372: '<input type="radio" name="numcols" value="2" />'.
373: &mt('two columns').'</label></span></p>');
374: }
375: $r->print(&print_footer($r,$phase,'display','Go'));
376: $r->print('</form>');
377: $r->print(&Apache::loncommon::end_page());
378: return;
379: }
380:
381: sub javascript_set_colnums {
382: return <<END;
383: function setDisplayColumns() {
384: if (document.pickactions.width.value > 1100) {
385: document.pickactions.numcols[1].checked = true;
386: } else {
387: document.pickactions.numcols[0].checked = true;
388: }
389: }
390: END
391: }
392:
393: sub color_pick_js {
394: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
395: my $output = <<"ENDCOL";
396: function pclose() {
397: parmwin=window.open("/adm/rat/empty.html","LONCAPAparms","height=350,width=350,scrollbars=no,menubar=no");
398: parmwin.close();
399: }
400:
401: $pjump_def
402:
403: function psub() {
404: pclose();
405: if (document.parmform.pres_marker.value!='') {
406: if (document.parmform.pres_type.value!='') {
407: eval('document.display.'+
408: document.parmform.pres_marker.value+
409: '.value=document.parmform.pres_value.value;');
410: }
411: } else {
412: document.parmform.pres_value.value='';
413: document.parmform.pres_marker.value='';
414: }
415: }
416:
417: function get_id (span_id) {
418: if (document.getElementById) {
419: return document.getElementById(span_id);
420: }
421: if (document.all) {
422: return document.all[span_id];
423: }
424: return false;
425: }
426:
427: function colchg_span (span_id_str,new_color_item) {
428: var span_ref = get_id(span_id_str);
429: if (span_ref.style) { span_ref = span_ref.style; }
430: span_ref.background = new_color_item.value;
431: span_ref.backgroundColor = new_color_item.value;
432: span_ref.bgColor = new_color_item.value;
433: }
434:
435: ENDCOL
436: return $output;
437: }
438:
439: sub get_crumb_text {
440: my %brcrumbtext = (
441: domain => 'Domain Settings',
1.4 raeburn 442: course => 'Display/Edit Settings',
1.1 raeburn 443: );
444: return %brcrumbtext;
445: }
446:
447: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>