Annotation of loncom/interface/lonconfigsettings.pm, revision 1.70
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.70 ! raeburn 4: # $Id: lonconfigsettings.pm,v 1.69 2023/04/13 15:21:00 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();
1.68 raeburn 40: use LONCAPA qw(:DEFAULT :match);
41: use File::Copy;
1.1 raeburn 42:
43: sub print_header {
1.59 raeburn 44: my ($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values) = @_;
1.30 raeburn 45: my ($pagetitle,$brcrumtitle,$action,$call_category_check,$instcode_check,
1.68 raeburn 46: $linkprot_check,$ltitools_check,$crstype,@actions,@code_order);
1.30 raeburn 47: if ($phase eq 'display') {
48: @actions = &Apache::loncommon::get_env_multiple('form.actions');
49: }
1.1 raeburn 50: if ($context eq 'domain') {
1.12 raeburn 51: ($pagetitle, $brcrumtitle) = ('View/Modify Domain Settings','View/Modify Domain Settings');
1.1 raeburn 52: $action = '/adm/domainprefs';
1.8 raeburn 53: if ($phase eq 'display') {
54: if (grep(/^coursecategories$/,@actions)) {
55: $call_category_check = qq|
56: if (formname == document.display) {
57: if (!categoryCheck(formname)) {
58: return;
59: }
60: }
61: |;
62: }
63: }
1.1 raeburn 64: } else {
1.24 raeburn 65: $crstype = &Apache::loncommon::course_type();
66: if ($crstype eq 'Community') {
1.7 raeburn 67: ($pagetitle,$brcrumtitle) = ('Community Configuration','Community Configuration');
68: } else {
69: ($pagetitle,$brcrumtitle) = ('Course Configuration','Course Configuration');
70: }
1.1 raeburn 71: $action = '/adm/courseprefs';
1.30 raeburn 72: if ($phase eq 'display') {
73: if (grep(/^courseinfo$/,@actions)) {
74: my %codedefaults;
75: &Apache::lonnet::auto_instcode_defaults($env{'request.role.domain'},\%codedefaults,
76: \@code_order);
77: if (@code_order) {
78: my $noinstcodestr = &mt('You indicated cloning based on category, but did not select any categories.');
1.31 damieng 79: &js_escape(\$noinstcodestr);
1.30 raeburn 80: $instcode_check = <<"ENDSCRIPT";
81: if (formname == document.display) {
82: if (formname.cloners_instcode.length) {
83: for (var j=0; j<formname.cloners_instcode.length; j++) {
84: if (formname.cloners_instcode[j].checked) {
85: if (formname.cloners_instcode[j].value == 1) {
86: var codes;
87: if (document.getElementsByClassName) {
88: codes = document.getElementsByClassName('LC_cloners_instcodes');
89: } else {
90: codes = getElementsByClassName(document.body,'LC_cloners_instcodes');
91: }
92: if (codes.length) {
93: var gotcode = 0;
94: for (var i=0; i<codes.length; i++) {
95: if (codes[i].selectedIndex != 0) {
96: gotcode = 1;
97: break;
98: }
99: }
100: if (!gotcode) {
101: for (var k=0; k<formname.cloners_instcode.length; k++) {
102: if (formname.cloners_instcode[k].value == 0) {
103: formname.cloners_instcode[k].checked = true;
104: }
105: }
106: toggleCloners(document.display.cloners_instcode);
107: alert('$noinstcodestr');
108: return false;
109: }
110: }
111: }
112: }
113: }
114: }
115: }
116:
117: ENDSCRIPT
118: }
119: }
1.68 raeburn 120: if (($context eq 'course') && ((grep(/^linkprot$/,@actions)) ||
121: (grep(/^ltitools$/,@actions)))) {
1.59 raeburn 122: my $allowed;
123: my $home = &Apache::lonnet::homeserver($confname,$dom);
124: unless ($home eq 'no_host') {
125: my @ids=&Apache::lonnet::current_machine_ids();
126: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
127: }
128: if ($allowed) {
1.68 raeburn 129: if (grep((/^linkprot$/,@actions))) {
130: $linkprot_check = <isecret_js('linkprot',$dom,$values);
1.59 raeburn 131: }
1.68 raeburn 132: if (grep((/^ltitools$/,@actions))) {
133: $ltitools_check = <isecret_js('ltitools',$dom,$values);
1.59 raeburn 134: }
135: }
136: }
1.30 raeburn 137: }
1.1 raeburn 138: }
139: my $alert = &mt('You must select at least one functionality type to display.');
1.31 damieng 140: &js_escape(\$alert);
1.1 raeburn 141: my $js = '
142: <script type="text/javascript">
1.6 raeburn 143: // <![CDATA[
144:
1.1 raeburn 145: function changePage(formname,newphase) {
146: formname.phase.value = newphase;
147: numchecked = 0;
148: if (formname == document.pickactions) {
149: if (formname.actions.length > 0) {
150: for (var i = 0; i<formname.actions.length; i++) {
151: if (formname.actions[i].checked) {
152: numchecked ++;
153: }
154: }
155: } else {
156: if (formname.actions.checked) {
157: numchecked ++;
158: }
159: }
160: if (numchecked > 0) {
161: formname.submit();
162: } else {
163: alert("'.$alert.'");
164: return;
165: }
166: }
1.68 raeburn 167: '.$instcode_check.$call_category_check.$linkprot_check.$ltitools_check.'
1.1 raeburn 168: formname.submit();
169: }'."\n";
170: if ($phase eq 'pickactions') {
1.22 foxr 171: $js .= &Apache::lonhtmlcommon::color_picker();
1.1 raeburn 172: $js .=
1.12 raeburn 173: &Apache::lonhtmlcommon::set_form_elements({actions => 'checkbox'})."\n";
1.1 raeburn 174: } elsif ($phase eq 'display') {
1.22 foxr 175: $js .= &Apache::lonhtmlcommon::color_picker();
1.1 raeburn 176: $js .= &color_pick_js()."\n";
1.68 raeburn 177: if ($context eq 'domain') {
178: if (grep(/^(lti|ltitools)$/,@actions)) {
179: $js .= <isec_javascript($dom)."\n";
180: }
181: }
1.1 raeburn 182: }
183: $js .= &Apache::loncommon::viewport_size_js().'
1.6 raeburn 184:
185: // ]]>
1.1 raeburn 186: </script>
187: ';
1.2 raeburn 188: if ($jscript) {
189: $js .= "
190:
191: $jscript
192:
193: ";
194: }
1.1 raeburn 195: my $additem;
196: if ($phase eq 'pickactions') {
197: my %loaditems = (
1.12 raeburn 198: 'onload' => "setFormElements(document.pickactions);",
1.1 raeburn 199: );
200: $additem = {'add_entries' => \%loaditems,};
1.30 raeburn 201: } elsif ($phase eq 'display') {
202: if ($context eq 'domain') {
1.34 raeburn 203: my $onload;
1.30 raeburn 204: if (grep(/^coursedefaults$/,@actions)) {
1.34 raeburn 205: $onload = "toggleDisplay(document.display,'cloneinstcode');".
206: "toggleDisplay(document.display,'credits');".
207: "toggleDisplay(document.display,'studentsubmission');";
208: }
209: if (grep(/^selfcreation$/,@actions)) {
210: my $prefix = 'cancreate_emailverified';
1.36 raeburn 211: my $customclass = 'LC_selfcreate_email';
212: my $classprefix = 'LC_canmodify_emailusername_';
213: my $optionsprefix = 'LC_options_emailusername_';
214: $onload .= "toggleRows(document.display,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
215: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
216: my $hascustom;
217: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
218: if (ref($emailrules) eq 'HASH') {
219: if (keys(%{$emailrules}) > 0) {
220: $hascustom = 'cancreate_emailrule';
221: }
222: }
223: my @posstypes;
224: if (ref($types) eq 'ARRAY') {
225: @posstypes = @{$types};
226: push(@posstypes,'default');
227: foreach my $type (@posstypes) {
228: $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
229: "'cancreate_emaildomain','$type');";
1.34 raeburn 230: }
1.36 raeburn 231: } else {
232: $onload .= "toggleEmailOptions(document.display,'cancreate_emailoptions','$hascustom',".
233: "'cancreate_emaildomain','default');";
1.34 raeburn 234: }
1.37 raeburn 235: }
236: if (grep(/^contacts$/,@actions)) {
237: my $customclass = 'LC_helpdesk_override';
238: my $optionsprefix = 'LC_options_helpdesk_';
1.38 raeburn 239: $onload .= "toggleHelpdeskRow(document.display,'overrides','$customclass','$optionsprefix');";
1.34 raeburn 240: }
1.40 raeburn 241: if (grep(/^lti$/,@actions)) {
242: $onload .= "toggleLTI(document.display,'user','add');".
243: "toggleLTI(document.display,'crs','add');".
1.42 raeburn 244: "toggleLTI(document.display,'sec','add');".
1.43 raeburn 245: "toggleLTI(document.display,'lcauth','add');".
1.44 raeburn 246: "toggleLTI(document.display,'lcmenu','add');".
1.46 raeburn 247: "toggleLTI(document.display,'passback','add');".
248: "toggleLTI(document.display,'callback','add');";
1.40 raeburn 249: if (ref($values) eq 'HASH') {
250: if (ref($values->{'lti'}) eq 'HASH') {
251: my $numlti = scalar(keys(%{$values->{'lti'}}));
252: for (my $i=0; $i<$numlti; $i++) {
253: $onload .= "toggleLTI(document.display,'user','$i');".
254: "toggleLTI(document.display,'crs','$i');".
1.42 raeburn 255: "toggleLTI(document.display,'sec','$i');".
1.43 raeburn 256: "toggleLTI(document.display,'lcauth','$i');".
1.44 raeburn 257: "toggleLTI(document.display,'lcmenu','$i');".
1.46 raeburn 258: "toggleLTI(document.display,'passback','$i');".
259: "toggleLTI(document.display,'callback','$i');";
1.40 raeburn 260: }
261: }
1.41 raeburn 262: }
1.58 raeburn 263: my %servers = &Apache::lonnet::get_servers($dom,'library');
264: foreach my $server (keys(%servers)) {
1.68 raeburn 265: $onload .= "togglePrivKey(document.display,'ltisec','$server');";
1.58 raeburn 266: }
1.68 raeburn 267: $onload .= "toggleLTIEncKey(document.display,'ltisec');";
1.40 raeburn 268: }
1.39 raeburn 269: if (grep(/^ltitools$/,@actions)) {
270: $onload .= "toggleLTITools(document.display,'passback','add');".
1.41 raeburn 271: "toggleLTITools(document.display,'roster','add');".
272: "toggleLTITools(document.display,'user','add');";
1.39 raeburn 273: if (ref($values) eq 'HASH') {
274: if (ref($values->{'ltitools'}) eq 'HASH') {
275: my $numltitools = scalar(keys(%{$values->{'ltitools'}}));
276: for (my $i=0; $i<$numltitools; $i++) {
277: $onload .= "toggleLTITools(document.display,'passback','$i');".
1.41 raeburn 278: "toggleLTITools(document.display,'roster','$i');".
279: "toggleLTITools(document.display,'user','$i');";
1.39 raeburn 280: }
281: }
282: }
1.68 raeburn 283: my %servers = &Apache::lonnet::get_servers($dom,'library');
284: foreach my $server (keys(%servers)) {
285: $onload .= "togglePrivKey(document.display,'toolsec','$server');";
286: }
287: $onload .= "toggleLTIEncKey(document.display,'toolsec');";
1.39 raeburn 288: }
1.48 raeburn 289: if (grep(/^wafproxy$/,@actions)) {
290: $onload .= "toggleWAF();checkWAF();updateWAF();";
291: }
1.47 raeburn 292: if (grep(/^proctoring$/,@actions)) {
293: $onload .= "toggleProctoring(document.display,'proctorio');".
294: "toggleProctoring(document.display,'examity');";
295: }
1.45 raeburn 296: if (grep(/^scantron$/,@actions)) {
1.54 raeburn 297: $onload .= "toggleScantron(document.display);";
1.45 raeburn 298: }
1.52 raeburn 299: if (grep(/^autoupdate$/,@actions)) {
1.54 raeburn 300: $onload .= "toggleLastActiveDays(document.display);";
1.52 raeburn 301: }
1.55 raeburn 302: if (grep(/^autoenroll$/,@actions)) {
303: $onload .= "toggleFailsafe(document.display);";
304: }
1.53 raeburn 305: if (grep(/^login$/,@actions)) {
306: my %domservers = &Apache::lonnet::get_servers($dom);
307: foreach my $server (sort(keys(%domservers))) {
308: $onload .= "toggleSamlOptions(document.display,'$server');";
309: }
310: }
1.34 raeburn 311: if ($onload) {
1.30 raeburn 312: my %loaditems = (
1.35 raeburn 313: 'onload' => $onload,
1.30 raeburn 314: );
315: $additem = {'add_entries' => \%loaditems,};
316: }
317: } elsif ($context eq 'course') {
1.68 raeburn 318: my ($onload,$ishome,$crshome_checked);
1.30 raeburn 319: if (grep(/^courseinfo$/,@actions)) {
1.56 raeburn 320: if (@code_order) {
321: $onload = "courseSet('','load');toggleCloners(document.display.cloners_instcode);";
322: }
323: }
1.60 raeburn 324: if (grep(/^linkprot$/,@actions)) {
1.56 raeburn 325: if (ref($values) eq 'HASH') {
1.60 raeburn 326: if (ref($values->{'linkprot'}) eq 'HASH') {
1.57 raeburn 327: my $ltiauth;
328: if (exists($env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'})) {
329: $ltiauth = $env{'course.'.$env{'request.course.id'}.'.internal.ltiauth'};
330: } else {
331: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
332: $ltiauth = $domdefs{'crsltiauth'};
333: }
1.68 raeburn 334: unless ($crshome_checked) {
335: $ishome = &is_home();
336: $crshome_checked = 1;
1.62 raeburn 337: }
1.60 raeburn 338: my $posslti = scalar(keys(%{$values->{'linkprot'}}));
1.57 raeburn 339: for (my $i=0; $i<=$posslti; $i++) {
340: my $num = $i;
341: if ($i == $posslti) {
342: $num = 'add';
343: }
1.60 raeburn 344: if (ref($values->{'linkprot'}->{$i}) eq 'HASH') {
345: if ($values->{'linkprot'}->{$i}->{'usable'}) {
1.68 raeburn 346: $onload .= "toggleChgSecret(document.display,'$num','secret','linkprot');";
1.57 raeburn 347: }
1.58 raeburn 348: }
1.70 ! raeburn 349: $onload .= "toggleLinkProtExtra(document.display,'returnurl','divurlparam','1','inline-block','$num');".
! 350: "toggleLinkProtExtra(document.display,'passback','passbackparam','1','inline-block','$num');";
1.57 raeburn 351: if ($ltiauth) {
1.65 raeburn 352: $onload .= "toggleLinkProtExtra(document.display,'requser','optional','1','block','$num');".
353: "toggleLinkProtExtra(document.display,'mapuser','userfield','other','inline-block','$num');";
1.56 raeburn 354: }
1.62 raeburn 355: if ($ishome) {
1.68 raeburn 356: $onload .= "uncheckLinkProtMakeVis('linkprot','visible','$num');";
357: }
358: }
359: }
360: }
361: }
362: if (grep(/^ltitools$/,@actions)) {
363: if (ref($values) eq 'HASH') {
364: if (ref($values->{'ltitools'}) eq 'HASH') {
365: unless ($crshome_checked) {
366: $ishome = &is_home();
367: $crshome_checked = 1;
368: }
369: my $possltitools = scalar(keys(%{$values->{'ltitools'}}));
370: for (my $i=0; $i<=$possltitools; $i++) {
371: my $num = $i;
372: if ($i == $possltitools) {
373: $num = 'add';
374: }
375: if (ref($values->{'ltitools'}->{$i}) eq 'HASH') {
376: if ($values->{'ltitools'}->{$i}->{'usable'}) {
377: $onload .= "toggleChgSecret(document.display,'$num','secret','ltitools');";
378: }
379: }
380: if ($ishome) {
381: $onload .= "uncheckLinkProtMakeVis('ltitools','visible','$num');";
1.62 raeburn 382: }
1.56 raeburn 383: }
384: }
1.30 raeburn 385: }
386: }
1.66 raeburn 387: if (grep(/^appearance$/,@actions)) {
1.67 raeburn 388: $onload .= "toggleExtRes();";
389: }
390: if (grep(/^localization$/,@actions)) {
391: $onload .= "toggleTimeZone();";
1.66 raeburn 392: }
1.56 raeburn 393: if ($onload) {
394: my %loaditems = (
395: 'onload' => $onload,
396: );
397: $additem = {'add_entries' => \%loaditems,};
398: }
1.30 raeburn 399: }
1.1 raeburn 400: }
401: $r->print(&Apache::loncommon::start_page($pagetitle,$js,$additem));
402: $r->print(&Apache::lonhtmlcommon::breadcrumbs($brcrumtitle));
403: $r->print('
404: <form name="parmform" action="">
405: <input type="hidden" name="pres_marker" />
406: <input type="hidden" name="pres_type" />
407: <input type="hidden" name="pres_value" />
408: </form>
409: ');
1.20 www 410: if ($container) {
1.24 raeburn 411: &Apache::lonparmset::startSettingsScreen($r,$container,$crstype);
1.20 www 412: }
1.1 raeburn 413: $r->print('<form method="post" name="'.$phase.'" action="'.$action.'"'.
414: ' enctype="multipart/form-data">');
415: return;
416: }
417:
1.68 raeburn 418: sub ltisecret_js {
419: my ($name,$dom,$values) = @_;
420: return unless (ref($values) eq 'HASH');
421: my $js;
422: if (($name eq 'linkprot') || ($name eq 'ltitools')) {
423: my (@changeable,@settable);
424: if (ref($values->{$name}) eq 'HASH') {
425: if (keys(%{$values->{$name}})) {
426: my @current = sort { $a <=> $b } keys(%{$values->{$name}});
427: if (@current) {
428: for (my $i=0; $i<@current; $i++) {
429: my $num = $current[$i];
430: if (ref($values->{$name}->{$num}) eq 'HASH') {
431: if ($values->{$name}->{$num}->{'usable'}) {
432: push(@changeable,$i);
433: } else {
434: push(@settable,$i);
435: }
436: }
437: }
438: }
439: }
440: }
441: my ($numrules,$intargjs);
442: $js .= <<ENDJS;
443:
444: var ${name}radio = '';
445: var ${name}secretinput = '';
446: var ${name}posscheck = '';
447:
448: ENDJS
449: if (@changeable) {
450: foreach my $num (@changeable) {
451: ($numrules,$intargjs) =
452: &Apache::loncommon::passwd_validation_js($name.'secretinput',$dom,$name,$num);
453: $js .= <<"ENDJS";
454: ${name}posscheck = '';
455: ${name}radio = document.display.elements['${name}_changesecret_$num'];
456: if (${name}radio.length) {
457: for (var i=0; i<${name}radio.length; i++) {
458: if (${name}radio[i].checked) {
459: if (${name}radio[i].value == 1) {
460: ${name}posscheck = 1;
461: }
462: }
463: }
464: }
465:
466: ENDJS
467: if ($numrules) {
468: $js .= <<"ENDJS";
469: if (${name}posscheck) {
470: ${name}secretinput = document.display.elements['${name}_secret_$num'].value;
471: $intargjs
472: }
473:
474: ENDJS
475: }
476: $js .= <<"ENDJS";
477: if (${name}posscheck) {
478: uncheckLinkProtMakeVis('$name','visible','$num');
479: document.display.elements['${name}_secret_$num'].type = 'password';
480: }
481:
482: ENDJS
483: }
484: }
485: if (@settable) {
486: foreach my $num (@settable) {
487: ($numrules,$intargjs) =
488: &Apache::loncommon::passwd_validation_js($name.'secretinput',$dom,$name,$num);
489: if ($numrules) {
490: $js .= <<ENDJS;
491: ${name}secretinput = document.display.elements['${name}_secret_$num'].value;
492: $intargjs
493:
494: ENDJS
495: }
496: $js .= <<ENDJS;
497: uncheckLinkProtMakeVis('$name','visible','$num');
498: document.display.elements['${name}_secret_$num'].type = 'password';
499:
500: ENDJS
501: }
502: }
503: ($numrules,$intargjs) =
504: &Apache::loncommon::passwd_validation_js($name.'secretinput',$dom,$name,'add');
505: if ($numrules) {
506: $js .= <<ENDJS
1.69 raeburn 507: ${name}secretinput = document.display.elements['${name}_secret_add'].value;
1.68 raeburn 508: if (document.display.elements['${name}_add'].checked) {
509: $intargjs
510: }
511:
512: ENDJS
513: }
514: $js .= <<ENDJS;
515: uncheckLinkProtMakeVis('$name','visible','add');
1.69 raeburn 516: document.display.elements['${name}_secret_add'].type = 'password';
1.68 raeburn 517:
518: ENDJS
519: }
520: return $js;
521: }
522:
523: sub is_home {
524: my $ishome;
525: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
526: unless (($chome eq 'no_host') || ($chome eq '')) {
527: my @ids=&Apache::lonnet::current_machine_ids();
528: foreach my $id (@ids) {
529: if ($id eq $chome) {
530: $ishome=1;
531: last;
532: }
533: }
534: }
535: return $ishome;
536: }
537:
1.1 raeburn 538: sub print_footer {
1.33 raeburn 539: my ($r,$phase,$newphase,$button_text,$actions,$container,$parm_permission) = @_;
1.1 raeburn 540: $button_text = &mt($button_text);
1.12 raeburn 541: $r->print('<input type="hidden" name="phase" value="" />');
1.5 raeburn 542: if (defined($env{'form.origin'})) {
543: $r->print('<input type="hidden" name="origin" value="'.$env{'form.origin'}.'" />'."\n");
544: }
1.1 raeburn 545: if (($phase eq 'display') || ($phase eq 'process')) {
546: if (ref($actions) eq 'ARRAY') {
547: foreach my $item (@{$actions}) {
1.16 raeburn 548: $r->print('<input type="hidden" name="actions" value="'.$item.'" />'."\n");
1.1 raeburn 549: }
550: }
551: }
552: my $dest='"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
553: if ($phase eq 'process') {
1.23 bisitz 554: $r->print(
555: &Apache::lonhtmlcommon::actionbox(
556: ['<a href='.$dest.'>'.$button_text.'</a>']));
1.1 raeburn 557: } else {
558: my $onclick;
559: if ($phase eq 'display') {
560: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
561: } else {
562: $onclick = '"javascript:changePage(document.'.$phase.','."'$newphase'".')"';
563: }
1.33 raeburn 564: my $showbutton = 1;
565: if (ref($parm_permission) eq 'HASH') {
566: unless (($parm_permission->{'process'}) || ($newphase eq 'display')) {
567: $showbutton = 0;
568: }
569: }
570: if ($showbutton) {
571: $r->print('<p><input type="button" name="store" value="'.
572: $button_text.'" onclick='.$onclick.' /></p>');
573: }
1.1 raeburn 574: }
575: if ($phase eq 'process') {
1.20 www 576: $r->print('</form>');
577: if ($container) {
578: &Apache::lonparmset::endSettingsScreen($r);
579: }
580: $r->print(&Apache::loncommon::end_page());
1.1 raeburn 581: }
582: return;
583: }
584:
585: sub make_changes {
1.33 raeburn 586: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$roles,
587: $allitems,$container,$parm_permission) = @_;
1.1 raeburn 588: my %brcrumtext = &get_crumb_text();
589: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.4 raeburn 590: my ($numchanged,%changes,%disallowed);
1.1 raeburn 591: &Apache::lonhtmlcommon::add_breadcrumb
592: ({href=>"javascript:changePage(document.$phase,'display')",
593: text=>$brcrumtext{$context}},
594: {href=>"javascript:changePage(document.$phase,'$phase')",
595: text=>"Updated"});
1.20 www 596: &print_header($r,$phase,$context,undef,$container);
1.50 raeburn 597: my ($crstype,%lastact,$errors);
1.7 raeburn 598: if ($context eq 'course') {
599: $crstype = &Apache::loncommon::course_type();
600: }
1.1 raeburn 601: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') &&
602: (ref($prefs) eq 'HASH')) {
603: foreach my $item (@{$prefs_order}) {
604: if (grep(/^\Q$item\E$/,@actions)) {
605: if ($context eq 'domain') {
1.4 raeburn 606: $r->print('<h3>'.&mt($prefs->{$item}{'text'}).'</h3>'.
607: &Apache::domainprefs::process_changes($r,$dom,
1.27 raeburn 608: $confname,$item,$roles,$values,\%lastact));
1.1 raeburn 609: } else {
1.4 raeburn 610: $changes{$item} = {};
1.50 raeburn 611: $errors =
1.51 raeburn 612: &Apache::courseprefs::process_changes($dom,$confname,$item,$values,
1.50 raeburn 613: $prefs->{$item},$changes{$item},
1.64 raeburn 614: $allitems,\%disallowed,$crstype,
615: \%lastact);
1.4 raeburn 616: if (keys(%{$changes{$item}}) > 0) {
617: $numchanged ++;
618: }
1.1 raeburn 619: }
620: }
621: }
622: }
1.4 raeburn 623: if ($context eq 'course') {
624: if ($numchanged) {
1.11 wenzelju 625: my $message = &Apache::courseprefs::store_changes($dom,$confname,$prefs_order,\@actions,
626: $prefs,$values,\%changes,$crstype);
627: $r->print(&Apache::loncommon::confirmwrapper($message));
1.4 raeburn 628: } else {
1.7 raeburn 629: if ($crstype eq 'Community') {
1.11 wenzelju 630: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to community configuration.")));
1.7 raeburn 631: } else {
1.11 wenzelju 632: $r->print(&Apache::loncommon::confirmwrapper(&mt("No changes made to course configuration.")));
1.7 raeburn 633: }
1.4 raeburn 634: }
635: if (keys(%disallowed) > 0) {
636: $r->print('<p>');
637: foreach my $item ('cloners','rolenames','feedback','discussion','localization') {
638: if (ref($disallowed{$item}) eq 'HASH') {
639: if (keys(%{$disallowed{$item}}) > 0) {
640: $r->print(&Apache::courseprefs::display_disallowed($item,$disallowed{$item},
1.7 raeburn 641: $prefs,$crstype));
1.4 raeburn 642: }
643: }
644: }
645: $r->print('</p>');
646: }
1.50 raeburn 647: if ($errors) {
648: $r->print('<p>'.$errors.'</p>');
649: }
1.4 raeburn 650: }
1.1 raeburn 651: $r->print('<p>');
1.4 raeburn 652: my $footer_text = 'Back to configuration display';
653: if ($context eq 'course') {
654: $footer_text = 'Back to display/edit settings';
655: }
1.33 raeburn 656: &print_footer($r,$phase,'display',$footer_text,\@actions,$container,$parm_permission);
1.1 raeburn 657: $r->print('</p>');
1.27 raeburn 658: return \%lastact;
1.1 raeburn 659: }
660:
661: sub display_settings {
1.3 raeburn 662: my ($r,$dom,$phase,$context,$prefs_order,$prefs,$values,$confname,$jscript,
1.33 raeburn 663: $allitems,$crstype,$container,$parm_permission) = @_;
1.1 raeburn 664: my %brcrumtext = &get_crumb_text();
665: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
666: &Apache::lonhtmlcommon::add_breadcrumb
667: ({href=>"javascript:changePage(document.$phase,'display')",
1.4 raeburn 668: text=>"Display/Edit Settings"});
1.30 raeburn 669: my $instcode;
670: if (ref($values) eq 'HASH') {
671: $instcode = $values->{'internal.coursecode'};
672: }
1.59 raeburn 673: &print_header($r,$phase,$context,$jscript,$container,$instcode,$dom,$confname,$values);
1.12 raeburn 674: my $divwidth = 900;
1.1 raeburn 675: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH') && (ref($values) eq 'HASH')) {
676: if (@actions > 0) {
677: my $rowsum = 0;
1.68 raeburn 678: my (%output,%rowtotal,@items,$got_check_uncheck,$got_change_secret);
1.1 raeburn 679: foreach my $item (@{$prefs_order}) {
680: if (grep(/^\Q$item\E$/,@actions)) {
681: push(@items,$item);
682: if ($context eq 'domain') {
1.29 raeburn 683: my $settings;
684: if (ref($values) eq 'HASH') {
685: $settings = $values->{$item};
686: }
1.32 raeburn 687: if (($item eq 'usersessions') || ($item eq 'ssl')) {
688: unless ($got_check_uncheck) {
689: $r->print('<script type="text/javascript">'."\n".
690: '// <![CDATA['."\n".
691: &Apache::loncommon::check_uncheck_jscript()."\n".
692: '// ]]>'."\n".
693: '</script>'."\n");
694: $got_check_uncheck = 1;
695: }
1.28 raeburn 696: } elsif ($item eq 'selfcreation') {
1.29 raeburn 697: if (ref($values) eq 'HASH') {
698: $settings = $values->{'usercreation'};
699: }
700: } elsif ($item eq 'defaults') {
701: if (ref($values->{'inststatus'}) eq 'HASH') {
702: if (ref($values->{'defaults'}) eq 'HASH') {
703: $settings = {%{$values->{'inststatus'}},%{$values->{'defaults'}}};
704: } else {
705: $settings = $values->{'inststatus'};
706: }
707: } else {
708: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
709: my $inststatus = {
710: inststatustypes => $usertypes,
711: inststatusorder => $types,
712: inststatusguest => [],
713: };
714: if (ref($values->{defaults}) eq 'HASH') {
715: $settings = {%{$inststatus},%{$values->{'defaults'}}};
716: } else {
717: $settings = $inststatus;
718: }
719: }
1.68 raeburn 720: } elsif (($item eq 'lti') || ($item eq 'ltitools')) {
721: unless ($got_change_secret) {
722: $r->print('<script type="text/javascript">'."\n".
723: '// <![CDATA['."\n".
724: &change_secret_js()."\n".
725: '// ]]>'."\n".
726: '</script>'."\n");
727: $got_change_secret = 1;
728: }
729: if ($item eq 'lti') {
730: if (ref($values->{'ltisec'}) eq 'HASH') {
731: if (ref($values->{'lti'}) eq 'HASH') {
732: $settings = {%{$values->{'lti'}},%{$values->{'ltisec'}}};
733: } else {
734: $settings = $values->{'ltisec'};
735: }
736: } elsif (ref($values->{'lti'}) eq 'HASH') {
737: $settings = $values->{'lti'};
738: }
739: } elsif ($item eq 'ltitools') {
740: if (ref($values->{'toolsec'}) eq 'HASH') {
741: if (ref($values->{'ltitools'}) eq 'HASH') {
742: $settings = {%{$values->{'ltitools'}},%{$values->{'toolsec'}}};
743: } else {
744: $settings = $values->{'toolsec'};
745: }
1.58 raeburn 746: }
747: }
1.15 raeburn 748: }
1.1 raeburn 749: ($output{$item},$rowtotal{$item}) =
750: &Apache::domainprefs::print_config_box($r,$dom,$confname,
1.28 raeburn 751: $phase,$item,$prefs->{$item},$settings);
1.1 raeburn 752: } else {
1.68 raeburn 753: unless ($got_change_secret) {
754: $r->print('<script type="text/javascript">'."\n".
755: '// <![CDATA['."\n".
756: &change_secret_js()."\n".
757: '// ]]>'."\n".
758: '</script>'."\n");
759: $got_change_secret = 1;
760: }
1.1 raeburn 761: ($output{$item},$rowtotal{$item}) =
1.56 raeburn 762: &Apache::courseprefs::print_config_box($r,$dom,$confname,$phase,
1.33 raeburn 763: $item,$prefs->{$item},$values,$allitems,$crstype,$parm_permission);
1.1 raeburn 764: }
765: $rowsum += $rowtotal{$item};
766: }
767: }
1.12 raeburn 768: $r->print('<div id="prefs" style="max-width:'.$divwidth.'px;margin: 10px auto 10px auto;">');
1.1 raeburn 769: for (my $i=0; $i<@items; $i++) {
770: $r->print($output{$items[$i]});
771: }
1.12 raeburn 772: $r->print('</div>');
1.33 raeburn 773: $r->print(&print_footer($r,$phase,'process','Save Changes',\@actions,$container,$parm_permission));
1.1 raeburn 774: } else {
775: $r->print('<input type="hidden" name="phase" value="" />'.
1.12 raeburn 776: '<span class="LC_error">'.&mt('No settings chosen').
777: '</span>');
1.1 raeburn 778: }
779: $r->print('</form>');
780: }
1.25 raeburn 781: if ($container) {
782: &Apache::lonparmset::endSettingsScreen($r);
783: }
1.1 raeburn 784: $r->print(&Apache::loncommon::end_page());
785: return;
786: }
787:
788: sub display_choices {
1.33 raeburn 789: my ($r,$phase,$context,$prefs_order,$prefs,$container,$parm_permission) = @_;
1.1 raeburn 790: if ($phase eq '') {
791: $phase = 'pickactions';
792: }
793: my %helphash;
1.20 www 794: &print_header($r,$phase,$context,undef,$container);
1.1 raeburn 795: $r->print('<script type="text/javascript">'."\n".
1.6 raeburn 796: '// <![CDATA['."\n".
1.1 raeburn 797: &Apache::loncommon::check_uncheck_jscript()."\n".
1.6 raeburn 798: '// ]]>'."\n".
1.12 raeburn 799: '</script>'."\n");
1.33 raeburn 800: my $heading = &mt('Settings to display/modify');
801: if (ref($parm_permission) eq 'HASH') {
802: unless ($parm_permission->{'process'}) {
803: $heading = &mt('Settings to display');
804: }
805: }
806: $r->print('<h3>'.$heading.'</h3>'.
1.13 raeburn 807: '<div><input type="button" value="'.&mt('check all').'" '.
1.1 raeburn 808: 'onclick="javascript:checkAll(document.pickactions.actions)"'.
809: ' />'.(' 'x2).
810: '<input type="button" value="'.&mt('uncheck all').'" '.
1.12 raeburn 811: 'onclick="javascript:uncheckAll(document.pickactions.actions)" />'.
812: "\n".
1.13 raeburn 813: '</div><div class="LC_left_float">');
1.12 raeburn 814: my ($numitems,$maxincol,$firstthird,$secondthird,$seconddiv,$thirddiv,$count);
1.1 raeburn 815: if (ref($prefs_order) eq 'ARRAY') {
816: $numitems = @{$prefs_order};
817: }
1.12 raeburn 818: my $numcols = 3;
819: $maxincol = int($numitems/$numcols);
820: if ($numitems%$numcols) {
821: $maxincol ++;
1.1 raeburn 822: }
1.14 raeburn 823: $firstthird = $maxincol;
824: $secondthird = $firstthird + $maxincol;
1.1 raeburn 825: $count = 0;
826: if ((ref($prefs_order) eq 'ARRAY') && (ref($prefs) eq 'HASH')) {
827: foreach my $item (@{$prefs_order}) {
828: $r->print('<h4>'.
829: &Apache::loncommon::help_open_topic($prefs->{$item}->{'help'}).
830: '<label><input type="checkbox" name="actions" value="'.$item.
831: '" /> '.&mt($prefs->{$item}->{'text'}).'</label></h4>');
832: $count ++;
1.12 raeburn 833: if ((!$seconddiv) && ($count >= $firstthird)) {
1.1 raeburn 834: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
835: $seconddiv = 1;
836: }
1.12 raeburn 837: if ((!$thirddiv) && ($count >= $secondthird)) {
838: $r->print('</div>'."\n".'<div class="LC_left_float">'."\n");
839: $thirddiv = 1;
1.13 raeburn 840: }
1.1 raeburn 841: }
842: }
1.49 raeburn 843: $r->print('</div><div style="padding:0;clear:both;margin:0;border:0"></div>');
1.33 raeburn 844: $r->print(&print_footer($r,$phase,'display','Display',undef,$container,$parm_permission));
1.1 raeburn 845: $r->print('</form>');
1.25 raeburn 846: if ($container) {
847: &Apache::lonparmset::endSettingsScreen($r);
848: }
1.1 raeburn 849: $r->print(&Apache::loncommon::end_page());
850: return;
851: }
852:
853: sub color_pick_js {
854: my $pjump_def = &Apache::lonhtmlcommon::pjump_javascript_definition();
855: my $output = <<"ENDCOL";
856:
857: $pjump_def
858:
859: function psub() {
1.21 www 860: modalWindow.close();
1.1 raeburn 861: if (document.parmform.pres_marker.value!='') {
862: if (document.parmform.pres_type.value!='') {
863: eval('document.display.'+
864: document.parmform.pres_marker.value+
865: '.value=document.parmform.pres_value.value;');
866: }
867: } else {
868: document.parmform.pres_value.value='';
869: document.parmform.pres_marker.value='';
870: }
871: }
872:
873: function get_id (span_id) {
874: if (document.getElementById) {
875: return document.getElementById(span_id);
876: }
877: if (document.all) {
878: return document.all[span_id];
879: }
880: return false;
881: }
882:
883: function colchg_span (span_id_str,new_color_item) {
884: var span_ref = get_id(span_id_str);
885: if (span_ref.style) { span_ref = span_ref.style; }
886: span_ref.background = new_color_item.value;
887: span_ref.backgroundColor = new_color_item.value;
888: span_ref.bgColor = new_color_item.value;
889: }
890:
891: ENDCOL
892: return $output;
893: }
894:
1.68 raeburn 895: sub ltisec_javascript {
896: my ($dom) = @_;
897: my %servers = &Apache::lonnet::get_servers($dom,'library');
898: my $primary = &Apache::lonnet::domain($dom,'primary');
899: my $course_servers = "'".join("','",keys(%servers))."'";
900: my $output = <<"ENDJS";
901:
902: function toggleLTIEncKey(form,context) {
903: var shownhosts = new Array();
904: var hiddenhosts = new Array();
905: var forcourse = new Array($course_servers);
906: var fromdomain = '$primary';
907: var crsradio;
908: if (context == 'ltisec') {
909: crsradio = form.elements['ltisec_crslinkprot'];
910: } else {
911: crsradio = form.elements['toolsec_crs'];
912: }
913: if (crsradio.length) {
914: for (var i=0; i<crsradio.length; i++) {
915: if (crsradio[i].checked) {
916: if (crsradio[i].value == 1) {
917: if (forcourse.length > 0) {
918: for (var j=0; j<forcourse.length; j++) {
919: if (!shownhosts.includes(forcourse[j])) {
920: shownhosts.push(forcourse[j]);
921: }
922: }
923: }
924: } else {
925: if (forcourse.length > 0) {
926: for (var j=0; j<forcourse.length; j++) {
927: if (!hiddenhosts.includes(forcourse[j])) {
928: hiddenhosts.push(forcourse[j]);
929: }
930: }
931: }
932: }
933: }
934: }
935: }
936: var domradio;
937: if (context == 'ltisec') {
938: domradio = form.elements['ltisec_domlinkprot'];
939: } else {
940: domradio = form.elements['toolsec_dom'];
941: }
942: if (domradio.length) {
943: for (var i=0; i<domradio.length; i++) {
944: if (domradio[i].checked) {
945: if (domradio[i].value == 1) {
946: if (!shownhosts.includes(fromdomain)) {
947: shownhosts.push(fromdomain);
948: }
949: } else {
950: if (!hiddenhosts.includes(fromdomain)) {
951: hiddenhosts.push(fromdomain);
952: }
953: }
954: }
955: }
956: }
957: if (context == 'ltisec') {
958: var consumersradio = form.elements['ltisec_consumers'];
959: if (consumersradio.length) {
960: for (var i=0; i<consumersradio.length; i++) {
961: if (consumersradio[i].checked) {
962: if (consumersradio[i].value == 1) {
963: if (!shownhosts.includes(fromdomain)) {
964: shownhosts.push(fromdomain);
965: }
966: } else {
967: if (!hiddenhosts.includes(fromdomain)) {
968: hiddenhosts.push(fromdomain);
969: }
970: }
971: }
972: }
973: }
974: }
975: if (shownhosts.length > 0) {
976: for (var i=0; i<shownhosts.length; i++) {
977: if (document.getElementById(context+'_info_'+shownhosts[i])) {
978: document.getElementById(context+'_info_'+shownhosts[i]).style.display = 'block';
979: }
980: }
981: if (document.getElementById(context+'_noprivkey')) {
982: document.getElementById(context+'_noprivkey').style.display = 'none';
983: }
984: } else {
985: if (document.getElementById(context+'_noprivkey')) {
986: document.getElementById(context+'_noprivkey').style.display = 'inline-block';
987: }
988: }
989: if (hiddenhosts.length > 0) {
990: for (var i=0; i<hiddenhosts.length; i++) {
991: if (!shownhosts.includes(hiddenhosts[i])) {
992: if (document.getElementById(context+'_info_'+hiddenhosts[i])) {
993: document.getElementById(context+'_info_'+hiddenhosts[i]).style.display = 'none';
994: }
995: }
996: }
997: }
998: return;
999: }
1000:
1001: function togglePrivKey(form,context,hostid) {
1002: var radioname = '';
1003: var currdivid = '';
1004: var newdivid = '';
1005: if ((document.getElementById(context+'_divcurrprivkey_'+hostid)) &&
1006: (document.getElementById(context+'_divchgprivkey_'+hostid))) {
1007: currdivid = document.getElementById(context+'_divcurrprivkey_'+hostid);
1008: newdivid = document.getElementById(context+'_divchgprivkey_'+hostid);
1009: radioname = form.elements[context+'_changeprivkey_'+hostid];
1010: if (radioname) {
1011: if (radioname.length > 0) {
1012: var setvis;
1013: for (var i=0; i<radioname.length; i++) {
1014: if (radioname[i].checked == true) {
1015: if (radioname[i].value == 1) {
1016: newdivid.style.display = 'inline-block';
1017: currdivid.style.display = 'none';
1018: setvis = 1;
1019: }
1020: break;
1021: }
1022: }
1023: if (!setvis) {
1024: newdivid.style.display = 'none';
1025: currdivid.style.display = 'inline-block';
1026: }
1027: }
1028: }
1029: }
1030: return;
1031: }
1032:
1033: ENDJS
1034:
1035: }
1036:
1037: sub ltitools_javascript {
1038: my ($settings) = @_;
1039: my $togglejs = <itools_toggle_js();
1040: unless (ref($settings) eq 'HASH') {
1041: return $togglejs;
1042: }
1043: my (%ordered,$total,%jstext);
1044: $total = 0;
1045: foreach my $item (keys(%{$settings})) {
1046: if (ref($settings->{$item}) eq 'HASH') {
1047: my $num = $settings->{$item}{'order'};
1048: $ordered{$num} = $item;
1049: }
1050: }
1051: $total = scalar(keys(%{$settings}));
1052: my @jsarray = ();
1053: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
1054: push(@jsarray,$ordered{$item});
1055: }
1056: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
1057: return <<"ENDSCRIPT";
1058: <script type="text/javascript">
1059: // <![CDATA[
1060: function reorderLTITools(form,item) {
1061: var changedVal;
1062: $jstext
1063: var newpos = 'ltitools_add_pos';
1064: var maxh = 1 + $total;
1065: var current = new Array;
1066: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
1067: if (item == newpos) {
1068: changedVal = newitemVal;
1069: } else {
1070: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
1071: current[newitemVal] = newpos;
1072: }
1073: for (var i=0; i<ltitools.length; i++) {
1074: var elementName = 'ltitools_'+ltitools[i];
1075: if (elementName != item) {
1076: if (form.elements[elementName]) {
1077: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
1078: current[currVal] = elementName;
1079: }
1080: }
1081: }
1082: var oldVal;
1083: for (var j=0; j<maxh; j++) {
1084: if (current[j] == undefined) {
1085: oldVal = j;
1086: }
1087: }
1088: if (oldVal < changedVal) {
1089: for (var k=oldVal+1; k<=changedVal ; k++) {
1090: var elementName = current[k];
1091: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
1092: }
1093: } else {
1094: for (var k=changedVal; k<oldVal; k++) {
1095: var elementName = current[k];
1096: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
1097: }
1098: }
1099: return;
1100: }
1101:
1102: // ]]>
1103: </script>
1104:
1105: $togglejs
1106:
1107: ENDSCRIPT
1108: }
1109:
1110: sub ltitools_toggle_js {
1111: return <<"ENDSCRIPT";
1112: <script type="text/javascript">
1113: // <![CDATA[
1114:
1115: function toggleLTITools(form,setting,item) {
1116: var radioname = '';
1117: var divid = '';
1118: if ((setting == 'passback') || (setting == 'roster')) {
1119: radioname = 'ltitools_'+setting+'_'+item;
1120: divid = 'ltitools_'+setting+'time_'+item;
1121: var num = form.elements[radioname].length;
1122: if (num) {
1123: var setvis = '';
1124: for (var i=0; i<num; i++) {
1125: if (form.elements[radioname][i].checked) {
1126: if (form.elements[radioname][i].value == '1') {
1127: if (document.getElementById(divid)) {
1128: document.getElementById(divid).style.display = 'inline-block';
1129: }
1130: setvis = 1;
1131: }
1132: break;
1133: }
1134: }
1135: }
1136: if (!setvis) {
1137: if (document.getElementById(divid)) {
1138: document.getElementById(divid).style.display = 'none';
1139: }
1140: }
1141: }
1142: if (setting == 'user') {
1143: divid = 'ltitools_'+setting+'_div_'+item;
1144: var checkid = 'ltitools_'+setting+'_field_'+item;
1145: if (document.getElementById(divid)) {
1146: if (document.getElementById(checkid)) {
1147: if (document.getElementById(checkid).checked) {
1148: document.getElementById(divid).style.display = 'inline-block';
1149: } else {
1150: document.getElementById(divid).style.display = 'none';
1151: }
1152: }
1153: }
1154: }
1155: return;
1156: }
1157: // ]]>
1158: </script>
1159:
1160: ENDSCRIPT
1161: }
1162:
1.1 raeburn 1163: sub get_crumb_text {
1164: my %brcrumbtext = (
1165: domain => 'Domain Settings',
1.4 raeburn 1166: course => 'Display/Edit Settings',
1.1 raeburn 1167: );
1168: return %brcrumbtext;
1169: }
1170:
1.68 raeburn 1171: sub publishlogo {
1172: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,
1173: $savefileas,$modified) = @_;
1174: my ($output,$fname,$logourl,$madethumb);
1175: if ($action eq 'upload') {
1176: $fname=$env{'form.'.$formname.'.filename'};
1177: chop($env{'form.'.$formname});
1178: } else {
1179: ($fname) = ($formname =~ /([^\/]+)$/);
1180: }
1181: if ($savefileas ne '') {
1182: $fname = $savefileas;
1183: }
1184: $fname=&Apache::lonnet::clean_filename($fname);
1185: # See if there is anything left
1186: unless ($fname) { return ('error: no uploaded file'); }
1187: $fname="$subdir/$fname";
1188: my $docroot=$r->dir_config('lonDocRoot');
1189: my $filepath="$docroot/priv";
1190: my $relpath = "$dom/$confname";
1191: my ($fnamepath,$file,$fetchthumb);
1192: $file=$fname;
1193: if ($fname=~m|/|) {
1194: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
1195: }
1196: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1197: my $count;
1198: for ($count=5;$count<=$#parts;$count++) {
1199: $filepath.="/$parts[$count]";
1200: if ((-e $filepath)!=1) {
1201: mkdir($filepath,02770);
1202: }
1203: }
1204: # Check for bad extension and disallow upload
1205: if ($file=~/\.(\w+)$/ &&
1206: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1207: $output =
1208: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1209: } elsif ($file=~/\.(\w+)$/ &&
1210: !defined(&Apache::loncommon::fileembstyle($1))) {
1211: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
1212: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1213: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1214: } elsif (-d "$filepath/$file") {
1215: $output = &mt('Filename is a directory name - rename the file and re-upload');
1216: } else {
1217: my $source = $filepath.'/'.$file;
1218: my $logfile;
1219: if (!open($logfile,">>",$source.'.log')) {
1220: return (&mt('No write permission to Authoring Space'));
1221: }
1222: print $logfile
1223: "\n================= Publish ".localtime()." ================\n".
1224: $env{'user.name'}.':'.$env{'user.domain'}."\n";
1225: # Save the file
1226: if (!open(FH,">",$source)) {
1227: &Apache::lonnet::logthis('Failed to create '.$source);
1228: return (&mt('Failed to create file'));
1229: }
1230: if ($action eq 'upload') {
1231: if (!print FH ($env{'form.'.$formname})) {
1232: &Apache::lonnet::logthis('Failed to write to '.$source);
1233: return (&mt('Failed to write file'));
1234: }
1235: } else {
1236: my $original = &Apache::lonnet::filelocation('',$formname);
1237: if(!copy($original,$source)) {
1238: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
1239: return (&mt('Failed to write file'));
1240: }
1241: }
1242: close(FH);
1243: chmod(0660, $source); # Permissions to rw-rw---.
1244:
1245: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
1246: my $copyfile=$targetdir.'/'.$file;
1247:
1248: my @parts=split(/\//,$targetdir);
1249: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
1250: for (my $count=5;$count<=$#parts;$count++) {
1251: $path.="/$parts[$count]";
1252: if (!-e $path) {
1253: print $logfile "\nCreating directory ".$path;
1254: mkdir($path,02770);
1255: }
1256: }
1257: my $versionresult;
1258: if (-e $copyfile) {
1259: $versionresult = &logo_versioning($targetdir,$file,$logfile);
1260: } else {
1261: $versionresult = 'ok';
1262: }
1263: if ($versionresult eq 'ok') {
1264: if (copy($source,$copyfile)) {
1265: print $logfile "\nCopied original source to ".$copyfile."\n";
1266: $output = 'ok';
1267: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1268: if (ref($modified) eq 'ARRAY') {
1269: push(@{$modified},[$copyfile,$source]);
1270: }
1271: my $metaoutput =
1272: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
1273: } else {
1274: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
1275: $output = &mt('Failed to copy file to RES space').", $!";
1276: }
1277: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
1278: my $inputfile = $filepath.'/'.$file;
1279: my $outfile = $filepath.'/'.'tn-'.$file;
1280: my ($fullwidth,$fullheight) = &Apache::lonnet::check_dimensions($inputfile);
1281: if ($fullwidth ne '' && $fullheight ne '') {
1282: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
1283: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1284: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
1285: system({$args[0]} @args);
1286: chmod(0660, $filepath.'/tn-'.$file);
1287: if (-e $outfile) {
1288: my $copyfile=$targetdir.'/tn-'.$file;
1289: if (copy($outfile,$copyfile)) {
1290: print $logfile "\nCopied source to ".$copyfile."\n";
1291: my $thumb_metaoutput =
1292: &write_metadata($dom,$confname,$formname,
1293: $targetdir,'tn-'.$file,$logfile);
1294: if (ref($modified) eq 'ARRAY') {
1295: push(@{$modified},[$copyfile,$outfile]);
1296: }
1297: $madethumb = 1;
1298: } else {
1299: print $logfile "\nUnable to write ".$copyfile.
1300: ':'.$!."\n";
1301: }
1302: }
1303: }
1304: }
1305: }
1306: } else {
1307: $output = $versionresult;
1308: }
1309: }
1310: return ($output,$logourl,$madethumb);
1311: }
1312:
1313: sub logo_versioning {
1314: my ($targetdir,$file,$logfile) = @_;
1315: my $target = $targetdir.'/'.$file;
1316: my ($maxversion,$fn,$extn,$output);
1317: $maxversion = 0;
1318: if ($file =~ /^(.+)\.(\w+)$/) {
1319: $fn=$1;
1320: $extn=$2;
1321: }
1322: opendir(DIR,$targetdir);
1323: while (my $filename=readdir(DIR)) {
1324: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
1325: $maxversion=($1>$maxversion)?$1:$maxversion;
1326: }
1327: }
1328: $maxversion++;
1329: print $logfile "\nCreating old version ".$maxversion."\n";
1330: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
1331: if (copy($target,$copyfile)) {
1332: print $logfile "Copied old target to ".$copyfile."\n";
1333: $copyfile=$copyfile.'.meta';
1334: if (copy($target.'.meta',$copyfile)) {
1335: print $logfile "Copied old target metadata to ".$copyfile."\n";
1336: $output = 'ok';
1337: } else {
1338: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
1339: $output = &mt('Failed to copy old meta').", $!, ";
1340: }
1341: } else {
1342: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
1343: $output = &mt('Failed to copy old target').", $!, ";
1344: }
1345: return $output;
1346: }
1347:
1348: sub write_metadata {
1349: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
1350: my (%metadatafields,%metadatakeys,$output);
1351: $metadatafields{'title'}=$formname;
1352: $metadatafields{'creationdate'}=time;
1353: $metadatafields{'lastrevisiondate'}=time;
1354: $metadatafields{'copyright'}='public';
1355: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
1356: $env{'user.domain'};
1357: $metadatafields{'authorspace'}=$confname.':'.$dom;
1358: $metadatafields{'domain'}=$dom;
1359: {
1360: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
1361: my $mfh;
1362: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1363: foreach (sort(keys(%metadatafields))) {
1364: unless ($_=~/\./) {
1365: my $unikey=$_;
1366: $unikey=~/^([A-Za-z]+)/;
1367: my $tag=$1;
1368: $tag=~tr/A-Z/a-z/;
1369: print $mfh "\n\<$tag";
1370: foreach (split(/\,/,$metadatakeys{$unikey})) {
1371: my $value=$metadatafields{$unikey.'.'.$_};
1372: $value=~s/\"/\'\'/g;
1373: print $mfh ' '.$_.'="'.$value.'"';
1374: }
1375: print $mfh '>'.
1376: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
1377: .'</'.$tag.'>';
1378: }
1379: }
1380: $output = 'ok';
1381: print $logfile "\nWrote metadata";
1382: close($mfh);
1383: } else {
1384: print $logfile "\nFailed to open metadata file";
1385: $output = &mt('Could not write metadata');
1386: }
1387: }
1388: return $output;
1389: }
1390:
1391: sub change_secret_js {
1392: return <<"ENDSCRIPT";
1393: function toggleChgSecret(form,num,item,name) {
1394: var radioname = '';
1395: var currdivid = '';
1396: var newdivid = '';
1397: if ((document.getElementById(name+'_divcurr'+item+'_'+num)) &&
1398: (document.getElementById(name+'_divchg'+item+'_'+num))) {
1399: currdivid = document.getElementById(name+'_divcurr'+item+'_'+num);
1400: newdivid = document.getElementById(name+'_divchg'+item+'_'+num);
1401: radioname = form.elements[name+'_change'+item+'_'+num];
1402: if (radioname) {
1403: if (radioname.length > 0) {
1404: var setvis;
1405: for (var i=0; i<radioname.length; i++) {
1406: if (radioname[i].checked == true) {
1407: if (radioname[i].value == 1) {
1408: newdivid.style.display = 'inline-block';
1409: currdivid.style.display = 'none';
1410: setvis = 1;
1411: }
1412: break;
1413: }
1414: }
1415: if (!setvis) {
1416: newdivid.style.display = 'none';
1417: currdivid.style.display = 'inline-block';
1418: }
1419: }
1420: }
1421: }
1422: return;
1423: }
1424:
1425: function uncheckLinkProtMakeVis(name,item,num) {
1426: if (document.getElementById(name+'_'+item+'_'+num)) {
1427: var currtype = document.getElementById(name+'_'+item+'_'+num).type;
1428: if (currtype.toLowerCase() == 'checkbox') {
1429: document.getElementById(name+'_'+item+'_'+num).checked = false;
1430: }
1431: }
1432: return;
1433: }
1434: ENDSCRIPT
1435:
1436: }
1437:
1.1 raeburn 1438: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>