<?vsp 
--  
--  $Id$
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2018 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, fn, ln varchar;
  declare cr static cursor for select ProductName, UnitPrice from Demo.demo.Products;
  declare bm any;
  declare i, f integer;

  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_1.vsp?sid=%s\r\n', sid));
      http (sprintf ('<HTML>
	                <BODY>
			  <p>The document moved <a href="vs_u_7_sample_1.vsp?sid=%s">here</a>.</p>
			</BODY>
	  	     </HTML>', sid));
      return;
    }

  open cr;
  if ((bm := deserialize(connection_get ('bm'))) is null)
    {
      fetch cr first into fn, ln;
      f := 0;
    }
  else
    {
      fetch cr bookmark bm into fn, ln;
      f := 1;
    }

  if ({?'prev'} = '1')
    {
      i := 0;
      declare exit handler for not found { bm := null;;  goto nf1; };
      while (i < (20 + connection_get ('fetched')))
	{
	  fetch cr previous into fn, ln;
          i := i + 1;
	}
nf1:;
    }

?>

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

   <table class="tableresult">
   <th>Product</th><th>Unit Price</th>
   <?vsp
      i := 0;
      declare exit handler for not found { f := 2; goto nf; };
      while (i < 20)
        {
   ?>

   <tr><td><?=fn?></td><td><?=ln?></td></tr>

   <?vsp
          fetch cr next into fn, ln;
          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_1.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_1.vsp?sid=<?=sid?>">&gt;&gt;next</a></td>
   <?vsp
	    }
          else
	    http ('<td>&nbsp;</td>');
   ?>
   </tr>
   </table>
  </BODY>
</HTML>
