File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.25: download - view: text, annotated - select for diffs
Tue May 21 18:18:07 2002 UTC (21 years, 11 months ago) by www
Branches: MAIN
CVS tags: HEAD
Kinda usable now

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

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