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