File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.72: download - view: text, annotated - select for diffs
Thu Jun 9 21:40:37 2005 UTC (18 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
Whodunit?

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

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