Annotation of loncom/interface/lonconfigsettings.pm, revision 1.29
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.29 ! raeburn 4: # $Id: lonconfigsettings.pm,v 1.28 2014/02/12 20:37:42 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;
1.20 www 38: use Apache::lonparmset();
1.1 raeburn 39:
40: sub print_header {
1.20 www 41: my ($r,$phase,$context,$jscript,$container) = @_;
1.24 raeburn 42: my ($pagetitle,$brcrumtitle,$action,$call_category_check,$crstype);
1.1 raeburn 43: if ($context eq 'domain') {
1.12 raeburn 44: ($pagetitle, $brcrumtitle) = ('View/Modify Domain Settings','View/Modify Domain Settings');
1.1 raeburn 45: $action = '/adm/domainprefs';
1.8 raeburn 46: if ($phase eq 'display') {
47: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
48: if (grep(/^coursecategories$/,@actions)) {
49: $call_category_check = qq|
50: if (formname == document.display) {
51: if (!categoryCheck(formname)) {
52: return;
53: }
54: }
55: |;
56: }
57: }
1.1 raeburn 58: } else {
1.24 raeburn 59: $crstype = &Apache::loncommon::course_type();
60: if ($crstype eq 'Community') {
1.7 raeburn 61: ($pagetitle,$brcrumtitle) = ('Community Configuration','Community Configuration');
62: } else {
63: ($pagetitle,$brcrumtitle) = ('Course Configuration','Course Configuration');
64: }
1.1 raeburn 65: $action = '/adm/courseprefs';
66: }
67: my $alert = &mt('You must select at least one functionality type to display.');
68: my $js = '
69: <script type="text/javascript">
1.6 raeburn 70: // <![CDATA[
71:
1.1 raeburn 72: function changePage(formname,newphase) {
73: formname.phase.value = newphase;
74: numchecked = 0;
75: if (formname == document.pickactions) {
76: if (formname.actions.length > 0) {
77: for (var i = 0; i<formname.actions.length; i++) {
78: if (formname.actions[i].checked) {
79: numchecked ++;
80: }
81: }
82: } else {
83: if (formname.actions.checked) {
84: numchecked ++;
85: }
86: }
87: if (numchecked > 0) {
88: formname.submit();
89: } else {
90: alert("'.$alert.'");
91: return;
92: }
93: }
1.8 raeburn 94: '.$call_category_check.'
1.1 raeburn 95: formname.submit();
96: }'."\n";
97: if ($phase eq 'pickactions') {
1.22 foxr 98: $js .= &Apache::lonhtmlcommon::color_picker();
1.1 raeburn 99: $js .=
1.12 raeburn 100: &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
1.1 raeburn 101: } elsif ($phase eq 'display') {
1.22 foxr 102: $js .= &Apache::lonhtmlcommon::color_picker();
1.1 raeburn 103: $js .= &color_pick_js()."\n";
104: }
105: $js .= &Apache::loncommon::viewport_size_js().'
1.6 raeburn 106:
107: // ]]>
1.1 raeburn 108: </script>
109: ';
1.2 raeburn 110: if ($jscript) {
111: $js .= "
112:
113: $jscript
114:
115: ";
116: }
1.1 raeburn 117: my $additem;
118: if ($phase eq 'pickactions') {
119: my %loaditems = (
1.12 raeburn 120: 'onload' => "setFormElements(document.pickactions);",
1.1 raeburn 121: );
122: $additem = {'add_entries' => \%loaditems,};
123: }
124: $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
125: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
126: $r->print('
127: <form name="parmform" action="">
128: <input type="hidden" name="pres_marker" />
129: <input type="hidden" name="pres_type" />
130: <input type="hidden" name="pres_value" />
131: </form>
132: ');
1.20 www 133: if ($container) {
1.24 raeburn 134: &Apache::lonparmset::startSettingsScreen($r,$container,$crstype);
1.20 www 135: }
1.1 raeburn 136: $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
137: ' enctype="multipart/form-data">');
138: return;
139: }
140:
141: sub print_footer {
1.20 www 142: my ($r,$phase,$newphase,$button_text,$actions,$container) = @_;
1.1 raeburn 143: $button_text = &mt($button_text);
1.12 raeburn 144: $r->print('<input type="hidden" name="phase" value="" />');
1.5 raeburn 145: if (defined($env{'form.origin'})) {
146: $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
147: }
1.1 raeburn 148: if (($phase eq 'display') || ($phase eq 'process')) {
149: if (ref($actions) eq 'ARRAY') {
150: foreach my $item (@{$actions}) {
1.16 raeburn 151: $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
1.1 raeburn 152: }
153: }
154: }
155: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
156: if ($phase eq 'process') {
1.23 bisitz 157: $r->print(
158: &Apache::lonhtmlcommon::actionbox(
159: ['<a href='.$dest.'>'.$button_text.'</a>']));
1.1 raeburn 160: } else {
161: my $onclick;
162: if ($phase eq 'display') {
163: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
164: } else {
165: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
166: }
167: $r->print('<p><input type="button" name="store" value="'.
168: $button_text.'" onclick='.$onclick.' /></p>');
169: }
170: if ($phase eq 'process') {
1.20 www 171: $r->print('</form>');
172: if ($container) {
173: &Apache::lonparmset::endSettingsScreen($r);
174: }
175: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 176: }
177: return;
178: }
179:
180: sub make_changes {
1.20 www 181: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,$allitems,$container) = @_;
1.1 raeburn 182: my %brcrumtext = &get_crumb_text();
183: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.4 raeburn 184: my ($numchanged,%changes,%disallowed);
1.1 raeburn 185: &Apache::lonhtmlcommon::add_breadcrumb
186: ({href=>"javascript:changePage(document.$phase,'display')",
187: text=>$brcrumtext{$context}},
188: {href=>"javascript:changePage(document.$phase,'$phase')",
189: text=>"Updated"});
1.20 www 190: &print_header($r,$phase,$context,undef,$container);
1.27 raeburn 191: my ($crstype,%lastact);
1.7 raeburn 192: if ($context eq 'course') {
193: $crstype = &Apache::loncommon::course_type();
194: }
1.1 raeburn 195: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') &&
196: (ref($prefs) eq 'HASH')) {
197: foreach my $item (@{$prefs_order}) {
198: if (grep(/^\Q$item\E$/,@actions)) {
199: if ($context eq 'domain') {
1.4 raeburn 200: $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
201: &Apache::domainprefs::process_changes($r,$dom,
1.27 raeburn 202: $confname,$item,$roles,$values,\%lastact));
1.1 raeburn 203: } else {
1.4 raeburn 204: $changes{$item} = {};
205: &Apache::courseprefs::process_changes($dom,$item,$values,
206: $prefs->{$item},$changes{$item},
1.7 raeburn 207: $allitems,\%disallowed,$crstype);
1.4 raeburn 208: if (keys(%{$changes{$item}}) > 0) {
209: $numchanged ++;
210: }
1.1 raeburn 211: }
212: }
213: }
214: }
1.4 raeburn 215: if ($context eq 'course') {
216: if ($numchanged) {
1.11 wenzelju 217: my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
218: $prefs,$values,\%changes,$crstype);
219: $r->print(&Apache::loncommon::confirmwrapper($message));
1.4 raeburn 220: } else {
1.7 raeburn 221: if ($crstype eq 'Community') {
1.11 wenzelju 222: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
1.7 raeburn 223: } else {
1.11 wenzelju 224: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
1.7 raeburn 225: }
1.4 raeburn 226: }
227: if (keys(%disallowed) > 0) {
228: $r->print('<p>');
229: foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
230: if (ref($disallowed{$item}) eq 'HASH') {
231: if (keys(%{$disallowed{$item}}) > 0) {
232: $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
1.7 raeburn 233: $prefs,$crstype));
1.4 raeburn 234: }
235: }
236: }
237: $r->print('</p>');
238: }
239: }
1.1 raeburn 240: $r->print('<p>');
1.4 raeburn 241: my $footer_text = 'Back to configuration display';
242: if ($context eq 'course') {
243: $footer_text = 'Back to display/edit settings';
244: }
1.20 www 245: &print_footer($r,$phase,'display',$footer_text,\@actions,$container);
1.1 raeburn 246: $r->print('</p>');
1.27 raeburn 247: return \%lastact;
1.1 raeburn 248: }
249:
250: sub display_settings {
1.3 raeburn 251: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
1.20 www 252: $allitems,$crstype,$container) = @_;
1.1 raeburn 253: my %brcrumtext = &get_crumb_text();
254: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
255: &Apache::lonhtmlcommon::add_breadcrumb
256: ({href=>"javascript:changePage(document.$phase,'display')",
1.4 raeburn 257: text=>"Display/Edit Settings"});
1.20 www 258: &print_header($r,$phase,$context,$jscript,$container);
1.12 raeburn 259: my $divwidth = 900;
1.1 raeburn 260: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) {
261: if (@actions > 0) {
262: my $rowsum = 0;
263: my (%output,%rowtotal,@items);
264: foreach my $item (@{$prefs_order}) {
265: if (grep(/^\Q$item\E$/,@actions)) {
266: push(@items,$item);
267: if ($context eq 'domain') {
1.29 ! raeburn 268: my $settings;
! 269: if (ref($values) eq 'HASH') {
! 270: $settings = $values->{$item};
! 271: }
1.15 raeburn 272: if ($item eq 'usersessions') {
273: $r->print('<script type="text/javascript">'."\n".
274: '// <![CDATA['."\n".
275: &Apache::loncommon::check_uncheck_jscript()."\n".
276: '// ]]>'."\n".
277: '</script>'."\n");
1.28 raeburn 278: } elsif ($item eq 'selfcreation') {
1.29 ! raeburn 279: if (ref($values) eq 'HASH') {
! 280: $settings = $values->{'usercreation'};
! 281: }
! 282: } elsif ($item eq 'defaults') {
! 283: if (ref($values->{'inststatus'}) eq 'HASH') {
! 284: if (ref($values->{'defaults'}) eq 'HASH') {
! 285: $settings = {%{$values->{'inststatus'}},%{$values->{'defaults'}}};
! 286: } else {
! 287: $settings = $values->{'inststatus'};
! 288: }
! 289: } else {
! 290: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
! 291: my $inststatus = {
! 292: inststatustypes => $usertypes,
! 293: inststatusorder => $types,
! 294: inststatusguest => [],
! 295: };
! 296: if (ref($values->{defaults}) eq 'HASH') {
! 297: $settings = {%{$inststatus},%{$values->{'defaults'}}};
! 298: } else {
! 299: $settings = $inststatus;
! 300: }
! 301: }
1.15 raeburn 302: }
1.1 raeburn 303: ($output{$item},$rowtotal{$item}) =
304: &Apache::domainprefs::print_config_box($r,$dom,$confname,
1.28 raeburn 305: $phase,$item,$prefs->{$item},$settings);
1.1 raeburn 306: } else {
307: ($output{$item},$rowtotal{$item}) =
308: &Apache::courseprefs::print_config_box($r,$dom,$phase,
1.7 raeburn 309: $item,$prefs->{$item},$values,$allitems,$crstype);
1.1 raeburn 310: }
311: $rowsum += $rowtotal{$item};
312: }
313: }
1.12 raeburn 314: $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
1.1 raeburn 315: for (my $i=0; $i<@items; $i++) {
316: $r->print($output{$items[$i]});
317: }
1.12 raeburn 318: $r->print('</div>');
1.20 www 319: $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container));
1.1 raeburn 320: } else {
321: $r->print('<input type="hidden" name="phase" value="" />'.
1.12 raeburn 322: '<span class="LC_error">'.&mt('No settings chosen').
323: '</span>');
1.1 raeburn 324: }
325: $r->print('</form>');
326: }
1.25 raeburn 327: if ($container) {
328: &Apache::lonparmset::endSettingsScreen($r);
329: }
1.1 raeburn 330: $r->print(&Apache::loncommon::end_page());
331: return;
332: }
333:
334: sub display_choices {
1.20 www 335: my ($r,$phase,$context,$prefs_order,$prefs,$container) = @_;
1.1 raeburn 336: if ($phase eq '') {
337: $phase = 'pickactions';
338: }
339: my %helphash;
1.20 www 340: &print_header($r,$phase,$context,undef,$container);
1.1 raeburn 341: $r->print('<script type="text/javascript">'."\n".
1.6 raeburn 342: '// <![CDATA['."\n".
1.1 raeburn 343: &Apache::loncommon::check_uncheck_jscript()."\n".
1.6 raeburn 344: '// ]]>'."\n".
1.12 raeburn 345: '</script>'."\n");
346: $r->print('<h3>'.&mt('Settings to display/modify').'</h3>'.
1.13 raeburn 347: '<div><input type="button" value="'.&mt('check all').'" '.
1.1 raeburn 348: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
349: ' />'.(' 'x2).
350: '<input type="button" value="'.&mt('uncheck all').'" '.
1.12 raeburn 351: 'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
352: "\n".
1.13 raeburn 353: '</div><div class="LC_left_float">');
1.12 raeburn 354: my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
1.1 raeburn 355: if (ref($prefs_order) eq 'ARRAY') {
356: $numitems = @{$prefs_order};
357: }
1.12 raeburn 358: my $numcols = 3;
359: $maxincol = int($numitems/$numcols);
360: if ($numitems%$numcols) {
361: $maxincol ++;
1.1 raeburn 362: }
1.14 raeburn 363: $firstthird = $maxincol;
364: $secondthird = $firstthird + $maxincol;
1.1 raeburn 365: $count = 0;
366: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
367: foreach my $item (@{$prefs_order}) {
368: $r->print('<h4>'.
369: &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
370: '<label><input type="checkbox" name="actions" value="'.$item.
371: '" /> '.&mt($prefs->{$item}->{'text'}).'</label></h4>');
372: $count ++;
1.12 raeburn 373: if ((!$seconddiv) && ($count >= $firstthird)) {
1.1 raeburn 374: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
375: $seconddiv = 1;
376: }
1.12 raeburn 377: if ((!$thirddiv) && ($count >= $secondthird)) {
378: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
379: $thirddiv = 1;
1.13 raeburn 380: }
1.1 raeburn 381: }
1.12 raeburn 382: $r->print('</div><br clear="all" />');
1.1 raeburn 383: }
1.20 www 384: $r->print(&print_footer($r,$phase,'display','Display',undef,$container));
1.1 raeburn 385: $r->print('</form>');
1.25 raeburn 386: if ($container) {
387: &Apache::lonparmset::endSettingsScreen($r);
388: }
1.1 raeburn 389: $r->print(&Apache::loncommon::end_page());
390: return;
391: }
392:
393: sub color_pick_js {
394: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
395: my $output = <<"ENDCOL";
396:
397: $pjump_def
398:
399: function psub() {
1.21 www 400: modalWindow.close();
1.1 raeburn 401: if (document.parmform.pres_marker.value!='') {
402: if (document.parmform.pres_type.value!='') {
403: eval('document.display.'+
404: document.parmform.pres_marker.value+
405: '.value=document.parmform.pres_value.value;');
406: }
407: } else {
408: document.parmform.pres_value.value='';
409: document.parmform.pres_marker.value='';
410: }
411: }
412:
413: function get_id (span_id) {
414: if (document.getElementById) {
415: return document.getElementById(span_id);
416: }
417: if (document.all) {
418: return document.all[span_id];
419: }
420: return false;
421: }
422:
423: function colchg_span (span_id_str,new_color_item) {
424: var span_ref = get_id(span_id_str);
425: if (span_ref.style) { span_ref = span_ref.style; }
426: span_ref.background = new_color_item.value;
427: span_ref.backgroundColor = new_color_item.value;
428: span_ref.bgColor = new_color_item.value;
429: }
430:
431: ENDCOL
432: return $output;
433: }
434:
435: sub get_crumb_text {
436: my %brcrumbtext = (
437: domain => 'Domain Settings',
1.4 raeburn 438: course => 'Display/Edit Settings',
1.1 raeburn 439: );
440: return %brcrumbtext;
441: }
442:
443: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>