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