File:  [LON-CAPA] / rat / lonratedt.pm
Revision 1.23: download - view: text, annotated - select for diffs
Tue May 21 13:41:13 2002 UTC (21 years, 11 months ago) by www
Branches: MAIN
CVS tags: HEAD
Group import seems to work now.

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

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