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