File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.69: download - view: text, annotated - select for diffs
Wed Jun 8 16:35:46 2005 UTC (18 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
Save the Zombies!

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

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