File:  [LON-CAPA] / loncom / interface / lonextresedit.pm
Revision 1.26: download - view: text, annotated - select for diffs
Wed Jul 4 13:55:27 2018 UTC (5 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6754 LON-CAPA as LTI Consumer
  - Move External Resource and External Tool to separate "tab".

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

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