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