<?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
--  
--  
?>
<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, '');
  _from := get_keyword('ConvertFrom', params, '');
  _to := get_keyword('ConvertTo', params, '');

  if (get_keyword('Convert', params, '') <> '')
  {
     -- 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;
    _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, 'convertRate', params, 11);
    }
    declare exit handler for sqlstate '*' { r := '** no result returned **'; goto endf; };
    {
      r := xml_tree_doc(xml_tree(_result[1][1]));
      _path := TUTORIAL_XSL_DIR () || '/tutorial/services/so_s_15/converted_value.xsl';

      http_value(xslt(_path, r, vector('oldvalue', {?'Amount'})));
    }
    r :=_result[1][1];
    http('<br><br>');
  }
?>
<font color="#AAAAAA" size="1" face="Helvetica">Powered by Virtuoso's web-services features.</font>
<?vsp
  http('\r\n</body></html>');
  return 0;
  endf: http_value(r);
  http('\r\n</body></html>');
?>
