File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.77: download - view: text, annotated - select for diffs
Tue May 23 18:31:13 2006 UTC (17 years, 11 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- typo

    1: # The LearningOnline Network with CAPA
    2: # Edit Handler for RAT Maps
    3: #
    4: # $Id: lonratedt.pm,v 1.77 2006/05/23 18:31:13 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: 
  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 %layout = ('border' => "0");
  409:     if ($env{'environment.remote'} eq 'off') {
  410:       $layout{'rows'} = "1,250,*";
  411:   } else {
  412:       $layout{'rows'} = "1,70,*";
  413:   }
  414:   my $js ='
  415: <script type="text/javascript">
  416:     var flag=0;
  417: </script>';
  418: 
  419:   my $start_page = 
  420:       &Apache::loncommon::start_page('Edit Sequence',$js,
  421: 				     {'frameset'    => 1,
  422: 				      'add_entries' => \%layout});
  423:   my $end_page = 
  424:       &Apache::loncommon::end_page({'frameset' => 1});
  425: 
  426:   $r->print(<<ENDDOCUMENT);
  427: $start_page
  428: <frame name="server" src="$url/loadonly/ratserver" noresize="noresize"
  429:        noscroll="noscroll" />
  430: <frame name="code" src="$url/loadonly/adveditmenu" />
  431: <frame name="mapout" src="/adm/rat/map.html" />
  432: $end_page
  433: ENDDOCUMENT
  434: }
  435: 
  436: # ---------------------------------------------------------------- Make buttons
  437: 
  438: sub buttons {
  439:     my $adv=shift;
  440:     my $output='<form method=post>';     
  441:     if ($adv==1) {
  442: 	$output.='<input type=submit name=forceadv value="'.&mt('Edit').'">'.
  443: 	    &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');;
  444:     } else {
  445:         unless ($adv==2) {
  446:            $output.='<input type=submit name=forcesmp value="'.&mt('Simple Edit').'">'.
  447: 	    &Apache::loncommon::help_open_topic('Sequence_Simple_Editor_Creation');
  448:         }
  449: 	$output.='<input type=submit name=forceadv value="'.&mt('Advanced Edit').'">'.
  450: 	    &Apache::loncommon::help_open_topic('Sequence_Advanced_Editor_Creation');
  451:     }
  452:     return $output.'</form><hr>';
  453: }
  454: 
  455: # ------------------------------------- Revive zombie idx or get unused number
  456: 
  457: sub getresidx {
  458:     my $url=shift;
  459:     my $max=1+($#resources>$#zombies?$#resources:$#zombies);
  460:     unless ($url) { return $max; }
  461:     for (my $i=0; $i<=$#zombies; $i++) {
  462: 	my ($title,$src,$ext,$type)=split(/\:/,$zombies[$i]);
  463: 	if ($src eq $url) {
  464: 	    undef $zombies[$i];
  465: 	    return $i;
  466: 	}
  467:     }
  468:     return $max;
  469: }
  470: 
  471: # --------------------------------------------------------------- Make a zombie
  472: 
  473: sub makezombie {
  474:     my $idx=shift;
  475:     my ($name,$url,$ext)=split(/\:/,$resources[$idx]);
  476:     my $now=time;
  477:     $zombies[$idx]=$name.
  478: 	' [('.$now.','.$env{'user.name'}.','.$env{'user.domain'}.')]:'.
  479: 	$url.':'.$ext.':zombie';
  480: }
  481: 
  482: # ----------------------------------------------------------- Paste into target
  483: # modifies @order, @resources
  484: 
  485: sub pastetarget {
  486:     my ($after,@which)=@_;
  487:     my @insertorder=();
  488:     foreach (@which) {
  489:         if (defined($_)) {
  490: 	    my ($name,$url)=split(/\=/,$_);
  491:             $name=&Apache::lonnet::unescape($name);
  492:             $url=&Apache::lonnet::unescape($url);
  493:             if ($url) {
  494: 	       my $idx=&getresidx($url);
  495:                $insertorder[$#insertorder+1]=$idx;
  496:                my $ext='false';
  497:                if ($url=~/^http\:\/\//) { $ext='true'; }
  498:                $url=~s/\:/\&colon;/g;
  499:                $name=~s/\:/\&colon;/g;
  500:                $resources[$idx]=$name.':'.$url.':'.$ext.':normal:res';
  501: 	   }
  502:         }
  503:     }
  504:     my @oldorder=splice(@order,$after);
  505:     @order=(@order,@insertorder,@oldorder);
  506: }
  507: 
  508: # ------------------------------------------------ Get start and finish correct
  509: # modifies @resources
  510: 
  511: sub startfinish {
  512: # Remove all start and finish
  513:     foreach (@order) {
  514: 	my ($name,$url,$ext)=split(/\:/,$resources[$_]);
  515:         if ($url=~/http\&colon\:\/\//) { $ext='true'; }
  516:         $resources[$_]=$name.':'.$url.':'.$ext.':normal:res';
  517:     }
  518: # Garbage collection
  519:     my $stillchange=1;
  520:      while (($#order>1) && ($stillchange)) {
  521:        $stillchange=0;
  522:        for (my $i=0;$i<=$#order;$i++) {
  523:  	  my ($name,$url,$ext)=split(/\:/,$resources[$order[$i]]);
  524:           unless ($url) {
  525: # Take out empty resource
  526:               for (my $j=$i+1;$j<=$#order;$j++) {
  527:                   $order[$j-1]=$order[$j];
  528: 	      }
  529:               $#order--;
  530: 	      $stillchange=1;
  531:               last;
  532:           }
  533:        }
  534:     }
  535: # Put in a start resource
  536:    my ($name,$url,$ext)=split(/\:/,$resources[$order[0]]);
  537:    $resources[$order[0]]=$name.':'.$url.':'.$ext.':start:res';
  538: # Make sure this has at least start and finish
  539:    if ($#order==0) {
  540:        $resources[&getresidx()]='::false';
  541:        $order[1]=$#resources;
  542:    }
  543: # Make the last one a finish resource
  544:    ($name,$url,$ext)=split(/\:/,$resources[$order[$#order]]);
  545:    $resources[$order[$#order]]=$name.':'.$url.':'.$ext.':finish:res';
  546: }
  547: 
  548: # ------------------------------------------------------------------- Store map
  549: 
  550: sub storemap {
  551:     my $realfn=shift;
  552:     my $fn=$realfn;
  553: # unless this is forced to work from the original file, use a temporary file
  554: # instead
  555:     unless (shift) {
  556:        $fn=$realfn.'.tmp';
  557:        unless (-e $fn) {
  558: 	  copy($realfn,$fn);
  559:        }
  560:     }
  561: # store data either into tmp or real file
  562:     &startfinish();
  563:     my $output='graphdef<:>no';
  564:     my $k=1;
  565:     for (my $i=0; $i<=$#order; $i++) {
  566:         if (defined($resources[$order[$i]])) {
  567: 	    $output.='<&>objcont<:>'.$order[$i].'<:>'.$resources[$order[$i]];
  568:         }
  569: 	if (defined($resparms[$order[$i]])) {
  570: 	    foreach (split('&&&',$resparms[$order[$i]])) {
  571: 		if ($_) {
  572: 		    $output.='<&>objparms<:>'.$order[$i].'<:>'.$_;
  573: 		}
  574: 	    }
  575: 	}
  576:         if (defined($order[$i+1])) {
  577: 	    if (defined($resources[$order[$i+1]])) {
  578:                $output.='<&>objlinks<:>'.$k.'<:>'.
  579: 		   $order[$i].':'.$order[$i+1].':0';
  580: 	       $k++;
  581:             }
  582:         }
  583:     }
  584:     for (my $i=0; $i<=$#zombies; $i++) {
  585:         if (defined($zombies[$i])) {
  586: 	    $output.='<&>objcont<:>'.$i.'<:>'.$zombies[$i];
  587:         }
  588:     }
  589:     $output=~s/http\&colon\;\/\///g;
  590:     $env{'form.output'}=$output;
  591:     return 
  592:      &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));
  593: }
  594: 
  595: # ------------------------------------------ Store and get parameters in global
  596: 
  597: sub storeparameter {
  598:     my ($to,$name,$value,$ptype)=@_;
  599:     my $newentry='';
  600:     my $nametype='';
  601:     foreach (split('&&&',$resparms[$to])) {
  602: 	my ($thistype,$thisname,$thisvalue)=split('___',$_);
  603: 	if ($thisname) {
  604: 	    unless ($thisname eq $name) {
  605: 		$newentry.=$_.'&&&';
  606: 	    } else {
  607: 		$nametype=$thistype;
  608: 	    }
  609: 	}
  610:     }
  611:     unless ($ptype) { $ptype=$nametype; }
  612:     unless ($ptype) { $ptype='string'; }
  613:     $newentry.=$ptype.'___'.$name.'___'.$value;
  614:     $resparms[$to]=$newentry;
  615: }
  616: 
  617: sub delparameter {
  618:     my ($to,$name)=@_;
  619:     my $newentry='';
  620:     my $nametype='';
  621:     foreach (split('&&&',$resparms[$to])) {
  622: 	my ($thistype,$thisname,$thisvalue)=split('___',$_);
  623: 	if ($thisname) {
  624: 	    unless ($thisname eq $name) {
  625: 		$newentry.=$_.'&&&';
  626: 	    }
  627: 	}
  628:     }
  629:     $resparms[$to]=$newentry;
  630: }
  631: 
  632: sub getparameter {
  633:     my ($to,$name)=@_;
  634:     my $value=undef;
  635:     my $ptype=undef;
  636:     foreach (split('&&&',$resparms[$to])) {
  637: 	my ($thistype,$thisname,$thisvalue)=split('___',$_);
  638: 	if ($thisname eq $name) {
  639: 	    $value=$thisvalue;
  640: 	    $ptype=$thistype;
  641: 	}
  642:     }
  643:     return ($value,$ptype);
  644: }
  645: 
  646: # ----------------------------------------------------------------- Edit script
  647: sub editscript {
  648:     my $mode=shift;
  649:     my $resurl=&Apache::loncommon::lastresurl();
  650:     return(<<ENDSCRIPT);
  651: var srch;
  652: var srchflag=-1; // 1 means currently open
  653:                  // 0 means closed (but has been open)
  654:                  // -1 means never yet opened/defined
  655: var srchmode='';
  656: 
  657: var idx;
  658: var idxflag=-1; // 1 means currently open
  659:                  // 0 means closed (but has been open)
  660:                  // -1 means never yet opened/defined
  661: var idxmode='';
  662: 
  663: // ------------------------------------------------------ Clears indexer window
  664: function idxclear() {
  665:   idx.document.clear();
  666: }
  667: 
  668: // ------------------------------------------------------- Clears search window
  669: function srchclear() {
  670:   srch.document.clear();
  671: }
  672: 
  673: // ------------------------------------------------------ Closes indexer window
  674: function idxclose() {
  675:   if (idx && !idx.closed) {
  676:     idxflag=0;
  677:     idx.close();
  678:   }
  679: }
  680: 
  681: // ------------------------------------------------------- Closes search window
  682: function srchclose() {
  683:   if (srch && !srch.closed) {
  684:     srchflag=0;
  685:     srch.close();
  686:   }
  687: }
  688: 
  689: // -------------------------------------------------------- Open indexer window
  690: function idxopen(mode) {
  691:    var options="scrollbars=1,resizable=1,menubar=0";
  692:    idxmode=mode;
  693:    idxflag=1;
  694:    idx=open("$resurl/?launch=1&mode=$mode&catalogmode="+mode,"idxout",options);
  695:    idx.focus();
  696: }
  697: 
  698: // ------------------------------------------------------ Open groupsort window
  699: function groupopen(url,recover) {
  700:    var options="scrollbars=1,resizable=1,menubar=0";
  701:    idxflag=1;
  702:    idx=open("/adm/groupsort?mode=$mode&recover="+recover+"&readfile="+url,"idxout",options);
  703:    idx.focus();
  704: }
  705: 
  706: // --------------------------------------------------------- Open search window
  707: function srchopen(mode) {
  708:    var options="scrollbars=1,resizable=1,menubar=0";
  709:    srchmode=mode;
  710:    srchflag=1;
  711:    srch=open("/adm/searchcat?launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
  712:    srch.focus();
  713: }
  714: // ----------------------------------------------------- launch indexer browser
  715: function groupsearch() {
  716:    srchcheck('groupsearch');
  717: }
  718: 
  719: function groupimport() {
  720:    idxcheck('groupimport');
  721: }
  722: 
  723: // ------------------------------------------------------- Do srch status check
  724: function srchcheck(mode) {
  725:    if (!srch || srch.closed || srchmode!=mode) {
  726:       srchopen(mode);
  727:    }
  728:    srch.focus();
  729: }
  730: 
  731: // -------------------------------------------------------- Do idx status check
  732: function idxcheck(mode) {
  733:    if (!idx || idx.closed || idxmode!=mode) {
  734:       idxopen(mode);
  735:    }
  736:    idx.focus();
  737: }
  738: 
  739: 
  740:     var editbrowser;
  741:     function openbrowser(formname,elementname,only,omit) {
  742:         var url = '$resurl/?';
  743:         if (editbrowser == null) {
  744:             url += 'launch=1&';
  745:         }
  746:         url += 'catalogmode=interactive&';
  747:         url += 'mode=edit&';
  748:         url += 'form=' + formname + '&';
  749:         if (only != null) {
  750:             url += 'only=' + only + '&';
  751:         } 
  752:         if (omit != null) {
  753:             url += 'omit=' + omit + '&';
  754:         }
  755:         url += 'element=' + elementname + '';
  756:         var title = 'Browser';
  757:         var options = 'scrollbars=1,resizable=1,menubar=0';
  758:         options += ',width=700,height=600';
  759:         editbrowser = open(url,title,options,'1');
  760:         editbrowser.focus();
  761:     }
  762: ENDSCRIPT
  763: }
  764: # ------------------------------------------------------- Simple edit processor
  765: 
  766: sub smpedt {
  767:    my ($r,$url,$errtext)=@_;
  768:    my $buttons=&buttons(2);
  769:    my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
  770:    my $targetmsg='';
  771:    if ($env{'form.save'}) {
  772:        copy($tmpfn,&Apache::lonnet::filelocation('',$url));
  773:        unlink($tmpfn);
  774:        my ($errtext,$fatal)=
  775:                            &mapread(&Apache::lonnet::filelocation('',$url),'');
  776:        unless ($fatal) {
  777: 	   $targetmsg='<b>'.&mt('Saved.').'</b><br />';
  778:        } else {
  779: 	   $targetmsg='<b>'.&mt('An error occured while saving.').'</b><br />';
  780:        }
  781:    }
  782:    if ($env{'form.revert'}) {
  783:        $targetmsg='<b>'.&mt('Reverted.').'</b><br />';
  784:        unlink($tmpfn);
  785:        my ($errtext,$fatal)=
  786:                            &mapread(&Apache::lonnet::filelocation('',$url),'');
  787:    }
  788:    if (-e $tmpfn) {
  789:       $targetmsg=
  790:         '<b><font color="red">'.&mt('You are working with an unsaved version of your map.').'</font></b><br>';
  791:       my ($errtext,$fatal)=&mapread($tmpfn,'');
  792:    }
  793: # ---------------------------------------------------------- Process form input
  794: 
  795:    my @importselect=&Apache::loncommon::get_env_multiple('form.importsel');
  796:    my @targetselect=&Apache::loncommon::get_env_multiple('form.target');
  797: # ============================================================ Process commands
  798: 
  799:    my $targetdetail=$env{'form.targetdetail'};
  800:    my $importdetail=$env{'form.curimpdetail'};
  801: 
  802: # ---------------------------------------------------- Importing from groupsort
  803:    if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
  804: 
  805:        $importdetail='';
  806:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
  807: 
  808:        my $lastsel;
  809: 
  810:        if (defined($importselect[-1])) {
  811: 	   $lastsel=$importselect[-1];
  812:        } else {
  813:            $lastsel=$#curimport;
  814:        }
  815: 
  816:        for (my $i=0;$i<=$lastsel;$i++) {
  817:            my ($name,$url)=split(/\=/,$curimport[$i]);
  818:            if ($url) {
  819:               $importdetail.='&'.$name.'='.$url;
  820: 	   }
  821:        }
  822: 
  823:       $importdetail.='&'.$env{'form.importdetail'};
  824: 
  825:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
  826:            my ($name,$url)=split(/\=/,$curimport[$i]);
  827:            if ($url) {
  828:               $importdetail.='&'.$name.'='.$url;
  829: 	  }
  830:        }
  831:        $importdetail=~s/\&+/\&/g;
  832:        $importdetail=~s/^\&//;
  833: 
  834: # ------------------------------------------------------------------- Clear all
  835:    } elsif ($env{'form.clear'}) {
  836:        $importdetail='';
  837: # ------------------------------------------------------------ Discard selected
  838:    } elsif ($env{'form.discard'}) {
  839:        $importdetail='';
  840:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
  841:        foreach (@importselect) {
  842: 	   $curimport[$_]='';
  843:        }
  844:        for (my $i=0;$i<=$#curimport;$i++) {
  845:            my ($name,$url)=split(/\=/,$curimport[$i]);
  846:            if ($url) {
  847:               $importdetail.='&'.$name.'='.$url;
  848: 	   }
  849:        }
  850: # --------------------------------------------------------- Loading another map
  851:    } elsif ($env{'form.loadmap'}) {
  852:        $importdetail='';
  853:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
  854: 
  855:        my $lastsel;
  856: 
  857:        if (defined($importselect[-1])) {
  858: 	   $lastsel=$importselect[-1];
  859:        } else {
  860:            $lastsel=$#curimport;
  861:        }
  862: 
  863:        for (my $i=0;$i<=$lastsel;$i++) {
  864:            my ($name,$url)=split(/\=/,$curimport[$i]);
  865:            if ($url) {
  866:               $importdetail.='&'.$name.'='.$url;
  867: 	   }
  868:        }
  869: 
  870:        foreach (
  871:     &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
  872: 	   my ($name,$url)=split(/\:/,$_);
  873:            if ($url) {
  874:               $importdetail.='&'.&Apache::lonnet::escape($name).'='.
  875: 		 	         &Apache::lonnet::escape($url);
  876: 	  }
  877:        }
  878: 
  879:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
  880:            my ($name,$url)=split(/\=/,$curimport[$i]);
  881:            if ($url) {
  882:               $importdetail.='&'.$name.'='.$url;
  883: 	  }
  884:        }
  885:        $importdetail=~s/\&+/\&/g;
  886:        $importdetail=~s/^\&//;
  887: 
  888: # ------------------------------------------------ Groupimport/search to target
  889:    } elsif ($env{'form.importdetail'}) {
  890:        my $lastsel;
  891:        if (defined($targetselect[-1])) {
  892: 	   $lastsel=$targetselect[-1];
  893:        } else {
  894:            $lastsel=$#order+1;
  895:        }
  896:        &pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
  897:        &storemap(&Apache::lonnet::filelocation('',$url));
  898: # ------------------------------------------------------------------------- Cut
  899:    } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
  900:        $importdetail='';
  901:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
  902: 
  903:        my $lastsel;
  904: 
  905:        if (defined($importselect[-1])) {
  906: 	   $lastsel=$importselect[-1];
  907:        } else {
  908:            $lastsel=$#curimport;
  909:        }
  910: 
  911:        for (my $i=0;$i<=$lastsel;$i++) {
  912:            my ($name,$url)=split(/\=/,$curimport[$i]);
  913:            if ($url) {
  914:               $importdetail.='&'.$name.'='.$url;
  915: 	   }
  916:        }
  917: 
  918:        foreach (@targetselect) {
  919: 	   my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
  920:            if ($url) {
  921:               $importdetail.='&'.&Apache::lonnet::escape($name).'='.
  922: 		 	         &Apache::lonnet::escape($url);
  923: 	  }
  924:        }
  925: 
  926:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
  927:            my ($name,$url)=split(/\=/,$curimport[$i]);
  928:            if ($url) {
  929:               $importdetail.='&'.$name.'='.$url;
  930: 	  }
  931:        }
  932:        $importdetail=~s/\&+/\&/g;
  933:        $importdetail=~s/^\&//;
  934: 
  935:        if ($env{'form.cut'}) {
  936:            my @neworder=();
  937:            for (my $i=0;$i<=$#order;$i++) {
  938:                my $include=1;
  939:                foreach (@targetselect) {
  940: 		   if ($_-1==$i) { $include=0; }
  941:                }
  942:                if ($include) { 
  943: 		   $neworder[$#neworder+1]=$order[$i]; 
  944: 	       } else {
  945: 		   &makezombie($order[$i]);
  946: 	       }
  947:            }
  948:            @order=@neworder;
  949:            &storemap(&Apache::lonnet::filelocation('',$url));      
  950:        }
  951: 
  952: # ----------------------------------------------------------------------- Paste
  953:    } elsif ($env{'form.paste'}) {
  954:        my $lastsel;
  955:        if (defined($targetselect[-1])) {
  956: 	   $lastsel=$targetselect[-1];
  957:        } else {
  958:            $lastsel=$#order+1;
  959:        }
  960:        my @newsequence;
  961:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
  962:        foreach (@importselect) {
  963:           $newsequence[$#newsequence+1]=$curimport[$_];
  964:        }
  965:        &pastetarget($lastsel,@newsequence);
  966:        &storemap(&Apache::lonnet::filelocation('',$url));
  967: # -------------------------------------------------------------------- Move up 
  968:    } elsif ($env{'form.moveup'}) {
  969:        foreach (sort @targetselect) {
  970:            if ($_-1>0) {
  971:               my $movethis=$order[$_-1];
  972:               $order[$_-1]=$order[$_-2];
  973:               $order[$_-2]=$movethis;
  974: 	  }
  975:        }
  976:        &storemap(&Apache::lonnet::filelocation('',$url));
  977: # ------------------------------------------------------------------ Move down
  978:    } elsif ($env{'form.movedown'}) {
  979:        foreach (reverse sort @targetselect) {
  980:            if ($_-1<$#order) {
  981:               my $movethis=$order[$_-1];
  982:               $order[$_-1]=$order[$_];
  983:               $order[$_]=$movethis;
  984: 	   }
  985:        }
  986:        &storemap(&Apache::lonnet::filelocation('',$url));
  987: # --------------------------------------------------------------------- Rename
  988:    } elsif ($env{'form.renameres'}) {
  989:        my $residx=$Apache::lonratedt::order[$env{'form.renameidx'}-1];
  990:        my ($name,@resrest)=split(/\:/,$Apache::lonratedt::resources[$residx]);
  991:        $name=$env{'form.renametitle'};
  992:        $name=~s/\:/\&colon\;/g;
  993:        $Apache::lonratedt::resources[$residx]=$name.':'.join(':',@resrest);
  994:        &storemap(&Apache::lonnet::filelocation('',$url));
  995:    }
  996: # ------------------------------------------------------------ Assemble windows
  997:    
  998:    my $idx=-1;
  999:    $importdetail='&'.$importdetail;
 1000:    $importdetail=~s/^\&+/\&/;
 1001:    my $importwindow=
 1002:        '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
 1003:      join("\n",map {
 1004:        $idx++;
 1005:        if ($_) { 
 1006:           my ($name,$url)=split(/\=/,$_);
 1007:           unless ($name) { $name=(split(/\//,$url))[-1]; }
 1008:           unless ($name) { $name='EMPTY'; }
 1009:           '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
 1010:                                     '</option>';
 1011:       }
 1012:    } split(/\&/,$importdetail));
 1013: 
 1014:    $idx=0;
 1015:    $targetdetail='';
 1016:    my $targetwindow=       
 1017:        '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
 1018:      join("\n",map { 
 1019:        my ($name,$url)=split(/\:/,$resources[$_]);
 1020:        unless ($name) {  $name=(split(/\//,$url))[-1]; }
 1021:        unless ($name) { $name='EMPTY'; }
 1022:        $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
 1023: 	                  &Apache::lonnet::escape($url);
 1024:        $idx++;
 1025:        $name=~s/\&colon;/\:/g;
 1026:        '<option value="'.$idx.'">'.$name.'</option>';
 1027:    } @order);
 1028: 
 1029: # ----------------------------------------------------- Start simple RAT screen
 1030:    my $editscript=&editscript('simple');
 1031: 
 1032:    my %lt=&Apache::lonlocal::texthash(
 1033: 				      'sa' => 'Save',
 1034: 				      'nt' => 'New Title',
 1035: 				      'se' => 'Search',
 1036: 				      'im' => 'Import',
 1037: 				      'vi' => 'View',
 1038: 				      'lm' => 'Load Map',
 1039: 				      'ds' => 'Discard Selected',
 1040: 				      'ca' => 'Clear All',
 1041: 				      'ta' => 'Temporary Assembly Workspace',
 1042: 				      'rv' => 'Revert to Last Saved',
 1043:                                       'sa' => 'Save',
 1044:                                       'mu' => 'Move Up',
 1045:                                       'md' => 'Move Down',
 1046:                                       're' => 'Rename',
 1047:                                       'as' => 'after selected',
 1048:                                       'cs' => 'Cut selected',
 1049:                                       'ps' => 'Copy selected',
 1050:                                       'pas' => 'Paste after selected',
 1051:                                       'reco' => 'Recover Deleted'
 1052: 				      );
 1053:    my $js=<<ENDJS;
 1054: <script type="text/javascript">
 1055: 
 1056:    $editscript
 1057: 
 1058:    function openview(entry) {
 1059:        var url=unescape((entry.split('='))[1]);
 1060:        var parts=new Array;
 1061:        parts=url.split('&colon;');
 1062:        url=parts.join(':');
 1063:        if (url) { open(url,'cat'); }
 1064:    }
 1065: 
 1066:    function viewtarget() {
 1067:        openview((document.forms.simpleedit.targetdetail.value.split('&'))
 1068:                 [document.forms.simpleedit.target.selectedIndex]);
 1069:    }
 1070: 
 1071:    function viewimport() {
 1072:        openview((document.forms.simpleedit.curimpdetail.value.split('&'))
 1073:                 [document.forms.simpleedit.importsel.selectedIndex]);
 1074:    }
 1075: 
 1076:    function renametarget() {
 1077:        var selidx=document.forms.simpleedit.target.selectedIndex;
 1078:        var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
 1079:                 [selidx];
 1080:        var oldname=unescape((entry.split('='))[0]);
 1081:        var nameparts=oldname.split('&colon;');
 1082:        oldname=unescape(nameparts.join(':'));
 1083:        nameparts=oldname.split('&#34;');
 1084:        oldname=unescape(nameparts.join('"'));
 1085:        nameparts=oldname.split('&#39;');
 1086:        oldname=unescape(nameparts.join("'"));
 1087:        newtitle=prompt('$lt{'nt'}',oldname);
 1088:        if (newtitle) {
 1089:            document.forms.simpleedit.renameres.value=1;
 1090:            document.forms.simpleedit.renameidx.value=selidx;
 1091:            document.forms.simpleedit.renametitle.value=newtitle;
 1092: 	   document.forms.simpleedit.submit();
 1093:        }
 1094:    }
 1095: 
 1096: </script>
 1097: ENDJS
 1098: 
 1099:     my $start_page = &Apache::loncommon::start_page(undef,$js).
 1100:         &Apache::loncommon::help_open_menu('',
 1101: 					   'Sequence_Simple_Editor_Creation',
 1102: 					   'Sequence_Simple_Editor_Creation',
 1103: 					   '',6,'RAT');    
 1104:     my $end_page = &Apache::loncommon::end_page();
 1105: 
 1106:     $r->print(<<ENDSMPHEAD);
 1107: $start_page
 1108: $buttons
 1109: <font color=red>$errtext</font>
 1110: <form name=simpleedit method=post>
 1111: <input type=hidden name=forcesmp value=1>
 1112: <input type=hidden name=renameres value=0>
 1113: <input type=hidden name=renametitle value=''>
 1114: <input type=hidden name=renameidx value=0>
 1115: <table>
 1116:     <tr><th width="40%">$lt{'ta'}</th>
 1117: <th>&nbsp;</th>
 1118: <th width="40%">File: $url</th></tr>
 1119: <tr><td bgcolor="#FFFFCC">
 1120: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
 1121: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
 1122: $lt{'as'}
 1123: <hr>
 1124: <input type=text size=20 name=importmap>
 1125: <input type=button 
 1126: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
 1127: value="Select Map"><input type=submit name=loadmap value="$lt{'lm'}"><hr>
 1128: <input type=submit name="discard" value="$lt{'ds'}">
 1129: <input type=submit name="clear" value="$lt{'ca'}">
 1130: <input type=button onClick="javascript:viewimport()" value="$lt{'vi'}">
 1131: 
 1132:     </td><td>&nbsp;</td><td bgcolor="#FFFFCC">
 1133: 
 1134: <input type=button onClick=
 1135: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
 1136: <input type=button onClick=
 1137: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
 1138: <input type=button onClick=
 1139: "javascript:impfortarget.value=1;javascript:groupopen('$url',1);" value="$lt{'reco'}">
 1140: $lt{'as'}
 1141: <hr>
 1142: <input type=submit name="moveup" value="$lt{'mu'}">
 1143: <input type=submit name="movedown" value="$lt{'md'}">
 1144: <input type=button onClick="javascript:renametarget()" value="$lt{'re'}">
 1145: <hr>$targetmsg
 1146: <input type=submit name="revert" value="$lt{'rv'}">
 1147: <input type=submit name="save" value="$lt{'sa'}">
 1148: <input type=button onClick="javascript:viewtarget()" value="$lt{'vi'}">
 1149: </td></tr>
 1150: 
 1151: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
 1152: $importwindow
 1153: </select>
 1154: </td>
 1155: <td bgcolor="#FFFFAA" align="center">
 1156: $lt{'cs'}<br>
 1157: <input type=submit name=cut value='<<<'><p>
 1158: <hr>
 1159: $lt{'ps'}<br>
 1160: <input type=submit name=copy value='<--'><p>
 1161: <hr>
 1162: $lt{'pas'}<br>
 1163: <input type=submit name=paste value='-->'>
 1164: </td>
 1165: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
 1166: $targetwindow
 1167: </select>
 1168: </table>
 1169: <input type=hidden name=importdetail value="">
 1170: <input type=hidden name=curimpdetail value="$importdetail">
 1171: <input type=hidden name=targetdetail value="$targetdetail">
 1172: <input type=hidden name=impfortarget value="0">
 1173: </form>
 1174: $end_page
 1175: ENDSMPHEAD
 1176: }
 1177: 
 1178: # ----------------------------------------------------------------- No such dir
 1179: sub nodir {
 1180:    my ($r,$dir)=@_;
 1181:    $dir=~s{^/home/\w+/public_html}{};
 1182:    $r->print(&Apache::loncommon::start_page(undef,undef,
 1183: 					    {'only_body' => 1,
 1184: 					     'bgcolor'   => '#FFFFFF',}).
 1185: 	     "<h1>No such directory: $dir</h1>".
 1186: 	     &Apache::loncommon::end_page());
 1187: }
 1188: 
 1189: # ---------------------------------------------------------------- View Handler
 1190: 
 1191: sub viewmap {
 1192:     my ($r,$url,$adv,$errtext)=@_;
 1193:     $r->print(
 1194: 	      &Apache::loncommon::start_page('Edit Content of a Map').
 1195: 	      &Apache::loncommon::help_open_menu('','','','',6,'RAT').
 1196: 	      &buttons($adv));
 1197:     if ($errtext) {
 1198: 	$r->print($errtext.'<hr />');
 1199:     }
 1200:     my $idx=0;
 1201:     $r->print('<h1>'.$url.'</h1>');
 1202:     if ($adv) {
 1203: 	$r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
 1204:     }
 1205:     $r->print( '<table border="0" cellspacing="2" cellpadding="4">'.
 1206:                '<tr bgcolor="#DDDDDD"><th>'.&mt('Type').'</th>'.
 1207:                '<th>'.&mt('Title in map').'</th>'.
 1208:                '<th>'.&mt('Filename of resource').'</th>'.
 1209:                '<th>'.&mt('Link to published resource').'</th>'.
 1210:                '<th>'.&mt('Link to resource in Construction Space').'</th>'.
 1211:                '</tr>');
 1212:     my @backgroundColors = ("#FFFFFF", "#F6F6F6");
 1213:     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
 1214: 	if (defined($_)) {
 1215:             $idx++;
 1216: 	    my ($title,$url,$cond)=split(/\:/,$_);
 1217: 	    if ($cond eq 'cond') { next; }
 1218:             $title=~s/\&colon\;/\:/g;
 1219:             $url=~s/\&colon\;/\:/g;
 1220:             unless ($title) { $title=(split(/\//,$url))[-1] };
 1221:             unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
 1222:             my $resurl = &Apache::lonratsrv::qtescape($url);
 1223:             my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
 1224:             my $filename; 
 1225:             if ($resurl =~ m#/([^/]+)$#) {
 1226:                 $filename = $1;
 1227:             }
 1228:             my $cstrurl = $resurl;
 1229:             $cstrurl =~ s#^/res/[^/]+/([^/]+)/#/priv/$1/#;
 1230:             my $bgcol = $idx%2; 
 1231:             $r->print('<tr bgcolor='.$backgroundColors[$bgcol].'><td>'.
 1232:                       '<img src="'.&Apache::loncommon::icon($resfilepath).
 1233:                       '" /></td><td>'.&Apache::lonratsrv::qtescape($title).
 1234:                       '</td><td>'.$filename.'</td><td>');
 1235:             if ($url) {
 1236: 		$r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
 1237:             }
 1238:             $r->print('</td><td>');
 1239:             if ($url) {
 1240:                $r->print('<a href="'.$cstrurl.'">'.
 1241:                          &mt('Construction space').'</a>');
 1242:             }
 1243:             $r->print('</td></tr>'."\n");
 1244:         }
 1245:     }
 1246:     $r->print('</table>');
 1247:     $r->print(&Apache::loncommon::end_page());
 1248: }
 1249: 
 1250: # ================================================================ Main Handler
 1251: 
 1252: sub handler {
 1253:   my $r=shift;
 1254:   &Apache::loncommon::content_type($r,'text/html');
 1255:   $r->send_http_header;
 1256: 
 1257:   return OK if $r->header_only;
 1258:   my $target = $env{'form.grade_target'};
 1259:   if ($target eq 'meta') {
 1260:       &Apache::loncommon::content_type($r,'text/html');
 1261:       $r->send_http_header;
 1262:       return OK;
 1263:   }
 1264:   
 1265:   my $url=$r->uri;
 1266:   my $fn=&Apache::lonnet::filelocation('',$url);
 1267: 
 1268:   my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
 1269:   unless (-e $dir) {
 1270:       &nodir($r,$dir);
 1271:       return OK;
 1272:   }
 1273: 
 1274: # ------------------------------------------- Determine which tools can be used
 1275:   my $adv=0;
 1276: 
 1277:   unless ($env{'form.forcesmp'}) {
 1278:      if ($env{'form.forceadv'}) {
 1279:         $adv=1;
 1280:      } elsif (my $fh=Apache::File->new($fn)) {
 1281: 	 my $allmap=join('',<$fh>);
 1282:          $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
 1283:      }
 1284:   }
 1285: 
 1286:   my $errtext='';
 1287:   my $fatal=0;
 1288: 
 1289: # -------------------------------------------------------------------- Load map
 1290:   ($errtext,$fatal)=&mapread($fn,$errtext);
 1291: 
 1292:   if ($fatal==1) { $adv=1; }
 1293: 
 1294: # ----------------------------------- adv==1 now means "graphical MUST be used"
 1295: 
 1296:   if ($env{'form.forceadv'}) {
 1297:       &ratedt($r,$url);
 1298:   } elsif ($env{'form.forcesmp'}) {
 1299:       &smpedt($r,$url,$errtext);
 1300:   } else {
 1301:       &viewmap($r,$url,$adv,$errtext);
 1302:   }
 1303:   return OK;
 1304: }
 1305: 
 1306: 1;
 1307: __END__
 1308: 
 1309: 
 1310: 
 1311: 
 1312: 
 1313: 
 1314: 

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