Skip to content

Instantly share code, notes, and snippets.

@jschultz0614
Created April 4, 2016 18:04
Show Gist options
  • Save jschultz0614/1f29decc830a81a62e6b861f0c1a008a to your computer and use it in GitHub Desktop.
Save jschultz0614/1f29decc830a81a62e6b861f0c1a008a to your computer and use it in GitHub Desktop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Import eNOM Pricing</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="/css/tables.css" rel="stylesheet" />
</head>
<body>
<div class="Table">
<div class="Row">
<div class="Cell border-bottom-1px-solid-000-000-000 border-right-1px-solid-000-000-000">Action Taken</div>
<div class="Cell border-bottom-1px-solid-000-000-000 border-right-1px-solid-000-000-000">TLD</div>
<div class="Cell border-bottom-1px-solid-000-000-000 border-right-1px-solid-000-000-000">Register Price</div>
<div class="Cell border-bottom-1px-solid-000-000-000 border-right-1px-solid-000-000-000">Transfer Price</div>
<div class="Cell border-bottom-1px-solid-000-000-000">Renew Price</div>
</div>
<?php
$ENOM_UserID = "**************";
$ENOM_Password = "**************";
$ENOM_API_Command = "PE_GetRetailPricing";
$ENOM_ResponseType = "XML";
$TLDOnly = "1";
$url = "https://reseller.enom.com/interface.asp?Command=$ENOM_API_Command&UID=$ENOM_UserID&PW=$ENOM_Password&ResponseType=$ENOM_ResponseType&TLDOnly=$TLDOnly";
$servername = "localhost";
$username = "**************";
$password = "**************";
$dbname = "**************";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
class XmlToJson {
public function Parse ($url) {
$fileContents = file_get_contents($url);
$fileContents = str_replace(array("\n", "\r", "\t"), '', $fileContents);
$fileContents = trim(str_replace('"', "'", $fileContents));
$simpleXml = simplexml_load_string($fileContents);
$json = json_encode($simpleXml);
return $json;
}
}
$_json = XmlToJson::Parse($url);
$json_post = json_decode(utf8_decode($_json), true);
for($i = 0; $i < $json_post['pricestructure']['count']; $i++){
$PricingArray = array(
'taxable' => 0,
'pricedata' => array ( '0' =>
array (
'registrar' => 'enom',
'1' => array(
'period' => '1',
'period_id' => '1',
'price' => number_format($json_post['pricestructure']['tld'][$i]['registerprice'], 2, '.', ''),
'transfer' => number_format($json_post['pricestructure']['tld'][$i]['transferprice'], 2, '.', ''),
'renew' => number_format($json_post['pricestructure']['tld'][$i]['renewprice'], 2, '.', '')
),
'2' => array(
'period' => '2',
'period_id' => '2',
'price' => number_format($json_post['pricestructure']['tld'][$i]['registerprice'] * 2, 2, '.', ''),
'transfer' => number_format($json_post['pricestructure']['tld'][$i]['transferprice'] * 2, 2, '.', ''),
'renew' => number_format($json_post['pricestructure']['tld'][$i]['renewprice'] * 2, 2, '.', '')
),
'5' => array(
'period' => '5',
'period_id' => '5',
'price' => number_format($json_post['pricestructure']['tld'][$i]['registerprice'] * 5, 2, '.', ''),
'transfer' => number_format($json_post['pricestructure']['tld'][$i]['transferprice'] * 5, 2, '.', ''),
'renew' => number_format($json_post['pricestructure']['tld'][$i]['renewprice'] * 5, 2, '.', '')
),
'10' => array(
'period' => '10',
'period_id' => '10',
'price' => number_format($json_post['pricestructure']['tld'][$i]['registerprice'] * 10, 2, '.', ''),
'transfer' => number_format($json_post['pricestructure']['tld'][$i]['transferprice'] * 10, 2, '.', ''),
'renew' => number_format($json_post['pricestructure']['tld'][$i]['renewprice'] * 10, 2, '.', '')
)
)
)
);
$StockInfo = "a:5:{s:12:\"stockEnabled\";i:0;s:14:\"availableStock\";i:0;s:7:\"soldOut\";i:0;s:13:\"acceptSoldOut\";i:0;s:14:\"showStockLevel\";i:0;}";
$BundledProducts = "a:3:{s:8:\"optional\";a:0:{}s:8:\"required\";a:0:{}s:7:\"coupons\";a:0:{}}', 'a:3:{s:19:\"autoInitiateTranfer\";s:1:\"1\";s:17:\"enableNamesuggest\";s:1:\"1\";s:14:\"maxNamesuggest\";s:1:\"5\";}";
$SerializedPricingArray = serialize($PricingArray);
$signup_order = $i + 1;
$SQL_SELECT_Statement = "SELECT * FROM package WHERE planname='" . $json_post['pricestructure']['tld'][$i]['tld'] . "';";
$SQL_UPDATE_Statement = "UPDATE package SET pricing='" . $SerializedPricingArray . "', signup_order=" . $signup_order . " WHERE planid=10 AND planname='" . $json_post['pricestructure']['tld'][$i]['tld'] . "';";
$SQL_INSERT_Statement = "INSERT INTO package (`planname`, `description`, `asset_html`, `highlight`, `planid`, `showpackage`, `pricing`, `style`, `automaticactivation`, `allowdirectlink`, `sendwelcome`, `stockInfo`, `emailTemplate`, `bundledProducts`, `advanced`, `signup_order`) VALUES ('" . $json_post['pricestructure']['tld'][$i]['tld'] . "', '', '', '0', 10, 1, '". $SerializedPricingArray . "', 0, 1, 0, 1, '" . $StockInfo . "', 35, '" . $BundledProducts . "', " . $signup_order . ")";
$result = mysqli_query($conn, $SQL_SELECT_Statement);
if (mysqli_num_rows($result) > 0 ) {
$Action = "Updating";
$result2 = mysqli_query($conn, $SQL_UPDATE_Statement);
} else {
$Action = "Inserting";
$result2 = mysqli_query($conn, $SQL_INSERT_Statement);
}
?>
<div class="Row">
<div class="Cell border-bottom-1px-solid-000-000-000 border-right-1px-solid-000-000-000">
<?php echo $Action ?>
</div>
<div class="Cell border-bottom-1px-solid-000-000-000 border-right-1px-solid-000-000-000">
<?php echo $json_post['pricestructure']['tld'][$i]['tld']; ?>
</div>
<div class="Cell border-bottom-1px-solid-000-000-000 border-right-1px-solid-000-000-000">
<?php echo number_format($json_post['pricestructure']['tld'][$i]['registerprice'], 2, '.', ''); ?>
</div>
<div class="Cell border-bottom-1px-solid-000-000-000 border-right-1px-solid-000-000-000">
<?php echo number_format($json_post['pricestructure']['tld'][$i]['transferprice'], 2, '.', ''); ?>
</div>
<div class="Cell border-bottom-1px-solid-000-000-000">
<?php echo number_format($json_post['pricestructure']['tld'][$i]['renewprice'], 2, '.', ''); ?>
</div>
</div>
<?php
}
mysqli_close($conn);
?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment