Annotation of rat/lonratedt.pm, revision 1.51

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

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