Annotation of rat/lonratedt.pm, revision 1.55

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

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