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