Annotation of loncom/interface/lonconfigsettings.pm, revision 1.21.4.13.2.4
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.21.4.13.2.4! (raeburn 4:: # $Id: lonconfigsettings.pm,v 1.21.4.13.2.3 2022/02/20 19:43:12 raeburn Exp $
1.1 raeburn 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
31: package Apache::lonconfigsettings;
32:
33: use strict;
34: use Apache::lonnet;
35: use Apache::loncommon();
36: use Apache::lonhtmlcommon();
37: use Apache::lonlocal;
1.21.4.7 raeburn 38: use Apache::courseclassifier();
39: use LONCAPA qw(:DEFAULT :match);
1.1 raeburn 40:
41: sub print_header {
1.21.4.13.2.3 (raeburn 42:: my ($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values) = @_;
1.21.4.7 raeburn 43: my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check,
1.21.4.13.2.3 (raeburn 44:: $linkprot_check,$crstype,@actions,@code_order);
1.21.4.7 raeburn 45: if ($phase eq 'display') {
46: @actions = &Apache::loncommon::get_env_multiple('form.actions');
47: }
1.1 raeburn 48: if ($context eq 'domain') {
1.12 raeburn 49: ($pagetitle, $brcrumtitle) = ('View/Modify Domain Settings','View/Modify Domain Settings');
1.1 raeburn 50: $action = '/adm/domainprefs';
1.8 raeburn 51: if ($phase eq 'display') {
52: if (grep(/^coursecategories$/,@actions)) {
53: $call_category_check = qq|
54: if (formname == document.display) {
55: if (!categoryCheck(formname)) {
56: return;
57: }
58: }
59: |;
60: }
61: }
1.1 raeburn 62: } else {
1.21.4.3 raeburn 63: $crstype = &Apache::loncommon::course_type();
64: if ($crstype eq 'Community') {
1.7 raeburn 65: ($pagetitle,$brcrumtitle) = ('Community Configuration','Community Configuration');
66: } else {
67: ($pagetitle,$brcrumtitle) = ('Course Configuration','Course Configuration');
68: }
1.1 raeburn 69: $action = '/adm/courseprefs';
1.21.4.7 raeburn 70: if ($phase eq 'display') {
71: if (grep(/^courseinfo$/,@actions)) {
72: my %codedefaults;
73: &Apache::lonnet::auto_instcode_defaults($env{'request.role.domain'},\%codedefaults,
74: \@code_order);
75: if (@code_order) {
76: my $noinstcodestr = &mt('You indicated cloning based on category, but did not select any categories.');
1.21.4.8 raeburn 77: &js_escape(\$noinstcodestr);
1.21.4.7 raeburn 78: $instcode_check = <<"ENDSCRIPT";
79: if (formname == document.display) {
80: if (formname.cloners_instcode.length) {
81: for (var j=0; j<formname.cloners_instcode.length; j++) {
82: if (formname.cloners_instcode[j].checked) {
83: if (formname.cloners_instcode[j].value == 1) {
84: var codes;
85: if (document.getElementsByClassName) {
86: codes = document.getElementsByClassName('LC_cloners_instcodes');
87: } else {
88: codes = getElementsByClassName(document.body,'LC_cloners_instcodes');
89: }
90: if (codes.length) {
91: var gotcode = 0;
92: for (var i=0; i<codes.length; i++) {
93: if (codes[i].selectedIndex != 0) {
94: gotcode = 1;
95: break;
96: }
97: }
98: if (!gotcode) {
99: for (var k=0; k<formname.cloners_instcode.length; k++) {
100: if (formname.cloners_instcode[k].value == 0) {
101: formname.cloners_instcode[k].checked = true;
102: }
103: }
104: toggleCloners(document.display.cloners_instcode);
105: alert('$noinstcodestr');
106: return false;
107: }
108: }
109: }
110: }
111: }
112: }
113: }
114:
115: ENDSCRIPT
116: }
117: }
1.21.4.13.2.3 (raeburn 118:: if (($context eq 'course') && ($phase eq 'display') &&
119:: (grep(/^linkprot$/,@actions))) {
120:: my $allowed;
121:: my $home = &Apache::lonnet::homeserver($confname,$dom);
122:: unless ($home eq 'no_host') {
123:: my @ids=&Apache::lonnet::current_machine_ids();
124:: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
125:: }
126:: if ($allowed) {
127:: my (@changeable,@settable);
128:: if (ref($values->{'linkprot'}) eq 'HASH') {
129:: if (keys(%{$values->{'linkprot'}})) {
130:: my @current = sort { $a <=> $b } keys(%{$values->{'linkprot'}});
131:: if (@current) {
132:: for (my $i=0; $i<@current; $i++) {
133:: my $num = $current[$i];
134:: if (ref($values->{'linkprot'}->{$num}) eq 'HASH') {
135:: if ($values->{'linkprot'}->{$num}->{'usable'}) {
136:: push(@changeable,$i);
137:: } else {
138:: push(@settable,$i);
139:: }
140:: }
141:: }
142:: }
143:: }
144:: }
145:: my ($numrules,$intargjs);
146:: $linkprot_check .= <<ENDJS;
147::
148:: var linkprotradio = '';
149:: var secretinput = '';
150:: ENDJS
151:: if (@changeable) {
152:: foreach my $num (@changeable) {
153:: ($numrules,$intargjs) =
154:: &Apache::loncommon::passwd_validation_js('secretinput',$dom,'linkprot',$num);
155:: if ($numrules) {
156:: $linkprot_check .= <<ENDJS;
157::
158:: linkprotradio = document.display.elements['linkprot_changesecret_$num'];
159:: secretinput = document.display.elements['linkprot_secret_$num'].value;
160:: if (linkprotradio.length) {
161:: for (var i=0; i<linkprotradio.length; i++) {
162:: if (linkprotradio[i].checked) {
163:: if (linkprotradio[i].value == 1) {
164:: $intargjs
165:: }
166:: }
167:: }
168:: }
169:: ENDJS
170:: }
171:: }
172:: }
173:: if (@settable) {
174:: foreach my $num (@changeable) {
175:: ($numrules,$intargjs) =
176:: &Apache::loncommon::passwd_validation_js('secretinput',$dom,'linkprot',$num);
177:: if ($numrules) {
178:: $linkprot_check .= <<ENDJS;
179:: secretinput = document.display.elements['linkprot_secret_$num'].value;
180:: $intargjs
181:: ENDJS
182:: }
183:: }
184:: }
185:: ($numrules,$intargjs) =
186:: &Apache::loncommon::passwd_validation_js('secretinput',$dom,'linkprot','add');
187:: if ($numrules) {
188:: $linkprot_check .= <<ENDJS
189:: secretinput = document.display.elements['linkprot_secret_add'].value;
190:: if (document.display.elements['linkprot_add'].checked) {
191:: $intargjs
192:: }
193:: ENDJS
194:: }
195:: }
196:: }
1.21.4.7 raeburn 197: }
1.1 raeburn 198: }
199: my $alert = &mt('You must select at least one functionality type to display.');
1.21.4.8 raeburn 200: &js_escape(\$alert);
1.1 raeburn 201: my $js = '
202: <script type="text/javascript">
1.6 raeburn 203: // <![CDATA[
204:
1.1 raeburn 205: function changePage(formname,newphase) {
206: formname.phase.value = newphase;
207: numchecked = 0;
208: if (formname == document.pickactions) {
209: if (formname.actions.length > 0) {
210: for (var i = 0; i<formname.actions.length; i++) {
211: if (formname.actions[i].checked) {
212: numchecked ++;
213: }
214: }
215: } else {
216: if (formname.actions.checked) {
217: numchecked ++;
218: }
219: }
220: if (numchecked > 0) {
221: formname.submit();
222: } else {
223: alert("'.$alert.'");
224: return;
225: }
226: }
1.21.4.13.2.3 (raeburn 227:: '.$instcode_check.$call_category_check.$linkprot_check.'
1.1 raeburn 228: formname.submit();
229: }'."\n";
230: if ($phase eq 'pickactions') {
1.21.4.2 raeburn 231: $js .= &Apache::lonhtmlcommon::color_picker();
1.1 raeburn 232: $js .=
1.12 raeburn 233: &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
1.1 raeburn 234: } elsif ($phase eq 'display') {
1.21.4.2 raeburn 235: $js .= &Apache::lonhtmlcommon::color_picker();
1.1 raeburn 236: $js .= &color_pick_js()."\n";
237: }
238: $js .= &Apache::loncommon::viewport_size_js().'
1.6 raeburn 239:
240: // ]]>
1.1 raeburn 241: </script>
242: ';
1.2 raeburn 243: if ($jscript) {
244: $js .= "
245:
246: $jscript
247:
248: ";
249: }
1.1 raeburn 250: my $additem;
251: if ($phase eq 'pickactions') {
252: my %loaditems = (
1.12 raeburn 253: 'onload' => "setFormElements(document.pickactions);",
1.1 raeburn 254: );
255: $additem = {'add_entries' => \%loaditems,};
1.21.4.7 raeburn 256: } elsif ($phase eq 'display') {
257: if ($context eq 'domain') {
1.21.4.10 raeburn 258: my $onload;
1.21.4.7 raeburn 259: if (grep(/^coursedefaults$/,@actions)) {
1.21.4.10 raeburn 260: $onload = "toggleDisplay(document.display,'cloneinstcode');".
261: "toggleDisplay(document.display,'credits');".
262: "toggleDisplay(document.display,'studentsubmission');";
263: }
264: if (grep(/^selfcreation$/,@actions)) {
265: my $prefix = 'cancreate_emailverified';
266: my $customclass = 'LC_selfcreate_email';
267: my $classprefix = 'LC_canmodify_emailusername_';
268: my $optionsprefix = 'LC_options_emailusername_';
269: $onload .= "toggleRows(document.display,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
270: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
271: my $hascustom;
272: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
273: if (ref($emailrules) eq 'HASH') {
274: if (keys(%{$emailrules}) > 0) {
275: $hascustom = 'cancreate_emailrule';
276: }
277: }
278: my @posstypes;
279: if (ref($types) eq 'ARRAY') {
280: @posstypes = @{$types};
281: push(@posstypes,'default');
282: foreach my $type (@posstypes) {
283: $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
284: "'cancreate_emaildomain','$type');";
285: }
286: } else {
287: $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
288: "'cancreate_emaildomain','default');";
289: }
290: }
1.21.4.11 raeburn 291: if (grep(/^contacts$/,@actions)) {
292: my $customclass = 'LC_helpdesk_override';
293: my $optionsprefix = 'LC_options_helpdesk_';
294: $onload .= "toggleHelpdeskRow(document.display,'overrides','$customclass','$optionsprefix');";
295: }
1.21.4.13.2.4! (raeburn 296:: if (grep(/^lti$/,@actions)) {
! 297:: my %servers = &Apache::lonnet::get_servers($dom,'library');
! 298:: foreach my $server (keys(%servers)) {
! 299:: $onload .= "togglePrivKey(document.display,'$server');";
! 300:: }
! 301:: $onload .= "toggleLTIEncKey(document.display);";
! 302:: }
1.21.4.13.2.1 (raeburn 303:: if (grep(/^ltitools$/,@actions)) {
304:: $onload .= "toggleLTITools(document.display,'user','add');";
305:: if (ref($values) eq 'HASH') {
306:: if (ref($values->{'ltitools'}) eq 'HASH') {
307:: my $numltitools = scalar(keys(%{$values->{'ltitools'}}));
308:: for (my $i=0; $i<$numltitools; $i++) {
309:: $onload .= "toggleLTITools(document.display,'user','$i');";
310:: }
311:: }
312:: }
313:: }
1.21.4.12 raeburn 314: if (grep(/^wafproxy$/,@actions)) {
315: $onload .= "toggleWAF();checkWAF();updateWAF();";
316: }
1.21.4.11 raeburn 317: if (grep(/^scantron$/,@actions)) {
1.21.4.13 raeburn 318: $onload .= "toggleScantron(document.display);";
1.21.4.11 raeburn 319: }
1.21.4.12 raeburn 320: if (grep(/^autoupdate$/,@actions)) {
1.21.4.13 raeburn 321: $onload .= "toggleLastActiveDays(document.display);";
322: }
323: if (grep(/^autoenroll$/,@actions)) {
324: $onload .= "toggleFailsafe(document.display);";
1.21.4.12 raeburn 325: }
326: if (grep(/^login$/,@actions)) {
327: my %domservers = &Apache::lonnet::get_servers($dom);
328: foreach my $server (sort(keys(%domservers))) {
329: $onload .= "toggleSamlOptions(document.display,'$server');";
330: }
331: }
1.21.4.10 raeburn 332: if ($onload) {
1.21.4.7 raeburn 333: my %loaditems = (
1.21.4.10 raeburn 334: 'onload' => $onload,
1.21.4.7 raeburn 335: );
336: $additem = {'add_entries' => \%loaditems,};
337: }
338: } elsif ($context eq 'course') {
1.21.4.13.2.2 (raeburn 339:: my $onload;
1.21.4.7 raeburn 340: if (grep(/^courseinfo$/,@actions)) {
341: if (@code_order) {
1.21.4.13.2.2 (raeburn 342:: $onload = "courseSet('','load');toggleCloners(document.display.cloners_instcode);";
343:: }
344:: }
1.21.4.13.2.3 (raeburn 345:: if (grep(/^linkprot$/,@actions)) {
1.21.4.13.2.2 (raeburn 346:: if (ref($values) eq 'HASH') {
1.21.4.13.2.3 (raeburn 347:: if (ref($values->{'linkprot'}) eq 'HASH') {
1.21.4.13.2.2 (raeburn 348:: my $ltiauth;
349:: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
350:: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
351:: } else {
352:: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
353:: $ltiauth = $domdefs{'crsltiauth'};
354:: }
1.21.4.13.2.3 (raeburn 355:: my $posslti = scalar(keys(%{$values->{'linkprot'}}));
1.21.4.13.2.2 (raeburn 356:: for (my $i=0; $i<=$posslti; $i++) {
357:: my $num = $i;
358:: if ($i == $posslti) {
359:: $num = 'add';
360:: }
1.21.4.13.2.3 (raeburn 361:: if (ref($values->{'linkprot'}->{$i}) eq 'HASH') {
362:: if ($values->{'linkprot'}->{$i}->{'usable'}) {
363:: $onload .= "toggleLinkProt(document.display,'$num','secret');";
1.21.4.13.2.2 (raeburn 364:: }
365:: }
366:: if ($ltiauth) {
1.21.4.13.2.3 (raeburn 367:: $onload .= "toggleLinkProtReqUser(document.display,'requser','optional','1','block','$num');".
368:: "toggleLinkProtReqUser(document.display,'mapuser','userfield','other','inline-block','$num');";
1.21.4.13.2.2 (raeburn 369:: }
370:: }
371:: }
1.21.4.7 raeburn 372: }
373: }
1.21.4.13.2.2 (raeburn 374:: if ($onload) {
375:: my %loaditems = (
376:: 'onload' => $onload,
377:: );
378:: $additem = {'add_entries' => \%loaditems,};
379:: }
1.21.4.7 raeburn 380: }
1.1 raeburn 381: }
382: $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
383: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
384: $r->print('
385: <form name="parmform" action="">
386: <input type="hidden" name="pres_marker" />
387: <input type="hidden" name="pres_type" />
388: <input type="hidden" name="pres_value" />
389: </form>
390: ');
391: $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
392: ' enctype="multipart/form-data">');
393: return;
394: }
395:
396: sub print_footer {
1.21.4.9 raeburn 397: my ($r,$phase,$newphase,$button_text,$actions,$container,$parm_permission) = @_;
1.1 raeburn 398: $button_text = &mt($button_text);
1.12 raeburn 399: $r->print('<input type="hidden" name="phase" value="" />');
1.5 raeburn 400: if (defined($env{'form.origin'})) {
401: $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
402: }
1.1 raeburn 403: if (($phase eq 'display') || ($phase eq 'process')) {
404: if (ref($actions) eq 'ARRAY') {
405: foreach my $item (@{$actions}) {
1.16 raeburn 406: $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
1.1 raeburn 407: }
408: }
409: }
410: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
411: if ($phase eq 'process') {
1.21.4.2 raeburn 412: $r->print(
413: &Apache::lonhtmlcommon::actionbox(
414: ['<a href='.$dest.'>'.$button_text.'</a>']));
1.1 raeburn 415: } else {
416: my $onclick;
417: if ($phase eq 'display') {
418: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
419: } else {
420: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
421: }
1.21.4.9 raeburn 422: my $showbutton = 1;
423: if (ref($parm_permission) eq 'HASH') {
424: unless (($parm_permission->{'process'}) || ($newphase eq 'display')) {
425: $showbutton = 0;
426: }
427: }
428: if ($showbutton) {
429: $r->print('<p><input type="button" name="store" value="'.
430: $button_text.'" onclick='.$onclick.' /></p>');
431: }
1.1 raeburn 432: }
433: if ($phase eq 'process') {
1.20 www 434: $r->print('</form>');
435: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 436: }
437: return;
438: }
439:
440: sub make_changes {
1.21.4.9 raeburn 441: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,
442: $allitems,$container,$parm_permission) = @_;
1.1 raeburn 443: my %brcrumtext = &get_crumb_text();
444: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.4 raeburn 445: my ($numchanged,%changes,%disallowed);
1.1 raeburn 446: &Apache::lonhtmlcommon::add_breadcrumb
447: ({href=>"javascript:changePage(document.$phase,'display')",
448: text=>$brcrumtext{$context}},
449: {href=>"javascript:changePage(document.$phase,'$phase')",
450: text=>"Updated"});
1.20 www 451: &print_header($r,$phase,$context,undef,$container);
1.21.4.12 raeburn 452: my ($crstype,%lastact,$errors);
1.7 raeburn 453: if ($context eq 'course') {
454: $crstype = &Apache::loncommon::course_type();
455: }
1.1 raeburn 456: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') &&
457: (ref($prefs) eq 'HASH')) {
458: foreach my $item (@{$prefs_order}) {
459: if (grep(/^\Q$item\E$/,@actions)) {
460: if ($context eq 'domain') {
1.4 raeburn 461: $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
462: &Apache::domainprefs::process_changes($r,$dom,
1.21.4.4 raeburn 463: $confname,$item,$roles,$values,\%lastact));
1.1 raeburn 464: } else {
1.4 raeburn 465: $changes{$item} = {};
1.21.4.12 raeburn 466: $errors =
1.21.4.13.2.1 (raeburn 467:: &Apache::courseprefs::process_changes($dom,$confname,$item,$values,
1.21.4.12 raeburn 468: $prefs->{$item},$changes{$item},
469: $allitems,\%disallowed,$crstype);
1.4 raeburn 470: if (keys(%{$changes{$item}}) > 0) {
471: $numchanged ++;
472: }
1.1 raeburn 473: }
474: }
475: }
476: }
1.4 raeburn 477: if ($context eq 'course') {
478: if ($numchanged) {
1.11 wenzelju 479: my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
480: $prefs,$values,\%changes,$crstype);
481: $r->print(&Apache::loncommon::confirmwrapper($message));
1.4 raeburn 482: } else {
1.7 raeburn 483: if ($crstype eq 'Community') {
1.11 wenzelju 484: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
1.7 raeburn 485: } else {
1.11 wenzelju 486: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
1.7 raeburn 487: }
1.4 raeburn 488: }
489: if (keys(%disallowed) > 0) {
490: $r->print('<p>');
491: foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
492: if (ref($disallowed{$item}) eq 'HASH') {
493: if (keys(%{$disallowed{$item}}) > 0) {
494: $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
1.7 raeburn 495: $prefs,$crstype));
1.4 raeburn 496: }
497: }
498: }
499: $r->print('</p>');
500: }
1.21.4.12 raeburn 501: if ($errors) {
502: $r->print('<p>'.$errors.'</p>');
503: }
1.4 raeburn 504: }
1.1 raeburn 505: $r->print('<p>');
1.4 raeburn 506: my $footer_text = 'Back to configuration display';
507: if ($context eq 'course') {
508: $footer_text = 'Back to display/edit settings';
509: }
1.21.4.9 raeburn 510: &print_footer($r,$phase,'display',$footer_text,\@actions,$container,$parm_permission);
1.1 raeburn 511: $r->print('</p>');
1.21.4.4 raeburn 512: return \%lastact;
1.1 raeburn 513: }
514:
515: sub display_settings {
1.3 raeburn 516: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
1.21.4.9 raeburn 517: $allitems,$crstype,$container,$parm_permission) = @_;
1.1 raeburn 518: my %brcrumtext = &get_crumb_text();
519: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
520: &Apache::lonhtmlcommon::add_breadcrumb
521: ({href=>"javascript:changePage(document.$phase,'display')",
1.4 raeburn 522: text=>"Display/Edit Settings"});
1.21.4.7 raeburn 523: my $instcode;
524: if (ref($values) eq 'HASH') {
525: $instcode = $values->{'internal.coursecode'};
526: }
1.21.4.13.2.3 (raeburn 527:: &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values);
1.12 raeburn 528: my $divwidth = 900;
1.1 raeburn 529: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) {
530: if (@actions > 0) {
531: my $rowsum = 0;
532: my (%output,%rowtotal,@items);
533: foreach my $item (@{$prefs_order}) {
534: if (grep(/^\Q$item\E$/,@actions)) {
535: push(@items,$item);
536: if ($context eq 'domain') {
1.21.4.6 raeburn 537: my $settings;
538: if (ref($values) eq 'HASH') {
539: $settings = $values->{$item};
540: }
1.15 raeburn 541: if ($item eq 'usersessions') {
542: $r->print('<script type="text/javascript">'."\n".
543: '// <![CDATA['."\n".
544: &Apache::loncommon::check_uncheck_jscript()."\n".
545: '// ]]>'."\n".
546: '</script>'."\n");
1.21.4.5 raeburn 547: } elsif ($item eq 'selfcreation') {
1.21.4.6 raeburn 548: if (ref($values) eq 'HASH') {
549: $settings = $values->{'usercreation'};
550: }
551: } elsif ($item eq 'defaults') {
552: if (ref($values->{'inststatus'}) eq 'HASH') {
553: if (ref($values->{'defaults'}) eq 'HASH') {
554: $settings = {%{$values->{'inststatus'}},%{$values->{'defaults'}}};
555: } else {
556: $settings = $values->{'inststatus'};
557: }
558: } else {
559: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
560: my $inststatus = {
561: inststatustypes => $usertypes,
562: inststatusorder => $types,
563: inststatusguest => [],
564: };
565: if (ref($values->{defaults}) eq 'HASH') {
566: $settings = {%{$inststatus},%{$values->{'defaults'}}};
567: } else {
568: $settings = $inststatus;
569: }
570: }
1.21.4.13.2.4! (raeburn 571:: } elsif ($item eq 'lti') {
! 572:: if (ref($values->{'ltisec'}) eq 'HASH') {
! 573:: $settings = $values->{'ltisec'};
! 574:: }
1.15 raeburn 575: }
1.1 raeburn 576: ($output{$item},$rowtotal{$item}) =
577: &Apache::domainprefs::print_config_box($r,$dom,$confname,
1.21.4.5 raeburn 578: $phase,$item,$prefs->{$item},$settings);
1.1 raeburn 579: } else {
580: ($output{$item},$rowtotal{$item}) =
1.21.4.13.2.2 (raeburn 581:: &Apache::courseprefs::print_config_box($r,$dom,$confname,$phase,
1.21.4.9 raeburn 582: $item,$prefs->{$item},$values,$allitems,$crstype,$parm_permission);
1.1 raeburn 583: }
584: $rowsum += $rowtotal{$item};
585: }
586: }
1.12 raeburn 587: $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
1.1 raeburn 588: for (my $i=0; $i<@items; $i++) {
589: $r->print($output{$items[$i]});
590: }
1.12 raeburn 591: $r->print('</div>');
1.21.4.9 raeburn 592: $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container,$parm_permission));
1.1 raeburn 593: } else {
594: $r->print('<input type="hidden" name="phase" value="" />'.
1.12 raeburn 595: '<span class="LC_error">'.&mt('No settings chosen').
596: '</span>');
1.1 raeburn 597: }
598: $r->print('</form>');
599: }
600: $r->print(&Apache::loncommon::end_page());
601: return;
602: }
603:
604: sub display_choices {
1.21.4.9 raeburn 605: my ($r,$phase,$context,$prefs_order,$prefs,$container,$parm_permission) = @_;
1.1 raeburn 606: if ($phase eq '') {
607: $phase = 'pickactions';
608: }
609: my %helphash;
1.20 www 610: &print_header($r,$phase,$context,undef,$container);
1.1 raeburn 611: $r->print('<script type="text/javascript">'."\n".
1.6 raeburn 612: '// <![CDATA['."\n".
1.1 raeburn 613: &Apache::loncommon::check_uncheck_jscript()."\n".
1.6 raeburn 614: '// ]]>'."\n".
1.12 raeburn 615: '</script>'."\n");
1.21.4.9 raeburn 616: my $heading = &mt('Settings to display/modify');
617: if (ref($parm_permission) eq 'HASH') {
618: unless ($parm_permission->{'process'}) {
619: $heading = &mt('Settings to display');
620: }
621: }
622: $r->print('<h3>'.$heading.'</h3>'.
1.13 raeburn 623: '<div><input type="button" value="'.&mt('check all').'" '.
1.1 raeburn 624: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
625: ' />'.(' 'x2).
626: '<input type="button" value="'.&mt('uncheck all').'" '.
1.12 raeburn 627: 'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
628: "\n".
1.13 raeburn 629: '</div><div class="LC_left_float">');
1.12 raeburn 630: my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
1.1 raeburn 631: if (ref($prefs_order) eq 'ARRAY') {
632: $numitems = @{$prefs_order};
633: }
1.12 raeburn 634: my $numcols = 3;
635: $maxincol = int($numitems/$numcols);
636: if ($numitems%$numcols) {
637: $maxincol ++;
1.1 raeburn 638: }
1.14 raeburn 639: $firstthird = $maxincol;
640: $secondthird = $firstthird + $maxincol;
1.1 raeburn 641: $count = 0;
642: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
643: foreach my $item (@{$prefs_order}) {
644: $r->print('<h4>'.
645: &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
646: '<label><input type="checkbox" name="actions" value="'.$item.
647: '" /> '.&mt($prefs->{$item}->{'text'}).'</label></h4>');
648: $count ++;
1.12 raeburn 649: if ((!$seconddiv) && ($count >= $firstthird)) {
1.1 raeburn 650: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
651: $seconddiv = 1;
652: }
1.12 raeburn 653: if ((!$thirddiv) && ($count >= $secondthird)) {
654: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
655: $thirddiv = 1;
1.13 raeburn 656: }
1.1 raeburn 657: }
658: }
1.21.4.12 raeburn 659: $r->print('</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
1.21.4.9 raeburn 660: $r->print(&print_footer($r,$phase,'display','Display',undef,$container,$parm_permission));
1.1 raeburn 661: $r->print('</form>');
662: $r->print(&Apache::loncommon::end_page());
663: return;
664: }
665:
666: sub color_pick_js {
667: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
668: my $output = <<"ENDCOL";
669:
670: $pjump_def
671:
672: function psub() {
1.21 www 673: modalWindow.close();
1.1 raeburn 674: if (document.parmform.pres_marker.value!='') {
675: if (document.parmform.pres_type.value!='') {
676: eval('document.display.'+
677: document.parmform.pres_marker.value+
678: '.value=document.parmform.pres_value.value;');
679: }
680: } else {
681: document.parmform.pres_value.value='';
682: document.parmform.pres_marker.value='';
683: }
684: }
685:
686: function get_id (span_id) {
687: if (document.getElementById) {
688: return document.getElementById(span_id);
689: }
690: if (document.all) {
691: return document.all[span_id];
692: }
693: return false;
694: }
695:
696: function colchg_span (span_id_str,new_color_item) {
697: var span_ref = get_id(span_id_str);
698: if (span_ref.style) { span_ref = span_ref.style; }
699: span_ref.background = new_color_item.value;
700: span_ref.backgroundColor = new_color_item.value;
701: span_ref.bgColor = new_color_item.value;
702: }
703:
704: ENDCOL
705: return $output;
706: }
707:
708: sub get_crumb_text {
709: my %brcrumbtext = (
710: domain => 'Domain Settings',
1.4 raeburn 711: course => 'Display/Edit Settings',
1.1 raeburn 712: );
713: return %brcrumbtext;
714: }
715:
716: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>