File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.68: download - view: text, annotated - select for diffs
Wed Jun 8 16:10:01 2005 UTC (18 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
* never recycle IDs, including zombies
* just because it's not replicated does not mean it does not exist

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

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