<?php
/* 
 * Sample for testing eMS parameters
 */
include_once('ems_functions.inc.php');

session_start();

if ($_REQUEST['MsgId'])
{
    if ($_REQUEST['System']=='Abnahme') $ems_cfg=$ems_abn;
    else if ($_REQUEST['System']=='Produktion') $ems_cfg=$ems_prod;
    $ret = EMS_Initiate($_REQUEST);
    if ($ret['ErrorMsg'] || !$ret['RedirectURL']) die($ret['ErrorMsg']);
    $_SESSION['emsReq']=$ret;
    if (!headers_sent()) header("Location:".$ret['RedirectURL']); else echo "<META HTTP-EQUIV=Refresh CONTENT=\"1; URL=".$ret['RedirectURL']."\">";
    unset($_SESSION['emsReq']['RedirectURL']);
    exit;
}
$MsgId=EMS_NewMsgId();
?>
<html>
<head>
  <title>eMS test</title>
  <script language="Javascript">
  function Fill(what)
  {
   var f=document.forms[0];
   f.elements[what+'[Nm]'].value='Mist Käfer';
   f.elements[what+'[Ctry]'].value='AT';
   f.elements[what+'[AdrLine][0]'].value='Misthaufenweg 14';
   f.elements[what+'[AdrLine][1]'].value='1230 Müllstadt';
  }
  </script>
</head>
<body>
<?php
if ($_REQUEST['rsp'])
{
    echo "<b>Result:</b>";
    print_r(EMS_Status($_SESSION['emsReq']));
}
?>
<form action="test.php">
<table>
<tr><td>System:</td><td><select name=System><option>Test</option><option>Abnahme</option><option>Produktion</option></select></td></tr>
<tr><td>MsgId:</td><td><input name=MsgId type=text size=10 value="<?=$MsgId?>"></td></tr>
<tr><td>MndtId:</td><td><input name=MndtId type=text size=35></td></tr>
<tr><td>Lang:</td><td><input name=Lang type=text size=6 value="<?=$ems_cfg['Lang']?>"></td></tr>
<tr><td>ExpirationTime:</td><td><input name=ExpirationTime size=2 value="<?=$ems_cfg['ExpirationTime']?>"> Min.</td></tr>
<tr><td>LclInstrm:</td><td><select name="LclInstrm"><option>CORE</option><option>B2B</option><option>invalid</option></select></td></tr>
<tr><td>Ocrncs:</td><td><select name="Ocrncs"><option>FRST</option><option selected>RCUR</option><option>OOFF</option><option>FNAL</option><option>invalid</option></select></td></tr>
<tr><td>ReturnUrl:</td><td><input name=ReturnUrl size=100 value="http://<?=$_SERVER['HTTP_HOST'].$PHP_SELF.'?rsp=1&amp;amp;PHPSESSID='.session_id()?>"></td></tr>
<tr><td>UltmtCdtr:<br><input type=button value='Fill'  onclick="Fill('UltmtCdtr')"></td><td><table>
  <tr><td>Name:</td><td><input name="UltmtCdtr[Nm]" size=70></td></tr>
  <tr><td>Ctry:</td><td><input name="UltmtCdtr[Ctry]" size=2></td></tr>
  <tr><td>AdrLine:</td><td><input name="UltmtCdtr[AdrLine][0]" size=70></td></tr>
  <tr><td></td><td><input name="UltmtCdtr[AdrLine][1]" size=70></td></tr>
</table></td></tr>
<tr><td>UltmtDbtr:<br><input type=button value='Fill'  onclick="Fill('UltmtDbtr')"></td><td><table>
  <tr><td>Name:</td><td><input name="UltmtDbtr[Nm]" size=70></td></tr>
  <tr><td>Ctry:</td><td><input name="UltmtDbtr[Ctry]" size=2></td></tr>
  <tr><td>AdrLine:</td><td><input name="UltmtDbtr[AdrLine][0]" size=70></td></tr>
  <tr><td></td><td><input name="UltmtDbtr[AdrLine][1]" size=70></td></tr>
</table></td></tr>
<tr><td>RfrdDoc:</td><td><input name=RfrdDoc size=25></td></tr>
</table>
<input type=submit>
</form></body></html>
