Annotation of loncom/interface/lonconfigsettings.pm, revision 1.21.4.13.2.3
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.21.4.13.2.3! (raeburn 4:: # $Id: lonconfigsettings.pm,v 1.21.4.13.2.2 2022/02/07 12:00:27 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.1 (raeburn 296:: if (grep(/^ltitools$/,@actions)) {
297:: $onload .= "toggleLTITools(document.display,'user','add');";
298:: if (ref($values) eq 'HASH') {
299:: if (ref($values->{'ltitools'}) eq 'HASH') {
300:: my $numltitools = scalar(keys(%{$values->{'ltitools'}}));
301:: for (my $i=0; $i<$numltitools; $i++) {
302:: $onload .= "toggleLTITools(document.display,'user','$i');";
303:: }
304:: }
305:: }
306:: }
1.21.4.12 raeburn 307: if (grep(/^wafproxy$/,@actions)) {
308: $onload .= "toggleWAF();checkWAF();updateWAF();";
309: }
1.21.4.11 raeburn 310: if (grep(/^scantron$/,@actions)) {
1.21.4.13 raeburn 311: $onload .= "toggleScantron(document.display);";
1.21.4.11 raeburn 312: }
1.21.4.12 raeburn 313: if (grep(/^autoupdate$/,@actions)) {
1.21.4.13 raeburn 314: $onload .= "toggleLastActiveDays(document.display);";
315: }
316: if (grep(/^autoenroll$/,@actions)) {
317: $onload .= "toggleFailsafe(document.display);";
1.21.4.12 raeburn 318: }
319: if (grep(/^login$/,@actions)) {
320: my %domservers = &Apache::lonnet::get_servers($dom);
321: foreach my $server (sort(keys(%domservers))) {
322: $onload .= "toggleSamlOptions(document.display,'$server');";
323: }
324: }
1.21.4.10 raeburn 325: if ($onload) {
1.21.4.7 raeburn 326: my %loaditems = (
1.21.4.10 raeburn 327: 'onload' => $onload,
1.21.4.7 raeburn 328: );
329: $additem = {'add_entries' => \%loaditems,};
330: }
331: } elsif ($context eq 'course') {
1.21.4.13.2.2 (raeburn 332:: my $onload;
1.21.4.7 raeburn 333: if (grep(/^courseinfo$/,@actions)) {
334: if (@code_order) {
1.21.4.13.2.2 (raeburn 335:: $onload = "courseSet('','load');toggleCloners(document.display.cloners_instcode);";
336:: }
337:: }
1.21.4.13.2.3! (raeburn 338:: if (grep(/^linkprot$/,@actions)) {
1.21.4.13.2.2 (raeburn 339:: if (ref($values) eq 'HASH') {
1.21.4.13.2.3! (raeburn 340:: if (ref($values->{'linkprot'}) eq 'HASH') {
1.21.4.13.2.2 (raeburn 341:: my $ltiauth;
342:: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
343:: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
344:: } else {
345:: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
346:: $ltiauth = $domdefs{'crsltiauth'};
347:: }
1.21.4.13.2.3! (raeburn 348:: my $posslti = scalar(keys(%{$values->{'linkprot'}}));
1.21.4.13.2.2 (raeburn 349:: for (my $i=0; $i<=$posslti; $i++) {
350:: my $num = $i;
351:: if ($i == $posslti) {
352:: $num = 'add';
353:: }
1.21.4.13.2.3! (raeburn 354:: if (ref($values->{'linkprot'}->{$i}) eq 'HASH') {
! 355:: if ($values->{'linkprot'}->{$i}->{'usable'}) {
! 356:: $onload .= "toggleLinkProt(document.display,'$num','secret');";
1.21.4.13.2.2 (raeburn 357:: }
358:: }
359:: if ($ltiauth) {
1.21.4.13.2.3! (raeburn 360:: $onload .= "toggleLinkProtReqUser(document.display,'requser','optional','1','block','$num');".
! 361:: "toggleLinkProtReqUser(document.display,'mapuser','userfield','other','inline-block','$num');";
1.21.4.13.2.2 (raeburn 362:: }
363:: }
364:: }
1.21.4.7 raeburn 365: }
366: }
1.21.4.13.2.2 (raeburn 367:: if ($onload) {
368:: my %loaditems = (
369:: 'onload' => $onload,
370:: );
371:: $additem = {'add_entries' => \%loaditems,};
372:: }
1.21.4.7 raeburn 373: }
1.1 raeburn 374: }
375: $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
376: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
377: $r->print('
378: <form name="parmform" action="">
379: <input type="hidden" name="pres_marker" />
380: <input type="hidden" name="pres_type" />
381: <input type="hidden" name="pres_value" />
382: </form>
383: ');
384: $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
385: ' enctype="multipart/form-data">');
386: return;
387: }
388:
389: sub print_footer {
1.21.4.9 raeburn 390: my ($r,$phase,$newphase,$button_text,$actions,$container,$parm_permission) = @_;
1.1 raeburn 391: $button_text = &mt($button_text);
1.12 raeburn 392: $r->print('<input type="hidden" name="phase" value="" />');
1.5 raeburn 393: if (defined($env{'form.origin'})) {
394: $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
395: }
1.1 raeburn 396: if (($phase eq 'display') || ($phase eq 'process')) {
397: if (ref($actions) eq 'ARRAY') {
398: foreach my $item (@{$actions}) {
1.16 raeburn 399: $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
1.1 raeburn 400: }
401: }
402: }
403: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
404: if ($phase eq 'process') {
1.21.4.2 raeburn 405: $r->print(
406: &Apache::lonhtmlcommon::actionbox(
407: ['<a href='.$dest.'>'.$button_text.'</a>']));
1.1 raeburn 408: } else {
409: my $onclick;
410: if ($phase eq 'display') {
411: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
412: } else {
413: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
414: }
1.21.4.9 raeburn 415: my $showbutton = 1;
416: if (ref($parm_permission) eq 'HASH') {
417: unless (($parm_permission->{'process'}) || ($newphase eq 'display')) {
418: $showbutton = 0;
419: }
420: }
421: if ($showbutton) {
422: $r->print('<p><input type="button" name="store" value="'.
423: $button_text.'" onclick='.$onclick.' /></p>');
424: }
1.1 raeburn 425: }
426: if ($phase eq 'process') {
1.20 www 427: $r->print('</form>');
428: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 429: }
430: return;
431: }
432:
433: sub make_changes {
1.21.4.9 raeburn 434: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,
435: $allitems,$container,$parm_permission) = @_;
1.1 raeburn 436: my %brcrumtext = &get_crumb_text();
437: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.4 raeburn 438: my ($numchanged,%changes,%disallowed);
1.1 raeburn 439: &Apache::lonhtmlcommon::add_breadcrumb
440: ({href=>"javascript:changePage(document.$phase,'display')",
441: text=>$brcrumtext{$context}},
442: {href=>"javascript:changePage(document.$phase,'$phase')",
443: text=>"Updated"});
1.20 www 444: &print_header($r,$phase,$context,undef,$container);
1.21.4.12 raeburn 445: my ($crstype,%lastact,$errors);
1.7 raeburn 446: if ($context eq 'course') {
447: $crstype = &Apache::loncommon::course_type();
448: }
1.1 raeburn 449: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') &&
450: (ref($prefs) eq 'HASH')) {
451: foreach my $item (@{$prefs_order}) {
452: if (grep(/^\Q$item\E$/,@actions)) {
453: if ($context eq 'domain') {
1.4 raeburn 454: $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
455: &Apache::domainprefs::process_changes($r,$dom,
1.21.4.4 raeburn 456: $confname,$item,$roles,$values,\%lastact));
1.1 raeburn 457: } else {
1.4 raeburn 458: $changes{$item} = {};
1.21.4.12 raeburn 459: $errors =
1.21.4.13.2.1 (raeburn 460:: &Apache::courseprefs::process_changes($dom,$confname,$item,$values,
1.21.4.12 raeburn 461: $prefs->{$item},$changes{$item},
462: $allitems,\%disallowed,$crstype);
1.4 raeburn 463: if (keys(%{$changes{$item}}) > 0) {
464: $numchanged ++;
465: }
1.1 raeburn 466: }
467: }
468: }
469: }
1.4 raeburn 470: if ($context eq 'course') {
471: if ($numchanged) {
1.11 wenzelju 472: my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
473: $prefs,$values,\%changes,$crstype);
474: $r->print(&Apache::loncommon::confirmwrapper($message));
1.4 raeburn 475: } else {
1.7 raeburn 476: if ($crstype eq 'Community') {
1.11 wenzelju 477: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
1.7 raeburn 478: } else {
1.11 wenzelju 479: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
1.7 raeburn 480: }
1.4 raeburn 481: }
482: if (keys(%disallowed) > 0) {
483: $r->print('<p>');
484: foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
485: if (ref($disallowed{$item}) eq 'HASH') {
486: if (keys(%{$disallowed{$item}}) > 0) {
487: $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
1.7 raeburn 488: $prefs,$crstype));
1.4 raeburn 489: }
490: }
491: }
492: $r->print('</p>');
493: }
1.21.4.12 raeburn 494: if ($errors) {
495: $r->print('<p>'.$errors.'</p>');
496: }
1.4 raeburn 497: }
1.1 raeburn 498: $r->print('<p>');
1.4 raeburn 499: my $footer_text = 'Back to configuration display';
500: if ($context eq 'course') {
501: $footer_text = 'Back to display/edit settings';
502: }
1.21.4.9 raeburn 503: &print_footer($r,$phase,'display',$footer_text,\@actions,$container,$parm_permission);
1.1 raeburn 504: $r->print('</p>');
1.21.4.4 raeburn 505: return \%lastact;
1.1 raeburn 506: }
507:
508: sub display_settings {
1.3 raeburn 509: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
1.21.4.9 raeburn 510: $allitems,$crstype,$container,$parm_permission) = @_;
1.1 raeburn 511: my %brcrumtext = &get_crumb_text();
512: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
513: &Apache::lonhtmlcommon::add_breadcrumb
514: ({href=>"javascript:changePage(document.$phase,'display')",
1.4 raeburn 515: text=>"Display/Edit Settings"});
1.21.4.7 raeburn 516: my $instcode;
517: if (ref($values) eq 'HASH') {
518: $instcode = $values->{'internal.coursecode'};
519: }
1.21.4.13.2.3! (raeburn 520:: &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values);
1.12 raeburn 521: my $divwidth = 900;
1.1 raeburn 522: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) {
523: if (@actions > 0) {
524: my $rowsum = 0;
525: my (%output,%rowtotal,@items);
526: foreach my $item (@{$prefs_order}) {
527: if (grep(/^\Q$item\E$/,@actions)) {
528: push(@items,$item);
529: if ($context eq 'domain') {
1.21.4.6 raeburn 530: my $settings;
531: if (ref($values) eq 'HASH') {
532: $settings = $values->{$item};
533: }
1.15 raeburn 534: if ($item eq 'usersessions') {
535: $r->print('<script type="text/javascript">'."\n".
536: '// <![CDATA['."\n".
537: &Apache::loncommon::check_uncheck_jscript()."\n".
538: '// ]]>'."\n".
539: '</script>'."\n");
1.21.4.5 raeburn 540: } elsif ($item eq 'selfcreation') {
1.21.4.6 raeburn 541: if (ref($values) eq 'HASH') {
542: $settings = $values->{'usercreation'};
543: }
544: } elsif ($item eq 'defaults') {
545: if (ref($values->{'inststatus'}) eq 'HASH') {
546: if (ref($values->{'defaults'}) eq 'HASH') {
547: $settings = {%{$values->{'inststatus'}},%{$values->{'defaults'}}};
548: } else {
549: $settings = $values->{'inststatus'};
550: }
551: } else {
552: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
553: my $inststatus = {
554: inststatustypes => $usertypes,
555: inststatusorder => $types,
556: inststatusguest => [],
557: };
558: if (ref($values->{defaults}) eq 'HASH') {
559: $settings = {%{$inststatus},%{$values->{'defaults'}}};
560: } else {
561: $settings = $inststatus;
562: }
563: }
1.15 raeburn 564: }
1.1 raeburn 565: ($output{$item},$rowtotal{$item}) =
566: &Apache::domainprefs::print_config_box($r,$dom,$confname,
1.21.4.5 raeburn 567: $phase,$item,$prefs->{$item},$settings);
1.1 raeburn 568: } else {
569: ($output{$item},$rowtotal{$item}) =
1.21.4.13.2.2 (raeburn 570:: &Apache::courseprefs::print_config_box($r,$dom,$confname,$phase,
1.21.4.9 raeburn 571: $item,$prefs->{$item},$values,$allitems,$crstype,$parm_permission);
1.1 raeburn 572: }
573: $rowsum += $rowtotal{$item};
574: }
575: }
1.12 raeburn 576: $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
1.1 raeburn 577: for (my $i=0; $i<@items; $i++) {
578: $r->print($output{$items[$i]});
579: }
1.12 raeburn 580: $r->print('</div>');
1.21.4.9 raeburn 581: $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container,$parm_permission));
1.1 raeburn 582: } else {
583: $r->print('<input type="hidden" name="phase" value="" />'.
1.12 raeburn 584: '<span class="LC_error">'.&mt('No settings chosen').
585: '</span>');
1.1 raeburn 586: }
587: $r->print('</form>');
588: }
589: $r->print(&Apache::loncommon::end_page());
590: return;
591: }
592:
593: sub display_choices {
1.21.4.9 raeburn 594: my ($r,$phase,$context,$prefs_order,$prefs,$container,$parm_permission) = @_;
1.1 raeburn 595: if ($phase eq '') {
596: $phase = 'pickactions';
597: }
598: my %helphash;
1.20 www 599: &print_header($r,$phase,$context,undef,$container);
1.1 raeburn 600: $r->print('<script type="text/javascript">'."\n".
1.6 raeburn 601: '// <![CDATA['."\n".
1.1 raeburn 602: &Apache::loncommon::check_uncheck_jscript()."\n".
1.6 raeburn 603: '// ]]>'."\n".
1.12 raeburn 604: '</script>'."\n");
1.21.4.9 raeburn 605: my $heading = &mt('Settings to display/modify');
606: if (ref($parm_permission) eq 'HASH') {
607: unless ($parm_permission->{'process'}) {
608: $heading = &mt('Settings to display');
609: }
610: }
611: $r->print('<h3>'.$heading.'</h3>'.
1.13 raeburn 612: '<div><input type="button" value="'.&mt('check all').'" '.
1.1 raeburn 613: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
614: ' />'.(' 'x2).
615: '<input type="button" value="'.&mt('uncheck all').'" '.
1.12 raeburn 616: 'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
617: "\n".
1.13 raeburn 618: '</div><div class="LC_left_float">');
1.12 raeburn 619: my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
1.1 raeburn 620: if (ref($prefs_order) eq 'ARRAY') {
621: $numitems = @{$prefs_order};
622: }
1.12 raeburn 623: my $numcols = 3;
624: $maxincol = int($numitems/$numcols);
625: if ($numitems%$numcols) {
626: $maxincol ++;
1.1 raeburn 627: }
1.14 raeburn 628: $firstthird = $maxincol;
629: $secondthird = $firstthird + $maxincol;
1.1 raeburn 630: $count = 0;
631: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
632: foreach my $item (@{$prefs_order}) {
633: $r->print('<h4>'.
634: &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
635: '<label><input type="checkbox" name="actions" value="'.$item.
636: '" /> '.&mt($prefs->{$item}->{'text'}).'</label></h4>');
637: $count ++;
1.12 raeburn 638: if ((!$seconddiv) && ($count >= $firstthird)) {
1.1 raeburn 639: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
640: $seconddiv = 1;
641: }
1.12 raeburn 642: if ((!$thirddiv) && ($count >= $secondthird)) {
643: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
644: $thirddiv = 1;
1.13 raeburn 645: }
1.1 raeburn 646: }
647: }
1.21.4.12 raeburn 648: $r->print('</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
1.21.4.9 raeburn 649: $r->print(&print_footer($r,$phase,'display','Display',undef,$container,$parm_permission));
1.1 raeburn 650: $r->print('</form>');
651: $r->print(&Apache::loncommon::end_page());
652: return;
653: }
654:
655: sub color_pick_js {
656: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
657: my $output = <<"ENDCOL";
658:
659: $pjump_def
660:
661: function psub() {
1.21 www 662: modalWindow.close();
1.1 raeburn 663: if (document.parmform.pres_marker.value!='') {
664: if (document.parmform.pres_type.value!='') {
665: eval('document.display.'+
666: document.parmform.pres_marker.value+
667: '.value=document.parmform.pres_value.value;');
668: }
669: } else {
670: document.parmform.pres_value.value='';
671: document.parmform.pres_marker.value='';
672: }
673: }
674:
675: function get_id (span_id) {
676: if (document.getElementById) {
677: return document.getElementById(span_id);
678: }
679: if (document.all) {
680: return document.all[span_id];
681: }
682: return false;
683: }
684:
685: function colchg_span (span_id_str,new_color_item) {
686: var span_ref = get_id(span_id_str);
687: if (span_ref.style) { span_ref = span_ref.style; }
688: span_ref.background = new_color_item.value;
689: span_ref.backgroundColor = new_color_item.value;
690: span_ref.bgColor = new_color_item.value;
691: }
692:
693: ENDCOL
694: return $output;
695: }
696:
697: sub get_crumb_text {
698: my %brcrumbtext = (
699: domain => 'Domain Settings',
1.4 raeburn 700: course => 'Display/Edit Settings',
1.1 raeburn 701: );
702: return %brcrumbtext;
703: }
704:
705: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>