Annotation of loncom/interface/lonextresedit.pm, revision 1.9
1.1 raeburn 1: # The LearningOnline Network
2: # Documents
3: #
1.9 ! raeburn 4: # $Id: lonextresedit.pm,v 1.8 2015/06/09 21:22:56 damieng 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.9 ! raeburn 63: if (&unescape($env{'form.suppurl'}) =~ m{^/adm/$cdom/$cnum/\d+/exttools?$}) {
! 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.9 ! raeburn 82: if ($url =~ m{/adm/$cdom/$cnum/\d+/exttools?$}) {
! 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') {
! 101: %ltitools = &Apache::lonnet::get_domain_ltitools($cdom);
! 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.9 ! raeburn 149: if ($oldurl =~ m{^/adm/$cdom/$cnum/\d+/exttools?$}) {
! 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.9 ! raeburn 160: if ($newurl =~ m{^(/adm/$cdom/$cnum/(\d+)/exttools?)\:?(.*)$}) {
! 161: $newurl = $1;
! 162: $marker = $2;
! 163: $args = $3;
! 164: }
1.5 raeburn 165: }
166: if ($supplementalflag) {
167: $residx = $newidx;
168: } else {
169: $residx = $oldidx;
170: }
1.1 raeburn 171: if ($folder && $container) {
172: if ($env{'form.importdetail'}) {
1.5 raeburn 173: my ($errtext,$fatal,$mismatchedid,@imports);
174: if (!$supplementalflag) {
175: if (($oldidx) && ($oldidx != $newidx)) {
176: $mismatchedid = 1;
177: }
1.1 raeburn 178: }
179: if ($mismatchedid) {
180: $errormsg = 'Wrong item identifier';
181: } elsif (($newtitle eq $oldtitle) && ($newurl eq $oldurl)) {
1.9 ! raeburn 182: if ($type eq 'tool') {
! 183: if ($args) {
! 184: ($updated,$errormsg) = &update_exttool($marker,$cdom,$cnum,$args);
! 185: unless ($updated) {
! 186: $output = &mt('No change');
! 187: }
! 188: } else {
! 189: $output = &mt('No change');
! 190: }
! 191: } else {
! 192: $output = &mt('No change');
! 193: }
1.1 raeburn 194: } else {
195: my $map = "/uploaded/$cdom/$cnum/$folder.$container";
196: my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
197: if ($fatal) {
198: $errormsg = &mt('Update failed: [_1].',$errtext);
199: } else {
200: my $saveurl = &LONCAPA::map::qtunescape($newurl);
201: my $savetitle = &LONCAPA::map::qtunescape($newtitle);
1.9 ! raeburn 202: my $ext = 'true';
! 203: if ($type eq 'tool') {
! 204: if ($args) {
! 205: ($updated,$errormsg) = &update_exttool($marker,$cdom,$cnum,$args);
! 206: }
! 207: $ext = 'false';
! 208: }
1.1 raeburn 209: $LONCAPA::map::resources[$residx] =
1.9 ! raeburn 210: join(':', ($savetitle,$saveurl,$ext,'normal','res'));
1.1 raeburn 211: my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
212: if ($errtext) {
213: $errormsg = &mt('Update failed: [_1].',$errtext);
214: } else {
215: $updated = 1;
1.5 raeburn 216: $title = $newtitle;
217: if ($newurl ne $oldurl) {
218: $url = $newurl;
1.9 ! raeburn 219: if ($ext eq 'true') {
! 220: $newurl =~ s{^http://}{};
! 221: $newurl = "ext/$newurl";
! 222: }
1.5 raeburn 223: }
1.1 raeburn 224: if (!$supplementalflag) {
225: if ($newurl ne $oldurl) {
1.5 raeburn 226: $symb = &Apache::lonnet::encode_symb($map,$residx,$newurl);
1.1 raeburn 227: } else {
228: $symb = $env{'form.symb'};
229: if ($symb) {
230: &Apache::lonnet::devalidate_title_cache($symb);
231: }
232: }
233: }
1.5 raeburn 234: my ($furl,$ferr) =
235: &Apache::lonuserstate::readmap("$cdom/$cnum");
1.1 raeburn 236: if ($ferr) {
237: $errormsg = &mt('Reload failed: [_1].',$ferr);
238: } else {
1.5 raeburn 239: unless ($supplementalflag) {
240: &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
241: }
1.1 raeburn 242: }
243: }
244: }
245: }
246: } else {
247: $output = &mt('No change');
248: }
249: } else {
1.9 ! raeburn 250: if ($type eq 'tool') {
! 251: $errormsg = &mt('Information about current external tool is incomplete.');
! 252: } else {
! 253: $errormsg = &mt('Information about current external resource is incomplete.');
! 254: }
1.1 raeburn 255: }
1.5 raeburn 256: return ($updated,$output,$errormsg,$residx,$url,$title,$symb);
1.1 raeburn 257: }
258:
1.9 ! raeburn 259: sub update_exttool {
! 260: my ($marker,$cdom,$cnum,$args) = @_;
! 261: my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
! 262: my (%newhash,$changed,$errormsg);
! 263: ($newhash{'target'},$newhash{'width'},$newhash{'height'}) = split(/:/,$args);
! 264: my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
! 265: foreach my $item ('target','width','height') {
! 266: $newhash{$item} =~ s/^\s+//;
! 267: $newhash{$item} =~ s/\s+$//;
! 268: unless ($item eq 'target') {
! 269: if ($newhash{'target'} eq 'iframe') {
! 270: $newhash{$item} = '';
! 271: }
! 272: }
! 273: if ($toolhash{$item} ne $newhash{$item}) {
! 274: if ($newhash{$item} eq '') {
! 275: delete($toolhash{$item});
! 276: } else {
! 277: $toolhash{$item} = $newhash{$item};
! 278: }
! 279: $changed = 1;
! 280: }
! 281: }
! 282: if ($changed) {
! 283: my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$cdom,$cnum);
! 284: unless ($putres eq 'ok') {
! 285: $errormsg = &mt('Failed to save updated settings.').' '.&mt('Error: [_1].',$putres);
! 286: }
! 287: }
! 288: return ($changed,$errormsg);
! 289: }
! 290:
1.1 raeburn 291: sub extedit_form {
1.9 ! raeburn 292: my ($supplementalflag,$residx,$orig_url,$orig_title,$pathitem,$helpitem,$caller,
! 293: $symb,$type,$cdom,$cnum,$ltitools) = @_;
! 294: if ($type ne 'tool') {
! 295: $type = 'ext';
! 296: }
1.1 raeburn 297: my %lt = &Apache::lonlocal::texthash(
298: ex => 'External Resource',
1.9 ! raeburn 299: et => 'External Tool',
1.1 raeburn 300: ed => 'Edit',
301: ee => 'External Resource Editor',
1.9 ! raeburn 302: te => 'External Tool Editor',
1.1 raeburn 303: pr => 'Preview',
304: sv => 'Save',
305: ul => 'URL',
306: ti => 'Title',
307: al => 'Add Link',
1.9 ! raeburn 308: at => 'Add Tool',
1.1 raeburn 309: );
310: my $tabid = 'aa';
311: my $size = 60;
312: if ($supplementalflag) {
313: $tabid = 'ee';
1.9 ! raeburn 314: }
! 315: my ($formname,$formid,$toggle,$fieldsetid,$urlid,$dispdivstyle,$dimendivstyle,
! 316: $legend,$urlelem,$toolelem,%toolattr);
! 317: $formname = 'new'.$type;
! 318: $toggle = $type;
! 319: $fieldsetid = 'upload'.$type.'form';
! 320: $urlid = $type.'url';
! 321: map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight');
! 322: $dispdivstyle = 'display:none';
! 323: $dimendivstyle = 'display:none';
! 324: if ($supplementalflag) {
! 325: $formname = 'newsupp'.$type;
! 326: $toggle = 'supp'.$type;
! 327: $fieldsetid = 'uploadsupp'.$type.'form';
! 328: $urlid = 'supp'.$type.'url';
! 329: map { $toolattr{$_} = 'supp'.$toolattr{$_}; } (keys(%toolattr));
1.1 raeburn 330: }
331: my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,
1.9 ! raeburn 332: $fieldsetstyle,$action,$hiddenelem,$form,$width,$height,$tooltarget,%chkstate);
1.1 raeburn 333: $fieldsetstyle = 'display: none;';
334: $action = '/adm/coursedocs';
335: if ($residx) {
336: if ($caller eq 'direct') {
337: $fieldsetstyle = 'display: block;';
338: $action = '/adm/extresedit';
1.9 ! raeburn 339: if ($type eq 'tool') {
! 340: $legend = $lt{'ee'};
! 341: } else {
! 342: $legend = $lt{'te'};
! 343: }
! 344: $legend = '<legend>'.$legend.'</legend>';
1.1 raeburn 345: if ($symb) {
346: $hiddenelem = '<input type="hidden" name="symb" value="'.$symb.'" />';
347: } elsif ($supplementalflag) {
348: $hiddenelem = '<input type="hidden" name="suppurl" value="'.
349: &HTML::Entities::encode(&escape($orig_url),'<>&"').'" />'."\n".
350: '<input type="hidden" name="title" value="'.
351: &HTML::Entities::encode(&escape($orig_title),'<>&"').'" />';
352: }
1.9 ! raeburn 353: } else {
! 354: $link = '<a class="LC_docs_ext_edit" href="javascript:editext('."'$residx','$type'".');">'.$lt{'ed'}.'</a> '."\n";
1.1 raeburn 355: $size = 40;
1.3 raeburn 356: $active = '<input type="hidden" name="active" value="'.$tabid.'" />';
1.1 raeburn 357: }
1.9 ! raeburn 358: $formname = 'edit'.$type.'_'.$residx;
! 359: $fieldsetid = 'upload'.$type.$residx;
! 360: $urlid = $type.'url_'.$residx;
! 361: map { $toolattr{$_} .= '_'.$residx; } (keys(%toolattr));
1.1 raeburn 362: $srcclass = ' class="LC_nobreak"';
1.9 ! raeburn 363: if ($type eq 'ext') {
! 364: $extsrc = '<span class="LC_docs_ext_edit">'.$lt{'ul'}.' </span>';
! 365: $preview = ' <a class="LC_docs_ext_edit" href="javascript:extUrlPreview('."'$urlid'".');">'.$lt{'pr'}.'</a>';
! 366: }
1.1 raeburn 367: $title = '<span class="LC_docs_ext_edit">'.$lt{'ti'}.' </span>';
368: $save = $lt{'sv'};
369: } else {
1.9 ! raeburn 370: $link = $lt{'ex'};
! 371: if ($type eq 'tool') {
! 372: $link = $lt{'et'};
! 373: }
! 374: $link = '<a class="LC_menubuttons_link" href="javascript:toggleUpload('."'$toggle'".');">'.$link.'</a>'.$helpitem;
! 375: if ($type eq 'tool') {
! 376: $legend = $lt{'te'};
! 377: } else {
! 378: $legend = $lt{'ee'};
! 379: }
! 380: $legend = '<legend>'.$legend.'</legend>';
1.1 raeburn 381: $title = $lt{'ti'}.':<br />';
382: $residx = 0;
1.9 ! raeburn 383: if ($type eq 'ext') {
! 384: $orig_url = 'http://';
! 385: $orig_title = $lt{'ex'};
! 386: $extsrc = $lt{'ul'}.':<br />';
! 387: $preview = '<input type="button" name="view" value="'.$lt{'pr'}.'" onclick="javascript:extUrlPreview('."'$urlid'".');" />';
! 388: $save = $lt{'al'};
! 389: } else {
! 390: $orig_title = $lt{'et'};
! 391: $save = $lt{'at'};
! 392: $orig_url = "/adm/$cdom/$cnum/new/exttool";
! 393: }
1.1 raeburn 394: $pathitem .= '<br />';
395: }
1.9 ! raeburn 396: $formid = $formname;
! 397: if ($type eq 'ext') {
! 398: $urlelem = '<input type="text" size="'.$size.'" name="exturl" id="'.$urlid.'" value="'.$orig_url.'" />';
! 399: } else {
! 400: my $class = 'LC_nobreak';
! 401: if ($residx) {
! 402: $class = 'LC_docs_ext_edit LC_nobreak';
! 403: if ($orig_url =~ m{^/adm/$cdom/$cnum/(\d+)/exttools?$}) {
! 404: my $marker = $1;
! 405: my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
! 406: if ($toolhash{'id'}) {
! 407: $dispdivstyle = 'display:block';
! 408: if (ref($ltitools) eq 'HASH') {
! 409: if (keys(%{$ltitools})) {
! 410: if (ref($ltitools->{$toolhash{'id'}}) eq 'HASH') {
! 411: my $tooltitle = $ltitools->{$toolhash{'id'}}->{'title'};
! 412: my $icon = $ltitools->{$toolhash{'id'}}->{'image'};
! 413: my $image;
! 414: if ($icon) {
! 415: $image = '<img src="'.$icon.'" alt="'.$tooltitle.'" />';
! 416: }
! 417: $tooltarget = $toolhash{'target'};
! 418: if ($tooltarget eq 'window') {
! 419: $dimendivstyle = 'display:block';
! 420: $chkstate{'window'} = 'checked="checked" ';
! 421: } else {
! 422: $chkstate{'iframe'} = 'checked="checked" ';
! 423: }
! 424: $width = $toolhash{'width'};
! 425: $height = $toolhash{'height'};
! 426: $toolelem = '<span class="LC_nobreak">'.$image.' '.$tooltitle.'</span><br />';
! 427: }
! 428: }
! 429: }
! 430: }
! 431: }
! 432: } else {
! 433: $toolelem = '<span class="LC_docs_ext_edit">'."\n".
! 434: '<select name="exttoolid" id="LC_exttoolid" onchange="javascript:updateExttool(this,'.
! 435: 'this.form,'."'$supplementalflag'".');">'."\n".
! 436: '<option value="" selected="selected">'.&mt('Select').'</option>';
! 437: my %bynum;
! 438: if (ref($ltitools) eq 'HASH') {
! 439: foreach my $id (keys(%{$ltitools})) {
! 440: if (ref($ltitools->{$id}) eq 'HASH') {
! 441: my $order = $ltitools->{$id}->{'order'};
! 442: $bynum{$order} = [$id,$ltitools->{$id}];
! 443: }
! 444: }
! 445: }
! 446: foreach my $item (sort { $a <=> $b } keys(%bynum)) {
! 447: if (ref($bynum{$item}) eq 'ARRAY') {
! 448: if (ref($bynum{$item}->[1]) eq 'HASH') {
! 449: my $tooltitle = $bynum{$item}->[1]->{'title'};
! 450: my $icon = $bynum{$item}->[1]->{'image'};
! 451: $toolelem .= '<option value="'.$bynum{$item}->[0].'">'.$tooltitle.'</option>';
! 452: }
! 453: }
! 454: }
! 455: $toolelem .= '</select></span>';
! 456: }
! 457: $toolelem .= '<div id="'.$toolattr{'dispdiv'}.'" style="'.$dispdivstyle.'">'.
! 458: '<span class="'.$class.'">'.&mt('Display target:').' '.
! 459: '<label><input type="radio" name="exttooltarget" value="iframe" '.$chkstate{'iframe'}.'onclick="updateTooldim(this.form,'.
! 460: "'$toolattr{dimendiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}'".');">'.&mt('iframe').'</label>'.(' 'x2).
! 461: '<label><input type="radio" name="exttooltarget" value="window" '.$chkstate{'window'}.'onclick="updateTooldim(this.form,'.
! 462: "'$toolattr{dimendiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}'".');">'.&mt('window').'</label>'.
! 463: '</span><div id="'.$toolattr{'dimendiv'}.'" style="'.$dimendivstyle.'">'.
! 464: '<span class="'.$class.'">'.
! 465: &mt('Width').'<input type="text" id="'.$toolattr{'dimenwidth'}.'" name="exttoolwidth" value="'.$width.'">'.(' 'x2).
! 466: &mt('Height').'<input type="text" id="'.$toolattr{'dimenheight'}.'" name="exttoolheight" value="'.$height.'"></span>'."\n".
! 467: '</div></div>';
! 468: }
! 469: my $chooser = $toolelem;
! 470: if ($type eq 'ext') {
! 471: $chooser = "
! 472: <div>
! 473: <span$srcclass>
! 474: $extsrc
! 475: $urlelem
! 476: $preview
! 477: </span>
! 478: </div>
! 479: ";
! 480: }
1.3 raeburn 481: $form = <<ENDFORM;
1.9 ! raeburn 482: <form action="$action" method="post" name="$formname" id="$formid">
1.2 raeburn 483: <fieldset id="$fieldsetid" style="$fieldsetstyle">
1.1 raeburn 484: $legend
485: $active
1.9 ! raeburn 486: $chooser
! 487: <div>
1.1 raeburn 488: <span$srcclass>
489: $title
490: <input type="text" size="$size" name="exttitle" value="$orig_title" />
491: <input type="hidden" name="importdetail" value="" />
492: $pathitem
493: $hiddenelem
1.9 ! raeburn 494: <input type="button" value="$save" onclick="javascript:setExternal(this.form,'$residx','$type','$orig_url');" />
1.1 raeburn 495: </span>
1.9 ! raeburn 496: </div>
1.1 raeburn 497: </fieldset>
498: </form>
499: ENDFORM
1.3 raeburn 500: if (wantarray) {
501: return ($link,$form);
502: } else {
503: return $link.$form;
504: }
1.1 raeburn 505: }
506:
507: sub display_editor {
1.9 ! raeburn 508: my ($url,$folderpath,$symb,$idx,$type,$cdom,$cnum) = @_;
! 509: my ($residx,$supplementalflag,$title,$pathitem,$output,$js);
1.1 raeburn 510: if ($folderpath =~ /^supplemental/) {
511: $supplementalflag = 1;
512: $residx = $idx;
513: $title = &unescape($env{'form.title'});
514: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
515: } elsif ($symb =~ /^uploaded/) {
516: (my $map,$residx,my $res) =
517: &Apache::lonnet::decode_symb($symb);
518: $title = &Apache::lonnet::gettitle($symb);
1.6 raeburn 519: my $path = &Apache::loncommon::symb_to_docspath($symb);
1.4 raeburn 520: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($path,'<>&"').'" />';
1.1 raeburn 521: }
1.9 ! raeburn 522: my %ltitools;
! 523: if ($type eq 'tool') {
! 524: %ltitools = &Apache::lonnet::get_domain_ltitools($cdom);
! 525: }
! 526: $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
1.1 raeburn 527: my $args = { 'force_register' => $env{'form.register'} };
1.9 ! raeburn 528: my $description = 'External Resource Editor';
! 529: if ($type eq 'tool') {
! 530: $description = 'External Tool Editor';
! 531: }
! 532: return &Apache::loncommon::start_page($description,$js,$args).
1.1 raeburn 533: '<div class="LC_left_float">'.
1.9 ! raeburn 534: &extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,'direct',
! 535: $symb,$type,$cdom,$cnum,\%ltitools).
1.1 raeburn 536: '</div>'.
537: &Apache::loncommon::end_page();
538: }
539:
540: sub extedit_javascript {
1.9 ! raeburn 541: my ($toolsref) = @_;
! 542: my $toolsjs;
! 543: if (ref($toolsref) eq 'HASH') {
! 544: my $num = scalar(keys(%{$toolsref}));
! 545: $toolsjs = " var ltitools = new Array($num);\n".
! 546: " var ltitoolsTarget = new Array($num);\n".
! 547: " var ltitoolsWidth = new Array($num);\n".
! 548: " var ltitoolsHeight = new Array($num);\n";
! 549: my $i = 0;
! 550: foreach my $key (sort { $a <=> $b } keys(%{$toolsref})) {
! 551: if (ref($toolsref->{$key})) {
! 552: my $target = $toolsref->{$key}->{'target'};
! 553: my $width = $toolsref->{$key}->{'width'};
! 554: my $height = $toolsref->{$key}->{'height'};
! 555: $toolsjs .= ' ltitools['.$i.'] = '."'$key';\n".
! 556: ' ltitoolsTarget['.$i.'] = '."'$target';\n".
! 557: ' ltitoolsWidth['.$i.'] = '."'$width';\n".
! 558: ' ltitoolsHeight['.$i.'] = '."'$height';\n";
! 559: $i++;
! 560: }
! 561: }
! 562: }
1.8 damieng 563: my %js_lt = &Apache::lonlocal::texthash(
1.1 raeburn 564: invurl => 'Invalid URL',
565: titbl => 'Title is blank',
1.9 ! raeburn 566: invtool => 'Please select an external tool',
1.1 raeburn 567: );
1.8 damieng 568: &js_escape(\%js_lt);
1.1 raeburn 569:
570: my $urlregexp = <<'ENDREGEXP';
571: /^([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
572: ENDREGEXP
573:
574: return <<ENDJS;
575:
576: var regexp = $urlregexp;
577:
1.9 ! raeburn 578: function setExternal(extform,residx,type,exttoolurl) {
1.1 raeburn 579: var title=extform.exttitle.value;
580: if (!String.trim) {
581: String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");}; }
582: if (title == null || title.trim()=="") {
1.8 damieng 583: alert("$js_lt{'titbl'}");
1.1 raeburn 584: extform.exttitle.focus();
585: return;
586: }
1.9 ! raeburn 587: if (type == 'ext') {
! 588: var url=extform.exturl.value;
! 589: if (!regexp.test(url)) {
! 590: alert("$js_lt{'invurl'}");
! 591: extform.exturl.focus();
! 592: return;
! 593: } else {
! 594: url = escape(url);
! 595: title = escape(title);
! 596: if (residx > 0) {
! 597: eval("extform.importdetail.value=title+'='+url+'='+residx;extform.submit();");
! 598: } else {
! 599: eval("extform.importdetail.value=title+'='+url;extform.submit();");
! 600: }
! 601: }
! 602: } else {
1.7 raeburn 603: title = escape(title);
1.9 ! raeburn 604: var info = exttoolurl;
! 605: if (residx == 0) {
! 606: var toolid = parseInt(extform.exttoolid.options[extform.exttoolid.selectedIndex].value);
! 607: if (isNaN(toolid)) {
! 608: alert("$js_lt{'invtool'}");
! 609: return;
! 610: }
! 611: info += ':'+toolid;
! 612: }
! 613: if (extform.exttooltarget.length) {
! 614: for (var i=0; i<extform.exttooltarget.length; i++) {
! 615: if (extform.exttooltarget[i].checked) {
! 616: if (extform.exttooltarget[i].value == 'window') {
! 617: var width = extform.exttoolwidth.value;
! 618: width.trim();
! 619: var height = extform.exttoolheight.value;
! 620: height.trim();
! 621: info += ':window:'+width+':'+height;
! 622: } else {
! 623: info += ':iframe';
! 624: }
! 625: }
! 626: }
! 627: }
! 628: info=escape(info);
1.1 raeburn 629: if (residx > 0) {
1.9 ! raeburn 630: eval("extform.importdetail.value=title+'='+info+'='+residx;extform.submit();");
1.1 raeburn 631: } else {
1.9 ! raeburn 632: eval("extform.importdetail.value=title+'='+info;extform.submit();");
1.1 raeburn 633: }
634: }
635: }
636:
1.9 ! raeburn 637: function editext(residx,type) {
! 638: if (document.getElementById('upload'+type+residx)) {
! 639: var curr = document.getElementById('upload'+type+residx).style.display;
1.1 raeburn 640: if (curr == 'none') {
641: disp = 'block';
642: } else {
643: disp = 'none';
644: }
1.9 ! raeburn 645: document.getElementById('upload'+type+residx).style.display=disp;
1.1 raeburn 646: }
647: resize_scrollbox('contentscroll','1','1');
648: return;
649: }
650:
651: function extUrlPreview(caller) {
652: if (document.getElementById(caller)) {
653: var url = document.getElementById(caller).value;
654: if (regexp.test(url)) {
655: openMyModal(url,500,400,'yes');
656: } else {
1.8 damieng 657: alert("$js_lt{'invurl'}");
1.1 raeburn 658: }
659: }
660: }
661:
1.9 ! raeburn 662: function updateExttool(caller,form,supplementalflag) {
! 663: var prefix = '';
! 664: if (supplementalflag == 1) {
! 665: prefix = 'supp';
! 666: }
! 667: dispdiv = prefix+'tooldispdiv';
! 668: dimendiv = prefix+'tooldimendiv';
! 669: widthinput = prefix+'toolwidth';
! 670: heightinput = prefix+'toolheight';
! 671: if (document.getElementById(dispdiv)) {
! 672: var toolpick = caller.options[caller.selectedIndex].value;
! 673: $toolsjs
! 674: if (toolpick == '') {
! 675: if (document.getElementById(dispdiv)) {
! 676: document.getElementById(dispdiv).style.display = 'none';
! 677: }
! 678: if (document.getElementById(dimendiv)) {
! 679: document.getElementById(dimendiv).style.display = 'none';
! 680: }
! 681: } else {
! 682: if (document.getElementById(dispdiv)) {
! 683: document.getElementById(dispdiv).style.display = 'block';
! 684: }
! 685: if (ltitools.length > 0) {
! 686: for (var j=0; j<ltitools.length; j++) {
! 687: if (ltitools[j] == toolpick) {
! 688: if (form.exttooltarget.length) {
! 689: for (var k=0; k<form.exttooltarget.length; k++) {
! 690: if (form.exttooltarget[k].value == ltitoolsTarget[j]) {
! 691: form.exttooltarget[k].checked = true;
! 692: break;
! 693: }
! 694: }
! 695: }
! 696: if (ltitoolsTarget[j] == 'window') {
! 697: dimen = 'block';
! 698: dimenwidth = ltitoolsWidth[j];
! 699: dimenheight = ltitoolsHeight[j];
! 700: } else {
! 701: dimen = 'none';
! 702: dimenwidth = '';
! 703: dimenheight = '';
! 704: }
! 705: if (document.getElementById(dimendiv)) {
! 706: document.getElementById(dimendiv).style.display = dimen;
! 707: }
! 708: if (document.getElementById(widthinput)) {
! 709: document.getElementById(widthinput).value = dimenwidth;
! 710: }
! 711: if (document.getElementById(heightinput)) {
! 712: document.getElementById(heightinput).value = dimenheight;
! 713: }
! 714: }
! 715: break;
! 716: }
! 717: }
! 718: }
! 719: }
! 720: }
! 721:
! 722: function updateTooldim(form,dimendiv,widthinput,heightinput) {
! 723: if (form.exttooltarget.length) {
! 724: for (var i=0; i<form.exttooltarget.length; i++) {
! 725: if (form.exttooltarget[i].checked) {
! 726: var dimen = 'none';
! 727: if (form.exttooltarget[i].value == 'window') {
! 728: dimen = 'block';
! 729: } else {
! 730: if (document.getElementById(widthinput)) {
! 731: document.getElementById(widthinput).value = '';
! 732: }
! 733: if (document.getElementById(heightinput)) {
! 734: document.getElementById(heightinput).value = '';
! 735: }
! 736: }
! 737: if (document.getElementById(dimendiv)) {
! 738: document.getElementById(dimendiv).style.display = dimen;
! 739: }
! 740: break;
! 741: }
! 742: }
! 743: }
! 744: }
! 745:
1.1 raeburn 746: ENDJS
747:
748: }
749:
750: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>