<?vsp 
--  
--  $Id: currency_list.vsp,v 1.3 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
--  
--  
?>
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="AUTHOR" content="James Chin (jchin@openlinksw.com), OpenLink Software">
<meta HTTP-EQUIV="Pragma" CONTENT="no-cache">
</head>
<body>
<?vsp
  declare _list, _result, _path, _out, r any;
  declare _amount, _from, _to varchar;
  declare _error integer;
  _amount := get_keyword('Amount', params, '1');
  _from := get_keyword('ConvertFrom', params, 'USD');
  _to := get_keyword('ConvertTo', params, 'USD');

  _out := string_output();
  _error := 0;
  doitagain: ;
  declare exit handler for sqlstate '*' { r := __SQL_MESSAGE; _error := _error + 1; if (_error > 4) goto endf; else goto doitagain; };
  {
    _result := soap_call(sprintf('localhost:%s', server_http_port()), '/exchange', null, 'currencyList', vector('names', ''), 11);
  }
  declare exit handler for sqlstate '*' { r := '** no result returned **'; goto endf;};
  {
    r := _result[1][1];
    _list :=xml_tree_doc(xml_tree(_result[1][1]));

    _path := TUTORIAL_XSL_DIR () || '/tutorial/services/so_s_15/currency_list.xsl';

    http('<h2><font face="Helvetica">Currency Exchange Rate Converter</font></h2>\r\n<font size="3" face="Verdana, Arial, sans-serif"><form action="conversion.vsp" method="POST" target="exchangebottom">\r\n', _out);
    http(sprintf('Convert&nbsp;<input type="text" name="Amount" value="%s">&nbsp;', _amount), _out);
    http_value(xslt(_path, _list, vector('selectionname', 'ConvertFrom', 'selvalue', _from)), 0, _out);
    http('&nbsp;into&nbsp;', _out);
    http_value(xslt(_path, _list, vector('selectionname', 'ConvertTo', 'selvalue', _to)), 0, _out);
    http('&nbsp;<input type="submit" name="Convert" value="Convert">', _out);
    http('\r\n</form>\r\n</font>',_out);
    http(string_output_string(_out));
  }
  http('</body></html>');
  return 0;
  endf: http(r);
  http('</body></html>');
?>
