1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
4: # $Id: lonconfigsettings.pm,v 1.59 2022/02/15 04:28:01 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,$instcode,$dom,$confname,$values) = @_;
44: my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check,
45: $linkprot_check,$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: if (($context eq 'course') && ($phase eq 'display') &&
120: (grep(/^linkprotection$/,@actions))) {
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);
129: if (ref($values->{'linkprotection'}) eq 'HASH') {
130: if (keys(%{$values->{'linkprotection'}})) {
131: my @current = sort { $a <=> $b } keys(%{$values->{'linkprotection'}});
132: if (@current) {
133: for (my $i=0; $i<@current; $i++) {
134: my $num = $current[$i];
135: if (ref($values->{'linkprotection'}->{$num}) eq 'HASH') {
136: if ($values->{'linkprotection'}->{$num}->{'usable'}) {
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) {
175: foreach my $num (@changeable) {
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: }
198: }
199: }
200: my $alert = &mt('You must select at least one functionality type to display.');
201: &js_escape(\$alert);
202: my $js = '
203: <script type="text/javascript">
204: // <![CDATA[
205:
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: }
228: '.$instcode_check.$call_category_check.$linkprot_check.'
229: formname.submit();
230: }'."\n";
231: if ($phase eq 'pickactions') {
232: $js .= &Apache::lonhtmlcommon::color_picker();
233: $js .=
234: &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
235: } elsif ($phase eq 'display') {
236: $js .= &Apache::lonhtmlcommon::color_picker();
237: $js .= &color_pick_js()."\n";
238: }
239: $js .= &Apache::loncommon::viewport_size_js().'
240:
241: // ]]>
242: </script>
243: ';
244: if ($jscript) {
245: $js .= "
246:
247: $jscript
248:
249: ";
250: }
251: my $additem;
252: if ($phase eq 'pickactions') {
253: my %loaditems = (
254: 'onload' => "setFormElements(document.pickactions);",
255: );
256: $additem = {'add_entries' => \%loaditems,};
257: } elsif ($phase eq 'display') {
258: if ($context eq 'domain') {
259: my $onload;
260: if (grep(/^coursedefaults$/,@actions)) {
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';
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');";
286: }
287: } else {
288: $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
289: "'cancreate_emaildomain','default');";
290: }
291: }
292: if (grep(/^contacts$/,@actions)) {
293: my $customclass = 'LC_helpdesk_override';
294: my $optionsprefix = 'LC_options_helpdesk_';
295: $onload .= "toggleHelpdeskRow(document.display,'overrides','$customclass','$optionsprefix');";
296: }
297: if (grep(/^lti$/,@actions)) {
298: $onload .= "toggleLTI(document.display,'user','add');".
299: "toggleLTI(document.display,'crs','add');".
300: "toggleLTI(document.display,'sec','add');".
301: "toggleLTI(document.display,'lcauth','add');".
302: "toggleLTI(document.display,'lcmenu','add');".
303: "toggleLTI(document.display,'passback','add');".
304: "toggleLTI(document.display,'callback','add');";
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');".
311: "toggleLTI(document.display,'sec','$i');".
312: "toggleLTI(document.display,'lcauth','$i');".
313: "toggleLTI(document.display,'lcmenu','$i');".
314: "toggleLTI(document.display,'passback','$i');".
315: "toggleLTI(document.display,'callback','$i');";
316: }
317: }
318: }
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);";
324: }
325: if (grep(/^ltitools$/,@actions)) {
326: $onload .= "toggleLTITools(document.display,'passback','add');".
327: "toggleLTITools(document.display,'roster','add');".
328: "toggleLTITools(document.display,'user','add');";
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');".
334: "toggleLTITools(document.display,'roster','$i');".
335: "toggleLTITools(document.display,'user','$i');";
336: }
337: }
338: }
339: }
340: if (grep(/^wafproxy$/,@actions)) {
341: $onload .= "toggleWAF();checkWAF();updateWAF();";
342: }
343: if (grep(/^proctoring$/,@actions)) {
344: $onload .= "toggleProctoring(document.display,'proctorio');".
345: "toggleProctoring(document.display,'examity');";
346: }
347: if (grep(/^scantron$/,@actions)) {
348: $onload .= "toggleScantron(document.display);";
349: }
350: if (grep(/^autoupdate$/,@actions)) {
351: $onload .= "toggleLastActiveDays(document.display);";
352: }
353: if (grep(/^autoenroll$/,@actions)) {
354: $onload .= "toggleFailsafe(document.display);";
355: }
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: }
362: if ($onload) {
363: my %loaditems = (
364: 'onload' => $onload,
365: );
366: $additem = {'add_entries' => \%loaditems,};
367: }
368: } elsif ($context eq 'course') {
369: my $onload;
370: if (grep(/^courseinfo$/,@actions)) {
371: if (@code_order) {
372: $onload = "courseSet('','load');toggleCloners(document.display.cloners_instcode);";
373: }
374: }
375: if (grep(/^linkprotection$/,@actions)) {
376: if (ref($values) eq 'HASH') {
377: if (ref($values->{'linkprotection'}) eq 'HASH') {
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: }
385: my $posslti = scalar(keys(%{$values->{'linkprotection'}}));
386: for (my $i=0; $i<=$posslti; $i++) {
387: my $num = $i;
388: if ($i == $posslti) {
389: $num = 'add';
390: }
391: if (ref($values->{'linkprotection'}->{$i}) eq 'HASH') {
392: if ($values->{'linkprotection'}->{$i}->{'usable'}) {
393: $onload .= "toggleLinkProt(document.display,'$num','secret');";
394: }
395: }
396: if ($ltiauth) {
397: $onload .= "toggleLinkProtReqUser(document.display,'requser','optional','1','block','$num');".
398: "toggleLinkProtReqUser(document.display,'mapuser','userfield','other','inline-block','$num');";
399: }
400: }
401: }
402: }
403: }
404: if ($onload) {
405: my %loaditems = (
406: 'onload' => $onload,
407: );
408: $additem = {'add_entries' => \%loaditems,};
409: }
410: }
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: ');
421: if ($container) {
422: &Apache::lonparmset::startSettingsScreen($r,$container,$crstype);
423: }
424: $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
425: ' enctype="multipart/form-data">');
426: return;
427: }
428:
429: sub print_footer {
430: my ($r,$phase,$newphase,$button_text,$actions,$container,$parm_permission) = @_;
431: $button_text = &mt($button_text);
432: $r->print('<input type="hidden" name="phase" value="" />');
433: if (defined($env{'form.origin'})) {
434: $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
435: }
436: if (($phase eq 'display') || ($phase eq 'process')) {
437: if (ref($actions) eq 'ARRAY') {
438: foreach my $item (@{$actions}) {
439: $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
440: }
441: }
442: }
443: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
444: if ($phase eq 'process') {
445: $r->print(
446: &Apache::lonhtmlcommon::actionbox(
447: ['<a href='.$dest.'>'.$button_text.'</a>']));
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: }
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: }
465: }
466: if ($phase eq 'process') {
467: $r->print('</form>');
468: if ($container) {
469: &Apache::lonparmset::endSettingsScreen($r);
470: }
471: $r->print(&Apache::loncommon::end_page());
472: }
473: return;
474: }
475:
476: sub make_changes {
477: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,
478: $allitems,$container,$parm_permission) = @_;
479: my %brcrumtext = &get_crumb_text();
480: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
481: my ($numchanged,%changes,%disallowed);
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"});
487: &print_header($r,$phase,$context,undef,$container);
488: my ($crstype,%lastact,$errors);
489: if ($context eq 'course') {
490: $crstype = &Apache::loncommon::course_type();
491: }
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') {
497: $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
498: &Apache::domainprefs::process_changes($r,$dom,
499: $confname,$item,$roles,$values,\%lastact));
500: } else {
501: $changes{$item} = {};
502: $errors =
503: &Apache::courseprefs::process_changes($dom,$confname,$item,$values,
504: $prefs->{$item},$changes{$item},
505: $allitems,\%disallowed,$crstype);
506: if (keys(%{$changes{$item}}) > 0) {
507: $numchanged ++;
508: }
509: }
510: }
511: }
512: }
513: if ($context eq 'course') {
514: if ($numchanged) {
515: my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
516: $prefs,$values,\%changes,$crstype);
517: $r->print(&Apache::loncommon::confirmwrapper($message));
518: } else {
519: if ($crstype eq 'Community') {
520: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
521: } else {
522: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
523: }
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},
531: $prefs,$crstype));
532: }
533: }
534: }
535: $r->print('</p>');
536: }
537: if ($errors) {
538: $r->print('<p>'.$errors.'</p>');
539: }
540: }
541: $r->print('<p>');
542: my $footer_text = 'Back to configuration display';
543: if ($context eq 'course') {
544: $footer_text = 'Back to display/edit settings';
545: }
546: &print_footer($r,$phase,'display',$footer_text,\@actions,$container,$parm_permission);
547: $r->print('</p>');
548: return \%lastact;
549: }
550:
551: sub display_settings {
552: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
553: $allitems,$crstype,$container,$parm_permission) = @_;
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')",
558: text=>"Display/Edit Settings"});
559: my $instcode;
560: if (ref($values) eq 'HASH') {
561: $instcode = $values->{'internal.coursecode'};
562: }
563: &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values);
564: my $divwidth = 900;
565: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) {
566: if (@actions > 0) {
567: my $rowsum = 0;
568: my (%output,%rowtotal,@items,$got_check_uncheck);
569: foreach my $item (@{$prefs_order}) {
570: if (grep(/^\Q$item\E$/,@actions)) {
571: push(@items,$item);
572: if ($context eq 'domain') {
573: my $settings;
574: if (ref($values) eq 'HASH') {
575: $settings = $values->{$item};
576: }
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: }
586: } elsif ($item eq 'selfcreation') {
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: }
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') {
618: $settings = $values->{'lti'};
619: }
620: }
621: ($output{$item},$rowtotal{$item}) =
622: &Apache::domainprefs::print_config_box($r,$dom,$confname,
623: $phase,$item,$prefs->{$item},$settings);
624: } else {
625: ($output{$item},$rowtotal{$item}) =
626: &Apache::courseprefs::print_config_box($r,$dom,$confname,$phase,
627: $item,$prefs->{$item},$values,$allitems,$crstype,$parm_permission);
628: }
629: $rowsum += $rowtotal{$item};
630: }
631: }
632: $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
633: for (my $i=0; $i<@items; $i++) {
634: $r->print($output{$items[$i]});
635: }
636: $r->print('</div>');
637: $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container,$parm_permission));
638: } else {
639: $r->print('<input type="hidden" name="phase" value="" />'.
640: '<span class="LC_error">'.&mt('No settings chosen').
641: '</span>');
642: }
643: $r->print('</form>');
644: }
645: if ($container) {
646: &Apache::lonparmset::endSettingsScreen($r);
647: }
648: $r->print(&Apache::loncommon::end_page());
649: return;
650: }
651:
652: sub display_choices {
653: my ($r,$phase,$context,$prefs_order,$prefs,$container,$parm_permission) = @_;
654: if ($phase eq '') {
655: $phase = 'pickactions';
656: }
657: my %helphash;
658: &print_header($r,$phase,$context,undef,$container);
659: $r->print('<script type="text/javascript">'."\n".
660: '// <![CDATA['."\n".
661: &Apache::loncommon::check_uncheck_jscript()."\n".
662: '// ]]>'."\n".
663: '</script>'."\n");
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>'.
671: '<div><input type="button" value="'.&mt('check all').'" '.
672: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
673: ' />'.(' 'x2).
674: '<input type="button" value="'.&mt('uncheck all').'" '.
675: 'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
676: "\n".
677: '</div><div class="LC_left_float">');
678: my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
679: if (ref($prefs_order) eq 'ARRAY') {
680: $numitems = @{$prefs_order};
681: }
682: my $numcols = 3;
683: $maxincol = int($numitems/$numcols);
684: if ($numitems%$numcols) {
685: $maxincol ++;
686: }
687: $firstthird = $maxincol;
688: $secondthird = $firstthird + $maxincol;
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 ++;
697: if ((!$seconddiv) && ($count >= $firstthird)) {
698: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
699: $seconddiv = 1;
700: }
701: if ((!$thirddiv) && ($count >= $secondthird)) {
702: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
703: $thirddiv = 1;
704: }
705: }
706: }
707: $r->print('</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
708: $r->print(&print_footer($r,$phase,'display','Display',undef,$container,$parm_permission));
709: $r->print('</form>');
710: if ($container) {
711: &Apache::lonparmset::endSettingsScreen($r);
712: }
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() {
724: modalWindow.close();
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',
762: course => 'Display/Edit Settings',
763: );
764: return %brcrumbtext;
765: }
766:
767: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>