Annotation of rat/lonratedt.pm, revision 1.32

1.1       www         1: # The LearningOnline Network with CAPA
                      2: # Edit Handler for RAT Maps
1.5       www         3: #
1.32    ! www         4: # $Id: lonratedt.pm,v 1.31 2002/06/24 14:12:04 www 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.1       www        28: # (TeX Content Handler
                     29: #
                     30: # 05/29/00,05/30 Gerd Kortemeyer)
1.4       www        31: # 7/1,6/30 Gerd Kortemeyer
1.1       www        32: 
                     33: package Apache::lonratedt;
                     34: 
                     35: use strict;
                     36: use Apache::Constants qw(:common);
1.3       www        37: use Apache::lonnet;
1.7       www        38: use Apache::lonratsrv;
1.30      www        39: use Apache::lonsequence;
1.1       www        40: 
1.23      www        41: my @order;
                     42: my @resources;
1.8       www        43: 
                     44: 
                     45: # Mapread read maps into global arrays @links and @resources, determines status
1.10      www        46: # sets @order - pointer to resources in right order
                     47: # sets @resources - array with the resources with correct idx
                     48: #
1.8       www        49: sub mapread {
                     50:     my $fn=shift;
                     51: 
1.10      www        52:     my @links;
1.8       www        53:     undef @links;
                     54:     undef @resources;
1.10      www        55:     undef @order;
1.23      www        56:     @resources=('');
                     57:     @order=();
1.8       www        58: 
                     59:     my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
                     60:     if ($errtext) { return ($errtext,2); }
                     61: 
1.9       www        62: # -------------------------------------------------------------------- Read map
1.8       www        63:     foreach (split(/\<\&\>/,$outtext)) {
1.9       www        64: 	my ($command,$number,$content)=split(/\<\:\>/,$_);
1.8       www        65:         if ($command eq 'objcont') {
1.9       www        66: 	    $resources[$number]=$content;
1.8       www        67:         }
                     68:         if ($command eq 'objlinks') {
1.9       www        69:             $links[$number]=$content;
1.31      www        70:         }
                     71:         if ($command eq 'objparms') {
                     72: 	    return('Map has resource parameters. Use advanced editor.',1);
1.9       www        73:         }
                     74:     }
                     75: # ------------------------------------------------------- Is this a linear map?
                     76:     my @starters=();
                     77:     my @endings=();
                     78:     undef @starters;
                     79:     undef @endings;
                     80: 
                     81:     foreach (@links) {
                     82:         if (defined($_)) {
                     83: 	    my ($start,$end,$cond)=split(/\:/,$_);
                     84:             if ((defined($starters[$start])) || (defined($endings[$end]))) { 
1.8       www        85: 		return
1.10      www        86:                  ('Map has branchings. Use advanced editor.',1);
1.8       www        87:             }
1.9       www        88: 	    $starters[$start]=1;
                     89: 	    $endings[$end]=1;
                     90: 	    if ($cond) {
1.8       www        91: 		return
1.10      www        92:                  ('Map has conditions. Use advanced editor.',1);
1.8       www        93:             }
                     94: 	}
                     95: 
                     96:     }
1.23      www        97:     for (my $i=1; $i<=$#resources; $i++) {
1.10      www        98:         if (defined($resources[$i])) {
                     99: 	    unless (($starters[$i]) || ($endings[$i])) {
                    100:                 return
                    101: 		 ('Map has unconnected resources. Use advanced editor.',1);
                    102:             }
                    103:         }
                    104:     }
                    105: 
                    106: # -------------------------------------------------- This is a linear map, sort
                    107: 
                    108:     my $startidx=0;
                    109:     my $endidx=0;
                    110:     for (my $i=0; $i<=$#resources; $i++) {
                    111:         if (defined($resources[$i])) {
                    112:             my ($title,$url,$ext,$type)=split(/\:/,$resources[$i]);
                    113: 	    if ($type eq 'start') { $startidx=$i; }
                    114:             if ($type eq 'finish') { $endidx=$i; }
                    115:         }
                    116:     }
                    117:     my $k=0;
                    118:     my $currentidx=$startidx;
                    119:     $order[$k]=$currentidx;
                    120:     for (my $i=0; $i<=$#resources; $i++) {
                    121:         foreach (@links) {
                    122: 	    my ($start,$end)=split(/\:/,$_);
                    123:             if ($start==$currentidx) {
                    124: 		$currentidx=$end;
                    125:                 $k++;
                    126:                 $order[$k]=$currentidx;
                    127:                 last;
                    128:             }
                    129:         }
                    130:         if ($currentidx==$endidx) { last; }
                    131:     }
1.8       www       132:     return $errtext;
                    133: }
                    134: 
