Diff for /rat/lonratedt.pm between versions 1.7 and 1.9

version 1.7, 2002/05/10 15:42:16 version 1.9, 2002/05/10 19:46:52
Line 37  use Apache::Constants qw(:common); Line 37  use Apache::Constants qw(:common);
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::lonratsrv;  use Apache::lonratsrv;
   
   my @links=();
   my @resources=();
   
   
   # Mapread read maps into global arrays @links and @resources, determines status
   
   sub mapread {
       my $fn=shift;
   
       undef @links;
       undef @resources;
   
       my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,'');
       if ($errtext) { return ($errtext,2); }
   
   # -------------------------------------------------------------------- Read map
       foreach (split(/\<\&\>/,$outtext)) {
    my ($command,$number,$content)=split(/\<\:\>/,$_);
           if ($command eq 'objcont') {
       $resources[$number]=$content;
           }
           if ($command eq 'objlinks') {
               $links[$number]=$content;
           }
       }
   # ------------------------------------------------------- Is this a linear map?
       my @starters=();
       my @endings=();
       undef @starters;
       undef @endings;
   
       foreach (@links) {
           if (defined($_)) {
       my ($start,$end,$cond)=split(/\:/,$_);
               if ((defined($starters[$start])) || (defined($endings[$end]))) { 
    return
                    ('Map too complex, has branchings. Use advanced editor.',1);
               }
       $starters[$start]=1;
       $endings[$end]=1;
       if ($cond) {
    return
                    ('Map too complex, has conditions. Use advanced editor.',1);
               }
    }
   
       }
       return $errtext;
   }
   
 # --------------------------------------------------------- Build up RAT screen  # --------------------------------------------------------- Build up RAT screen
 sub ratedt {  sub ratedt {
   my ($r,$url)=@_;    my ($r,$url)=@_;
Line 58  sub ratedt { Line 108  sub ratedt {
 ENDDOCUMENT  ENDDOCUMENT
 }  }
   
   # ---------------------------------------------------------------- Make buttons
   
   sub buttons {
       my $adv=shift;
       my $output='<form method=post>';     
       if ($adv==1) {
    $output.='<input type=submit name=forceadv value="Edit">';
       } else {
           unless ($adv==2) {
              $output.='<input type=submit name=forcesmp value="Simple Edit">';
           }
    $output.='<input type=submit name=forceadv value="Advanced Edit">';
       }
       return $output.'</form><hr>';
   }
   
 sub smpedt {  sub smpedt {
    my ($r,$fn)=@_;     my ($r,$errtext)=@_;
    my $errtext='';     my $buttons=&buttons(2);
    my ($outtext,$errtext)=&Apache::lonratsrv::loadmap($fn,$errtext);  # ----------------------------------------------------- Start simple RAT screen
    my @loadelements=split(/\<\&\>/,$outtext);  
    $r->print(<<ENDSMPHEAD);     $r->print(<<ENDSMPHEAD);
 <html>  <html>
 <head>  <head>
Line 148  function idxcheck(mode) { Line 213  function idxcheck(mode) {
 </script>  </script>
 </head>                   </head>                 
 <body bgcolor='#FFFFFF'>  <body bgcolor='#FFFFFF'>
 <form method=post>  $buttons
 <input type=submit name=forceadv   
 value="Advanced Map Editing - Graphical Resource Assembly Tool"><hr>  
 <font color=red>$errtext</font>  <font color=red>$errtext</font>
 <a href="javascript:groupsearch()">Group Search</a>  <a href="javascript:groupsearch()">Group Search</a>
 <a href="javascript:groupimport()">Group Import</a>  <a href="javascript:groupimport()">Group Import</a>
   
 ENDSMPHEAD  ENDSMPHEAD
     $r->print('<pre>');  
    foreach (@loadelements) { $r->print($_."\n") }  
      $r->print('</pre>');  
     $r->print(      $r->print(
       '<input type=submit name=forcesmp value="Store"></form></body></html>');        '<input type=submit name=forcesmp value="Store"></form></body></html>');
 }  }
Line 175  sub nodir { Line 236  sub nodir {
 ENDNODIR  ENDNODIR
 }  }
   
   # ---------------------------------------------------------------- View Handler
   
   sub viewmap {
       my ($r,$adv)=@_;
       $r->print('<html><body bgcolor="#FFFFFF">'.&buttons($adv));
       foreach (@resources) {
    if (defined($_)) {
       my ($title,$url)=split(/\:/,$_);
               $title=~s/\&colon\;/\:/g;
               $url=~s/\&colon\;/\:/g;
               unless ($title) { $title='<i>Unknown</i>'; }
               if ($url) {
    $r->print('<a href="'.&Apache::lonratsrv::qtescape($url).'">');
               }
               $r->print(&Apache::lonratsrv::qtescape($title));
               if ($url) { $r->print('</a>'); }
               $r->print('<br>');
           }
       }
       $r->print('</body></html>');
   }
   
 # ================================================================ Main Handler  # ================================================================ Main Handler
   
 sub handler {  sub handler {
Line 192  sub handler { Line 275  sub handler {
       &nodir($r,$dir);        &nodir($r,$dir);
       return OK;        return OK;
   }    }
   
   # ------------------------------------------- Determine which tools can be used
   my $adv=0;    my $adv=0;
   
   unless ($ENV{'form.forcesmp'}) {    unless ($ENV{'form.forcesmp'}) {
Line 203  sub handler { Line 288  sub handler {
      }       }
   }    }
   
   if ($adv) {    my $errtext='';
     my $fatal=0;
   
   # -------------------------------------------------------------------- Load map
     ($errtext,$fatal)=&mapread($fn,$errtext);
   
     if ($fatal==1) { $adv=1; }
   
   # ----------------------------------- adv==1 now means "graphical MUST be used"
   
     if ($ENV{'form.forceadv'}) {
       &ratedt($r,$url);        &ratedt($r,$url);
     } elsif ($ENV{'form.forcesmp'}) {
         &smpedt($r,$errtext);
   } else {    } else {
       &smpedt($r,$fn);        &viewmap($r,$adv);
   }    }
   return OK;    return OK;
 }  }

Removed from v.1.7  
changed lines
  Added in v.1.9


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