Annotation of loncom/interface/lonextresedit.pm, revision 1.8.2.4.2.1

1.1       raeburn     1: # The LearningOnline Network
                      2: # Documents
                      3: #
1.8.2.4.2.1! raeburn     4: # $Id: lonextresedit.pm,v 1.8.2.4 2019/07/30 19:53:22 raeburn Exp $
1.1       raeburn     5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
                     29: package Apache::lonextresedit;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common :http);
                     33: use HTML::Entities;
                     34: use Apache::lonlocal;
                     35: use Apache::lonnet;
                     36: use Apache::loncommon;
                     37: use Apache::lonhtmlcommon;
                     38: use Apache::lonuserstate;
                     39: use LONCAPA::map();
                     40: use LONCAPA qw(:DEFAULT :match);
                     41: 
                     42: sub handler {
                     43:     my $r=shift;
                     44:     &Apache::loncommon::content_type($r,'text/html');
                     45:     $r->send_http_header;
                     46: 
                     47:     return OK if $r->header_only;
                     48: 
                     49:     # Check for access
                     50:     if (! &Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
                     51:         $env{'user.error.msg'}=
                     52:             $r->uri.":mdc:0:0:Cannot modify course content.";
                     53:             return HTTP_NOT_ACCEPTABLE;
                     54:     }
                     55: 
                     56:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                     57:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                     58:     my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
1.8.2.4.2.1! raeburn    59:     my ($supplementalflag,$updated,$output,$errormsg,$residx,$url,$title,
        !            60:         $symb,$type);
1.5       raeburn    61:     if (($env{'form.folderpath'} =~ /^supplemental/) && ($env{'form.suppurl'})) {
                     62:         $supplementalflag = 1;
1.8.2.4.2.1! raeburn    63:         if (&unescape($env{'form.suppurl'}) =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
        !            64:             $type = 'tool';
        !            65:         }
1.7       raeburn    66:     }
1.5       raeburn    67:     if (($supplementalflag) || ($env{'form.symb'} =~ /^uploaded/)) {
1.7       raeburn    68:         ($updated,$output,$errormsg,$residx,$url,$title,$symb) =
1.1       raeburn    69:             &process_changes($supplementalflag,$cdom,$cnum,$chome);
                     70:         if ($supplementalflag) {
1.8.2.4.2.1! raeburn    71:             if ($url ne &unescape($env{'form.suppurl'})) {
1.1       raeburn    72:                  $env{'form.suppurl'} = $url;
                     73:             }
                     74:             if ($title ne $env{'form.title'}) {
                     75:                 $env{'form.title'} = $title;
                     76:             }
1.5       raeburn    77:             $env{'form.idx'} = $residx;
1.1       raeburn    78:         } else {
                     79:             if ($symb ne $env{'form.symb'}) {
                     80:                 $env{'form.symb'} = $symb;
                     81:             }
1.8.2.4.2.1! raeburn    82:             if ($url =~ m{/adm/$cdom/$cnum/\d+/ext\.tool$}) {
        !            83:                 $type = 'tool';
        !            84:             }
1.1       raeburn    85:         }
                     86:     } else {
                     87:         $errormsg = &mt('Information about external resource to edit is missing.');
                     88:     }
                     89:     if ($updated) {
1.8.2.4.2.1! raeburn    90:         my $msg = &mt('External Resource updated');
        !            91:         if ($type eq 'tool') {
        !            92:             $msg = &mt('External Tool updated');
        !            93:         }
        !            94:         $output = &Apache::lonhtmlcommon::confirm_success($msg);
1.1       raeburn    95:     }
                     96:     if ($errormsg) {
                     97:         $errormsg = '<p class="LC_error">'.$errormsg.'</p>';
                     98:     }
1.8.2.4.2.1! raeburn    99:     my %ltitools;
        !           100:     if ($type eq 'tool') {
        !           101:         %ltitools = &Apache::lonnet::get_domain_ltitools($cdom);
        !           102:     }
1.1       raeburn   103:     my $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
                    104:     my $pathitem = '<input type="hidden" name="folderpath" value="'.
                    105:                    &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.8.2.4.2.1! raeburn   106:     my $description = 'External Resource Editor';
        !           107:     if ($type eq 'tool') {
        !           108:         $description = 'External Tool Editor'; 
        !           109:     }
        !           110:     $r->print(&Apache::loncommon::start_page($description,$js).
1.1       raeburn   111:               '<div class="LC_left_float">'.
                    112:               $output.
                    113:               $errormsg.
                    114:               &extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,
1.8.2.4.2.1! raeburn   115:                            'direct',$env{'form.symb'},$type,$cdom,$cnum,\%ltitools).
1.1       raeburn   116:               '</div>'.&Apache::loncommon::end_page());
                    117:     return OK;
                    118: }
                    119: 
                    120: sub process_changes {
                    121:     my ($supplementalflag,$cdom,$cnum,$chome) = @_;
1.8.2.4.2.1! raeburn   122:     my ($folder,$container,$output,$errormsg,$updated,$symb,$oldidx,$oldurl,$type,
        !           123:         $oldtitle,$newidx,$newurl,$newtitle,$residx,$url,$title,$marker,$args);
1.1       raeburn   124:     if ($env{'form.symb'}) {
                    125:         $symb = $env{'form.symb'};
1.5       raeburn   126:         (my $map,$oldidx,$oldurl)=&Apache::lonnet::decode_symb($symb);
1.1       raeburn   127:         if ($map =~ m{^uploaded/$cdom/$cnum/(default(_\d+|))\.(sequence|page)$}) {
                    128:             $folder = $1;
                    129:             $container = $3;
                    130:         }
                    131:         $oldtitle = &Apache::lonnet::gettitle($env{'form.symb'});
1.8.2.4.2.1! raeburn   132:         if ($oldurl =~ m{^ext/(.+)$}) {
        !           133:             my $external = $1;
        !           134:             if ($external =~ m{^https://}) {
        !           135:                 $oldurl = $external;
        !           136:             } else {
        !           137:                 $oldurl = 'http://'.$oldurl;
        !           138:             }
        !           139:             $type = 'ext';
        !           140:         } else {
        !           141:             $type = 'tool';
        !           142:         }
1.1       raeburn   143:     } elsif ($env{'form.folderpath'}) {
                    144:         $folder = &unescape( (split('&',$env{'form.folderpath'}))[-2] );
                    145:         $oldurl = &unescape($env{'form.suppurl'});
                    146:         $oldtitle = &unescape($env{'form.title'});
                    147:         $container = 'sequence';
                    148:         $supplementalflag = 1;
1.8.2.4.2.1! raeburn   149:         if ($oldurl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
        !           150:             $type = 'tool';
1.5       raeburn   151:         } else {
1.8.2.4.2.1! raeburn   152:             $type = 'ext';
1.5       raeburn   153:         }
                    154:     }
                    155:     $url = $oldurl;
                    156:     $title = $oldtitle;
                    157:     if ($env{'form.importdetail'}) {
                    158:         ($newtitle,$newurl,$newidx) =
                    159:             map {&unescape($_)} split(/\=/,$env{'form.importdetail'});
1.8.2.4.2.1! raeburn   160:         if ($newurl =~ m{^(/adm/$cdom/$cnum/(\d+)/ext\.tool)\:?(.*)$}) {
        !           161:             $newurl = $1;
        !           162:             $marker = $2;
        !           163:             $args = $3;
        !           164:         }
1.5       raeburn   165:     }
                    166:     if ($supplementalflag) {
                    167:         $residx = $newidx;
                    168:     } else {
                    169:         $residx = $oldidx;
                    170:     }
1.1       raeburn   171:     if ($folder && $container) {
                    172:         if ($env{'form.importdetail'}) {
1.5       raeburn   173:             my ($errtext,$fatal,$mismatchedid,@imports);
                    174:             if (!$supplementalflag) {
                    175:                 if (($oldidx) && ($oldidx != $newidx)) {
                    176:                     $mismatchedid = 1;
                    177:                 }
1.1       raeburn   178:             }
                    179:             if ($mismatchedid) {
                    180:                 $errormsg = 'Wrong item identifier';
                    181:             } elsif (($newtitle eq $oldtitle) && ($newurl eq $oldurl)) {
1.8.2.4.2.1! raeburn   182:                 if ($type eq 'tool') {
        !           183:                     if ($args) {
        !           184:                         ($updated,$errormsg) = &update_exttool($marker,$cdom,$cnum,$args);
        !           185:                         unless ($updated) {
        !           186:                             $output = &mt('No change');      
        !           187:                         }
        !           188:                     } else {
        !           189:                         $output = &mt('No change');
        !           190:                     }
        !           191:                 } else {
        !           192:                     $output = &mt('No change');
        !           193:                 }
1.1       raeburn   194:             } else {
                    195:                 my $map = "/uploaded/$cdom/$cnum/$folder.$container";
                    196:                 my ($errtext,$fatal) = &LONCAPA::map::mapread($map);
                    197:                 if ($fatal) {
                    198:                     $errormsg = &mt('Update failed: [_1].',$errtext);
                    199:                 } else {
                    200:                     my $saveurl = &LONCAPA::map::qtunescape($newurl);
                    201:                     my $savetitle = &LONCAPA::map::qtunescape($newtitle);
1.8.2.4.2.1! raeburn   202:                     my $ext = 'true';
        !           203:                     if ($type eq 'tool') {
        !           204:                         if ($args) {
        !           205:                             ($updated,$errormsg) = &update_exttool($marker,$cdom,$cnum,$args);
        !           206:                         }
        !           207:                         $ext = 'false';
        !           208:                     }
1.1       raeburn   209:                     $LONCAPA::map::resources[$residx] =
1.8.2.4.2.1! raeburn   210:                         join(':', ($savetitle,$saveurl,$ext,'normal','res'));
1.1       raeburn   211:                     my ($outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                    212:                     if ($errtext) {
                    213:                         $errormsg = &mt('Update failed: [_1].',$errtext);
                    214:                     } else {
                    215:                         $updated = 1;
1.5       raeburn   216:                         $title = $newtitle;
                    217:                         if ($newurl ne $oldurl) {
                    218:                             $url = $newurl;
1.8.2.4.2.1! raeburn   219:                             if ($ext eq 'true') {
        !           220:                                 $newurl =~ s{^http://}{};
        !           221:                                 $newurl = "ext/$newurl";
        !           222:                             }
1.5       raeburn   223:                         }
1.1       raeburn   224:                         if (!$supplementalflag) {
                    225:                             if ($newurl ne $oldurl) {
1.5       raeburn   226:                                 $symb = &Apache::lonnet::encode_symb($map,$residx,$newurl);
1.1       raeburn   227:                             } else {
                    228:                                 $symb = $env{'form.symb'};
                    229:                                 if ($symb) {
                    230:                                     &Apache::lonnet::devalidate_title_cache($symb);
                    231:                                 }
                    232:                             }
                    233:                         }
1.5       raeburn   234:                         my ($furl,$ferr) = 
                    235:                             &Apache::lonuserstate::readmap("$cdom/$cnum");
1.1       raeburn   236:                         if ($ferr) {
                    237:                             $errormsg = &mt('Reload failed: [_1].',$ferr);
                    238:                         } else {
1.5       raeburn   239:                             unless ($supplementalflag) {
                    240:                                 &Apache::loncommon::update_content_constraints($cdom,$cnum,$chome,$cdom.'_'.$cnum);
                    241:                             }
1.1       raeburn   242:                         }
                    243:                     }
                    244:                 }
                    245:             }
                    246:         } else {
                    247:             $output = &mt('No change');
                    248:         }
                    249:     } else {
1.8.2.4.2.1! raeburn   250:         if ($type eq 'tool') {
        !           251:             $errormsg = &mt('Information about current external tool is incomplete.');
        !           252:         } else {
        !           253:             $errormsg = &mt('Information about current external resource is incomplete.');
        !           254:         }
1.1       raeburn   255:     }
1.5       raeburn   256:     return ($updated,$output,$errormsg,$residx,$url,$title,$symb);
1.1       raeburn   257: }
                    258: 
1.8.2.4.2.1! raeburn   259: sub update_exttool {
        !           260:     my ($marker,$cdom,$cnum,$args) = @_;
        !           261:     my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
        !           262:     my (%newhash,$changed,@deleted,$errormsg);
        !           263:     ($newhash{'target'},$newhash{'width'},$newhash{'height'},$newhash{'linktext'},$newhash{'explanation'},
        !           264:      $newhash{'crslabel'},$newhash{'crstitle'}) = split(/:/,$args);
        !           265:     foreach my $item ('linktext','explanation','crslabel','crstitle') {
        !           266:         $newhash{$item} = &unescape($newhash{$item});
        !           267:     }
        !           268:     my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
        !           269:     foreach my $item ('target','width','height','linktext','explanation','crslabel','crstitle') {
        !           270:         $newhash{$item} =~ s/^\s+//;
        !           271:         $newhash{$item} =~ s/\s+$//;
        !           272:         if (($item eq 'width') || ($item eq 'height') || ($item eq 'linktext') || ($item eq 'explanation')) {
        !           273:             if ($newhash{'target'} eq 'iframe') {
        !           274:                 $newhash{$item} = '';
        !           275:             } elsif ($newhash{'target'} eq 'tab') {
        !           276:                 if (($item eq 'width') || ($item eq 'height')) {
        !           277:                     $newhash{$item} = '';
        !           278:                 }
        !           279:             }
        !           280:         }
        !           281:         if ($toolhash{$item} ne $newhash{$item}) {
        !           282:             if ($newhash{$item} eq '') {
        !           283:                 unless (($item eq 'target') ||
        !           284:                         ((($item eq 'width') || ($item eq 'height')) &&
        !           285:                          (($newhash{'target'} eq 'window') || 
        !           286:                           (($newhash{'target'} eq '') && ($toolhash{'target'} eq 'window')))) ||
        !           287:                         ((($item eq 'linktext') || ($item eq 'explanation')) &&
        !           288:                          ((($newhash{'target'} =~ /^(window|tab)$/)) ||
        !           289:                          (($newhash{'target'} eq '') && ($toolhash{'target'} =~ /^(window|tab)$/))))) {
        !           290:                     delete($toolhash{$item});
        !           291:                     push(@deleted,$item);
        !           292:                     $changed = 1;
        !           293:                 }
        !           294:             } else {
        !           295:                 $toolhash{$item} = $newhash{$item};
        !           296:                 $changed = 1; 
        !           297:             }
        !           298:         }
        !           299:     }
        !           300:     if ($changed) {
        !           301:         my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$cdom,$cnum);
        !           302:         unless ($putres eq 'ok') {
        !           303:             $errormsg = &mt('Failed to save updated settings.').' '.&mt('Error: [_1].',$putres);
        !           304:         }
        !           305:     }
        !           306:     if (@deleted) {
        !           307:         &Apache::lonnet::del('exttool_'.$marker,\@deleted,$cdom,$cnum);
        !           308:     }
        !           309:     return ($changed,$errormsg);
        !           310: }
        !           311: 
1.1       raeburn   312: sub extedit_form {
1.8.2.4.2.1! raeburn   313:     my ($supplementalflag,$residx,$orig_url,$orig_title,$pathitem,$helpitem,$caller,
        !           314:         $symb,$type,$cdom,$cnum,$ltitools,$disabled) = @_;
        !           315:     if ($type ne 'tool') {
        !           316:         $type = 'ext';
        !           317:     }
1.1       raeburn   318:     my %lt = &Apache::lonlocal::texthash(
                    319:         ex => 'External Resource',
1.8.2.4.2.1! raeburn   320:         et => 'External Tool',
1.1       raeburn   321:         ed => 'Edit',
                    322:         ee => 'External Resource Editor',
1.8.2.4.2.1! raeburn   323:         te => 'External Tool Editor',
1.1       raeburn   324:         pr => 'Preview',
                    325:         sv => 'Save',
                    326:         ul => 'URL',
                    327:         ti => 'Title',
                    328:         al => 'Add Link',
1.8.2.4.2.1! raeburn   329:         at => 'Add Tool',
1.1       raeburn   330:     );
                    331:     my $tabid = 'aa';
                    332:     my $size = 60;
                    333:     if ($supplementalflag) {
                    334:         $tabid = 'ee';
                    335:     }
1.8.2.4.2.1! raeburn   336:     my ($formname,$formid,$toggle,$fieldsetid,$urlid,$dispdivstyle,$dimendivstyle,
        !           337:         $windivstyle,$linktextstyle,$explanationstyle,$labelstyle,$titlestyle,
        !           338:         $legend,$urlelem,$toolelem,%toolattr);
        !           339:     $formname = 'new'.$type;
        !           340:     $toggle = $type;
        !           341:     $fieldsetid = 'upload'.$type.'form';
        !           342:     $urlid = $type.'url';
        !           343:     map { $toolattr{$_} = $type.$_; } ('dispdiv','dimendiv','dimenwidth','dimenheight',
        !           344:                                        'crstitlediv','crslabeldiv','crstitle','crslabel',
        !           345:                                        'windiv','linktextdiv','explanationdiv','linktext', 
        !           346:                                        'explanation');
        !           347:     $dispdivstyle = 'display:none';
        !           348:     $dimendivstyle = 'display:none';
        !           349:     $windivstyle = 'display:none';
        !           350:     $linktextstyle = 'display:none';
        !           351:     $explanationstyle = 'display:none';
        !           352:     $labelstyle = 'display:none';
        !           353:     $titlestyle = 'display:none';
        !           354:     if ($supplementalflag) {
        !           355:         $formname = 'newsupp'.$type;
        !           356:         $toggle = 'supp'.$type;
        !           357:         $fieldsetid = 'uploadsupp'.$type.'form';
        !           358:         $urlid = 'supp'.$type.'url';
        !           359:         map { $toolattr{$_} = 'supp'.$toolattr{$_}; } (keys(%toolattr));
        !           360:     }
        !           361:     my ($link,$legend,$active,$srcclass,$extsrc,$preview,$title,$save,$crstitle,$crslabel,
        !           362:         $fieldsetstyle,$action,$hiddenelem,$form,$width,$height,$tooltarget,
        !           363:         $linktext,$explanation,%chkstate);
1.1       raeburn   364:     $fieldsetstyle = 'display: none;';
                    365:     $action = '/adm/coursedocs';
1.8.2.2   raeburn   366:     my $protocol = ($ENV{'SERVER_PORT'} == 443?'https':'http');
1.8.2.4.2.1! raeburn   367:     my $rows = 2;
        !           368:     my $cols = 20;
1.1       raeburn   369:     if ($residx) {
                    370:         if ($caller eq 'direct') {
                    371:             $fieldsetstyle = 'display: block;';
                    372:             $action = '/adm/extresedit';
1.8.2.4.2.1! raeburn   373:             $rows = 10;
        !           374:             $cols = 45;
        !           375:             if ($type eq 'tool') {
        !           376:                 $legend = $lt{'ee'};
        !           377:             } else {
        !           378:                 $legend = $lt{'te'};
        !           379:             }
        !           380:             $legend = '<legend>'.$legend.'</legend>';
1.1       raeburn   381:             if ($symb) {
                    382:                 $hiddenelem = '<input type="hidden" name="symb" value="'.$symb.'" />';
                    383:             } elsif ($supplementalflag) {
                    384:                 $hiddenelem = '<input type="hidden" name="suppurl" value="'.
                    385:                               &HTML::Entities::encode(&escape($orig_url),'<>&"').'" />'."\n".
                    386:                               '<input type="hidden" name="title" value="'.
                    387:                               &HTML::Entities::encode(&escape($orig_title),'<>&"').'" />';
                    388:             }
1.8.2.4.2.1! raeburn   389:         } else {
        !           390:             $link = '<a class="LC_docs_ext_edit" href="javascript:editext('."'$residx','$type'".');">'.$lt{'ed'}.'</a>&nbsp;'."\n";
1.1       raeburn   391:             $size = 40;
1.3       raeburn   392:             $active = '<input type="hidden" name="active" value="'.$tabid.'" />';
1.1       raeburn   393:         }
1.8.2.4.2.1! raeburn   394:         $formname = 'edit'.$type.'_'.$residx;
        !           395:         $fieldsetid = 'upload'.$type.$residx;
        !           396:         $urlid = $type.'url_'.$residx;
        !           397:         map { $toolattr{$_} .= '_'.$residx; } (keys(%toolattr));
1.1       raeburn   398:         $srcclass = ' class="LC_nobreak"';
1.8.2.4.2.1! raeburn   399:         if ($type eq 'ext') {
        !           400:             $extsrc = '<span class="LC_docs_ext_edit">'.$lt{'ul'}.'&nbsp;</span>';
        !           401:             $preview = '&nbsp;<a class="LC_docs_ext_edit" href="javascript:extUrlPreview('."'$urlid','$protocol'".');">'.$lt{'pr'}.'</a>';
        !           402:         }
1.1       raeburn   403:         $title = '<span class="LC_docs_ext_edit">'.$lt{'ti'}.'&nbsp;</span>';
                    404:         $save = $lt{'sv'};
                    405:     } else {
1.8.2.4.2.1! raeburn   406:         $link = $lt{'ex'};
        !           407:         if ($type eq 'tool') {
        !           408:             $link = $lt{'et'};
        !           409:         }
        !           410:         $link = '<a class="LC_menubuttons_link" href="javascript:toggleUpload('."'$toggle'".');">'.$link.'</a>'.$helpitem;
        !           411:         if ($type eq 'tool') {
        !           412:             $legend = $lt{'te'};
        !           413:         } else {
        !           414:             $legend = $lt{'ee'};
        !           415:         }
        !           416:         $legend = '<legend>'.$legend.'</legend>';
1.1       raeburn   417:         $title = $lt{'ti'}.':<br />';
                    418:         $residx = 0;
1.8.2.4.2.1! raeburn   419:         if ($type eq 'ext') {
        !           420:             $orig_url = 'http://';
        !           421:             $orig_title = $lt{'ex'};
        !           422:             $extsrc = $lt{'ul'}.':<br />';
        !           423:             $preview = '<input type="button" name="view" value="'.$lt{'pr'}.'" onclick="javascript:extUrlPreview('."'$urlid','$protocol'".');"'.$disabled.' />';
        !           424:             $save = $lt{'al'};
        !           425:         } else {
        !           426:             $orig_title = $lt{'et'};
        !           427:             $save = $lt{'at'};
        !           428:             $orig_url = "/adm/$cdom/$cnum/new/ext\.tool"; 
        !           429:         }
1.1       raeburn   430:         $pathitem .= '<br />';
                    431:     }
1.8.2.4.2.1! raeburn   432:     $formid = $formname;
        !           433:     if ($type eq 'ext') {
        !           434:         $urlelem = '<input type="text" size="'.$size.'" name="exturl" id="'.$urlid.'" value="'.$orig_url.'"'.$disabled.' />';
        !           435:     } else {
        !           436:         my $class = 'LC_nobreak';
        !           437:         if ($residx) {
        !           438:             $class = 'LC_docs_ext_edit LC_nobreak'; 
        !           439:             if ($orig_url =~ m{^/adm/$cdom/$cnum/(\d+)/ext\.tool$}) {
        !           440:                 my $marker = $1;
        !           441:                 my %toolhash=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
        !           442:                 if ($toolhash{'id'}) {
        !           443:                     if (ref($ltitools) eq 'HASH') {
        !           444:                         if (keys(%{$ltitools})) {
        !           445:                             if (ref($ltitools->{$toolhash{'id'}}) eq 'HASH') {
        !           446:                                 my $tooltitle = $ltitools->{$toolhash{'id'}}->{'title'};
        !           447:                                 my $icon = $ltitools->{$toolhash{'id'}}->{'image'};
        !           448:                                 my $image;
        !           449:                                 if ($icon) {
        !           450:                                     $image = '<img src="'.$icon.'" alt="'.$tooltitle.'" />';
        !           451:                                 }
        !           452:                                 $tooltarget = $toolhash{'target'};
        !           453:                                 if ($tooltarget eq 'window') {
        !           454:                                     $dimendivstyle = 'display:block';
        !           455:                                     $windivstyle = 'display:block';
        !           456:                                     $chkstate{'window'} = 'checked="checked" ';
        !           457:                                 } elsif ($tooltarget eq 'tab') {
        !           458:                                     $windivstyle = 'display:block';
        !           459:                                     $chkstate{'tab'} = 'checked="checked" ';
        !           460:                                 } else {
        !           461:                                     $chkstate{'iframe'} = 'checked="checked" ';
        !           462:                                 }
        !           463:                                 $width = $toolhash{'width'};
        !           464:                                 $height = $toolhash{'height'};
        !           465:                                 $linktext = $toolhash{'linktext'};
        !           466:                                 $explanation = $toolhash{'explanation'};
        !           467:                                 if (ref($ltitools->{$toolhash{'id'}}->{'crsconf'}) eq 'HASH') {
        !           468:                                     if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'title'}) {
        !           469:                                         $crstitle = $toolhash{'crstitle'};
        !           470:                                         $titlestyle = 'display:inline';
        !           471:                                     }
        !           472:                                     if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'label'}) {  
        !           473:                                         $crslabel = $toolhash{'crslabel'};
        !           474:                                         $labelstyle = 'display:inline';
        !           475:                                     }
        !           476:                                     if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'target'}) {
        !           477:                                         $dispdivstyle = 'display:block';
        !           478:                                     }
        !           479:                                     if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'linktext'}) {
        !           480:                                         $linktextstyle = 'padding:0;display:inline';
        !           481:                                     }
        !           482:                                     if ($ltitools->{$toolhash{'id'}}->{'crsconf'}->{'explanation'}) {
        !           483:                                         $explanationstyle = 'padding:0;display:inline';
        !           484:                                     }
        !           485:                                 }
        !           486:                                 $toolelem = '<span class="LC_nobreak">'.$image.'&nbsp;'.$tooltitle.'</span><br />';
        !           487:                             }
        !           488:                         }
        !           489:                     }
        !           490:                 }
        !           491:             }
        !           492:         } else {
        !           493:             $toolelem = '<span class="LC_docs_ext_edit">'."\n".
        !           494:                        '<select name="exttoolid" id="LC_exttoolid" onchange="javascript:updateExttool(this,'.
        !           495:                        'this.form,'."'$supplementalflag'".');"'.$disabled.'>'."\n".
        !           496:                        '<option value="" selected="selected">'.&mt('Select').'</option>';
        !           497:             my %bynum;
        !           498:             if (ref($ltitools) eq 'HASH') {
        !           499:                 foreach my $id (keys(%{$ltitools})) {
        !           500:                     if (ref($ltitools->{$id}) eq 'HASH') {
        !           501:                         my $order = $ltitools->{$id}->{'order'};
        !           502:                         $bynum{$order} = [$id,$ltitools->{$id}];
        !           503:                     }
        !           504:                 }
        !           505:             }
        !           506:             foreach my $item (sort { $a <=> $b } keys(%bynum)) {
        !           507:                 if (ref($bynum{$item}) eq 'ARRAY') {
        !           508:                     if (ref($bynum{$item}->[1]) eq 'HASH') {
        !           509:                         my $tooltitle = $bynum{$item}->[1]->{'title'};
        !           510:                         my $icon =  $bynum{$item}->[1]->{'image'};
        !           511:                         $toolelem .= '<option value="'.$bynum{$item}->[0].'">'.$tooltitle.'</option>';
        !           512:                     }
        !           513:                 }
        !           514:             }
        !           515:             $toolelem .= '</select></span><br />';
        !           516:             $crslabel = $env{'course.'.$cdom.'_'.$cnum.'.internal.coursecode'};
        !           517:             $crstitle = $env{'course.'.$cdom.'_'.$cnum.'.description'};
        !           518:         }
        !           519:         $toolelem .= '<div id="'.$toolattr{'dispdiv'}.'" style="'.$dispdivstyle.'">'.
        !           520:                     '<span class="'.$class.'">'.&mt('Display target:').'&nbsp;'.
        !           521:                     '<label><input type="radio" name="exttooltarget" value="iframe" '.$chkstate{'iframe'}.'onclick="updateTooldim(this.form,'.
        !           522:                     "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
        !           523:                     '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('iframe').'</label>'.('&nbsp;'x2).
        !           524:                     '<label><input type="radio" name="exttooltarget" value="tab" '.$chkstate{'tab'}.'onclick="updateTooldim(this.form,'.
        !           525:                     "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
        !           526:                     '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('tab').'</label>'.('&nbsp;'x2).
        !           527:                     '<label><input type="radio" name="exttooltarget" value="window" '.$chkstate{'window'}.'onclick="updateTooldim(this.form,'.
        !           528:                     "'$toolattr{dimendiv}','$toolattr{windiv}','$toolattr{dimenwidth}','$toolattr{dimenheight}',
        !           529:                     '$toolattr{linktext}','$toolattr{explanation}'".');"'.$disabled.' />'.&mt('window').'</label></span>'.
        !           530:                     '<div id="'.$toolattr{'dimendiv'}.'" style="'.$dimendivstyle.'"><span class="'.$class.'">'.
        !           531:                     &mt('Width').':&nbsp;<input type="text" size="4" id="'.$toolattr{'dimenwidth'}.'" name="exttoolwidth" value="'.$width.'"'.$disabled.' />'.('&nbsp;'x2).
        !           532:                     &mt('Height').':&nbsp;<input type="text" size="4" id="'.$toolattr{'dimenheight'}.'" name="exttoolheight" value="'.$height.'"'.$disabled.' /></span>'."\n".
        !           533:                     '</div></div>';
        !           534:         $toolelem .= '<div id="'.$toolattr{'windiv'}.'" style="'.$windivstyle.'">'.
        !           535:                      '<div id="'.$toolattr{'linktextdiv'}.'" class="LC_left_float" style="'.$linktextstyle.'">'.
        !           536:                      '<span class="'.$class.'">'.&mt('Link Text').'</span><br /><input type="text" size="25" id="'.$toolattr{'linktext'}.
        !           537:                      '" name="exttoollinktext" value="'.$linktext.'"'.$disabled.' />'.
        !           538:                      '</div><div id="'.$toolattr{'explanationdiv'}.'" class="LC_left_float" style="'.$explanationstyle.'">'.
        !           539:                      '<span class="'.$class.'">'.&mt('Explanation').'</span><br />'.
        !           540:                      '<textarea rows="'.$rows.'" cols="'.$cols.'" id="'.$toolattr{'explanation'}.'" name="exttoolexplanation" '.$disabled.'>'.
        !           541:                      $explanation.'</textarea></div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
        !           542:                      '</div>';
        !           543:         $toolelem .= '<div id="'.$toolattr{'crslabeldiv'}.'" style="'.$labelstyle.'">'.
        !           544:                     '<span class="'.$class.'">'.&mt('Course label:').'&nbsp;'.
        !           545:                     '<input type="text" id="'.$toolattr{'crslabel'}.'" name="exttoollabel" value="'.$crslabel.'"'.$disabled.' /></span><br />'.
        !           546:                     '</div>'.
        !           547:                     '<div id="'.$toolattr{'crstitlediv'}.'" style="'.$titlestyle.'">'.
        !           548:                     '<span class="'.$class.'">'.&mt('Course title:').'&nbsp;'.
        !           549:                     '<input type="text" id="'.$toolattr{'crstitle'}.'" name="exttooltitle" value="'.$crstitle.'"'.$disabled.' /></span><br />'.
        !           550:                     '</div>';
        !           551:     }
        !           552:     my $chooser = $toolelem;
        !           553:     if ($type eq 'ext') {
        !           554:         $chooser = "
        !           555: <div>
        !           556: <span$srcclass>
        !           557: $extsrc
        !           558: $urlelem
        !           559: $preview
        !           560: </span>
        !           561: </div>
        !           562: ";
        !           563:     }
