Annotation of rat/lonratedt.pm, revision 1.60

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

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