Annotation of loncom/interface/lonextresedit.pm, revision 1.22
1.1 raeburn 1: # The LearningOnline Network
2: # Documents
3: #
1.22 ! raeburn 4: # $Id: lonextresedit.pm,v 1.21 2017/11/30 14:41:20 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: #
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'};
1.9 raeburn 59: my ($supplementalflag,$updated,$output,$errormsg,$residx,$url,$title,
60: $symb,$type);
1.5 raeburn 61: if (($env{'form.folderpath'} =~ /^supplemental/) && ($env{'form.suppurl'})) {
62: $supplementalflag = 1;
1.18 raeburn 63: if (&unescape($env{'form.suppurl'}) =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
1.9 raeburn 64: $type = 'tool';
65: }
1.7 raeburn 66: }
1.5 raeburn 67: if (($supplementalflag) || ($env{'form.symb'} =~ /^uploaded/)) {
1.7 raeburn 68: ($updated,$output,$errormsg,$residx,$url,$title,$symb) =
1.1 raeburn 69: &process_changes($supplementalflag,$cdom,$cnum,$chome);
70: if ($supplementalflag) {
1.9 raeburn 71: if ($url ne &unescape($env{'form.suppurl'})) {
1.1 raeburn 72: $env{'form.suppurl'} = $url;
73: }
74: if ($title ne $env{'form.title'}) {
75: $env{'form.title'} = $title;
76: }
1.5 raeburn 77: $env{'form.idx'} = $residx;
1.1 raeburn 78: } else {
79: if ($symb ne $env{'form.symb'}) {
80: $env{'form.symb'} = $symb;
81: }
1.18 raeburn 82: if ($url =~ m{/adm/$cdom/$cnum/\d+/ext\.tool$}) {
1.9 raeburn 83: $type = 'tool';
84: }
1.1 raeburn 85: }
86: } else {
87: $errormsg = &mt('Information about external resource to edit is missing.');
88: }
89: if ($updated) {
1.9 raeburn 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);
1.1 raeburn 95: }
96: if ($errormsg) {
97: $errormsg = '<p class="LC_error">'.$errormsg.'</p>';
98: }
1.9 raeburn 99: my %ltitools;
100: if ($type eq 'tool') {
1.21 raeburn 101: %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
1.9 raeburn 102: }
1.1 raeburn 103: my $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
104: my $pathitem = '<input type="hidden" name="folderpath" value="'.
105: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.9 raeburn 106: my $description = 'External Resource Editor';
107: if ($type eq 'tool') {
108: $description = 'External Tool Editor';
109: }
110: $r->print(&Apache::loncommon::start_page($description,$js).
1.1 raeburn 111: '<div class="LC_left_float">'.
112: $output.
113: $errormsg.
114: &extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,
1.9 raeburn 115: 'direct',$env{'form.symb'},$type,$cdom,$cnum,\%ltitools).
1.1 raeburn 116: '</div>'.&Apache::loncommon::end_page());
117: return OK;
118: }
119:
120: sub process_changes {
121: my ($supplementalflag,$cdom,$cnum,$chome) = @_;
1.9 raeburn 122: my ($folder,$container,$output,$errormsg,$updated,$symb,$oldidx,$oldurl,$type,
123: $oldtitle,$newidx,$newurl,$newtitle,$residx,$url,$title,$marker,$args);
1.1 raeburn 124: if ($env{'form.symb'}) {
125: $symb = $env{'form.symb'};
1.5 raeburn 126: (my $map,$oldidx,$oldurl)=&Apache::lonnet::decode_symb($symb);
1.1 raeburn 127: if ($map =~ m{^uploaded/$cdom/$cnum/(default(_\d+|))\.(sequence|page)$}) {
128: $folder = $1;
129: $container = $3;
130: }
131: $oldtitle = &Apache::lonnet::gettitle($env{'form.symb'});
1.9 raeburn 132: if ($oldurl =~ m{^ext/(.+)$}) {
133: my $external = $1;
134: if ($external =~ m{^https://}) {
135: $oldurl = $external;
136: } else {
137: $oldurl = 'http://'.$oldurl;
138: }
139: $type = 'ext';
140: } else {
141: $type = 'tool';
142: }
1.1 raeburn 143: } elsif ($env{'form.folderpath'}) {
144: $folder = &unescape( (split('&',$env{'form.folderpath'}))[-2] );
145: $oldurl = &unescape($env{'form.suppurl'});
146: $oldtitle = &unescape($env{'form.title'});
147: $container = 'sequence';
148: $supplementalflag = 1;
1.18 raeburn 149: if ($oldurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
1.9 raeburn 150: $type = 'tool';
1.5 raeburn 151: } else {
1.9 raeburn 152: $type = 'ext';
1.5 raeburn 153: }
154: }
155: $url = $oldurl;
156: $title = $oldtitle;
157: if ($env{'form.importdetail'}) {
158: ($newtitle,$newurl,$newidx) =
159: map {&unescape($_)} split(/\=/,$env{'form.importdetail'});
1.18 raeburn 160: if ($newurl =~ m{^(/adm/$cdom/$cnum/(\d+)/ext\.tool)\:?(.*)$}) {
1.9 raeburn 161: $newurl = $1;
162: $marker = $2;
163: $args = $3;
164: }
1.5 raeburn 165: }
166: if ($supplementalflag) {
167: $residx = $newidx;
168: } else {
169: $residx = $oldidx;
170: }
1.1 raeburn 171: if ($folder && $container) {
172: if ($env{'form.importdetail'}) {
1.5 raeburn 173: my ($errtext,$fatal,$mismatchedid,@imports);
174: if (!$supplementalflag) {
175: if (($oldidx) && ($oldidx != $newidx)) {
176: $mismatchedid = 1;
177: }
1.1 raeburn 178: }
179: if ($mismatchedid) {
180: $errormsg = 'Wrong item identifier';
181: } elsif (($newtitle eq $oldtitle) && ($newurl eq $oldurl)) {
1.9 raeburn 182: if ($type eq 'tool') {
183: if ($args) {
184: ($updated,$errormsg) = &update_exttool($marker,$cdom,$cnum,$args);
185: unless ($updated) {
186: $output = &mt('No change');
187: }
188: } else {
189: $output = &mt('No change');
190: }
191: } else {
192: $output = &mt('No change');
193: }
1.1 raeburn 194: } else {
195: my $map = "/uploaded/$cdom/$cnum/$folder.$container";
196: my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
197: if ($fatal) {
198: $errormsg = &mt('Update failed: [_1].',$errtext);
199: } else {
200: my $saveurl = &LONCAPA::map::qtunescape($newurl);
201: my $savetitle = &LONCAPA::map::qtunescape($newtitle);
1.9 raeburn 202: my $ext = 'true';
203: if ($type eq 'tool') {
204: if ($args) {
205: ($updated,$errormsg) = &update_exttool($marker,$cdom,$cnum,$args);
206: }
207: $ext = 'false';
208: }
1.1 raeburn 209: $LONCAPA::map::resources[$residx] =
1.9 raeburn 210: join(':', ($savetitle,$saveurl,$ext,'normal','res'));
1.1 raeburn 211: my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
212: if ($errtext) {
213: $errormsg = &mt('Update failed: [_1].',$errtext);
214: } else {
215: $updated = 1;
1.5 raeburn 216: $title = $newtitle;
217: if ($newurl ne $oldurl) {
218: $url = $newurl;
1.9 raeburn 219: if ($ext eq 'true') {
220: $newurl =~ s{^http://}{};
221: $newurl = "ext/$newurl";
222: }
1.5 raeburn 223: }
1.1 raeburn 224: if (!$supplementalflag) {
225: if ($newurl ne $oldurl) {
1.5 raeburn 226: $symb = &Apache::lonnet::encode_symb($map,$residx,$newurl);
1.1 raeburn 227: } else {
228: $symb = $env{'form.symb'};
229: if ($symb) {
230: &Apache::lonnet::devalidate_title_cache($symb);
231: }
232: }
233: }
1.5 raeburn 234: my ($furl,$ferr) =
235: &Apache::lonuserstate::readmap("$cdom/$cnum");
1.1 raeburn 236: if ($ferr) {
237: $errormsg = &mt('Reload failed: [_1].',$ferr);
238: } else {
1.5 raeburn 239: unless ($supplementalflag) {
240: &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
241: }
1.1 raeburn 242: }
243: }
244: }
245: }
246: } else {
247: $output = &mt('No change');
248: }
249: } else {
1.9 raeburn 250: if ($type eq 'tool') {
251: $errormsg = &mt('Information about current external tool is incomplete.');
252: } else {
253: $errormsg = &mt('Information about current external resource is incomplete.');
254: }
1.1 raeburn 255: }
1.5 raeburn 256: return ($updated,$output,$errormsg,$residx,$url,$title,$symb);
1.1 raeburn 257: }
258:
1.9 raeburn 259: sub update_exttool {
260: my ($marker,$cdom,$cnum,$args) = @_;
261: my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
1.10 raeburn 262: my (%newhash,$changed,@deleted,$errormsg);
1.16 raeburn 263: ($newhash{'target'},$newhash{'width'},$newhash{'height'},$newhash{'linktext'},$newhash{'explanation'},
1.20 raeburn 264: $newhash{'crslabel'},$newhash{'crstitle'},$newhash{'crsappend'}) = split(/:/,$args);
265: foreach my $item ('linktext','explanation','crslabel','crstitle','crsappend') {
1.16 raeburn 266: $newhash{$item} = &unescape($newhash{$item});
267: }
1.9 raeburn 268: my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
1.20 raeburn 269: foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle','crsappend') {
1.9 raeburn 270: $newhash{$item} =~ s/^\s+//;
271: $newhash{$item} =~ s/\s+$//;
1.16 raeburn 272: if (($item eq 'width') || ($item eq 'height') || ($item eq 'linktext') || ($item eq 'explanation')) {
1.9 raeburn 273: if ($newhash{'target'} eq 'iframe') {
274: $newhash{$item} = '';
1.19 raeburn 275: } elsif ($newhash{'target'} eq 'tab') {
276: if (($item eq 'width') || ($item eq 'height')) {
277: $newhash{$item} = '';
278: }
1.9 raeburn 279: }
280: }
281: if ($toolhash{$item} ne $newhash{$item}) {
282: if ($newhash{$item} eq '') {
1.10 raeburn 283: unless (($item eq 'target') ||
1.19 raeburn 284: ((($item eq 'width') || ($item eq 'height')) &&
1.10 raeburn 285: (($newhash{'target'} eq 'window') ||
1.19 raeburn 286: (($newhash{'target'} eq '') && ($toolhash{'target'} eq 'window')))) ||
287: ((($item eq 'linktext') || ($item eq 'explanation')) &&
288: ((($newhash{'target'} =~ /^(window|tab)$/)) ||
289: (($newhash{'target'} eq '') && ($toolhash{'target'} =~ /^(window|tab)$/))))) {
1.10 raeburn 290: delete($toolhash{$item});
291: push(@deleted,$item);
292: $changed = 1;
293: }
1.9 raeburn 294: } else {
295: $toolhash{$item} = $newhash{$item};
1.10 raeburn 296: $changed = 1;
1.9 raeburn 297: }
298: }
299: }
300: if ($changed) {
301: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$cdom,$cnum);
302: unless ($putres eq 'ok') {
1.10 raeburn 303: $errormsg = &mt('Failed to save updated settings.').' '.&mt('Error: [_1].',$putres);
1.9 raeburn 304: }
305: }
1.10 raeburn 306: if (@deleted) {
307: &Apache::lonnet::del('exttool_'.$marker,\@deleted,$cdom,$cnum);
308: }
1.9 raeburn 309: return ($changed,$errormsg);
310: }
311:
1.1 raeburn 312: sub extedit_form {
1.9 raeburn 313: my ($supplementalflag,$residx,$orig_url,$orig_title,$pathitem,$helpitem,$caller,
1.11 raeburn 314: $symb,$type,$cdom,$cnum,$ltitools,$disabled) = @_;
1.9 raeburn 315: if ($type ne 'tool') {
316: $type = 'ext';
317: }
1.1 raeburn 318: my %lt = &Apache::lonlocal::texthash(
319: ex => 'External Resource',
1.9 raeburn 320: et => 'External Tool',
1.1 raeburn 321: ed => 'Edit',
322: ee => 'External Resource Editor',
1.9 raeburn 323: te => 'External Tool Editor',
1.1 raeburn 324: pr => 'Preview',
325: sv => 'Save',
326: ul => 'URL',
327: ti => 'Title',
328: al => 'Add Link',
1.9 raeburn 329: at => 'Add Tool',
1.1 raeburn 330: );
331: my $tabid = 'aa';
332: my $size = 60;
333: if ($supplementalflag) {
334: $tabid = 'ee';
1.9 raeburn 335: }
336: my ($formname,$formid,$toggle,$fieldsetid,$urlid,$dispdivstyle,$dimendivstyle,
1.16 raeburn 337: $windivstyle,$linktextstyle,$explanationstyle,$labelstyle,$titlestyle,
1.20 raeburn 338: $appendstyle,$legend,$urlelem,$toolelem,%toolattr);
1.9 raeburn 339: $formname = 'new'.$type;
340: $toggle = $type;
341: $fieldsetid = 'upload'.$type.'form';
342: $urlid = $type.'url';
1.10 raeburn 343: map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight',
1.20 raeburn 344: 'crstitlediv','crslabeldiv','crsappenddiv',
345: 'crstitle','crslabel','crsappend','windiv',
346: 'linktextdiv','explanationdiv','linktext',
347: 'explanation','providerurl');
1.9 raeburn 348: $dispdivstyle = 'display:none';
349: $dimendivstyle = 'display:none';
1.16 raeburn 350: $windivstyle = 'display:none';
351: $linktextstyle = 'display:none';
352: $explanationstyle = 'display:none';
1.10 raeburn 353: $labelstyle = 'display:none';
354: $titlestyle = 'display:none';
1.20 raeburn 355: $appendstyle = 'display:none';
1.9 raeburn 356: if ($supplementalflag) {
357: $formname = 'newsupp'.$type;
358: $toggle = 'supp'.$type;
359: $fieldsetid = 'uploadsupp'.$type.'form';
360: $urlid = 'supp'.$type.'url';
361: map { $toolattr{$_} = 'supp'.$toolattr{$_}; } (keys(%toolattr));
1.1 raeburn 362: }
1.10 raeburn 363: my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,$crstitle,$crslabel,
1.20 raeburn 364: $crsappend,$fieldsetstyle,$action,$hiddenelem,$form,$width,$height,$tooltarget,
365: $linktext,$explanation,$providerurl,%chkstate);
1.1 raeburn 366: $fieldsetstyle = 'display: none;';
367: $action = '/adm/coursedocs';
1.14 raeburn 368: my $protocol = ($ENV{'SERVER_PORT'} == 443?'https':'http');
1.16 raeburn 369: my $rows = 2;
370: my $cols = 20;
1.1 raeburn 371: if ($residx) {
372: if ($caller eq 'direct') {
373: $fieldsetstyle = 'display: block;';
374: $action = '/adm/extresedit';
1.16 raeburn 375: $rows = 10;
376: $cols = 45;
1.9 raeburn 377: if ($type eq 'tool') {
378: $legend = $lt{'ee'};
379: } else {
380: $legend = $lt{'te'};
381: }
382: $legend = '<legend>'.$legend.'</legend>';
1.1 raeburn 383: if ($symb) {
384: $hiddenelem = '<input type="hidden" name="symb" value="'.$symb.'" />';
385: } elsif ($supplementalflag) {
386: $hiddenelem = '<input type="hidden" name="suppurl" value="'.
387: &HTML::Entities::encode(&escape($orig_url),'<>&"').'" />'."\n".
388: '<input type="hidden" name="title" value="'.
389: &HTML::Entities::encode(&escape($orig_title),'<>&"').'" />';
390: }
1.9 raeburn 391: } else {
392: $link = '<a class="LC_docs_ext_edit" href="javascript:editext('."'$residx','$type'".');">'.$lt{'ed'}.'</a> '."\n";
1.1 raeburn 393: $size = 40;
1.3 raeburn 394: $active = '<input type="hidden" name="active" value="'.$tabid.'" />';
1.1 raeburn 395: }
1.9 raeburn 396: $formname = 'edit'.$type.'_'.$residx;
397: $fieldsetid = 'upload'.$type.$residx;
398: $urlid = $type.'url_'.$residx;
399: map { $toolattr{$_} .= '_'.$residx; } (keys(%toolattr));
1.1 raeburn 400: $srcclass = ' class="LC_nobreak"';
1.9 raeburn 401: if ($type eq 'ext') {
402: $extsrc = '<span class="LC_docs_ext_edit">'.$lt{'ul'}.' </span>';
1.14 raeburn 403: $preview = ' <a class="LC_docs_ext_edit" href="javascript:extUrlPreview('."'$urlid','$protocol'".');">'.$lt{'pr'}.'</a>';
1.9 raeburn 404: }
1.1 raeburn 405: $title = '<span class="LC_docs_ext_edit">'.$lt{'ti'}.' </span>';
406: $save = $lt{'sv'};
407: } else {
1.9 raeburn 408: $link = $lt{'ex'};
409: if ($type eq 'tool') {
410: $link = $lt{'et'};
411: }
412: $link = '<a class="LC_menubuttons_link" href="javascript:toggleUpload('."'$toggle'".');">'.$link.'</a>'.$helpitem;
413: if ($type eq 'tool') {
414: $legend = $lt{'te'};
415: } else {
416: $legend = $lt{'ee'};
417: }
418: $legend = '<legend>'.$legend.'</legend>';
1.1 raeburn 419: $title = $lt{'ti'}.':<br />';
420: $residx = 0;
1.9 raeburn 421: if ($type eq 'ext') {
422: $orig_url = 'http://';
423: $orig_title = $lt{'ex'};
424: $extsrc = $lt{'ul'}.':<br />';
1.14 raeburn 425: $preview = '<input type="button" name="view" value="'.$lt{'pr'}.'" onclick="javascript:extUrlPreview('."'$urlid','$protocol'".');"'.$disabled.' />';
1.9 raeburn 426: $save = $lt{'al'};
427: } else {
428: $orig_title = $lt{'et'};
429: $save = $lt{'at'};
1.18 raeburn 430: $orig_url = "/adm/$cdom/$cnum/new/ext\.tool";
1.9 raeburn 431: }
1.1 raeburn 432: $pathitem .= '<br />';
433: }
1.9 raeburn 434: $formid = $formname;
435: if ($type eq 'ext') {
1.11 raeburn 436: $urlelem = '<input type="text" size="'.$size.'" name="exturl" id="'.$urlid.'" value="'.$orig_url.'"'.$disabled.' />';
1.9 raeburn 437: } else {
438: my $class = 'LC_nobreak';
439: if ($residx) {
440: $class = 'LC_docs_ext_edit LC_nobreak';
1.18 raeburn 441: if ($orig_url =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) {
1.9 raeburn 442: my $marker = $1;
443: my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
444: if ($toolhash{'id'}) {
445: if (ref($ltitools) eq 'HASH') {
446: if (keys(%{$ltitools})) {
447: if (ref($ltitools->{$toolhash{'id'}}) eq 'HASH') {
448: my $tooltitle = $ltitools->{$toolhash{'id'}}->{'title'};
449: my $icon = $ltitools->{$toolhash{'id'}}->{'image'};
450: my $image;
451: if ($icon) {
452: $image = '<img src="'.$icon.'" alt="'.$tooltitle.'" />';
453: }
1.20 raeburn 454: if ($ltitools->{$toolhash{'id'}}->{'url'} =~ m{://}) {
455: (my $prot,my $host,$providerurl) = ($ltitools->{$toolhash{'id'}}->{'url'} =~ m{^([^/]+)://([^/]+)(|/.+)$});
456: } else {
457: $providerurl = $ltitools->{$toolhash{'id'}}->{'url'};
458: }
1.9 raeburn 459: $tooltarget = $toolhash{'target'};
460: if ($tooltarget eq 'window') {
461: $dimendivstyle = 'display:block';
1.16 raeburn 462: $windivstyle = 'display:block';
1.9 raeburn 463: $chkstate{'window'} = 'checked="checked" ';
1.19 raeburn 464: } elsif ($tooltarget eq 'tab') {
465: $windivstyle = 'display:block';
466: $chkstate{'tab'} = 'checked="checked" ';
1.9 raeburn 467: } else {
468: $chkstate{'iframe'} = 'checked="checked" ';
469: }
470: $width = $toolhash{'width'};
471: $height = $toolhash{'height'};
1.16 raeburn 472: $linktext = $toolhash{'linktext'};
473: $explanation = $toolhash{'explanation'};
1.10 raeburn 474: if (ref($ltitools->{$toolhash{'id'}}->{'crsconf'}) eq 'HASH') {
475: if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'title'}) {
476: $crstitle = $toolhash{'crstitle'};
477: $titlestyle = 'display:inline';
478: }
479: if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'label'}) {
480: $crslabel = $toolhash{'crslabel'};
481: $labelstyle = 'display:inline';
482: }
1.20 raeburn 483: if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'append'}) {
484: $crsappend = $toolhash{'crsappend'};
485: $appendstyle = 'display:inline';
486: }
1.10 raeburn 487: if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'target'}) {
488: $dispdivstyle = 'display:block';
489: }
1.16 raeburn 490: if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'linktext'}) {
491: $linktextstyle = 'padding:0;display:inline';
492: }
493: if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'explanation'}) {
494: $explanationstyle = 'padding:0;display:inline';
495: }
1.10 raeburn 496: }
1.9 raeburn 497: $toolelem = '<span class="LC_nobreak">'.$image.' '.$tooltitle.'</span><br />';
498: }
499: }
500: }
501: }
502: }
503: } else {
504: $toolelem = '<span class="LC_docs_ext_edit">'."\n".
505: '<select name="exttoolid" id="LC_exttoolid" onchange="javascript:updateExttool(this,'.
1.11 raeburn 506: 'this.form,'."'$supplementalflag'".');"'.$disabled.'>'."\n".
1.9 raeburn 507: '<option value="" selected="selected">'.&mt('Select').'</option>';
508: my %bynum;
509: if (ref($ltitools) eq 'HASH') {
510: foreach my $id (keys(%{$ltitools})) {
511: if (ref($ltitools->{$id}) eq 'HASH') {
512: my $order = $ltitools->{$id}->{'order'};
513: $bynum{$order} = [$id,$ltitools->{$id}];
514: }
515: }
516: }
517: foreach my $item (sort { $a <=> $b } keys(%bynum)) {
518: if (ref($bynum{$item}) eq 'ARRAY') {
519: if (ref($bynum{$item}->[1]) eq 'HASH') {
520: my $tooltitle = $bynum{$item}->[1]->{'title'};
521: my $icon = $bynum{$item}->[1]->{'image'};
522: $toolelem .= '<option value="'.$bynum{$item}->[0].'">'.$tooltitle.'</option>';
523: }
524: }
525: }
1.10 raeburn 526: $toolelem .= '</select></span><br />';
527: $crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
528: $crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'};
1.20 raeburn 529: $crsappend = '';
1.9 raeburn 530: }
531: $toolelem .= '<div id="'.$toolattr{'dispdiv'}.'" style="'.$dispdivstyle.'">'.
532: '<span class="'.$class.'">'.&mt('Display target:').' '.
533: '<label><input type="radio" name="exttooltarget" value="iframe" '.$chkstate{'iframe'}.'onclick="updateTooldim(this.form,'.
1.16 raeburn 534: "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
535: '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('iframe').'</label>'.(' 'x2).
1.19 raeburn 536: '<label><input type="radio" name="exttooltarget" value="tab" '.$chkstate{'tab'}.'onclick="updateTooldim(this.form,'.
537: "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
538: '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('tab').'</label>'.(' 'x2).
1.9 raeburn 539: '<label><input type="radio" name="exttooltarget" value="window" '.$chkstate{'window'}.'onclick="updateTooldim(this.form,'.
1.16 raeburn 540: "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
541: '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('window').'</label></span>'.
542: '<div id="'.$toolattr{'dimendiv'}.'" style="'.$dimendivstyle.'"><span class="'.$class.'">'.
543: &mt('Width').': <input type="text" size="4" id="'.$toolattr{'dimenwidth'}.'" name="exttoolwidth" value="'.$width.'"'.$disabled.' />'.(' 'x2).
544: &mt('Height').': <input type="text" size="4" id="'.$toolattr{'dimenheight'}.'" name="exttoolheight" value="'.$height.'"'.$disabled.' /></span>'."\n".
545: '</div></div>';
546: $toolelem .= '<div id="'.$toolattr{'windiv'}.'" style="'.$windivstyle.'">'.
547: '<div id="'.$toolattr{'linktextdiv'}.'" class="LC_left_float" style="'.$linktextstyle.'">'.
548: '<span class="'.$class.'">'.&mt('Link Text').'</span><br /><input type="text" size="25" id="'.$toolattr{'linktext'}.
549: '" name="exttoollinktext" value="'.$linktext.'"'.$disabled.' />'.
550: '</div><div id="'.$toolattr{'explanationdiv'}.'" class="LC_left_float" style="'.$explanationstyle.'">'.
551: '<span class="'.$class.'">'.&mt('Explanation').'</span><br />'.
552: '<textarea rows="'.$rows.'" cols="'.$cols.'" id="'.$toolattr{'explanation'}.'" name="exttoolexplanation" '.$disabled.'>'.
553: $explanation.'</textarea></div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
554: '</div>';
555: $toolelem .= '<div id="'.$toolattr{'crslabeldiv'}.'" style="'.$labelstyle.'">'.
1.10 raeburn 556: '<span class="'.$class.'">'.&mt('Course label:').' '.
1.16 raeburn 557: '<input type="text" id="'.$toolattr{'crslabel'}.'" name="exttoollabel" value="'.$crslabel.'"'.$disabled.' /></span><br />'.
1.10 raeburn 558: '</div>'.
559: '<div id="'.$toolattr{'crstitlediv'}.'" style="'.$titlestyle.'">'.
560: '<span class="'.$class.'">'.&mt('Course title:').' '.
1.16 raeburn 561: '<input type="text" id="'.$toolattr{'crstitle'}.'" name="exttooltitle" value="'.$crstitle.'"'.$disabled.' /></span><br />'.
1.20 raeburn 562: '</div>'.
563: '<div id="'.$toolattr{'crsappenddiv'}.'" style="'.$appendstyle.'">'.
564: '<span class="'.$class.'">'.&mt('Append to URL[_1]',
565: '<span id="'.$toolattr{'providerurl'}.'"> ('.$providerurl.')<br /></span>').
1.22 ! raeburn 566: '<input type="text" id="'.$toolattr{'crsappend'}.'" size="30" name="exttoolappend" value="'.$crsappend.'"'.$disabled.' /></span><br />'.
1.10 raeburn 567: '</div>';
1.9 raeburn 568: }
569: my $chooser = $toolelem;
570: if ($type eq 'ext') {
571: $chooser = "
572: <div>
573: <span$srcclass>
574: $extsrc
575: $urlelem
576: $preview
577: </span>
578: </div>
579: ";
580: }
1.3 raeburn 581: $form = <<ENDFORM;
1.9 raeburn 582: <form action="$action" method="post" name="$formname" id="$formid">
1.2 raeburn 583: <fieldset id="$fieldsetid" style="$fieldsetstyle">
1.1 raeburn 584: $legend
585: $active
1.9 raeburn 586: $chooser
587: <div>
1.1 raeburn 588: <span$srcclass>
589: $title
1.11 raeburn 590: <input type="text" size="$size" name="exttitle" value="$orig_title" $disabled />
1.1 raeburn 591: <input type="hidden" name="importdetail" value="" />
592: $pathitem
593: $hiddenelem
1.13 raeburn 594: <input type="button" value="$save" onclick="javascript:setExternal(this.form,'$residx','$type','$orig_url','$supplementalflag');" $disabled />
1.1 raeburn 595: </span>
1.9 raeburn 596: </div>
1.1 raeburn 597: </fieldset>
598: </form>
599: ENDFORM
1.3 raeburn 600: if (wantarray) {
601: return ($link,$form);
602: } else {
603: return $link.$form;
604: }
1.1 raeburn 605: }
606:
607: sub display_editor {
1.15 raeburn 608: my ($url,$folderpath,$symb,$idx,$type,$cdom,$cnum,$hostname) = @_;
1.12 raeburn 609: my ($residx,$supplementalflag,$title,$pathitem,$output,$js,$navmap);
1.1 raeburn 610: if ($folderpath =~ /^supplemental/) {
611: $supplementalflag = 1;
612: $residx = $idx;
613: $title = &unescape($env{'form.title'});
614: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
615: } elsif ($symb =~ /^uploaded/) {
616: (my $map,$residx,my $res) =
617: &Apache::lonnet::decode_symb($symb);
618: $title = &Apache::lonnet::gettitle($symb);
1.12 raeburn 619: my $path = &Apache::loncommon::symb_to_docspath($symb,\$navmap);
1.4 raeburn 620: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($path,'<>&"').'" />';
1.1 raeburn 621: }
1.9 raeburn 622: my %ltitools;
623: if ($type eq 'tool') {
1.21 raeburn 624: %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
1.9 raeburn 625: }
626: $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
1.1 raeburn 627: my $args = { 'force_register' => $env{'form.register'} };
1.15 raeburn 628: if ($hostname) {
629: $args->{'hostname'} = $hostname;
630: }
1.9 raeburn 631: my $description = 'External Resource Editor';
632: if ($type eq 'tool') {
633: $description = 'External Tool Editor';
634: }
635: return &Apache::loncommon::start_page($description,$js,$args).
1.1 raeburn 636: '<div class="LC_left_float">'.
1.9 raeburn 637: &extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,'direct',
638: $symb,$type,$cdom,$cnum,\%ltitools).
1.1 raeburn 639: '</div>'.
640: &Apache::loncommon::end_page();
641: }
642:
643: sub extedit_javascript {
1.9 raeburn 644: my ($toolsref) = @_;
645: my $toolsjs;
646: if (ref($toolsref) eq 'HASH') {
647: my $num = scalar(keys(%{$toolsref}));
648: $toolsjs = " var ltitools = new Array($num);\n".
1.20 raeburn 649: " var ltitoolsUrl = new Array($num);\n".
1.9 raeburn 650: " var ltitoolsTarget = new Array($num);\n".
651: " var ltitoolsWidth = new Array($num);\n".
1.10 raeburn 652: " var ltitoolsHeight = new Array($num);\n".
1.16 raeburn 653: " var ltitoolsLinkDef = new Array($num);\n".
654: " var ltitoolsExplainDef = new Array($num);\n".
1.10 raeburn 655: " var ltitoolsDisplay = new Array($num);\n".
1.16 raeburn 656: " var ltitoolsLink = new Array($num);\n".
657: " var ltitoolsExplain = new Array($num);\n".
1.10 raeburn 658: " var ltitoolsLabel = new Array($num);\n".
659: " var ltitoolsTitle = new Array($num);\n";
1.20 raeburn 660: " var ltitoolsAppend = new Array($num);\n";
1.9 raeburn 661: my $i = 0;
662: foreach my $key (sort { $a <=> $b } keys(%{$toolsref})) {
1.16 raeburn 663: if (ref($toolsref->{$key}) eq 'HASH') {
664: if (ref($toolsref->{$key}->{'display'}) eq 'HASH') {
665: my $target = $toolsref->{$key}->{'display'}->{'target'};
666: my $width = $toolsref->{$key}->{'display'}->{'width'};
667: my $height = $toolsref->{$key}->{'display'}->{'height'};
668: my $linkdef = $toolsref->{$key}->{'display'}->{'linktext'};
669: my $explaindef = $toolsref->{$key}->{'display'}->{'explanation'};
1.20 raeburn 670: my $providerurl;
671: if ($toolsref->{$key}->{'url'} =~ m{://}) {
672: (my $prot,my $host,$providerurl) = ($toolsref->{$key}->{'url'} =~ m{^([^/]+)://([^/]+)(|/.+)$});
673: } else {
674: $providerurl = $toolsref->{$key}->{'url'};
675: }
1.22 ! raeburn 676: $providerurl = &LONCAPA::map::qtunescape($providerurl);
1.16 raeburn 677: $toolsjs .= ' ltitools['.$i.'] = '."'$key';\n".
678: ' ltitoolsTarget['.$i.'] = '."'$target';\n".
679: ' ltitoolsWidth['.$i.'] = '."'$width';\n".
680: ' ltitoolsHeight['.$i.'] = '."'$height';\n".
681: ' ltitoolsLinkDef['.$i.'] = '."'$linkdef';\n".
1.20 raeburn 682: ' ltitoolsExplainDef['.$i.'] = '."'$explaindef';\n".
683: ' ltitoolsUrl['.$i.'] = '."'$providerurl';\n";
1.16 raeburn 684: }
1.10 raeburn 685: if (ref($toolsref->{$key}->{'crsconf'}) eq 'HASH') {
686: my $display = $toolsref->{$key}->{'crsconf'}->{'target'};
687: $toolsjs .= ' ltitoolsDisplay['.$i.'] = '."'$display';\n";
1.16 raeburn 688: my $linktext = $toolsref->{$key}->{'crsconf'}->{'linktext'};
689: $toolsjs .= ' ltitoolsLink['.$i.'] = '."'$linktext';\n";
690: my $explanation = $toolsref->{$key}->{'crsconf'}->{'explanation'};
691: $toolsjs .= ' ltitoolsExplain['.$i.'] = '."'$explanation';\n";
1.10 raeburn 692: my $label = $toolsref->{$key}->{'crsconf'}->{'label'};
693: $toolsjs .= ' ltitoolsLabel['.$i.'] = '."'$label';\n";
694: my $title = $toolsref->{$key}->{'crsconf'}->{'title'};
695: $toolsjs .= ' ltitoolsTitle['.$i.'] = '."'$title';\n";
1.20 raeburn 696: my $append = $toolsref->{$key}->{'crsconf'}->{'append'};
697: $toolsjs .= ' ltitoolsAppend['.$i.'] = '."'$append';\n";
1.10 raeburn 698: }
1.20 raeburn 699:
1.9 raeburn 700: $i++;
701: }
702: }
703: }
1.8 damieng 704: my %js_lt = &Apache::lonlocal::texthash(
1.1 raeburn 705: invurl => 'Invalid URL',
706: titbl => 'Title is blank',
1.9 raeburn 707: invtool => 'Please select an external tool',
1.1 raeburn 708: );
1.8 damieng 709: &js_escape(\%js_lt);
1.1 raeburn 710:
711: my $urlregexp = <<'ENDREGEXP';
712: /^([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
713: ENDREGEXP
714:
715: return <<ENDJS;
716:
717: var regexp = $urlregexp;
718:
1.10 raeburn 719: function setExternal(extform,residx,type,exttoolurl,supplementalflag) {
1.1 raeburn 720: var title=extform.exttitle.value;
721: if (!String.trim) {
722: String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");}; }
723: if (title == null || title.trim()=="") {
1.8 damieng 724: alert("$js_lt{'titbl'}");
1.1 raeburn 725: extform.exttitle.focus();
726: return;
727: }
1.9 raeburn 728: if (type == 'ext') {
729: var url=extform.exturl.value;
730: if (!regexp.test(url)) {
731: alert("$js_lt{'invurl'}");
732: extform.exturl.focus();
733: return;
734: } else {
735: url = escape(url);
736: title = escape(title);
737: if (residx > 0) {
738: eval("extform.importdetail.value=title+'='+url+'='+residx;extform.submit();");
739: } else {
740: eval("extform.importdetail.value=title+'='+url;extform.submit();");
741: }
742: }
743: } else {
1.7 raeburn 744: title = escape(title);
1.9 raeburn 745: var info = exttoolurl;
746: if (residx == 0) {
747: var toolid = parseInt(extform.exttoolid.options[extform.exttoolid.selectedIndex].value);
748: if (isNaN(toolid)) {
749: alert("$js_lt{'invtool'}");
750: return;
751: }
752: info += ':'+toolid;
753: }
1.10 raeburn 754: var prefix = '';
755: if (supplementalflag == 1) {
756: prefix = 'supp';
757: }
758: var dispdiv = prefix+'tooldispdiv';
1.16 raeburn 759: var windiv = prefix+'toolwindiv';
1.10 raeburn 760: if (residx > 0) {
761: dispdiv += '_'+residx;
1.16 raeburn 762: windiv += '_'+residx;
1.10 raeburn 763: }
764: if (document.getElementById(dispdiv)) {
765: if (document.getElementById(dispdiv).style.display == 'block') {
766: if (extform.exttooltarget.length) {
767: for (var i=0; i<extform.exttooltarget.length; i++) {
768: if (extform.exttooltarget[i].checked) {
769: if (extform.exttooltarget[i].value == 'window') {
770: var width = extform.exttoolwidth.value;
771: width.trim();
772: var height = extform.exttoolheight.value;
773: height.trim();
1.16 raeburn 774: info += ':window:'+width+':'+height;
1.19 raeburn 775: } else if (extform.exttooltarget[i].value == 'tab') {
776: info += ':tab::';
1.10 raeburn 777: } else {
778: info += ':iframe::';
779: }
780: }
1.9 raeburn 781: }
782: }
1.10 raeburn 783: } else {
784: info += ':::';
1.9 raeburn 785: }
1.10 raeburn 786: } else {
787: info += ':::';
788: }
1.16 raeburn 789: if (document.getElementById(windiv)) {
790: if (document.getElementById(windiv).style.display == 'block') {
791: var linktextdiv = prefix+'toollinktextdiv';
792: var explanationdiv = prefix+'toolexplanationdiv';
793: if (residx > 0) {
794: linktextdiv += '_'+residx;
795: explanationdiv += '_'+residx;
796: }
797: if (document.getElementById(linktextdiv).style.display == 'inline') {
798: var linktext = extform.exttoollinktext.value;
799: linktext.trim();
800: info += ':'+escape(linktext);
801: } else {
802: info += ':';
803: }
804: if (document.getElementById(explanationdiv).style.display == 'inline') {
805: var explaintext = extform.exttoolexplanation.value;
806: explaintext.trim();
807: info += ':'+escape(explaintext);
808: } else {
809: info += ':';
810: }
811: } else {
812: info += '::';
813: }
814: } else {
815: info += '::';
816: }
1.10 raeburn 817: var labelinput = prefix+'toolcrslabel';
818: var titleinput = prefix+'toolcrstitle';
1.20 raeburn 819: var appendinput = prefix+'toolcrsappend';
1.10 raeburn 820: if (residx > 0) {
821: labelinput += '_'+residx;
822: titleinput += '_'+residx;
1.20 raeburn 823: appendinput += '_'+residx;
1.10 raeburn 824: }
825: if (document.getElementById(labelinput)) {
826: var crslabel = document.getElementById(labelinput).value;
827: crslabel.trim();
828: info += ':'+escape(crslabel);
829: } else {
830: info += ':';
831: }
832: if (document.getElementById(titleinput)) {
833: var crstitle = document.getElementById(titleinput).value;
834: crstitle.trim();
835: info += ':'+escape(crstitle);
836: } else {
837: info += ':';
1.9 raeburn 838: }
1.20 raeburn 839: if (document.getElementById(appendinput)) {
840: var crsappend = document.getElementById(appendinput).value;
841: crsappend.trim();
842: info += ':'+escape(crsappend);
843: } else {
844: info += ':';
845: }
1.9 raeburn 846: info=escape(info);
1.1 raeburn 847: if (residx > 0) {
1.9 raeburn 848: eval("extform.importdetail.value=title+'='+info+'='+residx;extform.submit();");
1.1 raeburn 849: } else {
1.9 raeburn 850: eval("extform.importdetail.value=title+'='+info;extform.submit();");
1.1 raeburn 851: }
852: }
853: }
854:
1.9 raeburn 855: function editext(residx,type) {
856: if (document.getElementById('upload'+type+residx)) {
857: var curr = document.getElementById('upload'+type+residx).style.display;
1.1 raeburn 858: if (curr == 'none') {
859: disp = 'block';
860: } else {
861: disp = 'none';
862: }
1.9 raeburn 863: document.getElementById('upload'+type+residx).style.display=disp;
1.1 raeburn 864: }
865: resize_scrollbox('contentscroll','1','1');
866: return;
867: }
868:
1.14 raeburn 869: function extUrlPreview(caller,protocol) {
1.1 raeburn 870: if (document.getElementById(caller)) {
871: var url = document.getElementById(caller).value;
872: if (regexp.test(url)) {
1.14 raeburn 873: var http_regex = /^http\:\/\//gi;
874: if ((protocol == 'https') && (http_regex.test(url))) {
875: window.open(url,"externalpreview","height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1");
876: } else {
877: openMyModal(url,500,400,'yes');
878: }
1.1 raeburn 879: } else {
1.8 damieng 880: alert("$js_lt{'invurl'}");
1.1 raeburn 881: }
882: }
883: }
884:
1.9 raeburn 885: function updateExttool(caller,form,supplementalflag) {
886: var prefix = '';
887: if (supplementalflag == 1) {
888: prefix = 'supp';
889: }
890: dispdiv = prefix+'tooldispdiv';
891: dimendiv = prefix+'tooldimendiv';
1.16 raeburn 892: widthinput = prefix+'tooldimenwidth';
893: heightinput = prefix+'tooldimenheight';
1.10 raeburn 894: labeldiv = prefix+'toolcrslabeldiv';
895: titlediv = prefix+'toolcrstitlediv';
1.20 raeburn 896: appenddiv = prefix+'toolcrsappenddiv';
897: providerurl = prefix+'toolproviderurl';
1.10 raeburn 898: labelinput = prefix+'toolcrslabel';
899: titleinput = prefix+'toolcrstitle';
1.20 raeburn 900: appendinput = prefix+'toolcrsappend';
1.16 raeburn 901: windiv = prefix+'toolwindiv';
902: linktextdiv = prefix+'toollinktextdiv';
903: linktextinput = prefix+'toollinktext';
904: explanationdiv = prefix+'toolexplanationdiv';
905: explanationinput = prefix+'toolexplanation';
1.9 raeburn 906: if (document.getElementById(dispdiv)) {
907: var toolpick = caller.options[caller.selectedIndex].value;
908: $toolsjs
909: if (toolpick == '') {
910: if (document.getElementById(dispdiv)) {
911: document.getElementById(dispdiv).style.display = 'none';
912: }
913: if (document.getElementById(dimendiv)) {
914: document.getElementById(dimendiv).style.display = 'none';
915: }
1.16 raeburn 916: if (document.getElementById(windiv)) {
917: document.getElementById(windiv).style.display = 'none';
918: }
919: if (document.getElementById(linktextdiv)) {
920: document.getElementById(linktextdiv).style.display = 'none';
921: }
922: if (document.getElementById(explanationdiv)) {
923: document.getElementById(explanationdiv).style.display = 'none';
924: }
1.10 raeburn 925: if (document.getElementById(labeldiv)) {
926: document.getElementById(labeldiv).style.display = 'none';
927: }
928: if (document.getElementById(titlediv)) {
929: document.getElementById(titlediv).style.display = 'none';
930: }
1.20 raeburn 931: if (document.getElementById(appenddiv)) {
932: document.getElementById(appenddiv).style.display = 'none';
933: }
1.9 raeburn 934: } else {
935: if (ltitools.length > 0) {
936: for (var j=0; j<ltitools.length; j++) {
937: if (ltitools[j] == toolpick) {
1.10 raeburn 938: if (document.getElementById(dispdiv)) {
939: if (ltitoolsDisplay[j]) {
940: document.getElementById(dispdiv).style.display = 'block';
941: if (form.exttooltarget.length) {
942: for (var k=0; k<form.exttooltarget.length; k++) {
943: if (form.exttooltarget[k].value == ltitoolsTarget[j]) {
944: form.exttooltarget[k].checked = true;
945: break;
946: }
947: }
948: }
1.16 raeburn 949: }
950: var dimen = 'none';
951: var dimenwidth = '';
952: var dimenheight = '';
953: if ((ltitoolsDisplay[j]) && (ltitoolsTarget[j] == 'window')) {
954: dimen = 'block';
955: dimenwidth = ltitoolsWidth[j];
956: dimenheight = ltitoolsHeight[j];
957: }
958: if (document.getElementById(dimendiv)) {
959: document.getElementById(dimendiv).style.display = dimen;
960: }
961: if (document.getElementById(widthinput)) {
962: document.getElementById(widthinput).value = dimenwidth;
963: }
964: if (document.getElementById(heightinput)) {
965: document.getElementById(heightinput).value = dimenheight;
966: }
967: }
968: if (document.getElementById(windiv)) {
1.19 raeburn 969: if ((ltitoolsTarget[j] == 'window') || (ltitoolsTarget[j] == 'tab')) {
1.16 raeburn 970: document.getElementById(windiv).style.display = 'block';
971: } else {
972: document.getElementById(windiv).style.display = 'none';
973: }
974: if (document.getElementById(linktextdiv)) {
1.17 raeburn 975: if (ltitoolsLink[j]) {
1.16 raeburn 976: document.getElementById(linktextdiv).style.display = 'inline';
1.10 raeburn 977: } else {
1.16 raeburn 978: document.getElementById(linktextdiv).style.display = 'none';
1.10 raeburn 979: }
1.16 raeburn 980: }
981: if (document.getElementById(linktextinput)) {
1.17 raeburn 982: if (ltitoolsLink[j]) {
1.16 raeburn 983: document.getElementById(linktextinput).value = ltitoolsLinkDef[j];
984: } else {
985: document.getElementById(linktextinput).value = '';
1.10 raeburn 986: }
1.16 raeburn 987: }
988: if (document.getElementById(explanationdiv)) {
1.17 raeburn 989: if (ltitoolsExplain[j]) {
1.16 raeburn 990: document.getElementById(explanationdiv).style.display = 'inline';
991: } else {
992: document.getElementById(explanationdiv).style.display = 'none';
1.10 raeburn 993: }
1.16 raeburn 994: }
995: if (document.getElementById(explanationinput)) {
1.17 raeburn 996: if (ltitoolsExplain[j]) {
1.16 raeburn 997: document.getElementById(explanationinput).value = ltitoolsExplainDef[j];
998: } else {
999: document.getElementById(explananationinput).value = '';
1.9 raeburn 1000: }
1001: }
1002: }
1.10 raeburn 1003: if (document.getElementById(labeldiv)) {
1004: if (ltitoolsLabel[j]) {
1005: document.getElementById(labeldiv).style.display = 'inline';
1006: } else {
1007: document.getElementById(labeldiv).style.display = 'none';
1008: }
1.9 raeburn 1009: }
1.10 raeburn 1010: if (document.getElementById(titlediv)) {
1011: if (ltitoolsTitle[j]) {
1012: document.getElementById(titlediv).style.display = 'inline';
1013: } else {
1014: document.getElementById(titlediv).style.display = 'none';
1015: }
1.9 raeburn 1016: }
1.20 raeburn 1017: if (document.getElementById(appenddiv)) {
1018: if (ltitoolsAppend[j]) {
1019: document.getElementById(appenddiv).style.display = 'inline';
1020: if (document.getElementById(providerurl)) {
1021: if ((ltitoolsUrl[j] != '') && (ltitoolsUrl[j] != null)) {
1.22 ! raeburn 1022: document.getElementById(providerurl).innerHTML = ' ('+ltitoolsUrl[j]+')<br />';
1.20 raeburn 1023: }
1024: }
1025: } else {
1026: document.getElementById(appenddiv).style.display = 'none';
1027: if (document.getElementById(providerurl)) {
1.22 ! raeburn 1028: document.getElementById(providerurl).innerHTML = '';
1.20 raeburn 1029: }
1030: }
1031: }
1.10 raeburn 1032: break;
1.9 raeburn 1033: }
1034: }
1035: }
1036: }
1037: }
1038: }
1039:
1.16 raeburn 1040: function updateTooldim(form,dimendiv,windiv,widthinput,heightinput,linkinput,explaininput) {
1.9 raeburn 1041: if (form.exttooltarget.length) {
1042: for (var i=0; i<form.exttooltarget.length; i++) {
1043: if (form.exttooltarget[i].checked) {
1044: var dimen = 'none';
1.17 raeburn 1045: var linkconf = 'none';
1.9 raeburn 1046: if (form.exttooltarget[i].value == 'window') {
1047: dimen = 'block';
1.16 raeburn 1048: linkconf = 'block';
1.9 raeburn 1049: } else {
1.19 raeburn 1050: if (form.exttooltarget[i].value == 'tab') {
1051: linkconf = 'block';
1052: } else {
1053: if (document.getElementById(widthinput)) {
1054: document.getElementById(widthinput).value = '';
1055: }
1056: if (document.getElementById(heightinput)) {
1057: document.getElementById(heightinput).value = '';
1058: }
1059: if (document.getElementById(linkinput)) {
1060: document.getElementById(linkinput).value = '';
1061: }
1062: if (document.getElementById(explaininput)) {
1063: document.getElementById(explaininput).value = '';
1064: }
1.16 raeburn 1065: }
1.9 raeburn 1066: }
1067: if (document.getElementById(dimendiv)) {
1068: document.getElementById(dimendiv).style.display = dimen;
1069: }
1.16 raeburn 1070: if (document.getElementById(windiv)) {
1071: document.getElementById(windiv).style.display = linkconf;
1.17 raeburn 1072: }
1.9 raeburn 1073: break;
1074: }
1075: }
1076: }
1077: }
1078:
1.1 raeburn 1079: ENDJS
1080:
1081: }
1082:
1083: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>