Annotation of rat/lonratedt.pm, revision 1.82

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

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