1.3       raeburn   564:     $form = <<ENDFORM;
1.8.2.4.2.1! raeburn   565: <form action="$action" method="post" name="$formname" id="$formid">
1.2       raeburn   566: <fieldset id="$fieldsetid" style="$fieldsetstyle">
1.1       raeburn   567: $legend
                    568: $active
1.8.2.4.2.1! raeburn   569: $chooser
        !           570: <div>
1.1       raeburn   571: <span$srcclass>
                    572: $title
1.8.2.1   raeburn   573: <input type="text" size="$size" name="exttitle" value="$orig_title" $disabled />
1.1       raeburn   574: <input type="hidden" name="importdetail" value="" />
                    575: $pathitem
                    576: $hiddenelem
1.8.2.4.2.1! raeburn   577: <input type="button" value="$save" onclick="javascript:setExternal(this.form,'$residx','$type','$orig_url','$supplementalflag');" $disabled />
1.1       raeburn   578: </span>
1.8.2.4.2.1! raeburn   579: </div>
1.1       raeburn   580: </fieldset>
                    581: </form>
                    582: ENDFORM
1.3       raeburn   583:     if (wantarray) {
                    584:         return ($link,$form);
                    585:     } else {
                    586:         return $link.$form;
                    587:     }
1.1       raeburn   588: }
                    589: 
                    590: sub display_editor {
1.8.2.3   raeburn   591:     my ($url,$folderpath,$symb,$idx,$type,$cdom,$cnum,$hostname) = @_;
1.8.2.1   raeburn   592:     my ($residx,$supplementalflag,$title,$pathitem,$output,$js,$navmap);
1.1       raeburn   593:     if ($folderpath =~ /^supplemental/) {
                    594:         $supplementalflag = 1;
                    595:         $residx = $idx;
                    596:         $title = &unescape($env{'form.title'});
                    597:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
                    598:     } elsif ($symb =~ /^uploaded/) {
                    599:         (my $map,$residx,my $res) =
                    600:             &Apache::lonnet::decode_symb($symb);
                    601:         $title = &Apache::lonnet::gettitle($symb);
1.8.2.1   raeburn   602:         my $path = &Apache::loncommon::symb_to_docspath($symb,\$navmap);
1.4       raeburn   603:         $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($path,'<>&"').'" />';
1.1       raeburn   604:     }
1.8.2.4.2.1! raeburn   605:     my %ltitools;
        !           606:     if ($type eq 'tool') {
        !           607:         %ltitools = &Apache::lonnet::get_domain_ltitools($cdom);
        !           608:     }
1.8.2.1   raeburn   609:     $js = &Apache::lonhtmlcommon::scripttag(&extedit_javascript());
1.1       raeburn   610:     my $args = { 'force_register' => $env{'form.register'} };
1.8.2.3   raeburn   611:     if ($hostname) {
                    612:         $args->{'hostname'} = $hostname;
                    613:     }
1.8.2.4.2.1! raeburn   614:     my $description = 'External Resource Editor';
        !           615:     if ($type eq 'tool') {
        !           616:         $description = 'External Tool Editor';
        !           617:     }
        !           618:     return &Apache::loncommon::start_page($description,$js,$args).
1.1       raeburn   619:            '<div class="LC_left_float">'.
1.8.2.4.2.1! raeburn   620:            &extedit_form($supplementalflag,$residx,$url,$title,$pathitem,undef,'direct',
        !           621:                          $symb,$type,$cdom,$cnum,\%ltitools).
1.1       raeburn   622:            '</div>'.
                    623:            &Apache::loncommon::end_page();
                    624: }
                    625: 
                    626: sub extedit_javascript {
1.8.2.4.2.1! raeburn   627:     my ($toolsref) = @_;
        !           628:     my $toolsjs;
        !           629:     if (ref($toolsref) eq 'HASH') {
        !           630:         my $num = scalar(keys(%{$toolsref}));
        !           631:         $toolsjs = "        var ltitools = new Array($num);\n".
        !           632:                    "        var ltitoolsTarget = new Array($num);\n".
        !           633:                    "        var ltitoolsWidth = new Array($num);\n".
        !           634:                    "        var ltitoolsHeight = new Array($num);\n".
        !           635:                    "        var ltitoolsLinkDef = new Array($num);\n".
        !           636:                    "        var ltitoolsExplainDef = new Array($num);\n".
        !           637:                    "        var ltitoolsDisplay = new Array($num);\n".
        !           638:                    "        var ltitoolsLink = new Array($num);\n".
        !           639:                    "        var ltitoolsExplain = new Array($num);\n".
        !           640:                    "        var ltitoolsLabel = new Array($num);\n".
        !           641:                    "        var ltitoolsTitle = new Array($num);\n";
        !           642:         my $i = 0;
        !           643:         foreach my $key (sort { $a <=> $b } keys(%{$toolsref})) {
        !           644:             if (ref($toolsref->{$key}) eq 'HASH') {
        !           645:                 if (ref($toolsref->{$key}->{'display'}) eq 'HASH') {
        !           646:                     my $target = $toolsref->{$key}->{'display'}->{'target'};
        !           647:                     my $width = $toolsref->{$key}->{'display'}->{'width'};
        !           648:                     my $height = $toolsref->{$key}->{'display'}->{'height'};
        !           649:                     my $linkdef = $toolsref->{$key}->{'display'}->{'linktext'};
        !           650:                     my $explaindef = $toolsref->{$key}->{'display'}->{'explanation'};
        !           651:                     $toolsjs .= '        ltitools['.$i.'] = '."'$key';\n".
        !           652:                                 '        ltitoolsTarget['.$i.'] = '."'$target';\n".
        !           653:                                 '        ltitoolsWidth['.$i.'] = '."'$width';\n".
        !           654:                                 '        ltitoolsHeight['.$i.'] = '."'$height';\n".
        !           655:                                 '        ltitoolsLinkDef['.$i.'] = '."'$linkdef';\n".
        !           656:                                 '        ltitoolsExplainDef['.$i.'] = '."'$explaindef';\n";
        !           657:                 }
        !           658:                 if (ref($toolsref->{$key}->{'crsconf'}) eq 'HASH') {
        !           659:                     my $display = $toolsref->{$key}->{'crsconf'}->{'target'};
        !           660:                     $toolsjs .= '         ltitoolsDisplay['.$i.'] = '."'$display';\n";
        !           661:                     my $linktext = $toolsref->{$key}->{'crsconf'}->{'linktext'};
        !           662:                     $toolsjs .= '         ltitoolsLink['.$i.'] = '."'$linktext';\n";
        !           663:                     my $explanation = $toolsref->{$key}->{'crsconf'}->{'explanation'};
        !           664:                     $toolsjs .= '         ltitoolsExplain['.$i.'] = '."'$explanation';\n";
        !           665:                     my $label = $toolsref->{$key}->{'crsconf'}->{'label'};
        !           666:                     $toolsjs .= '         ltitoolsLabel['.$i.'] = '."'$label';\n";
        !           667:                     my $title = $toolsref->{$key}->{'crsconf'}->{'title'};
        !           668:                     $toolsjs .= '         ltitoolsTitle['.$i.'] = '."'$title';\n";
        !           669:                 }
        !           670:                 $i++;
        !           671:             }
        !           672:         }
        !           673:     }
1.8       damieng   674:     my %js_lt = &Apache::lonlocal::texthash(
1.1       raeburn   675:         invurl  => 'Invalid URL',
                    676:         titbl   => 'Title is blank',
1.8.2.4   raeburn   677:         mixfra  => 'Show preview in pop-up? (http in https page + no framing)',
                    678:         mixonly => 'Show preview in pop-up? (http in https page)',
                    679:         fraonly => 'Show preview in pop-up? (framing disallowed)',
                    680:         nopopup => 'Pop-up blocked',
                    681:         nopriv  => 'Insufficient privileges to use preview',
                    682:         badurl  => 'URL is not: http://hostname/path or https://hostname/path',
1.8.2.4.2.1! raeburn   683:         invtool => 'Please select an external tool',
1.1       raeburn   684:     );
1.8       damieng   685:     &js_escape(\%js_lt);
1.1       raeburn   686: 
                    687:     my $urlregexp = <<'ENDREGEXP';
                    688: /^([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
                    689: ENDREGEXP
                    690: 
                    691:     return <<ENDJS;
                    692: 
                    693: var regexp = $urlregexp;
                    694: 
1.8.2.4.2.1! raeburn   695: function setExternal(extform,residx,type,exttoolurl,supplementalflag) {
1.1       raeburn   696:     var title=extform.exttitle.value;
                    697:     if (!String.trim) {
                    698:         String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");};    }
                    699:     if (title == null || title.trim()=="") {
1.8       damieng   700:         alert("$js_lt{'titbl'}");
1.1       raeburn   701:         extform.exttitle.focus();
                    702:         return;
                    703:     }
1.8.2.4.2.1! raeburn   704:     if (type == 'ext') {
        !           705:         var url=extform.exturl.value;
        !           706:         if (!regexp.test(url)) {
        !           707:             alert("$js_lt{'invurl'}");
        !           708:             extform.exturl.focus();
        !           709:             return;
        !           710:         } else {
        !           711:             url = escape(url);
        !           712:             title = escape(title);
        !           713:             if (residx > 0) {
        !           714:                eval("extform.importdetail.value=title+'='+url+'='+residx;extform.submit();");
        !           715:             } else {
        !           716:                eval("extform.importdetail.value=title+'='+url;extform.submit();");
        !           717:             }
        !           718:         }
        !           719:     } else {
1.7       raeburn   720:         title = escape(title);
1.8.2.4.2.1! raeburn   721:         var info = exttoolurl;
        !           722:         if (residx == 0) {
        !           723:             var toolid = parseInt(extform.exttoolid.options[extform.exttoolid.selectedIndex].value);
        !           724:             if (isNaN(toolid)) {
        !           725:                 alert("$js_lt{'invtool'}");
        !           726:                 return;
        !           727:             }
        !           728:             info += ':'+toolid;
        !           729:         }
        !           730:         var prefix = '';
        !           731:         if (supplementalflag == 1) {
        !           732:            prefix = 'supp';
        !           733:         }
        !           734:         var dispdiv = prefix+'tooldispdiv';
        !           735:         var windiv = prefix+'toolwindiv';
1.1       raeburn   736:         if (residx > 0) {
1.8.2.4.2.1! raeburn   737:             dispdiv += '_'+residx;
        !           738:             windiv += '_'+residx;
        !           739:         }
        !           740:         if (document.getElementById(dispdiv)) {
        !           741:             if (document.getElementById(dispdiv).style.display == 'block') {
        !           742:                 if (extform.exttooltarget.length) {
        !           743:                     for (var i=0; i<extform.exttooltarget.length; i++) {
        !           744:                         if (extform.exttooltarget[i].checked) {
        !           745:                             if (extform.exttooltarget[i].value == 'window') {
        !           746:                                 var width = extform.exttoolwidth.value;
        !           747:                                 width.trim();
        !           748:                                 var height = extform.exttoolheight.value;
        !           749:                                 height.trim();
        !           750:                                 info += ':window:'+width+':'+height;
        !           751:                             } else if (extform.exttooltarget[i].value == 'tab') {
        !           752:                                 info += ':tab::';
        !           753:                             } else {
        !           754:                                 info += ':iframe::';
        !           755:                             }
        !           756:                         }
        !           757:                     }
        !           758:                 }
        !           759:             } else {
        !           760:                 info += ':::';
        !           761:             }
1.1       raeburn   762:         } else {
1.8.2.4.2.1! raeburn   763:             info += ':::';
        !           764:         }
        !           765:         if (document.getElementById(windiv)) {
        !           766:             if (document.getElementById(windiv).style.display == 'block') {
        !           767:                 var linktextdiv = prefix+'toollinktextdiv';
        !           768:                 var explanationdiv = prefix+'toolexplanationdiv';
        !           769:                 if (residx > 0) {
        !           770:                     linktextdiv += '_'+residx;
        !           771:                     explanationdiv += '_'+residx;
        !           772:                 }
        !           773:                 if (document.getElementById(linktextdiv).style.display == 'inline') {
        !           774:                     var linktext = extform.exttoollinktext.value;
        !           775:                     linktext.trim();
        !           776:                     info += ':'+escape(linktext);
        !           777:                 } else {
        !           778:                     info += ':';
        !           779:                 }
        !           780:                 if (document.getElementById(explanationdiv).style.display == 'inline') {
        !           781:                     var explaintext = extform.exttoolexplanation.value;
        !           782:                     explaintext.trim();
        !           783:                     info += ':'+escape(explaintext);
        !           784:                 } else {
        !           785:                     info += ':';
        !           786:                 }
        !           787:             } else {
        !           788:                 info += '::';
        !           789:             }
        !           790:         } else {
        !           791:             info += '::';
        !           792:         }
        !           793:         var labelinput = prefix+'toolcrslabel';
        !           794:         var titleinput = prefix+'toolcrstitle';
        !           795:         if (residx > 0) {
        !           796:             labelinput += '_'+residx;
        !           797:             titleinput += '_'+residx;
        !           798:         }
        !           799:         if (document.getElementById(labelinput)) {
        !           800:             var crslabel = document.getElementById(labelinput).value;
        !           801:             crslabel.trim();
        !           802:             info += ':'+escape(crslabel);
        !           803:         } else {
        !           804:             info += ':';
        !           805:         } 
        !           806:         if (document.getElementById(titleinput)) {
        !           807:             var crstitle = document.getElementById(titleinput).value;
        !           808:             crstitle.trim();
        !           809:             info += ':'+escape(crstitle);
        !           810:         } else {
        !           811:             info += ':';
        !           812:         }
        !           813:         info=escape(info);
        !           814:         if (residx > 0) {
        !           815:             eval("extform.importdetail.value=title+'='+info+'='+residx;extform.submit();");
        !           816:         } else {
        !           817:             eval("extform.importdetail.value=title+'='+info;extform.submit();");
1.1       raeburn   818:         }
                    819:     }
                    820: }
                    821: 
1.8.2.4.2.1! raeburn   822: function editext(residx,type) {
        !           823:     if (document.getElementById('upload'+type+residx)) {
        !           824:         var curr = document.getElementById('upload'+type+residx).style.display;
1.1       raeburn   825:         if (curr == 'none') {
                    826:             disp = 'block';
                    827:         } else {
                    828:             disp = 'none';
                    829:         }
1.8.2.4.2.1! raeburn   830:         document.getElementById('upload'+type+residx).style.display=disp;
1.1       raeburn   831:     }
                    832:     resize_scrollbox('contentscroll','1','1');
                    833:     return;
                    834: }
                    835: 
1.8.2.2   raeburn   836: function extUrlPreview(caller,protocol) {
1.1       raeburn   837:     if (document.getElementById(caller)) {
                    838:         var url = document.getElementById(caller).value;
                    839:         if (regexp.test(url)) {
1.8.2.2   raeburn   840:             var http_regex = /^http\:\/\//gi;
1.8.2.4   raeburn   841:             var mixed = 0;
                    842:             var noiframe = 0;
                    843:             var nopriv = 0;
                    844:             var badurl = 0;
                    845:             var name = "externalpreview";
1.8.2.2   raeburn   846:             if ((protocol == 'https') && (http_regex.test(url))) {
1.8.2.4   raeburn   847:                 mixed = 1;
1.8.2.2   raeburn   848:             }
1.8.2.4   raeburn   849:             var http = new XMLHttpRequest();
                    850:             var lcurl = "/adm/exturlcheck";
                    851:             var params = "exturl="+url;
                    852:             http.open("POST",lcurl, true);
                    853:             http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    854:             http.onreadystatechange = function() {
                    855:                 if (http.readyState == 4) {
                    856:                     if (http.status == 200) {
                    857:                         if (http.responseText.length > 0) {
                    858:                             if (http.responseText == 1) {
                    859:                                 noiframe = 1;
                    860:                             } else if (http.responseText == -1) {
                    861:                                 nopriv = 1;
                    862:                             } else if (http.responseText == 0) {
                    863:                                 badurl = 1;
                    864:                             }
                    865:                         }
                    866:                         openPreviewWindow(url,name,noiframe,mixed,nopriv,badurl);
                    867:                     }
                    868:                 }
                    869:             }
                    870:             http.send(params);
1.1       raeburn   871:         } else {
1.8       damieng   872:             alert("$js_lt{'invurl'}");
1.1       raeburn   873:         }
                    874:     }
                    875: }
                    876: 
1.8.2.4   raeburn   877: var previewLCWindow = null;
                    878: function openPreviewWindow(url,name,noiframe,mixed,nopriv,badurl) {
                    879:     if (previewLCWindow !=null) {
                    880:         previewLCWindow.close();
                    881:     }
                    882:     if (badurl) {
                    883:         alert("$js_lt{'badurl'}");
                    884:     } else if (nopriv) {
                    885:         alert("$js_lt{'nopriv'}");
                    886:     } else if ((noiframe == 1) || (mixed == 1)) {
                    887:         var encurl = encodeURI(url);
                    888:         var msg;
                    889:         if (mixed == 1) {
                    890:             if (noiframe == 1) {
                    891:                 msg = "$js_lt{'mixfra'}";
                    892:             } else {
                    893:                 msg = "$js_lt{'mixonly'}";
                    894:             }
                    895:         } else {
                    896:             msg = "$js_lt{'fraonly'}";
                    897:         }
                    898:         if (confirm(msg)) {
                    899:             previewLCWindow = window.open(url,name,"height=400,width=500,scrollbars=1,resizable=1,menubar=0,location=1");
                    900:             if (previewLCWindow != null) {
                    901:                 previewLCWindow.focus();
                    902:             } else {
                    903:                 alert("$js_lt{'nopopup'}");
                    904:             }
                    905:         }
                    906:     } else {
                    907:         openMyModal(url,500,400,'yes');
                    908:     }
                    909: }
                    910: 
1.8.2.4.2.1! raeburn   911: function updateExttool(caller,form,supplementalflag) {
        !           912:     var prefix = '';
        !           913:     if (supplementalflag == 1) {
        !           914:         prefix = 'supp';
        !           915:     }
        !           916:     dispdiv = prefix+'tooldispdiv';
        !           917:     dimendiv = prefix+'tooldimendiv';
        !           918:     widthinput = prefix+'tooldimenwidth';
        !           919:     heightinput = prefix+'tooldimenheight';
        !           920:     labeldiv = prefix+'toolcrslabeldiv';
        !           921:     titlediv = prefix+'toolcrstitlediv';
        !           922:     labelinput = prefix+'toolcrslabel';
        !           923:     titleinput = prefix+'toolcrstitle';
        !           924:     windiv = prefix+'toolwindiv';  
        !           925:     linktextdiv = prefix+'toollinktextdiv';
        !           926:     linktextinput = prefix+'toollinktext';
        !           927:     explanationdiv = prefix+'toolexplanationdiv';
        !           928:     explanationinput = prefix+'toolexplanation';
        !           929:     if (document.getElementById(dispdiv)) {
        !           930:         var toolpick = caller.options[caller.selectedIndex].value;
        !           931:         $toolsjs
        !           932:         if (toolpick == '') {
        !           933:             if (document.getElementById(dispdiv)) {
        !           934:                 document.getElementById(dispdiv).style.display = 'none';    
        !           935:             }
        !           936:             if (document.getElementById(dimendiv)) {
        !           937:                 document.getElementById(dimendiv).style.display = 'none';
        !           938:             }
        !           939:             if (document.getElementById(windiv)) {
        !           940:                 document.getElementById(windiv).style.display = 'none';
        !           941:             }
        !           942:             if (document.getElementById(linktextdiv)) {
        !           943:                 document.getElementById(linktextdiv).style.display = 'none';
        !           944:             }
        !           945:             if (document.getElementById(explanationdiv)) {
        !           946:                 document.getElementById(explanationdiv).style.display = 'none';
        !           947:             }
        !           948:             if (document.getElementById(labeldiv)) {
        !           949:                 document.getElementById(labeldiv).style.display = 'none';
        !           950:             }
        !           951:             if (document.getElementById(titlediv)) {
        !           952:                 document.getElementById(titlediv).style.display = 'none';
        !           953:             }
        !           954:         } else {
        !           955:             if (ltitools.length > 0) {
        !           956:                 for (var j=0; j<ltitools.length; j++) {
        !           957:                     if (ltitools[j] == toolpick) {
        !           958:                         if (document.getElementById(dispdiv)) {
        !           959:                             if (ltitoolsDisplay[j]) {
        !           960:                                 document.getElementById(dispdiv).style.display = 'block';
        !           961:                                 if (form.exttooltarget.length) {
        !           962:                                     for (var k=0; k<form.exttooltarget.length; k++) {
        !           963:                                         if (form.exttooltarget[k].value == ltitoolsTarget[j]) {
        !           964:                                             form.exttooltarget[k].checked = true;
        !           965:                                             break;
        !           966:                                         }
        !           967:                                     }
        !           968:                                 }
        !           969:                             }
        !           970:                             var dimen = 'none';
        !           971:                             var dimenwidth = '';
        !           972:                             var dimenheight = '';
        !           973:                             if ((ltitoolsDisplay[j]) && (ltitoolsTarget[j] == 'window')) {
        !           974:                                 dimen = 'block';
        !           975:                                 dimenwidth = ltitoolsWidth[j];
        !           976:                                 dimenheight = ltitoolsHeight[j];                    
        !           977:                             }
        !           978:                             if (document.getElementById(dimendiv)) {
        !           979:                                 document.getElementById(dimendiv).style.display = dimen;
        !           980:                             }
        !           981:                             if (document.getElementById(widthinput)) {
        !           982:                                 document.getElementById(widthinput).value = dimenwidth;
        !           983:                             }
        !           984:                             if (document.getElementById(heightinput)) {
        !           985:                                 document.getElementById(heightinput).value = dimenheight;
        !           986:                             }
        !           987:                         }
        !           988:                         if (document.getElementById(windiv)) {
        !           989:                             if ((ltitoolsTarget[j] == 'window') || (ltitoolsTarget[j] == 'tab')) {
        !           990:                                 document.getElementById(windiv).style.display = 'block';
        !           991:                             } else {
        !           992:                                 document.getElementById(windiv).style.display = 'none';
        !           993:                             }
        !           994:                             if (document.getElementById(linktextdiv)) {
        !           995:                                 if (ltitoolsLink[j]) {
        !           996:                                     document.getElementById(linktextdiv).style.display = 'inline';
        !           997:                                 } else {
        !           998:                                     document.getElementById(linktextdiv).style.display = 'none';
        !           999:                                 }
        !          1000:                             }
        !          1001:                             if (document.getElementById(linktextinput)) {
        !          1002:                                 if (ltitoolsLink[j]) {
        !          1003:                                     document.getElementById(linktextinput).value = ltitoolsLinkDef[j]; 
        !          1004:                                 } else {
        !          1005:                                     document.getElementById(linktextinput).value = '';
        !          1006:                                 }
        !          1007:                             }
        !          1008:                             if (document.getElementById(explanationdiv)) {
        !          1009:                                 if (ltitoolsExplain[j]) {
        !          1010:                                     document.getElementById(explanationdiv).style.display = 'inline';
        !          1011:                                 } else {
        !          1012:                                     document.getElementById(explanationdiv).style.display = 'none';
        !          1013:                                 }
        !          1014:                             }
        !          1015:                             if (document.getElementById(explanationinput)) {
        !          1016:                                 if (ltitoolsExplain[j]) {
        !          1017:                                     document.getElementById(explanationinput).value = ltitoolsExplainDef[j];
        !          1018:                                 } else {
        !          1019:                                     document.getElementById(explananationinput).value = '';
        !          1020:                                 }
        !          1021:                             }
        !          1022:                         }
        !          1023:                         if (document.getElementById(labeldiv)) {
        !          1024:                             if (ltitoolsLabel[j]) {
        !          1025:                                 document.getElementById(labeldiv).style.display = 'inline';
        !          1026:                             } else {
        !          1027:                                 document.getElementById(labeldiv).style.display = 'none';
        !          1028:                             } 
        !          1029:                         }
        !          1030:                         if (document.getElementById(titlediv)) {
        !          1031:                             if (ltitoolsTitle[j]) {
        !          1032:                                 document.getElementById(titlediv).style.display = 'inline';
        !          1033:                             } else {
        !          1034:                                 document.getElementById(titlediv).style.display = 'none';
        !          1035:                             }
        !          1036:                         }
        !          1037:                         break;
        !          1038:                     }
        !          1039:                 }
        !          1040:             }
        !          1041:         }
        !          1042:     }
        !          1043: }
        !          1044: 
        !          1045: function updateTooldim(form,dimendiv,windiv,widthinput,heightinput,linkinput,explaininput) {
        !          1046:     if (form.exttooltarget.length) {
        !          1047:         for (var i=0; i<form.exttooltarget.length; i++) {
        !          1048:             if (form.exttooltarget[i].checked) {
        !          1049:                 var dimen = 'none';
        !          1050:                 var linkconf = 'none';
        !          1051:                 if (form.exttooltarget[i].value == 'window') {
        !          1052:                     dimen = 'block';
        !          1053:                     linkconf = 'block';
        !          1054:                 } else {
        !          1055:                     if (form.exttooltarget[i].value == 'tab') {
        !          1056:                         linkconf = 'block';
        !          1057:                     } else {
        !          1058:                         if (document.getElementById(widthinput)) {
        !          1059:                             document.getElementById(widthinput).value = '';
        !          1060:                         }
        !          1061:                         if (document.getElementById(heightinput)) {
        !          1062:                             document.getElementById(heightinput).value = '';
        !          1063:                         }
        !          1064:                         if (document.getElementById(linkinput)) {
        !          1065:                             document.getElementById(linkinput).value = '';
        !          1066:                         }
        !          1067:                         if (document.getElementById(explaininput)) {
        !          1068:                             document.getElementById(explaininput).value = '';
        !          1069:                         }
        !          1070:                     }
        !          1071:                 }
        !          1072:                 if (document.getElementById(dimendiv)) {
        !          1073:                     document.getElementById(dimendiv).style.display = dimen;
        !          1074:                 }
        !          1075:                 if (document.getElementById(windiv)) {
        !          1076:                     document.getElementById(windiv).style.display = linkconf;
        !          1077:                 }
        !          1078:                 break;
        !          1079:             }
        !          1080:         }
        !          1081:     }
        !          1082: }
        !          1083: 
1.1       raeburn  1084: ENDJS
                   1085: 
                   1086: }
                   1087: 
                   1088: 1;

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