File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.70: download - view: text, annotated - select for diffs
Wed Jun 8 17:42:01 2005 UTC (18 years, 10 months ago) by www
Branches: MAIN
CVS tags: HEAD
Saving my work: Zombies

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

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