Annotation of rat/lonratedt.pm, revision 1.67

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Edit Handler for RAT Maps
1.5       www         3: #
1.67    ! www         4: # $Id: lonratedt.pm,v 1.66 2005/04/07 07:34:52 albertel 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.20      www       451: # ----------------------------------------------------------- Paste into target
                    452: # modifies @order, @resources
                    453: 
                    454: sub pastetarget {
                    455:     my ($after,@which)=@_;
                    456:     my @insertorder=();
                    457:     foreach (@which) {
                    458:         if (defined($_)) {
                    459: 	    my ($name,$url)=split(/\=/,$_);
1.21      www       460:             $name=&Apache::lonnet::unescape($name);
                    461:             $url=&Apache::lonnet::unescape($url);
                    462:             if ($url) {
                    463: 	       my $idx=$#resources+1;
                    464:                $insertorder[$#insertorder+1]=$idx;
                    465:                my $ext='false';
                    466:                if ($url=~/^http\:\/\//) { $ext='true'; }
                    467:                $url=~s/\:/\&colon;/g;
1.37      www       468:                $name=~s/\:/\&colon;/g;
1.21      www       469:                $resources[$idx]=$name.':'.$url.':'.$ext.':normal:res';
                    470: 	   }
1.20      www       471:         }
                    472:     }
1.23      www       473:     my @oldorder=splice(@order,$after);
                    474:     @order=(@order,@insertorder,@oldorder);
1.21      www       475: }
                    476: 
                    477: # ------------------------------------------------ Get start and finish correct
                    478: # modifies @resources
                    479: 
                    480: sub startfinish {
1.43      www       481: # Remove all start and finish
1.21      www       482:     foreach (@order) {
                    483: 	my ($name,$url,$ext)=split(/\:/,$resources[$_]);
1.22      www       484:         if ($url=~/http\&colon\:\/\//) { $ext='true'; }
1.21      www       485:         $resources[$_]=$name.':'.$url.':'.$ext.':normal:res';
                    486:     }
1.43      www       487: # Garbage collection
                    488:     my $stillchange=1;
                    489:      while (($#order>1) && ($stillchange)) {
                    490:        $stillchange=0;
                    491:        for (my $i=0;$i<=$#order;$i++) {
                    492:  	  my ($name,$url,$ext)=split(/\:/,$resources[$order[$i]]);
                    493:           unless ($url) {
                    494: # Take out empty resource
                    495:               for (my $j=$i+1;$j<=$#order;$j++) {
                    496:                   $order[$j-1]=$order[$j];
                    497: 	      }
                    498:               $#order--;
                    499: 	      $stillchange=1;
                    500:               last;
                    501:           }
                    502:        }
                    503:     }
                    504: # Put in a start resource
1.23      www       505:    my ($name,$url,$ext)=split(/\:/,$resources[$order[0]]);
                    506:    $resources[$order[0]]=$name.':'.$url.':'.$ext.':start:res';
1.43      www       507: # Make sure this has at least start and finish
1.33      www       508:    if ($#order==0) {
                    509:        $resources[$#resources+1]='::false';
                    510:        $order[1]=$#resources;
                    511:    }
1.43      www       512: # Make the last one a finish resource
1.42      www       513:    ($name,$url,$ext)=split(/\:/,$resources[$order[$#order]]);
1.21      www       514:    $resources[$order[$#order]]=$name.':'.$url.':'.$ext.':finish:res';
1.20      www       515: }
                    516: 
1.22      www       517: # ------------------------------------------------------------------- Store map
                    518: 
                    519: sub storemap {
1.34      www       520:     my $realfn=shift;
1.35      www       521:     my $fn=$realfn;
                    522: # unless this is forced to work from the original file, use a temporary file
                    523: # instead
                    524:     unless (shift) {
                    525:        $fn=$realfn.'.tmp';
                    526:        unless (-e $fn) {
                    527: 	  copy($realfn,$fn);
                    528:        }
1.34      www       529:     }
1.35      www       530: # store data either into tmp or real file
1.22      www       531:     &startfinish();
                    532:     my $output='graphdef<:>no';
                    533:     my $k=1;
                    534:     for (my $i=0; $i<=$#order; $i++) {
                    535:         if (defined($resources[$order[$i]])) {
                    536: 	    $output.='<&>objcont<:>'.$order[$i].'<:>'.$resources[$order[$i]];
                    537:         }
1.54      www       538: 	if (defined($resparms[$order[$i]])) {
1.55      www       539: 	    foreach (split('&&&',$resparms[$order[$i]])) {
                    540: 		if ($_) {
                    541: 		    $output.='<&>objparms<:>'.$order[$i].'<:>'.$_;
                    542: 		}
                    543: 	    }
1.54      www       544: 	}
1.22      www       545:         if (defined($order[$i+1])) {
                    546: 	    if (defined($resources[$order[$i+1]])) {
                    547:                $output.='<&>objlinks<:>'.$k.'<:>'.
                    548: 		   $order[$i].':'.$order[$i+1].':0';
                    549: 	       $k++;
                    550:             }
                    551:         }
                    552:     }
1.23      www       553:     $output=~s/http\&colon\;\/\///g;
1.65      albertel  554:     $env{'form.output'}=$output;
1.22      www       555:     return 
                    556:      &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));
                    557: }
                    558: 
1.56      www       559: # ------------------------------------------ Store and get parameters in global
                    560: 
                    561: sub storeparameter {
                    562:     my ($to,$name,$value,$ptype)=@_;
                    563:     my $newentry='';
                    564:     my $nametype='';
                    565:     foreach (split('&&&',$resparms[$to])) {
                    566: 	my ($thistype,$thisname,$thisvalue)=split('___',$_);
                    567: 	if ($thisname) {
                    568: 	    unless ($thisname eq $name) {
                    569: 		$newentry.=$_.'&&&';
                    570: 	    } else {
                    571: 		$nametype=$thistype;
                    572: 	    }
                    573: 	}
                    574:     }
                    575:     unless ($ptype) { $ptype=$nametype; }
                    576:     unless ($ptype) { $ptype='string'; }
                    577:     $newentry.=$ptype.'___'.$name.'___'.$value;
1.57      www       578:     $resparms[$to]=$newentry;
                    579: }
                    580: 
                    581: sub delparameter {
                    582:     my ($to,$name)=@_;
                    583:     my $newentry='';
                    584:     my $nametype='';
                    585:     foreach (split('&&&',$resparms[$to])) {
                    586: 	my ($thistype,$thisname,$thisvalue)=split('___',$_);
                    587: 	if ($thisname) {
                    588: 	    unless ($thisname eq $name) {
                    589: 		$newentry.=$_.'&&&';
                    590: 	    }
                    591: 	}
                    592:     }
1.56      www       593:     $resparms[$to]=$newentry;
                    594: }
                    595: 
                    596: sub getparameter {
1.58      www       597:     my ($to,$name)=@_;
1.56      www       598:     my $value=undef;
                    599:     my $ptype=undef;
                    600:     foreach (split('&&&',$resparms[$to])) {
                    601: 	my ($thistype,$thisname,$thisvalue)=split('___',$_);
                    602: 	if ($thisname eq $name) {
                    603: 	    $value=$thisvalue;
                    604: 	    $ptype=$thistype;
                    605: 	}
                    606:     }
                    607:     return ($value,$ptype);
                    608: }
                    609: 
                    610: # ----------------------------------------------------------------- Edit script
1.32      www       611: sub editscript {
                    612:     my $mode=shift;
1.51      www       613:     my $resurl=&Apache::loncommon::lastresurl();
1.32      www       614:     return(<<ENDSCRIPT);
                    615: var srch;
                    616: var srchflag=-1; // 1 means currently open
                    617:                  // 0 means closed (but has been open)
                    618:                  // -1 means never yet opened/defined
                    619: var srchmode='';
                    620: 
                    621: var idx;
                    622: var idxflag=-1; // 1 means currently open
                    623:                  // 0 means closed (but has been open)
                    624:                  // -1 means never yet opened/defined
                    625: var idxmode='';
                    626: 
                    627: // ------------------------------------------------------ Clears indexer window
                    628: function idxclear() {
                    629:   idx.document.clear();
                    630: }
                    631: 
                    632: // ------------------------------------------------------- Clears search window
                    633: function srchclear() {
                    634:   srch.document.clear();
                    635: }
                    636: 
                    637: // ------------------------------------------------------ Closes indexer window
                    638: function idxclose() {
                    639:   if (idx && !idx.closed) {
                    640:     idxflag=0;
                    641:     idx.close();
                    642:   }
                    643: }
                    644: 
                    645: // ------------------------------------------------------- Closes search window
                    646: function srchclose() {
                    647:   if (srch && !srch.closed) {
                    648:     srchflag=0;
                    649:     srch.close();
                    650:   }
                    651: }
                    652: 
                    653: // -------------------------------------------------------- Open indexer window
                    654: function idxopen(mode) {
                    655:    var options="scrollbars=1,resizable=1,menubar=0";
                    656:    idxmode=mode;
                    657:    idxflag=1;
1.51      www       658:    idx=open("$resurl/?launch=1&mode=$mode&catalogmode="+mode,"idxout",options);
1.32      www       659:    idx.focus();
                    660: }
                    661: 
                    662: // --------------------------------------------------------- Open search window
                    663: function srchopen(mode) {
                    664:    var options="scrollbars=1,resizable=1,menubar=0";
                    665:    srchmode=mode;
                    666:    srchflag=1;
                    667:    srch=open("/adm/searchcat?launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
                    668:    srch.focus();
                    669: }
                    670: // ----------------------------------------------------- launch indexer browser
                    671: function groupsearch() {
                    672:    srchcheck('groupsearch');
                    673: }
                    674: 
                    675: function groupimport() {
                    676:    idxcheck('groupimport');
                    677: }
                    678: // ------------------------------------------------------- Do srch status check
                    679: function srchcheck(mode) {
                    680:    if (!srch || srch.closed || srchmode!=mode) {
                    681:       srchopen(mode);
                    682:    }
                    683:    srch.focus();
                    684: }
                    685: 
                    686: // -------------------------------------------------------- Do idx status check
                    687: function idxcheck(mode) {
                    688:    if (!idx || idx.closed || idxmode!=mode) {
                    689:       idxopen(mode);
                    690:    }
                    691:    idx.focus();
                    692: }
                    693: 
                    694: 
                    695:     var editbrowser;
                    696:     function openbrowser(formname,elementname,only,omit) {
1.51      www       697:         var url = '$resurl/?';
1.32      www       698:         if (editbrowser == null) {
                    699:             url += 'launch=1&';
                    700:         }
                    701:         url += 'catalogmode=interactive&';
                    702:         url += 'mode=edit&';
                    703:         url += 'form=' + formname + '&';
                    704:         if (only != null) {
                    705:             url += 'only=' + only + '&';
                    706:         } 
                    707:         if (omit != null) {
                    708:             url += 'omit=' + omit + '&';
                    709:         }
                    710:         url += 'element=' + elementname + '';
                    711:         var title = 'Browser';
                    712:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    713:         options += ',width=700,height=600';
                    714:         editbrowser = open(url,title,options,'1');
                    715:         editbrowser.focus();
                    716:     }
                    717: ENDSCRIPT
                    718: }
1.20      www       719: # ------------------------------------------------------- Simple edit processor
                    720: 
1.3       www       721: sub smpedt {
1.22      www       722:    my ($r,$url,$errtext)=@_;
1.8       www       723:    my $buttons=&buttons(2);
1.34      www       724:    my $tmpfn=&Apache::lonnet::filelocation('',$url).'.tmp';
                    725:    my $targetmsg='';
1.65      albertel  726:    if ($env{'form.save'}) {
1.34      www       727:        copy($tmpfn,&Apache::lonnet::filelocation('',$url));
                    728:        unlink($tmpfn);
1.35      www       729:        my ($errtext,$fatal)=
                    730:                            &mapread(&Apache::lonnet::filelocation('',$url),'');
1.60      www       731:        unless ($fatal) {
                    732: 	   $targetmsg='<b>'.&mt('Saved.').'</b><br />';
                    733:        } else {
                    734: 	   $targetmsg='<b>'.&mt('An error occured while saving.').'</b><br />';
                    735:        }
1.34      www       736:    }
1.65      albertel  737:    if ($env{'form.revert'}) {
1.60      www       738:        $targetmsg='<b>'.&mt('Reverted.').'</b><br />';
1.34      www       739:        unlink($tmpfn);
1.35      www       740:        my ($errtext,$fatal)=
                    741:                            &mapread(&Apache::lonnet::filelocation('',$url),'');
1.34      www       742:    }
                    743:    if (-e $tmpfn) {
                    744:       $targetmsg=
1.49      sakharuk  745:         '<b><font color="red">'.&mt('You are working with an unsaved version of your map.').'</font></b><br>';
1.34      www       746:       my ($errtext,$fatal)=&mapread($tmpfn,'');
                    747:    }
1.12      www       748: # ---------------------------------------------------------- Process form input
                    749: 
1.66      albertel  750:    my @importselect=&Apache::loncommon::get_env_multiple('form.importsel');
                    751:    my @targetselect=&Apache::loncommon::get_env_multiple('form.target');
1.13      www       752: # ============================================================ Process commands
1.12      www       753: 
1.65      albertel  754:    my $targetdetail=$env{'form.targetdetail'};
                    755:    my $importdetail=$env{'form.curimpdetail'};
1.13      www       756: 
                    757: # ---------------------------------------------------- Importing from groupsort
1.65      albertel  758:    if (($env{'form.importdetail'}) && (!$env{'form.impfortarget'})) {
1.13      www       759: 
1.14      www       760:        $importdetail='';
1.65      albertel  761:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.13      www       762: 
                    763:        my $lastsel;
                    764: 
                    765:        if (defined($importselect[-1])) {
                    766: 	   $lastsel=$importselect[-1];
                    767:        } else {
                    768:            $lastsel=$#curimport;
                    769:        }
                    770: 
                    771:        for (my $i=0;$i<=$lastsel;$i++) {
                    772:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    773:            if ($url) {
1.18      www       774:               $importdetail.='&'.$name.'='.$url;
1.13      www       775: 	   }
                    776:        }
                    777: 
1.65      albertel  778:       $importdetail.='&'.$env{'form.importdetail'};
1.13      www       779: 
                    780:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
                    781:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    782:            if ($url) {
1.18      www       783:               $importdetail.='&'.$name.'='.$url;
1.13      www       784: 	  }
                    785:        }
                    786:        $importdetail=~s/\&+/\&/g;
                    787:        $importdetail=~s/^\&//;
                    788: 
1.14      www       789: # ------------------------------------------------------------------- Clear all
1.65      albertel  790:    } elsif ($env{'form.clear'}) {
1.14      www       791:        $importdetail='';
                    792: # ------------------------------------------------------------ Discard selected
1.65      albertel  793:    } elsif ($env{'form.discard'}) {
1.14      www       794:        $importdetail='';
1.65      albertel  795:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.14      www       796:        foreach (@importselect) {
                    797: 	   $curimport[$_]='';
                    798:        }
                    799:        for (my $i=0;$i<=$#curimport;$i++) {
                    800:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    801:            if ($url) {
1.18      www       802:               $importdetail.='&'.$name.'='.$url;
1.14      www       803: 	   }
                    804:        }
1.17      www       805: # --------------------------------------------------------- Loading another map
1.65      albertel  806:    } elsif ($env{'form.loadmap'}) {
1.17      www       807:        $importdetail='';
1.65      albertel  808:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.17      www       809: 
                    810:        my $lastsel;
                    811: 
                    812:        if (defined($importselect[-1])) {
                    813: 	   $lastsel=$importselect[-1];
                    814:        } else {
                    815:            $lastsel=$#curimport;
                    816:        }
                    817: 
                    818:        for (my $i=0;$i<=$lastsel;$i++) {
                    819:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    820:            if ($url) {
1.18      www       821:               $importdetail.='&'.$name.'='.$url;
1.17      www       822: 	   }
                    823:        }
                    824: 
                    825:        foreach (
1.65      albertel  826:     &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1.17      www       827: 	   my ($name,$url)=split(/\:/,$_);
                    828:            if ($url) {
                    829:               $importdetail.='&'.&Apache::lonnet::escape($name).'='.
                    830: 		 	         &Apache::lonnet::escape($url);
                    831: 	  }
                    832:        }
                    833: 
                    834:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
                    835:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    836:            if ($url) {
1.18      www       837:               $importdetail.='&'.$name.'='.$url;
1.17      www       838: 	  }
                    839:        }
                    840:        $importdetail=~s/\&+/\&/g;
                    841:        $importdetail=~s/^\&//;
                    842: 
1.20      www       843: # ------------------------------------------------ Groupimport/search to target
1.65      albertel  844:    } elsif ($env{'form.importdetail'}) {
1.20      www       845:        my $lastsel;
                    846:        if (defined($targetselect[-1])) {
                    847: 	   $lastsel=$targetselect[-1];
                    848:        } else {
1.23      www       849:            $lastsel=$#order+1;
1.20      www       850:        }
1.65      albertel  851:        &pastetarget($lastsel,split(/\&/,$env{'form.importdetail'}));
1.22      www       852:        &storemap(&Apache::lonnet::filelocation('',$url));
1.20      www       853: # ------------------------------------------------------------------------- Cut
1.65      albertel  854:    } elsif (($env{'form.cut'}) || ($env{'form.copy'})) {
1.25      www       855:        $importdetail='';
1.65      albertel  856:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.25      www       857: 
                    858:        my $lastsel;
                    859: 
                    860:        if (defined($importselect[-1])) {
                    861: 	   $lastsel=$importselect[-1];
                    862:        } else {
                    863:            $lastsel=$#curimport;
                    864:        }
                    865: 
                    866:        for (my $i=0;$i<=$lastsel;$i++) {
                    867:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    868:            if ($url) {
                    869:               $importdetail.='&'.$name.'='.$url;
                    870: 	   }
                    871:        }
                    872: 
                    873:        foreach (@targetselect) {
                    874: 	   my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
                    875:            if ($url) {
                    876:               $importdetail.='&'.&Apache::lonnet::escape($name).'='.
                    877: 		 	         &Apache::lonnet::escape($url);
                    878: 	  }
                    879:        }
                    880: 
                    881:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
                    882:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    883:            if ($url) {
                    884:               $importdetail.='&'.$name.'='.$url;
                    885: 	  }
                    886:        }
                    887:        $importdetail=~s/\&+/\&/g;
                    888:        $importdetail=~s/^\&//;
                    889: 
1.65      albertel  890:        if ($env{'form.cut'}) {
1.25      www       891:            my @neworder=();
                    892:            for (my $i=0;$i<=$#order;$i++) {
                    893:                my $include=1;
                    894:                foreach (@targetselect) {
                    895: 		   if ($_-1==$i) { $include=0; }
                    896:                }
                    897:                if ($include) { $neworder[$#neworder+1]=$order[$i]; }
                    898:            }
                    899:            @order=@neworder;
                    900:            &storemap(&Apache::lonnet::filelocation('',$url));      
                    901:        }
                    902: 
1.20      www       903: # ----------------------------------------------------------------------- Paste
1.65      albertel  904:    } elsif ($env{'form.paste'}) {
1.24      www       905:        my $lastsel;
                    906:        if (defined($targetselect[-1])) {
                    907: 	   $lastsel=$targetselect[-1];
                    908:        } else {
                    909:            $lastsel=$#order+1;
                    910:        }
                    911:        my @newsequence;
1.65      albertel  912:        my @curimport=split(/\&/,$env{'form.curimpdetail'});
1.24      www       913:        foreach (@importselect) {
                    914:           $newsequence[$#newsequence+1]=$curimport[$_];
                    915:        }
                    916:        &pastetarget($lastsel,@newsequence);
                    917:        &storemap(&Apache::lonnet::filelocation('',$url));
1.39      www       918: # -------------------------------------------------------------------- Move up 
1.65      albertel  919:    } elsif ($env{'form.moveup'}) {
1.39      www       920:        foreach (sort @targetselect) {
                    921:            if ($_-1>0) {
                    922:               my $movethis=$order[$_-1];
                    923:               $order[$_-1]=$order[$_-2];
                    924:               $order[$_-2]=$movethis;
                    925: 	  }
                    926:        }
                    927:        &storemap(&Apache::lonnet::filelocation('',$url));
                    928: # ------------------------------------------------------------------ Move down
1.65      albertel  929:    } elsif ($env{'form.movedown'}) {
1.39      www       930:        foreach (reverse sort @targetselect) {
                    931:            if ($_-1<$#order) {
                    932:               my $movethis=$order[$_-1];
                    933:               $order[$_-1]=$order[$_];
                    934:               $order[$_]=$movethis;
                    935: 	   }
                    936:        }
                    937:        &storemap(&Apache::lonnet::filelocation('',$url));
                    938: # --------------------------------------------------------------------- Rename
1.65      albertel  939:    } elsif ($env{'form.renameres'}) {
                    940:        my $residx=$Apache::lonratedt::order[$env{'form.renameidx'}-1];
1.39      www       941:        my ($name,@resrest)=split(/\:/,$Apache::lonratedt::resources[$residx]);
1.65      albertel  942:        $name=$env{'form.renametitle'};
1.40      www       943:        $name=~s/\:/\&colon\;/g;
1.41      www       944:        $Apache::lonratedt::resources[$residx]=$name.':'.join(':',@resrest);
1.39      www       945:        &storemap(&Apache::lonnet::filelocation('',$url));
1.13      www       946:    }
1.12      www       947: # ------------------------------------------------------------ Assemble windows
1.20      www       948:    
1.13      www       949:    my $idx=-1;
1.34      www       950:    $importdetail='&'.$importdetail;
                    951:    $importdetail=~s/^\&+/\&/;
1.29      www       952:    my $importwindow=
1.50      sakharuk  953:        '<option value="-1"> ---- '.&mt('Import and Paste Area').' ---- </option>'.
1.29      www       954:      join("\n",map {
1.13      www       955:        $idx++;
                    956:        if ($_) { 
1.15      www       957:           my ($name,$url)=split(/\=/,$_);
                    958:           unless ($name) { $name=(split(/\//,$url))[-1]; }
                    959:           unless ($name) { $name='EMPTY'; }
1.13      www       960:           '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
                    961:                                     '</option>';
                    962:       }
                    963:    } split(/\&/,$importdetail));
1.12      www       964: 
1.13      www       965:    $idx=0;
1.39      www       966:    $targetdetail='';
1.29      www       967:    my $targetwindow=       
1.49      sakharuk  968:        '<option value="0"> ------- '.&mt('Target Edit Map').' ------- </option>'.
1.29      www       969:      join("\n",map { 
1.13      www       970:        my ($name,$url)=split(/\:/,$resources[$_]);
1.15      www       971:        unless ($name) {  $name=(split(/\//,$url))[-1]; }
                    972:        unless ($name) { $name='EMPTY'; }
1.13      www       973:        $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
                    974: 	                  &Apache::lonnet::escape($url);
                    975:        $idx++;
1.37      www       976:        $name=~s/\&colon;/\:/g;
1.20      www       977:        '<option value="'.$idx.'">'.$name.'</option>';
1.11      www       978:    } @order);
                    979: 
1.8       www       980: # ----------------------------------------------------- Start simple RAT screen
1.32      www       981:    my $editscript=&editscript('simple');
1.61      albertel  982:    my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,
1.65      albertel  983: 					($env{'environment.remote'} ne 'off')).
1.59      albertel  984:        &Apache::loncommon::help_open_menu('','Sequence_Simple_Editor_Creation','Sequence_Simple_Editor_Creation','',6,'RAT');
1.47      www       985:    my %lt=&Apache::lonlocal::texthash(
                    986: 				      'sa' => 'Save',
                    987: 				      'nt' => 'New Title',
                    988: 				      'se' => 'Search',
                    989: 				      'im' => 'Import',
                    990: 				      'vi' => 'View',
                    991: 				      'lm' => 'Load Map',
                    992: 				      'ds' => 'Discard Selected',
                    993: 				      'ca' => 'Clear All',
                    994: 				      'ta' => 'Temporary Assembly Workspace',
                    995: 				      'rv' => 'Revert to Last Saved',
                    996:                                       'sa' => 'Save',
                    997:                                       'mu' => 'Move Up',
                    998:                                       'md' => 'Move Down',
                    999:                                       're' => 'Rename',
1.49      sakharuk 1000:                                       'as' => 'after selected',
                   1001:                                       'cs' => 'Cut selected',
                   1002:                                       'ps' => 'Copy selected',
                   1003:                                       'pas' => 'Paste after selected',
1.47      www      1004: 				      );
1.3       www      1005:    $r->print(<<ENDSMPHEAD);
                   1006: <html>
1.6       www      1007: <head>
                   1008: <script>
1.15      www      1009: 
1.32      www      1010:    $editscript
1.19      www      1011: 
                   1012:    function openview(entry) {
                   1013:        var url=unescape((entry.split('='))[1]);
1.20      www      1014:        var parts=new Array;
                   1015:        parts=url.split('&colon;');
                   1016:        url=parts.join(':');
1.19      www      1017:        if (url) { open(url,'cat'); }
                   1018:    }
                   1019: 
                   1020:    function viewtarget() {
                   1021:        openview((document.forms.simpleedit.targetdetail.value.split('&'))
1.34      www      1022:                 [document.forms.simpleedit.target.selectedIndex]);
1.19      www      1023:    }
                   1024: 
                   1025:    function viewimport() {
                   1026:        openview((document.forms.simpleedit.curimpdetail.value.split('&'))
1.34      www      1027:                 [document.forms.simpleedit.importsel.selectedIndex]);
1.19      www      1028:    }
                   1029: 
1.39      www      1030:    function renametarget() {
                   1031:        var selidx=document.forms.simpleedit.target.selectedIndex;
                   1032:        var entry=(document.forms.simpleedit.targetdetail.value.split('&'))
                   1033:                 [selidx];
1.41      www      1034:        var oldname=unescape((entry.split('='))[0]);
                   1035:        var nameparts=oldname.split('&colon;');
                   1036:        oldname=unescape(nameparts.join(':'));
                   1037:        nameparts=oldname.split('&#34;');
                   1038:        oldname=unescape(nameparts.join('"'));
                   1039:        nameparts=oldname.split('&#39;');
                   1040:        oldname=unescape(nameparts.join("'"));
1.47      www      1041:        newtitle=prompt('$lt{'nt'}',oldname);
1.39      www      1042:        if (newtitle) {
                   1043:            document.forms.simpleedit.renameres.value=1;
                   1044:            document.forms.simpleedit.renameidx.value=selidx;
                   1045:            document.forms.simpleedit.renametitle.value=newtitle;
                   1046: 	   document.forms.simpleedit.submit();
                   1047:        }
                   1048:    }
                   1049: 
1.6       www      1050: </script>
                   1051: </head>                 
1.34      www      1052: $bodytag
1.8       www      1053: $buttons
1.7       www      1054: <font color=red>$errtext</font>
1.13      www      1055: <form name=simpleedit method=post>
1.11      www      1056: <input type=hidden name=forcesmp value=1>
1.39      www      1057: <input type=hidden name=renameres value=0>
                   1058: <input type=hidden name=renametitle value=''>
                   1059: <input type=hidden name=renameidx value=0>
1.11      www      1060: <table>
1.47      www      1061:     <tr><th width="40%">$lt{'ta'}</th>
1.12      www      1062: <th>&nbsp;</th>
1.37      www      1063: <th width="40%">File: $url</th></tr>
1.12      www      1064: <tr><td bgcolor="#FFFFCC">
1.47      www      1065: <input type=button onClick="javascript:groupsearch()" value="$lt{'se'}">
                   1066: <input type=button onClick="javascript:groupimport();" value="$lt{'im'}">
1.49      sakharuk 1067: $lt{'as'}
1.14      www      1068: <hr>
1.15      www      1069: <input type=text size=20 name=importmap>
                   1070: <input type=button 
                   1071: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
1.47      www      1072: value="Select Map"><input type=submit name=loadmap value="$lt{'lm'}"><hr>
                   1073: <input type=submit name="discard" value="$lt{'ds'}">
                   1074: <input type=submit name="clear" value="$lt{'ca'}">
                   1075: <input type=button onClick="javascript:viewimport()" value="$lt{'vi'}">
1.16      www      1076: 
1.12      www      1077:     </td><td>&nbsp;</td><td bgcolor="#FFFFCC">
1.16      www      1078: 
                   1079: <input type=button onClick=
1.47      www      1080: "javascript:impfortarget.value=1;groupsearch()" value="$lt{'se'}">
1.16      www      1081: <input type=button onClick=
1.47      www      1082: "javascript:impfortarget.value=1;groupimport();" value="$lt{'im'}">
1.49      sakharuk 1083: $lt{'as'}
1.39      www      1084: <hr>
1.47      www      1085: <input type=submit name="moveup" value="$lt{'mu'}">
                   1086: <input type=submit name="movedown" value="$lt{'md'}">
                   1087: <input type=button onClick="javascript:renametarget()" value="$lt{'re'}">
1.34      www      1088: <hr>$targetmsg
1.47      www      1089: <input type=submit name="revert" value="$lt{'rv'}">
                   1090: <input type=submit name="save" value="$lt{'sa'}">
                   1091: <input type=button onClick="javascript:viewtarget()" value="$lt{'vi'}">
1.12      www      1092: </td></tr>
1.16      www      1093: 
1.27      www      1094: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
1.12      www      1095: $importwindow
                   1096: </select>
1.11      www      1097: </td>
1.12      www      1098: <td bgcolor="#FFFFAA" align="center">
1.49      sakharuk 1099: $lt{'cs'}<br>
1.11      www      1100: <input type=submit name=cut value='<<<'><p>
1.12      www      1101: <hr>
1.49      sakharuk 1102: $lt{'ps'}<br>
1.25      www      1103: <input type=submit name=copy value='<--'><p>
                   1104: <hr>
1.49      sakharuk 1105: $lt{'pas'}<br>
1.25      www      1106: <input type=submit name=paste value='-->'>
1.11      www      1107: </td>
1.27      www      1108: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
1.11      www      1109: $targetwindow
                   1110: </select>
1.12      www      1111: </table>
1.13      www      1112: <input type=hidden name=importdetail value="">
                   1113: <input type=hidden name=curimpdetail value="$importdetail">
1.12      www      1114: <input type=hidden name=targetdetail value="$targetdetail">
1.16      www      1115: <input type=hidden name=impfortarget value="0">
1.12      www      1116: </form>
                   1117: </body></html>
1.3       www      1118: ENDSMPHEAD
                   1119: }
                   1120: 
1.11      www      1121: # ----------------------------------------------------------------- No such dir
1.4       www      1122: sub nodir {
                   1123:    my ($r,$dir)=@_;
                   1124:    $dir=~s/^\/home\/\w+\/public\_html//;
                   1125:    $r->print(<<ENDNODIR);
                   1126: <html>
                   1127: <body bgcolor='#FFFFFF'>
                   1128: <h1>No such directory: $dir</h1>
                   1129: </body>
                   1130: </html>
                   1131: ENDNODIR
                   1132: }
                   1133: 
1.8       www      1134: # ---------------------------------------------------------------- View Handler
                   1135: 
                   1136: sub viewmap {
1.17      www      1137:     my ($r,$url,$adv,$errtext)=@_;
1.34      www      1138:     $r->print('<html>'.
                   1139:      &Apache::loncommon::bodytag('Edit Content of a Map').
1.59      albertel 1140: 	      &Apache::loncommon::help_open_menu('','','','',6,'RAT').
1.53      www      1141: 	      &buttons($adv));
1.10      www      1142:     if ($errtext) {
1.53      www      1143: 	$r->print($errtext.'<hr />');
1.10      www      1144:     }
1.26      www      1145:     my $idx=0;
1.34      www      1146:     $r->print('<h1>'.$url.'</h1>');
1.44      www      1147:     if ($adv) {
1.47      www      1148: 	$r->print('<p><b><font color="red">'.&mt('Map contents are not shown in order.').'</font></b></p><br />');
1.44      www      1149:     }
1.64      raeburn  1150:     $r->print( '<table border="0" cellspacing="2" cellpadding="4">'.
                   1151:                '<tr bgcolor="#DDDDDD"><th>'.&mt('Type').'</th>'.
                   1152:                '<th>'.&mt('Title in map').'</th>'.
                   1153:                '<th>'.&mt('Filename of resource').'</th>'.
                   1154:                '<th>'.&mt('Link to published resource').'</th>'.
                   1155:                '<th>'.&mt('Link to resource in Construction Space').'</th>'.
                   1156:                '</tr>');
                   1157:     my @backgroundColors = ("#FFFFFF", "#F6F6F6");
1.17      www      1158:     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9       www      1159: 	if (defined($_)) {
1.26      www      1160:             $idx++;
1.62      albertel 1161: 	    my ($title,$url,$cond)=split(/\:/,$_);
                   1162: 	    if ($cond eq 'cond') { next; }
1.9       www      1163:             $title=~s/\&colon\;/\:/g;
                   1164:             $url=~s/\&colon\;/\:/g;
1.15      www      1165:             unless ($title) { $title=(split(/\//,$url))[-1] };
1.64      raeburn  1166:             unless ($title) { $title='<i>'.&mt('Empty').'</i>'; }
                   1167:             my $resurl = &Apache::lonratsrv::qtescape($url);
                   1168:             my $resfilepath = $Apache::lonnet::perlvar{'lonDocRoot'}.$resurl;
                   1169:             my $filename; 
                   1170:             if ($resurl =~ m#/([^/]+)$#) {
                   1171:                 $filename = $1;
                   1172:             }
                   1173:             my $cstrurl = $resurl;
                   1174:             $cstrurl =~ s#^/res/[^/]+/([^/]+)/#/priv/$1/#;
                   1175:             my $bgcol = $idx%2; 
                   1176:             $r->print('<tr bgcolor='.$backgroundColors[$bgcol].'><td>'.
                   1177:                       '<img src="'.&Apache::loncommon::icon($resfilepath).
                   1178:                       '" /></td><td>'.&Apache::lonratsrv::qtescape($title).
                   1179:                       '</td><td>'.$filename.'</td><td>');
                   1180:             if ($url) {
                   1181:                 if (-e $resfilepath) {
                   1182: 		    $r->print('<a href="'.$resurl.'">'.&mt('Resource space').'</a>');
                   1183:                 } else {
                   1184:                     $r->print(&mt('unpublished'));
                   1185:                 }
                   1186:             }
                   1187:             $r->print('</td><td>');
1.9       www      1188:             if ($url) {
1.64      raeburn  1189:                $r->print('<a href="'.$cstrurl.'">'.
                   1190:                          &mt('Construction space').'</a>');
1.9       www      1191:             }
1.64      raeburn  1192:             $r->print('</td></tr>'."\n");
1.9       www      1193:         }
                   1194:     }
1.64      raeburn  1195:     $r->print('</table>');
1.8       www      1196:     $r->print('</body></html>');
                   1197: }
                   1198: 
1.3       www      1199: # ================================================================ Main Handler
                   1200: 
                   1201: sub handler {
                   1202:   my $r=shift;
1.47      www      1203:   &Apache::loncommon::content_type($r,'text/html');
1.3       www      1204:   $r->send_http_header;
                   1205: 
                   1206:   return OK if $r->header_only;
1.65      albertel 1207:   my $target = $env{'form.grade_target'};
1.48      albertel 1208:   if ($target eq 'meta') {
                   1209:       &Apache::loncommon::content_type($r,'text/html');
                   1210:       $r->send_http_header;
                   1211:       return OK;
                   1212:   }
                   1213:   
1.3       www      1214:   my $url=$r->uri;
                   1215:   my $fn=&Apache::lonnet::filelocation('',$url);
                   1216: 
1.4       www      1217:   my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
                   1218:   unless (-e $dir) {
                   1219:       &nodir($r,$dir);
                   1220:       return OK;
                   1221:   }
1.8       www      1222: 
                   1223: # ------------------------------------------- Determine which tools can be used
1.3       www      1224:   my $adv=0;
                   1225: 
1.65      albertel 1226:   unless ($env{'form.forcesmp'}) {
                   1227:      if ($env{'form.forceadv'}) {
1.3       www      1228:         $adv=1;
                   1229:      } elsif (my $fh=Apache::File->new($fn)) {
                   1230: 	 my $allmap=join('',<$fh>);
                   1231:          $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
                   1232:      }
                   1233:   }
                   1234: 
1.8       www      1235:   my $errtext='';
                   1236:   my $fatal=0;
                   1237: 
                   1238: # -------------------------------------------------------------------- Load map
                   1239:   ($errtext,$fatal)=&mapread($fn,$errtext);
                   1240: 
                   1241:   if ($fatal==1) { $adv=1; }
                   1242: 
                   1243: # ----------------------------------- adv==1 now means "graphical MUST be used"
                   1244: 
1.65      albertel 1245:   if ($env{'form.forceadv'}) {
1.3       www      1246:       &ratedt($r,$url);
1.65      albertel 1247:   } elsif ($env{'form.forcesmp'}) {
1.22      www      1248:       &smpedt($r,$url,$errtext);
1.3       www      1249:   } else {
1.17      www      1250:       &viewmap($r,$url,$adv,$errtext);
1.3       www      1251:   }
1.1       www      1252:   return OK;
                   1253: }
                   1254: 
                   1255: 1;
                   1256: __END__
                   1257: 
                   1258: 
                   1259: 
                   1260: 
                   1261: 
                   1262: 
                   1263: 

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