Annotation of loncom/interface/lonconfigsettings.pm, revision 1.21.4.2
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.21.4.2! raeburn 4: # $Id: lonconfigsettings.pm,v 1.21.4.1 2012/05/02 20:32:37 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.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') {
1.21.4.2! raeburn 96: $js .= &Apache::lonhtmlcommon::color_picker();
1.1 raeburn 97: $js .=
1.12 raeburn 98: &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
1.1 raeburn 99: } elsif ($phase eq 'display') {
1.21.4.2! raeburn 100: $js .= &Apache::lonhtmlcommon::color_picker();
1.1 raeburn 101: $js .= &color_pick_js()."\n";
102: }
103: $js .= &Apache::loncommon::viewport_size_js().'
1.6 raeburn 104:
105: // ]]>
1.1 raeburn 106: </script>
107: ';
1.2 raeburn 108: if ($jscript) {
109: $js .= "
110:
111: $jscript
112:
113: ";
114: }
1.1 raeburn 115: my $additem;
116: if ($phase eq 'pickactions') {
117: my %loaditems = (
1.12 raeburn 118: 'onload' => "setFormElements(document.pickactions);",
1.1 raeburn 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 {
1.20 www 137: my ($r,$phase,$newphase,$button_text,$actions,$container) = @_;
1.1 raeburn 138: $button_text = &mt($button_text);
1.12 raeburn 139: $r->print('<input type="hidden" name="phase" value="" />');
1.5 raeburn 140: if (defined($env{'form.origin'})) {
141: $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
142: }
1.1 raeburn 143: if (($phase eq 'display') || ($phase eq 'process')) {
144: if (ref($actions) eq 'ARRAY') {
145: foreach my $item (@{$actions}) {
1.16 raeburn 146: $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
1.1 raeburn 147: }
148: }
149: }
150: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
151: if ($phase eq 'process') {
1.21.4.2! raeburn 152: $r->print(
! 153: &Apache::lonhtmlcommon::actionbox(
! 154: ['<a href='.$dest.'>'.$button_text.'</a>']));
1.1 raeburn 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') {
1.20 www 166: $r->print('</form>');
167: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 168: }
169: return;
170: }
171:
172: sub make_changes {
1.20 www 173: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,$allitems,$container) = @_;
1.1 raeburn 174: my %brcrumtext = &get_crumb_text();
175: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.4 raeburn 176: my ($numchanged,%changes,%disallowed);
1.1 raeburn 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"});
1.20 www 182: &print_header($r,$phase,$context,undef,$container);
1.7 raeburn 183: my $crstype;
184: if ($context eq 'course') {
185: $crstype = &Apache::loncommon::course_type();
186: }
1.1 raeburn 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') {
1.4 raeburn 192: $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
193: &Apache::domainprefs::process_changes($r,$dom,
1.7 raeburn 194: $confname,$item,$roles,$values));
1.1 raeburn 195: } else {
1.4 raeburn 196: $changes{$item} = {};
197: &Apache::courseprefs::process_changes($dom,$item,$values,
198: $prefs->{$item},$changes{$item},
1.7 raeburn 199: $allitems,\%disallowed,$crstype);
1.4 raeburn 200: if (keys(%{$changes{$item}}) > 0) {
201: $numchanged ++;
202: }
1.1 raeburn 203: }
204: }
205: }
206: }
1.4 raeburn 207: if ($context eq 'course') {
208: if ($numchanged) {
1.11 wenzelju 209: my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
210: $prefs,$values,\%changes,$crstype);
211: $r->print(&Apache::loncommon::confirmwrapper($message));
1.4 raeburn 212: } else {
1.7 raeburn 213: if ($crstype eq 'Community') {
1.11 wenzelju 214: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
1.7 raeburn 215: } else {
1.11 wenzelju 216: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
1.7 raeburn 217: }
1.4 raeburn 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},
1.7 raeburn 225: $prefs,$crstype));
1.4 raeburn 226: }
227: }
228: }
229: $r->print('</p>');
230: }
231: }
1.1 raeburn 232: $r->print('<p>');
1.4 raeburn 233: my $footer_text = 'Back to configuration display';
234: if ($context eq 'course') {
235: $footer_text = 'Back to display/edit settings';
236: }
1.20 www 237: &print_footer($r,$phase,'display',$footer_text,\@actions,$container);
1.1 raeburn 238: $r->print('</p>');
239: }
240:
241: sub display_settings {
1.3 raeburn 242: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
1.20 www 243: $allitems,$crstype,$container) = @_;
1.1 raeburn 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')",
1.4 raeburn 248: text=>"Display/Edit Settings"});
1.20 www 249: &print_header($r,$phase,$context,$jscript,$container);
1.12 raeburn 250: my $divwidth = 900;
1.1 raeburn 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') {
1.15 raeburn 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: }
1.1 raeburn 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,
1.7 raeburn 272: $item,$prefs->{$item},$values,$allitems,$crstype);
1.1 raeburn 273: }
274: $rowsum += $rowtotal{$item};
275: }
276: }
1.12 raeburn 277: $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
1.1 raeburn 278: for (my $i=0; $i<@items; $i++) {
279: $r->print($output{$items[$i]});
280: }
1.12 raeburn 281: $r->print('</div>');
1.20 www 282: $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container));
1.1 raeburn 283: } else {
284: $r->print('<input type="hidden" name="phase" value="" />'.
1.12 raeburn 285: '<span class="LC_error">'.&mt('No settings chosen').
286: '</span>');
1.1 raeburn 287: }
288: $r->print('</form>');
289: }
290: $r->print(&Apache::loncommon::end_page());
291: return;
292: }
293:
294: sub display_choices {
1.20 www 295: my ($r,$phase,$context,$prefs_order,$prefs,$container) = @_;
1.1 raeburn 296: if ($phase eq '') {
297: $phase = 'pickactions';
298: }
299: my %helphash;
1.20 www 300: &print_header($r,$phase,$context,undef,$container);
1.1 raeburn 301: $r->print('<script type="text/javascript">'."\n".
1.6 raeburn 302: '// <![CDATA['."\n".
1.1 raeburn 303: &Apache::loncommon::check_uncheck_jscript()."\n".
1.6 raeburn 304: '// ]]>'."\n".
1.12 raeburn 305: '</script>'."\n");
306: $r->print('<h3>'.&mt('Settings to display/modify').'</h3>'.
1.13 raeburn 307: '<div><input type="button" value="'.&mt('check all').'" '.
1.1 raeburn 308: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
309: ' />'.(' 'x2).
310: '<input type="button" value="'.&mt('uncheck all').'" '.
1.12 raeburn 311: 'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
312: "\n".
1.13 raeburn 313: '</div><div class="LC_left_float">');
1.12 raeburn 314: my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
1.1 raeburn 315: if (ref($prefs_order) eq 'ARRAY') {
316: $numitems = @{$prefs_order};
317: }
1.12 raeburn 318: my $numcols = 3;
319: $maxincol = int($numitems/$numcols);
320: if ($numitems%$numcols) {
321: $maxincol ++;
1.1 raeburn 322: }
1.14 raeburn 323: $firstthird = $maxincol;
324: $secondthird = $firstthird + $maxincol;
1.1 raeburn 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 ++;
1.12 raeburn 333: if ((!$seconddiv) && ($count >= $firstthird)) {
1.1 raeburn 334: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
335: $seconddiv = 1;
336: }
1.12 raeburn 337: if ((!$thirddiv) && ($count >= $secondthird)) {
338: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
339: $thirddiv = 1;
1.13 raeburn 340: }
1.1 raeburn 341: }
1.12 raeburn 342: $r->print('</div><br clear="all" />');
1.1 raeburn 343: }
1.20 www 344: $r->print(&print_footer($r,$phase,'display','Display',undef,$container));
1.1 raeburn 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() {
1.21 www 357: modalWindow.close();
1.1 raeburn 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',
1.4 raeburn 395: course => 'Display/Edit Settings',
1.1 raeburn 396: );
397: return %brcrumbtext;
398: }
399:
400: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>