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