1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: lonextresedit.pm,v 1.8.2.4.4.2 2023/07/05 18:41:20 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::lonextresedit;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use HTML::Entities;
34: use Apache::lonlocal;
35: use Apache::lonnet;
36: use Apache::loncommon;
37: use Apache::lonhtmlcommon;
38: use Apache::lonuserstate;
39: use LONCAPA::map();
40: use LONCAPA qw(:DEFAULT :match);
41:
42: sub handler {
43: my $r=shift;
44: &Apache::loncommon::content_type($r,'text/html');
45: $r->send_http_header;
46:
47: return OK if $r->header_only;
48:
49: # Check for access
50: if (! &Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
51: $env{'user.error.msg'}=
52: $r->uri.":mdc:0:0:Cannot modify course content.";
53: return HTTP_NOT_ACCEPTABLE;
54: }
55:
56: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
57: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
58: my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
59: my ($supplementalflag,$updated,$output,$errormsg,$residx,$url,$title,
60: $symb,$type);
61: if (($env{'form.folderpath'} =~ /^supplemental/) && ($env{'form.suppurl'})) {
62: $supplementalflag = 1;
63: if (&unescape($env{'form.suppurl'}) =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
64: $type = 'tool';
65: }
66: }
67: if (($supplementalflag) || ($env{'form.symb'} =~ /^uploaded/)) {
68: ($updated,$output,$errormsg,$residx,$url,$title,$symb) =
69: &process_changes($supplementalflag,$cdom,$cnum,$chome);
70: if ($supplementalflag) {
71: if ($url ne &unescape($env{'form.suppurl'})) {
72: $env{'form.suppurl'} = $url;
73: }
74: if ($title ne $env{'form.title'}) {
75: $env{'form.title'} = $title;
76: }
77: $env{'form.idx'} = $residx;
78: } else {
79: if ($symb ne $env{'form.symb'}) {
80: $env{'form.symb'} = $symb;
81: }
82: if ($url =~ m{/adm/$cdom/$cnum/\d+/ext\.tool$}) {
83: $type = 'tool';
84: }
85: }
86: } else {
87: $errormsg = &mt('Information about external resource to edit is missing.');
88: }
89: if ($updated) {
90: my $msg = &mt('External Resource updated');
91: if ($type eq 'tool') {
92: $msg = &mt('External Tool updated');
93: }
94: $output = &Apache::lonhtmlcommon::confirm_success($msg);
95: }
96: if ($errormsg) {
97: $errormsg = '<p class="LC_error">'.$errormsg.'</p>';
98: }
99: my %ltitools;
100: if ($type eq 'tool') {
101: my (%domtools,%crstools);
102: my %tooltypes = &Apache::loncommon::usable_exttools();
103: if ($tooltypes{'dom'}) {
104: %domtools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
105: }
106: if ($tooltypes{'crs'}) {
107: %crstools = &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
108: }
109: %ltitools = (
110: dom => \%domtools,
111: crs => \%crstools,
112: );
113: }
114: my $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
115: my $pathitem = '<input type="hidden" name="folderpath" value="'.
116: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
117: my $description = 'External Resource Editor';
118: if ($type eq 'tool') {
119: $description = 'External Tool Editor';
120: }
121: $r->print(&Apache::loncommon::start_page($description,$js).
122: '<div class="LC_left_float">'.
123: $output.
124: $errormsg.
125: &extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,
126: 'direct',$env{'form.symb'},$type,$cdom,$cnum,\%ltitools).
127: '</div>'.&Apache::loncommon::end_page());
128: return OK;
129: }
130:
131: sub process_changes {
132: my ($supplementalflag,$cdom,$cnum,$chome) = @_;
133: my ($folder,$container,$output,$errormsg,$updated,$symb,$oldidx,$oldurl,$type,
134: $oldtitle,$newidx,$newurl,$newtitle,$residx,$url,$title,$marker,$args);
135: if ($env{'form.symb'}) {
136: $symb = $env{'form.symb'};
137: (my $map,$oldidx,$oldurl)=&Apache::lonnet::decode_symb($symb);
138: if ($map =~ m{^uploaded/$cdom/$cnum/(default(_\d+|))\.(sequence|page)$}) {
139: $folder = $1;
140: $container = $3;
141: }
142: $oldtitle = &Apache::lonnet::gettitle($env{'form.symb'});
143: if ($oldurl =~ m{^ext/(.+)$}) {
144: my $external = $1;
145: if ($external =~ m{^https://}) {
146: $oldurl = $external;
147: } else {
148: $oldurl = 'http://'.$oldurl;
149: }
150: $type = 'ext';
151: } else {
152: $type = 'tool';
153: }
154: } elsif ($env{'form.folderpath'}) {
155: $folder = &unescape( (split('&',$env{'form.folderpath'}))[-2] );
156: $oldurl = &unescape($env{'form.suppurl'});
157: $oldtitle = &unescape($env{'form.title'});
158: $container = 'sequence';
159: $supplementalflag = 1;
160: if ($oldurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
161: $type = 'tool';
162: } else {
163: $type = 'ext';
164: }
165: }
166: $url = $oldurl;
167: $title = $oldtitle;
168: if ($env{'form.importdetail'}) {
169: ($newtitle,$newurl,$newidx) =
170: map {&unescape($_)} split(/\=/,$env{'form.importdetail'});
171: if ($newurl =~ m{^(/adm/$cdom/$cnum/(\d+)/ext\.tool)\:?(.*)$}) {
172: $newurl = $1;
173: $marker = $2;
174: $args = $3;
175: if ((!$symb) && (!$supplementalflag)) {
176: $symb = "uploaded/$cdom/$cnum/$folder.$container"."___$newidx"."___adm/$cdom/$cnum/$marker/ext.tool";
177: }
178: }
179: }
180: if ($supplementalflag) {
181: $residx = $newidx;
182: } else {
183: $residx = $oldidx;
184: }
185: if ($folder && $container) {
186: if ($env{'form.importdetail'}) {
187: my ($errtext,$fatal,$mismatchedid,$needreload,$newgradable,@imports);
188: if (!$supplementalflag) {
189: if (($oldidx) && ($oldidx != $newidx)) {
190: $mismatchedid = 1;
191: }
192: }
193: if ($mismatchedid) {
194: $errormsg = 'Wrong item identifier';
195: } elsif (($newtitle eq $oldtitle) && ($newurl eq $oldurl)) {
196: if ($type eq 'tool') {
197: if ($args) {
198: ($updated,$newgradable,$errormsg) = &update_exttool($marker,$cdom,$cnum,
199: $supplementalflag,$args);
200: if ($updated) {
201: if ($newgradable) {
202: my $map = "/uploaded/$cdom/$cnum/$folder.$container";
203: my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
204: if ($fatal) {
205: $errormsg = &mt('Update failed: [_1].',$errtext);
206: } else {
207: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',
208: $newgradable,'string_yesno');
209: my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,1);
210: if ($errtext) {
211: $errormsg = &mt('Update failed: [_1].',$errtext);
212: } else {
213: $needreload = 1;
214: }
215: }
216: }
217: } else {
218: $output = &mt('No change');
219: }
220: } else {
221: $output = &mt('No change');
222: }
223: } else {
224: $output = &mt('No change');
225: }
226: } else {
227: my $map = "/uploaded/$cdom/$cnum/$folder.$container";
228: my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
229: if ($fatal) {
230: $errormsg = &mt('Update failed: [_1].',$errtext);
231: } else {
232: my $saveurl = &LONCAPA::map::qtunescape($newurl);
233: my $savetitle = &LONCAPA::map::qtunescape($newtitle);
234: my $ext = 'true';
235: if ($type eq 'tool') {
236: if ($args) {
237: ($updated,$newgradable,$errormsg) = &update_exttool($marker,$cdom,$cnum,
238: $supplementalflag,$args);
239: if ($newgradable) {
240: &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$newgradable,
241: 'string_yesno');
242: $needreload = 1;
243: }
244: }
245: $ext = 'false';
246: }
247: my $dotimeupdate;
248: unless ($supplementalflag) {
249: if (($newgradable) || ($newurl ne $oldurl)) {
250: $dotimeupdate = 1;
251: }
252: }
253: $LONCAPA::map::resources[$residx] =
254: join(':', ($savetitle,$saveurl,$ext,'normal','res'));
255: my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,$dotimeupdate);
256: if ($errtext) {
257: $errormsg = &mt('Update failed: [_1].',$errtext);
258: } else {
259: $updated = 1;
260: $title = $newtitle;
261: if ($newurl ne $oldurl) {
262: $url = $newurl;
263: if ($ext eq 'true') {
264: $newurl =~ s{^http://}{};
265: $newurl = "ext/$newurl";
266: }
267: }
268: if (!$supplementalflag) {
269: if ($newurl ne $oldurl) {
270: $symb = &Apache::lonnet::encode_symb($map,$residx,$newurl);
271: } else {
272: $symb = $env{'form.symb'};
273: if ($symb) {
274: &Apache::lonnet::devalidate_title_cache($symb);
275: }
276: }
277: $needreload = 1;
278: }
279: }
280: }
281: }
282: if ($needreload) {
283: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
284: if ($ferr) {
285: $errormsg = &mt('Reload failed: [_1].',$ferr);
286: } else {
287: unless ($supplementalflag) {
288: &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,
289: $cdom.'_'.$cnum);
290: }
291: }
292: }
293: if (($type eq 'tool') && ($newgradable)) {
294: my $uri = &Apache::lonnet::declutter($url);
295: &Apache::lonnet::devalidate_cache_new('meta',$uri);
296: }
297: } else {
298: $output = &mt('No change');
299: }
300: } else {
301: if ($type eq 'tool') {
302: $errormsg = &mt('Information about current external tool is incomplete.');
303: } else {
304: $errormsg = &mt('Information about current external resource is incomplete.');
305: }
306: }
307: return ($updated,$output,$errormsg,$residx,$url,$title,$symb);
308: }
309:
310: sub update_exttool {
311: my ($marker,$cdom,$cnum,$supplementalflag,$args) = @_;
312: my (%newhash,$changed,$newgradable,@deleted,$errormsg);
313: ($newhash{'target'},$newhash{'width'},$newhash{'height'},$newhash{'linktext'},$newhash{'explanation'},
314: $newhash{'crslabel'},$newhash{'crstitle'},$newhash{'crsappend'},$newhash{'gradable'}) = split(/:/,$args);
315: foreach my $item ('linktext','explanation','crslabel','crstitle','crsappend') {
316: $newhash{$item} = &unescape($newhash{$item});
317: }
318: my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
319: foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle','crsappend','gradable') {
320: $newhash{$item} =~ s/^\s+//;
321: $newhash{$item} =~ s/\s+$//;
322: if (($item eq 'width') || ($item eq 'height') || ($item eq 'linktext') || ($item eq 'explanation')) {
323: if ($newhash{'target'} eq 'iframe') {
324: $newhash{$item} = '';
325: } elsif ($newhash{'target'} eq 'tab') {
326: if (($item eq 'width') || ($item eq 'height')) {
327: $newhash{$item} = '';
328: }
329: }
330: } elsif ($item eq 'gradable') {
331: unless ($newhash{$item} == 1) {
332: $newhash{$item} = '';
333: }
334: }
335: if ($toolhash{$item} ne $newhash{$item}) {
336: if (($item eq 'gradable') && (!$supplementalflag)) {
337: if ($newhash{$item}) {
338: $newgradable = 'yes';
339: } else {
340: $newgradable = 'no';
341: }
342: }
343: if ($newhash{$item} eq '') {
344: unless (($item eq 'target') ||
345: ((($item eq 'width') || ($item eq 'height')) &&
346: (($newhash{'target'} eq 'window') ||
347: (($newhash{'target'} eq '') && ($toolhash{'target'} eq 'window')))) ||
348: ((($item eq 'linktext') || ($item eq 'explanation')) &&
349: ((($newhash{'target'} =~ /^(window|tab)$/)) ||
350: (($newhash{'target'} eq '') && ($toolhash{'target'} =~ /^(window|tab)$/))))) {
351: delete($toolhash{$item});
352: push(@deleted,$item);
353: $changed = 1;
354: }
355: } else {
356: $toolhash{$item} = $newhash{$item};
357: $changed = 1;
358: }
359: }
360: }
361: if ($changed) {
362: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$cdom,$cnum);
363: unless ($putres eq 'ok') {
364: $errormsg = &mt('Failed to save updated settings.').' '.&mt('Error: [_1].',$putres);
365: }
366: }
367: if (@deleted) {
368: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$cdom,$cnum);
369: }
370: return ($changed,$newgradable,$errormsg);
371: }
372:
373: sub extedit_form {
374: my ($supplementalflag,$residx,$orig_url,$orig_title,$pathitem,$helpitem,$caller,
375: $symb,$type,$cdom,$cnum,$ltitools,$disabled) = @_;
376: if ($type ne 'tool') {
377: $type = 'ext';
378: }
379: my %lt = &Apache::lonlocal::texthash(
380: ex => 'External Resource',
381: et => 'External Tool',
382: ed => 'Edit',
383: ee => 'External Resource Editor',
384: te => 'External Tool Editor',
385: pr => 'Preview',
386: sv => 'Save',
387: ul => 'URL',
388: ti => 'Title',
389: al => 'Add Link',
390: at => 'Add Tool',
391: dd => 'Defined in domain',
392: dc => 'Defined in course',
393: );
394: my $tabid = 'aa';
395: my $size = 60;
396: if ($supplementalflag) {
397: $tabid = 'ee';
398: }
399: my ($formname,$formid,$toggle,$fieldsetid,$urlid,$subdivid,$dispdivstyle,$dimendivstyle,
400: $windivstyle,$linktextstyle,$explanationstyle,$labelstyle,$titlestyle,
401: $appendstyle,$gradablestyle,$subdivstyle,$legend,$urlelem,$toolelem,%toolattr);
402: $formname = 'new'.$type;
403: $toggle = $type;
404: $fieldsetid = 'upload'.$type.'form';
405: $urlid = $type.'url';
406: map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight',
407: 'crstitlediv','crslabeldiv','crsappenddiv',
408: 'gradablediv','crstitle','crslabel','crsappend',
409: 'windiv','linktextdiv','explanationdiv',
410: 'linktext','explanation','providerurl');
411: $dispdivstyle = 'display:none';
412: $dimendivstyle = 'display:none';
413: $windivstyle = 'display:none';
414: $linktextstyle = 'display:none';
415: $explanationstyle = 'display:none';
416: $labelstyle = 'display:none';
417: $titlestyle = 'display:none';
418: $appendstyle = 'display:none';
419: $gradablestyle = 'display:none';
420: $subdivstyle = 'display:block';
421: if ($supplementalflag) {
422: $formname = 'newsupp'.$type;
423: $toggle = 'supp'.$type;
424: $fieldsetid = 'uploadsupp'.$type.'form';
425: $urlid = 'supp'.$type.'url';
426: map { $toolattr{$_} = 'supp'.$toolattr{$_}; } (keys(%toolattr));
427: }
428: my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,$crstitle,$crslabel,
429: $crsappend,$fieldsetstyle,$action,$hiddenelem,$form,$width,$height,$tooltarget,
430: $linktext,$explanation,$providerurl,$chkgrd,$chknogrd,%chkstate);
431: $fieldsetstyle = 'display: none;';
432: $action = '/adm/coursedocs';
433: my $protocol = ($ENV{'SERVER_PORT'} == 443?'https':'http');
434: my $rows = 2;
435: my $cols = 20;
436: if ($residx) {
437: if ($caller eq 'direct') {
438: $fieldsetstyle = 'display: block;';
439: $action = '/adm/extresedit';
440: $rows = 10;
441: $cols = 45;
442: if ($type eq 'tool') {
443: $legend = $lt{'te'};
444: } else {
445: $legend = $lt{'ee'};
446: }
447: $legend = '<legend>'.$legend.'</legend>';
448: if ($symb) {
449: $hiddenelem = '<input type="hidden" name="symb" value="'.$symb.'" />';
450: } elsif ($supplementalflag) {
451: $hiddenelem = '<input type="hidden" name="suppurl" value="'.
452: &HTML::Entities::encode(&escape($orig_url),'<>&"').'" />'."\n".
453: '<input type="hidden" name="title" value="'.
454: &HTML::Entities::encode(&escape($orig_title),'<>&"').'" />';
455: }
456: } else {
457: $link = '<a class="LC_docs_ext_edit" href="javascript:editext('."'$residx','$type'".');">'.$lt{'ed'}.'</a> '."\n";
458: $size = 40;
459: $active = '<input type="hidden" name="active" value="'.$tabid.'" />';
460: }
461: $formname = 'edit'.$type.'_'.$residx;
462: $fieldsetid = 'upload'.$type.$residx;
463: $urlid = $type.'url_'.$residx;
464: map { $toolattr{$_} .= '_'.$residx; } (keys(%toolattr));
465: $srcclass = ' class="LC_nobreak"';
466: if ($type eq 'ext') {
467: $extsrc = '<span class="LC_docs_ext_edit">'.$lt{'ul'}.' </span>';
468: $preview = ' <a class="LC_docs_ext_edit" href="javascript:extUrlPreview('."'$urlid','$protocol'".');">'.$lt{'pr'}.'</a>';
469: }
470: $title = '<span class="LC_docs_ext_edit">'.$lt{'ti'}.' </span>';
471: $save = $lt{'sv'};
472: } else {
473: $link = $lt{'ex'};
474: if ($type eq 'tool') {
475: $link = $lt{'et'};
476: }
477: $link = '<a class="LC_menubuttons_link" href="javascript:toggleUpload('."'$toggle'".');">'.$link.'</a>'.$helpitem;
478: if ($type eq 'tool') {
479: $legend = $lt{'te'};
480: } else {
481: $legend = $lt{'ee'};
482: }
483: $legend = '<legend>'.$legend.'</legend>';
484: $title = $lt{'ti'}.':<br />';
485: $residx = 0;
486: if ($type eq 'ext') {
487: $orig_url = 'http://';
488: $orig_title = $lt{'ex'};
489: $extsrc = $lt{'ul'}.':<br />';
490: $preview = '<input type="button" name="view" value="'.$lt{'pr'}.'" onclick="javascript:extUrlPreview('."'$urlid','$protocol'".');"'.$disabled.' />';
491: $save = $lt{'al'};
492: } else {
493: $orig_title = $lt{'et'};
494: $save = $lt{'at'};
495: $orig_url = "/adm/$cdom/$cnum/new/ext\.tool";
496: }
497: $pathitem .= '<br />';
498: }
499: $formid = $formname;
500: if ($type eq 'ext') {
501: $urlelem = '<input type="text" size="'.$size.'" name="exturl" id="'.$urlid.'" value="'.$orig_url.'"'.$disabled.' />';
502: } else {
503: my $class = 'LC_nobreak';
504: if ($residx) {
505: $class = 'LC_docs_ext_edit LC_nobreak';
506: if ($orig_url =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) {
507: my $marker = $1;
508: my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
509: my ($tooltype,$tool,$ltihash);
510: if ($toolhash{'id'} =~/^c(\d+)$/) {
511: $tool = $1;
512: $tooltype = 'crs';
513: if (ref($ltitools) eq 'HASH') {
514: if (ref($ltitools->{'crs'}) eq 'HASH') {
515: $ltihash = $ltitools->{'crs'}->{$tool};
516: }
517: }
518: } elsif ($toolhash{'id'} =~/^\d+$/) {
519: $tooltype = 'dom';
520: $tool = $toolhash{'id'};
521: if (ref($ltitools) eq 'HASH') {
522: if (ref($ltitools->{'dom'}) eq 'HASH') {
523: $ltihash = $ltitools->{'dom'}->{$tool};
524: }
525: }
526: }
527: if (($tool ne '') && (ref($ltihash) eq 'HASH')) {
528: my $tooltitle = $ltihash->{'title'};
529: my $icon = $ltihash->{'image'};
530: my $image;
531: if ($icon) {
532: $image = '<img src="'.$icon.'" alt="'.$tooltitle.'" />';
533: }
534: if ($ltihash->{'url'} =~ m{://}) {
535: (my $prot,my $host,$providerurl) = ($ltihash->{'url'} =~ m{^([^/]+)://([^/]+)(|/.+)$});
536: } else {
537: $providerurl = $ltihash->{'url'};
538: }
539: $tooltarget = $toolhash{'target'};
540: if ($tooltarget eq 'window') {
541: $dimendivstyle = 'display:block';
542: $windivstyle = 'display:block';
543: $chkstate{'window'} = 'checked="checked" ';
544: } elsif ($tooltarget eq 'tab') {
545: $windivstyle = 'display:block';
546: $chkstate{'tab'} = 'checked="checked" ';
547: } else {
548: $chkstate{'iframe'} = 'checked="checked" ';
549: }
550: $width = $toolhash{'width'};
551: $height = $toolhash{'height'};
552: $linktext = $toolhash{'linktext'};
553: $explanation = $toolhash{'explanation'};
554: if ($toolhash{'gradable'}) {
555: $chkgrd = ' checked="checked"';
556: } else {
557: $chknogrd = ' checked="checked"';
558: }
559: if (ref($ltihash->{'crsconf'}) eq 'HASH') {
560: if ($ltihash->{'crsconf'}->{'title'}) {
561: $crstitle = $toolhash{'crstitle'};
562: $titlestyle = 'display:inline';
563: }
564: if ($ltihash->{'crsconf'}->{'label'}) {
565: $crslabel = $toolhash{'crslabel'};
566: $labelstyle = 'display:inline';
567: }
568: if ($ltihash->{'crsconf'}->{'append'}) {
569: $crsappend = $toolhash{'crsappend'};
570: $appendstyle = 'display:inline';
571: }
572: if ($ltihash->{'crsconf'}->{'target'}) {
573: $dispdivstyle = 'display:block';
574: }
575: if ($ltihash->{'crsconf'}->{'linktext'}) {
576: $linktextstyle = 'padding:0;display:inline';
577: }
578: if ($ltihash->{'crsconf'}->{'explanation'}) {
579: $explanationstyle = 'padding:0;display:inline';
580: }
581: }
582: $toolelem = '<span class="LC_nobreak">'.$image.' '.$tooltitle.'</span><br />';
583: $gradablestyle = 'display:inline';
584: }
585: }
586: } else {
587: $subdivstyle = 'display:none';
588: my $toolradio = 'exttooltype';
589: my $exttypeon = 'LC_exttoolon';
590: my $exttypeoff = 'LC_exttooloff';
591: my $exttypeonsty = 'display:none';
592: my $exttypeoffsty = 'display:none';
593: my $exttypeofftext;
594: if ($supplementalflag) {
595: $toolradio = 'suppexttooltype';
596: $exttypeon = 'LC_exttoolonsupp';
597: $exttypeoff = 'LC_exttooloffsupp';
598: }
599: my ($numcrstools,$numdomtools,$typeclick,%defcheck,%typedesc);
600: %typedesc = (
601: crs => 'Defined in course',
602: dom => 'Defined in domain',
603: );
604: #FIXME need crstype
605: my $seloptions;
606: $subdivid = 'LC_addtool';
607: if ($supplementalflag) {
608: $subdivid = 'LC_addtoolsupp';
609: }
610: if (ref($ltitools) eq 'HASH') {
611: if (ref($ltitools->{'crs'}) eq 'HASH') {
612: $numcrstools = scalar(keys(%{$ltitools->{'crs'}}));
613: }
614: if (ref($ltitools->{'dom'}) eq 'HASH') {
615: $numdomtools = scalar(keys(%{$ltitools->{'dom'}}));
616: }
617: if ($numcrstools || $numdomtools) {
618: $typeclick = ' onclick="'.
619: 'javascript:updateExttoolSel(this.form,'."'$toolradio','$supplementalflag'".');"';
620: } else {
621: $exttypeoffsty = 'display:block';
622: $exttypeofftext = &mt('No external tools defined in either the domain or the course are available for selection.');
623: }
624: if ($numcrstools && !$numdomtools) {
625: $defcheck{'crs'} = ' checked="checked"';
626: $subdivstyle = 'display:block';
627: $exttypeonsty = 'display:block';
628: my $firstoption = '<option value="" selected="selected">'.&mt('Select').'</option>';
629: $seloptions = &ordered_tooloptions($ltitools->{'crs'});
630: if ($seloptions) {
631: $seloptions = "$firstoption\n$seloptions";
632: }
633: $exttypeofftext = &mt('No external tools defined in the domain are available for selection.');
634: } elsif (!$numcrstools && $numdomtools) {
635: $defcheck{'dom'} = ' checked="checked"';
636: $subdivstyle = 'display:block';
637: $exttypeonsty = 'display:block';
638: my $firstoption = '<option value="" selected="selected">'.&mt('Select').'</option>';
639: $seloptions = &ordered_tooloptions($ltitools->{'dom'});
640: if ($seloptions) {
641: $seloptions = "$firstoption\n$seloptions";
642: }
643: #FIXME need crstype
644: $exttypeofftext = &mt('No external tools defined in the course are available for selection.');
645: }
646: }
647: foreach my $type ('crs','dom') {
648: $toolelem .= '<span class="LC_nobreak"> <label>'.
649: '<input type="radio" name="'.$toolradio.'" value="'.$type.'"'.$defcheck{$type}.
650: $typeclick.$disabled.' />'.$typedesc{$type}.'</label></span> '."\n";
651: }
652: $toolelem .= '<div id="'.$exttypeon.'" style="'.$exttypeonsty.'">'.
653: '<select name="exttoolid" onchange="javascript:updateExttool(this,'.
654: 'this.form,'."'$supplementalflag'".');"'.$disabled.'>'."\n".
655: $seloptions.
656: '</select><br /></div>'."\n".
657: '<div id="'.$exttypeoff.'" style="'.$exttypeoffsty.'">'.
658: $exttypeofftext.
659: '<br /></div>'."\n";
660: $crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
661: $crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'};
662: $crsappend = '';
663: $chknogrd = ' checked="checked"';
664: }
665: $toolelem .= '<div id="'.$toolattr{'dispdiv'}.'" style="'.$dispdivstyle.'">'.
666: '<span class="'.$class.'">'.&mt('Display target:').' '.
667: '<label><input type="radio" name="exttooltarget" value="iframe" '.$chkstate{'iframe'}.'onclick="updateTooldim(this.form,'.
668: "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
669: '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('iframe').'</label>'.(' 'x2).
670: '<label><input type="radio" name="exttooltarget" value="tab" '.$chkstate{'tab'}.'onclick="updateTooldim(this.form,'.
671: "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
672: '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('tab').'</label>'.(' 'x2).
673: '<label><input type="radio" name="exttooltarget" value="window" '.$chkstate{'window'}.'onclick="updateTooldim(this.form,'.
674: "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
675: '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('window').'</label></span>'.
676: '<div id="'.$toolattr{'dimendiv'}.'" style="'.$dimendivstyle.'"><span class="'.$class.'">'.
677: &mt('Width').': <input type="text" size="4" id="'.$toolattr{'dimenwidth'}.'" name="exttoolwidth" value="'.$width.'"'.$disabled.' />'.(' 'x2).
678: &mt('Height').': <input type="text" size="4" id="'.$toolattr{'dimenheight'}.'" name="exttoolheight" value="'.$height.'"'.$disabled.' /></span>'."\n".
679: '</div></div>';
680: $toolelem .= '<div id="'.$toolattr{'windiv'}.'" style="'.$windivstyle.'">'.
681: '<div id="'.$toolattr{'linktextdiv'}.'" class="LC_left_float" style="'.$linktextstyle.'">'.
682: '<span class="'.$class.'">'.&mt('Link Text').'</span><br /><input type="text" size="25" id="'.$toolattr{'linktext'}.
683: '" name="exttoollinktext" value="'.$linktext.'"'.$disabled.' />'.
684: '</div><div id="'.$toolattr{'explanationdiv'}.'" class="LC_left_float" style="'.$explanationstyle.'">'.
685: '<span class="'.$class.'">'.&mt('Explanation').'</span><br />'.
686: '<textarea rows="'.$rows.'" cols="'.$cols.'" id="'.$toolattr{'explanation'}.'" name="exttoolexplanation" '.$disabled.'>'.
687: $explanation.'</textarea></div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
688: '</div>';
689: $toolelem .= '<div id="'.$toolattr{'crslabeldiv'}.'" style="'.$labelstyle.'">'.
690: '<span class="'.$class.'">'.&mt('Course label:').' '.
691: '<input type="text" id="'.$toolattr{'crslabel'}.'" name="exttoollabel" value="'.$crslabel.'"'.$disabled.' /></span><br />'.
692: '</div>'.
693: '<div id="'.$toolattr{'crstitlediv'}.'" style="'.$titlestyle.'">'.
694: '<span class="'.$class.'">'.&mt('Course title:').' '.
695: '<input type="text" id="'.$toolattr{'crstitle'}.'" name="exttooltitle" value="'.$crstitle.'"'.$disabled.' /></span><br />'.
696: '</div>'.
697: '<div id="'.$toolattr{'crsappenddiv'}.'" style="'.$appendstyle.'">'.
698: '<span class="'.$class.'">'.&mt('Append to URL[_1]',
699: '<span id="'.$toolattr{'providerurl'}.'"> ('.$providerurl.')<br /></span>').
700: '<input type="text" id="'.$toolattr{'crsappend'}.'" size="30" name="exttoolappend" value="'.$crsappend.'"'.$disabled.' /></span><br />'.
701: '</div>'.
702: '<div id="'.$toolattr{'gradablediv'}.'" style="'.$gradablestyle.'">'.
703: '<span class="'.$class.'">'.&mt('Gradable').' '.
704: '<label><input type="radio" name="exttoolgradable" value="1"'.$chkgrd.$disabled.
705: ' />'.&mt('Yes').'</label>'.(' 'x2).
706: '<label><input type="radio" name="exttoolgradable" value="0"'.$chknogrd.$disabled.
707: ' />'.&mt('No').'</label></span></div>';
708: }
709: my $chooser = $toolelem;
710: if ($type eq 'ext') {
711: $chooser = "
712: <div>
713: <span$srcclass>
714: $extsrc
715: $urlelem
716: $preview
717: </span>
718: </div>
719: ";
720: }
721: $form = <<ENDFORM;
722: <form action="$action" method="post" name="$formname" id="$formid">
723: <fieldset id="$fieldsetid" style="$fieldsetstyle">
724: $legend
725: $active
726: $chooser
727: <div id="$subdivid" style="$subdivstyle">
728: <span$srcclass>
729: $title
730: <input type="text" size="$size" name="exttitle" value="$orig_title" $disabled />
731: <input type="hidden" name="importdetail" value="" />
732: $pathitem
733: $hiddenelem
734: <input type="button" value="$save" onclick="javascript:setExternal(this.form,'$residx','$type','$orig_url','$supplementalflag');" $disabled />
735: </span>
736: </div>
737: </fieldset>
738: </form>
739: ENDFORM
740: if (wantarray) {
741: return ($link,$form);
742: } else {
743: return $link.$form;
744: }
745: }
746:
747: sub ordered_tooloptions {
748: my ($toolsref) = @_;
749: my ($seloptions,@ids,@titles);
750: if (ref($toolsref) eq 'HASH') {
751: my %bynum;
752: foreach my $id (keys(%{$toolsref})) {
753: if (ref($toolsref->{$id}) eq 'HASH') {
754: my $order = $toolsref->{$id}->{'order'};
755: $bynum{$order} = [$id,$toolsref->{$id}];
756: }
757: }
758: foreach my $item (sort { $a <=> $b } keys(%bynum)) {
759: if (ref($bynum{$item}) eq 'ARRAY') {
760: if (ref($bynum{$item}->[1]) eq 'HASH') {
761: my $tooltitle = $bynum{$item}->[1]->{'title'};
762: push(@titles,$tooltitle);
763: push(@ids,$bynum{$item}->[0]);
764: $seloptions .= '<option value="'.$bynum{$item}->[0].'">'.$tooltitle.'</option>'."\n";
765: }
766: }
767: }
768: }
769: if (wantarray) {
770: return (\@ids,\@titles);
771: } else {
772: return $seloptions;
773: }
774: }
775:
776: sub display_editor {
777: my ($url,$folderpath,$symb,$idx,$type,$cdom,$cnum,$hostname) = @_;
778: my ($residx,$supplementalflag,$title,$pathitem,$output,$js,$navmap);
779: if ($folderpath =~ /^supplemental/) {
780: $supplementalflag = 1;
781: $residx = $idx;
782: $title = &unescape($env{'form.title'});
783: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
784: } elsif ($symb =~ /^uploaded/) {
785: (my $map,$residx,my $res) =
786: &Apache::lonnet::decode_symb($symb);
787: $title = &Apache::lonnet::gettitle($symb);
788: my $path = &Apache::loncommon::symb_to_docspath($symb,\$navmap);
789: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($path,'<>&"').'" />';
790: }
791: my (%ltitools,%tooltypes);
792: if ($type eq 'tool') {
793: my (%domtools,%crstools);
794: %tooltypes = &Apache::loncommon::usable_exttools();
795: if ($tooltypes{'dom'}) {
796: %domtools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
797: }
798: if ($tooltypes{'crs'}) {
799: %crstools = &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
800: }
801: %ltitools = (
802: dom => \%domtools,
803: crs => \%crstools,
804: );
805: }
806: $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
807: my $args = { 'force_register' => $env{'form.register'} };
808: if ($hostname) {
809: $args->{'hostname'} = $hostname;
810: }
811: my $description = 'External Resource Editor';
812: if ($type eq 'tool') {
813: $description = 'External Tool Editor';
814: }
815: return &Apache::loncommon::start_page($description,$js,$args).
816: '<div class="LC_left_float">'.
817: &extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,'direct',
818: $symb,$type,$cdom,$cnum,\%ltitools).
819: '</div>'.
820: &Apache::loncommon::end_page();
821: }
822:
823: sub extedit_javascript {
824: my ($toolsref) = @_;
825: my ($toolsjs,$exttoolnums,$exttooloptions);
826: if (ref($toolsref) eq 'HASH') {
827: $toolsjs = " var ltitools = new Array();\n".
828: " var ltitoolsUrl = new Array();\n".
829: " var ltitoolsTarget = new Array();\n".
830: " var ltitoolsWidth = new Array();\n".
831: " var ltitoolsHeight = new Array();\n".
832: " var ltitoolsLinkDef = new Array();\n".
833: " var ltitoolsExplainDef = new Array();\n".
834: " var ltitoolsDisplay = new Array();\n".
835: " var ltitoolsLink = new Array();\n".
836: " var ltitoolsExplain = new Array();\n".
837: " var ltitoolsLabel = new Array();\n".
838: " var ltitoolsTitle = new Array();\n".
839: " var ltitoolsAppend = new Array();\n";
840: $exttoolnums = " var ltitoolsnum = new Array();\n".
841: " var tooloptval = new Array();\n".
842: " var toolopttxt = new Array();\n";
843: my $idx = 0;
844: foreach my $type ('crs','dom') {
845: if (ref($toolsref->{$type}) eq 'HASH') {
846: my $num = scalar(keys(%{$toolsref->{$type}}));
847: $toolsjs .= " ltitools[$idx] = new Array($num);\n".
848: " ltitoolsUrl[$idx] = new Array($num);\n".
849: " ltitoolsTarget[$idx] = new Array($num);\n".
850: " ltitoolsWidth[$idx] = new Array($num);\n".
851: " ltitoolsHeight[$idx] = new Array($num);\n".
852: " ltitoolsLinkDef[$idx] = new Array($num);\n".
853: " ltitoolsExplainDef[$idx] = new Array($num);\n".
854: " ltitoolsDisplay[$idx] = new Array($num);\n".
855: " ltitoolsLink[$idx] = new Array($num);\n".
856: " ltitoolsExplain[$idx] = new Array($num);\n".
857: " ltitoolsLabel[$idx] = new Array($num);\n".
858: " ltitoolsTitle[$idx] = new Array($num);\n".
859: " ltitoolsAppend[$idx] = new Array($num);\n";
860: my $i=0;
861: foreach my $key (sort { $a <=> $b } keys(%{$toolsref->{$type}})) {
862: if (ref($toolsref->{$type}->{$key}) eq 'HASH') {
863: if (ref($toolsref->{$type}->{$key}->{'display'}) eq 'HASH') {
864: my $target = $toolsref->{$type}->{$key}->{'display'}->{'target'};
865: my $width = $toolsref->{$type}->{$key}->{'display'}->{'width'};
866: my $height = $toolsref->{$type}->{$key}->{'display'}->{'height'};
867: my $linkdef = $toolsref->{$type}->{$key}->{'display'}->{'linktext'};
868: my $explaindef = $toolsref->{$type}->{$key}->{'display'}->{'explanation'};
869: my $providerurl;
870: if ($toolsref->{$type}->{$key}->{'url'} =~ m{://}) {
871: (my $prot,my $host,$providerurl) =
872: ($toolsref->{$type}->{$key}->{'url'} =~ m{^([^/]+)://([^/]+)(|/.+)$});
873: } else {
874: $providerurl = $toolsref->{$type}->{$key}->{'url'};
875: }
876: $providerurl = &LONCAPA::map::qtunescape($providerurl);
877: $toolsjs .= " ltitools[$idx][$i] = '$key';\n".
878: " ltitoolsTarget[$idx][$i] = '$target';\n".
879: " ltitoolsWidth[$idx][$i] = '$width';\n".
880: " ltitoolsHeight[$idx][$i] = '$height';\n".
881: " ltitoolsLinkDef[$idx][$i] = '$linkdef';\n".
882: " ltitoolsExplainDef[$idx][$i] = '$explaindef';\n".
883: " ltitoolsUrl[$idx][$i] = '$providerurl';\n";
884: }
885: if (ref($toolsref->{$type}->{$key}->{'crsconf'}) eq 'HASH') {
886: my $display = $toolsref->{$type}->{$key}->{'crsconf'}->{'target'};
887: $toolsjs .= " ltitoolsDisplay[$idx][$i] = '$display';\n";
888: my $linktext = $toolsref->{$type}->{$key}->{'crsconf'}->{'linktext'};
889: $toolsjs .= " ltitoolsLink[$idx][$i] = '$linktext';\n";
890: my $explanation = $toolsref->{$type}->{$key}->{'crsconf'}->{'explanation'};
891: $toolsjs .= " ltitoolsExplain[$idx][$i] = '$explanation';\n";
892: my $label = $toolsref->{$type}->{$key}->{'crsconf'}->{'label'};
893: $toolsjs .= " ltitoolsLabel[$idx][$i] = '$label';\n";
894: my $title = $toolsref->{$type}->{$key}->{'crsconf'}->{'title'};
895: $toolsjs .= " ltitoolsTitle[$idx][$i] = '$title';\n";
896: my $append = $toolsref->{$type}->{$key}->{'crsconf'}->{'append'};
897: $toolsjs .= " ltitoolsAppend[$idx][$i] = '$append';\n";
898: }
899: }
900: $i++;
901: }
902: my $firstoption = '<option value="" selected="selected">'.&mt('Select').'</option>';
903: my ($idsref,$titlesref) = &ordered_tooloptions($toolsref->{$type});
904: if ((ref($idsref) eq 'ARRAY') && (ref($titlesref) eq 'ARRAY')) {
905: my $count = scalar(@{$idsref});
906: $exttooloptions .= " tooloptval[$idx] = new Array($count);\n".
907: " toolopttxt[$idx] = new Array($count);\n";
908: for (my $n=0; $n<@{$idsref}; $n++) {
909: my $id = $idsref->[$n];
910: my $text = $titlesref->[$n];
911: $exttooloptions .= " tooloptval[$idx][$n] = '$id';\n".
912: " toolopttxt[$idx][$n] = '$text';\n";
913: }
914: }
915: $exttoolnums .= " ltitoolsnum[$idx] = $i;\n";
916: }
917: $idx ++;
918: }
919: }
920: my %js_lt = &Apache::lonlocal::texthash(
921: invurl => 'Invalid URL',
922: titbl => 'Title is blank',
923: invtool => 'Please select an external tool',
924: mixfra => 'Show preview in pop-up? (http in https page + no framing)',
925: mixonly => 'Show preview in pop-up? (http in https page)',
926: fraonly => 'Show preview in pop-up? (framing disallowed)',
927: nopopup => 'Pop-up blocked',
928: nopriv => 'Insufficient privileges to use preview',
929: badurl => 'URL is not: http://hostname/path or https://hostname/path',
930: sele => 'Select',
931: );
932: &js_escape(\%js_lt);
933:
934: my $urlregexp = <<'ENDREGEXP';
935: /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i
936: ENDREGEXP
937:
938: return <<ENDJS;
939:
940: var regexp = $urlregexp;
941:
942: function setExternal(extform,residx,type,exttoolurl,supplementalflag) {
943: var title=extform.exttitle.value;
944: if (!String.trim) {
945: String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");}; }
946: if (title == null || title.trim()=="") {
947: alert("$js_lt{'titbl'}");
948: extform.exttitle.focus();
949: return;
950: }
951: if (type == 'ext') {
952: var url=extform.exturl.value;
953: if (!regexp.test(url)) {
954: alert("$js_lt{'invurl'}");
955: extform.exturl.focus();
956: return;
957: } else {
958: url = escape(url);
959: title = escape(title);
960: if (residx > 0) {
961: eval("extform.importdetail.value=title+'='+url+'='+residx;extform.submit();");
962: } else {
963: eval("extform.importdetail.value=title+'='+url;extform.submit();");
964: }
965: }
966: } else {
967: title = escape(title);
968: var info = exttoolurl;
969: var prefix = '';
970: if (supplementalflag == 1) {
971: prefix = 'supp';
972: }
973: if (residx == 0) {
974: var toolid = parseInt(extform.exttoolid.options[extform.exttoolid.selectedIndex].value);
975: if (isNaN(toolid)) {
976: alert("$js_lt{'invtool'}");
977: return;
978: }
979: var typeelem = extform.elements[prefix+'exttooltype'];
980: if (typeelem.length) {
981: for (var i=0; i<typeelem.length; i++) {
982: if (typeelem[i].checked) {
983: tooltype = typeelem[i].value;
984: }
985: }
986: }
987: if (tooltype == 'crs') {
988: info += ':c'+toolid;
989: } else {
990: info += ':'+toolid;
991: }
992: }
993: var dispdiv = prefix+'tooldispdiv';
994: var windiv = prefix+'toolwindiv';
995: if (residx > 0) {
996: dispdiv += '_'+residx;
997: windiv += '_'+residx;
998: }
999: if (document.getElementById(dispdiv)) {
1000: if (document.getElementById(dispdiv).style.display == 'block') {
1001: if (extform.exttooltarget.length) {
1002: for (var i=0; i<extform.exttooltarget.length; i++) {
1003: if (extform.exttooltarget[i].checked) {
1004: if (extform.exttooltarget[i].value == 'window') {
1005: var width = extform.exttoolwidth.value;
1006: width.trim();
1007: var height = extform.exttoolheight.value;
1008: height.trim();
1009: info += ':window:'+width+':'+height;
1010: } else if (extform.exttooltarget[i].value == 'tab') {
1011: info += ':tab::';
1012: } else {
1013: info += ':iframe::';
1014: }
1015: }
1016: }
1017: }
1018: } else {
1019: info += ':::';
1020: }
1021: } else {
1022: info += ':::';
1023: }
1024: if (document.getElementById(windiv)) {
1025: if (document.getElementById(windiv).style.display == 'block') {
1026: var linktextdiv = prefix+'toollinktextdiv';
1027: var explanationdiv = prefix+'toolexplanationdiv';
1028: if (residx > 0) {
1029: linktextdiv += '_'+residx;
1030: explanationdiv += '_'+residx;
1031: }
1032: if (document.getElementById(linktextdiv).style.display == 'inline') {
1033: var linktext = extform.exttoollinktext.value;
1034: linktext.trim();
1035: info += ':'+escape(linktext);
1036: } else {
1037: info += ':';
1038: }
1039: if (document.getElementById(explanationdiv).style.display == 'inline') {
1040: var explaintext = extform.exttoolexplanation.value;
1041: explaintext.trim();
1042: info += ':'+escape(explaintext);
1043: } else {
1044: info += ':';
1045: }
1046: } else {
1047: info += '::';
1048: }
1049: } else {
1050: info += '::';
1051: }
1052: var labelinput = prefix+'toolcrslabel';
1053: var titleinput = prefix+'toolcrstitle';
1054: var appendinput = prefix+'toolcrsappend';
1055: if (residx > 0) {
1056: labelinput += '_'+residx;
1057: titleinput += '_'+residx;
1058: appendinput += '_'+residx;
1059: }
1060: if (document.getElementById(labelinput)) {
1061: var crslabel = document.getElementById(labelinput).value;
1062: crslabel.trim();
1063: info += ':'+escape(crslabel);
1064: } else {
1065: info += ':';
1066: }
1067: if (document.getElementById(titleinput)) {
1068: var crstitle = document.getElementById(titleinput).value;
1069: crstitle.trim();
1070: info += ':'+escape(crstitle);
1071: } else {
1072: info += ':';
1073: }
1074: if (document.getElementById(appendinput)) {
1075: var crsappend = document.getElementById(appendinput).value;
1076: crsappend.trim();
1077: info += ':'+escape(crsappend);
1078: } else {
1079: info += ':';
1080: }
1081: var gradablediv = prefix+'toolgradablediv';
1082: if (residx > 0) {
1083: gradablediv += '_'+residx;
1084: }
1085: if (document.getElementById(gradablediv)) {
1086: if (document.getElementById(gradablediv).style.display == 'inline') {
1087: if (extform.exttoolgradable.length) {
1088: for (var i=0; i<extform.exttoolgradable.length; i++) {
1089: if (extform.exttoolgradable[i].checked) {
1090: if (extform.exttoolgradable[i].value == '1') {
1091: info += ':1';
1092: } else {
1093: info += ':';
1094: }
1095: break;
1096: }
1097: }
1098: } else {
1099: info += ':';
1100: }
1101: } else {
1102: info += ':';
1103: }
1104: } else {
1105: info += ':';
1106: }
1107: info=escape(info);
1108: if (residx > 0) {
1109: eval("extform.importdetail.value=title+'='+info+'='+residx;extform.submit();");
1110: } else {
1111: eval("extform.importdetail.value=title+'='+info;extform.submit();");
1112: }
1113: }
1114: }
1115:
1116: function editext(residx,type) {
1117: if (document.getElementById('upload'+type+residx)) {
1118: var curr = document.getElementById('upload'+type+residx).style.display;
1119: if (curr == 'none') {
1120: disp = 'block';
1121: } else {
1122: disp = 'none';
1123: }
1124: document.getElementById('upload'+type+residx).style.display=disp;
1125: }
1126: resize_scrollbox('contentscroll','1','1');
1127: return;
1128: }
1129:
1130: function extUrlPreview(caller,protocol) {
1131: if (document.getElementById(caller)) {
1132: var url = document.getElementById(caller).value;
1133: if (regexp.test(url)) {
1134: var http_regex = /^http\:\/\//gi;
1135: var mixed = 0;
1136: var noiframe = 0;
1137: var nopriv = 0;
1138: var badurl = 0;
1139: var name = "externalpreview";
1140: if ((protocol == 'https') && (http_regex.test(url))) {
1141: mixed = 1;
1142: }
1143: var http = new XMLHttpRequest();
1144: var lcurl = "/adm/exturlcheck";
1145: var params = "exturl="+url;
1146: http.open("POST",lcurl, true);
1147: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
1148: http.onreadystatechange = function() {
1149: if (http.readyState == 4) {
1150: if (http.status == 200) {
1151: if (http.responseText.length > 0) {
1152: if (http.responseText == 1) {
1153: noiframe = 1;
1154: } else if (http.responseText == -1) {
1155: nopriv = 1;
1156: } else if (http.responseText == 0) {
1157: badurl = 1;
1158: }
1159: }
1160: openPreviewWindow(url,name,noiframe,mixed,nopriv,badurl);
1161: }
1162: }
1163: }
1164: http.send(params);
1165: } else {
1166: alert("$js_lt{'invurl'}");
1167: }
1168: }
1169: }
1170:
1171: var previewLCWindow = null;
1172: function openPreviewWindow(url,name,noiframe,mixed,nopriv,badurl) {
1173: if (previewLCWindow !=null) {
1174: previewLCWindow.close();
1175: }
1176: if (badurl) {
1177: alert("$js_lt{'badurl'}");
1178: } else if (nopriv) {
1179: alert("$js_lt{'nopriv'}");
1180: } else if ((noiframe == 1) || (mixed == 1)) {
1181: var encurl = encodeURI(url);
1182: var msg;
1183: if (mixed == 1) {
1184: if (noiframe == 1) {
1185: msg = "$js_lt{'mixfra'}";
1186: } else {
1187: msg = "$js_lt{'mixonly'}";
1188: }
1189: } else {
1190: msg = "$js_lt{'fraonly'}";
1191: }
1192: if (confirm(msg)) {
1193: previewLCWindow = window.open(url,name,"height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1");
1194: if (previewLCWindow != null) {
1195: previewLCWindow.focus();
1196: } else {
1197: alert("$js_lt{'nopopup'}");
1198: }
1199: }
1200: } else {
1201: openMyModal(url,500,400,'yes');
1202: }
1203: }
1204:
1205: function updateExttoolSel(form,radioname,supplementalflag) {
1206: var prefix = '';
1207: var typepick;
1208: var radelem = form.elements[radioname];
1209: if (radelem.length) {
1210: for (var i=0; i<radelem.length; i++) {
1211: if (radelem[i].checked) {
1212: if (radelem[i].value == 'crs') {
1213: typepick = 0;
1214: } else if (radelem[i].value == 'dom') {
1215: typepick = 1;
1216: }
1217: break;
1218: }
1219: }
1220: }
1221: if (supplementalflag == 1) {
1222: prefix = 'supp';
1223: }
1224: $exttoolnums
1225: $exttooloptions
1226: if ((typepick == 0) || (typepick == 1)) {
1227: var selelem = form.elements['exttoolid'];
1228: var i, numopts = selelem.options.length -1;
1229: if (numopts >=0) {
1230: for (i = numopts; i >= 0; i--) {
1231: selelem.remove(i);
1232: }
1233: }
1234: if (ltitoolsnum[typepick]) {
1235: if ((Array.isArray(tooloptval[typepick])) && (Array.isArray(toolopttxt[typepick]))) {
1236: var len = tooloptval[typepick].length;
1237: if (len) {
1238: selelem.options[selelem.options.length] = new Option('$js_lt{sele}','',1,1);
1239: var j;
1240: for (j=0; j<len; j++) {
1241: selelem.options[selelem.options.length] = new Option(toolopttxt[typepick][j],tooloptval[typepick][j]);
1242: }
1243: selelem.selectedIndex = 0;
1244: }
1245: }
1246: if (document.getElementById('LC_exttoolon'+prefix)) {
1247: document.getElementById('LC_exttoolon'+prefix).style.display = 'block';
1248: }
1249: if (document.getElementById('LC_exttooloff'+prefix)) {
1250: document.getElementById('LC_exttooloff'+prefix).style.display = 'none';
1251: }
1252: if (document.getElementById('LC_addtool'+prefix)) {
1253: document.getElementById('LC_addtool'+prefix).style.display = 'block';
1254: }
1255: } else {
1256: if (document.getElementById('LC_exttoolon'+prefix)) {
1257: document.getElementById('LC_exttoolon'+prefix).style.display = 'none';
1258: }
1259: if (document.getElementById('LC_exttooloff'+prefix)) {
1260: document.getElementById('LC_exttooloff'+prefix).style.display = 'block';
1261: }
1262: if (document.getElementById('LC_addtool'+prefix)) {
1263: document.getElementById('LC_addtool'+prefix).style.display = 'none';
1264: }
1265: }
1266: if (selelem.options.length == 0) {
1267: selelem.options[selelem.options.length] = new Option('','');
1268: selelem.selectedIndex = 0;
1269: }
1270: updateExttool(selelem,form,supplementalflag);
1271: resize_scrollbox('contentscroll','1','1');
1272: }
1273: return;
1274: }
1275:
1276: function updateExttool(caller,form,supplementalflag) {
1277: var prefix = '';
1278: if (supplementalflag == 1) {
1279: prefix = 'supp';
1280: }
1281: dispdiv = prefix+'tooldispdiv';
1282: dimendiv = prefix+'tooldimendiv';
1283: widthinput = prefix+'tooldimenwidth';
1284: heightinput = prefix+'tooldimenheight';
1285: labeldiv = prefix+'toolcrslabeldiv';
1286: titlediv = prefix+'toolcrstitlediv';
1287: appenddiv = prefix+'toolcrsappenddiv';
1288: gradablediv = prefix+'toolgradablediv';
1289: providerurl = prefix+'toolproviderurl';
1290: labelinput = prefix+'toolcrslabel';
1291: titleinput = prefix+'toolcrstitle';
1292: appendinput = prefix+'toolcrsappend';
1293: windiv = prefix+'toolwindiv';
1294: linktextdiv = prefix+'toollinktextdiv';
1295: linktextinput = prefix+'toollinktext';
1296: explanationdiv = prefix+'toolexplanationdiv';
1297: explanationinput = prefix+'toolexplanation';
1298: if (document.getElementById(dispdiv)) {
1299: var toolpick = caller.options[caller.selectedIndex].value;
1300: $toolsjs
1301: if (toolpick == '') {
1302: if (document.getElementById(dispdiv)) {
1303: document.getElementById(dispdiv).style.display = 'none';
1304: }
1305: if (document.getElementById(dimendiv)) {
1306: document.getElementById(dimendiv).style.display = 'none';
1307: }
1308: if (document.getElementById(windiv)) {
1309: document.getElementById(windiv).style.display = 'none';
1310: }
1311: if (document.getElementById(linktextdiv)) {
1312: document.getElementById(linktextdiv).style.display = 'none';
1313: }
1314: if (document.getElementById(explanationdiv)) {
1315: document.getElementById(explanationdiv).style.display = 'none';
1316: }
1317: if (document.getElementById(labeldiv)) {
1318: document.getElementById(labeldiv).style.display = 'none';
1319: }
1320: if (document.getElementById(titlediv)) {
1321: document.getElementById(titlediv).style.display = 'none';
1322: }
1323: if (document.getElementById(appenddiv)) {
1324: document.getElementById(appenddiv).style.display = 'none';
1325: }
1326: if (document.getElementById(gradablediv)) {
1327: document.getElementById(gradablediv).style.display = 'none';
1328: }
1329: } else {
1330: var tooltype = '';
1331: var typeelem = form.elements[prefix+'exttooltype'];
1332: if (typeelem.length) {
1333: for (var i=0; i<typeelem.length; i++) {
1334: if (typeelem[i].checked) {
1335: tooltype = typeelem[i].value;
1336: }
1337: }
1338: }
1339: if ((tooltype == 'crs') || (tooltype == 'dom')) {
1340: var i = 0;
1341: if (tooltype == 'dom') {
1342: i = 1;
1343: }
1344: if (ltitools[i].length > 0) {
1345: for (var j=0; j<ltitools[i].length; j++) {
1346: if (ltitools[i][j] == toolpick) {
1347: if (document.getElementById(dispdiv)) {
1348: if (ltitoolsDisplay[i][j]) {
1349: document.getElementById(dispdiv).style.display = 'block';
1350: if (form.exttooltarget.length) {
1351: for (var k=0; k<form.exttooltarget.length; k++) {
1352: if (form.exttooltarget[k].value == ltitoolsTarget[i][j]) {
1353: form.exttooltarget[k].checked = true;
1354: break;
1355: }
1356: }
1357: }
1358: }
1359: var dimen = 'none';
1360: var dimenwidth = '';
1361: var dimenheight = '';
1362: if ((ltitoolsDisplay[i][j]) && (ltitoolsTarget[i][j] == 'window')) {
1363: dimen = 'block';
1364: dimenwidth = ltitoolsWidth[i][j];
1365: dimenheight = ltitoolsHeight[i][j];
1366: }
1367: if (document.getElementById(dimendiv)) {
1368: document.getElementById(dimendiv).style.display = dimen;
1369: }
1370: if (document.getElementById(widthinput)) {
1371: document.getElementById(widthinput).value = dimenwidth;
1372: }
1373: if (document.getElementById(heightinput)) {
1374: document.getElementById(heightinput).value = dimenheight;
1375: }
1376: }
1377: if (document.getElementById(windiv)) {
1378: if ((ltitoolsTarget[i][j] == 'window') || (ltitoolsTarget[i][j] == 'tab')) {
1379: document.getElementById(windiv).style.display = 'block';
1380: } else {
1381: document.getElementById(windiv).style.display = 'none';
1382: }
1383: if (document.getElementById(linktextdiv)) {
1384: if (ltitoolsLink[i][j]) {
1385: document.getElementById(linktextdiv).style.display = 'inline';
1386: } else {
1387: document.getElementById(linktextdiv).style.display = 'none';
1388: }
1389: }
1390: if (document.getElementById(linktextinput)) {
1391: if (ltitoolsLink[i][j]) {
1392: document.getElementById(linktextinput).value = ltitoolsLinkDef[i][j];
1393: } else {
1394: document.getElementById(linktextinput).value = '';
1395: }
1396: }
1397: if (document.getElementById(explanationdiv)) {
1398: if (ltitoolsExplain[i][j]) {
1399: document.getElementById(explanationdiv).style.display = 'inline';
1400: } else {
1401: document.getElementById(explanationdiv).style.display = 'none';
1402: }
1403: }
1404: if (document.getElementById(explanationinput)) {
1405: if (ltitoolsExplain[i][j]) {
1406: document.getElementById(explanationinput).value = ltitoolsExplainDef[i][j];
1407: } else {
1408: document.getElementById(explananationinput).value = '';
1409: }
1410: }
1411: }
1412: if (document.getElementById(labeldiv)) {
1413: if (ltitoolsLabel[i][j]) {
1414: document.getElementById(labeldiv).style.display = 'inline';
1415: } else {
1416: document.getElementById(labeldiv).style.display = 'none';
1417: }
1418: }
1419: if (document.getElementById(titlediv)) {
1420: if (ltitoolsTitle[i][j]) {
1421: document.getElementById(titlediv).style.display = 'inline';
1422: } else {
1423: document.getElementById(titlediv).style.display = 'none';
1424: }
1425: }
1426: if (document.getElementById(appenddiv)) {
1427: if (ltitoolsAppend[i][j]) {
1428: document.getElementById(appenddiv).style.display = 'inline';
1429: if (document.getElementById(providerurl)) {
1430: if ((ltitoolsUrl[i][j] != '') && (ltitoolsUrl[i][j] != null)) {
1431: document.getElementById(providerurl).innerHTML = ' ('+ltitoolsUrl[i][j]+')<br />';
1432: }
1433: }
1434: } else {
1435: document.getElementById(appenddiv).style.display = 'none';
1436: if (document.getElementById(providerurl)) {
1437: document.getElementById(providerurl).innerHTML = '';
1438: }
1439: }
1440: }
1441: if (document.getElementById(gradablediv)) {
1442: if (supplementalflag != 1) {
1443: document.getElementById(gradablediv).style.display = 'inline';
1444: }
1445: }
1446: break;
1447: }
1448: }
1449: }
1450: }
1451: }
1452: }
1453: }
1454:
1455: function updateTooldim(form,dimendiv,windiv,widthinput,heightinput,linkinput,explaininput) {
1456: if (form.exttooltarget.length) {
1457: for (var i=0; i<form.exttooltarget.length; i++) {
1458: if (form.exttooltarget[i].checked) {
1459: var dimen = 'none';
1460: var linkconf = 'none';
1461: if (form.exttooltarget[i].value == 'window') {
1462: dimen = 'block';
1463: linkconf = 'block';
1464: } else {
1465: if (form.exttooltarget[i].value == 'tab') {
1466: linkconf = 'block';
1467: } else {
1468: if (document.getElementById(widthinput)) {
1469: document.getElementById(widthinput).value = '';
1470: }
1471: if (document.getElementById(heightinput)) {
1472: document.getElementById(heightinput).value = '';
1473: }
1474: if (document.getElementById(linkinput)) {
1475: document.getElementById(linkinput).value = '';
1476: }
1477: if (document.getElementById(explaininput)) {
1478: document.getElementById(explaininput).value = '';
1479: }
1480: }
1481: }
1482: if (document.getElementById(dimendiv)) {
1483: document.getElementById(dimendiv).style.display = dimen;
1484: }
1485: if (document.getElementById(windiv)) {
1486: document.getElementById(windiv).style.display = linkconf;
1487: }
1488: break;
1489: }
1490: }
1491: }
1492: }
1493:
1494: ENDJS
1495:
1496: }
1497:
1498: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>