<?vsp 
--  
--  $Id$
--  
--  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 result, ses, r, sel, _use_stored, val varchar;
   declare idx, len integer;
   declare _list any;
   r := ''; sel := '';
   -- When hosted in dav we set the 'Content' value to empty, because string_session will crate problems
   declare _params any;
   _params := vector();
   for (declare i int,i:=0;i<length(params);i:=i+2)
     if (params[i] <> 'Content')
       _params := vector_concat(_params,vector(params[i],params[i+1]));
   params := _params;
   _use_stored := {?'use_stored'};
   if (_use_stored is NULL)
     params := vector_concat (params, vector ('use_stored', NULL));
   if ({?'exec'} = 'Get data')
   {
      declare exit handler for sqlstate '*' { r := __SQL_MESSAGE; goto endf; };
       {
	 result := soap_call (sprintf ('localhost:%s', server_http_port ()), '/SOAP_SO_S_11/', null, 'administrative_divisions', params, 11);
       }
      declare exit handler for sqlstate '*' { r := '** no result returned **'; goto endf; };
       {
	 r := result[1][1];
	 http (r);
	 http_xslt (TUTORIAL_XSL_DIR() || '/tutorial/services/so_s_11/sr.xsl', params);
	 return 0;
       }
   }
endf:
?>
<html>
<HEAD><link rel="stylesheet" type="text/css" href="../demo.css" /></HEAD>
<body>
<H3>SOAP client</H3>
<?vsp
  if (r <> '')
    http_value (r,'pre');
?>
<form method="post" name="so_s_11_c2" action="so_s_11_client.vsp">
<table class="tableentry">
<tr><td>1. Use the stored data </td><td><input type="checkbox" <?vsp if (_use_stored = 'on') http ('CHECKED'); ?> name="use_stored" onClick="javascript:document.so_s_11_c2.submit();"></td></tr>
<tr><td>2. Select a country to get the administrative divisions</td><td>
<input type="hidden" name="province" value="">
<select name="country">
<?vsp
    _list := vector ();
    if (_use_stored = 'on')
      for select c_name from countries_xml do {_list := vector_concat (_list, vector (c_name));}
    else
      for select c_name from countries do {_list := vector_concat (_list, vector (c_name));}
    len := length (_list);
    idx := 0;
    while (idx < len)
     {
       val := _list[idx];
       if (upper(val) = 'UNITED STATES') sel := 'SELECTED'; else  sel := '';
?>
<option value="<?=val?>" <?=sel?>><?=val?></option>
<?vsp
       idx := idx + 1;
     }
?>
</select>
</td></tr>
<tr><td>3. Call the administrative_divisions</td><td><input type="submit" name="exec" value="Get data"></td></tr>
</table>
</form>

</body>
</html>

