File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.67: download - view: text, annotated - select for diffs
Wed Jun 8 15:44:51 2005 UTC (18 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
Remember zombies when fully reading a map
Forget zombies when just generating a listing

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

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