File:  [LON-CAPA] / loncom / interface / lonextresedit.pm
Revision 1.8.2.4.4.3: download - view: text, annotated - select for diffs
Tue Jul 11 23:17:40 2023 UTC (10 months, 3 weeks ago) by raeburn
Branches: version_2_11_4_msu
Diff to branchpoint 1.8.2.4: preferred, unified
- Satisfy w3c HTML validation which does not allow id="" attributew.

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

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