1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: lonconfigsettings.pm,v 1.21.4.2 2012/12/10 23:31:38 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:
39: sub print_header {
40: my ($r,$phase,$context,$jscript,$container) = @_;
41: my ($pagetitle,$brcrumtitle,$action,$call_category_check);
42: if ($context eq 'domain') {
43: ($pagetitle, $brcrumtitle) = ('View/Modify Domain Settings','View/Modify Domain Settings');
44: $action = '/adm/domainprefs';
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: }
57: } else {
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: }
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">
68: // <![CDATA[
69:
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: }
92: '.$call_category_check.'
93: formname.submit();
94: }'."\n";
95: if ($phase eq 'pickactions') {
96: $js .= &Apache::lonhtmlcommon::color_picker();
97: $js .=
98: &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
99: } elsif ($phase eq 'display') {
100: $js .= &Apache::lonhtmlcommon::color_picker();
101: $js .= &color_pick_js()."\n";
102: }
103: $js .= &Apache::loncommon::viewport_size_js().'
104:
105: // ]]>
106: </script>
107: ';
108: if ($jscript) {
109: $js .= "
110:
111: $jscript
112:
113: ";
114: }
115: my $additem;
116: if ($phase eq 'pickactions') {
117: my %loaditems = (
118: 'onload' => "setFormElements(document.pickactions);",
119: );
120: $additem = {'add_entries' => \%loaditems,};
121: }
122: $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
123: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
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,$container) = @_;
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(
153: &Apache::lonhtmlcommon::actionbox(
154: ['<a href='.$dest.'>'.$button_text.'</a>']));
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: $r->print(&Apache::loncommon::end_page());
168: }
169: return;
170: }
171:
172: sub make_changes {
173: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,$allitems,$container) = @_;
174: my %brcrumtext = &get_crumb_text();
175: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
176: my ($numchanged,%changes,%disallowed);
177: &Apache::lonhtmlcommon::add_breadcrumb
178: ({href=>"javascript:changePage(document.$phase,'display')",
179: text=>$brcrumtext{$context}},
180: {href=>"javascript:changePage(document.$phase,'$phase')",
181: text=>"Updated"});
182: &print_header($r,$phase,$context,undef,$container);
183: my $crstype;
184: if ($context eq 'course') {
185: $crstype = &Apache::loncommon::course_type();
186: }
187: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') &&
188: (ref($prefs) eq 'HASH')) {
189: foreach my $item (@{$prefs_order}) {
190: if (grep(/^\Q$item\E$/,@actions)) {
191: if ($context eq 'domain') {
192: $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
193: &Apache::domainprefs::process_changes($r,$dom,
194: $confname,$item,$roles,$values));
195: } else {
196: $changes{$item} = {};
197: &Apache::courseprefs::process_changes($dom,$item,$values,
198: $prefs->{$item},$changes{$item},
199: $allitems,\%disallowed,$crstype);
200: if (keys(%{$changes{$item}}) > 0) {
201: $numchanged ++;
202: }
203: }
204: }
205: }
206: }
207: if ($context eq 'course') {
208: if ($numchanged) {
209: my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
210: $prefs,$values,\%changes,$crstype);
211: $r->print(&Apache::loncommon::confirmwrapper($message));
212: } else {
213: if ($crstype eq 'Community') {
214: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
215: } else {
216: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
217: }
218: }
219: if (keys(%disallowed) > 0) {
220: $r->print('<p>');
221: foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
222: if (ref($disallowed{$item}) eq 'HASH') {
223: if (keys(%{$disallowed{$item}}) > 0) {
224: $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
225: $prefs,$crstype));
226: }
227: }
228: }
229: $r->print('</p>');
230: }
231: }
232: $r->print('<p>');
233: my $footer_text = 'Back to configuration display';
234: if ($context eq 'course') {
235: $footer_text = 'Back to display/edit settings';
236: }
237: &print_footer($r,$phase,'display',$footer_text,\@actions,$container);
238: $r->print('</p>');
239: }
240:
241: sub display_settings {
242: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
243: $allitems,$crstype,$container) = @_;
244: my %brcrumtext = &get_crumb_text();
245: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
246: &Apache::lonhtmlcommon::add_breadcrumb
247: ({href=>"javascript:changePage(document.$phase,'display')",
248: text=>"Display/Edit Settings"});
249: &print_header($r,$phase,$context,$jscript,$container);
250: my $divwidth = 900;
251: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) {
252: if (@actions > 0) {
253: my $rowsum = 0;
254: my (%output,%rowtotal,@items);
255: foreach my $item (@{$prefs_order}) {
256: if (grep(/^\Q$item\E$/,@actions)) {
257: push(@items,$item);
258: if ($context eq 'domain') {
259: if ($item eq 'usersessions') {
260: $r->print('<script type="text/javascript">'."\n".
261: '// <![CDATA['."\n".
262: &Apache::loncommon::check_uncheck_jscript()."\n".
263: '// ]]>'."\n".
264: '</script>'."\n");
265: }
266: ($output{$item},$rowtotal{$item}) =
267: &Apache::domainprefs::print_config_box($r,$dom,$confname,
268: $phase,$item,$prefs->{$item},$values->{$item});
269: } else {
270: ($output{$item},$rowtotal{$item}) =
271: &Apache::courseprefs::print_config_box($r,$dom,$phase,
272: $item,$prefs->{$item},$values,$allitems,$crstype);
273: }
274: $rowsum += $rowtotal{$item};
275: }
276: }
277: $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
278: for (my $i=0; $i<@items; $i++) {
279: $r->print($output{$items[$i]});
280: }
281: $r->print('</div>');
282: $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container));
283: } else {
284: $r->print('<input type="hidden" name="phase" value="" />'.
285: '<span class="LC_error">'.&mt('No settings chosen').
286: '</span>');
287: }
288: $r->print('</form>');
289: }
290: $r->print(&Apache::loncommon::end_page());
291: return;
292: }
293:
294: sub display_choices {
295: my ($r,$phase,$context,$prefs_order,$prefs,$container) = @_;
296: if ($phase eq '') {
297: $phase = 'pickactions';
298: }
299: my %helphash;
300: &print_header($r,$phase,$context,undef,$container);
301: $r->print('<script type="text/javascript">'."\n".
302: '// <![CDATA['."\n".
303: &Apache::loncommon::check_uncheck_jscript()."\n".
304: '// ]]>'."\n".
305: '</script>'."\n");
306: $r->print('<h3>'.&mt('Settings to display/modify').'</h3>'.
307: '<div><input type="button" value="'.&mt('check all').'" '.
308: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
309: ' />'.(' 'x2).
310: '<input type="button" value="'.&mt('uncheck all').'" '.
311: 'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
312: "\n".
313: '</div><div class="LC_left_float">');
314: my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
315: if (ref($prefs_order) eq 'ARRAY') {
316: $numitems = @{$prefs_order};
317: }
318: my $numcols = 3;
319: $maxincol = int($numitems/$numcols);
320: if ($numitems%$numcols) {
321: $maxincol ++;
322: }
323: $firstthird = $maxincol;
324: $secondthird = $firstthird + $maxincol;
325: $count = 0;
326: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
327: foreach my $item (@{$prefs_order}) {
328: $r->print('<h4>'.
329: &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
330: '<label><input type="checkbox" name="actions" value="'.$item.
331: '" /> '.&mt($prefs->{$item}->{'text'}).'</label></h4>');
332: $count ++;
333: if ((!$seconddiv) && ($count >= $firstthird)) {
334: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
335: $seconddiv = 1;
336: }
337: if ((!$thirddiv) && ($count >= $secondthird)) {
338: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
339: $thirddiv = 1;
340: }
341: }
342: $r->print('</div><br clear="all" />');
343: }
344: $r->print(&print_footer($r,$phase,'display','Display',undef,$container));
345: $r->print('</form>');
346: $r->print(&Apache::loncommon::end_page());
347: return;
348: }
349:
350: sub color_pick_js {
351: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
352: my $output = <<"ENDCOL";
353:
354: $pjump_def
355:
356: function psub() {
357: modalWindow.close();
358: if (document.parmform.pres_marker.value!='') {
359: if (document.parmform.pres_type.value!='') {
360: eval('document.display.'+
361: document.parmform.pres_marker.value+
362: '.value=document.parmform.pres_value.value;');
363: }
364: } else {
365: document.parmform.pres_value.value='';
366: document.parmform.pres_marker.value='';
367: }
368: }
369:
370: function get_id (span_id) {
371: if (document.getElementById) {
372: return document.getElementById(span_id);
373: }
374: if (document.all) {
375: return document.all[span_id];
376: }
377: return false;
378: }
379:
380: function colchg_span (span_id_str,new_color_item) {
381: var span_ref = get_id(span_id_str);
382: if (span_ref.style) { span_ref = span_ref.style; }
383: span_ref.background = new_color_item.value;
384: span_ref.backgroundColor = new_color_item.value;
385: span_ref.bgColor = new_color_item.value;
386: }
387:
388: ENDCOL
389: return $output;
390: }
391:
392: sub get_crumb_text {
393: my %brcrumbtext = (
394: domain => 'Domain Settings',
395: course => 'Display/Edit Settings',
396: );
397: return %brcrumbtext;
398: }
399:
400: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>