File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.71: download - view: text, annotated - select for diffs
Wed Jun 8 18:49:38 2005 UTC (18 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
Bug #882: ID management, get old idx back

    1: # The LearningOnline Network with CAPA
    2: # Edit Handler for RAT Maps
    3: #
    4: # $Id: lonratedt.pm,v 1.71 2005/06/08 18:49:38 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: 
   29: 
   30: package Apache::lonratedt;
   31: 
   32: =pod
   33: 
   34: =head1 NAME
   35: 
   36: Apache::lonratedt: simple resource assembly tool
   37: 
   38: =head1 SYNOPSIS
   39: 
   40: lonratedt provides the routines and the handler for the Advanced
   41:     Resource Assembly Tool (RAT), and ties the various pieces together
   42:     with Javascript.
   43: 
   44: =head1 OVERVIEW
   45: 
   46: =head2 Map Representation
   47: 
   48: =begin latex
   49: 
   50: %
   51: \begin{figure}
   52: \begin{center}\includegraphics[%
   53:   width=0.55\paperwidth,bb = 0 0 200 100, draft, type=eps]{Map_Example}\end{center}
   54: 
   55: 
   56: \caption{\label{Map_In_Advanced_Editor}Example of a Map in the Advanced Editor}
   57: \end{figure}
   58: %
   59: \begin{figure}
   60: \begin{lyxcode}
   61: <map>
   62: 
   63: ~~<resource~id=\char`\"{}1\char`\"{}
   64: 
   65: ~~~~src=\char`\"{}/res/msu/korte/phy231welcome.html\char`\"{}
   66: 
   67: ~~~~type=\char`\"{}start\char`\"{}
   68: 
   69: ~~~~title=\char`\"{}Start\char`\"{}>
   70: 
   71: ~~~~</resource>
   72: 
   73: ~~<resource~id=\char`\"{}2\char`\"{}
   74: 
   75: ~~~~src=\char`\"{}\char`\"{}~type=\char`\"{}finish\char`\"{}
   76: 
   77: ~~~~title=\char`\"{}Finish\char`\"{}>
   78: 
   79: ~~~~</resource>
   80: 
   81: ~~<resource~id=\char`\"{}6\char`\"{}
   82: 
   83: ~~~~src=\char`\"{}/res/msu/korte/tests/units.problem\char`\"{}
   84: 
   85: ~~~~type=\char`\"{}mandatory\char`\"{}
   86: 
   87: ~~~~title=\char`\"{}Physical~Units~Test\char`\"{}>
   88: 
   89: ~~~~</resource>
   90: 
   91: ~~<resource~id=\char`\"{}9\char`\"{}
   92: 
   93: ~~~~src=\char`\"{}/res/msu/korte/chapters/onedim.sequence\char`\"{}
   94: 
   95: ~~~~title=\char`\"{}Motion~in~One~Dimension\char`\"{}>
   96: 
   97: ~~~~</resource>
   98: 
   99: ~~<resource~id=\char`\"{}11\char`\"{}
  100: 
  101: ~~~~src=\char`\"{}/res/msu/bauer/bridges/units.sequence\char`\"{}
  102: 
  103: ~~~~title=\char`\"{}Physical~Units~Refresher\char`\"{}>
  104: 
  105: ~~~~</resource>
  106: 
  107: ~~<condition~id=\char`\"{}19\char`\"{}
  108: 
  109: ~~~~type=\char`\"{}stop\char`\"{}
  110: 
  111: ~~~~value=\char`\"{}user.assessments{[}this./res/msu/korte/tests/units.problem{]}.status=solved\char`\"{}>
  112: 
  113: ~~~~</condition>
  114: 
  115: ~~<link~from=\char`\"{}1\char`\"{}~to=\char`\"{}6\char`\"{}></link>
  116: 
  117: ~~<link~from=\char`\"{}6\char`\"{}~to=\char`\"{}9\char`\"{}~condition=\char`\"{}19\char`\"{}></link>
  118: 
  119: ~~<link~from=\char`\"{}6\char`\"{}~to=\char`\"{}11\char`\"{}></link>
  120: 
  121: ~~<link~from=\char`\"{}11\char`\"{}~to=\char`\"{}6\char`\"{}></link>
  122: 
  123: ~~</map>
  124: \end{lyxcode}
  125: 
  126: \caption{\label{XML}XML for Map in Figure \ref{Map_In_Advanced_Editor}}
  127: \end{figure}
  128: 
  129: =end latex
  130: 
  131: Fig. "XML for Map in Figure" shows the XML representation of the
  132: resource map shown in Fig. "Example of a Map in the Advanced Editor",
  133: which is the format in which maps are stored. In the figure, however,
  134: additional graphical map layout information generated by the Advanced
  135: Resource Assembly Tool is not displayed. This graphical information is
  136: optional to re-generate the same graphical layout when the map is
  137: brought up again in the Resource Assembly Tool, and is not needed for
  138: any other system functionality.
  139: 
  140: Maps can be generated by tools other than the Resource Assembly
  141: Tool. In particular, an author might have some other representation of
  142: a course sequence, which can be converted into a map using scripts. If
  143: this map then were to be brought up in the Resource Assembly Tool, the
  144: Tool would automatically generate a graphical layout for it. Each
  145: entry of the map (resources, conditions and links) is stored in a
  146: separate tag.
  147: 
  148: Resources and conditionsX<conditions> have to have unique ID
  149: numbers. These numbers are automatically generated by the Resource
  150: Assembly Tool when the entry is first created, or added to the entries
  151: when a map generated outside the Resource Assembly Tool is first
  152: retrieved. They can also be assigned by custom scripts or added in by
  153: hand.
  154: 
  155: In the XML example, entry 1 is the start resource of the map. When
  156: this map is accessed, the source (src) URL of this tag will be the
  157: first resource rendered. Entry 2 is the finish resource of this
  158: map. This resource will be the last resource in the sequence of
  159: resources. Entry 6 is a problem resource with the given URL and title,
  160: as well as the priority "mandatory". Entry 19 is a condition, which is
  161: used by the link between entries 6, the problem, and 9, a
  162: sequence. I<The final syntax for conditions has not yet been
  163: determined.>
  164: 
  165: =cut
  166: 
  167: use strict;
  168: use Apache::Constants qw(:common);
  169: use Apache::lonnet;
  170: use Apache::lonratsrv;
  171: use Apache::lonsequence;
  172: use Apache::loncommon;
  173: use Apache::lonlocal;
  174: use File::Copy;
  175: 
  176: use vars qw(@order @resources @resparms @zombies);
  177: 
  178: 
  179: # Mapread read maps into global arrays @links and @resources, determines status
  180: # sets @order - pointer to resources in right order
  181: # sets @resources - array with the resources with correct idx
  182: #
  183: sub mapread {
  184:     my $fn=shift;
  185: 
  186:     my @links;
  187:     undef @links;
  188:     undef @resources;
  189:     undef @order;
  190:     undef @resparms;
  191:     undef @zombies;
  192: 
  193:     @resources=('');
  194:     @order=();
  195:     @resparms=();
  196:     @zombies=();
  197: 
  198:     my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
  199:     if ($errtext) { return ($errtext,2); }
  200: 
  201: # -------------------------------------------------------------------- Read map
  202:     foreach (split(/\<\&\>/,$outtext)) {
  203: 	my ($command,$number,$content)=split(/\<\:\>/,$_);
  204:         if ($command eq 'objcont') {
  205: 	    my ($title,$src,$ext,$type)=split(/\:/,$content);
  206: 	    if ($ext eq 'cond') { next; }
  207: 	    if ($type ne 'zombie') {
  208: 		$resources[$number]=$content;
  209: 	    } else {
  210: 		$zombies[$number]=$content;
  211: 	    }
  212:         }
  213:         if ($command eq 'objlinks') {
  214:             $links[$number]=$content;
  215:         }
  216:         if ($command eq 'objparms') {
  217: 	    if ($resparms[$number]) {
  218: 		$resparms[$number].='&&&'.$content;
  219: 	    } else {
  220: 		$resparms[$number]=$content;
  221: 	    }
  222:         }
  223:     }
  224: # ------------------------------------------------------- Is this a linear map?
  225:     my @starters=();
  226:     my @endings=();
  227:     undef @starters;
  228:     undef @endings;
  229: 
  230:     foreach (@links) {
  231:         if (defined($_)) {
  232: 	    my ($start,$end,$cond)=split(/\:/,$_);
  233:             if ((defined($starters[$start])) || (defined($endings[$end]))) { 
  234: 		return
  235:                  (&mt('Map has branchings. Use advanced editor.'),1);
  236:             }
  237: 	    $starters[$start]=1;
  238: 	    $endings[$end]=1;
  239: 	    if ($cond) {
  240: 		return
  241:                  (&mt('Map has conditions. Use advanced editor.'),1);
  242:             }
  243: 	}
  244: 
  245:     }
  246:     for (my $i=1; $i<=$#resources; $i++) {
  247:         if (defined($resources[$i])) {
  248: 	    unless (($starters[$i]) || ($endings[$i])) {
  249:                 return
  250: 		 (&mt('Map has unconnected resources. Use advanced editor.'),1);
  251:             }
  252:         }
  253:     }
  254: # ---------------------------------------------- Did we just read an empty map?
  255:     if ($#resources<1) {
  256:         undef $resources[0];
  257: 	$resources[1]=':::start';
  258:         $resources[2]=':::finish';
  259:     }
  260: # -------------------------------------------------- This is a linear map, sort
  261: 
  262:     my $startidx=0;
  263:     my $endidx=0;
  264:     for (my $i=0; $i<=$#resources; $i++) {
  265:         if (defined($resources[$i])) {
  266:             my ($title,$url,$ext,$type)=split(/\:/,$resources[$i]);
  267: 	    if ($type eq 'start') { $startidx=$i; }
  268:             if ($type eq 'finish') { $endidx=$i; }
  269:         }
  270:     }
  271:     my $k=0;
  272:     my $currentidx=$startidx;
  273:     $order[$k]=$currentidx;
  274:     for (my $i=0; $i<=$#resources; $i++) {
  275:         foreach (@links) {
  276: 	    my ($start,$end)=split(/\:/,$_);
  277:             if ($start==$currentidx) {
  278: 		$currentidx=$end;
  279:                 $k++;
  280:                 $order[$k]=$currentidx;
  281:                 last;
  282:             }
  283:         }
  284:         if ($currentidx==$endidx) { last; }
  285:     }
  286:     return $errtext;
  287: }
  288: 
  289: # ---------------------------------------------- Read a map as well as possible
  290: # Also used by the sequence handler
  291: # Call lonsequence::attemptread to read from resource space
  292: #
  293: sub attemptread {
  294:     my $fn=shift;
  295: 
  296:     my @links;
  297:     undef @links;
  298:     my @theseres;
  299:     undef @theseres;
  300: 
  301:     my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
  302:     if ($errtext) { return @theseres }
  303: 
  304: # -------------------------------------------------------------------- Read map
  305:     foreach (split(/\<\&\>/,$outtext)) {
  306: 	my ($command,$number,$content)=split(/\<\:\>/,$_);
  307:         if ($command eq 'objcont') {
  308: 	    my ($title,$src,$ext,$type)=split(/\:/,$content);
  309: 	    unless ($type eq 'zombie') {
  310: 		$theseres[$number]=$content;
  311: 	    }
  312:         }
  313:         if ($command eq 'objlinks') {
  314:             $links[$number]=$content;
  315:         }
  316:     }
  317: 
  318: # --------------------------------------------------------------- Sort, sort of
  319: 
  320:     my @objsort=();
  321:     undef @objsort;
  322: 
  323:     my @data1=();
  324:     my @data2=();
  325:     undef @data1;
  326:     undef @data2;
  327: 
  328:     my $k;
  329:     my $kj;
  330:     my $j;
  331:     my $ij;
  332: 
  333:    for ($k=1;$k<=$#theseres;$k++) {
  334:       if (defined($theseres[$k])) {
  335:          $objsort[$#objsort+1]=$k;
  336:       }
  337:    }
  338: 
  339:    for ($k=1;$k<=$#links;$k++) {
  340:      if (defined($links[$k])) {
  341:       @data1=split(/\:/,$links[$k]);
  342:       $kj=-1;
  343:       for (my $j=0;$j<=$#objsort;$j++) {
  344:          if ((split(/\:/,$objsort[$j]))[0]==$data1[0]) {
  345:             $kj=$j;
  346:          }
  347:       }
  348:       if ($kj!=-1) { $objsort[$kj].=':'.$data1[1]; }
  349:      }
  350:    }
  351:     for ($k=0;$k<=$#objsort;$k++) {
  352:       for ($j=0;$j<=$#objsort;$j++) {
  353:         if ($k!=$j) {
  354:           @data1=split(/\:/,$objsort[$k]);
  355:           @data2=split(/\:/,$objsort[$j]);
  356:           my $dol=$#data1+1;
  357:           my $dtl=$#data2+1;
  358:           if ($dol+$dtl<1000) {
  359:            for ($kj=1;$kj<$dol;$kj++) {
  360:              if ($data1[$kj]==$data2[0]) {
  361:                 for ($ij=1;$ij<$dtl;$ij++) {
  362:                    $data1[$#data1+1]=$data2[$ij];
  363:                 }
  364:              }
  365:            }
  366:            for ($kj=1;$kj<$dtl;$kj++) {
  367:              if ($data2[$kj]==$data1[0]) {
  368:                  for ($ij=1;$ij<$dol;$ij++) {
  369:                     $data2[$#data2+1]=$data1[$ij];
  370:                  }
  371:              }
  372:            }
  373:            $objsort[$k]=join(':',@data1);
  374:            $objsort[$j]=join(':',@data2);
  375:           }
  376:          }
  377:       } 
  378:   }
  379: # ---------------------------------------------------------------- Now sort out
  380: 
  381:     @objsort=sort {
  382:       my @data1=split(/\:/,$a);
  383:       my @data2=split(/\:/,$b);
  384:       my $rvalue=0;
  385:       my $k;
  386:       for ($k=1;$k<=$#data1;$k++) {
  387:          if ($data1[$k]==$data2[0]) { $rvalue--; }
  388:       }
  389:       for ($k=1;$k<=$#data2;$k++) {
  390:          if ($data2[$k]==$data1[0]) { $rvalue++; }
  391:       }
  392:       if ($rvalue==0) { $rvalue=$#data2-$#data1; }
  393:       $rvalue;
  394:     } @objsort;
  395: 
  396:     my @outres=();
  397:     undef @outres;
  398: 
  399:     for ($k=0;$k<=$#objsort;$k++) {
  400: 	$outres[$k]=$theseres[(split(/\:/,$objsort[$k]))[0]];
  401:     }
  402:     return @outres;
  403: }
  404: 
  405: # --------------------------------------------------------- Build up RAT screen
  406: sub ratedt {
  407:   my ($r,$url)=@_;
  408:   my $frameset = '<frameset rows="1,70,*" border="0">';
  409:   if ($env{'environment.remote'} eq 'off') {
  410:       $frameset = '<frameset rows="1,250,*" border="0">';
  411:   }
  412:   $r->print(<<ENDDOCUMENT);
  413: 
  414: <html>
  415: <head>
  416: <script language="JavaScript">
  417:     var flag=0;
  418: </script>
  419: </head>
  420: $frameset
  421: <frame name=server src="$url/loadonly/ratserver" noresize noscroll>
  422: <frame name=code src="$url/loadonly/adveditmenu">
  423: <frame name=mapout src="/adm/rat/map.html">
  424: </frameset>
  425: </html>
  426: 
  427: ENDDOCUMENT
  428: }
  429: 
  430: # ---------------------------------------------------------------- Make buttons
  431: 
  432: sub buttons {
  433:     my $adv=shift;
  434:     my $output='<form method=post>';     
  435:     if ($adv==1) {
  436: 	$output.='<input type=submit name=forceadv value="'.&mt('Edit').'">'.
  437: 	    &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');;
  438:     } else {
  439:         unless ($adv==2) {
  440:            $output.='<input type=submit name=forcesmp value="'.&mt('Simple Edit').'">'.
  441: 	    &Apache::loncommon::help_open_topic('Sequence_Simple_Editor_Creation');
  442:         }
  443: 	$output.='<input type=submit name=forceadv value="'.&mt('Advanced Edit').'">'.
  444: 	    &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');
  445:     }
  446:     return $output.'</form><hr>';
  447: }
  448: 
  449: # ------------------------------------- Revive zombie idx or get unused number
  450: 
  451: sub getresidx {
  452:     my $url=shift;
  453:     my $max=1+($#resources>$#zombies?$#resources:$#zombies);
  454:     unless ($url) { return $max; }
  455:     for (my $i=0; $i<=$#zombies; $i++) {
  456: 	my ($title,$src,$ext,$type)=split(/\:/,$zombies[$i]);
  457: 	if ($src eq $url) {
  458: 	    undef $zombies[$i];
  459: 	    return $i;
  460: 	}
  461:     }
  462:     return $max;
  463: }
  464: 
  465: # --------------------------------------------------------------- Make a zombie
  466: 
  467: sub makezombie {
  468:     my $idx=shift;
  469:     my ($name,$url,$ext)=split(/\:/,$resources[$idx]);
  470:     $zombies[$idx]=$name.':'.$url.':'.$ext.':zombie';
  471: }
  472: 
  473: # ----------------------------------------------------------- Paste into target
  474: # modifies @order, @resources
  475: 
  476: sub pastetarget {
  477:     my ($after,@which)=@_;
  478:     my @insertorder=();
  479:     foreach (@which) {
  480:         if (defined($_)) {
  481: 	    my ($name,$url)=split(/\=/,$_);
  482:             $name=&Apache::lonnet::unescape($name);
  483:             $url=&Apache::lonnet::unescape($url);
  484:             if ($url) {
  485: 	       my $idx=&getresidx($url);
  486:                $insertorder[$#insertorder+1]=$idx;
  487:                my $ext='false';
  488:                if ($url=~/^http\:\/\//) { $ext='true'; }
  489:                $url=~s/\:/\&colon;/g;
  490:                $name=~s/\:/\&colon;/g;
  491:                $resources[$idx]=$name.':'.$url.':'.$ext.':normal:res';
  492: 	   }
  493:         }
  494:     }
  495:     my @oldorder=splice(@order,$after);
  496:     @order=(@order,@insertorder,@oldorder);
  497: }
  498: 
  499: # ------------------------------------------------ Get start and finish correct
  500: # modifies @resources
  501: 
  502: sub startfinish {
  503: # Remove all start and finish
  504:     foreach (@order) {
  505: 	my ($name,$url,$ext)=split(/\:/,$resources[$_]);
  506:         if ($url=~/http\&colon\:\/\//) { $ext='true'; }
  507:         $resources[$_]=$name.':'.$url.':'.$ext.':normal:res';
  508:     }
  509: # Garbage collection
  510:     my $stillchange=1;
  511:      while (($#order>1) && ($stillchange)) {
  512:        $stillchange=0;
  513:        for (my $i=0;$i<=$#order;$i++) {
  514:  	  my ($name,$url,$ext)=split(/\:/,$resources[$order[$i]]);
  515:           unless ($url) {
  516: # Take out empty resource
  517:               for (my $j=$i+1;$j<=$#order;$j++) {
  518:                   $order[$j-1]=$order[$j];
  519: 	      }
  520:               $#order--;
  521: 	      $stillchange=1;
  522:               last;
  523:           }
  524:        }
  525:     }
  526: # Put in a start resource
  527:    my ($name,$url,$ext)=split(/\:/,$resources[$order[0]]);
  528:    $resources[$order[0]]=$name.':'.$url.':'.$ext.':start:res';
  529: # Make sure this has at least start and finish
  530:    if ($#order==0) {
  531:        $resources[&getresidx()]='::false';
  532:        $order[1]=$#resources;
  533:    }
  534: # Make the last one a finish resource
  535:    ($name,$url,$ext)=split(/\:/,$resources[$order[$#order]]);
  536:    $resources[$order[$#order]]=$name.':'.$url.':'.$ext.':finish:res';
  537: }
  538: 
  539: # ------------------------------------------------------------------- Store map
  540: 
  541: sub storemap {
  542:     my $realfn=shift;
  543:     my $fn=$realfn;
  544: # unless this is forced to work from the original file, use a temporary file
  545: # instead
  546:     unless (shift) {
  547:        $fn=$realfn.'.tmp';
  548:        unless (-e $fn) {
  549: 	  copy($realfn,$fn);
  550:        }
  551:     }
  552: # store data either into tmp or real file
  553:     &startfinish();
  554:     my $output='graphdef<:>no';
  555:     my $k=1;
  556:     for (my $i=0; $i<=$#order; $i++) {
  557:         if (defined($resources[$order[$i]])) {
  558: 	    $output.='<&>objcont<:>'.$order[$i].'<:>'.$resources[$order[$i]];
  559:         }
  560: 	if (defined($resparms[$order[$i]])) {
  561: 	    foreach (split('&&&',$resparms[$order[$i]])) {
  562: 		if ($_) {
  563: 		    $output.='<&>objparms<:>'.$order[$i].'<:>'.$_;
  564: 		}
  565: 	    }
  566: 	}
  567:         if (defined($order[$i+1])) {
  568: 	    if (defined($resources[$order[$i+1]])) {
  569:                $output.='<&>objlinks<:>'.$k.'<:>'.
  570: 		   $order[$i].':'.$order[$i+1].':0';
  571: 	       $k++;
  572:             }
  573:         }
  574:     }
  575:     for (my $i=0; $i<=$#zombies; $i++) {
  576:         if (defined($zombies[$i])) {
  577: 	    $output.='<&>objcont<:>'.$i.'<:>'.$zombies[$i];
  578:         }
  579:     }
  580:     $output=~s/http\&colon\;\/\///g;
  581:     $env{'form.output'}=$output;
  582:     return 
  583:      &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));
  584: }
  585: 
  586: # ------------------------------------------ Store and get parameters in global
  587: 
  588: sub storeparameter {
  589:     my ($to,$name,$value,$ptype)=@_;
  590:     my $newentry='';
  591:     my $nametype='';
  592:     foreach (split('&&&',$resparms[$to])) {
  593: 	my ($thistype,$thisname,$thisvalue)=split('___',$_);
  594: 	if ($thisname) {
  595: 	    unless ($thisname eq $name) {
  596: 		$newentry.=$_.'&&&';
  597: 	    } else {
  598: 		$nametype=$thistype;
  599: 	    }
  600: 	}
  601:     }
  602:     unless ($ptype) { $ptype=$nametype; }
  603:     unless ($ptype) { $ptype='string'; }
  604:     $newentry.=$ptype.'___'.$name.'___'.$value;
  605:     $resparms[$to]=$newentry;
  606: }
  607: 
  608: sub delparameter {
  609:     my ($to,$name)=@_;
  610:     my $newentry='';
  611:     my $nametype='';
  612:     foreach (split('&&&',$resparms[$to])) {
  613: 	my ($thistype,$thisname,$thisvalue)=split('___',$_);
  614: 	if ($thisname) {
  615: 	    unless ($thisname eq $name) {
  616: 		$newentry.=$_.'&&&';
  617: 	    }
  618: 	}
  619:     }
  620:     $resparms[$to]=$newentry;
  621: }
  622: 
  623: sub getparameter {
  624:     my ($to,$name)=@_;
  625:     my $value=undef;
  626:     my $ptype=undef;
  627:     foreach (split('&&&',$resparms[$to])) {
  628: 	my ($thistype,$thisname,$thisvalue)=split('___',$_);
  629: 	if ($thisname eq $name) {
  630: 	    $value=$thisvalue;
  631: 	    $ptype=$thistype;
  632: 	}
  633:     }
  634:     return ($value,$ptype);
  635: }
  636: 
  637: # ----------------------------------------------------------------- Edit script
  638: sub editscript {
  639:     my $mode=shift;
  640:     my $resurl=&Apache::loncommon::lastresurl();
  641:     return(<<ENDSCRIPT);
  642: var srch;
  643: var srchflag=-1; // 1 means currently open
  644:                  // 0 means closed (but has been open)
  645:                  // -1 means never yet opened/defined
  646: var srchmode='';
  647: 
  648: var idx;
  649: var idxflag=-1; // 1 means currently open
  650:                  // 0 means closed (but has been open)
  651:                  // -1 means never yet opened/defined
  652: var idxmode='';
  653: 
  654: // ------------------------------------------------------ Clears indexer window
  655: function idxclear() {
  656:   idx.document.clear();
  657: }
  658: 
  659: // ------------------------------------------------------- Clears search window
  660: function srchclear() {
  661:   srch.document.clear();
  662: }
  663: 
  664: // ------------------------------------------------------ Closes indexer window
  665: function idxclose() {
  666:   if (idx && !idx.closed) {
  667:     idxflag=0;
  668:     idx.close();
  669:   }
  670: }
  671: 
  672: // ------------------------------------------------------- Closes search window
  673: function srchclose() {
  674:   if (srch && !srch.closed) {
  675:     srchflag=0;
  676:     srch.close();
  677:   }
  678: }
  679: 
  680: // -------------------------------------------------------- Open indexer window
  681: function idxopen(mode) {
  682:    var options="scrollbars=1,resizable=1,menubar=0";
  683:    idxmode=mode;
  684:    idxflag=1;
  685:    idx=open("$resurl/?launch=1&mode=$mode&catalogmode="+mode,"idxout",options);
  686:    idx.focus();
  687: }
  688: 
  689: // --------------------------------------------------------- Open search window
  690: function srchopen(mode) {
  691:    var options="scrollbars=1,resizable=1,menubar=0";
  692:    srchmode=mode;
  693:    srchflag=1;
  694:    srch=open("/adm/searchcat?launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
  695:    srch.focus();
  696: }
  697: // ----------------------------------------------------- launch indexer browser
  698: function groupsearch() {
  699:    srchcheck('groupsearch');
  700: }
  701: 
  702: function groupimport() {
  703:    idxcheck('groupimport');
  704: }
  705: // ------------------------------------------------------- Do srch status check
  706: function srchcheck(mode) {
  707:    if (!srch || srch.closed || srchmode!=mode) {
  708:       srchopen(mode);
  709:    }
  710:    srch.focus();
  711: }
  712: 
  713: // -------------------------------------------------------- Do idx status check
  714: function idxcheck(mode) {
  715:    if (!idx || idx.closed || idxmode!=mode) {
  716:       idxopen(mode);
  717:    }
  718:    idx.focus();
  719: }
  720: 
  721: 
  722:     var editbrowser;
  723:     function openbrowser(formname,elementname,only,omit) {
  724:         var url = '$resurl/?';
  725:         if (editbrowser == null) {
  726:             url += 'launch=1&';
  727:         }
  728:         url += 'catalogmode=interactive&';
  729:         url += 'mode=edit&';
  730:         url += 'form=' + formname + '&';
  731:         if (only != null) {
  732:             url += 'only=' + only + '&';
  733:         } 
  734:         if (omit != null) {
  735:             url += 'omit=' + omit + '&';
  736:         }
  737:         url += 'element=' + elementname + '';
  738:         var title = 'Browser';
  739:         var options = 'scrollbars=1,resizable=1,menubar=0';
  740:         options += ',width=700,height=600';
  741:         editbrowser = open(url,title,options,'1');
  742:         editbrowser.focus();
  743:     }
  744: ENDSCRIPT
  745: }
  746: # ------------------------------------------------------- Simple edit processor
  747: 
  748: sub smpedt {
  749:    my ($r,$url,$errtext)=@_;
  750:    my $buttons=&buttons(2);
  751:    my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
  752:    my $targetmsg='';
  753:    if ($env{'form.save'}) {
  754:        copy($tmpfn,&Apache::lonnet::filelocation('',$url));
  755:        unlink($tmpfn);
  756:        my ($errtext,$fatal)=
  757:                            &mapread(&Apache::lonnet::filelocation('',$url),'');
  758:        unless ($fatal) {
  759: 	   $targetmsg='<b>'.&mt('Saved.').'</b><br />';
  760:        } else {
  761: 	   $targetmsg='<b>'.&mt('An error occured while saving.').'</b><br />';
  762:        }
  763:    }
  764:    if ($env{'form.revert'}) {
  765:        $targetmsg='<b>'.&mt('Reverted.').'</b><br />';
  766:        unlink($tmpfn);
  767:        my ($errtext,$fatal)=
  768:                            &mapread(&Apache::lonnet::filelocation('',$url),'');
  769:    }
  770:    if (-e $tmpfn) {
  771:       $targetmsg=
  772:         '<b><font color="red">'.&mt('You are working with an unsaved version of your map.').'</font></b><br>';
  773:       my ($errtext,$fatal)=&mapread($tmpfn,'');
  774:    }
  775: # ---------------------------------------------------------- Process form input
  776: 
  777:    my @importselect=&Apache::loncommon::get_env_multiple('form.importsel');
  778:    my @targetselect=&Apache::loncommon::get_env_multiple('form.target');
  779: # ============================================================ Process commands
  780: 
  781:    my $targetdetail=$env{'form.targetdetail'};
  782:    my $importdetail=$env{'form.curimpdetail'};
  783: 
  784: # ---------------------------------------------------- Importing from groupsort
  785:    if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
  786: 
  787:        $importdetail='';
  788:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
  789: 
  790:        my $lastsel;
  791: 
  792:        if (defined($importselect[-1])) {
  793: 	   $lastsel=$importselect[-1];
  794:        } else {
  795:            $lastsel=$#curimport;
  796:        }
  797: 
  798:        for (my $i=0;$i<=$lastsel;$i++) {
  799:            my ($name,$url)=split(/\=/,$curimport[$i]);
  800:            if ($url) {
  801:               $importdetail.='&'.$name.'='.$url;
  802: 	   }
  803:        }
  804: 
  805:       $importdetail.='&'.$env{'form.importdetail'};
  806: 
  807:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
  808:            my ($name,$url)=split(/\=/,$curimport[$i]);
  809:            if ($url) {
  810:               $importdetail.='&'.$name.'='.$url;
  811: 	  }
  812:        }
  813:        $importdetail=~s/\&+/\&/g;
  814:        $importdetail=~s/^\&//;
  815: 
  816: # ------------------------------------------------------------------- Clear all
  817:    } elsif ($env{'form.clear'}) {
  818:        $importdetail='';
  819: # ------------------------------------------------------------ Discard selected
  820:    } elsif ($env{'form.discard'}) {
  821:        $importdetail='';
  822:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
  823:        foreach (@importselect) {
  824: 	   $curimport[$_]='';
  825:        }
  826:        for (my $i=0;$i<=$#curimport;$i++) {
  827:            my ($name,$url)=split(/\=/,$curimport[$i]);
  828:            if ($url) {
  829:               $importdetail.='&'.$name.'='.$url;
  830: 	   }
  831:        }
  832: # --------------------------------------------------------- Loading another map
  833:    } elsif ($env{'form.loadmap'}) {
  834:        $importdetail='';
  835:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
  836: 
  837:        my $lastsel;
  838: 
  839:        if (defined($importselect[-1])) {
  840: 	   $lastsel=$importselect[-1];
  841:        } else {
  842:            $lastsel=$#curimport;
  843:        }
  844: 
  845:        for (my $i=0;$i<=$lastsel;$i++) {
  846:            my ($name,$url)=split(/\=/,$curimport[$i]);
  847:            if ($url) {
  848:               $importdetail.='&'.$name.'='.$url;
  849: 	   }
  850:        }
  851: 
  852:        foreach (
  853:     &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
  854: 	   my ($name,$url)=split(/\:/,$_);
  855:            if ($url) {
  856:               $importdetail.='&'.&Apache::lonnet::escape($name).'='.
  857: 		 	         &Apache::lonnet::escape($url);
  858: 	  }
  859:        }
  860: 
  861:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
  862:            my ($name,$url)=split(/\=/,$curimport[$i]);
  863:            if ($url) {
  864:               $importdetail.='&'.$name.'='.$url;
  865: 	  }
  866:        }
  867:        $importdetail=~s/\&+/\&/g;
  868:        $importdetail=~s/^\&//;
  869: 
  870: # ------------------------------------------------ Groupimport/search to target
  871:    } elsif ($env{'form.importdetail'}) {
  872:        my $lastsel;
  873:        if (defined($targetselect[-1])) {
  874: 	   $lastsel=$targetselect[-1];
  875:        } else {
  876:            $lastsel=$#order+1;
  877:        }
  878:        &pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
  879:        &storemap(&Apache::lonnet::filelocation('',$url));
  880: # ------------------------------------------------------------------------- Cut
  881:    } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
  882:        $importdetail='';
  883:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
  884: 
  885:        my $lastsel;
  886: 
  887:        if (defined($importselect[-1])) {
  888: 	   $lastsel=$importselect[-1];
  889:        } else {
  890:            $lastsel=$#curimport;
  891:        }
  892: 
  893:        for (my $i=0;$i<=$lastsel;$i++) {
  894:            my ($name,$url)=split(/\=/,$curimport[$i]);
  895:            if ($url) {
  896:               $importdetail.='&'.$name.'='.$url;
  897: 	   }
  898:        }
  899: 
  900:        foreach (@targetselect) {
  901: 	   my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
  902:            if ($url) {
  903:               $importdetail.='&'.&Apache::lonnet::escape($name).'='.
  904: 		 	         &Apache::lonnet::escape($url);
  905: 	  }
  906:        }
  907: 
  908:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
  909:            my ($name,$url)=split(/\=/,$curimport[$i]);
  910:            if ($url) {
  911:               $importdetail.='&'.$name.'='.$url;
  912: 	  }
  913:        }
  914:        $importdetail=~s/\&+/\&/g;
  915:        $importdetail=~s/^\&//;
  916: 
  917:        if ($env{'form.cut'}) {
  918:            my @neworder=();
  919:            for (my $i=0;$i<=$#order;$i++) {
  920:                my $include=1;
  921:                foreach (@targetselect) {
  922: 		   if ($_-1==$i) { $include=0; }
  923:                }
  924:                if ($include) { 
  925: 		   $neworder[$#neworder+1]=$order[$i]; 
  926: 	       } else {
  927: 		   &makezombie($order[$i]);
  928: 	       }
  929:            }
  930:            @order=@neworder;
  931:            &storemap(&Apache::lonnet::filelocation('',$url));      
  932:        }
  933: 
  934: # ----------------------------------------------------------------------- Paste
  935:    } elsif ($env{'form.paste'}) {
  936:        my $lastsel;
  937:        if (defined($targetselect[-1])) {
  938: 	   $lastsel=$targetselect[-1];
  939:        } else {
  940:            $lastsel=$#order+1;
  941:        }
  942:        my @newsequence;
  943:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
  944:        foreach (@importselect) {
  945:           $newsequence[$#newsequence+1]=$curimport[$_];
  946:        }
  947:        &pastetarget($lastsel,@newsequence);
  948:        &storemap(&Apache::lonnet::filelocation('',$url));
  949: # -------------------------------------------------------------------- Move up 
  950:    } elsif ($env{'form.moveup'}) {
  951:        foreach (sort @targetselect) {
  952:            if ($_-1>0) {
  953:               my $movethis=$order[$_-1];
  954:               $order[$_-1]=$order[$_-2];
  955:               $order[$_-2]=$movethis;
  956: 	  }
  957:        }
  958:        &storemap(&Apache::lonnet::filelocation('',$url));
  959: # ------------------------------------------------------------------ Move down
  960:    } elsif ($env{'form.movedown'}) {
  961:        foreach (reverse sort @targetselect) {
  962:            if ($_-1<$#order) {
  963:               my $movethis=$order[$_-1];
  964:               $order[$_-1]=$order[$_];
  965:               $order[$_]=$movethis;
  966: 	   }
  967:        }
  968:        &storemap(&Apache::lonnet::filelocation('',$url));
  969: # --------------------------------------------------------------------- Rename
  970:    } elsif ($env{'form.renameres'}) {
  971:        my $residx=$Apache::lonratedt::order[$env{'form.renameidx'}-1];
  972:        my ($name,@resrest)=split(/\:/,$Apache::lonratedt::resources[$residx]);
  973:        $name=$env{'form.renametitle'};
  974:        $name=~s/\:/\&colon\;/g;
  975:        $Apache::lonratedt::resources[$residx]=$name.':'.join(':',@resrest);
  976:        &storemap(&Apache::lonnet::filelocation('',$url));
  977:    }
  978: # ------------------------------------------------------------ Assemble windows
  979:    
  980:    my $idx=-1;
  981:    $importdetail='&'.$importdetail;
  982:    $importdetail=~s/^\&+/\&/;
  983:    my $importwindow=
  984:        '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
  985:      join("\n",map {
  986:        $idx++;
  987:        if ($_) { 
  988:           my ($name,$url)=split(/\=/,$_);
  989:           unless ($name) { $name=(split(/\//,$url))[-1]; }
  990:           unless ($name) { $name='EMPTY'; }
  991:           '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
  992:                                     '</option>';
  993:       }
  994:    } split(/\&/,$importdetail));
  995: 
  996:    $idx=0;
  997:    $targetdetail='';
  998:    my $targetwindow=       
  999:        '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
 1000:      join("\n",map { 
 1001:        my ($name,$url)=split(/\:/,$resources[$_]);
 1002:        unless ($name) {  $name=(split(/\//,$url))[-1]; }
 1003:        unless ($name) { $name='EMPTY'; }
 1004:        $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
 1005: 	                  &Apache::lonnet::escape($url);
 1006:        $idx++;
 1007:        $name=~s/\&colon;/\:/g;
 1008:        '<option value="'.$idx.'">'.$name.'</option>';
 1009:    } @order);
 1010: 
 1011: # ----------------------------------------------------- Start simple RAT screen
 1012:    my $editscript=&editscript('simple');
 1013:    my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,
 1014: 					($env{'environment.remote'} ne 'off')).
 1015:        &Apache::loncommon::help_open_menu('','Sequence_Simple_Editor_Creation','Sequence_Simple_Editor_Creation','',6,'RAT');
 1016:    my %lt=&Apache::lonlocal::texthash(
 1017: 				      'sa' => 'Save',
 1018: 				      'nt' => 'New Title',
 1019: 				      'se' => 'Search',
 1020: 				      'im' => 'Import',
 1021: 				      'vi' => 'View',
 1022: 				      'lm' => 'Load Map',
 1023: 				      'ds' => 'Discard Selected',
 1024: 				      'ca' => 'Clear All',
 1025: 				      'ta' => 'Temporary Assembly Workspace',
 1026: 				      'rv' => 'Revert to Last Saved',
 1027:                                       'sa' => 'Save',
 1028:                                       'mu' => 'Move Up',
 1029:                                       'md' => 'Move Down',
 1030:                                       're' => 'Rename',
 1031:                                       'as' => 'after selected',
 1032:                                       'cs' => 'Cut selected',
 1033:                                       'ps' => 'Copy selected',
 1034:                                       'pas' => 'Paste after selected',
 1035: 				      );
 1036:    $r->print(<<ENDSMPHEAD);
 1037: <html>
 1038: <head>
 1039: <script>
 1040: 
 1041:    $editscript
 1042: 
 1043:    function openview(entry) {
 1044:        var url=unescape((entry.split('='))[1]);
 1045:        var parts=new Array;
 1046:        parts=url.split('&colon;');
 1047:        url=parts.join(':');
 1048:        if (url) { open(url,'cat'); }
 1049:    }
 1050: 
 1051:    function viewtarget() {
 1052:        openview((document.forms.simpleedit.targetdetail.value.split('&'))
 1053:                 [document.forms.simpleedit.target.selectedIndex]);
 1054:    }
 1055: 
 1056:    function viewimport() {
 1057:        openview((document.forms.simpleedit.curimpdetail.value.split('&'))
 1058:                 [document.forms.simpleedit.importsel.selectedIndex]);
 1059:    }
 1060: 
 1061:    function renametarget() {
 1062:        var selidx=document.forms.simpleedit.target.selectedIndex;
 1063:        var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
 1064:                 [selidx];
 1065:        var oldname=unescape((entry.split('='))[0]);
 1066:        var nameparts=oldname.split('&colon;');
 1067:        oldname=unescape(nameparts.join(':'));
 1068:        nameparts=oldname.split('&#34;');
 1069:        oldname=unescape(nameparts.join('"'));
 1070:        nameparts=oldname.split('&#39;');
 1071:        oldname=unescape(nameparts.join("'"));
 1072:        newtitle=prompt('$lt{'nt'}',oldname);
 1073:        if (newtitle) {
 1074:            document.forms.simpleedit.renameres.value=1;
 1075:            document.forms.simpleedit.renameidx.value=selidx;
 1076:            document.forms.simpleedit.renametitle.value=newtitle;
 1077: 	   document.forms.simpleedit.submit();
 1078:        }
 1079:    }
 1080: 
 1081: </script>
 1082: </head>                 
 1083: $bodytag
 1084: $buttons
 1085: <font color=red>$errtext</font>
 1086: <form name=simpleedit method=post>
 1087: <input type=hidden name=forcesmp value=1>
 1088: <input type=hidden name=renameres value=0>
 1089: <input type=hidden name=renametitle value=''>
 1090: <input type=hidden name=renameidx value=0>
 1091: <table>
 1092:     <tr><th width="40%">$lt{'ta'}</th>
 1093: <th>&nbsp;</th>
 1094: <th width="40%">File: $url</th></tr>
 1095: <tr><td bgcolor="#FFFFCC">
 1096: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
 1097: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
 1098: $lt{'as'}
 1099: <hr>
 1100: <input type=text size=20 name=importmap>
 1101: <input type=button 
 1102: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
 1103: value="Select Map"><input type=submit name=loadmap value="$lt{'lm'}"><hr>
 1104: <input type=submit name="discard" value="$lt{'ds'}">
 1105: <input type=submit name="clear" value="$lt{'ca'}">
 1106: <input type=button onClick="javascript:viewimport()" value="$lt{'vi'}">
 1107: 
 1108:     </td><td>&nbsp;</td><td bgcolor="#FFFFCC">
 1109: 
 1110: <input type=button onClick=
 1111: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
 1112: <input type=button onClick=
 1113: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
 1114: $lt{'as'}
 1115: <hr>
 1116: <input type=submit name="moveup" value="$lt{'mu'}">
 1117: <input type=submit name="movedown" value="$lt{'md'}">
 1118: <input type=button onClick="javascript:renametarget()" value="$lt{'re'}">
 1119: <hr>$targetmsg
 1120: <input type=submit name="revert" value="$lt{'rv'}">
 1121: <input type=submit name="save" value="$lt{'sa'}">
 1122: <input type=button onClick="javascript:viewtarget()" value="$lt{'vi'}">
 1123: </td></tr>
 1124: 
 1125: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
 1126: $importwindow
 1127: </select>
 1128: </td>
 1129: <td bgcolor="#FFFFAA" align="center">
 1130: $lt{'cs'}<br>
 1131: <input type=submit name=cut value='<<<'><p>
 1132: <hr>
 1133: $lt{'ps'}<br>
 1134: <input type=submit name=copy value='<--'><p>
 1135: <hr>
 1136: $lt{'pas'}<br>
 1137: <input type=submit name=paste value='-->'>
 1138: </td>
 1139: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
 1140: $targetwindow
 1141: </select>
 1142: </table>
 1143: <input type=hidden name=importdetail value="">
 1144: <input type=hidden name=curimpdetail value="$importdetail">
 1145: <input type=hidden name=targetdetail value="$targetdetail">
 1146: <input type=hidden name=impfortarget value="0">
 1147: </form>
 1148: </body></html>
 1149: ENDSMPHEAD
 1150: }
 1151: 
 1152: # ----------------------------------------------------------------- No such dir
 1153: sub nodir {
 1154:    my ($r,$dir)=@_;
 1155:    $dir=~s/^\/home\/\w+\/public\_html//;
 1156:    $r->print(<<ENDNODIR);
 1157: <html>
 1158: <body bgcolor='#FFFFFF'>
 1159: <h1>No such directory: $dir</h1>
 1160: </body>
 1161: </html>
 1162: ENDNODIR
 1163: }
 1164: 
 1165: # ---------------------------------------------------------------- View Handler
 1166: 
 1167: sub viewmap {
 1168:     my ($r,$url,$adv,$errtext)=@_;
 1169:     $r->print('<html>'.
 1170:      &Apache::loncommon::bodytag('Edit Content of a Map').
 1171: 	      &Apache::loncommon::help_open_menu('','','','',6,'RAT').
 1172: 	      &buttons($adv));
 1173:     if ($errtext) {
 1174: 	$r->print($errtext.'<hr />');
 1175:     }
 1176:     my $idx=0;
 1177:     $r->print('<h1>'.$url.'</h1>');
 1178:     if ($adv) {
 1179: 	$r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
 1180:     }
 1181:     $r->print( '<table border="0" cellspacing="2" cellpadding="4">'.
 1182:                '<tr bgcolor="#DDDDDD"><th>'.&mt('Type').'</th>'.
 1183:                '<th>'.&mt('Title in map').'</th>'.
 1184:                '<th>'.&mt('Filename of resource').'</th>'.
 1185:                '<th>'.&mt('Link to published resource').'</th>'.
 1186:                '<th>'.&mt('Link to resource in Construction Space').'</th>'.
 1187:                '</tr>');
 1188:     my @backgroundColors = ("#FFFFFF", "#F6F6F6");
 1189:     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
 1190: 	if (defined($_)) {
 1191:             $idx++;
 1192: 	    my ($title,$url,$cond)=split(/\:/,$_);
 1193: 	    if ($cond eq 'cond') { next; }
 1194:             $title=~s/\&colon\;/\:/g;
 1195:             $url=~s/\&colon\;/\:/g;
 1196:             unless ($title) { $title=(split(/\//,$url))[-1] };
 1197:             unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
 1198:             my $resurl = &Apache::lonratsrv::qtescape($url);
 1199:             my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
 1200:             my $filename; 
 1201:             if ($resurl =~ m#/([^/]+)$#) {
 1202:                 $filename = $1;
 1203:             }
 1204:             my $cstrurl = $resurl;
 1205:             $cstrurl =~ s#^/res/[^/]+/([^/]+)/#/priv/$1/#;
 1206:             my $bgcol = $idx%2; 
 1207:             $r->print('<tr bgcolor='.$backgroundColors[$bgcol].'><td>'.
 1208:                       '<img src="'.&Apache::loncommon::icon($resfilepath).
 1209:                       '" /></td><td>'.&Apache::lonratsrv::qtescape($title).
 1210:                       '</td><td>'.$filename.'</td><td>');
 1211:             if ($url) {
 1212: 		$r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
 1213:             }
 1214:             $r->print('</td><td>');
 1215:             if ($url) {
 1216:                $r->print('<a href="'.$cstrurl.'">'.
 1217:                          &mt('Construction space').'</a>');
 1218:             }
 1219:             $r->print('</td></tr>'."\n");
 1220:         }
 1221:     }
 1222:     $r->print('</table>');
 1223:     $r->print('</body></html>');
 1224: }
 1225: 
 1226: # ================================================================ Main Handler
 1227: 
 1228: sub handler {
 1229:   my $r=shift;
 1230:   &Apache::loncommon::content_type($r,'text/html');
 1231:   $r->send_http_header;
 1232: 
 1233:   return OK if $r->header_only;
 1234:   my $target = $env{'form.grade_target'};
 1235:   if ($target eq 'meta') {
 1236:       &Apache::loncommon::content_type($r,'text/html');
 1237:       $r->send_http_header;
 1238:       return OK;
 1239:   }
 1240:   
 1241:   my $url=$r->uri;
 1242:   my $fn=&Apache::lonnet::filelocation('',$url);
 1243: 
 1244:   my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
 1245:   unless (-e $dir) {
 1246:       &nodir($r,$dir);
 1247:       return OK;
 1248:   }
 1249: 
 1250: # ------------------------------------------- Determine which tools can be used
 1251:   my $adv=0;
 1252: 
 1253:   unless ($env{'form.forcesmp'}) {
 1254:      if ($env{'form.forceadv'}) {
 1255:         $adv=1;
 1256:      } elsif (my $fh=Apache::File->new($fn)) {
 1257: 	 my $allmap=join('',<$fh>);
 1258:          $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
 1259:      }
 1260:   }
 1261: 
 1262:   my $errtext='';
 1263:   my $fatal=0;
 1264: 
 1265: # -------------------------------------------------------------------- Load map
 1266:   ($errtext,$fatal)=&mapread($fn,$errtext);
 1267: 
 1268:   if ($fatal==1) { $adv=1; }
 1269: 
 1270: # ----------------------------------- adv==1 now means "graphical MUST be used"
 1271: 
 1272:   if ($env{'form.forceadv'}) {
 1273:       &ratedt($r,$url);
 1274:   } elsif ($env{'form.forcesmp'}) {
 1275:       &smpedt($r,$url,$errtext);
 1276:   } else {
 1277:       &viewmap($r,$url,$adv,$errtext);
 1278:   }
 1279:   return OK;
 1280: }
 1281: 
 1282: 1;
 1283: __END__
 1284: 
 1285: 
 1286: 
 1287: 
 1288: 
 1289: 
 1290: 

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