File:  [LON-CAPA] / loncom / interface / lonextresedit.pm
Revision 1.16: download - view: text, annotated - select for diffs
Tue Apr 25 22:18:59 2017 UTC (7 years, 2 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6754. Make LON-CAPA an LTI Tool Consumer (LTI 1.1).
  When LTI Tool set to be accessed via link to open new tab,
  domain configuration for each Tool includes:
  (a) default link text
  (b) default text block
  (c) whether link text and/or text block content configurable in course.

    1: # The LearningOnline Network
    2: # Documents
    3: #
    4: # $Id: lonextresedit.pm,v 1.16 2017/04/25 22:18:59 raeburn Exp $
    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'};
   59:     my ($supplementalflag,$updated,$output,$errormsg,$residx,$url,$title,
   60:         $symb,$type);
   61:     if (($env{'form.folderpath'} =~ /^supplemental/) && ($env{'form.suppurl'})) {
   62:         $supplementalflag = 1;
   63:         if (&unescape($env{'form.suppurl'}) =~ m{^/adm/$cdom/$cnum/\d+/exttools?$}) {
   64:             $type = 'tool';
   65:         }
   66:     }
   67:     if (($supplementalflag) || ($env{'form.symb'} =~ /^uploaded/)) {
   68:         ($updated,$output,$errormsg,$residx,$url,$title,$symb) =
   69:             &process_changes($supplementalflag,$cdom,$cnum,$chome);
   70:         if ($supplementalflag) {
   71:             if ($url ne &unescape($env{'form.suppurl'})) {
   72:                  $env{'form.suppurl'} = $url;
   73:             }
   74:             if ($title ne $env{'form.title'}) {
   75:                 $env{'form.title'} = $title;
   76:             }
   77:             $env{'form.idx'} = $residx;
   78:         } else {
   79:             if ($symb ne $env{'form.symb'}) {
   80:                 $env{'form.symb'} = $symb;
   81:             }
   82:             if ($url =~ m{/adm/$cdom/$cnum/\d+/exttools?$}) {
   83:                 $type = 'tool';
   84:             }
   85:         }
   86:     } else {
   87:         $errormsg = &mt('Information about external resource to edit is missing.');
   88:     }
   89:     if ($updated) {
   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);
   95:     }
   96:     if ($errormsg) {
   97:         $errormsg = '<p class="LC_error">'.$errormsg.'</p>';
   98:     }
   99:     my %ltitools;
  100:     if ($type eq 'tool') {
  101:         %ltitools = &Apache::lonnet::get_domain_ltitools($cdom);
  102:     }
  103:     my $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
  104:     my $pathitem = '<input type="hidden" name="folderpath" value="'.
  105:                    &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
  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).
  111:               '<div class="LC_left_float">'.
  112:               $output.
  113:               $errormsg.
  114:               &extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,
  115:                            'direct',$env{'form.symb'},$type,$cdom,$cnum,\%ltitools).
  116:               '</div>'.&Apache::loncommon::end_page());
  117:     return OK;
  118: }
  119: 
  120: sub process_changes {
  121:     my ($supplementalflag,$cdom,$cnum,$chome) = @_;
  122:     my ($folder,$container,$output,$errormsg,$updated,$symb,$oldidx,$oldurl,$type,
  123:         $oldtitle,$newidx,$newurl,$newtitle,$residx,$url,$title,$marker,$args);
  124:     if ($env{'form.symb'}) {
  125:         $symb = $env{'form.symb'};
  126:         (my $map,$oldidx,$oldurl)=&Apache::lonnet::decode_symb($symb);
  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'});
  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:         }
  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;
  149:         if ($oldurl =~ m{^/adm/$cdom/$cnum/\d+/exttools?$}) {
  150:             $type = 'tool';
  151:         } else {
  152:             $type = 'ext';
  153:         }
  154:     }
  155:     $url = $oldurl;
  156:     $title = $oldtitle;
  157:     if ($env{'form.importdetail'}) {
  158:         ($newtitle,$newurl,$newidx) =
  159:             map {&unescape($_)} split(/\=/,$env{'form.importdetail'});
  160:         if ($newurl =~ m{^(/adm/$cdom/$cnum/(\d+)/exttools?)\:?(.*)$}) {
  161:             $newurl = $1;
  162:             $marker = $2;
  163:             $args = $3;
  164:         }
  165:     }
  166:     if ($supplementalflag) {
  167:         $residx = $newidx;
  168:     } else {
  169:         $residx = $oldidx;
  170:     }
  171:     if ($folder && $container) {
  172:         if ($env{'form.importdetail'}) {
  173:             my ($errtext,$fatal,$mismatchedid,@imports);
  174:             if (!$supplementalflag) {
  175:                 if (($oldidx) && ($oldidx != $newidx)) {
  176:                     $mismatchedid = 1;
  177:                 }
  178:             }
  179:             if ($mismatchedid) {
  180:                 $errormsg = 'Wrong item identifier';
  181:             } elsif (($newtitle eq $oldtitle) && ($newurl eq $oldurl)) {
  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:                 }
  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);
  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:                     }
  209:                     $LONCAPA::map::resources[$residx] =
  210:                         join(':', ($savetitle,$saveurl,$ext,'normal','res'));
  211:                     my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
  212:                     if ($errtext) {
  213:                         $errormsg = &mt('Update failed: [_1].',$errtext);
  214:                     } else {
  215:                         $updated = 1;
  216:                         $title = $newtitle;
  217:                         if ($newurl ne $oldurl) {
  218:                             $url = $newurl;
  219:                             if ($ext eq 'true') {
  220:                                 $newurl =~ s{^http://}{};
  221:                                 $newurl = "ext/$newurl";
  222:                             }
  223:                         }
  224:                         if (!$supplementalflag) {
  225:                             if ($newurl ne $oldurl) {
  226:                                 $symb = &Apache::lonnet::encode_symb($map,$residx,$newurl);
  227:                             } else {
  228:                                 $symb = $env{'form.symb'};
  229:                                 if ($symb) {
  230:                                     &Apache::lonnet::devalidate_title_cache($symb);
  231:                                 }
  232:                             }
  233:                         }
  234:                         my ($furl,$ferr) = 
  235:                             &Apache::lonuserstate::readmap("$cdom/$cnum");
  236:                         if ($ferr) {
  237:                             $errormsg = &mt('Reload failed: [_1].',$ferr);
  238:                         } else {
  239:                             unless ($supplementalflag) {
  240:                                 &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
  241:                             }
  242:                         }
  243:                     }
  244:                 }
  245:             }
  246:         } else {
  247:             $output = &mt('No change');
  248:         }
  249:     } else {
  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:         }
  255:     }
  256:     return ($updated,$output,$errormsg,$residx,$url,$title,$symb);
  257: }
  258: 
  259: sub update_exttool {
  260:     my ($marker,$cdom,$cnum,$args) = @_;
  261:     my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
  262:     my (%newhash,$changed,@deleted,$errormsg);
  263:     ($newhash{'target'},$newhash{'width'},$newhash{'height'},$newhash{'linktext'},$newhash{'explanation'},
  264:      $newhash{'crslabel'},$newhash{'crstitle'}) = split(/:/,$args);
  265:     foreach my $item ('linktext','explanation','crslabel','crstitle') {
  266:         $newhash{$item} = &unescape($newhash{$item});
  267:     }
  268:     my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
  269:     foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle') {
  270:         $newhash{$item} =~ s/^\s+//;
  271:         $newhash{$item} =~ s/\s+$//;
  272:         if (($item eq 'width') || ($item eq 'height') || ($item eq 'linktext') || ($item eq 'explanation')) {
  273:             if ($newhash{'target'} eq 'iframe') {
  274:                 $newhash{$item} = '';
  275:             }
  276:         }
  277:         if ($toolhash{$item} ne $newhash{$item}) {
  278:             if ($newhash{$item} eq '') {
  279:                 unless (($item eq 'target') ||
  280:                         ((($item eq 'width') || ($item eq 'height') || ($item eq 'linktext') || ($item eq 'explanation')) &&
  281:                          (($newhash{'target'} eq 'window') || 
  282:                           (($newhash{'target'} eq '') && ($toolhash{'target'} eq 'window'))))) {
  283:                     delete($toolhash{$item});
  284:                     push(@deleted,$item);
  285:                     $changed = 1;
  286:                 }
  287:             } else {
  288:                 $toolhash{$item} = $newhash{$item};
  289:                 $changed = 1; 
  290:             }
  291:         }
  292:     }
  293:     if ($changed) {
  294:         my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$cdom,$cnum);
  295:         unless ($putres eq 'ok') {
  296:             $errormsg = &mt('Failed to save updated settings.').' '.&mt('Error: [_1].',$putres);
  297:         }
  298:     }
  299:     if (@deleted) {
  300:         &Apache::lonnet::del('exttool_'.$marker,\@deleted,$cdom,$cnum);
  301:     }
  302:     return ($changed,$errormsg);
  303: }
  304: 
  305: sub extedit_form {
  306:     my ($supplementalflag,$residx,$orig_url,$orig_title,$pathitem,$helpitem,$caller,
  307:         $symb,$type,$cdom,$cnum,$ltitools,$disabled) = @_;
  308:     if ($type ne 'tool') {
  309:         $type = 'ext';
  310:     }
  311:     my %lt = &Apache::lonlocal::texthash(
  312:         ex => 'External Resource',
  313:         et => 'External Tool',
  314:         ed => 'Edit',
  315:         ee => 'External Resource Editor',
  316:         te => 'External Tool Editor',
  317:         pr => 'Preview',
  318:         sv => 'Save',
  319:         ul => 'URL',
  320:         ti => 'Title',
  321:         al => 'Add Link',
  322:         at => 'Add Tool',
  323:     );
  324:     my $tabid = 'aa';
  325:     my $size = 60;
  326:     if ($supplementalflag) {
  327:         $tabid = 'ee';
  328:     }
  329:     my ($formname,$formid,$toggle,$fieldsetid,$urlid,$dispdivstyle,$dimendivstyle,
  330:         $windivstyle,$linktextstyle,$explanationstyle,$labelstyle,$titlestyle,
  331:         $legend,$urlelem,$toolelem,%toolattr);
  332:     $formname = 'new'.$type;
  333:     $toggle = $type;
  334:     $fieldsetid = 'upload'.$type.'form';
  335:     $urlid = $type.'url';
  336:     map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight',
  337:                                        'crstitlediv','crslabeldiv','crstitle','crslabel',
  338:                                        'windiv','linktextdiv','explanationdiv','linktext', 
  339:                                        'explanation');
  340:     $dispdivstyle = 'display:none';
  341:     $dimendivstyle = 'display:none';
  342:     $windivstyle = 'display:none';
  343:     $linktextstyle = 'display:none';
  344:     $explanationstyle = 'display:none';
  345:     $labelstyle = 'display:none';
  346:     $titlestyle = 'display:none';
  347:     if ($supplementalflag) {
  348:         $formname = 'newsupp'.$type;
  349:         $toggle = 'supp'.$type;
  350:         $fieldsetid = 'uploadsupp'.$type.'form';
  351:         $urlid = 'supp'.$type.'url';
  352:         map { $toolattr{$_} = 'supp'.$toolattr{$_}; } (keys(%toolattr));
  353:     }
  354:     my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,$crstitle,$crslabel,
  355:         $fieldsetstyle,$action,$hiddenelem,$form,$width,$height,$tooltarget,
  356:         $linktext,$explanation,%chkstate);
  357:     $fieldsetstyle = 'display: none;';
  358:     $action = '/adm/coursedocs';
  359:     my $protocol = ($ENV{'SERVER_PORT'} == 443?'https':'http');
  360:     my $rows = 2;
  361:     my $cols = 20;
  362:     if ($residx) {
  363:         if ($caller eq 'direct') {
  364:             $fieldsetstyle = 'display: block;';
  365:             $action = '/adm/extresedit';
  366:             $rows = 10;
  367:             $cols = 45;
  368:             if ($type eq 'tool') {
  369:                 $legend = $lt{'ee'};
  370:             } else {
  371:                 $legend = $lt{'te'};
  372:             }
  373:             $legend = '<legend>'.$legend.'</legend>';
  374:             if ($symb) {
  375:                 $hiddenelem = '<input type="hidden" name="symb" value="'.$symb.'" />';
  376:             } elsif ($supplementalflag) {
  377:                 $hiddenelem = '<input type="hidden" name="suppurl" value="'.
  378:                               &HTML::Entities::encode(&escape($orig_url),'<>&"').'" />'."\n".
  379:                               '<input type="hidden" name="title" value="'.
  380:                               &HTML::Entities::encode(&escape($orig_title),'<>&"').'" />';
  381:             }
  382:         } else {
  383:             $link = '<a class="LC_docs_ext_edit" href="javascript:editext('."'$residx','$type'".');">'.$lt{'ed'}.'</a>&nbsp;'."\n";
  384:             $size = 40;
  385:             $active = '<input type="hidden" name="active" value="'.$tabid.'" />';
  386:         }
  387:         $formname = 'edit'.$type.'_'.$residx;
  388:         $fieldsetid = 'upload'.$type.$residx;
  389:         $urlid = $type.'url_'.$residx;
  390:         map { $toolattr{$_} .= '_'.$residx; } (keys(%toolattr));
  391:         $srcclass = ' class="LC_nobreak"';
  392:         if ($type eq 'ext') {
  393:             $extsrc = '<span class="LC_docs_ext_edit">'.$lt{'ul'}.'&nbsp;</span>';
  394:             $preview = '&nbsp;<a class="LC_docs_ext_edit" href="javascript:extUrlPreview('."'$urlid','$protocol'".');">'.$lt{'pr'}.'</a>';
  395:         }
  396:         $title = '<span class="LC_docs_ext_edit">'.$lt{'ti'}.'&nbsp;</span>';
  397:         $save = $lt{'sv'};
  398:     } else {
  399:         $link = $lt{'ex'};
  400:         if ($type eq 'tool') {
  401:             $link = $lt{'et'};
  402:         }
  403:         $link = '<a class="LC_menubuttons_link" href="javascript:toggleUpload('."'$toggle'".');">'.$link.'</a>'.$helpitem;
  404:         if ($type eq 'tool') {
  405:             $legend = $lt{'te'};
  406:         } else {
  407:             $legend = $lt{'ee'};
  408:         }
  409:         $legend = '<legend>'.$legend.'</legend>';
  410:         $title = $lt{'ti'}.':<br />';
  411:         $residx = 0;
  412:         if ($type eq 'ext') {
  413:             $orig_url = 'http://';
  414:             $orig_title = $lt{'ex'};
  415:             $extsrc = $lt{'ul'}.':<br />';
  416:             $preview = '<input type="button" name="view" value="'.$lt{'pr'}.'" onclick="javascript:extUrlPreview('."'$urlid','$protocol'".');"'.$disabled.' />';
  417:             $save = $lt{'al'};
  418:         } else {
  419:             $orig_title = $lt{'et'};
  420:             $save = $lt{'at'};
  421:             $orig_url = "/adm/$cdom/$cnum/new/exttool"; 
  422:         }
  423:         $pathitem .= '<br />';
  424:     }
  425:     $formid = $formname;
  426:     if ($type eq 'ext') {
  427:         $urlelem = '<input type="text" size="'.$size.'" name="exturl" id="'.$urlid.'" value="'.$orig_url.'"'.$disabled.' />';
  428:     } else {
  429:         my $class = 'LC_nobreak';
  430:         if ($residx) {
  431:             $class = 'LC_docs_ext_edit LC_nobreak'; 
  432:             if ($orig_url =~ m{^/adm/$cdom/$cnum/(\d+)/exttools?$}) {
  433:                 my $marker = $1;
  434:                 my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
  435:                 if ($toolhash{'id'}) {
  436:                     if (ref($ltitools) eq 'HASH') {
  437:                         if (keys(%{$ltitools})) {
  438:                             if (ref($ltitools->{$toolhash{'id'}}) eq 'HASH') {
  439:                                 my $tooltitle = $ltitools->{$toolhash{'id'}}->{'title'};
  440:                                 my $icon = $ltitools->{$toolhash{'id'}}->{'image'};
  441:                                 my $image;
  442:                                 if ($icon) {
  443:                                     $image = '<img src="'.$icon.'" alt="'.$tooltitle.'" />';
  444:                                 }
  445:                                 $tooltarget = $toolhash{'target'};
  446:                                 if ($tooltarget eq 'window') {
  447:                                     $dimendivstyle = 'display:block';
  448:                                     $windivstyle = 'display:block';
  449:                                     $chkstate{'window'} = 'checked="checked" ';
  450:                                 } else {
  451:                                     $chkstate{'iframe'} = 'checked="checked" ';
  452:                                 }
  453:                                 $width = $toolhash{'width'};
  454:                                 $height = $toolhash{'height'};
  455:                                 $linktext = $toolhash{'linktext'};
  456:                                 $explanation = $toolhash{'explanation'};
  457:                                 if (ref($ltitools->{$toolhash{'id'}}->{'crsconf'}) eq 'HASH') {
  458:                                     if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'title'}) {
  459:                                         $crstitle = $toolhash{'crstitle'};
  460:                                         $titlestyle = 'display:inline';
  461:                                     }
  462:                                     if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'label'}) {  
  463:                                         $crslabel = $toolhash{'crslabel'};
  464:                                         $labelstyle = 'display:inline';
  465:                                     }
  466:                                     if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'target'}) {
  467:                                         $dispdivstyle = 'display:block';
  468:                                     }
  469:                                     if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'linktext'}) {
  470:                                         $linktextstyle = 'padding:0;display:inline';
  471:                                     }
  472:                                     if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'explanation'}) {
  473:                                         $explanationstyle = 'padding:0;display:inline';
  474:                                     }
  475:                                 }
  476:                                 $toolelem = '<span class="LC_nobreak">'.$image.'&nbsp;'.$tooltitle.'</span><br />';
  477:                             }
  478:                         }
  479:                     }
  480:                 }
  481:             }
  482:         } else {
  483:             $toolelem = '<span class="LC_docs_ext_edit">'."\n".
  484:                        '<select name="exttoolid" id="LC_exttoolid" onchange="javascript:updateExttool(this,'.
  485:                        'this.form,'."'$supplementalflag'".');"'.$disabled.'>'."\n".
  486:                        '<option value="" selected="selected">'.&mt('Select').'</option>';
  487:             my %bynum;
  488:             if (ref($ltitools) eq 'HASH') {
  489:                 foreach my $id (keys(%{$ltitools})) {
  490:                     if (ref($ltitools->{$id}) eq 'HASH') {
  491:                         my $order = $ltitools->{$id}->{'order'};
  492:                         $bynum{$order} = [$id,$ltitools->{$id}];
  493:                     }
  494:                 }
  495:             }
  496:             foreach my $item (sort { $a <=> $b } keys(%bynum)) {
  497:                 if (ref($bynum{$item}) eq 'ARRAY') {
  498:                     if (ref($bynum{$item}->[1]) eq 'HASH') {
  499:                         my $tooltitle = $bynum{$item}->[1]->{'title'};
  500:                         my $icon =  $bynum{$item}->[1]->{'image'};
  501:                         $toolelem .= '<option value="'.$bynum{$item}->[0].'">'.$tooltitle.'</option>';
  502:                     }
  503:                 }
  504:             }
  505:             $toolelem .= '</select></span><br />';
  506:             $crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
  507:             $crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'};
  508:         }
  509:         $toolelem .= '<div id="'.$toolattr{'dispdiv'}.'" style="'.$dispdivstyle.'">'.
  510:                     '<span class="'.$class.'">'.&mt('Display target:').'&nbsp;'.
  511:                     '<label><input type="radio" name="exttooltarget" value="iframe" '.$chkstate{'iframe'}.'onclick="updateTooldim(this.form,'.
  512:                     "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
  513:                     '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('iframe').'</label>'.('&nbsp;'x2).
  514:                     '<label><input type="radio" name="exttooltarget" value="window" '.$chkstate{'window'}.'onclick="updateTooldim(this.form,'.
  515:                     "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
  516:                     '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('window').'</label></span>'.
  517:                     '<div id="'.$toolattr{'dimendiv'}.'" style="'.$dimendivstyle.'"><span class="'.$class.'">'.
  518:                     &mt('Width').':&nbsp;<input type="text" size="4" id="'.$toolattr{'dimenwidth'}.'" name="exttoolwidth" value="'.$width.'"'.$disabled.' />'.('&nbsp;'x2).
  519:                     &mt('Height').':&nbsp;<input type="text" size="4" id="'.$toolattr{'dimenheight'}.'" name="exttoolheight" value="'.$height.'"'.$disabled.' /></span>'."\n".
  520:                     '</div></div>';
  521:         $toolelem .= '<div id="'.$toolattr{'windiv'}.'" style="'.$windivstyle.'">'.
  522:                      '<div id="'.$toolattr{'linktextdiv'}.'" class="LC_left_float" style="'.$linktextstyle.'">'.
  523:                      '<span class="'.$class.'">'.&mt('Link Text').'</span><br /><input type="text" size="25" id="'.$toolattr{'linktext'}.
  524:                      '" name="exttoollinktext" value="'.$linktext.'"'.$disabled.' />'.
  525:                      '</div><div id="'.$toolattr{'explanationdiv'}.'" class="LC_left_float" style="'.$explanationstyle.'">'.
  526:                      '<span class="'.$class.'">'.&mt('Explanation').'</span><br />'.
  527:                      '<textarea rows="'.$rows.'" cols="'.$cols.'" id="'.$toolattr{'explanation'}.'" name="exttoolexplanation" '.$disabled.'>'.
  528:                      $explanation.'</textarea></div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
  529:                      '</div>';
  530:         $toolelem .= '<div id="'.$toolattr{'crslabeldiv'}.'" style="'.$labelstyle.'">'.
  531:                     '<span class="'.$class.'">'.&mt('Course label:').'&nbsp;'.
  532:                     '<input type="text" id="'.$toolattr{'crslabel'}.'" name="exttoollabel" value="'.$crslabel.'"'.$disabled.' /></span><br />'.
  533:                     '</div>'.
  534:                     '<div id="'.$toolattr{'crstitlediv'}.'" style="'.$titlestyle.'">'.
  535:                     '<span class="'.$class.'">'.&mt('Course title:').'&nbsp;'.
  536:                     '<input type="text" id="'.$toolattr{'crstitle'}.'" name="exttooltitle" value="'.$crstitle.'"'.$disabled.' /></span><br />'.
  537:                     '</div>';
  538:     }
  539:     my $chooser = $toolelem;
  540:     if ($type eq 'ext') {
  541:         $chooser = "
  542: <div>
  543: <span$srcclass>
  544: $extsrc
  545: $urlelem
  546: $preview
  547: </span>
  548: </div>
  549: ";
  550:     }
  551:     $form = <<ENDFORM;
  552: <form action="$action" method="post" name="$formname" id="$formid">
  553: <fieldset id="$fieldsetid" style="$fieldsetstyle">
  554: $legend
  555: $active
  556: $chooser
  557: <div>
  558: <span$srcclass>
  559: $title
  560: <input type="text" size="$size" name="exttitle" value="$orig_title" $disabled />
  561: <input type="hidden" name="importdetail" value="" />
  562: $pathitem
  563: $hiddenelem
  564: <input type="button" value="$save" onclick="javascript:setExternal(this.form,'$residx','$type','$orig_url','$supplementalflag');" $disabled />
  565: </span>
  566: </div>
  567: </fieldset>
  568: </form>
  569: ENDFORM
  570:     if (wantarray) {
  571:         return ($link,$form);
  572:     } else {
  573:         return $link.$form;
  574:     }
  575: }
  576: 
  577: sub display_editor {
  578:     my ($url,$folderpath,$symb,$idx,$type,$cdom,$cnum,$hostname) = @_;
  579:     my ($residx,$supplementalflag,$title,$pathitem,$output,$js,$navmap);
  580:     if ($folderpath =~ /^supplemental/) {
  581:         $supplementalflag = 1;
  582:         $residx = $idx;
  583:         $title = &unescape($env{'form.title'});
  584:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
  585:     } elsif ($symb =~ /^uploaded/) {
  586:         (my $map,$residx,my $res) =
  587:             &Apache::lonnet::decode_symb($symb);
  588:         $title = &Apache::lonnet::gettitle($symb);
  589:         my $path = &Apache::loncommon::symb_to_docspath($symb,\$navmap);
  590:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($path,'<>&"').'" />';
  591:     }
  592:     my %ltitools;
  593:     if ($type eq 'tool') {
  594:         %ltitools = &Apache::lonnet::get_domain_ltitools($cdom);
  595:     }
  596:     $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
  597:     my $args = { 'force_register' => $env{'form.register'} };
  598:     if ($hostname) {
  599:         $args->{'hostname'} = $hostname;
  600:     }
  601:     my $description = 'External Resource Editor';
  602:     if ($type eq 'tool') {
  603:         $description = 'External Tool Editor';
  604:     }
  605:     return &Apache::loncommon::start_page($description,$js,$args).
  606:            '<div class="LC_left_float">'.
  607:            &extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,'direct',
  608:                          $symb,$type,$cdom,$cnum,\%ltitools).
  609:            '</div>'.
  610:            &Apache::loncommon::end_page();
  611: }
  612: 
  613: sub extedit_javascript {
  614:     my ($toolsref) = @_;
  615:     my $toolsjs;
  616:     if (ref($toolsref) eq 'HASH') {
  617:         my $num = scalar(keys(%{$toolsref}));
  618:         $toolsjs = "        var ltitools = new Array($num);\n".
  619:                    "        var ltitoolsTarget = new Array($num);\n".
  620:                    "        var ltitoolsWidth = new Array($num);\n".
  621:                    "        var ltitoolsHeight = new Array($num);\n".
  622:                    "        var ltitoolsLinkDef = new Array($num);\n".
  623:                    "        var ltitoolsExplainDef = new Array($num);\n".
  624:                    "        var ltitoolsDisplay = new Array($num);\n".
  625:                    "        var ltitoolsLink = new Array($num);\n".
  626:                    "        var ltitoolsExplain = new Array($num);\n".
  627:                    "        var ltitoolsLabel = new Array($num);\n".
  628:                    "        var ltitoolsTitle = new Array($num);\n";
  629:         my $i = 0;
  630:         foreach my $key (sort { $a <=> $b } keys(%{$toolsref})) {
  631:             if (ref($toolsref->{$key}) eq 'HASH') {
  632:                 if (ref($toolsref->{$key}->{'display'}) eq 'HASH') {
  633:                     my $target = $toolsref->{$key}->{'display'}->{'target'};
  634:                     my $width = $toolsref->{$key}->{'display'}->{'width'};
  635:                     my $height = $toolsref->{$key}->{'display'}->{'height'};
  636:                     my $linkdef = $toolsref->{$key}->{'display'}->{'linktext'};
  637:                     my $explaindef = $toolsref->{$key}->{'display'}->{'explanation'};
  638:                     $toolsjs .= '        ltitools['.$i.'] = '."'$key';\n".
  639:                                 '        ltitoolsTarget['.$i.'] = '."'$target';\n".
  640:                                 '        ltitoolsWidth['.$i.'] = '."'$width';\n".
  641:                                 '        ltitoolsHeight['.$i.'] = '."'$height';\n".
  642:                                 '        ltitoolsLinkDef['.$i.'] = '."'$linkdef';\n".
  643:                                 '        ltitoolsExplainDef['.$i.'] = '."'$explaindef';\n";
  644:                 }
  645:                 if (ref($toolsref->{$key}->{'crsconf'}) eq 'HASH') {
  646:                     my $display = $toolsref->{$key}->{'crsconf'}->{'target'};
  647:                     $toolsjs .= '         ltitoolsDisplay['.$i.'] = '."'$display';\n";
  648:                     my $linktext = $toolsref->{$key}->{'crsconf'}->{'linktext'};
  649:                     $toolsjs .= '         ltitoolsLink['.$i.'] = '."'$linktext';\n";
  650:                     my $explanation = $toolsref->{$key}->{'crsconf'}->{'explanation'};
  651:                     $toolsjs .= '         ltitoolsExplain['.$i.'] = '."'$explanation';\n";
  652:                     my $label = $toolsref->{$key}->{'crsconf'}->{'label'};
  653:                     $toolsjs .= '         ltitoolsLabel['.$i.'] = '."'$label';\n";
  654:                     my $title = $toolsref->{$key}->{'crsconf'}->{'title'};
  655:                     $toolsjs .= '         ltitoolsTitle['.$i.'] = '."'$title';\n";
  656:                 }
  657:                 $i++;
  658:             }
  659:         }
  660:     }
  661:     my %js_lt = &Apache::lonlocal::texthash(
  662:         invurl  => 'Invalid URL',
  663:         titbl   => 'Title is blank',
  664:         invtool => 'Please select an external tool',
  665:     );
  666:     &js_escape(\%js_lt);
  667: 
  668:     my $urlregexp = <<'ENDREGEXP';
  669: /^([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
  670: ENDREGEXP
  671: 
  672:     return <<ENDJS;
  673: 
  674: var regexp = $urlregexp;
  675: 
  676: function setExternal(extform,residx,type,exttoolurl,supplementalflag) {
  677:     var title=extform.exttitle.value;
  678:     if (!String.trim) {
  679:         String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");};    }
  680:     if (title == null || title.trim()=="") {
  681:         alert("$js_lt{'titbl'}");
  682:         extform.exttitle.focus();
  683:         return;
  684:     }
  685:     if (type == 'ext') {
  686:         var url=extform.exturl.value;
  687:         if (!regexp.test(url)) {
  688:             alert("$js_lt{'invurl'}");
  689:             extform.exturl.focus();
  690:             return;
  691:         } else {
  692:             url = escape(url);
  693:             title = escape(title);
  694:             if (residx > 0) {
  695:                eval("extform.importdetail.value=title+'='+url+'='+residx;extform.submit();");
  696:             } else {
  697:                eval("extform.importdetail.value=title+'='+url;extform.submit();");
  698:             }
  699:         }
  700:     } else {
  701:         title = escape(title);
  702:         var info = exttoolurl;
  703:         if (residx == 0) {
  704:             var toolid = parseInt(extform.exttoolid.options[extform.exttoolid.selectedIndex].value);
  705:             if (isNaN(toolid)) {
  706:                 alert("$js_lt{'invtool'}");
  707:                 return;
  708:             }
  709:             info += ':'+toolid;
  710:         }
  711:         var prefix = '';
  712:         if (supplementalflag == 1) {
  713:            prefix = 'supp';
  714:         }
  715:         var dispdiv = prefix+'tooldispdiv';
  716:         var windiv = prefix+'toolwindiv';
  717:         if (residx > 0) {
  718:             dispdiv += '_'+residx;
  719:             windiv += '_'+residx;
  720:         }
  721:         if (document.getElementById(dispdiv)) {
  722:             if (document.getElementById(dispdiv).style.display == 'block') {
  723:                 if (extform.exttooltarget.length) {
  724:                     for (var i=0; i<extform.exttooltarget.length; i++) {
  725:                         if (extform.exttooltarget[i].checked) {
  726:                             if (extform.exttooltarget[i].value == 'window') {
  727:                                 var width = extform.exttoolwidth.value;
  728:                                 width.trim();
  729:                                 var height = extform.exttoolheight.value;
  730:                                 height.trim();
  731:                                 info += ':window:'+width+':'+height;
  732:                             } else {
  733:                                 info += ':iframe::';
  734:                             }
  735:                         }
  736:                     }
  737:                 }
  738:             } else {
  739:                 info += ':::';
  740:             }
  741:         } else {
  742:             info += ':::';
  743:         }
  744:         if (document.getElementById(windiv)) {
  745:             if (document.getElementById(windiv).style.display == 'block') {
  746:                 var linktextdiv = prefix+'toollinktextdiv';
  747:                 var explanationdiv = prefix+'toolexplanationdiv';
  748:                 if (residx > 0) {
  749:                     linktextdiv += '_'+residx;
  750:                     explanationdiv += '_'+residx;
  751:                 }
  752:                 if (document.getElementById(linktextdiv).style.display == 'inline') {
  753:                     var linktext = extform.exttoollinktext.value;
  754:                     linktext.trim();
  755:                     info += ':'+escape(linktext);
  756:                 } else {
  757:                     info += ':';
  758:                 }
  759:                 if (document.getElementById(explanationdiv).style.display == 'inline') {
  760:                     var explaintext = extform.exttoolexplanation.value;
  761:                     explaintext.trim();
  762:                     info += ':'+escape(explaintext);
  763:                 } else {
  764:                     info += ':';
  765:                 }
  766:             } else {
  767:                 info += '::';
  768:             }
  769:         } else {
  770:             info += '::';
  771:         }
  772:         var labelinput = prefix+'toolcrslabel';
  773:         var titleinput = prefix+'toolcrstitle';
  774:         if (residx > 0) {
  775:             labelinput += '_'+residx;
  776:             titleinput += '_'+residx;
  777:         }
  778:         if (document.getElementById(labelinput)) {
  779:             var crslabel = document.getElementById(labelinput).value;
  780:             crslabel.trim();
  781:             info += ':'+escape(crslabel);
  782:         } else {
  783:             info += ':';
  784:         } 
  785:         if (document.getElementById(titleinput)) {
  786:             var crstitle = document.getElementById(titleinput).value;
  787:             crstitle.trim();
  788:             info += ':'+escape(crstitle);
  789:         } else {
  790:             info += ':';
  791:         }
  792:         info=escape(info);
  793:         if (residx > 0) {
  794:             eval("extform.importdetail.value=title+'='+info+'='+residx;extform.submit();");
  795:         } else {
  796:             eval("extform.importdetail.value=title+'='+info;extform.submit();");
  797:         }
  798:     }
  799: }
  800: 
  801: function editext(residx,type) {
  802:     if (document.getElementById('upload'+type+residx)) {
  803:         var curr = document.getElementById('upload'+type+residx).style.display;
  804:         if (curr == 'none') {
  805:             disp = 'block';
  806:         } else {
  807:             disp = 'none';
  808:         }
  809:         document.getElementById('upload'+type+residx).style.display=disp;
  810:     }
  811:     resize_scrollbox('contentscroll','1','1');
  812:     return;
  813: }
  814: 
  815: function extUrlPreview(caller,protocol) {
  816:     if (document.getElementById(caller)) {
  817:         var url = document.getElementById(caller).value;
  818:         if (regexp.test(url)) {
  819:             var http_regex = /^http\:\/\//gi;
  820:             if ((protocol == 'https') && (http_regex.test(url))) {
  821:                 window.open(url,"externalpreview","height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1");
  822:             } else {
  823:                 openMyModal(url,500,400,'yes');
  824:             }
  825:         } else {
  826:             alert("$js_lt{'invurl'}");
  827:         }
  828:     }
  829: }
  830: 
  831: function updateExttool(caller,form,supplementalflag) {
  832:     var prefix = '';
  833:     if (supplementalflag == 1) {
  834:         prefix = 'supp';
  835:     }
  836:     dispdiv = prefix+'tooldispdiv';
  837:     dimendiv = prefix+'tooldimendiv';
  838:     widthinput = prefix+'tooldimenwidth';
  839:     heightinput = prefix+'tooldimenheight';
  840:     labeldiv = prefix+'toolcrslabeldiv';
  841:     titlediv = prefix+'toolcrstitlediv';
  842:     labelinput = prefix+'toolcrslabel';
  843:     titleinput = prefix+'toolcrstitle';
  844:     windiv = prefix+'toolwindiv';  
  845:     linktextdiv = prefix+'toollinktextdiv';
  846:     linktextinput = prefix+'toollinktext';
  847:     explanationdiv = prefix+'toolexplanationdiv';
  848:     explanationinput = prefix+'toolexplanation';
  849:     if (document.getElementById(dispdiv)) {
  850:         var toolpick = caller.options[caller.selectedIndex].value;
  851:         $toolsjs
  852:         if (toolpick == '') {
  853:             if (document.getElementById(dispdiv)) {
  854:                 document.getElementById(dispdiv).style.display = 'none';    
  855:             }
  856:             if (document.getElementById(dimendiv)) {
  857:                 document.getElementById(dimendiv).style.display = 'none';
  858:             }
  859:             if (document.getElementById(windiv)) {
  860:                 document.getElementById(windiv).style.display = 'none';
  861:             }
  862:             if (document.getElementById(linktextdiv)) {
  863:                 document.getElementById(linktextdiv).style.display = 'none';
  864:             }
  865:             if (document.getElementById(explanationdiv)) {
  866:                 document.getElementById(explanationdiv).style.display = 'none';
  867:             }
  868:             if (document.getElementById(labeldiv)) {
  869:                 document.getElementById(labeldiv).style.display = 'none';
  870:             }
  871:             if (document.getElementById(titlediv)) {
  872:                 document.getElementById(titlediv).style.display = 'none';
  873:             }
  874:         } else {
  875:             if (ltitools.length > 0) {
  876:                 for (var j=0; j<ltitools.length; j++) {
  877:                     if (ltitools[j] == toolpick) {
  878:                         if (document.getElementById(dispdiv)) {
  879:                             if (ltitoolsDisplay[j]) {
  880:                                 document.getElementById(dispdiv).style.display = 'block';
  881:                                 if (form.exttooltarget.length) {
  882:                                     for (var k=0; k<form.exttooltarget.length; k++) {
  883:                                         if (form.exttooltarget[k].value == ltitoolsTarget[j]) {
  884:                                             form.exttooltarget[k].checked = true;
  885:                                             break;
  886:                                         }
  887:                                     }
  888:                                 }
  889:                             }
  890:                             var dimen = 'none';
  891:                             var dimenwidth = '';
  892:                             var dimenheight = '';
  893:                             if ((ltitoolsDisplay[j]) && (ltitoolsTarget[j] == 'window')) {
  894:                                 dimen = 'block';
  895:                                 dimenwidth = ltitoolsWidth[j];
  896:                                 dimenheight = ltitoolsHeight[j];                    
  897:                             }
  898:                             if (document.getElementById(dimendiv)) {
  899:                                 document.getElementById(dimendiv).style.display = dimen;
  900:                             }
  901:                             if (document.getElementById(widthinput)) {
  902:                                 document.getElementById(widthinput).value = dimenwidth;
  903:                             }
  904:                             if (document.getElementById(heightinput)) {
  905:                                 document.getElementById(heightinput).value = dimenheight;
  906:                             }
  907:                         }
  908:                         if (document.getElementById(windiv)) {
  909:                             if (ltitoolsTarget[j] == 'window') {
  910:                                 document.getElementById(windiv).style.display = 'block';
  911:                             } else {
  912:                                 document.getElementById(windiv).style.display = 'none';
  913:                             }
  914:                             if (document.getElementById(linktextdiv)) {
  915:                                 if ((ltitoolsLink[j]) && (ltitoolsTarget[j] == 'window')) {
  916:                                     document.getElementById(linktextdiv).style.display = 'inline';
  917:                                 } else {
  918:                                     document.getElementById(linktextdiv).style.display = 'none';
  919:                                 }
  920:                             }
  921:                             if (document.getElementById(linktextinput)) {
  922:                                 if ((ltitoolsLink[j]) && (ltitoolsTarget[j] == 'window')) {
  923:                                     document.getElementById(linktextinput).value = ltitoolsLinkDef[j]; 
  924:                                 } else {
  925:                                     document.getElementById(linktextinput).value = '';
  926:                                 }
  927:                             }
  928:                             if (document.getElementById(explanationdiv)) {
  929:                                 if ((ltitoolsExplain[j]) && (ltitoolsTarget[j] == 'window')) {
  930:                                     document.getElementById(explanationdiv).style.display = 'inline';
  931:                                 } else {
  932:                                     document.getElementById(explanationdiv).style.display = 'none';
  933:                                 }
  934:                             }
  935:                             if (document.getElementById(explanationinput)) {
  936:                                 if ((ltitoolsExplain[j]) && (ltitoolsTarget[j] == 'window')) {
  937:                                     document.getElementById(explanationinput).value = ltitoolsExplainDef[j];
  938:                                 } else {
  939:                                     document.getElementById(explananationinput).value = '';
  940:                                 }
  941:                             }
  942:                         }
  943:                         if (document.getElementById(labeldiv)) {
  944:                             if (ltitoolsLabel[j]) {
  945:                                 document.getElementById(labeldiv).style.display = 'inline';
  946:                             } else {
  947:                                 document.getElementById(labeldiv).style.display = 'none';
  948:                             } 
  949:                         }
  950:                         if (document.getElementById(titlediv)) {
  951:                             if (ltitoolsTitle[j]) {
  952:                                 document.getElementById(titlediv).style.display = 'inline';
  953:                             } else {
  954:                                 document.getElementById(titlediv).style.display = 'none';
  955:                             }
  956:                         }
  957:                         break;
  958:                     }
  959:                 }
  960:             }
  961:         }
  962:     }
  963: }
  964: 
  965: function updateTooldim(form,dimendiv,windiv,widthinput,heightinput,linkinput,explaininput) {
  966:     if (form.exttooltarget.length) {
  967:         for (var i=0; i<form.exttooltarget.length; i++) {
  968:             if (form.exttooltarget[i].checked) {
  969:                 var dimen = 'none';
  970:                 var linkconf = 'none'; 
  971:                 if (form.exttooltarget[i].value == 'window') {
  972:                     dimen = 'block';
  973:                     linkconf = 'block';
  974:                 } else {
  975:                     if (document.getElementById(widthinput)) {
  976:                         document.getElementById(widthinput).value = '';
  977:                     }
  978:                     if (document.getElementById(heightinput)) {
  979:                         document.getElementById(heightinput).value = '';
  980:                     }
  981:                     if (document.getElementById(linkinput)) {
  982:                         document.getElementById(linkinput).value = '';
  983:                     }
  984:                     if (document.getElementById(explaininput)) {
  985:                         document.getElementById(explaininput).value = '';
  986:                     }
  987:                 }
  988:                 if (document.getElementById(dimendiv)) {
  989:                     document.getElementById(dimendiv).style.display = dimen;
  990:                 }
  991:                 if (document.getElementById(windiv)) {
  992:                     document.getElementById(windiv).style.display = linkconf;
  993:                 }  
  994:                 break;
  995:             }
  996:         }
  997:     }
  998: }
  999: 
 1000: ENDJS
 1001: 
 1002: }
 1003: 
 1004: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>