File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.81: download - view: text, annotated - select for diffs
Mon Jun 26 22:47:35 2006 UTC (17 years, 10 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_99_0, HEAD
- help_open_men changes
- also adding the location bar into res space browsing of simple rat

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

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