<?vsp 
--  
--  $Id: vs_u_7_sample_3.vsp,v 1.2.2.1 2012/03/08 12:55:16 source Exp $
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2012 OpenLink Software
--  
--  This project is free software; you can redistribute it and/or modify it
--  under the terms of the GNU General Public License as published by the
--  Free Software Foundation; only version 2 of the License, dated June 1991.
--  
--  This program is distributed in the hope that it will be useful, but
--  WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
--  General Public License for more details.
--  
--  You should have received a copy of the GNU General Public License along
--  with this program; if not, write to the Free Software Foundation, Inc.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--  
--  

  declare sid, id varchar;
  declare cr dynamic cursor for  select c.CompanyName, c.Phone, c.Fax, c.CustomerID, o.OrderID, o.ShippedDate , od.ProductID, od.Quantity from demo..Customers c , demo..Orders o, demo..Order_Details od where c.CompanyName like 'A%' and o.CustomerID = c.CustomerID and od.OrderID = o.OrderID order by c.CustomerID;
  declare bm any;
  declare i, f integer;
  declare cn, ph, fax, cid, oid, sd, pid, qu varchar;

  sid := {?'sid'};

  if (sid is null)
    {
      if ((sid := connection_get ('sid')) is null)
	sid := '';
      http_request_status ('HTTP/1.1 302 Found');
      http_header (sprintf ('Location: vs_u_7_sample_3.vsp?sid=%s\r\n', sid));
      http (sprintf ('<HTML>
	                <BODY>
			  <p>The document moved <a href="vs_u_7_sample_3.vsp?sid=%s">here</a>.</p>
			</BODY>
	  	     </HTML>', sid));
      return;
    }

  open cr;
  if ((bm := deserialize(connection_get ('bm'))) is null)
    {
      fetch cr first into cn, ph, fax, cid, oid, sd, pid, qu;
      f := 0;
    }
  else
    {
      fetch cr bookmark bm into cn, ph, fax, cid, oid, sd, pid, qu;
      f := 1;
    }

  if ({?'prev'} = '1')
    {
      i := 0;
      declare exit handler for not found { bm := null; f:= 0;  goto nf1; };
      while (i < (20 + connection_get ('fetched')))
	{
	  fetch cr previous into cn, ph, fax, cid, oid, sd, pid, qu;
          i := i + 1;
	}
nf1:;
    }

?>

<HTML>
  <head>
    <link rel="stylesheet" type="text/css" href="/tutorial/web/demo.css">
  </head>
  <BODY>
   <H3>Scrollable page using the dynamic cursor</H3>

   <table class="tableresult">
   <th>CustomerName</th>
   <th>Phone</th>
   <th>Fax</th>
   <th>CustomerID</th>
   <th>OrderID</th>
   <th>ShippedDate</th>
   <th>ProductID</th>
   <th>Quantity</th>
   <?vsp
      i := 0;
      declare exit handler for not found { f := 2; goto nf; };
      while (i < 20)
        {
   ?>

   <tr>
      <td><?=cn?></td>
      <td><?=ph?></td>
      <td><?=fax?></td>
      <td><?=cid?></td>
      <td><?=oid?></td>
      <td><?=sd?></td>
      <td><?=pid?></td>
      <td><?=qu?></td>
   </tr>

   <?vsp
          fetch cr next into cn, ph, fax, cid, oid, sd, pid, qu;
          bm := bookmark(cr);
          i := i + 1;
	}
      nf:
      connection_set ('bm', serialize(bm));
      connection_set ('fetched', i);


   ?>
   <tr>
   <?vsp
          if (f <> 0)
            {
   ?>
   <td><a href="vs_u_7_sample_3.vsp?sid=<?=sid?>&prev=1">&lt;&lt;back</a></td>
   <?vsp
	    }
          else
	    http ('<td>&nbsp;</td>');
          if (f <> 2)
            {
   ?>
   <td><a href="vs_u_7_sample_3.vsp?sid=<?=sid?>">&gt;&gt;next</a></td>
   <?vsp
	    }
          else
	    http ('<td>&nbsp;</td>');
   ?>
   </tr>
   </table>
  </BODY>
</HTML>
