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