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