<?php

require_once('lib/nusoap.php');

$site 'http://sandbox.didww.com/api/?wsdl';
$error 0;
$client = new soapclient($sitetrue);
$err $client->getError();
if (
$err)
{
    echo 
'ERROR: <pre>' $err '</pre>';
}

$username        'username@domain.com';        // Reseller username
$_key            '122345678909';                // Reseller authentication key 
$auth_string    sha1($username.$_key."sandbox");// Build unique key



if ($_POST)
{
    if (
$_POST['list'])
    {
        if (
$_POST['co_id'] == ""
        {
            echo 
'ERROR: Wrong country ID';
            
$error 1;
        }
        
        if (!
$err)
        {
            
$arr = array();
            
$arr[0] = $auth_string;
            
$arr[1] = $_POST['co_id'];
            
            
$result2 $client->call('getcities'$arr);
            if (
$client->fault
            {
                
$error 1;
                echo 
'ERROR: <pre>';
                
print_r($result2);
                echo 
'</pre>';
            } 
            else 
            {
                
$err $client->getError();
                if (
$err
                {
                    
$error 1;
                    echo 
'ERROR: <pre>' $err '</pre>';
                } 
            }
        }
    }
}

$result $client->call('getcountries'$auth_string);

if (
$client->fault
{
    
$error 1;
    echo 
'ERROR: <pre>';
    
print_r($result);
    echo 
'</pre>';

else 
{
    
    
$err $client->getError();
    if (
$err
    {
        
$error 1;
        echo 
'ERROR: <pre>' $err '</pre>';
    } 
}

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>DID World Wide: API Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css.css" rel="stylesheet" type="text/css">
</head>
<br><br>
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php if ($error == 0) { ?>
<table width="30%" border="0" cellspacing="0" cellpadding="0" class="main" align="center">
<form name="getcountries" action="coverage.php" method="post">
<input name="list" value="1" type="hidden">
<tr>
    <td colspan="3" align="center" class="theader">&nbsp;</td>
</tr>
<tr>
    <td class="datatdh">Select country:</td>
    <td class="datatd">
        <select name="co_id" onChange="this.form.submit();"> 
            <option value="" selected>Select country</option>
            <?php for ($c =0$c count($result);$c++) { ?>
                <option value="<?php echo $result[$c]['country_id']; ?><?php if ($_POST['co_id'] ==  $result[$c]['country_id']) echo 'selected';?>><?php echo $result[$c]['country_prefix']." - "$result[$c]['country_name']; ?></option>;
            <?php ?>
        </select>
    </td>
    <td class="datatd"><input type="submit" class="bsubmit" name="list"  value="List cities"></td>
</tr>
</form>
</table>
<br>
<?php if ($error == && count($result2) > 0) { ?>
<table width="30%" border="0" cellspacing="0" cellpadding="0" class="main" align="center">
<tr>
    <td colspan="13" align="center" class="theader" nowrap>&nbsp;</td>
</tr>
<tr>
    <td class="datatdt" align="center">City prefix</td>    
    <td class="datatdt" align="center">Cities</td>    
    <td class="datatdt" align="center">Price</td>
    <td class="datatdt">&nbsp;</td>
</tr>
<?php for($i=0$i<count($result2); $i++){ ?>
<form name="order" action="order.php" method="post">
<input type="hidden" name="uniq" value="<?php echo $result2[$i]['uniq'];?>">
<tr>
    <td class="datatd" align="center" nowrap><?php echo $result2[$i]['city_prefix']; ?></td>
    <td class="datatd" align="center" nowrap><?php echo $result2[$i]['city_name']; ?></td>
    <td class="datatd" align="center" nowrap><?php  echo sprintf("%01.2f"$result2[$i]['monthly']); ?></td>
    <td class="datatdt" align="center"><input type="submit" style="width: 70px" name="order_did" value="Order DID"></td>
</tr>
</form>
<?php ?>
</table>
<?php }} ?>
</body>
</html>