1.16      www       135: # ---------------------------------------------- Read a map as well as possible
1.28      www       136: # Also used by the sequence handler
                    137: # Call lonsequence::attemptread to read from resource space
                    138: #
1.16      www       139: sub attemptread {
                    140:     my $fn=shift;
                    141: 
                    142:     my @links;
                    143:     undef @links;
                    144:     my @theseres;
                    145:     undef @theseres;
                    146: 
                    147:     my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
                    148:     if ($errtext) { return @theseres }
                    149: 
                    150: # -------------------------------------------------------------------- Read map
                    151:     foreach (split(/\<\&\>/,$outtext)) {
                    152: 	my ($command,$number,$content)=split(/\<\:\>/,$_);
                    153:         if ($command eq 'objcont') {
                    154: 	    $theseres[$number]=$content;
                    155:         }
                    156:         if ($command eq 'objlinks') {
                    157:             $links[$number]=$content;
                    158:         }
                    159:     }
                    160: 
                    161: # --------------------------------------------------------------- Sort, sort of
                    162: 
1.17      www       163:     my @objsort=();
                    164:     undef @objsort;
1.16      www       165: 
1.17      www       166:     my @data1=();
                    167:     my @data2=();
                    168:     undef @data1;
                    169:     undef @data2;
                    170: 
                    171:     my $k;
                    172:     my $kj;
                    173:     my $j;
                    174:     my $ij;
                    175: 
                    176:    for ($k=1;$k<=$#theseres;$k++) {
                    177:       if (defined($theseres[$k])) {
                    178:          $objsort[$#objsort+1]=$k;
                    179:       }
                    180:    }
1.16      www       181: 
1.17      www       182:    for ($k=1;$k<=$#links;$k++) {
                    183:      if (defined($links[$k])) {
                    184:       @data1=split(/\:/,$links[$k]);
                    185:       $kj=-1;
                    186:       for (my $j=0;$j<=$#objsort;$j++) {
                    187:          if ((split(/\:/,$objsort[$j]))[0]==$data1[0]) {
                    188:             $kj=$j;
                    189:          }
                    190:       }
                    191:       if ($kj!=-1) { $objsort[$kj].=':'.$data1[1]; }
                    192:      }
                    193:    }
                    194:     for ($k=0;$k<=$#objsort;$k++) {
                    195:       for ($j=0;$j<=$#objsort;$j++) {
                    196:         if ($k!=$j) {
                    197:           @data1=split(/\:/,$objsort[$k]);
                    198:           @data2=split(/\:/,$objsort[$j]);
                    199:           my $dol=$#data1+1;
                    200:           my $dtl=$#data2+1;
                    201:           if ($dol+$dtl<1000) {
                    202:            for ($kj=1;$kj<$dol;$kj++) {
                    203:              if ($data1[$kj]==$data2[0]) {
                    204:                 for ($ij=1;$ij<$dtl;$ij++) {
                    205:                    $data1[$#data1+1]=$data2[$ij];
                    206:                 }
                    207:              }
                    208:            }
                    209:            for ($kj=1;$kj<$dtl;$kj++) {
                    210:              if ($data2[$kj]==$data1[0]) {
                    211:                  for ($ij=1;$ij<$dol;$ij++) {
                    212:                     $data2[$#data2+1]=$data1[$ij];
                    213:                  }
                    214:              }
                    215:            }
                    216:            $objsort[$k]=join(':',@data1);
                    217:            $objsort[$j]=join(':',@data2);
                    218:           }
                    219:          }
                    220:       } 
                    221:   }
                    222: # ---------------------------------------------------------------- Now sort out
1.16      www       223: 
1.17      www       224:     @objsort=sort {
                    225:       my @data1=split(/\:/,$a);
                    226:       my @data2=split(/\:/,$b);
                    227:       my $rvalue=0;
                    228:       my $k;
                    229:       for ($k=1;$k<=$#data1;$k++) {
                    230:          if ($data1[$k]==$data2[0]) { $rvalue--; }
                    231:       }
                    232:       for ($k=1;$k<=$#data2;$k++) {
                    233:          if ($data2[$k]==$data1[0]) { $rvalue++; }
                    234:       }
                    235:       if ($rvalue==0) { $rvalue=$#data2-$#data1; }
                    236:       $rvalue;
                    237:     } @objsort;
                    238: 
                    239:     my @outres=();
                    240:     undef @outres;
                    241: 
                    242:     for ($k=0;$k<=$#objsort;$k++) {
                    243: 	$outres[$k]=$theseres[(split(/\:/,$objsort[$k]))[0]];
                    244:     }
                    245:     return @outres;
1.16      www       246: }
                    247: 
1.3       www       248: # --------------------------------------------------------- Build up RAT screen
                    249: sub ratedt {
                    250:   my ($r,$url)=@_;
1.1       www       251:   $r->print(<<ENDDOCUMENT);
                    252: 
                    253: <html>
1.2       harris41  254: <head>
                    255: <script language="JavaScript">
                    256:     var flag=0;
                    257: </script>
                    258: </head>
1.1       www       259: <frameset rows="1,50,*" border=0>
                    260: <frame name=server src="$url/loadonly/ratserver" noresize noscroll>
                    261: <frame name=code src="/adm/rat/code.html">
                    262: <frame name=mapout src="/adm/rat/map.html">
                    263: </frameset>
                    264: </html>
                    265: 
                    266: ENDDOCUMENT
1.3       www       267: }
                    268: 
1.8       www       269: # ---------------------------------------------------------------- Make buttons
                    270: 
                    271: sub buttons {
                    272:     my $adv=shift;
                    273:     my $output='<form method=post>';     
                    274:     if ($adv==1) {
                    275: 	$output.='<input type=submit name=forceadv value="Edit">';
                    276:     } else {
                    277:         unless ($adv==2) {
                    278:            $output.='<input type=submit name=forcesmp value="Simple Edit">';
                    279:         }
                    280: 	$output.='<input type=submit name=forceadv value="Advanced Edit">';
                    281:     }
                    282:     return $output.'</form><hr>';
                    283: }
                    284: 
1.20      www       285: # ----------------------------------------------------------- Paste into target
                    286: # modifies @order, @resources
                    287: 
                    288: sub pastetarget {
                    289:     my ($after,@which)=@_;
                    290:     my @insertorder=();
                    291:     foreach (@which) {
                    292:         if (defined($_)) {
                    293: 	    my ($name,$url)=split(/\=/,$_);
1.21      www       294:             $name=&Apache::lonnet::unescape($name);
                    295:             $url=&Apache::lonnet::unescape($url);
                    296:             if ($url) {
                    297: 	       my $idx=$#resources+1;
                    298:                $insertorder[$#insertorder+1]=$idx;
                    299:                my $ext='false';
                    300:                if ($url=~/^http\:\/\//) { $ext='true'; }
                    301:                $url=~s/\:/\&colon;/g;
                    302:                $resources[$idx]=$name.':'.$url.':'.$ext.':normal:res';
                    303: 	   }
1.20      www       304:         }
                    305:     }
1.23      www       306:     my @oldorder=splice(@order,$after);
                    307:     @order=(@order,@insertorder,@oldorder);
1.21      www       308: }
                    309: 
                    310: # ------------------------------------------------ Get start and finish correct
                    311: # modifies @resources
                    312: 
                    313: sub startfinish {
                    314:     foreach (@order) {
                    315: 	my ($name,$url,$ext)=split(/\:/,$resources[$_]);
1.22      www       316:         if ($url=~/http\&colon\:\/\//) { $ext='true'; }
1.21      www       317:         $resources[$_]=$name.':'.$url.':'.$ext.':normal:res';
                    318:     }
1.23      www       319:    my ($name,$url,$ext)=split(/\:/,$resources[$order[0]]);
                    320:    $resources[$order[0]]=$name.':'.$url.':'.$ext.':start:res';
1.21      www       321:    my ($name,$url,$ext)=split(/\:/,$resources[$order[$#order]]);
                    322:    $resources[$order[$#order]]=$name.':'.$url.':'.$ext.':finish:res';
1.20      www       323: }
                    324: 
1.22      www       325: # ------------------------------------------------------------------- Store map
                    326: 
                    327: sub storemap {
                    328:     my $fn=shift;
                    329:     &startfinish();
                    330:     my $output='graphdef<:>no';
                    331:     my $k=1;
                    332:     for (my $i=0; $i<=$#order; $i++) {
                    333:         if (defined($resources[$order[$i]])) {
                    334: 	    $output.='<&>objcont<:>'.$order[$i].'<:>'.$resources[$order[$i]];
                    335:         }
                    336:         if (defined($order[$i+1])) {
                    337: 	    if (defined($resources[$order[$i+1]])) {
                    338:                $output.='<&>objlinks<:>'.$k.'<:>'.
                    339: 		   $order[$i].':'.$order[$i+1].':0';
                    340: 	       $k++;
                    341:             }
                    342:         }
                    343:     }
1.23      www       344:     $output=~s/http\&colon\;\/\///g;
1.22      www       345:     $ENV{'form.output'}=$output;
                    346:     return 
                    347:      &Apache::lonratsrv::loadmap($fn,&Apache::lonratsrv::savemap($fn,''));
                    348: }
                    349: 
1.32    ! www       350: sub editscript {
        !           351:     my $mode=shift;
        !           352:     return(<<ENDSCRIPT);
        !           353: var srch;
        !           354: var srchflag=-1; // 1 means currently open
        !           355:                  // 0 means closed (but has been open)
        !           356:                  // -1 means never yet opened/defined
        !           357: var srchmode='';
        !           358: 
        !           359: var idx;
        !           360: var idxflag=-1; // 1 means currently open
        !           361:                  // 0 means closed (but has been open)
        !           362:                  // -1 means never yet opened/defined
        !           363: var idxmode='';
        !           364: 
        !           365: // ------------------------------------------------------ Clears indexer window
        !           366: function idxclear() {
        !           367:   idx.document.clear();
        !           368: }
        !           369: 
        !           370: // ------------------------------------------------------- Clears search window
        !           371: function srchclear() {
        !           372:   srch.document.clear();
        !           373: }
        !           374: 
        !           375: // ------------------------------------------------------ Closes indexer window
        !           376: function idxclose() {
        !           377:   if (idx && !idx.closed) {
        !           378:     idxflag=0;
        !           379:     idx.close();
        !           380:   }
        !           381: }
        !           382: 
        !           383: // ------------------------------------------------------- Closes search window
        !           384: function srchclose() {
        !           385:   if (srch && !srch.closed) {
        !           386:     srchflag=0;
        !           387:     srch.close();
        !           388:   }
        !           389: }
        !           390: 
        !           391: // -------------------------------------------------------- Open indexer window
        !           392: function idxopen(mode) {
        !           393:    var options="scrollbars=1,resizable=1,menubar=0";
        !           394:    idxmode=mode;
        !           395:    idxflag=1;
        !           396:    idx=open("/res/?launch=1&mode=$mode&catalogmode="+mode,"idxout",options);
        !           397:    idx.focus();
        !           398: }
        !           399: 
        !           400: // --------------------------------------------------------- Open search window
        !           401: function srchopen(mode) {
        !           402:    var options="scrollbars=1,resizable=1,menubar=0";
        !           403:    srchmode=mode;
        !           404:    srchflag=1;
        !           405:    srch=open("/adm/searchcat?launch=1&mode=$mode&catalogmode="+mode,"srchout",options);
        !           406:    srch.focus();
        !           407: }
        !           408: // ----------------------------------------------------- launch indexer browser
        !           409: function groupsearch() {
        !           410:    srchcheck('groupsearch');
        !           411: }
        !           412: 
        !           413: function groupimport() {
        !           414:    idxcheck('groupimport');
        !           415: }
        !           416: // ------------------------------------------------------- Do srch status check
        !           417: function srchcheck(mode) {
        !           418:    if (!srch || srch.closed || srchmode!=mode) {
        !           419:       srchopen(mode);
        !           420:    }
        !           421:    srch.focus();
        !           422: }
        !           423: 
        !           424: // -------------------------------------------------------- Do idx status check
        !           425: function idxcheck(mode) {
        !           426:    if (!idx || idx.closed || idxmode!=mode) {
        !           427:       idxopen(mode);
        !           428:    }
        !           429:    idx.focus();
        !           430: }
        !           431: 
        !           432: 
        !           433:     var editbrowser;
        !           434:     function openbrowser(formname,elementname,only,omit) {
        !           435:         var url = '/res/?';
        !           436:         if (editbrowser == null) {
        !           437:             url += 'launch=1&';
        !           438:         }
        !           439:         url += 'catalogmode=interactive&';
        !           440:         url += 'mode=edit&';
        !           441:         url += 'form=' + formname + '&';
        !           442:         if (only != null) {
        !           443:             url += 'only=' + only + '&';
        !           444:         } 
        !           445:         if (omit != null) {
        !           446:             url += 'omit=' + omit + '&';
        !           447:         }
        !           448:         url += 'element=' + elementname + '';
        !           449:         var title = 'Browser';
        !           450:         var options = 'scrollbars=1,resizable=1,menubar=0';
        !           451:         options += ',width=700,height=600';
        !           452:         editbrowser = open(url,title,options,'1');
        !           453:         editbrowser.focus();
        !           454:     }
        !           455: ENDSCRIPT
        !           456: }
1.20      www       457: # ------------------------------------------------------- Simple edit processor
                    458: 
1.3       www       459: sub smpedt {
1.22      www       460:    my ($r,$url,$errtext)=@_;
1.8       www       461:    my $buttons=&buttons(2);
1.12      www       462: 
                    463: # ---------------------------------------------------------- Process form input
                    464: 
                    465:    my @importselect=();
                    466:    my @targetselect=();
                    467:    undef @importselect;
                    468:    undef @targetselect;
1.27      www       469:    if (defined($ENV{'form.importsel'})) {
                    470:        if (ref($ENV{'form.importsel'})) {
                    471: 	   @importselect=sort(@{$ENV{'form.importsel'}});
1.12      www       472:        } else {
1.27      www       473:            @importselect=($ENV{'form.importsel'});
1.12      www       474:        }
                    475:    }
                    476:    if (defined($ENV{'form.target'})) {
                    477:        if (ref($ENV{'form.target'})) {
1.25      www       478: 	   @targetselect=sort(@{$ENV{'form.target'}});
1.12      www       479:        } else {
                    480:            @targetselect=($ENV{'form.target'});
                    481:        }
                    482:    }
1.13      www       483: # ============================================================ Process commands
1.12      www       484: 
1.14      www       485:    my $targetdetail=$ENV{'form.targetdetail'};
                    486:    my $importdetail=$ENV{'form.curimpdetail'};
1.13      www       487: 
                    488: # ---------------------------------------------------- Importing from groupsort
1.16      www       489:    if (($ENV{'form.importdetail'}) && (!$ENV{'form.impfortarget'})) {
1.13      www       490: 
1.14      www       491:        $importdetail='';
1.13      www       492:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
                    493: 
                    494:        my $lastsel;
                    495: 
                    496:        if (defined($importselect[-1])) {
                    497: 	   $lastsel=$importselect[-1];
                    498:        } else {
                    499:            $lastsel=$#curimport;
                    500:        }
                    501: 
                    502:        for (my $i=0;$i<=$lastsel;$i++) {
                    503:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    504:            if ($url) {
1.18      www       505:               $importdetail.='&'.$name.'='.$url;
1.13      www       506: 	   }
                    507:        }
                    508: 
                    509:       $importdetail.='&'.$ENV{'form.importdetail'};
                    510: 
                    511:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
                    512:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    513:            if ($url) {
1.18      www       514:               $importdetail.='&'.$name.'='.$url;
1.13      www       515: 	  }
                    516:        }
                    517:        $importdetail=~s/\&+/\&/g;
                    518:        $importdetail=~s/^\&//;
                    519: 
1.14      www       520: # ------------------------------------------------------------------- Clear all
                    521:    } elsif ($ENV{'form.clear'}) {
                    522:        $importdetail='';
                    523: # ------------------------------------------------------------ Discard selected
                    524:    } elsif ($ENV{'form.discard'}) {
                    525:        $importdetail='';
                    526:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
                    527:        foreach (@importselect) {
                    528: 	   $curimport[$_]='';
                    529:        }
                    530:        for (my $i=0;$i<=$#curimport;$i++) {
                    531:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    532:            if ($url) {
1.18      www       533:               $importdetail.='&'.$name.'='.$url;
1.14      www       534: 	   }
                    535:        }
1.17      www       536: # --------------------------------------------------------- Loading another map
                    537:    } elsif ($ENV{'form.loadmap'}) {
                    538:        $importdetail='';
                    539:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
                    540: 
                    541:        my $lastsel;
                    542: 
                    543:        if (defined($importselect[-1])) {
                    544: 	   $lastsel=$importselect[-1];
                    545:        } else {
                    546:            $lastsel=$#curimport;
                    547:        }
                    548: 
                    549:        for (my $i=0;$i<=$lastsel;$i++) {
                    550:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    551:            if ($url) {
1.18      www       552:               $importdetail.='&'.$name.'='.$url;
1.17      www       553: 	   }
                    554:        }
                    555: 
                    556:        foreach (
1.30      www       557:     &Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
1.17      www       558: 	   my ($name,$url)=split(/\:/,$_);
                    559:            if ($url) {
                    560:               $importdetail.='&'.&Apache::lonnet::escape($name).'='.
                    561: 		 	         &Apache::lonnet::escape($url);
                    562: 	  }
                    563:        }
                    564: 
                    565:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
                    566:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    567:            if ($url) {
1.18      www       568:               $importdetail.='&'.$name.'='.$url;
1.17      www       569: 	  }
                    570:        }
                    571:        $importdetail=~s/\&+/\&/g;
                    572:        $importdetail=~s/^\&//;
                    573: 
1.20      www       574: # ------------------------------------------------ Groupimport/search to target
                    575:    } elsif ($ENV{'form.importdetail'}) {
                    576:        my $lastsel;
                    577:        if (defined($targetselect[-1])) {
                    578: 	   $lastsel=$targetselect[-1];
                    579:        } else {
1.23      www       580:            $lastsel=$#order+1;
1.20      www       581:        }
1.21      www       582:        &pastetarget($lastsel,split(/\&/,$ENV{'form.importdetail'}));
1.22      www       583:        &storemap(&Apache::lonnet::filelocation('',$url));
1.20      www       584: # ------------------------------------------------------------------------- Cut
1.25      www       585:    } elsif (($ENV{'form.cut'}) || ($ENV{'form.copy'})) {
                    586:        $importdetail='';
                    587:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
                    588: 
                    589:        my $lastsel;
                    590: 
                    591:        if (defined($importselect[-1])) {
                    592: 	   $lastsel=$importselect[-1];
                    593:        } else {
                    594:            $lastsel=$#curimport;
                    595:        }
                    596: 
                    597:        for (my $i=0;$i<=$lastsel;$i++) {
                    598:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    599:            if ($url) {
                    600:               $importdetail.='&'.$name.'='.$url;
                    601: 	   }
                    602:        }
                    603: 
                    604:        foreach (@targetselect) {
                    605: 	   my ($name,$url)=split(/\:/,$resources[$order[$_-1]]);
                    606:            if ($url) {
                    607:               $importdetail.='&'.&Apache::lonnet::escape($name).'='.
                    608: 		 	         &Apache::lonnet::escape($url);
                    609: 	  }
                    610:        }
                    611: 
                    612:        for (my $i=$lastsel+1;$i<=$#curimport;$i++) {
                    613:            my ($name,$url)=split(/\=/,$curimport[$i]);
                    614:            if ($url) {
                    615:               $importdetail.='&'.$name.'='.$url;
                    616: 	  }
                    617:        }
                    618:        $importdetail=~s/\&+/\&/g;
                    619:        $importdetail=~s/^\&//;
                    620: 
                    621:        if ($ENV{'form.cut'}) {
                    622:            my @neworder=();
                    623:            for (my $i=0;$i<=$#order;$i++) {
                    624:                my $include=1;
                    625:                foreach (@targetselect) {
                    626: 		   if ($_-1==$i) { $include=0; }
                    627:                }
                    628:                if ($include) { $neworder[$#neworder+1]=$order[$i]; }
                    629:            }
                    630:            @order=@neworder;
                    631:            &storemap(&Apache::lonnet::filelocation('',$url));      
                    632:        }
                    633: 
1.20      www       634: # ----------------------------------------------------------------------- Paste
                    635:    } elsif ($ENV{'form.paste'}) {
1.24      www       636:        my $lastsel;
                    637:        if (defined($targetselect[-1])) {
                    638: 	   $lastsel=$targetselect[-1];
                    639:        } else {
                    640:            $lastsel=$#order+1;
                    641:        }
                    642:        my @newsequence;
                    643:        my @curimport=split(/\&/,$ENV{'form.curimpdetail'});
                    644:        foreach (@importselect) {
                    645:           $newsequence[$#newsequence+1]=$curimport[$_];
                    646:        }
                    647:        &pastetarget($lastsel,@newsequence);
                    648:        &storemap(&Apache::lonnet::filelocation('',$url));
1.20      www       649: # ------------------------------------------------ 
1.13      www       650:    }
1.12      www       651: # ------------------------------------------------------------ Assemble windows
1.20      www       652:    
1.13      www       653:    my $idx=-1;
1.29      www       654:    my $importwindow=
                    655:        '<option value="-1"> ---- Import and Paste Area ---- </option>'.
                    656:      join("\n",map {
1.13      www       657:        $idx++;
                    658:        if ($_) { 
1.15      www       659:           my ($name,$url)=split(/\=/,$_);
                    660:           unless ($name) { $name=(split(/\//,$url))[-1]; }
                    661:           unless ($name) { $name='EMPTY'; }
1.13      www       662:           '<option value="'.$idx.'">'.&Apache::lonnet::unescape($name).
                    663:                                     '</option>';
                    664:       }
                    665:    } split(/\&/,$importdetail));
1.12      www       666: 
1.13      www       667:    $idx=0;
1.29      www       668:    my $targetwindow=       
                    669:        '<option value="0"> ------- Target Edit Map ------- </option>'.
                    670:      join("\n",map { 
1.13      www       671:        my ($name,$url)=split(/\:/,$resources[$_]);
1.15      www       672:        unless ($name) {  $name=(split(/\//,$url))[-1]; }
                    673:        unless ($name) { $name='EMPTY'; }
1.13      www       674:        $targetdetail.='&'.&Apache::lonnet::escape($name).'='.
                    675: 	                  &Apache::lonnet::escape($url);
                    676:        $idx++;
1.20      www       677:        '<option value="'.$idx.'">'.$name.'</option>';
1.11      www       678:    } @order);
                    679: 
1.8       www       680: # ----------------------------------------------------- Start simple RAT screen
1.32    ! www       681:    my $editscript=&editscript('simple');
1.3       www       682:    $r->print(<<ENDSMPHEAD);
                    683: <html>
1.6       www       684: <head>
                    685: <script>
1.15      www       686: 
1.32    ! www       687:    $editscript
1.19      www       688: 
                    689:    function openview(entry) {
                    690:        var url=unescape((entry.split('='))[1]);
1.20      www       691:        var parts=new Array;
                    692:        parts=url.split('&colon;');
                    693:        url=parts.join(':');
1.19      www       694:        if (url) { open(url,'cat'); }
                    695:    }
                    696: 
                    697:    function viewtarget() {
                    698:        openview((document.forms.simpleedit.targetdetail.value.split('&'))
                    699:                 [document.forms.simpleedit.target.selectedIndex+1]);
                    700:    }
                    701: 
                    702:    function viewimport() {
                    703:        openview((document.forms.simpleedit.curimpdetail.value.split('&'))
1.27      www       704:                 [document.forms.simpleedit.importsel.selectedIndex+1]);
1.19      www       705:    }
                    706: 
1.6       www       707: </script>
                    708: </head>                 
1.3       www       709: <body bgcolor='#FFFFFF'>
1.8       www       710: $buttons
1.7       www       711: <font color=red>$errtext</font>
1.29      www       712: <h1>$url</h1>
1.13      www       713: <form name=simpleedit method=post>
1.11      www       714: <input type=hidden name=forcesmp value=1>
                    715: <table>
1.12      www       716:     <tr><th width="40%">Import</th>
                    717: <th>&nbsp;</th>
                    718: <th width="40%">Target</th></tr>
                    719: <tr><td bgcolor="#FFFFCC">
                    720: <input type=button onClick="javascript:groupsearch()" value="Group Search">
1.13      www       721: <input type=button onClick="javascript:groupimport();" value="Group Import">
1.15      www       722: after selected
1.14      www       723: <hr>
1.15      www       724: <input type=text size=20 name=importmap>
                    725: <input type=button 
                    726: onClick="javascript:openbrowser('simpleedit','importmap','sequence,page','')"
                    727: value="Browse"><input type=submit name=loadmap value="Load Map"><hr>
1.14      www       728: <input type=submit name="discard" value="Discard Selected">
                    729: <input type=submit name="clear" value="Clear All">
1.12      www       730: <input type=button onClick="javascript:viewimport()" value="View">
1.16      www       731: 
1.12      www       732:     </td><td>&nbsp;</td><td bgcolor="#FFFFCC">
1.16      www       733: 
                    734: <input type=button onClick=
                    735: "javascript:impfortarget.value=1;groupsearch()" value="Group Search">
                    736: <input type=button onClick=
                    737: "javascript:impfortarget.value=1;groupimport();" value="Group Import">
                    738: after selected
                    739: <hr><input type=button onClick="javascript:viewtarget()" value="View">
1.12      www       740: </td></tr>
1.16      www       741: 
1.27      www       742: <tr><td bgcolor="#FFFFCC"><select name="importsel" size=10 multiple>
1.12      www       743: $importwindow
                    744: </select>
1.11      www       745: </td>
1.12      www       746: <td bgcolor="#FFFFAA" align="center">
                    747: Cut selected<br>
1.11      www       748: <input type=submit name=cut value='<<<'><p>
1.12      www       749: <hr>
1.25      www       750: Copy selected<br>
                    751: <input type=submit name=copy value='<--'><p>
                    752: <hr>
1.12      www       753: Paste after selected<br>
1.25      www       754: <input type=submit name=paste value='-->'>
1.11      www       755: </td>
1.27      www       756: <td bgcolor="#FFFFCC"><select name="target" size=10 multiple>
1.11      www       757: $targetwindow
                    758: </select>
1.12      www       759: </table>
1.13      www       760: <input type=hidden name=importdetail value="">
                    761: <input type=hidden name=curimpdetail value="$importdetail">
1.12      www       762: <input type=hidden name=targetdetail value="$targetdetail">
1.16      www       763: <input type=hidden name=impfortarget value="0">
1.12      www       764: </form>
                    765: </body></html>
1.3       www       766: ENDSMPHEAD
                    767: }
                    768: 
1.11      www       769: # ----------------------------------------------------------------- No such dir
1.4       www       770: sub nodir {
                    771:    my ($r,$dir)=@_;
                    772:    $dir=~s/^\/home\/\w+\/public\_html//;
                    773:    $r->print(<<ENDNODIR);
                    774: <html>
                    775: <body bgcolor='#FFFFFF'>
                    776: <h1>No such directory: $dir</h1>
                    777: </body>
                    778: </html>
                    779: ENDNODIR
                    780: }
                    781: 
1.8       www       782: # ---------------------------------------------------------------- View Handler
                    783: 
                    784: sub viewmap {
1.17      www       785:     my ($r,$url,$adv,$errtext)=@_;
1.28      www       786:     $r->print('<html><body bgcolor="#FFFFFF">'.&buttons($adv));
1.10      www       787:     if ($errtext) {
                    788: 	$r->print($errtext.'<hr>');
                    789:     }
1.26      www       790:     my $idx=0;
1.17      www       791:     foreach (&attemptread(&Apache::lonnet::filelocation('',$url))) {
1.9       www       792: 	if (defined($_)) {
1.26      www       793:             $idx++;
1.9       www       794: 	    my ($title,$url)=split(/\:/,$_);
                    795:             $title=~s/\&colon\;/\:/g;
                    796:             $url=~s/\&colon\;/\:/g;
1.15      www       797:             unless ($title) { $title=(split(/\//,$url))[-1] };
                    798:             unless ($title) { $title='<i>Empty</i>'; }
1.9       www       799:             if ($url) {
                    800: 		$r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
                    801:             }
                    802:             $r->print(&Apache::lonratsrv::qtescape($title));
                    803:             if ($url) { $r->print('</a>'); }
1.28      www       804: 	    $r->print('<br>');
1.9       www       805:         }
                    806:     }
1.8       www       807:     $r->print('</body></html>');
                    808: }
                    809: 
1.3       www       810: # ================================================================ Main Handler
                    811: 
                    812: sub handler {
                    813:   my $r=shift;
                    814:   $r->content_type('text/html');
                    815:   $r->send_http_header;
                    816: 
                    817:   return OK if $r->header_only;
                    818: 
                    819:   my $url=$r->uri;
                    820:   my $fn=&Apache::lonnet::filelocation('',$url);
                    821: 
1.4       www       822:   my ($dir)=($fn=~/^(.+)\/[^\/]+$/);
                    823:   unless (-e $dir) {
                    824:       &nodir($r,$dir);
                    825:       return OK;
                    826:   }
1.8       www       827: 
                    828: # ------------------------------------------- Determine which tools can be used
1.3       www       829:   my $adv=0;
                    830: 
                    831:   unless ($ENV{'form.forcesmp'}) {
                    832:      if ($ENV{'form.forceadv'}) {
                    833:         $adv=1;
                    834:      } elsif (my $fh=Apache::File->new($fn)) {
                    835: 	 my $allmap=join('',<$fh>);
                    836:          $adv=($allmap=~/\<map[^\>]+mode\s*\=\s*(\'|\")rat/is);
                    837:      }
                    838:   }
                    839: 
1.8       www       840:   my $errtext='';
                    841:   my $fatal=0;
                    842: 
                    843: # -------------------------------------------------------------------- Load map
                    844:   ($errtext,$fatal)=&mapread($fn,$errtext);
                    845: 
                    846:   if ($fatal==1) { $adv=1; }
                    847: 
                    848: # ----------------------------------- adv==1 now means "graphical MUST be used"
                    849: 
                    850:   if ($ENV{'form.forceadv'}) {
1.3       www       851:       &ratedt($r,$url);
1.8       www       852:   } elsif ($ENV{'form.forcesmp'}) {
1.22      www       853:       &smpedt($r,$url,$errtext);
1.3       www       854:   } else {
1.17      www       855:       &viewmap($r,$url,$adv,$errtext);
1.3       www       856:   }
1.1       www       857:   return OK;
                    858: }
                    859: 
                    860: 1;
                    861: __END__
                    862: 
                    863: 
                    864: 
                    865: 
                    866: 
                    867: 
                    868: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.