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