File:  [LON-CAPA] / loncom / interface / lonextresedit.pm
Revision 1.34: download - view: text, annotated - select for diffs
Wed Jul 12 00:05:02 2023 UTC (10 months, 1 week ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, HEAD
- Satisfy w3c HTML validation which does not allow id="" attributes.

    1: # The LearningOnline Network
    2: # Documents
    3: #
    4: # $Id: lonextresedit.pm,v 1.34 2023/07/12 00:05:02 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+/ext\.tool$}) {
   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+/ext\.tool$}) {
   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:         my (%domtools,%crstools);
  102:         my %tooltypes = &Apache::loncommon::usable_exttools();
  103:         if ($tooltypes{'dom'}) {
  104:             %domtools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
  105:         }
  106:         if ($tooltypes{'crs'}) {
  107:             %crstools = &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
  108:         }
  109:         %ltitools = (
  110:                       dom => \%domtools,
  111:                       crs => \%crstools,
  112:                     );
  113:     }
  114:     my $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
  115:     my $pathitem = '<input type="hidden" name="folderpath" value="'.
  116:                    &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
  117:     my $description = 'External Resource Editor';
  118:     if ($type eq 'tool') {
  119:         $description = 'External Tool Editor'; 
  120:     }
  121:     $r->print(&Apache::loncommon::start_page($description,$js).
  122:               '<div class="LC_left_float">'.
  123:               $output.
  124:               $errormsg.
  125:               &extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,
  126:                            'direct',$env{'form.symb'},$type,$cdom,$cnum,\%ltitools).
  127:               '</div>'.&Apache::loncommon::end_page());
  128:     return OK;
  129: }
  130: 
  131: sub process_changes {
  132:     my ($supplementalflag,$cdom,$cnum,$chome) = @_;
  133:     my ($folder,$container,$output,$errormsg,$updated,$symb,$oldidx,$oldurl,$type,
  134:         $oldtitle,$newidx,$newurl,$newtitle,$residx,$url,$title,$marker,$args);
  135:     if ($env{'form.symb'}) {
  136:         $symb = $env{'form.symb'};
  137:         (my $map,$oldidx,$oldurl)=&Apache::lonnet::decode_symb($symb);
  138:         if ($map =~ m{^uploaded/$cdom/$cnum/(default(_\d+|))\.(sequence|page)$}) {
  139:             $folder = $1;
  140:             $container = $3;
  141:         }
  142:         $oldtitle = &Apache::lonnet::gettitle($env{'form.symb'});
  143:         if ($oldurl =~ m{^ext/(.+)$}) {
  144:             my $external = $1;
  145:             if ($external =~ m{^https://}) {
  146:                 $oldurl = $external;
  147:             } else {
  148:                 $oldurl = 'http://'.$oldurl;
  149:             }
  150:             $type = 'ext';
  151:         } else {
  152:             $type = 'tool';
  153:         }
  154:     } elsif ($env{'form.folderpath'}) {
  155:         $folder = &unescape( (split('&',$env{'form.folderpath'}))[-2] );
  156:         $oldurl = &unescape($env{'form.suppurl'});
  157:         $oldtitle = &unescape($env{'form.title'});
  158:         $container = 'sequence';
  159:         $supplementalflag = 1;
  160:         if ($oldurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
  161:             $type = 'tool';
  162:         } else {
  163:             $type = 'ext';
  164:         }
  165:     }
  166:     $url = $oldurl;
  167:     $title = $oldtitle;
  168:     if ($env{'form.importdetail'}) {
  169:         ($newtitle,$newurl,$newidx) =
  170:             map {&unescape($_)} split(/\=/,$env{'form.importdetail'});
  171:         if ($newurl =~ m{^(/adm/$cdom/$cnum/(\d+)/ext\.tool)\:?(.*)$}) {
  172:             $newurl = $1;
  173:             $marker = $2;
  174:             $args = $3;
  175:             if ((!$symb) && (!$supplementalflag)) {
  176:                 $symb = "uploaded/$cdom/$cnum/$folder.$container"."___$newidx"."___adm/$cdom/$cnum/$marker/ext.tool";
  177:             }
  178:         }
  179:     }
  180:     if ($supplementalflag) {
  181:         $residx = $newidx;
  182:     } else {
  183:         $residx = $oldidx;
  184:     }
  185:     if ($folder && $container) {
  186:         if ($env{'form.importdetail'}) {
  187:             my ($errtext,$fatal,$mismatchedid,$needreload,$newgradable,@imports);
  188:             if (!$supplementalflag) {
  189:                 if (($oldidx) && ($oldidx != $newidx)) {
  190:                     $mismatchedid = 1;
  191:                 }
  192:             }
  193:             if ($mismatchedid) {
  194:                 $errormsg = 'Wrong item identifier';
  195:             } elsif (($newtitle eq $oldtitle) && ($newurl eq $oldurl)) {
  196:                 if ($type eq 'tool') {
  197:                     if ($args) {
  198:                         ($updated,$newgradable,$errormsg) = &update_exttool($marker,$cdom,$cnum,
  199:                                                                             $supplementalflag,$args);
  200:                         if ($updated) {
  201:                             if ($newgradable) {
  202:                                 my $map = "/uploaded/$cdom/$cnum/$folder.$container";
  203:                                 my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
  204:                                 if ($fatal) {
  205:                                     $errormsg = &mt('Update failed: [_1].',$errtext);
  206:                                 } else {
  207:                                     &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',
  208:                                                                   $newgradable,'string_yesno');
  209:                                     my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,1);
  210:                                     if ($errtext) {
  211:                                         $errormsg = &mt('Update failed: [_1].',$errtext);
  212:                                     } else {
  213:                                         $needreload = 1;
  214:                                     }
  215:                                 }
  216:                             }
  217:                         } else {
  218:                             $output = &mt('No change');
  219:                         }
  220:                     } else {
  221:                         $output = &mt('No change');
  222:                     }
  223:                 } else {
  224:                     $output = &mt('No change');
  225:                 }
  226:             } else {
  227:                 my $map = "/uploaded/$cdom/$cnum/$folder.$container";
  228:                 my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
  229:                 if ($fatal) {
  230:                     $errormsg = &mt('Update failed: [_1].',$errtext);
  231:                 } else {
  232:                     my $saveurl = &LONCAPA::map::qtunescape($newurl);
  233:                     my $savetitle = &LONCAPA::map::qtunescape($newtitle);
  234:                     my $ext = 'true';
  235:                     if ($type eq 'tool') {
  236:                         if ($args) {
  237:                             ($updated,$newgradable,$errormsg) = &update_exttool($marker,$cdom,$cnum,
  238:                                                                                 $supplementalflag,$args);
  239:                             if ($newgradable) {
  240:                                 &LONCAPA::map::storeparameter($residx,'parameter_0_gradable',$newgradable,
  241:                                                               'string_yesno');
  242:                                 $needreload = 1;
  243:                             }
  244:                         }
  245:                         $ext = 'false';
  246:                     }
  247:                     my $dotimeupdate;
  248:                     unless ($supplementalflag) {
  249:                         if (($newgradable) || ($newurl ne $oldurl)) {
  250:                             $dotimeupdate = 1;
  251:                         }
  252:                     }
  253:                     $LONCAPA::map::resources[$residx] =
  254:                         join(':', ($savetitle,$saveurl,$ext,'normal','res'));
  255:                     my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1,$dotimeupdate);
  256:                     if ($errtext) {
  257:                         $errormsg = &mt('Update failed: [_1].',$errtext);
  258:                     } else {
  259:                         $updated = 1;
  260:                         $title = $newtitle;
  261:                         if ($newurl ne $oldurl) {
  262:                             $url = $newurl;
  263:                             if ($ext eq 'true') {
  264:                                 $newurl =~ s{^http://}{};
  265:                                 $newurl = "ext/$newurl";
  266:                             }
  267:                         }
  268:                         if (!$supplementalflag) {
  269:                             if ($newurl ne $oldurl) {
  270:                                 $symb = &Apache::lonnet::encode_symb($map,$residx,$newurl);
  271:                             } else {
  272:                                 $symb = $env{'form.symb'};
  273:                                 if ($symb) {
  274:                                     &Apache::lonnet::devalidate_title_cache($symb);
  275:                                 }
  276:                             }
  277:                             $needreload = 1;
  278:                         }
  279:                     }
  280:                 }
  281:             }
  282:             if ($needreload) {
  283:                 my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
  284:                 if ($ferr) {
  285:                     $errormsg = &mt('Reload failed: [_1].',$ferr);
  286:                 } else {
  287:                     &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,
  288:                                                                    $cdom.'_'.$cnum);
  289:                 }
  290:             }
  291:             if (($type eq 'tool') && ($newgradable)) {
  292:                 my $uri = &Apache::lonnet::declutter($url);
  293:                 &Apache::lonnet::devalidate_cache_new('meta',$uri);
  294:             }
  295:         } else {
  296:             $output = &mt('No change');
  297:         }
  298:     } else {
  299:         if ($type eq 'tool') {
  300:             $errormsg = &mt('Information about current external tool is incomplete.');
  301:         } else {
  302:             $errormsg = &mt('Information about current external resource is incomplete.');
  303:         }
  304:     }
  305:     return ($updated,$output,$errormsg,$residx,$url,$title,$symb);
  306: }
  307: 
  308: sub update_exttool {
  309:     my ($marker,$cdom,$cnum,$supplementalflag,$args) = @_;
  310:     my (%newhash,$changed,$newgradable,@deleted,$errormsg);
  311:     ($newhash{'target'},$newhash{'width'},$newhash{'height'},$newhash{'linktext'},$newhash{'explanation'},
  312:      $newhash{'crslabel'},$newhash{'crstitle'},$newhash{'crsappend'},$newhash{'gradable'}) = split(/:/,$args);
  313:     foreach my $item ('linktext','explanation','crslabel','crstitle','crsappend') {
  314:         $newhash{$item} = &unescape($newhash{$item});
  315:     }
  316:     my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
  317:     foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle','crsappend','gradable') {
  318:         $newhash{$item} =~ s/^\s+//;
  319:         $newhash{$item} =~ s/\s+$//;
  320:         if (($item eq 'width') || ($item eq 'height') || ($item eq 'linktext') || ($item eq 'explanation')) {
  321:             if ($newhash{'target'} eq 'iframe') {
  322:                 $newhash{$item} = '';
  323:             } elsif ($newhash{'target'} eq 'tab') {
  324:                 if (($item eq 'width') || ($item eq 'height')) {
  325:                     $newhash{$item} = '';
  326:                 }
  327:             }
  328:         } elsif ($item eq 'gradable') {
  329:             unless ($newhash{$item} == 1) {
  330:                 $newhash{$item} = '';
  331:             }
  332:         }
  333:         if ($toolhash{$item} ne $newhash{$item}) {
  334:             if (($item eq 'gradable') && (!$supplementalflag)) {
  335:                 if ($newhash{$item}) {
  336:                     $newgradable = 'yes';
  337:                 } else {
  338:                     $newgradable = 'no';
  339:                 }
  340:             }
  341:             if ($newhash{$item} eq '') {
  342:                 unless (($item eq 'target') ||
  343:                         ((($item eq 'width') || ($item eq 'height')) &&
  344:                          (($newhash{'target'} eq 'window') || 
  345:                           (($newhash{'target'} eq '') && ($toolhash{'target'} eq 'window')))) ||
  346:                         ((($item eq 'linktext') || ($item eq 'explanation')) &&
  347:                          ((($newhash{'target'} =~ /^(window|tab)$/)) ||
  348:                          (($newhash{'target'} eq '') && ($toolhash{'target'} =~ /^(window|tab)$/))))) {
  349:                     delete($toolhash{$item});
  350:                     push(@deleted,$item);
  351:                     $changed = 1;
  352:                 }
  353:             } else {
  354:                 $toolhash{$item} = $newhash{$item};
  355:                 $changed = 1; 
  356:             }
  357:         }
  358:     }
  359:     if ($changed) {
  360:         my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$cdom,$cnum);
  361:         unless ($putres eq 'ok') {
  362:             $errormsg = &mt('Failed to save updated settings.').' '.&mt('Error: [_1].',$putres);
  363:         }
  364:     }
  365:     if (@deleted) {
  366:         &Apache::lonnet::del('exttool_'.$marker,\@deleted,$cdom,$cnum);
  367:     }
  368:     return ($changed,$newgradable,$errormsg);
  369: }
  370: 
  371: sub extedit_form {
  372:     my ($supplementalflag,$residx,$orig_url,$orig_title,$pathitem,$helpitem,$caller,
  373:         $symb,$type,$cdom,$cnum,$ltitools,$disabled) = @_;
  374:     if ($type ne 'tool') {
  375:         $type = 'ext';
  376:     }
  377:     my %lt = &Apache::lonlocal::texthash(
  378:         ex => 'External Resource',
  379:         et => 'External Tool',
  380:         ed => 'Edit',
  381:         ee => 'External Resource Editor',
  382:         te => 'External Tool Editor',
  383:         pr => 'Preview',
  384:         sv => 'Save',
  385:         ul => 'URL',
  386:         ti => 'Title',
  387:         al => 'Add Link',
  388:         at => 'Add Tool',
  389:         dd => 'Defined in domain',
  390:         dc => 'Defined in course',
  391:     );
  392:     my $tabid = 'aa';
  393:     my $size = 60;
  394:     if ($supplementalflag) {
  395:         $tabid = 'ee';
  396:     }
  397:     my ($formname,$formid,$toggle,$fieldsetid,$urlid,$subdivid,$dispdivstyle,$dimendivstyle,
  398:         $windivstyle,$linktextstyle,$explanationstyle,$labelstyle,$titlestyle,
  399:         $appendstyle,$gradablestyle,$subdivstyle,$legend,$urlelem,$toolelem,%toolattr);
  400:     $formname = 'new'.$type;
  401:     $toggle = $type;
  402:     $fieldsetid = 'external'.$type.'form';
  403:     $urlid = $type.'url';
  404:     map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight',
  405:                                        'crstitlediv','crslabeldiv','crsappenddiv',
  406:                                        'gradablediv','crstitle','crslabel','crsappend',
  407:                                        'windiv','linktextdiv','explanationdiv',
  408:                                        'linktext','explanation','providerurl');
  409:     $dispdivstyle = 'display:none';
  410:     $dimendivstyle = 'display:none';
  411:     $windivstyle = 'display:none';
  412:     $linktextstyle = 'display:none';
  413:     $explanationstyle = 'display:none';
  414:     $labelstyle = 'display:none';
  415:     $titlestyle = 'display:none';
  416:     $appendstyle = 'display:none';
  417:     $gradablestyle = 'display:none';
  418:     $subdivstyle = 'display:block';
  419:     if ($supplementalflag) {
  420:         $formname = 'newsupp'.$type;
  421:         $toggle = 'supp'.$type;
  422:         $fieldsetid = 'externalsupp'.$type.'form';
  423:         $urlid = 'supp'.$type.'url';
  424:         map { $toolattr{$_} = 'supp'.$toolattr{$_}; } (keys(%toolattr));
  425:     }
  426:     my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,$crstitle,$crslabel,
  427:         $crsappend,$fieldsetstyle,$action,$hiddenelem,$form,$width,$height,$tooltarget,
  428:         $linktext,$explanation,$providerurl,$chkgrd,$chknogrd,%chkstate);
  429:     $fieldsetstyle = 'display: none;';
  430:     $action = '/adm/coursedocs';
  431:     my $protocol = ($ENV{'SERVER_PORT'} == 443?'https':'http');
  432:     my $rows = 2;
  433:     my $cols = 20;
  434:     if ($residx) {
  435:         if ($caller eq 'direct') {
  436:             $fieldsetstyle = 'display: block;';
  437:             $action = '/adm/extresedit';
  438:             $rows = 10;
  439:             $cols = 45;
  440:             if ($type eq 'tool') {
  441:                 $legend = $lt{'te'};
  442:             } else {
  443:                 $legend = $lt{'ee'};
  444:             }
  445:             $legend = '<legend>'.$legend.'</legend>';
  446:             if ($symb) {
  447:                 $hiddenelem = '<input type="hidden" name="symb" value="'.$symb.'" />';
  448:             } elsif ($supplementalflag) {
  449:                 $hiddenelem = '<input type="hidden" name="suppurl" value="'.
  450:                               &HTML::Entities::encode(&escape($orig_url),'<>&"').'" />'."\n".
  451:                               '<input type="hidden" name="title" value="'.
  452:                               &HTML::Entities::encode(&escape($orig_title),'<>&"').'" />';
  453:             }
  454:         } else {
  455:             $link = '<a class="LC_docs_ext_edit" href="javascript:editext('."'$residx','$type'".');">'.$lt{'ed'}.'</a>&nbsp;'."\n";
  456:             $size = 40;
  457:             $active = '<input type="hidden" name="active" value="'.$tabid.'" />';
  458:         }
  459:         $formname = 'edit'.$type.'_'.$residx;
  460:         $fieldsetid = 'external'.$type.$residx;
  461:         $urlid = $type.'url_'.$residx;
  462:         map { $toolattr{$_} .= '_'.$residx; } (keys(%toolattr));
  463:         $srcclass = ' class="LC_nobreak"';
  464:         if ($type eq 'ext') {
  465:             $extsrc = '<span class="LC_docs_ext_edit">'.$lt{'ul'}.'&nbsp;</span>';
  466:             $preview = '&nbsp;<a class="LC_docs_ext_edit" href="javascript:extUrlPreview('."'$urlid','$protocol'".');">'.$lt{'pr'}.'</a>';
  467:         }
  468:         $title = '<span class="LC_docs_ext_edit">'.$lt{'ti'}.'&nbsp;</span>';
  469:         $save = $lt{'sv'};
  470:     } else {
  471:         $link = $lt{'ex'};
  472:         if ($type eq 'tool') {
  473:             $link = $lt{'et'};
  474:         }
  475:         $link = '<a class="LC_menubuttons_link" href="javascript:toggleExternal('."'$toggle'".');">'.$link.'</a>'.$helpitem;
  476:         if ($type eq 'tool') {
  477:             $legend = $lt{'te'};
  478:         } else {
  479:             $legend = $lt{'ee'};
  480:         }
  481:         $legend = '<legend>'.$legend.'</legend>';
  482:         $title = $lt{'ti'}.':<br />';
  483:         $residx = 0;
  484:         if ($type eq 'ext') {
  485:             $orig_url = 'http://';
  486:             $orig_title = $lt{'ex'};
  487:             $extsrc = $lt{'ul'}.':<br />';
  488:             $preview = '<input type="button" name="view" value="'.$lt{'pr'}.'" onclick="javascript:extUrlPreview('."'$urlid','$protocol'".');"'.$disabled.' />';
  489:             $save = $lt{'al'};
  490:         } else {
  491:             $orig_title = $lt{'et'};
  492:             $save = $lt{'at'};
  493:             $orig_url = "/adm/$cdom/$cnum/new/ext\.tool"; 
  494:         }
  495:         $pathitem .= '<br />';
  496:     }
  497:     $formid = $formname;
  498:     if ($type eq 'ext') {
  499:         $urlelem = '<input type="text" size="'.$size.'" name="exturl" id="'.$urlid.'" value="'.$orig_url.'"'.$disabled.' />';
  500:     } else {
  501:         my $class = 'LC_nobreak';
  502:         if ($residx) {
  503:             $class = 'LC_docs_ext_edit LC_nobreak'; 
  504:             if ($orig_url =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) {
  505:                 my $marker = $1;
  506:                 my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
  507:                 my ($tooltype,$tool,$ltihash);
  508:                 if ($toolhash{'id'} =~/^c(\d+)$/) {
  509:                     $tool = $1;
  510:                     $tooltype = 'crs';
  511:                     if (ref($ltitools) eq 'HASH') {
  512:                         if (ref($ltitools->{'crs'}) eq 'HASH') {
  513:                             $ltihash = $ltitools->{'crs'}->{$tool};
  514:                         }
  515:                     }
  516:                 } elsif ($toolhash{'id'} =~/^\d+$/) {
  517:                     $tooltype = 'dom';
  518:                     $tool = $toolhash{'id'};
  519:                     if (ref($ltitools) eq 'HASH') {
  520:                         if (ref($ltitools->{'dom'}) eq 'HASH') {
  521:                             $ltihash = $ltitools->{'dom'}->{$tool};
  522:                         }
  523:                     }
  524:                 }
  525:                 if (($tool ne '') && (ref($ltihash) eq 'HASH')) {
  526:                     my $tooltitle = $ltihash->{'title'};
  527:                     my $icon = $ltihash->{'image'};
  528:                     my $image;
  529:                     if ($icon) {
  530:                         $image = '<img src="'.$icon.'" alt="'.$tooltitle.'" />';
  531:                     }
  532:                     if ($ltihash->{'url'} =~ m{://}) {
  533:                         (my $prot,my $host,$providerurl) = ($ltihash->{'url'} =~ m{^([^/]+)://([^/]+)(|/.+)$});
  534:                     } else {
  535:                         $providerurl = $ltihash->{'url'};
  536:                     }
  537:                     $tooltarget = $toolhash{'target'};
  538:                     if ($tooltarget eq 'window') {
  539:                         $dimendivstyle = 'display:block';
  540:                         $windivstyle = 'display:block';
  541:                         $chkstate{'window'} = 'checked="checked" ';
  542:                     } elsif ($tooltarget eq 'tab') {
  543:                         $windivstyle = 'display:block';
  544:                         $chkstate{'tab'} = 'checked="checked" ';
  545:                     } else {
  546:                         $chkstate{'iframe'} = 'checked="checked" ';
  547:                     }
  548:                     $width = $toolhash{'width'};
  549:                     $height = $toolhash{'height'};
  550:                     $linktext = $toolhash{'linktext'};
  551:                     $explanation = $toolhash{'explanation'};
  552:                     if ($toolhash{'gradable'}) {
  553:                         $chkgrd = ' checked="checked"';
  554:                     } else {
  555:                         $chknogrd = ' checked="checked"';
  556:                     }
  557:                     if (ref($ltihash->{'crsconf'}) eq 'HASH') {
  558:                         if ($ltihash->{'crsconf'}->{'title'}) {
  559:                             $crstitle = $toolhash{'crstitle'};
  560:                             $titlestyle = 'display:inline';
  561:                         }
  562:                         if ($ltihash->{'crsconf'}->{'label'}) {  
  563:                             $crslabel = $toolhash{'crslabel'};
  564:                             $labelstyle = 'display:inline';
  565:                         }
  566:                         if ($ltihash->{'crsconf'}->{'append'}) {
  567:                             $crsappend = $toolhash{'crsappend'};
  568:                             $appendstyle = 'display:inline';
  569:                         }
  570:                         if ($ltihash->{'crsconf'}->{'target'}) {
  571:                             $dispdivstyle = 'display:block';
  572:                         }
  573:                         if ($ltihash->{'crsconf'}->{'linktext'}) {
  574:                             $linktextstyle = 'padding:0;display:inline';
  575:                         }
  576:                         if ($ltihash->{'crsconf'}->{'explanation'}) {
  577:                             $explanationstyle = 'padding:0;display:inline';
  578:                         }
  579:                     }
  580:                     $toolelem = '<span class="LC_nobreak">'.$image.'&nbsp;'.$tooltitle.'</span><br />';
  581:                     $gradablestyle = 'display:inline';
  582:                 }
  583:             }
  584:         } else {
  585:             $subdivstyle = 'display:none';
  586:             my $toolradio = 'exttooltype';
  587:             my $exttypeon = 'LC_exttoolon';
  588:             my $exttypeoff = 'LC_exttooloff';
  589:             my $exttypeonsty = 'display:none';
  590:             my $exttypeoffsty = 'display:none';
  591:             my $exttypeofftext;
  592:             if ($supplementalflag) {
  593:                 $toolradio = 'suppexttooltype';
  594:                 $exttypeon = 'LC_exttoolonsupp';
  595:                 $exttypeoff = 'LC_exttooloffsupp';
  596:             }
  597:             my ($numcrstools,$numdomtools,$typeclick,%defcheck,%typedesc);
  598:             %typedesc = (
  599:                           crs => 'Defined in course',
  600:                           dom => 'Defined in domain',
  601:                         );
  602: #FIXME need crstype
  603:             my $seloptions;
  604:             $subdivid = 'LC_addtool';
  605:             if ($supplementalflag) {
  606:                 $subdivid = 'LC_addtoolsupp';
  607:             }
  608:             if (ref($ltitools) eq 'HASH') {
  609:                 if (ref($ltitools->{'crs'}) eq 'HASH') {
  610:                     $numcrstools = scalar(keys(%{$ltitools->{'crs'}}));
  611:                 }
  612:                 if (ref($ltitools->{'dom'}) eq 'HASH') {
  613:                     $numdomtools = scalar(keys(%{$ltitools->{'dom'}}));
  614:                 }
  615:                 if ($numcrstools || $numdomtools) {
  616:                     $typeclick = ' onclick="'.
  617:                         'javascript:updateExttoolSel(this.form,'."'$toolradio','$supplementalflag'".');"';
  618:                 } else {
  619:                     $exttypeoffsty = 'display:block';
  620:                     $exttypeofftext = &mt('No external tools defined in either the domain or the course are available for selection.');
  621:                 }
  622:                 if ($numcrstools && !$numdomtools) {
  623:                     $defcheck{'crs'} = ' checked="checked"';
  624:                     $subdivstyle = 'display:block';
  625:                     $exttypeonsty = 'display:block';
  626:                     my $firstoption = '<option value="" selected="selected">'.&mt('Select').'</option>';
  627:                     $seloptions = &ordered_tooloptions($ltitools->{'crs'});
  628:                     if ($seloptions) {
  629:                         $seloptions = "$firstoption\n$seloptions";
  630:                     }
  631:                     $exttypeofftext = &mt('No external tools defined in the domain are available for selection.');
  632:                 } elsif (!$numcrstools && $numdomtools) {
  633:                     $defcheck{'dom'} = ' checked="checked"';
  634:                     $subdivstyle = 'display:block';
  635:                     $exttypeonsty = 'display:block';
  636:                     my $firstoption = '<option value="" selected="selected">'.&mt('Select').'</option>';
  637:                     $seloptions = &ordered_tooloptions($ltitools->{'dom'});
  638:                     if ($seloptions) {
  639:                         $seloptions = "$firstoption\n$seloptions";
  640:                     }
  641: #FIXME need crstype
  642:                     $exttypeofftext = &mt('No external tools defined in the course are available for selection.');
  643:                 }
  644:             }
  645:             foreach my $type ('crs','dom') {
  646:                 $toolelem .= '<span class="LC_nobreak"> <label>'.
  647:                              '<input type="radio" name="'.$toolradio.'" value="'.$type.'"'.$defcheck{$type}.
  648:                              $typeclick.$disabled.' />'.$typedesc{$type}.'</label></span> '."\n";
  649:             }
  650:             $toolelem .= '<div id="'.$exttypeon.'" style="'.$exttypeonsty.'">'.
  651:                          '<select name="exttoolid" onchange="javascript:updateExttool(this,'.
  652:                          'this.form,'."'$supplementalflag'".');"'.$disabled.'>'."\n".
  653:                          $seloptions.
  654:                          '</select><br /></div>'."\n".
  655:                          '<div id="'.$exttypeoff.'" style="'.$exttypeoffsty.'">'.
  656:                          $exttypeofftext.
  657:                          '<br /></div>'."\n";
  658:             $crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
  659:             $crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'};
  660:             $crsappend = '';
  661:             $chknogrd = ' checked="checked"';
  662:         }
  663:         $toolelem .= '<div id="'.$toolattr{'dispdiv'}.'" style="'.$dispdivstyle.'">'.
  664:                     '<span class="'.$class.'">'.&mt('Display target:').'&nbsp;'.
  665:                     '<label><input type="radio" name="exttooltarget" value="iframe" '.$chkstate{'iframe'}.'onclick="updateTooldim(this.form,'.
  666:                     "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
  667:                     '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('iframe').'</label>'.('&nbsp;'x2).
  668:                     '<label><input type="radio" name="exttooltarget" value="tab" '.$chkstate{'tab'}.'onclick="updateTooldim(this.form,'.
  669:                     "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
  670:                     '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('tab').'</label>'.('&nbsp;'x2).
  671:                     '<label><input type="radio" name="exttooltarget" value="window" '.$chkstate{'window'}.'onclick="updateTooldim(this.form,'.
  672:                     "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
  673:                     '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('window').'</label></span>'.
  674:                     '<div id="'.$toolattr{'dimendiv'}.'" style="'.$dimendivstyle.'"><span class="'.$class.'">'.
  675:                     &mt('Width').':&nbsp;<input type="text" size="4" id="'.$toolattr{'dimenwidth'}.'" name="exttoolwidth" value="'.$width.'"'.$disabled.' />'.('&nbsp;'x2).
  676:                     &mt('Height').':&nbsp;<input type="text" size="4" id="'.$toolattr{'dimenheight'}.'" name="exttoolheight" value="'.$height.'"'.$disabled.' /></span>'."\n".
  677:                     '</div></div>';
  678:         $toolelem .= '<div id="'.$toolattr{'windiv'}.'" style="'.$windivstyle.'">'.
  679:                      '<div id="'.$toolattr{'linktextdiv'}.'" class="LC_left_float" style="'.$linktextstyle.'">'.
  680:                      '<span class="'.$class.'">'.&mt('Link Text').'</span><br /><input type="text" size="25" id="'.$toolattr{'linktext'}.
  681:                      '" name="exttoollinktext" value="'.$linktext.'"'.$disabled.' />'.
  682:                      '</div><div id="'.$toolattr{'explanationdiv'}.'" class="LC_left_float" style="'.$explanationstyle.'">'.
  683:                      '<span class="'.$class.'">'.&mt('Explanation').'</span><br />'.
  684:                      '<textarea rows="'.$rows.'" cols="'.$cols.'" id="'.$toolattr{'explanation'}.'" name="exttoolexplanation" '.$disabled.'>'.
  685:                      $explanation.'</textarea></div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
  686:                      '</div>';
  687:         $toolelem .= '<div id="'.$toolattr{'crslabeldiv'}.'" style="'.$labelstyle.'">'.
  688:                     '<span class="'.$class.'">'.&mt('Course label:').'&nbsp;'.
  689:                     '<input type="text" id="'.$toolattr{'crslabel'}.'" name="exttoollabel" value="'.$crslabel.'"'.$disabled.' /></span><br />'.
  690:                     '</div>'.
  691:                     '<div id="'.$toolattr{'crstitlediv'}.'" style="'.$titlestyle.'">'.
  692:                     '<span class="'.$class.'">'.&mt('Course title:').'&nbsp;'.
  693:                     '<input type="text" id="'.$toolattr{'crstitle'}.'" name="exttooltitle" value="'.$crstitle.'"'.$disabled.' /></span><br />'.
  694:                     '</div>'.
  695:                     '<div id="'.$toolattr{'crsappenddiv'}.'" style="'.$appendstyle.'">'.
  696:                     '<span class="'.$class.'">'.&mt('Append to URL[_1]',
  697:                     '<span id="'.$toolattr{'providerurl'}.'">&nbsp;('.$providerurl.')<br /></span>').
  698:                     '<input type="text" id="'.$toolattr{'crsappend'}.'" size="30" name="exttoolappend" value="'.$crsappend.'"'.$disabled.' /></span><br />'.
  699:                     '</div>'.
  700:                     '<div id="'.$toolattr{'gradablediv'}.'" style="'.$gradablestyle.'">'.
  701:                     '<span class="'.$class.'">'.&mt('Gradable').'&nbsp;'.
  702:                     '<label><input type="radio" name="exttoolgradable" value="1"'.$chkgrd.$disabled.
  703:                     ' />'.&mt('Yes').'</label>'.('&nbsp;'x2).
  704:                     '<label><input type="radio" name="exttoolgradable" value="0"'.$chknogrd.$disabled.
  705:                     ' />'.&mt('No').'</label></span></div>';
  706:     }
  707:     my $chooser = $toolelem;
  708:     if ($type eq 'ext') {
  709:         $chooser = "
  710: <div>
  711: <span$srcclass>
  712: $extsrc
  713: $urlelem
  714: $preview
  715: </span>
  716: </div>
  717: ";
  718:     }
  719:     my $idattr;
  720:     unless ($subdivid eq '') {
  721:         $idattr = 'id="'.$subdivid.'"';
  722:     }
  723:     $form = <<ENDFORM;
  724: <form action="$action" method="post" name="$formname" id="$formid">
  725: <fieldset id="$fieldsetid" style="$fieldsetstyle">
  726: $legend
  727: $active
  728: $chooser
  729: <div $idattr style="$subdivstyle">
  730: <span$srcclass>
  731: $title
  732: <input type="text" size="$size" name="exttitle" value="$orig_title" $disabled />
  733: <input type="hidden" name="importdetail" value="" />
  734: $pathitem
  735: $hiddenelem
  736: <input type="button" value="$save" onclick="javascript:setExternal(this.form,'$residx','$type','$orig_url','$supplementalflag');" $disabled />
  737: </span>
  738: </div>
  739: </fieldset>
  740: </form>
  741: ENDFORM
  742:     if (wantarray) {
  743:         return ($link,$form);
  744:     } else {
  745:         return $link.$form;
  746:     }
  747: }
  748: 
  749: sub ordered_tooloptions {
  750:     my ($toolsref) = @_;
  751:     my ($seloptions,@ids,@titles);
  752:     if (ref($toolsref) eq 'HASH') {
  753:         my %bynum;
  754:         foreach my $id (keys(%{$toolsref})) {
  755:             if (ref($toolsref->{$id}) eq 'HASH') {
  756:                 my $order = $toolsref->{$id}->{'order'};
  757:                 $bynum{$order} = [$id,$toolsref->{$id}];
  758:             }
  759:         }
  760:         foreach my $item (sort { $a <=> $b } keys(%bynum)) {
  761:             if (ref($bynum{$item}) eq 'ARRAY') {
  762:                 if (ref($bynum{$item}->[1]) eq 'HASH') {
  763:                     my $tooltitle = $bynum{$item}->[1]->{'title'};
  764:                     push(@titles,$tooltitle);
  765:                     push(@ids,$bynum{$item}->[0]);
  766:                     $seloptions .= '<option value="'.$bynum{$item}->[0].'">'.$tooltitle.'</option>'."\n";
  767:                 }
  768:             }
  769:         }
  770:     }
  771:     if (wantarray) {
  772:         return (\@ids,\@titles);
  773:     } else {
  774:         return $seloptions;
  775:     }
  776: }
  777: 
  778: sub display_editor {
  779:     my ($url,$folderpath,$symb,$idx,$type,$cdom,$cnum,$hostname) = @_;
  780:     my ($residx,$supplementalflag,$title,$pathitem,$output,$js,$navmap);
  781:     if ($folderpath =~ /^supplemental/) {
  782:         $supplementalflag = 1;
  783:         $residx = $idx;
  784:         $title = &unescape($env{'form.title'});
  785:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
  786:     } elsif ($symb =~ /^uploaded/) {
  787:         (my $map,$residx,my $res) =
  788:             &Apache::lonnet::decode_symb($symb);
  789:         $title = &Apache::lonnet::gettitle($symb);
  790:         my $path = &Apache::loncommon::symb_to_docspath($symb,\$navmap);
  791:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($path,'<>&"').'" />';
  792:     }
  793:     my (%ltitools,%tooltypes);
  794:     if ($type eq 'tool') {
  795:         my (%domtools,%crstools);
  796:         %tooltypes = &Apache::loncommon::usable_exttools();
  797:         if ($tooltypes{'dom'}) {
  798:             %domtools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
  799:         }
  800:         if ($tooltypes{'crs'}) {
  801:             %crstools = &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
  802:         }
  803:         %ltitools = (
  804:                       dom => \%domtools,
  805:                       crs => \%crstools,
  806:                     );
  807:     }
  808:     $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
  809:     my $args = { 'force_register' => $env{'form.register'} };
  810:     if ($hostname) {
  811:         $args->{'hostname'} = $hostname;
  812:     }
  813:     my $description = 'External Resource Editor';
  814:     if ($type eq 'tool') {
  815:         $description = 'External Tool Editor';
  816:     }
  817:     return &Apache::loncommon::start_page($description,$js,$args).
  818:            '<div class="LC_left_float">'.
  819:            &extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,'direct',
  820:                          $symb,$type,$cdom,$cnum,\%ltitools).
  821:            '</div>'.
  822:            &Apache::loncommon::end_page();
  823: }
  824: 
  825: sub extedit_javascript {
  826:     my ($toolsref) = @_;
  827:     my ($toolsjs,$exttoolnums,$exttooloptions);
  828:     if (ref($toolsref) eq 'HASH') {
  829:         $toolsjs = "        var ltitools = new Array();\n".
  830:                    "        var ltitoolsUrl = new Array();\n".
  831:                    "        var ltitoolsTarget = new Array();\n".
  832:                    "        var ltitoolsWidth = new Array();\n".
  833:                    "        var ltitoolsHeight = new Array();\n".
  834:                    "        var ltitoolsLinkDef = new Array();\n".
  835:                    "        var ltitoolsExplainDef = new Array();\n".
  836:                    "        var ltitoolsDisplay = new Array();\n".
  837:                    "        var ltitoolsLink = new Array();\n".
  838:                    "        var ltitoolsExplain = new Array();\n".
  839:                    "        var ltitoolsLabel = new Array();\n".
  840:                    "        var ltitoolsTitle = new Array();\n".
  841:                    "        var ltitoolsAppend = new Array();\n";
  842:         $exttoolnums = "        var ltitoolsnum = new Array();\n".
  843:                        "        var tooloptval = new Array();\n".
  844:                        "        var toolopttxt = new Array();\n";
  845:         my $idx = 0;
  846:         foreach my $type ('crs','dom') {
  847:             if (ref($toolsref->{$type}) eq 'HASH') {
  848:                 my $num = scalar(keys(%{$toolsref->{$type}}));
  849:                 $toolsjs .= "        ltitools[$idx] = new Array($num);\n".
  850:                             "        ltitoolsUrl[$idx] = new Array($num);\n".
  851:                             "        ltitoolsTarget[$idx] = new Array($num);\n".
  852:                             "        ltitoolsWidth[$idx] = new Array($num);\n".
  853:                             "        ltitoolsHeight[$idx] = new Array($num);\n".
  854:                             "        ltitoolsLinkDef[$idx] = new Array($num);\n".
  855:                             "        ltitoolsExplainDef[$idx] = new Array($num);\n".
  856:                             "        ltitoolsDisplay[$idx] = new Array($num);\n".
  857:                             "        ltitoolsLink[$idx] = new Array($num);\n".
  858:                             "        ltitoolsExplain[$idx] = new Array($num);\n".
  859:                             "        ltitoolsLabel[$idx] = new Array($num);\n".
  860:                             "        ltitoolsTitle[$idx] = new Array($num);\n".
  861:                             "        ltitoolsAppend[$idx] = new Array($num);\n";
  862:                 my $i=0;
  863:                 foreach my $key (sort { $a <=> $b } keys(%{$toolsref->{$type}})) {
  864:                     if (ref($toolsref->{$type}->{$key}) eq 'HASH') {
  865:                         if (ref($toolsref->{$type}->{$key}->{'display'}) eq 'HASH') {
  866:                             my $target = $toolsref->{$type}->{$key}->{'display'}->{'target'};
  867:                             my $width = $toolsref->{$type}->{$key}->{'display'}->{'width'};
  868:                             my $height = $toolsref->{$type}->{$key}->{'display'}->{'height'};
  869:                             my $linkdef = $toolsref->{$type}->{$key}->{'display'}->{'linktext'};
  870:                             my $explaindef = $toolsref->{$type}->{$key}->{'display'}->{'explanation'};
  871:                             my $providerurl;
  872:                             if ($toolsref->{$type}->{$key}->{'url'} =~ m{://}) {
  873:                                 (my $prot,my $host,$providerurl) =
  874:                                     ($toolsref->{$type}->{$key}->{'url'} =~ m{^([^/]+)://([^/]+)(|/.+)$});
  875:                             } else {
  876:                                 $providerurl = $toolsref->{$type}->{$key}->{'url'};
  877:                             }
  878:                             $providerurl = &LONCAPA::map::qtunescape($providerurl);
  879:                             $toolsjs .= "        ltitools[$idx][$i] = '$key';\n".
  880:                                         "        ltitoolsTarget[$idx][$i] = '$target';\n".
  881:                                         "        ltitoolsWidth[$idx][$i] = '$width';\n".
  882:                                         "        ltitoolsHeight[$idx][$i] = '$height';\n".
  883:                                         "        ltitoolsLinkDef[$idx][$i] = '$linkdef';\n".
  884:                                         "        ltitoolsExplainDef[$idx][$i] = '$explaindef';\n".
  885:                                         "        ltitoolsUrl[$idx][$i] = '$providerurl';\n";
  886:                         }
  887:                         if (ref($toolsref->{$type}->{$key}->{'crsconf'}) eq 'HASH') {
  888:                             my $display = $toolsref->{$type}->{$key}->{'crsconf'}->{'target'};
  889:                             $toolsjs .= "         ltitoolsDisplay[$idx][$i] = '$display';\n";
  890:                             my $linktext = $toolsref->{$type}->{$key}->{'crsconf'}->{'linktext'};
  891:                             $toolsjs .= "         ltitoolsLink[$idx][$i] = '$linktext';\n";
  892:                             my $explanation = $toolsref->{$type}->{$key}->{'crsconf'}->{'explanation'};
  893:                             $toolsjs .= "         ltitoolsExplain[$idx][$i] = '$explanation';\n";
  894:                             my $label = $toolsref->{$type}->{$key}->{'crsconf'}->{'label'};
  895:                             $toolsjs .= "         ltitoolsLabel[$idx][$i] = '$label';\n";
  896:                             my $title = $toolsref->{$type}->{$key}->{'crsconf'}->{'title'};
  897:                             $toolsjs .= "         ltitoolsTitle[$idx][$i] = '$title';\n";
  898:                             my $append = $toolsref->{$type}->{$key}->{'crsconf'}->{'append'};
  899:                             $toolsjs .= "         ltitoolsAppend[$idx][$i] = '$append';\n";
  900:                         }
  901:                     }
  902:                     $i++;
  903:                 }
  904:                 my $firstoption = '<option value="" selected="selected">'.&mt('Select').'</option>';
  905:                 my ($idsref,$titlesref) = &ordered_tooloptions($toolsref->{$type});
  906:                 if ((ref($idsref) eq 'ARRAY') && (ref($titlesref) eq 'ARRAY')) {
  907:                     my $count = scalar(@{$idsref});
  908:                     $exttooloptions .= "        tooloptval[$idx] = new Array($count);\n".
  909:                                        "        toolopttxt[$idx] = new Array($count);\n";
  910:                     for (my $n=0; $n<@{$idsref}; $n++) {
  911:                         my $id = $idsref->[$n];
  912:                         my $text = $titlesref->[$n];
  913:                         $exttooloptions .= "         tooloptval[$idx][$n] = '$id';\n".
  914:                                            "         toolopttxt[$idx][$n] = '$text';\n";
  915:                     }
  916:                 }
  917:                 $exttoolnums .= "        ltitoolsnum[$idx] = $i;\n";
  918:             }
  919:             $idx ++;
  920:         }
  921:     }
  922:     my %js_lt = &Apache::lonlocal::texthash(
  923:         invurl  => 'Invalid URL',
  924:         titbl   => 'Title is blank',
  925:         invtool => 'Please select an external tool',
  926:         mixfra  => 'Show preview in pop-up? (http in https page + no framing)',
  927:         mixonly => 'Show preview in pop-up? (http in https page)',
  928:         fraonly => 'Show preview in pop-up? (framing disallowed)',
  929:         nopopup => 'Pop-up blocked',
  930:         nopriv  => 'Insufficient privileges to use preview',
  931:         badurl  => 'URL is not: http://hostname/path or https://hostname/path',
  932:         sele    => 'Select',
  933:     );
  934:     &js_escape(\%js_lt);
  935: 
  936:     my $urlregexp = <<'ENDREGEXP';
  937: /^([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
  938: ENDREGEXP
  939: 
  940:     return <<ENDJS;
  941: 
  942: var regexp = $urlregexp;
  943: 
  944: function setExternal(extform,residx,type,exttoolurl,supplementalflag) {
  945:     var title=extform.exttitle.value;
  946:     if (!String.trim) {
  947:         String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");};    }
  948:     if (title == null || title.trim()=="") {
  949:         alert("$js_lt{'titbl'}");
  950:         extform.exttitle.focus();
  951:         return;
  952:     }
  953:     if (type == 'ext') {
  954:         var url=extform.exturl.value;
  955:         if (!regexp.test(url)) {
  956:             alert("$js_lt{'invurl'}");
  957:             extform.exturl.focus();
  958:             return;
  959:         } else {
  960:             url = escape(url);
  961:             title = escape(title);
  962:             if (residx > 0) {
  963:                eval("extform.importdetail.value=title+'='+url+'='+residx;extform.submit();");
  964:             } else {
  965:                eval("extform.importdetail.value=title+'='+url;extform.submit();");
  966:             }
  967:         }
  968:     } else {
  969:         title = escape(title);
  970:         var info = exttoolurl;
  971:         var prefix = '';
  972:         if (supplementalflag == 1) {
  973:            prefix = 'supp';
  974:         }
  975:         if (residx == 0) {
  976:             var toolid = parseInt(extform.exttoolid.options[extform.exttoolid.selectedIndex].value);
  977:             if (isNaN(toolid)) {
  978:                 alert("$js_lt{'invtool'}");
  979:                 return;
  980:             }
  981:             var typeelem = extform.elements[prefix+'exttooltype'];
  982:             if (typeelem.length) {
  983:                 for (var i=0; i<typeelem.length; i++) {
  984:                     if (typeelem[i].checked) {
  985:                         tooltype = typeelem[i].value;
  986:                     }
  987:                 }
  988:             }
  989:             if (tooltype == 'crs') {
  990:                 info += ':c'+toolid;
  991:             } else {
  992:                 info += ':'+toolid;
  993:             }
  994:         }
  995:         var dispdiv = prefix+'tooldispdiv';
  996:         var windiv = prefix+'toolwindiv';
  997:         if (residx > 0) {
  998:             dispdiv += '_'+residx;
  999:             windiv += '_'+residx;
 1000:         }
 1001:         if (document.getElementById(dispdiv)) {
 1002:             if (document.getElementById(dispdiv).style.display == 'block') {
 1003:                 if (extform.exttooltarget.length) {
 1004:                     for (var i=0; i<extform.exttooltarget.length; i++) {
 1005:                         if (extform.exttooltarget[i].checked) {
 1006:                             if (extform.exttooltarget[i].value == 'window') {
 1007:                                 var width = extform.exttoolwidth.value;
 1008:                                 width.trim();
 1009:                                 var height = extform.exttoolheight.value;
 1010:                                 height.trim();
 1011:                                 info += ':window:'+width+':'+height;
 1012:                             } else if (extform.exttooltarget[i].value == 'tab') {
 1013:                                 info += ':tab::';
 1014:                             } else {
 1015:                                 info += ':iframe::';
 1016:                             }
 1017:                         }
 1018:                     }
 1019:                 }
 1020:             } else {
 1021:                 info += ':::';
 1022:             }
 1023:         } else {
 1024:             info += ':::';
 1025:         }
 1026:         if (document.getElementById(windiv)) {
 1027:             if (document.getElementById(windiv).style.display == 'block') {
 1028:                 var linktextdiv = prefix+'toollinktextdiv';
 1029:                 var explanationdiv = prefix+'toolexplanationdiv';
 1030:                 if (residx > 0) {
 1031:                     linktextdiv += '_'+residx;
 1032:                     explanationdiv += '_'+residx;
 1033:                 }
 1034:                 if (document.getElementById(linktextdiv).style.display == 'inline') {
 1035:                     var linktext = extform.exttoollinktext.value;
 1036:                     linktext.trim();
 1037:                     info += ':'+escape(linktext);
 1038:                 } else {
 1039:                     info += ':';
 1040:                 }
 1041:                 if (document.getElementById(explanationdiv).style.display == 'inline') {
 1042:                     var explaintext = extform.exttoolexplanation.value;
 1043:                     explaintext.trim();
 1044:                     info += ':'+escape(explaintext);
 1045:                 } else {
 1046:                     info += ':';
 1047:                 }
 1048:             } else {
 1049:                 info += '::';
 1050:             }
 1051:         } else {
 1052:             info += '::';
 1053:         }
 1054:         var labelinput = prefix+'toolcrslabel';
 1055:         var titleinput = prefix+'toolcrstitle';
 1056:         var appendinput = prefix+'toolcrsappend';
 1057:         if (residx > 0) {
 1058:             labelinput += '_'+residx;
 1059:             titleinput += '_'+residx;
 1060:             appendinput += '_'+residx;
 1061:         }
 1062:         if (document.getElementById(labelinput)) {
 1063:             var crslabel = document.getElementById(labelinput).value;
 1064:             crslabel.trim();
 1065:             info += ':'+escape(crslabel);
 1066:         } else {
 1067:             info += ':';
 1068:         } 
 1069:         if (document.getElementById(titleinput)) {
 1070:             var crstitle = document.getElementById(titleinput).value;
 1071:             crstitle.trim();
 1072:             info += ':'+escape(crstitle);
 1073:         } else {
 1074:             info += ':';
 1075:         }
 1076:         if (document.getElementById(appendinput)) {
 1077:             var crsappend = document.getElementById(appendinput).value;
 1078:             crsappend.trim();
 1079:             info += ':'+escape(crsappend);
 1080:         } else {
 1081:             info += ':';
 1082:         }
 1083:         var gradablediv = prefix+'toolgradablediv';
 1084:         if (residx > 0) {
 1085:             gradablediv += '_'+residx;
 1086:         }
 1087:         if (document.getElementById(gradablediv)) {
 1088:             if (document.getElementById(gradablediv).style.display == 'inline') {
 1089:                 if (extform.exttoolgradable.length) {
 1090:                     for (var i=0; i<extform.exttoolgradable.length; i++) {
 1091:                         if (extform.exttoolgradable[i].checked) {
 1092:                             if (extform.exttoolgradable[i].value == '1') {
 1093:                                 info += ':1';
 1094:                             } else {
 1095:                                 info += ':';
 1096:                             }
 1097:                             break;
 1098:                         }
 1099:                     }
 1100:                 } else {
 1101:                     info += ':';
 1102:                 }
 1103:             } else {
 1104:                 info += ':';
 1105:             }
 1106:         } else {
 1107:             info += ':';
 1108:         }
 1109:         info=escape(info);
 1110:         if (residx > 0) {
 1111:             eval("extform.importdetail.value=title+'='+info+'='+residx;extform.submit();");
 1112:         } else {
 1113:             eval("extform.importdetail.value=title+'='+info;extform.submit();");
 1114:         }
 1115:     }
 1116: }
 1117: 
 1118: function editext(residx,type) {
 1119:     if (document.getElementById('external'+type+residx)) {
 1120:         var curr = document.getElementById('external'+type+residx).style.display;
 1121:         if (curr == 'none') {
 1122:             disp = 'block';
 1123:         } else {
 1124:             disp = 'none';
 1125:         }
 1126:         document.getElementById('external'+type+residx).style.display=disp;
 1127:     }
 1128:     resize_scrollbox('contentscroll','1','1');
 1129:     return;
 1130: }
 1131: 
 1132: function extUrlPreview(caller,protocol) {
 1133:     if (document.getElementById(caller)) {
 1134:         var url = document.getElementById(caller).value;
 1135:         if (regexp.test(url)) {
 1136:             var http_regex = /^http\:\/\//gi;
 1137:             var mixed = 0;
 1138:             var noiframe = 0;
 1139:             var nopriv = 0;
 1140:             var badurl = 0;
 1141:             var name = "externalpreview";
 1142:             if ((protocol == 'https') && (http_regex.test(url))) {
 1143:                 mixed = 1;
 1144:             }
 1145:             var http = new XMLHttpRequest();
 1146:             var lcurl = "/adm/exturlcheck";
 1147:             var params = "exturl="+url;
 1148:             http.open("POST",lcurl, true);
 1149:             http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
 1150:             http.onreadystatechange = function() {
 1151:                 if (http.readyState == 4) {
 1152:                     if (http.status == 200) {
 1153:                         if (http.responseText.length > 0) {
 1154:                             if (http.responseText == 1) {
 1155:                                 noiframe = 1;
 1156:                             } else if (http.responseText == -1) {
 1157:                                 nopriv = 1;
 1158:                             } else if (http.responseText == 0) {
 1159:                                 badurl = 1;
 1160:                             }
 1161:                         }
 1162:                         openPreviewWindow(url,name,noiframe,mixed,nopriv,badurl);
 1163:                     }
 1164:                 }
 1165:             }
 1166:             http.send(params);
 1167:         } else {
 1168:             alert("$js_lt{'invurl'}");
 1169:         }
 1170:     }
 1171: }
 1172: 
 1173: var previewLCWindow = null;
 1174: function openPreviewWindow(url,name,noiframe,mixed,nopriv,badurl) {
 1175:     if (previewLCWindow !=null) {
 1176:         previewLCWindow.close();
 1177:     }
 1178:     if (badurl) {
 1179:         alert("$js_lt{'badurl'}");
 1180:     } else if (nopriv) {
 1181:         alert("$js_lt{'nopriv'}");
 1182:     } else if ((noiframe == 1) || (mixed == 1)) {
 1183:         var encurl = encodeURI(url);
 1184:         var msg;
 1185:         if (mixed == 1) {
 1186:             if (noiframe == 1) {
 1187:                 msg = "$js_lt{'mixfra'}";
 1188:             } else {
 1189:                 msg = "$js_lt{'mixonly'}";
 1190:             }
 1191:         } else {
 1192:             msg = "$js_lt{'fraonly'}";
 1193:         }
 1194:         if (confirm(msg)) {
 1195:             previewLCWindow = window.open(url,name,"height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1");
 1196:             if (previewLCWindow != null) {
 1197:                 previewLCWindow.focus();
 1198:             } else {
 1199:                 alert("$js_lt{'nopopup'}");
 1200:             }
 1201:         }
 1202:     } else {
 1203:         openMyModal(url,500,400,'yes');
 1204:     }
 1205: }
 1206: 
 1207: function updateExttoolSel(form,radioname,supplementalflag) {
 1208:     var prefix = '';
 1209:     var typepick;
 1210:     var radelem = form.elements[radioname];
 1211:     if (radelem.length) {
 1212:         for (var i=0; i<radelem.length; i++) {
 1213:             if (radelem[i].checked) {
 1214:                 if (radelem[i].value == 'crs') {
 1215:                     typepick = 0;
 1216:                 } else if (radelem[i].value == 'dom') {
 1217:                     typepick = 1;
 1218:                 }
 1219:                 break;
 1220:             }
 1221:         }
 1222:     }
 1223:     if (supplementalflag == 1) {
 1224:         prefix = 'supp';
 1225:     }
 1226:     $exttoolnums
 1227:     $exttooloptions
 1228:     if ((typepick == 0) || (typepick == 1)) {
 1229:         var selelem = form.elements['exttoolid'];
 1230:         var i, numopts = selelem.options.length -1;
 1231:         if (numopts >=0) {
 1232:             for (i = numopts; i >= 0; i--) {
 1233:                 selelem.remove(i);
 1234:             }
 1235:         }
 1236:         if (ltitoolsnum[typepick]) {
 1237:             if ((Array.isArray(tooloptval[typepick])) && (Array.isArray(toolopttxt[typepick]))) {
 1238:                 var len = tooloptval[typepick].length;
 1239:                 if (len) {
 1240:                     selelem.options[selelem.options.length] = new Option('$js_lt{sele}','',1,1);
 1241:                     var j;
 1242:                     for (j=0; j<len; j++) {
 1243:                         selelem.options[selelem.options.length] = new Option(toolopttxt[typepick][j],tooloptval[typepick][j]);
 1244:                     }
 1245:                     selelem.selectedIndex = 0;
 1246:                 }
 1247:             }
 1248:             if (document.getElementById('LC_exttoolon'+prefix)) {
 1249:                 document.getElementById('LC_exttoolon'+prefix).style.display = 'block';
 1250:             }
 1251:             if (document.getElementById('LC_exttooloff'+prefix)) {
 1252:                 document.getElementById('LC_exttooloff'+prefix).style.display = 'none';
 1253:             }
 1254:             if (document.getElementById('LC_addtool'+prefix)) {
 1255:                 document.getElementById('LC_addtool'+prefix).style.display = 'block';
 1256:             }
 1257:         } else {
 1258:             if (document.getElementById('LC_exttoolon'+prefix)) {
 1259:                 document.getElementById('LC_exttoolon'+prefix).style.display = 'none';
 1260:             }
 1261:             if (document.getElementById('LC_exttooloff'+prefix)) {
 1262:                 document.getElementById('LC_exttooloff'+prefix).style.display = 'block';
 1263:             }
 1264:             if (document.getElementById('LC_addtool'+prefix)) {
 1265:                 document.getElementById('LC_addtool'+prefix).style.display = 'none';
 1266:             }
 1267:         }
 1268:         if (selelem.options.length == 0) {
 1269:             selelem.options[selelem.options.length] = new Option('','');
 1270:             selelem.selectedIndex = 0;
 1271:         }
 1272:         updateExttool(selelem,form,supplementalflag);
 1273:         resize_scrollbox('contentscroll','1','1');
 1274:     }
 1275:     return;
 1276: }
 1277: 
 1278: function updateExttool(caller,form,supplementalflag) {
 1279:     var prefix = '';
 1280:     if (supplementalflag == 1) {
 1281:         prefix = 'supp';
 1282:     }
 1283:     dispdiv = prefix+'tooldispdiv';
 1284:     dimendiv = prefix+'tooldimendiv';
 1285:     widthinput = prefix+'tooldimenwidth';
 1286:     heightinput = prefix+'tooldimenheight';
 1287:     labeldiv = prefix+'toolcrslabeldiv';
 1288:     titlediv = prefix+'toolcrstitlediv';
 1289:     appenddiv = prefix+'toolcrsappenddiv';
 1290:     gradablediv = prefix+'toolgradablediv';
 1291:     providerurl = prefix+'toolproviderurl';
 1292:     labelinput = prefix+'toolcrslabel';
 1293:     titleinput = prefix+'toolcrstitle';
 1294:     appendinput = prefix+'toolcrsappend';
 1295:     windiv = prefix+'toolwindiv';  
 1296:     linktextdiv = prefix+'toollinktextdiv';
 1297:     linktextinput = prefix+'toollinktext';
 1298:     explanationdiv = prefix+'toolexplanationdiv';
 1299:     explanationinput = prefix+'toolexplanation';
 1300:     if (document.getElementById(dispdiv)) {
 1301:         var toolpick = caller.options[caller.selectedIndex].value;
 1302:         $toolsjs
 1303:         if (toolpick == '') {
 1304:             if (document.getElementById(dispdiv)) {
 1305:                 document.getElementById(dispdiv).style.display = 'none';    
 1306:             }
 1307:             if (document.getElementById(dimendiv)) {
 1308:                 document.getElementById(dimendiv).style.display = 'none';
 1309:             }
 1310:             if (document.getElementById(windiv)) {
 1311:                 document.getElementById(windiv).style.display = 'none';
 1312:             }
 1313:             if (document.getElementById(linktextdiv)) {
 1314:                 document.getElementById(linktextdiv).style.display = 'none';
 1315:             }
 1316:             if (document.getElementById(explanationdiv)) {
 1317:                 document.getElementById(explanationdiv).style.display = 'none';
 1318:             }
 1319:             if (document.getElementById(labeldiv)) {
 1320:                 document.getElementById(labeldiv).style.display = 'none';
 1321:             }
 1322:             if (document.getElementById(titlediv)) {
 1323:                 document.getElementById(titlediv).style.display = 'none';
 1324:             }
 1325:             if (document.getElementById(appenddiv)) {
 1326:                 document.getElementById(appenddiv).style.display = 'none';
 1327:             }
 1328:             if (document.getElementById(gradablediv)) {
 1329:                 document.getElementById(gradablediv).style.display = 'none';
 1330:             }
 1331:         } else {
 1332:             var tooltype = '';
 1333:             var typeelem = form.elements[prefix+'exttooltype'];
 1334:             if (typeelem.length) {
 1335:                 for (var i=0; i<typeelem.length; i++) {
 1336:                     if (typeelem[i].checked) {
 1337:                         tooltype = typeelem[i].value;
 1338:                     }
 1339:                 }
 1340:             }
 1341:             if ((tooltype == 'crs') || (tooltype == 'dom')) {
 1342:                 var i = 0;
 1343:                 if (tooltype == 'dom') {
 1344:                     i = 1;
 1345:                 }
 1346:                 if (ltitools[i].length > 0) {
 1347:                     for (var j=0; j<ltitools[i].length; j++) {
 1348:                         if (ltitools[i][j] == toolpick) {
 1349:                             if (document.getElementById(dispdiv)) {
 1350:                                 if (ltitoolsDisplay[i][j]) {
 1351:                                     document.getElementById(dispdiv).style.display = 'block';
 1352:                                     if (form.exttooltarget.length) {
 1353:                                         for (var k=0; k<form.exttooltarget.length; k++) {
 1354:                                             if (form.exttooltarget[k].value == ltitoolsTarget[i][j]) {
 1355:                                                 form.exttooltarget[k].checked = true;
 1356:                                                 break;
 1357:                                             }
 1358:                                         }
 1359:                                     }
 1360:                                 }
 1361:                                 var dimen = 'none';
 1362:                                 var dimenwidth = '';
 1363:                                 var dimenheight = '';
 1364:                                 if ((ltitoolsDisplay[i][j]) && (ltitoolsTarget[i][j] == 'window')) {
 1365:                                     dimen = 'block';
 1366:                                     dimenwidth = ltitoolsWidth[i][j];
 1367:                                     dimenheight = ltitoolsHeight[i][j];
 1368:                                 }
 1369:                                 if (document.getElementById(dimendiv)) {
 1370:                                     document.getElementById(dimendiv).style.display = dimen;
 1371:                                 }
 1372:                                 if (document.getElementById(widthinput)) {
 1373:                                     document.getElementById(widthinput).value = dimenwidth;
 1374:                                 }
 1375:                                 if (document.getElementById(heightinput)) {
 1376:                                     document.getElementById(heightinput).value = dimenheight;
 1377:                                 }
 1378:                             }
 1379:                             if (document.getElementById(windiv)) {
 1380:                                 if ((ltitoolsTarget[i][j] == 'window') || (ltitoolsTarget[i][j] == 'tab')) {
 1381:                                     document.getElementById(windiv).style.display = 'block';
 1382:                                 } else {
 1383:                                     document.getElementById(windiv).style.display = 'none';
 1384:                                 }
 1385:                                 if (document.getElementById(linktextdiv)) {
 1386:                                     if (ltitoolsLink[i][j]) {
 1387:                                         document.getElementById(linktextdiv).style.display = 'inline';
 1388:                                     } else {
 1389:                                         document.getElementById(linktextdiv).style.display = 'none';
 1390:                                     }
 1391:                                 }
 1392:                                 if (document.getElementById(linktextinput)) {
 1393:                                     if (ltitoolsLink[i][j]) {
 1394:                                         document.getElementById(linktextinput).value = ltitoolsLinkDef[i][j];
 1395:                                     } else {
 1396:                                         document.getElementById(linktextinput).value = '';
 1397:                                     }
 1398:                                 }
 1399:                                 if (document.getElementById(explanationdiv)) {
 1400:                                     if (ltitoolsExplain[i][j]) {
 1401:                                         document.getElementById(explanationdiv).style.display = 'inline';
 1402:                                     } else {
 1403:                                         document.getElementById(explanationdiv).style.display = 'none';
 1404:                                     }
 1405:                                 }
 1406:                                 if (document.getElementById(explanationinput)) {
 1407:                                     if (ltitoolsExplain[i][j]) {
 1408:                                         document.getElementById(explanationinput).value = ltitoolsExplainDef[i][j];
 1409:                                     } else {
 1410:                                         document.getElementById(explananationinput).value = '';
 1411:                                     }
 1412:                                 }
 1413:                             }
 1414:                             if (document.getElementById(labeldiv)) {
 1415:                                 if (ltitoolsLabel[i][j]) {
 1416:                                     document.getElementById(labeldiv).style.display = 'inline';
 1417:                                 } else {
 1418:                                     document.getElementById(labeldiv).style.display = 'none';
 1419:                                 }
 1420:                             }
 1421:                             if (document.getElementById(titlediv)) {
 1422:                                 if (ltitoolsTitle[i][j]) {
 1423:                                     document.getElementById(titlediv).style.display = 'inline';
 1424:                                 } else {
 1425:                                     document.getElementById(titlediv).style.display = 'none';
 1426:                                 }
 1427:                             }
 1428:                             if (document.getElementById(appenddiv)) {
 1429:                                 if (ltitoolsAppend[i][j]) {
 1430:                                     document.getElementById(appenddiv).style.display = 'inline';
 1431:                                     if (document.getElementById(providerurl)) {
 1432:                                         if ((ltitoolsUrl[i][j] != '') && (ltitoolsUrl[i][j] != null)) {
 1433:                                             document.getElementById(providerurl).innerHTML = '&nbsp;('+ltitoolsUrl[i][j]+')<br />';
 1434:                                         }
 1435:                                     }
 1436:                                 } else {
 1437:                                     document.getElementById(appenddiv).style.display = 'none';
 1438:                                     if (document.getElementById(providerurl)) {
 1439:                                         document.getElementById(providerurl).innerHTML = '';
 1440:                                     }
 1441:                                 }
 1442:                             }
 1443:                             if (document.getElementById(gradablediv)) {
 1444:                                 if (supplementalflag != 1) {
 1445:                                     document.getElementById(gradablediv).style.display = 'inline';
 1446:                                 }
 1447:                             }
 1448:                             break;
 1449:                         }
 1450:                     }
 1451:                 }
 1452:             }
 1453:         }
 1454:     }
 1455: }
 1456: 
 1457: function updateTooldim(form,dimendiv,windiv,widthinput,heightinput,linkinput,explaininput) {
 1458:     if (form.exttooltarget.length) {
 1459:         for (var i=0; i<form.exttooltarget.length; i++) {
 1460:             if (form.exttooltarget[i].checked) {
 1461:                 var dimen = 'none';
 1462:                 var linkconf = 'none';
 1463:                 if (form.exttooltarget[i].value == 'window') {
 1464:                     dimen = 'block';
 1465:                     linkconf = 'block';
 1466:                 } else {
 1467:                     if (form.exttooltarget[i].value == 'tab') {
 1468:                         linkconf = 'block';
 1469:                     } else {
 1470:                         if (document.getElementById(widthinput)) {
 1471:                             document.getElementById(widthinput).value = '';
 1472:                         }
 1473:                         if (document.getElementById(heightinput)) {
 1474:                             document.getElementById(heightinput).value = '';
 1475:                         }
 1476:                         if (document.getElementById(linkinput)) {
 1477:                             document.getElementById(linkinput).value = '';
 1478:                         }
 1479:                         if (document.getElementById(explaininput)) {
 1480:                             document.getElementById(explaininput).value = '';
 1481:                         }
 1482:                     }
 1483:                 }
 1484:                 if (document.getElementById(dimendiv)) {
 1485:                     document.getElementById(dimendiv).style.display = dimen;
 1486:                 }
 1487:                 if (document.getElementById(windiv)) {
 1488:                     document.getElementById(windiv).style.display = linkconf;
 1489:                 }
 1490:                 break;
 1491:             }
 1492:         }
 1493:     }
 1494: }
 1495: 
 1496: ENDJS
 1497: 
 1498: }
 1499: 
 1500: 1;

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