File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.33: download - view: text, annotated - select for diffs
Mon Aug 26 12:38:40 2002 UTC (21 years, 8 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #637
Will insert finish resource if map only has one resource.

    1: # The LearningOnline Network with CAPA
    2: # Edit Handler for RAT Maps
    3: #
    4: # $Id: lonratedt.pm,v 1.33 2002/08/26 12:38:40 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: 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: sub editscript {
  354:     my $mode=shift;
  355:     return(<<ENDSCRIPT);
  356: var srch;
  357: var srchflag=-1; // 1 means currently open
  358:                  // 0 means closed (but has been open)
  359:                  // -1 means never yet opened/defined
  360: var srchmode='';
  361: 
  362: var idx;
  363: var idxflag=-1; // 1 means currently open
  364:                  // 0 means closed (but has been open)
  365:                  // -1 means never yet opened/defined
  366: var idxmode='';
  367: 
  368: // ------------------------------------------------------ Clears indexer window
  369: function idxclear() {
  370:   idx.document.clear();
  371: }
  372: 
  373: // ------------------------------------------------------- Clears search window
  374: function srchclear() {
  375:   srch.document.clear();
  376: }
  377: 
  378: // ------------------------------------------------------ Closes indexer window
  379: function idxclose() {
  380:   if (idx && !idx.closed) {
  381:     idxflag=0;
  382:     idx.close();
  383:   }
  384: }
  385: 
  386: // ------------------------------------------------------- Closes search window
  387: function srchclose() {
  388:   if (srch && !srch.closed) {
  389:     srchflag=0;
  390:     srch.close();
  391:   }
  392: }
  393: 
  394: // -------------------------------------------------------- Open indexer window
  395: function idxopen(mode) {
  396:    var options="scrollbars=1,resizable=1,menubar=0";
  397:    idxmode=mode;
  398:    idxflag=1;
  399:    idx=open("/res/?launch=1&mode=$mode&catalogmode="+mode,"idxout",options);
  400:    idx.focus();
  401: }
  402: 
  403: // --------------------------------------------------------- Open search window
  404: function srchopen(mode) {
  405:    var options="scrollbars=1,resizable=1,menubar=0";
  406:    srchmode=mode;
  407:    srchflag=1;
  408:    srch=open("/adm/searchcat?launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
  409:    srch.focus();
  410: }
  411: // ----------------------------------------------------- launch indexer browser
  412: function groupsearch() {
  413:    srchcheck('groupsearch');
  414: }
  415: 
  416: function groupimport() {
  417:    idxcheck('groupimport');
  418: }
  419: // ------------------------------------------------------- Do srch status check
  420: function srchcheck(mode) {
  421:    if (!srch || srch.closed || srchmode!=mode) {
  422:       srchopen(mode);
  423:    }
  424:    srch.focus();
  425: }
  426: 
  427: // -------------------------------------------------------- Do idx status check
  428: function idxcheck(mode) {
  429:    if (!idx || idx.closed || idxmode!=mode) {
  430:       idxopen(mode);
  431:    }
  432:    idx.focus();
  433: }
  434: 
  435: 
  436:     var editbrowser;
  437:     function openbrowser(formname,elementname,only,omit) {
  438:         var url = '/res/?';
  439:         if (editbrowser == null) {
  440:             url += 'launch=1&';
  441:         }
  442:         url += 'catalogmode=interactive&';
  443:         url += 'mode=edit&';
  444:         url += 'form=' + formname + '&';
  445:         if (only != null) {
  446:             url += 'only=' + only + '&';
  447:         } 
  448:         if (omit != null) {
  449:             url += 'omit=' + omit + '&';
  450:         }
  451:         url += 'element=' + elementname + '';
  452:         var title = 'Browser';
  453:         var options = 'scrollbars=1,resizable=1,menubar=0';
  454:         options += ',width=700,height=600';
  455:         editbrowser = open(url,title,options,'1');
  456:         editbrowser.focus();
  457:     }
  458: ENDSCRIPT
  459: }
  460: # ------------------------------------------------------- Simple edit processor
  461: 
  462: sub smpedt {
  463:    my ($r,$url,$errtext)=@_;
  464:    my $buttons=&buttons(2);
  465: 
  466: # ---------------------------------------------------------- Process form input
  467: 
  468:    my @importselect=();
  469:    my @targetselect=();
  470:    undef @importselect;
  471:    undef @targetselect;
  472:    if (defined($ENV{'form.importsel'})) {
  473:        if (ref($ENV{'form.importsel'})) {
  474: 	   @importselect=sort(@{$ENV{'form.importsel'}});
  475:        } else {
  476:            @importselect=($ENV{'form.importsel'});
  477:        }
  478:    }
  479:    if (defined($ENV{'form.target'})) {
  480:        if (ref($ENV{'form.target'})) {
  481: 	   @targetselect=sort(@{$ENV{'form.target'}});
  482:        } else {
  483:            @targetselect=($ENV{'form.target'});
  484:        }
  485:    }
  486: # ============================================================ Process commands
  487: 
  488:    my $targetdetail=$ENV{'form.targetdetail'};
  489:    my $importdetail=$ENV{'form.curimpdetail'};
  490: 
  491: # ---------------------------------------------------- Importing from groupsort
  492:    if (($ENV{'form.importdetail'}) && (!$ENV{'form.impfortarget'})) {
  493: 
  494:        $importdetail='';
  495:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
  496: 
  497:        my $lastsel;
  498: 
  499:        if (defined($importselect[-1])) {
  500: 	   $lastsel=$importselect[-1];
  501:        } else {
  502:            $lastsel=$#curimport;
  503:        }
  504: 
  505:        for (my $i=0;$i<=$lastsel;$i++) {
  506:            my ($name,$url)=split(/\=/,$curimport[$i]);
  507:            if ($url) {
  508:               $importdetail.='&'.$name.'='.$url;
  509: 	   }
  510:        }
  511: 
  512:       $importdetail.='&'.$ENV{'form.importdetail'};
  513: 
  514:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
  515:            my ($name,$url)=split(/\=/,$curimport[$i]);
  516:            if ($url) {
  517:               $importdetail.='&'.$name.'='.$url;
  518: 	  }
  519:        }
  520:        $importdetail=~s/\&+/\&/g;
  521:        $importdetail=~s/^\&//;
  522: 
  523: # ------------------------------------------------------------------- Clear all
  524:    } elsif ($ENV{'form.clear'}) {
  525:        $importdetail='';
  526: # ------------------------------------------------------------ Discard selected
  527:    } elsif ($ENV{'form.discard'}) {
  528:        $importdetail='';
  529:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
  530:        foreach (@importselect) {
  531: 	   $curimport[$_]='';
  532:        }
  533:        for (my $i=0;$i<=$#curimport;$i++) {
  534:            my ($name,$url)=split(/\=/,$curimport[$i]);
  535:            if ($url) {
  536:               $importdetail.='&'.$name.'='.$url;
  537: 	   }
  538:        }
  539: # --------------------------------------------------------- Loading another map
  540:    } elsif ($ENV{'form.loadmap'}) {
  541:        $importdetail='';
  542:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
  543: 
  544:        my $lastsel;
  545: 
  546:        if (defined($importselect[-1])) {
  547: 	   $lastsel=$importselect[-1];
  548:        } else {
  549:            $lastsel=$#curimport;
  550:        }
  551: 
  552:        for (my $i=0;$i<=$lastsel;$i++) {
  553:            my ($name,$url)=split(/\=/,$curimport[$i]);
  554:            if ($url) {
  555:               $importdetail.='&'.$name.'='.$url;
  556: 	   }
  557:        }
  558: 
  559:        foreach (
  560:     &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
  561: 	   my ($name,$url)=split(/\:/,$_);
  562:            if ($url) {
  563:               $importdetail.='&'.&Apache::lonnet::escape($name).'='.
  564: 		 	         &Apache::lonnet::escape($url);
  565: 	  }
  566:        }
  567: 
  568:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
  569:            my ($name,$url)=split(/\=/,$curimport[$i]);
  570:            if ($url) {
  571:               $importdetail.='&'.$name.'='.$url;
  572: 	  }
  573:        }
  574:        $importdetail=~s/\&+/\&/g;
  575:        $importdetail=~s/^\&//;
  576: 
  577: # ------------------------------------------------ Groupimport/search to target
  578:    } elsif ($ENV{'form.importdetail'}) {
  579:        my $lastsel;
  580:        if (defined($targetselect[-1])) {
  581: 	   $lastsel=$targetselect[-1];
  582:        } else {
  583:            $lastsel=$#order+1;
  584:        }
  585:        &pastetarget($lastsel,split(/\&/,$ENV{'form.importdetail'}));
  586:        &storemap(&Apache::lonnet::filelocation('',$url));
  587: # ------------------------------------------------------------------------- Cut
  588:    } elsif (($ENV{'form.cut'}) || ($ENV{'form.copy'})) {
  589:        $importdetail='';
  590:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
  591: 
  592:        my $lastsel;
  593: 
  594:        if (defined($importselect[-1])) {
  595: 	   $lastsel=$importselect[-1];
  596:        } else {
  597:            $lastsel=$#curimport;
  598:        }
  599: 
  600:        for (my $i=0;$i<=$lastsel;$i++) {
  601:            my ($name,$url)=split(/\=/,$curimport[$i]);
  602:            if ($url) {
  603:               $importdetail.='&'.$name.'='.$url;
  604: 	   }
  605:        }
  606: 
  607:        foreach (@targetselect) {
  608: 	   my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
  609:            if ($url) {
  610:               $importdetail.='&'.&Apache::lonnet::escape($name).'='.
  611: 		 	         &Apache::lonnet::escape($url);
  612: 	  }
  613:        }
  614: 
  615:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
  616:            my ($name,$url)=split(/\=/,$curimport[$i]);
  617:            if ($url) {
  618:               $importdetail.='&'.$name.'='.$url;
  619: 	  }
  620:        }
  621:        $importdetail=~s/\&+/\&/g;
  622:        $importdetail=~s/^\&//;
  623: 
  624:        if ($ENV{'form.cut'}) {
  625:            my @neworder=();
  626:            for (my $i=0;$i<=$#order;$i++) {
  627:                my $include=1;
  628:                foreach (@targetselect) {
  629: 		   if ($_-1==$i) { $include=0; }
  630:                }
  631:                if ($include) { $neworder[$#neworder+1]=$order[$i]; }
  632:            }
  633:            @order=@neworder;
  634:            &storemap(&Apache::lonnet::filelocation('',$url));      
  635:        }
  636: 
  637: # ----------------------------------------------------------------------- Paste
  638:    } elsif ($ENV{'form.paste'}) {
  639:        my $lastsel;
  640:        if (defined($targetselect[-1])) {
  641: 	   $lastsel=$targetselect[-1];
  642:        } else {
  643:            $lastsel=$#order+1;
  644:        }
  645:        my @newsequence;
  646:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
  647:        foreach (@importselect) {
  648:           $newsequence[$#newsequence+1]=$curimport[$_];
  649:        }
  650:        &pastetarget($lastsel,@newsequence);
  651:        &storemap(&Apache::lonnet::filelocation('',$url));
  652: # ------------------------------------------------ 
  653:    }
  654: # ------------------------------------------------------------ Assemble windows
  655:    
  656:    my $idx=-1;
  657:    my $importwindow=
  658:        '<option value="-1"> ---- Import and Paste Area ---- </option>'.
  659:      join("\n",map {
  660:        $idx++;
  661:        if ($_) { 
  662:           my ($name,$url)=split(/\=/,$_);
  663:           unless ($name) { $name=(split(/\//,$url))[-1]; }
  664:           unless ($name) { $name='EMPTY'; }
  665:           '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
  666:                                     '</option>';
  667:       }
  668:    } split(/\&/,$importdetail));
  669: 
  670:    $idx=0;
  671:    my $targetwindow=       
  672:        '<option value="0"> ------- Target Edit Map ------- </option>'.
  673:      join("\n",map { 
  674:        my ($name,$url)=split(/\:/,$resources[$_]);
  675:        unless ($name) {  $name=(split(/\//,$url))[-1]; }
  676:        unless ($name) { $name='EMPTY'; }
  677:        $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
  678: 	                  &Apache::lonnet::escape($url);
  679:        $idx++;
  680:        '<option value="'.$idx.'">'.$name.'</option>';
  681:    } @order);
  682: 
  683: # ----------------------------------------------------- Start simple RAT screen
  684:    my $editscript=&editscript('simple');
  685:    $r->print(<<ENDSMPHEAD);
  686: <html>
  687: <head>
  688: <script>
  689: 
  690:    $editscript
  691: 
  692:    function openview(entry) {
  693:        var url=unescape((entry.split('='))[1]);
  694:        var parts=new Array;
  695:        parts=url.split('&colon;');
  696:        url=parts.join(':');
  697:        if (url) { open(url,'cat'); }
  698:    }
  699: 
  700:    function viewtarget() {
  701:        openview((document.forms.simpleedit.targetdetail.value.split('&'))
  702:                 [document.forms.simpleedit.target.selectedIndex+1]);
  703:    }
  704: 
  705:    function viewimport() {
  706:        openview((document.forms.simpleedit.curimpdetail.value.split('&'))
  707:                 [document.forms.simpleedit.importsel.selectedIndex+1]);
  708:    }
  709: 
  710: </script>
  711: </head>                 
  712: <body bgcolor='#FFFFFF'>
  713: $buttons
  714: <font color=red>$errtext</font>
  715: <h1>$url</h1>
  716: <form name=simpleedit method=post>
  717: <input type=hidden name=forcesmp value=1>
  718: <table>
  719:     <tr><th width="40%">Import</th>
  720: <th>&nbsp;</th>
  721: <th width="40%">Target</th></tr>
  722: <tr><td bgcolor="#FFFFCC">
  723: <input type=button onClick="javascript:groupsearch()" value="Group Search">
  724: <input type=button onClick="javascript:groupimport();" value="Group Import">
  725: after selected
  726: <hr>
  727: <input type=text size=20 name=importmap>
  728: <input type=button 
  729: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
  730: value="Browse"><input type=submit name=loadmap value="Load Map"><hr>
  731: <input type=submit name="discard" value="Discard Selected">
  732: <input type=submit name="clear" value="Clear All">
  733: <input type=button onClick="javascript:viewimport()" value="View">
  734: 
  735:     </td><td>&nbsp;</td><td bgcolor="#FFFFCC">
  736: 
  737: <input type=button onClick=
  738: "javascript:impfortarget.value=1;groupsearch()" value="Group Search">
  739: <input type=button onClick=
  740: "javascript:impfortarget.value=1;groupimport();" value="Group Import">
  741: after selected
  742: <hr><input type=button onClick="javascript:viewtarget()" value="View">
  743: </td></tr>
  744: 
  745: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
  746: $importwindow
  747: </select>
  748: </td>
  749: <td bgcolor="#FFFFAA" align="center">
  750: Cut selected<br>
  751: <input type=submit name=cut value='<<<'><p>
  752: <hr>
  753: Copy selected<br>
  754: <input type=submit name=copy value='<--'><p>
  755: <hr>
  756: Paste after selected<br>
  757: <input type=submit name=paste value='-->'>
  758: </td>
  759: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
  760: $targetwindow
  761: </select>
  762: </table>
  763: <input type=hidden name=importdetail value="">
  764: <input type=hidden name=curimpdetail value="$importdetail">
  765: <input type=hidden name=targetdetail value="$targetdetail">
  766: <input type=hidden name=impfortarget value="0">
  767: </form>
  768: </body></html>
  769: ENDSMPHEAD
  770: }
  771: 
  772: # ----------------------------------------------------------------- No such dir
  773: sub nodir {
  774:    my ($r,$dir)=@_;
  775:    $dir=~s/^\/home\/\w+\/public\_html//;
  776:    $r->print(<<ENDNODIR);
  777: <html>
  778: <body bgcolor='#FFFFFF'>
  779: <h1>No such directory: $dir</h1>
  780: </body>
  781: </html>
  782: ENDNODIR
  783: }
  784: 
  785: # ---------------------------------------------------------------- View Handler
  786: 
  787: sub viewmap {
  788:     my ($r,$url,$adv,$errtext)=@_;
  789:     $r->print('<html><body bgcolor="#FFFFFF">'.&buttons($adv));
  790:     if ($errtext) {
  791: 	$r->print($errtext.'<hr>');
  792:     }
  793:     my $idx=0;
  794:     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
  795: 	if (defined($_)) {
  796:             $idx++;
  797: 	    my ($title,$url)=split(/\:/,$_);
  798:             $title=~s/\&colon\;/\:/g;
  799:             $url=~s/\&colon\;/\:/g;
  800:             unless ($title) { $title=(split(/\//,$url))[-1] };
  801:             unless ($title) { $title='<i>Empty</i>'; }
  802:             if ($url) {
  803: 		$r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
  804:             }
  805:             $r->print(&Apache::lonratsrv::qtescape($title));
  806:             if ($url) { $r->print('</a>'); }
  807: 	    $r->print('<br>');
  808:         }
  809:     }
  810:     $r->print('</body></html>');
  811: }
  812: 
  813: # ================================================================ Main Handler
  814: 
  815: sub handler {
  816:   my $r=shift;
  817:   $r->content_type('text/html');
  818:   $r->send_http_header;
  819: 
  820:   return OK if $r->header_only;
  821: 
  822:   my $url=$r->uri;
  823:   my $fn=&Apache::lonnet::filelocation('',$url);
  824: 
  825:   my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
  826:   unless (-e $dir) {
  827:       &nodir($r,$dir);
  828:       return OK;
  829:   }
  830: 
  831: # ------------------------------------------- Determine which tools can be used
  832:   my $adv=0;
  833: 
  834:   unless ($ENV{'form.forcesmp'}) {
  835:      if ($ENV{'form.forceadv'}) {
  836:         $adv=1;
  837:      } elsif (my $fh=Apache::File->new($fn)) {
  838: 	 my $allmap=join('',<$fh>);
  839:          $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
  840:      }
  841:   }
  842: 
  843:   my $errtext='';
  844:   my $fatal=0;
  845: 
  846: # -------------------------------------------------------------------- Load map
  847:   ($errtext,$fatal)=&mapread($fn,$errtext);
  848: 
  849:   if ($fatal==1) { $adv=1; }
  850: 
  851: # ----------------------------------- adv==1 now means "graphical MUST be used"
  852: 
  853:   if ($ENV{'form.forceadv'}) {
  854:       &ratedt($r,$url);
  855:   } elsif ($ENV{'form.forcesmp'}) {
  856:       &smpedt($r,$url,$errtext);
  857:   } else {
  858:       &viewmap($r,$url,$adv,$errtext);
  859:   }
  860:   return OK;
  861: }
  862: 
  863: 1;
  864: __END__
  865: 
  866: 
  867: 
  868: 
  869: 
  870: 
  871: 

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