<?vsp 
--  
--  $Id: vs_u_7_sample_2.vsp,v 1.2 2006/08/15 19:30:34 source Exp $
--  
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2006 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 keyset cursor for select CompanyName, ContactName from Demo.demo.Customers;
  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_2.vsp?sid=%s\r\n', sid));
      http (sprintf ('<HTML>
	                <BODY>
			  <p>The document moved <a href="vs_u_7_sample_2.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; f:= 0;  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 keyset cursor</H3>

   <table class="tableresult">
   <th>CompanyName</th><th>ContactName</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_2.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_2.vsp?sid=<?=sid?>">&gt;&gt;next</a></td>
   <?vsp
	    }
          else
	    http ('<td>&nbsp;</td>');
   ?>
   </tr>
   </table>
  </BODY>
</HTML>
