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