Annotation of rat/lonratedt.pm, revision 1.77

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

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