File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.64: download - view: text, annotated - select for diffs
Wed Mar 23 22:54:18 2005 UTC (19 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: version_1_3_X, version_1_3_3, HEAD
Modify &viewmap() so that links to resources in a map point to resources in RES and also in CSTR.  Designed to facilitate browsing of courses imported from IMS packages, which generate maps containing unpublished resources.

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

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