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