File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.31.2.1: download - view: text, annotated - select for diffs
Fri Aug 30 22:28:05 2002 UTC (21 years, 8 months ago) by albertel
Branches: version_0_5_1
Diff to branchpoint 1.31: preferred, unified
- backport o single resource fix from 1.33

    1: # The LearningOnline Network with CAPA
    2: # Edit Handler for RAT Maps
    3: #
    4: # $Id: lonratedt.pm,v 1.31.2.1 2002/08/30 22:28:05 albertel 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: # (TeX Content Handler
   29: #
   30: # 05/29/00,05/30 Gerd Kortemeyer)
   31: # 7/1,6/30 Gerd Kortemeyer
   32: 
   33: package Apache::lonratedt;
   34: 
   35: use strict;
   36: use Apache::Constants qw(:common);
   37: use Apache::lonnet;
   38: use Apache::lonratsrv;
   39: use Apache::lonsequence;
   40: 
   41: use vars qw(@order @resources);
   42: 
   43: 
   44: # Mapread read maps into global arrays @links and @resources, determines status
   45: # sets @order - pointer to resources in right order
   46: # sets @resources - array with the resources with correct idx
   47: #
   48: sub mapread {
   49:     my $fn=shift;
   50: 
   51:     my @links;
   52:     undef @links;
   53:     undef @resources;
   54:     undef @order;
   55:     @resources=('');
   56:     @order=();
   57: 
   58:     my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
   59:     if ($errtext) { return ($errtext,2); }
   60: 
   61: # -------------------------------------------------------------------- Read map
   62:     foreach (split(/\<\&\>/,$outtext)) {
   63: 	my ($command,$number,$content)=split(/\<\:\>/,$_);
   64:         if ($command eq 'objcont') {
   65: 	    $resources[$number]=$content;
   66:         }
   67:         if ($command eq 'objlinks') {
   68:             $links[$number]=$content;
   69:         }
   70:         if ($command eq 'objparms') {
   71: 	    return('Map has resource parameters. Use advanced editor.',1);
   72:         }
   73:     }
   74: # ------------------------------------------------------- Is this a linear map?
   75:     my @starters=();
   76:     my @endings=();
   77:     undef @starters;
   78:     undef @endings;
   79: 
   80:     foreach (@links) {
   81:         if (defined($_)) {
   82: 	    my ($start,$end,$cond)=split(/\:/,$_);
   83:             if ((defined($starters[$start])) || (defined($endings[$end]))) { 
   84: 		return
   85:                  ('Map has branchings. Use advanced editor.',1);
   86:             }
   87: 	    $starters[$start]=1;
   88: 	    $endings[$end]=1;
   89: 	    if ($cond) {
   90: 		return
   91:                  ('Map has conditions. Use advanced editor.',1);
   92:             }
   93: 	}
   94: 
   95:     }
   96:     for (my $i=1; $i<=$#resources; $i++) {
   97:         if (defined($resources[$i])) {
   98: 	    unless (($starters[$i]) || ($endings[$i])) {
   99:                 return
  100: 		 ('Map has unconnected resources. Use advanced editor.',1);
  101:             }
  102:         }
  103:     }
  104: 
  105: # -------------------------------------------------- This is a linear map, sort
  106: 
  107:     my $startidx=0;
  108:     my $endidx=0;
  109:     for (my $i=0; $i<=$#resources; $i++) {
  110:         if (defined($resources[$i])) {
  111:             my ($title,$url,$ext,$type)=split(/\:/,$resources[$i]);
  112: 	    if ($type eq 'start') { $startidx=$i; }
  113:             if ($type eq 'finish') { $endidx=$i; }
  114:         }
  115:     }
  116:     my $k=0;
  117:     my $currentidx=$startidx;
  118:     $order[$k]=$currentidx;
  119:     for (my $i=0; $i<=$#resources; $i++) {
  120:         foreach (@links) {
  121: 	    my ($start,$end)=split(/\:/,$_);
  122:             if ($start==$currentidx) {
  123: 		$currentidx=$end;
  124:                 $k++;
  125:                 $order[$k]=$currentidx;
  126:                 last;
  127:             }
  128:         }
  129:         if ($currentidx==$endidx) { last; }
  130:     }
  131:     return $errtext;
  132: }
  133: 
  134: # ---------------------------------------------- Read a map as well as possible
  135: # Also used by the sequence handler
  136: # Call lonsequence::attemptread to read from resource space
  137: #
  138: sub attemptread {
  139:     my $fn=shift;
  140: 
  141:     my @links;
  142:     undef @links;
  143:     my @theseres;
  144:     undef @theseres;
  145: 
  146:     my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
  147:     if ($errtext) { return @theseres }
  148: 
  149: # -------------------------------------------------------------------- Read map
  150:     foreach (split(/\<\&\>/,$outtext)) {
  151: 	my ($command,$number,$content)=split(/\<\:\>/,$_);
  152:         if ($command eq 'objcont') {
  153: 	    $theseres[$number]=$content;
  154:         }
  155:         if ($command eq 'objlinks') {
  156:             $links[$number]=$content;
  157:         }
  158:     }
  159: 
  160: # --------------------------------------------------------------- Sort, sort of
  161: 
  162:     my @objsort=();
  163:     undef @objsort;
  164: 
  165:     my @data1=();
  166:     my @data2=();
  167:     undef @data1;
  168:     undef @data2;
  169: 
  170:     my $k;
  171:     my $kj;
  172:     my $j;
  173:     my $ij;
  174: 
  175:    for ($k=1;$k<=$#theseres;$k++) {
  176:       if (defined($theseres[$k])) {
  177:          $objsort[$#objsort+1]=$k;
  178:       }
  179:    }
  180: 
  181:    for ($k=1;$k<=$#links;$k++) {
  182:      if (defined($links[$k])) {
  183:       @data1=split(/\:/,$links[$k]);
  184:       $kj=-1;
  185:       for (my $j=0;$j<=$#objsort;$j++) {
  186:          if ((split(/\:/,$objsort[$j]))[0]==$data1[0]) {
  187:             $kj=$j;
  188:          }
  189:       }
  190:       if ($kj!=-1) { $objsort[$kj].=':'.$data1[1]; }
  191:      }
  192:    }
  193:     for ($k=0;$k<=$#objsort;$k++) {
  194:       for ($j=0;$j<=$#objsort;$j++) {
  195:         if ($k!=$j) {
  196:           @data1=split(/\:/,$objsort[$k]);
  197:           @data2=split(/\:/,$objsort[$j]);
  198:           my $dol=$#data1+1;
  199:           my $dtl=$#data2+1;
  200:           if ($dol+$dtl<1000) {
  201:            for ($kj=1;$kj<$dol;$kj++) {
  202:              if ($data1[$kj]==$data2[0]) {
  203:                 for ($ij=1;$ij<$dtl;$ij++) {
  204:                    $data1[$#data1+1]=$data2[$ij];
  205:                 }
  206:              }
  207:            }
  208:            for ($kj=1;$kj<$dtl;$kj++) {
  209:              if ($data2[$kj]==$data1[0]) {
  210:                  for ($ij=1;$ij<$dol;$ij++) {
  211:                     $data2[$#data2+1]=$data1[$ij];
  212:                  }
  213:              }
  214:            }
  215:            $objsort[$k]=join(':',@data1);
  216:            $objsort[$j]=join(':',@data2);
  217:           }
  218:          }
  219:       } 
  220:   }
  221: # ---------------------------------------------------------------- Now sort out
  222: 
  223:     @objsort=sort {
  224:       my @data1=split(/\:/,$a);
  225:       my @data2=split(/\:/,$b);
  226:       my $rvalue=0;
  227:       my $k;
  228:       for ($k=1;$k<=$#data1;$k++) {
  229:          if ($data1[$k]==$data2[0]) { $rvalue--; }
  230:       }
  231:       for ($k=1;$k<=$#data2;$k++) {
  232:          if ($data2[$k]==$data1[0]) { $rvalue++; }
  233:       }
  234:       if ($rvalue==0) { $rvalue=$#data2-$#data1; }
  235:       $rvalue;
  236:     } @objsort;
  237: 
  238:     my @outres=();
  239:     undef @outres;
  240: 
  241:     for ($k=0;$k<=$#objsort;$k++) {
  242: 	$outres[$k]=$theseres[(split(/\:/,$objsort[$k]))[0]];
  243:     }
  244:     return @outres;
  245: }
  246: 
  247: # --------------------------------------------------------- Build up RAT screen
  248: sub ratedt {
  249:   my ($r,$url)=@_;
  250:   $r->print(<<ENDDOCUMENT);
  251: 
  252: <html>
  253: <head>
  254: <script language="JavaScript">
  255:     var flag=0;
  256: </script>
  257: </head>
  258: <frameset rows="1,50,*" border=0>
  259: <frame name=server src="$url/loadonly/ratserver" noresize noscroll>
  260: <frame name=code src="/adm/rat/code.html">
  261: <frame name=mapout src="/adm/rat/map.html">
  262: </frameset>
  263: </html>
  264: 
  265: ENDDOCUMENT
  266: }
  267: 
  268: # ---------------------------------------------------------------- Make buttons
  269: 
  270: sub buttons {
  271:     my $adv=shift;
  272:     my $output='<form method=post>';     
  273:     if ($adv==1) {
  274: 	$output.='<input type=submit name=forceadv value="Edit">';
  275:     } else {
  276:         unless ($adv==2) {
  277:            $output.='<input type=submit name=forcesmp value="Simple Edit">';
  278:         }
  279: 	$output.='<input type=submit name=forceadv value="Advanced Edit">';
  280:     }
  281:     return $output.'</form><hr>';
  282: }
  283: 
  284: # ----------------------------------------------------------- Paste into target
  285: # modifies @order, @resources
  286: 
  287: sub pastetarget {
  288:     my ($after,@which)=@_;
  289:     my @insertorder=();
  290:     foreach (@which) {
  291:         if (defined($_)) {
  292: 	    my ($name,$url)=split(/\=/,$_);
  293:             $name=&Apache::lonnet::unescape($name);
  294:             $url=&Apache::lonnet::unescape($url);
  295:             if ($url) {
  296: 	       my $idx=$#resources+1;
  297:                $insertorder[$#insertorder+1]=$idx;
  298:                my $ext='false';
  299:                if ($url=~/^http\:\/\//) { $ext='true'; }
  300:                $url=~s/\:/\&colon;/g;
  301:                $resources[$idx]=$name.':'.$url.':'.$ext.':normal:res';
  302: 	   }
  303:         }
  304:     }
  305:     my @oldorder=splice(@order,$after);
  306:     @order=(@order,@insertorder,@oldorder);
  307: }
  308: 
  309: # ------------------------------------------------ Get start and finish correct
  310: # modifies @resources
  311: 
  312: sub startfinish {
  313:     foreach (@order) {
  314: 	my ($name,$url,$ext)=split(/\:/,$resources[$_]);
  315:         if ($url=~/http\&colon\:\/\//) { $ext='true'; }
  316:         $resources[$_]=$name.':'.$url.':'.$ext.':normal:res';
  317:     }
  318:    my ($name,$url,$ext)=split(/\:/,$resources[$order[0]]);
  319:    $resources[$order[0]]=$name.':'.$url.':'.$ext.':start:res';
  320:    if ($#order==0) {
  321:        $resources[$#resources+1]='::false';
  322:        $order[1]=$#resources;
  323:    }
  324:    my ($name,$url,$ext)=split(/\:/,$resources[$order[$#order]]);
  325:    $resources[$order[$#order]]=$name.':'.$url.':'.$ext.':finish:res';
  326: }
  327: 
  328: # ------------------------------------------------------------------- Store map
  329: 
  330: sub storemap {
  331:     my $fn=shift;
  332:     &startfinish();
  333:     my $output='graphdef<:>no';
  334:     my $k=1;
  335:     for (my $i=0; $i<=$#order; $i++) {
  336:         if (defined($resources[$order[$i]])) {
  337: 	    $output.='<&>objcont<:>'.$order[$i].'<:>'.$resources[$order[$i]];
  338:         }
  339:         if (defined($order[$i+1])) {
  340: 	    if (defined($resources[$order[$i+1]])) {
  341:                $output.='<&>objlinks<:>'.$k.'<:>'.
  342: 		   $order[$i].':'.$order[$i+1].':0';
  343: 	       $k++;
  344:             }
  345:         }
  346:     }
  347:     $output=~s/http\&colon\;\/\///g;
  348:     $ENV{'form.output'}=$output;
  349:     return 
  350:      &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));
  351: }
  352: 
  353: # ------------------------------------------------------- Simple edit processor
  354: 
  355: sub smpedt {
  356:    my ($r,$url,$errtext)=@_;
  357:    my $buttons=&buttons(2);
  358: 
  359: # ---------------------------------------------------------- Process form input
  360: 
  361:    my @importselect=();
  362:    my @targetselect=();
  363:    undef @importselect;
  364:    undef @targetselect;
  365:    if (defined($ENV{'form.importsel'})) {
  366:        if (ref($ENV{'form.importsel'})) {
  367: 	   @importselect=sort(@{$ENV{'form.importsel'}});
  368:        } else {
  369:            @importselect=($ENV{'form.importsel'});
  370:        }
  371:    }
  372:    if (defined($ENV{'form.target'})) {
  373:        if (ref($ENV{'form.target'})) {
  374: 	   @targetselect=sort(@{$ENV{'form.target'}});
  375:        } else {
  376:            @targetselect=($ENV{'form.target'});
  377:        }
  378:    }
  379: # ============================================================ Process commands
  380: 
  381:    my $targetdetail=$ENV{'form.targetdetail'};
  382:    my $importdetail=$ENV{'form.curimpdetail'};
  383: 
  384: # ---------------------------------------------------- Importing from groupsort
  385:    if (($ENV{'form.importdetail'}) && (!$ENV{'form.impfortarget'})) {
  386: 
  387:        $importdetail='';
  388:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
  389: 
  390:        my $lastsel;
  391: 
  392:        if (defined($importselect[-1])) {
  393: 	   $lastsel=$importselect[-1];
  394:        } else {
  395:            $lastsel=$#curimport;
  396:        }
  397: 
  398:        for (my $i=0;$i<=$lastsel;$i++) {
  399:            my ($name,$url)=split(/\=/,$curimport[$i]);
  400:            if ($url) {
  401:               $importdetail.='&'.$name.'='.$url;
  402: 	   }
  403:        }
  404: 
  405:       $importdetail.='&'.$ENV{'form.importdetail'};
  406: 
  407:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
  408:            my ($name,$url)=split(/\=/,$curimport[$i]);
  409:            if ($url) {
  410:               $importdetail.='&'.$name.'='.$url;
  411: 	  }
  412:        }
  413:        $importdetail=~s/\&+/\&/g;
  414:        $importdetail=~s/^\&//;
  415: 
  416: # ------------------------------------------------------------------- Clear all
  417:    } elsif ($ENV{'form.clear'}) {
  418:        $importdetail='';
  419: # ------------------------------------------------------------ Discard selected
  420:    } elsif ($ENV{'form.discard'}) {
  421:        $importdetail='';
  422:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
  423:        foreach (@importselect) {
  424: 	   $curimport[$_]='';
  425:        }
  426:        for (my $i=0;$i<=$#curimport;$i++) {
  427:            my ($name,$url)=split(/\=/,$curimport[$i]);
  428:            if ($url) {
  429:               $importdetail.='&'.$name.'='.$url;
  430: 	   }
  431:        }
  432: # --------------------------------------------------------- Loading another map
  433:    } elsif ($ENV{'form.loadmap'}) {
  434:        $importdetail='';
  435:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
  436: 
  437:        my $lastsel;
  438: 
  439:        if (defined($importselect[-1])) {
  440: 	   $lastsel=$importselect[-1];
  441:        } else {
  442:            $lastsel=$#curimport;
  443:        }
  444: 
  445:        for (my $i=0;$i<=$lastsel;$i++) {
  446:            my ($name,$url)=split(/\=/,$curimport[$i]);
  447:            if ($url) {
  448:               $importdetail.='&'.$name.'='.$url;
  449: 	   }
  450:        }
  451: 
  452:        foreach (
  453:     &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
  454: 	   my ($name,$url)=split(/\:/,$_);
  455:            if ($url) {
  456:               $importdetail.='&'.&Apache::lonnet::escape($name).'='.
  457: 		 	         &Apache::lonnet::escape($url);
  458: 	  }
  459:        }
  460: 
  461:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
  462:            my ($name,$url)=split(/\=/,$curimport[$i]);
  463:            if ($url) {
  464:               $importdetail.='&'.$name.'='.$url;
  465: 	  }
  466:        }
  467:        $importdetail=~s/\&+/\&/g;
  468:        $importdetail=~s/^\&//;
  469: 
  470: # ------------------------------------------------ Groupimport/search to target
  471:    } elsif ($ENV{'form.importdetail'}) {
  472:        my $lastsel;
  473:        if (defined($targetselect[-1])) {
  474: 	   $lastsel=$targetselect[-1];
  475:        } else {
  476:            $lastsel=$#order+1;
  477:        }
  478:        &pastetarget($lastsel,split(/\&/,$ENV{'form.importdetail'}));
  479:        &storemap(&Apache::lonnet::filelocation('',$url));
  480: # ------------------------------------------------------------------------- Cut
  481:    } elsif (($ENV{'form.cut'}) || ($ENV{'form.copy'})) {
  482:        $importdetail='';
  483:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
  484: 
  485:        my $lastsel;
  486: 
  487:        if (defined($importselect[-1])) {
  488: 	   $lastsel=$importselect[-1];
  489:        } else {
  490:            $lastsel=$#curimport;
  491:        }
  492: 
  493:        for (my $i=0;$i<=$lastsel;$i++) {
  494:            my ($name,$url)=split(/\=/,$curimport[$i]);
  495:            if ($url) {
  496:               $importdetail.='&'.$name.'='.$url;
  497: 	   }
  498:        }
  499: 
  500:        foreach (@targetselect) {
  501: 	   my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
  502:            if ($url) {
  503:               $importdetail.='&'.&Apache::lonnet::escape($name).'='.
  504: 		 	         &Apache::lonnet::escape($url);
  505: 	  }
  506:        }
  507: 
  508:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
  509:            my ($name,$url)=split(/\=/,$curimport[$i]);
  510:            if ($url) {
  511:               $importdetail.='&'.$name.'='.$url;
  512: 	  }
  513:        }
  514:        $importdetail=~s/\&+/\&/g;
  515:        $importdetail=~s/^\&//;
  516: 
  517:        if ($ENV{'form.cut'}) {
  518:            my @neworder=();
  519:            for (my $i=0;$i<=$#order;$i++) {
  520:                my $include=1;
  521:                foreach (@targetselect) {
  522: 		   if ($_-1==$i) { $include=0; }
  523:                }
  524:                if ($include) { $neworder[$#neworder+1]=$order[$i]; }
  525:            }
  526:            @order=@neworder;
  527:            &storemap(&Apache::lonnet::filelocation('',$url));      
  528:        }
  529: 
  530: # ----------------------------------------------------------------------- Paste
  531:    } elsif ($ENV{'form.paste'}) {
  532:        my $lastsel;
  533:        if (defined($targetselect[-1])) {
  534: 	   $lastsel=$targetselect[-1];
  535:        } else {
  536:            $lastsel=$#order+1;
  537:        }
  538:        my @newsequence;
  539:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
  540:        foreach (@importselect) {
  541:           $newsequence[$#newsequence+1]=$curimport[$_];
  542:        }
  543:        &pastetarget($lastsel,@newsequence);
  544:        &storemap(&Apache::lonnet::filelocation('',$url));
  545: # ------------------------------------------------ 
  546:    }
  547: # ------------------------------------------------------------ Assemble windows
  548:    
  549:    my $idx=-1;
  550:    my $importwindow=
  551:        '<option value="-1"> ---- Import and Paste Area ---- </option>'.
  552:      join("\n",map {
  553:        $idx++;
  554:        if ($_) { 
  555:           my ($name,$url)=split(/\=/,$_);
  556:           unless ($name) { $name=(split(/\//,$url))[-1]; }
  557:           unless ($name) { $name='EMPTY'; }
  558:           '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
  559:                                     '</option>';
  560:       }
  561:    } split(/\&/,$importdetail));
  562: 
  563:    $idx=0;
  564:    my $targetwindow=       
  565:        '<option value="0"> ------- Target Edit Map ------- </option>'.
  566:      join("\n",map { 
  567:        my ($name,$url)=split(/\:/,$resources[$_]);
  568:        unless ($name) {  $name=(split(/\//,$url))[-1]; }
  569:        unless ($name) { $name='EMPTY'; }
  570:        $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
  571: 	                  &Apache::lonnet::escape($url);
  572:        $idx++;
  573:        '<option value="'.$idx.'">'.$name.'</option>';
  574:    } @order);
  575: 
  576: # ----------------------------------------------------- Start simple RAT screen
  577:    $r->print(<<ENDSMPHEAD);
  578: <html>
  579: <head>
  580: <script>
  581: var srch;
  582: var srchflag=-1; // 1 means currently open
  583:                  // 0 means closed (but has been open)
  584:                  // -1 means never yet opened/defined
  585: var srchmode='';
  586: 
  587: var idx;
  588: var idxflag=-1; // 1 means currently open
  589:                  // 0 means closed (but has been open)
  590:                  // -1 means never yet opened/defined
  591: var idxmode='';
  592: 
  593: // ------------------------------------------------------ Clears indexer window
  594: function idxclear() {
  595:   idx.document.clear();
  596: }
  597: 
  598: // ------------------------------------------------------- Clears search window
  599: function srchclear() {
  600:   srch.document.clear();
  601: }
  602: 
  603: // ------------------------------------------------------ Closes indexer window
  604: function idxclose() {
  605:   if (idx && !idx.closed) {
  606:     idxflag=0;
  607:     idx.close();
  608:   }
  609: }
  610: 
  611: // ------------------------------------------------------- Closes search window
  612: function srchclose() {
  613:   if (srch && !srch.closed) {
  614:     srchflag=0;
  615:     srch.close();
  616:   }
  617: }
  618: 
  619: // -------------------------------------------------------- Open indexer window
  620: function idxopen(mode) {
  621:    var options="scrollbars=1,resizable=1,menubar=0";
  622:    idxmode=mode;
  623:    idxflag=1;
  624:    idx=open("/res/?launch=1&mode=simple&catalogmode="+mode,"idxout",options);
  625:    idx.focus();
  626: }
  627: 
  628: // --------------------------------------------------------- Open search window
  629: function srchopen(mode) {
  630:    var options="scrollbars=1,resizable=1,menubar=0";
  631:    srchmode=mode;
  632:    srchflag=1;
  633:    srch=open("/adm/searchcat?launch=1&mode=simple&catalogmode="+mode,"srchout",options);
  634:    srch.focus();
  635: }
  636: // ----------------------------------------------------- launch indexer browser
  637: function groupsearch() {
  638:    srchcheck('groupsearch');
  639: }
  640: 
  641: function groupimport() {
  642:    idxcheck('groupimport');
  643: }
  644: // ------------------------------------------------------- Do srch status check
  645: function srchcheck(mode) {
  646:    if (!srch || srch.closed || srchmode!=mode) {
  647:       srchopen(mode);
  648:    }
  649:    srch.focus();
  650: }
  651: 
  652: // -------------------------------------------------------- Do idx status check
  653: function idxcheck(mode) {
  654:    if (!idx || idx.closed || idxmode!=mode) {
  655:       idxopen(mode);
  656:    }
  657:    idx.focus();
  658: }
  659: 
  660: 
  661:     var editbrowser;
  662:     function openbrowser(formname,elementname,only,omit) {
  663:         var url = '/res/?';
  664:         if (editbrowser == null) {
  665:             url += 'launch=1&';
  666:         }
  667:         url += 'catalogmode=interactive&';
  668:         url += 'mode=edit&';
  669:         url += 'form=' + formname + '&';
  670:         if (only != null) {
  671:             url += 'only=' + only + '&';
  672:         } 
  673:         if (omit != null) {
  674:             url += 'omit=' + omit + '&';
  675:         }
  676:         url += 'element=' + elementname + '';
  677:         var title = 'Browser';
  678:         var options = 'scrollbars=1,resizable=1,menubar=0';
  679:         options += ',width=700,height=600';
  680:         editbrowser = open(url,title,options,'1');
  681:         editbrowser.focus();
  682:     }
  683: 
  684:    function openview(entry) {
  685:        var url=unescape((entry.split('='))[1]);
  686:        var parts=new Array;
  687:        parts=url.split('&colon;');
  688:        url=parts.join(':');
  689:        if (url) { open(url,'cat'); }
  690:    }
  691: 
  692:    function viewtarget() {
  693:        openview((document.forms.simpleedit.targetdetail.value.split('&'))
  694:                 [document.forms.simpleedit.target.selectedIndex+1]);
  695:    }
  696: 
  697:    function viewimport() {
  698:        openview((document.forms.simpleedit.curimpdetail.value.split('&'))
  699:                 [document.forms.simpleedit.importsel.selectedIndex+1]);
  700:    }
  701: 
  702: </script>
  703: </head>                 
  704: <body bgcolor='#FFFFFF'>
  705: $buttons
  706: <font color=red>$errtext</font>
  707: <h1>$url</h1>
  708: <form name=simpleedit method=post>
  709: <input type=hidden name=forcesmp value=1>
  710: <table>
  711:     <tr><th width="40%">Import</th>
  712: <th>&nbsp;</th>
  713: <th width="40%">Target</th></tr>
  714: <tr><td bgcolor="#FFFFCC">
  715: <input type=button onClick="javascript:groupsearch()" value="Group Search">
  716: <input type=button onClick="javascript:groupimport();" value="Group Import">
  717: after selected
  718: <hr>
  719: <input type=text size=20 name=importmap>
  720: <input type=button 
  721: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
  722: value="Browse"><input type=submit name=loadmap value="Load Map"><hr>
  723: <input type=submit name="discard" value="Discard Selected">
  724: <input type=submit name="clear" value="Clear All">
  725: <input type=button onClick="javascript:viewimport()" value="View">
  726: 
  727:     </td><td>&nbsp;</td><td bgcolor="#FFFFCC">
  728: 
  729: <input type=button onClick=
  730: "javascript:impfortarget.value=1;groupsearch()" value="Group Search">
  731: <input type=button onClick=
  732: "javascript:impfortarget.value=1;groupimport();" value="Group Import">
  733: after selected
  734: <hr><input type=button onClick="javascript:viewtarget()" value="View">
  735: </td></tr>
  736: 
  737: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
  738: $importwindow
  739: </select>
  740: </td>
  741: <td bgcolor="#FFFFAA" align="center">
  742: Cut selected<br>
  743: <input type=submit name=cut value='<<<'><p>
  744: <hr>
  745: Copy selected<br>
  746: <input type=submit name=copy value='<--'><p>
  747: <hr>
  748: Paste after selected<br>
  749: <input type=submit name=paste value='-->'>
  750: </td>
  751: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
  752: $targetwindow
  753: </select>
  754: </table>
  755: <input type=hidden name=importdetail value="">
  756: <input type=hidden name=curimpdetail value="$importdetail">
  757: <input type=hidden name=targetdetail value="$targetdetail">
  758: <input type=hidden name=impfortarget value="0">
  759: </form>
  760: </body></html>
  761: ENDSMPHEAD
  762: }
  763: 
  764: # ----------------------------------------------------------------- No such dir
  765: sub nodir {
  766:    my ($r,$dir)=@_;
  767:    $dir=~s/^\/home\/\w+\/public\_html//;
  768:    $r->print(<<ENDNODIR);
  769: <html>
  770: <body bgcolor='#FFFFFF'>
  771: <h1>No such directory: $dir</h1>
  772: </body>
  773: </html>
  774: ENDNODIR
  775: }
  776: 
  777: # ---------------------------------------------------------------- View Handler
  778: 
  779: sub viewmap {
  780:     my ($r,$url,$adv,$errtext)=@_;
  781:     $r->print('<html><body bgcolor="#FFFFFF">'.&buttons($adv));
  782:     if ($errtext) {
  783: 	$r->print($errtext.'<hr>');
  784:     }
  785:     my $idx=0;
  786:     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
  787: 	if (defined($_)) {
  788:             $idx++;
  789: 	    my ($title,$url)=split(/\:/,$_);
  790:             $title=~s/\&colon\;/\:/g;
  791:             $url=~s/\&colon\;/\:/g;
  792:             unless ($title) { $title=(split(/\//,$url))[-1] };
  793:             unless ($title) { $title='<i>Empty</i>'; }
  794:             if ($url) {
  795: 		$r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
  796:             }
  797:             $r->print(&Apache::lonratsrv::qtescape($title));
  798:             if ($url) { $r->print('</a>'); }
  799: 	    $r->print('<br>');
  800:         }
  801:     }
  802:     $r->print('</body></html>');
  803: }
  804: 
  805: # ================================================================ Main Handler
  806: 
  807: sub handler {
  808:   my $r=shift;
  809:   $r->content_type('text/html');
  810:   $r->send_http_header;
  811: 
  812:   return OK if $r->header_only;
  813: 
  814:   my $url=$r->uri;
  815:   my $fn=&Apache::lonnet::filelocation('',$url);
  816: 
  817:   my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
  818:   unless (-e $dir) {
  819:       &nodir($r,$dir);
  820:       return OK;
  821:   }
  822: 
  823: # ------------------------------------------- Determine which tools can be used
  824:   my $adv=0;
  825: 
  826:   unless ($ENV{'form.forcesmp'}) {
  827:      if ($ENV{'form.forceadv'}) {
  828:         $adv=1;
  829:      } elsif (my $fh=Apache::File->new($fn)) {
  830: 	 my $allmap=join('',<$fh>);
  831:          $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
  832:      }
  833:   }
  834: 
  835:   my $errtext='';
  836:   my $fatal=0;
  837: 
  838: # -------------------------------------------------------------------- Load map
  839:   ($errtext,$fatal)=&mapread($fn,$errtext);
  840: 
  841:   if ($fatal==1) { $adv=1; }
  842: 
  843: # ----------------------------------- adv==1 now means "graphical MUST be used"
  844: 
  845:   if ($ENV{'form.forceadv'}) {
  846:       &ratedt($r,$url);
  847:   } elsif ($ENV{'form.forcesmp'}) {
  848:       &smpedt($r,$url,$errtext);
  849:   } else {
  850:       &viewmap($r,$url,$adv,$errtext);
  851:   }
  852:   return OK;
  853: }
  854: 
  855: 1;
  856: __END__
  857: 
  858: 
  859: 
  860: 
  861: 
  862: 
  863: 

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