Annotation of loncom/interface/lonextresedit.pm, revision 1.29
1.1 raeburn 1: # The LearningOnline Network
2: # Documents
3: #
1.29 ! raeburn 4: # $Id: lonextresedit.pm,v 1.28 2019/05/02 02:12:18 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.28 raeburn 770: mixfra => 'Show preview in pop-up? (http in https page + no framing)',
771: mixonly => 'Show preview in pop-up? (http in https page)',
772: fraonly => 'Show preview in pop-up? (framing disallowed)',
773: nopopup => 'Pop-up blocked',
774: nopriv => 'Insufficient privileges to use preview',
775: badurl => 'URL is not: http://hostname/path or https://hostname/path',
1.1 raeburn 776: );
1.8 damieng 777: &js_escape(\%js_lt);
1.1 raeburn 778:
779: my $urlregexp = <<'ENDREGEXP';
780: /^([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
781: ENDREGEXP
782:
783: return <<ENDJS;
784:
785: var regexp = $urlregexp;
786:
1.10 raeburn 787: function setExternal(extform,residx,type,exttoolurl,supplementalflag) {
1.1 raeburn 788: var title=extform.exttitle.value;
789: if (!String.trim) {
790: String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");}; }
791: if (title == null || title.trim()=="") {
1.8 damieng 792: alert("$js_lt{'titbl'}");
1.1 raeburn 793: extform.exttitle.focus();
794: return;
795: }
1.9 raeburn 796: if (type == 'ext') {
797: var url=extform.exturl.value;
798: if (!regexp.test(url)) {
799: alert("$js_lt{'invurl'}");
800: extform.exturl.focus();
801: return;
802: } else {
803: url = escape(url);
804: title = escape(title);
805: if (residx > 0) {
806: eval("extform.importdetail.value=title+'='+url+'='+residx;extform.submit();");
807: } else {
808: eval("extform.importdetail.value=title+'='+url;extform.submit();");
809: }
810: }
811: } else {
1.7 raeburn 812: title = escape(title);
1.9 raeburn 813: var info = exttoolurl;
814: if (residx == 0) {
815: var toolid = parseInt(extform.exttoolid.options[extform.exttoolid.selectedIndex].value);
816: if (isNaN(toolid)) {
817: alert("$js_lt{'invtool'}");
818: return;
819: }
820: info += ':'+toolid;
821: }
1.10 raeburn 822: var prefix = '';
823: if (supplementalflag == 1) {
824: prefix = 'supp';
825: }
826: var dispdiv = prefix+'tooldispdiv';
1.16 raeburn 827: var windiv = prefix+'toolwindiv';
1.10 raeburn 828: if (residx > 0) {
829: dispdiv += '_'+residx;
1.16 raeburn 830: windiv += '_'+residx;
1.10 raeburn 831: }
832: if (document.getElementById(dispdiv)) {
833: if (document.getElementById(dispdiv).style.display == 'block') {
834: if (extform.exttooltarget.length) {
835: for (var i=0; i<extform.exttooltarget.length; i++) {
836: if (extform.exttooltarget[i].checked) {
837: if (extform.exttooltarget[i].value == 'window') {
838: var width = extform.exttoolwidth.value;
839: width.trim();
840: var height = extform.exttoolheight.value;
841: height.trim();
1.16 raeburn 842: info += ':window:'+width+':'+height;
1.19 raeburn 843: } else if (extform.exttooltarget[i].value == 'tab') {
844: info += ':tab::';
1.10 raeburn 845: } else {
846: info += ':iframe::';
847: }
848: }
1.9 raeburn 849: }
850: }
1.10 raeburn 851: } else {
852: info += ':::';
1.9 raeburn 853: }
1.10 raeburn 854: } else {
855: info += ':::';
856: }
1.16 raeburn 857: if (document.getElementById(windiv)) {
858: if (document.getElementById(windiv).style.display == 'block') {
859: var linktextdiv = prefix+'toollinktextdiv';
860: var explanationdiv = prefix+'toolexplanationdiv';
861: if (residx > 0) {
862: linktextdiv += '_'+residx;
863: explanationdiv += '_'+residx;
864: }
865: if (document.getElementById(linktextdiv).style.display == 'inline') {
866: var linktext = extform.exttoollinktext.value;
867: linktext.trim();
868: info += ':'+escape(linktext);
869: } else {
870: info += ':';
871: }
872: if (document.getElementById(explanationdiv).style.display == 'inline') {
873: var explaintext = extform.exttoolexplanation.value;
874: explaintext.trim();
875: info += ':'+escape(explaintext);
876: } else {
877: info += ':';
878: }
879: } else {
880: info += '::';
881: }
882: } else {
883: info += '::';
884: }
1.10 raeburn 885: var labelinput = prefix+'toolcrslabel';
886: var titleinput = prefix+'toolcrstitle';
1.20 raeburn 887: var appendinput = prefix+'toolcrsappend';
1.10 raeburn 888: if (residx > 0) {
889: labelinput += '_'+residx;
890: titleinput += '_'+residx;
1.20 raeburn 891: appendinput += '_'+residx;
1.10 raeburn 892: }
893: if (document.getElementById(labelinput)) {
894: var crslabel = document.getElementById(labelinput).value;
895: crslabel.trim();
896: info += ':'+escape(crslabel);
897: } else {
898: info += ':';
899: }
900: if (document.getElementById(titleinput)) {
901: var crstitle = document.getElementById(titleinput).value;
902: crstitle.trim();
903: info += ':'+escape(crstitle);
904: } else {
905: info += ':';
1.9 raeburn 906: }
1.20 raeburn 907: if (document.getElementById(appendinput)) {
908: var crsappend = document.getElementById(appendinput).value;
909: crsappend.trim();
910: info += ':'+escape(crsappend);
911: } else {
912: info += ':';
913: }
1.23 raeburn 914: var gradablediv = prefix+'toolgradablediv';
915: if (residx > 0) {
916: gradablediv += '_'+residx;
917: }
918: if (document.getElementById(gradablediv)) {
919: if (document.getElementById(gradablediv).style.display == 'inline') {
920: if (extform.exttoolgradable.length) {
921: for (var i=0; i<extform.exttoolgradable.length; i++) {
922: if (extform.exttoolgradable[i].checked) {
923: if (extform.exttoolgradable[i].value == '1') {
924: info += ':1';
925: } else {
926: info += ':';
927: }
928: break;
929: }
930: }
931: } else {
932: info += ':';
933: }
934: } else {
935: info += ':';
936: }
937: } else {
938: info += ':';
939: }
1.9 raeburn 940: info=escape(info);
1.1 raeburn 941: if (residx > 0) {
1.9 raeburn 942: eval("extform.importdetail.value=title+'='+info+'='+residx;extform.submit();");
1.1 raeburn 943: } else {
1.9 raeburn 944: eval("extform.importdetail.value=title+'='+info;extform.submit();");
1.1 raeburn 945: }
946: }
947: }
948:
1.9 raeburn 949: function editext(residx,type) {
1.27 raeburn 950: if (document.getElementById('external'+type+residx)) {
951: var curr = document.getElementById('external'+type+residx).style.display;
1.1 raeburn 952: if (curr == 'none') {
953: disp = 'block';
954: } else {
955: disp = 'none';
956: }
1.27 raeburn 957: document.getElementById('external'+type+residx).style.display=disp;
1.1 raeburn 958: }
959: resize_scrollbox('contentscroll','1','1');
960: return;
961: }
962:
1.14 raeburn 963: function extUrlPreview(caller,protocol) {
1.1 raeburn 964: if (document.getElementById(caller)) {
965: var url = document.getElementById(caller).value;
966: if (regexp.test(url)) {
1.14 raeburn 967: var http_regex = /^http\:\/\//gi;
1.28 raeburn 968: var mixed = 0;
969: var noiframe = 0;
970: var nopriv = 0;
971: var badurl = 0;
972: var name = "externalpreview";
1.14 raeburn 973: if ((protocol == 'https') && (http_regex.test(url))) {
1.28 raeburn 974: mixed = 1;
975: }
976: var http = new XMLHttpRequest();
977: var lcurl = "/adm/exturlcheck";
978: var params = "exturl="+url;
979: http.open("POST",lcurl, true);
980: http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
981: http.onreadystatechange = function() {
982: if (http.readyState == 4) {
983: if (http.status == 200) {
1.29 ! raeburn 984: if (http.responseText.length > 0) {
! 985: if (http.responseText == 1) {
! 986: noiframe = 1;
! 987: } else if (http.responseText == -1) {
! 988: nopriv = 1;
! 989: } else if (http.responseText == 0) {
! 990: badurl = 1;
! 991: }
1.28 raeburn 992: }
993: openPreviewWindow(url,name,noiframe,mixed,nopriv,badurl);
994: }
995: }
996: }
997: http.send(params);
998: } else {
999: alert("$js_lt{'invurl'}");
1000: }
1001: }
1002: }
1003:
1004: var previewLCWindow = null;
1005: function openPreviewWindow(url,name,noiframe,mixed,nopriv,badurl) {
1006: if (previewLCWindow !=null) {
1007: previewLCWindow.close();
1008: }
1009: if (badurl) {
1010: alert("$js_lt{'badurl'}");
1011: } else if (nopriv) {
1012: alert("$js_lt{'nopriv'}");
1013: } else if ((noiframe == 1) || (mixed == 1)) {
1014: var encurl = encodeURI(url);
1015: var msg;
1016: if (mixed == 1) {
1017: if (noiframe == 1) {
1018: msg = "$js_lt{'mixfra'}";
1.14 raeburn 1019: } else {
1.28 raeburn 1020: msg = "$js_lt{'mixonly'}";
1.14 raeburn 1021: }
1.1 raeburn 1022: } else {
1.28 raeburn 1023: msg = "$js_lt{'fraonly'}";
1024: }
1025: if (confirm(msg)) {
1026: previewLCWindow = window.open(url,name,"height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1");
1027: if (previewLCWindow != null) {
1028: previewLCWindow.focus();
1029: } else {
1030: alert("$js_lt{'nopopup'}");
1031: }
1.1 raeburn 1032: }
1.28 raeburn 1033: } else {
1034: openMyModal(url,500,400,'yes');
1.1 raeburn 1035: }
1036: }
1037:
1.9 raeburn 1038: function updateExttool(caller,form,supplementalflag) {
1039: var prefix = '';
1040: if (supplementalflag == 1) {
1041: prefix = 'supp';
1042: }
1043: dispdiv = prefix+'tooldispdiv';
1044: dimendiv = prefix+'tooldimendiv';
1.16 raeburn 1045: widthinput = prefix+'tooldimenwidth';
1046: heightinput = prefix+'tooldimenheight';
1.10 raeburn 1047: labeldiv = prefix+'toolcrslabeldiv';
1048: titlediv = prefix+'toolcrstitlediv';
1.20 raeburn 1049: appenddiv = prefix+'toolcrsappenddiv';
1.23 raeburn 1050: gradablediv = prefix+'toolgradablediv';
1.20 raeburn 1051: providerurl = prefix+'toolproviderurl';
1.10 raeburn 1052: labelinput = prefix+'toolcrslabel';
1053: titleinput = prefix+'toolcrstitle';
1.20 raeburn 1054: appendinput = prefix+'toolcrsappend';
1.16 raeburn 1055: windiv = prefix+'toolwindiv';
1056: linktextdiv = prefix+'toollinktextdiv';
1057: linktextinput = prefix+'toollinktext';
1058: explanationdiv = prefix+'toolexplanationdiv';
1059: explanationinput = prefix+'toolexplanation';
1.9 raeburn 1060: if (document.getElementById(dispdiv)) {
1061: var toolpick = caller.options[caller.selectedIndex].value;
1062: $toolsjs
1063: if (toolpick == '') {
1064: if (document.getElementById(dispdiv)) {
1065: document.getElementById(dispdiv).style.display = 'none';
1066: }
1067: if (document.getElementById(dimendiv)) {
1068: document.getElementById(dimendiv).style.display = 'none';
1069: }
1.16 raeburn 1070: if (document.getElementById(windiv)) {
1071: document.getElementById(windiv).style.display = 'none';
1072: }
1073: if (document.getElementById(linktextdiv)) {
1074: document.getElementById(linktextdiv).style.display = 'none';
1075: }
1076: if (document.getElementById(explanationdiv)) {
1077: document.getElementById(explanationdiv).style.display = 'none';
1078: }
1.10 raeburn 1079: if (document.getElementById(labeldiv)) {
1080: document.getElementById(labeldiv).style.display = 'none';
1081: }
1082: if (document.getElementById(titlediv)) {
1083: document.getElementById(titlediv).style.display = 'none';
1084: }
1.20 raeburn 1085: if (document.getElementById(appenddiv)) {
1086: document.getElementById(appenddiv).style.display = 'none';
1087: }
1.23 raeburn 1088: if (document.getElementById(gradablediv)) {
1089: document.getElementById(gradablediv).style.display = 'none';
1090: }
1.9 raeburn 1091: } else {
1092: if (ltitools.length > 0) {
1093: for (var j=0; j<ltitools.length; j++) {
1094: if (ltitools[j] == toolpick) {
1.10 raeburn 1095: if (document.getElementById(dispdiv)) {
1096: if (ltitoolsDisplay[j]) {
1097: document.getElementById(dispdiv).style.display = 'block';
1098: if (form.exttooltarget.length) {
1099: for (var k=0; k<form.exttooltarget.length; k++) {
1100: if (form.exttooltarget[k].value == ltitoolsTarget[j]) {
1101: form.exttooltarget[k].checked = true;
1102: break;
1103: }
1104: }
1105: }
1.16 raeburn 1106: }
1107: var dimen = 'none';
1108: var dimenwidth = '';
1109: var dimenheight = '';
1110: if ((ltitoolsDisplay[j]) && (ltitoolsTarget[j] == 'window')) {
1111: dimen = 'block';
1112: dimenwidth = ltitoolsWidth[j];
1113: dimenheight = ltitoolsHeight[j];
1114: }
1115: if (document.getElementById(dimendiv)) {
1116: document.getElementById(dimendiv).style.display = dimen;
1117: }
1118: if (document.getElementById(widthinput)) {
1119: document.getElementById(widthinput).value = dimenwidth;
1120: }
1121: if (document.getElementById(heightinput)) {
1122: document.getElementById(heightinput).value = dimenheight;
1123: }
1124: }
1125: if (document.getElementById(windiv)) {
1.19 raeburn 1126: if ((ltitoolsTarget[j] == 'window') || (ltitoolsTarget[j] == 'tab')) {
1.16 raeburn 1127: document.getElementById(windiv).style.display = 'block';
1128: } else {
1129: document.getElementById(windiv).style.display = 'none';
1130: }
1131: if (document.getElementById(linktextdiv)) {
1.17 raeburn 1132: if (ltitoolsLink[j]) {
1.16 raeburn 1133: document.getElementById(linktextdiv).style.display = 'inline';
1.10 raeburn 1134: } else {
1.16 raeburn 1135: document.getElementById(linktextdiv).style.display = 'none';
1.10 raeburn 1136: }
1.16 raeburn 1137: }
1138: if (document.getElementById(linktextinput)) {
1.17 raeburn 1139: if (ltitoolsLink[j]) {
1.16 raeburn 1140: document.getElementById(linktextinput).value = ltitoolsLinkDef[j];
1141: } else {
1142: document.getElementById(linktextinput).value = '';
1.10 raeburn 1143: }
1.16 raeburn 1144: }
1145: if (document.getElementById(explanationdiv)) {
1.17 raeburn 1146: if (ltitoolsExplain[j]) {
1.16 raeburn 1147: document.getElementById(explanationdiv).style.display = 'inline';
1148: } else {
1149: document.getElementById(explanationdiv).style.display = 'none';
1.10 raeburn 1150: }
1.16 raeburn 1151: }
1152: if (document.getElementById(explanationinput)) {
1.17 raeburn 1153: if (ltitoolsExplain[j]) {
1.16 raeburn 1154: document.getElementById(explanationinput).value = ltitoolsExplainDef[j];
1155: } else {
1156: document.getElementById(explananationinput).value = '';
1.9 raeburn 1157: }
1158: }
1159: }
1.10 raeburn 1160: if (document.getElementById(labeldiv)) {
1161: if (ltitoolsLabel[j]) {
1162: document.getElementById(labeldiv).style.display = 'inline';
1163: } else {
1164: document.getElementById(labeldiv).style.display = 'none';
1165: }
1.9 raeburn 1166: }
1.10 raeburn 1167: if (document.getElementById(titlediv)) {
1168: if (ltitoolsTitle[j]) {
1169: document.getElementById(titlediv).style.display = 'inline';
1170: } else {
1171: document.getElementById(titlediv).style.display = 'none';
1172: }
1.9 raeburn 1173: }
1.20 raeburn 1174: if (document.getElementById(appenddiv)) {
1175: if (ltitoolsAppend[j]) {
1176: document.getElementById(appenddiv).style.display = 'inline';
1177: if (document.getElementById(providerurl)) {
1178: if ((ltitoolsUrl[j] != '') && (ltitoolsUrl[j] != null)) {
1.22 raeburn 1179: document.getElementById(providerurl).innerHTML = ' ('+ltitoolsUrl[j]+')<br />';
1.20 raeburn 1180: }
1181: }
1182: } else {
1183: document.getElementById(appenddiv).style.display = 'none';
1184: if (document.getElementById(providerurl)) {
1.22 raeburn 1185: document.getElementById(providerurl).innerHTML = '';
1.20 raeburn 1186: }
1187: }
1188: }
1.23 raeburn 1189: if (document.getElementById(gradablediv)) {
1190: if (supplementalflag != 1) {
1191: document.getElementById(gradablediv).style.display = 'inline';
1192: }
1193: }
1.10 raeburn 1194: break;
1.9 raeburn 1195: }
1196: }
1197: }
1198: }
1199: }
1200: }
1201:
1.16 raeburn 1202: function updateTooldim(form,dimendiv,windiv,widthinput,heightinput,linkinput,explaininput) {
1.9 raeburn 1203: if (form.exttooltarget.length) {
1204: for (var i=0; i<form.exttooltarget.length; i++) {
1205: if (form.exttooltarget[i].checked) {
1206: var dimen = 'none';
1.17 raeburn 1207: var linkconf = 'none';
1.9 raeburn 1208: if (form.exttooltarget[i].value == 'window') {
1209: dimen = 'block';
1.16 raeburn 1210: linkconf = 'block';
1.9 raeburn 1211: } else {
1.19 raeburn 1212: if (form.exttooltarget[i].value == 'tab') {
1213: linkconf = 'block';
1214: } else {
1215: if (document.getElementById(widthinput)) {
1216: document.getElementById(widthinput).value = '';
1217: }
1218: if (document.getElementById(heightinput)) {
1219: document.getElementById(heightinput).value = '';
1220: }
1221: if (document.getElementById(linkinput)) {
1222: document.getElementById(linkinput).value = '';
1223: }
1224: if (document.getElementById(explaininput)) {
1225: document.getElementById(explaininput).value = '';
1226: }
1.16 raeburn 1227: }
1.9 raeburn 1228: }
1229: if (document.getElementById(dimendiv)) {
1230: document.getElementById(dimendiv).style.display = dimen;
1231: }
1.16 raeburn 1232: if (document.getElementById(windiv)) {
1233: document.getElementById(windiv).style.display = linkconf;
1.17 raeburn 1234: }
1.9 raeburn 1235: break;
1236: }
1237: }
1238: }
1239: }
1240:
1.1 raeburn 1241: ENDJS
1242:
1243: }
1244:
1245: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>