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