<?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 uid, pwd, addrs any;
 declare elm glocation;
 declare addr, tmp any;
 declare res, sp any;
 declare i int;

 uid := get_keyword ('uid', params, '');
 pwd := get_keyword ('pwd', params, '');
 addrs := get_keyword ('addrs', params, '');

 addrs := trim (addrs);

 if (not length (addrs) and {?'go'} is not null)
   signal ('22023', 'No address is given.');

 tmp := split_and_decode (addrs, 0, '\0\0\n');
 addr := vector ();

 foreach (any it in tmp) do
  {
    it := trim (it, '\r\n ');
    if (length (it))
      {
        if (i = 0)
          sp := it;
        else
          addr := vector_concat (addr, vector (it));
        i := i + 1;
      }
  }

 res := vector ();
 if ({?'go'} is not null)
   {
     res := gcalculate (sp, addr, uid, pwd);
   }

?>
<html>
  <head><link rel="stylesheet" type="text/css" href="../demo.css" /></head>
  <body>
    <h3>Route Planner demo</h3>
    <form action="mappoint.vsp" method="post">
    <table class="tableentry">
	<tr>
          <td>
	    1. Enter a list of addresses, <br>every address must be on a single line.<br>
	       First line muste be start point <br> rest are destinations.
	  </td>
          <td>
	    <textarea name="addrs" cols="60" rows="6"><?=addrs?></textarea>
	  </td>
        </tr>
	<tr>
          <td>
            2. Enter username for MS Mappoint service
	  </td>
          <td>
            <input type="text" name="uid" value="<?=uid?>"/>
	  </td>
        </tr>
	<tr>
          <td>
            3. Enter password for MS Mappoint service
	  </td>
          <td>
            <input type="text" name="pwd" value="<?=pwd?>"/>
	  </td>
        </tr>
	<tr>
          <td>
            4. Execute the call
	  </td>
          <td>
            <input type="submit" name="go" value="Calculate"/>
	  </td>
        </tr>
     </table>
    </form>
    <table class="tableresult">
    <th>Address</th><th>Latitude</th><th>Longitude</th>
    <?vsp
       foreach (glocation loc in res) do
         {
    ?>
    <tr><td><?=loc.name?></td><td><?=loc.x?></td><td><?=loc.y?></td></tr>
    <?vsp
	 }
    ?>
    </table>
  </body>
</html>
