Annotation of rat/lonratedt.pm, revision 1.68

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

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