Annotation of rat/lonratedt.pm, revision 1.65

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

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