<?php
require_once('lib/nusoap.php');

$site 'http://sandbox.didww.com/api/?wsdl';
$error 0;
$hide =  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 (!$_hashkey
    
$hashkey  md5(mt_rand());        // Build hashkey for this order


if ($_POST
{
    if (
$_POST['order_did'])
    {
        if (
$_POST['uniq'] == "") die("Invalid Country and city key!");
        if (
$hashkey == "" || (strlen($hashkey) < 10)) die("Invalid Hash key! Please, provide hash key for every new order, min 10 characters");
        
$arr = array();
        
$arr[0] = $auth_string;
        
$arr[1]    = $hashkey;
        
$arr[2] = $_POST['uniq'];
        
$arr[3] = 1// 0 - Disable, 1 - Enable
        
        
$result $client->call('neworder'$arr);

        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>';
            }
        }
    }
    
    if (
$_POST['build_map'])
    {
        if (
$_POST['did_id'] == "") die("Invalid DID ID!");
        if (
$_POST['map_proto'] == "") die("Invalid Protocol!");
        if (
$_POST['map_uri'] == "") die("Invalid URI!");
        
        
$error 0;
        
        
$arr = array();
        
$arr[0] = $auth_string;
        
$arr[1]    = $_POST['did_id'];
        
$arr[2] = $_POST['map_proto'];
        
$arr[3] = $_POST['map_uri'];;
        
        
$result2 $client->call('buildmapping'$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>';
            } 
            else 
            {
                
$hide 1;
                echo 
'<br><br><p align=center>';
                echo 
'Congratulations. You have ordered DID and configured mapping.';
                echo 
'<br>';
                echo 
'Result: ';
                
print_r($result2);
            }
        }
    }
}


$msg "DID ID: ".$result['did_id']."<br>";
$msg .= "DID Number: ".$result['did_number']."<br>";
?>
<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 == && $hide == 0) { ?>
<p align="center"><?php echo $msg?></p>
<br>
<table width="50%" border="0" cellspacing="0" cellpadding="0" class="main" align="center">
<form name="new_order" action="order.php" method="post">
<input type="hidden" name="did_id"  value="<?php echo $result['did_id']; ?>">
<tr>
    <td colspan="2" align="center" class="theader">Build mapping for DID: <?php echo $result['did_number']; ?></td>
</tr>
<tr>
    <td class="datatdh">Protocol:</td>
    <td class="datatd">
        <input type="radio" name="map_proto"  value="1">SIP &nbsp;&nbsp;&nbsp; 
        <input type="radio" name="map_proto" value="2">IAX &nbsp;&nbsp;&nbsp; 
        <input type="radio" name="map_proto" value="3">H.323
    </td>
</tr>
<tr>
    <td class="datatdh">URI:</td>
    <td class="datatd">
        <input type="text" name="map_uri" size="40">
    </td>
</tr>
<tr>
    <td class="datatds" colspan="2" align="center">
        <input type="submit" style="width: 80px" name="build_map" value=" Save ">
    </td>
</tr>
</form>
</table>
<?php ?>
<br>
<p align="center"><a href="coverage.php">Back to the coverage list</a></p>
</body>
</html>