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