Annotation of loncom/interface/lonconfigsettings.pm, revision 1.67
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.67 ! raeburn 4: # $Id: lonconfigsettings.pm,v 1.66 2022/08/28 02:41: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.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.59 raeburn 43: my ($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values) = @_;
1.30 raeburn 44: my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check,
1.59 raeburn 45: $linkprot_check,$crstype,@actions,@code_order);
1.30 raeburn 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.');
1.31 damieng 78: &js_escape(\$noinstcodestr);
1.30 raeburn 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: }
1.59 raeburn 119: if (($context eq 'course') && ($phase eq 'display') &&
1.60 raeburn 120: (grep(/^linkprot$/,@actions))) {
1.59 raeburn 121: my $allowed;
122: my $home = &Apache::lonnet::homeserver($confname,$dom);
123: unless ($home eq 'no_host') {
124: my @ids=&Apache::lonnet::current_machine_ids();
125: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
126: }
127: if ($allowed) {
128: my (@changeable,@settable);
1.60 raeburn 129: if (ref($values->{'linkprot'}) eq 'HASH') {
130: if (keys(%{$values->{'linkprot'}})) {
131: my @current = sort { $a <=> $b } keys(%{$values->{'linkprot'}});
1.59 raeburn 132: if (@current) {
133: for (my $i=0; $i<@current; $i++) {
134: my $num = $current[$i];
1.60 raeburn 135: if (ref($values->{'linkprot'}->{$num}) eq 'HASH') {
136: if ($values->{'linkprot'}->{$num}->{'usable'}) {
1.59 raeburn 137: push(@changeable,$i);
138: } else {
139: push(@settable,$i);
140: }
141: }
142: }
143: }
144: }
145: }
146: my ($numrules,$intargjs);
147: $linkprot_check .= <<ENDJS;
148:
149: var linkprotradio = '';
150: var secretinput = '';
1.62 raeburn 151: var posscheck = '';
152:
1.59 raeburn 153: ENDJS
154: if (@changeable) {
155: foreach my $num (@changeable) {
156: ($numrules,$intargjs) =
157: &Apache::loncommon::passwd_validation_js('secretinput',$dom,'linkprot',$num);
1.62 raeburn 158: $linkprot_check .= <<ENDJS;
159: posscheck = '';
1.59 raeburn 160: linkprotradio = document.display.elements['linkprot_changesecret_$num'];
161: if (linkprotradio.length) {
162: for (var i=0; i<linkprotradio.length; i++) {
163: if (linkprotradio[i].checked) {
164: if (linkprotradio[i].value == 1) {
1.62 raeburn 165: posscheck = 1;
1.59 raeburn 166: }
167: }
168: }
169: }
1.62 raeburn 170:
171: ENDJS
172: if ($numrules) {
173: $linkprot_check .= <<ENDJS;
174: if (posscheck) {
175: secretinput = document.display.elements['linkprot_secret_$num'].value;
176: $intargjs
177: }
178:
1.59 raeburn 179: ENDJS
180: }
1.62 raeburn 181: $linkprot_check .= <<ENDJS;
182: if (posscheck) {
1.63 raeburn 183: uncheckLinkProtMakeVis('visible','$num');
1.62 raeburn 184: document.display.elements['linkprot_secret_$num'].type = 'password';
185: }
186:
187: ENDJS
1.59 raeburn 188: }
189: }
190: if (@settable) {
1.61 raeburn 191: foreach my $num (@settable) {
1.59 raeburn 192: ($numrules,$intargjs) =
193: &Apache::loncommon::passwd_validation_js('secretinput',$dom,'linkprot',$num);
194: if ($numrules) {
195: $linkprot_check .= <<ENDJS;
196: secretinput = document.display.elements['linkprot_secret_$num'].value;
197: $intargjs
1.62 raeburn 198:
1.59 raeburn 199: ENDJS
200: }
1.62 raeburn 201: $linkprot_check .= <<ENDJS;
1.63 raeburn 202: uncheckLinkProtMakeVis('visible','$num');
1.62 raeburn 203: document.display.elements['linkprot_secret_$num'].type = 'password';
204:
205: ENDJS
1.59 raeburn 206: }
207: }
208: ($numrules,$intargjs) =
209: &Apache::loncommon::passwd_validation_js('secretinput',$dom,'linkprot','add');
210: if ($numrules) {
211: $linkprot_check .= <<ENDJS
212: secretinput = document.display.elements['linkprot_secret_add'].value;
213: if (document.display.elements['linkprot_add'].checked) {
1.63 raeburn 214: $intargjs
1.59 raeburn 215: }
1.62 raeburn 216:
1.59 raeburn 217: ENDJS
218: }
1.62 raeburn 219: $linkprot_check .= <<ENDJS;
1.63 raeburn 220: uncheckLinkProtMakeVis('visible','add');
1.62 raeburn 221: document.display.elements['linkprot_secret_add'].type = 'password';
222:
223: ENDJS
1.59 raeburn 224: }
225: }
1.30 raeburn 226: }
1.1 raeburn 227: }
228: my $alert = &mt('You must select at least one functionality type to display.');
1.31 damieng 229: &js_escape(\$alert);
1.1 raeburn 230: my $js = '
231: <script type="text/javascript">
1.6 raeburn 232: // <![CDATA[
233:
1.1 raeburn 234: function changePage(formname,newphase) {
235: formname.phase.value = newphase;
236: numchecked = 0;
237: if (formname == document.pickactions) {
238: if (formname.actions.length > 0) {
239: for (var i = 0; i<formname.actions.length; i++) {
240: if (formname.actions[i].checked) {
241: numchecked ++;
242: }
243: }
244: } else {
245: if (formname.actions.checked) {
246: numchecked ++;
247: }
248: }
249: if (numchecked > 0) {
250: formname.submit();
251: } else {
252: alert("'.$alert.'");
253: return;
254: }
255: }
1.59 raeburn 256: '.$instcode_check.$call_category_check.$linkprot_check.'
1.1 raeburn 257: formname.submit();
258: }'."\n";
259: if ($phase eq 'pickactions') {
1.22 foxr 260: $js .= &Apache::lonhtmlcommon::color_picker();
1.1 raeburn 261: $js .=
1.12 raeburn 262: &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
1.1 raeburn 263: } elsif ($phase eq 'display') {
1.22 foxr 264: $js .= &Apache::lonhtmlcommon::color_picker();
1.1 raeburn 265: $js .= &color_pick_js()."\n";
266: }
267: $js .= &Apache::loncommon::viewport_size_js().'
1.6 raeburn 268:
269: // ]]>
1.1 raeburn 270: </script>
271: ';
1.2 raeburn 272: if ($jscript) {
273: $js .= "
274:
275: $jscript
276:
277: ";
278: }
1.1 raeburn 279: my $additem;
280: if ($phase eq 'pickactions') {
281: my %loaditems = (
1.12 raeburn 282: 'onload' => "setFormElements(document.pickactions);",
1.1 raeburn 283: );
284: $additem = {'add_entries' => \%loaditems,};
1.30 raeburn 285: } elsif ($phase eq 'display') {
286: if ($context eq 'domain') {
1.34 raeburn 287: my $onload;
1.30 raeburn 288: if (grep(/^coursedefaults$/,@actions)) {
1.34 raeburn 289: $onload = "toggleDisplay(document.display,'cloneinstcode');".
290: "toggleDisplay(document.display,'credits');".
291: "toggleDisplay(document.display,'studentsubmission');";
292: }
293: if (grep(/^selfcreation$/,@actions)) {
294: my $prefix = 'cancreate_emailverified';
1.36 raeburn 295: my $customclass = 'LC_selfcreate_email';
296: my $classprefix = 'LC_canmodify_emailusername_';
297: my $optionsprefix = 'LC_options_emailusername_';
298: $onload .= "toggleRows(document.display,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
299: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
300: my $hascustom;
301: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
302: if (ref($emailrules) eq 'HASH') {
303: if (keys(%{$emailrules}) > 0) {
304: $hascustom = 'cancreate_emailrule';
305: }
306: }
307: my @posstypes;
308: if (ref($types) eq 'ARRAY') {
309: @posstypes = @{$types};
310: push(@posstypes,'default');
311: foreach my $type (@posstypes) {
312: $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
313: "'cancreate_emaildomain','$type');";
1.34 raeburn 314: }
1.36 raeburn 315: } else {
316: $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
317: "'cancreate_emaildomain','default');";
1.34 raeburn 318: }
1.37 raeburn 319: }
320: if (grep(/^contacts$/,@actions)) {
321: my $customclass = 'LC_helpdesk_override';
322: my $optionsprefix = 'LC_options_helpdesk_';
1.38 raeburn 323: $onload .= "toggleHelpdeskRow(document.display,'overrides','$customclass','$optionsprefix');";
1.34 raeburn 324: }
1.40 raeburn 325: if (grep(/^lti$/,@actions)) {
326: $onload .= "toggleLTI(document.display,'user','add');".
327: "toggleLTI(document.display,'crs','add');".
1.42 raeburn 328: "toggleLTI(document.display,'sec','add');".
1.43 raeburn 329: "toggleLTI(document.display,'lcauth','add');".
1.44 raeburn 330: "toggleLTI(document.display,'lcmenu','add');".
1.46 raeburn 331: "toggleLTI(document.display,'passback','add');".
332: "toggleLTI(document.display,'callback','add');";
1.40 raeburn 333: if (ref($values) eq 'HASH') {
334: if (ref($values->{'lti'}) eq 'HASH') {
335: my $numlti = scalar(keys(%{$values->{'lti'}}));
336: for (my $i=0; $i<$numlti; $i++) {
337: $onload .= "toggleLTI(document.display,'user','$i');".
338: "toggleLTI(document.display,'crs','$i');".
1.42 raeburn 339: "toggleLTI(document.display,'sec','$i');".
1.43 raeburn 340: "toggleLTI(document.display,'lcauth','$i');".
1.44 raeburn 341: "toggleLTI(document.display,'lcmenu','$i');".
1.46 raeburn 342: "toggleLTI(document.display,'passback','$i');".
343: "toggleLTI(document.display,'callback','$i');";
1.40 raeburn 344: }
345: }
1.41 raeburn 346: }
1.58 raeburn 347: my %servers = &Apache::lonnet::get_servers($dom,'library');
348: foreach my $server (keys(%servers)) {
349: $onload .= "togglePrivKey(document.display,'$server');";
350: }
351: $onload .= "toggleLTIEncKey(document.display);";
1.40 raeburn 352: }
1.39 raeburn 353: if (grep(/^ltitools$/,@actions)) {
354: $onload .= "toggleLTITools(document.display,'passback','add');".
1.41 raeburn 355: "toggleLTITools(document.display,'roster','add');".
356: "toggleLTITools(document.display,'user','add');";
1.39 raeburn 357: if (ref($values) eq 'HASH') {
358: if (ref($values->{'ltitools'}) eq 'HASH') {
359: my $numltitools = scalar(keys(%{$values->{'ltitools'}}));
360: for (my $i=0; $i<$numltitools; $i++) {
361: $onload .= "toggleLTITools(document.display,'passback','$i');".
1.41 raeburn 362: "toggleLTITools(document.display,'roster','$i');".
363: "toggleLTITools(document.display,'user','$i');";
1.39 raeburn 364: }
365: }
366: }
367: }
1.48 raeburn 368: if (grep(/^wafproxy$/,@actions)) {
369: $onload .= "toggleWAF();checkWAF();updateWAF();";
370: }
1.47 raeburn 371: if (grep(/^proctoring$/,@actions)) {
372: $onload .= "toggleProctoring(document.display,'proctorio');".
373: "toggleProctoring(document.display,'examity');";
374: }
1.45 raeburn 375: if (grep(/^scantron$/,@actions)) {
1.54 raeburn 376: $onload .= "toggleScantron(document.display);";
1.45 raeburn 377: }
1.52 raeburn 378: if (grep(/^autoupdate$/,@actions)) {
1.54 raeburn 379: $onload .= "toggleLastActiveDays(document.display);";
1.52 raeburn 380: }
1.55 raeburn 381: if (grep(/^autoenroll$/,@actions)) {
382: $onload .= "toggleFailsafe(document.display);";
383: }
1.53 raeburn 384: if (grep(/^login$/,@actions)) {
385: my %domservers = &Apache::lonnet::get_servers($dom);
386: foreach my $server (sort(keys(%domservers))) {
387: $onload .= "toggleSamlOptions(document.display,'$server');";
388: }
389: }
1.34 raeburn 390: if ($onload) {
1.30 raeburn 391: my %loaditems = (
1.35 raeburn 392: 'onload' => $onload,
1.30 raeburn 393: );
394: $additem = {'add_entries' => \%loaditems,};
395: }
396: } elsif ($context eq 'course') {
1.56 raeburn 397: my $onload;
1.30 raeburn 398: if (grep(/^courseinfo$/,@actions)) {
1.56 raeburn 399: if (@code_order) {
400: $onload = "courseSet('','load');toggleCloners(document.display.cloners_instcode);";
401: }
402: }
1.60 raeburn 403: if (grep(/^linkprot$/,@actions)) {
1.56 raeburn 404: if (ref($values) eq 'HASH') {
1.60 raeburn 405: if (ref($values->{'linkprot'}) eq 'HASH') {
1.57 raeburn 406: my $ltiauth;
407: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
408: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
409: } else {
410: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
411: $ltiauth = $domdefs{'crsltiauth'};
412: }
1.62 raeburn 413: my $ishome;
414: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
415: unless (($chome eq 'no_host') || ($chome eq '')) {
416: my @ids=&Apache::lonnet::current_machine_ids();
417: foreach my $id (@ids) { if ($id eq $chome) { $ishome=1; } }
418: }
1.60 raeburn 419: my $posslti = scalar(keys(%{$values->{'linkprot'}}));
1.57 raeburn 420: for (my $i=0; $i<=$posslti; $i++) {
421: my $num = $i;
422: if ($i == $posslti) {
423: $num = 'add';
424: }
1.60 raeburn 425: if (ref($values->{'linkprot'}->{$i}) eq 'HASH') {
426: if ($values->{'linkprot'}->{$i}->{'usable'}) {
1.59 raeburn 427: $onload .= "toggleLinkProt(document.display,'$num','secret');";
1.57 raeburn 428: }
1.58 raeburn 429: }
1.65 raeburn 430: $onload .= "toggleLinkProtExtra(document.display,'returnurl','divurlparam','1','inline-block','$num');";
1.57 raeburn 431: if ($ltiauth) {
1.65 raeburn 432: $onload .= "toggleLinkProtExtra(document.display,'requser','optional','1','block','$num');".
433: "toggleLinkProtExtra(document.display,'mapuser','userfield','other','inline-block','$num');";
1.56 raeburn 434: }
1.62 raeburn 435: if ($ishome) {
436: $onload .= "uncheckLinkProtMakeVis('visible','$num');";
437: }
1.56 raeburn 438: }
439: }
1.30 raeburn 440: }
441: }
1.66 raeburn 442: if (grep(/^appearance$/,@actions)) {
1.67 ! raeburn 443: $onload .= "toggleExtRes();";
! 444: }
! 445: if (grep(/^localization$/,@actions)) {
! 446: $onload .= "toggleTimeZone();";
1.66 raeburn 447: }
1.56 raeburn 448: if ($onload) {
449: my %loaditems = (
450: 'onload' => $onload,
451: );
452: $additem = {'add_entries' => \%loaditems,};
453: }
1.30 raeburn 454: }
1.1 raeburn 455: }
456: $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
457: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
458: $r->print('
459: <form name="parmform" action="">
460: <input type="hidden" name="pres_marker" />
461: <input type="hidden" name="pres_type" />
462: <input type="hidden" name="pres_value" />
463: </form>
464: ');
1.20 www 465: if ($container) {
1.24 raeburn 466: &Apache::lonparmset::startSettingsScreen($r,$container,$crstype);
1.20 www 467: }
1.1 raeburn 468: $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
469: ' enctype="multipart/form-data">');
470: return;
471: }
472:
473: sub print_footer {
1.33 raeburn 474: my ($r,$phase,$newphase,$button_text,$actions,$container,$parm_permission) = @_;
1.1 raeburn 475: $button_text = &mt($button_text);
1.12 raeburn 476: $r->print('<input type="hidden" name="phase" value="" />');
1.5 raeburn 477: if (defined($env{'form.origin'})) {
478: $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
479: }
1.1 raeburn 480: if (($phase eq 'display') || ($phase eq 'process')) {
481: if (ref($actions) eq 'ARRAY') {
482: foreach my $item (@{$actions}) {
1.16 raeburn 483: $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
1.1 raeburn 484: }
485: }
486: }
487: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
488: if ($phase eq 'process') {
1.23 bisitz 489: $r->print(
490: &Apache::lonhtmlcommon::actionbox(
491: ['<a href='.$dest.'>'.$button_text.'</a>']));
1.1 raeburn 492: } else {
493: my $onclick;
494: if ($phase eq 'display') {
495: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
496: } else {
497: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
498: }
1.33 raeburn 499: my $showbutton = 1;
500: if (ref($parm_permission) eq 'HASH') {
501: unless (($parm_permission->{'process'}) || ($newphase eq 'display')) {
502: $showbutton = 0;
503: }
504: }
505: if ($showbutton) {
506: $r->print('<p><input type="button" name="store" value="'.
507: $button_text.'" onclick='.$onclick.' /></p>');
508: }
1.1 raeburn 509: }
510: if ($phase eq 'process') {
1.20 www 511: $r->print('</form>');
512: if ($container) {
513: &Apache::lonparmset::endSettingsScreen($r);
514: }
515: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 516: }
517: return;
518: }
519:
520: sub make_changes {
1.33 raeburn 521: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,
522: $allitems,$container,$parm_permission) = @_;
1.1 raeburn 523: my %brcrumtext = &get_crumb_text();
524: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.4 raeburn 525: my ($numchanged,%changes,%disallowed);
1.1 raeburn 526: &Apache::lonhtmlcommon::add_breadcrumb
527: ({href=>"javascript:changePage(document.$phase,'display')",
528: text=>$brcrumtext{$context}},
529: {href=>"javascript:changePage(document.$phase,'$phase')",
530: text=>"Updated"});
1.20 www 531: &print_header($r,$phase,$context,undef,$container);
1.50 raeburn 532: my ($crstype,%lastact,$errors);
1.7 raeburn 533: if ($context eq 'course') {
534: $crstype = &Apache::loncommon::course_type();
535: }
1.1 raeburn 536: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') &&
537: (ref($prefs) eq 'HASH')) {
538: foreach my $item (@{$prefs_order}) {
539: if (grep(/^\Q$item\E$/,@actions)) {
540: if ($context eq 'domain') {
1.4 raeburn 541: $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
542: &Apache::domainprefs::process_changes($r,$dom,
1.27 raeburn 543: $confname,$item,$roles,$values,\%lastact));
1.1 raeburn 544: } else {
1.4 raeburn 545: $changes{$item} = {};
1.50 raeburn 546: $errors =
1.51 raeburn 547: &Apache::courseprefs::process_changes($dom,$confname,$item,$values,
1.50 raeburn 548: $prefs->{$item},$changes{$item},
1.64 raeburn 549: $allitems,\%disallowed,$crstype,
550: \%lastact);
1.4 raeburn 551: if (keys(%{$changes{$item}}) > 0) {
552: $numchanged ++;
553: }
1.1 raeburn 554: }
555: }
556: }
557: }
1.4 raeburn 558: if ($context eq 'course') {
559: if ($numchanged) {
1.11 wenzelju 560: my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
561: $prefs,$values,\%changes,$crstype);
562: $r->print(&Apache::loncommon::confirmwrapper($message));
1.4 raeburn 563: } else {
1.7 raeburn 564: if ($crstype eq 'Community') {
1.11 wenzelju 565: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
1.7 raeburn 566: } else {
1.11 wenzelju 567: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
1.7 raeburn 568: }
1.4 raeburn 569: }
570: if (keys(%disallowed) > 0) {
571: $r->print('<p>');
572: foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
573: if (ref($disallowed{$item}) eq 'HASH') {
574: if (keys(%{$disallowed{$item}}) > 0) {
575: $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
1.7 raeburn 576: $prefs,$crstype));
1.4 raeburn 577: }
578: }
579: }
580: $r->print('</p>');
581: }
1.50 raeburn 582: if ($errors) {
583: $r->print('<p>'.$errors.'</p>');
584: }
1.4 raeburn 585: }
1.1 raeburn 586: $r->print('<p>');
1.4 raeburn 587: my $footer_text = 'Back to configuration display';
588: if ($context eq 'course') {
589: $footer_text = 'Back to display/edit settings';
590: }
1.33 raeburn 591: &print_footer($r,$phase,'display',$footer_text,\@actions,$container,$parm_permission);
1.1 raeburn 592: $r->print('</p>');
1.27 raeburn 593: return \%lastact;
1.1 raeburn 594: }
595:
596: sub display_settings {
1.3 raeburn 597: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
1.33 raeburn 598: $allitems,$crstype,$container,$parm_permission) = @_;
1.1 raeburn 599: my %brcrumtext = &get_crumb_text();
600: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
601: &Apache::lonhtmlcommon::add_breadcrumb
602: ({href=>"javascript:changePage(document.$phase,'display')",
1.4 raeburn 603: text=>"Display/Edit Settings"});
1.30 raeburn 604: my $instcode;
605: if (ref($values) eq 'HASH') {
606: $instcode = $values->{'internal.coursecode'};
607: }
1.59 raeburn 608: &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values);
1.12 raeburn 609: my $divwidth = 900;
1.1 raeburn 610: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) {
611: if (@actions > 0) {
612: my $rowsum = 0;
1.32 raeburn 613: my (%output,%rowtotal,@items,$got_check_uncheck);
1.1 raeburn 614: foreach my $item (@{$prefs_order}) {
615: if (grep(/^\Q$item\E$/,@actions)) {
616: push(@items,$item);
617: if ($context eq 'domain') {
1.29 raeburn 618: my $settings;
619: if (ref($values) eq 'HASH') {
620: $settings = $values->{$item};
621: }
1.32 raeburn 622: if (($item eq 'usersessions') || ($item eq 'ssl')) {
623: unless ($got_check_uncheck) {
624: $r->print('<script type="text/javascript">'."\n".
625: '// <![CDATA['."\n".
626: &Apache::loncommon::check_uncheck_jscript()."\n".
627: '// ]]>'."\n".
628: '</script>'."\n");
629: $got_check_uncheck = 1;
630: }
1.28 raeburn 631: } elsif ($item eq 'selfcreation') {
1.29 raeburn 632: if (ref($values) eq 'HASH') {
633: $settings = $values->{'usercreation'};
634: }
635: } elsif ($item eq 'defaults') {
636: if (ref($values->{'inststatus'}) eq 'HASH') {
637: if (ref($values->{'defaults'}) eq 'HASH') {
638: $settings = {%{$values->{'inststatus'}},%{$values->{'defaults'}}};
639: } else {
640: $settings = $values->{'inststatus'};
641: }
642: } else {
643: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
644: my $inststatus = {
645: inststatustypes => $usertypes,
646: inststatusorder => $types,
647: inststatusguest => [],
648: };
649: if (ref($values->{defaults}) eq 'HASH') {
650: $settings = {%{$inststatus},%{$values->{'defaults'}}};
651: } else {
652: $settings = $inststatus;
653: }
654: }
1.58 raeburn 655: } elsif ($item eq 'lti') {
656: if (ref($values->{'ltisec'}) eq 'HASH') {
657: if (ref($values->{'lti'}) eq 'HASH') {
658: $settings = {%{$values->{'lti'}},%{$values->{'ltisec'}}};
659: } else {
660: $settings = $values->{'ltisec'};
661: }
662: } elsif (ref($values->{'lti'}) eq 'HASH') {
1.59 raeburn 663: $settings = $values->{'lti'};
1.58 raeburn 664: }
1.15 raeburn 665: }
1.1 raeburn 666: ($output{$item},$rowtotal{$item}) =
667: &Apache::domainprefs::print_config_box($r,$dom,$confname,
1.28 raeburn 668: $phase,$item,$prefs->{$item},$settings);
1.1 raeburn 669: } else {
670: ($output{$item},$rowtotal{$item}) =
1.56 raeburn 671: &Apache::courseprefs::print_config_box($r,$dom,$confname,$phase,
1.33 raeburn 672: $item,$prefs->{$item},$values,$allitems,$crstype,$parm_permission);
1.1 raeburn 673: }
674: $rowsum += $rowtotal{$item};
675: }
676: }
1.12 raeburn 677: $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
1.1 raeburn 678: for (my $i=0; $i<@items; $i++) {
679: $r->print($output{$items[$i]});
680: }
1.12 raeburn 681: $r->print('</div>');
1.33 raeburn 682: $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container,$parm_permission));
1.1 raeburn 683: } else {
684: $r->print('<input type="hidden" name="phase" value="" />'.
1.12 raeburn 685: '<span class="LC_error">'.&mt('No settings chosen').
686: '</span>');
1.1 raeburn 687: }
688: $r->print('</form>');
689: }
1.25 raeburn 690: if ($container) {
691: &Apache::lonparmset::endSettingsScreen($r);
692: }
1.1 raeburn 693: $r->print(&Apache::loncommon::end_page());
694: return;
695: }
696:
697: sub display_choices {
1.33 raeburn 698: my ($r,$phase,$context,$prefs_order,$prefs,$container,$parm_permission) = @_;
1.1 raeburn 699: if ($phase eq '') {
700: $phase = 'pickactions';
701: }
702: my %helphash;
1.20 www 703: &print_header($r,$phase,$context,undef,$container);
1.1 raeburn 704: $r->print('<script type="text/javascript">'."\n".
1.6 raeburn 705: '// <![CDATA['."\n".
1.1 raeburn 706: &Apache::loncommon::check_uncheck_jscript()."\n".
1.6 raeburn 707: '// ]]>'."\n".
1.12 raeburn 708: '</script>'."\n");
1.33 raeburn 709: my $heading = &mt('Settings to display/modify');
710: if (ref($parm_permission) eq 'HASH') {
711: unless ($parm_permission->{'process'}) {
712: $heading = &mt('Settings to display');
713: }
714: }
715: $r->print('<h3>'.$heading.'</h3>'.
1.13 raeburn 716: '<div><input type="button" value="'.&mt('check all').'" '.
1.1 raeburn 717: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
718: ' />'.(' 'x2).
719: '<input type="button" value="'.&mt('uncheck all').'" '.
1.12 raeburn 720: 'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
721: "\n".
1.13 raeburn 722: '</div><div class="LC_left_float">');
1.12 raeburn 723: my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
1.1 raeburn 724: if (ref($prefs_order) eq 'ARRAY') {
725: $numitems = @{$prefs_order};
726: }
1.12 raeburn 727: my $numcols = 3;
728: $maxincol = int($numitems/$numcols);
729: if ($numitems%$numcols) {
730: $maxincol ++;
1.1 raeburn 731: }
1.14 raeburn 732: $firstthird = $maxincol;
733: $secondthird = $firstthird + $maxincol;
1.1 raeburn 734: $count = 0;
735: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
736: foreach my $item (@{$prefs_order}) {
737: $r->print('<h4>'.
738: &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
739: '<label><input type="checkbox" name="actions" value="'.$item.
740: '" /> '.&mt($prefs->{$item}->{'text'}).'</label></h4>');
741: $count ++;
1.12 raeburn 742: if ((!$seconddiv) && ($count >= $firstthird)) {
1.1 raeburn 743: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
744: $seconddiv = 1;
745: }
1.12 raeburn 746: if ((!$thirddiv) && ($count >= $secondthird)) {
747: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
748: $thirddiv = 1;
1.13 raeburn 749: }
1.1 raeburn 750: }
751: }
1.49 raeburn 752: $r->print('</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
1.33 raeburn 753: $r->print(&print_footer($r,$phase,'display','Display',undef,$container,$parm_permission));
1.1 raeburn 754: $r->print('</form>');
1.25 raeburn 755: if ($container) {
756: &Apache::lonparmset::endSettingsScreen($r);
757: }
1.1 raeburn 758: $r->print(&Apache::loncommon::end_page());
759: return;
760: }
761:
762: sub color_pick_js {
763: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
764: my $output = <<"ENDCOL";
765:
766: $pjump_def
767:
768: function psub() {
1.21 www 769: modalWindow.close();
1.1 raeburn 770: if (document.parmform.pres_marker.value!='') {
771: if (document.parmform.pres_type.value!='') {
772: eval('document.display.'+
773: document.parmform.pres_marker.value+
774: '.value=document.parmform.pres_value.value;');
775: }
776: } else {
777: document.parmform.pres_value.value='';
778: document.parmform.pres_marker.value='';
779: }
780: }
781:
782: function get_id (span_id) {
783: if (document.getElementById) {
784: return document.getElementById(span_id);
785: }
786: if (document.all) {
787: return document.all[span_id];
788: }
789: return false;
790: }
791:
792: function colchg_span (span_id_str,new_color_item) {
793: var span_ref = get_id(span_id_str);
794: if (span_ref.style) { span_ref = span_ref.style; }
795: span_ref.background = new_color_item.value;
796: span_ref.backgroundColor = new_color_item.value;
797: span_ref.bgColor = new_color_item.value;
798: }
799:
800: ENDCOL
801: return $output;
802: }
803:
804: sub get_crumb_text {
805: my %brcrumbtext = (
806: domain => 'Domain Settings',
1.4 raeburn 807: course => 'Display/Edit Settings',
1.1 raeburn 808: );
809: return %brcrumbtext;
810: }
811:
812: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>