Пример #1
0
<?php

// Security
if ($SMCallback !== true) {
    echo "Unauthorized!";
    // Not executed in the context of Sitemagic
    exit;
}
$ip = SMEnvironment::GetEnvironmentValue("REMOTE_ADDR");
$ip = $ip !== null ? $ip : "";
// DataSource definitions.
// NOTICE: Some fields have MaxLength multiplied by 8 to support the length of encoded Unicode characters.
$dataSourcesAllowed = array("SMShopProducts" => array("AuthRequired" => array("Create", "Update", "Delete"), "XmlLockRequired" => array(), "XmlTimeOut" => -1, "XmlMemoryRequired" => -1, "OrderBy" => "Category ASC, Title ASC", "Fields" => array("Id" => array("DataType" => "string", "MaxLength" => 30 * 8), "Category" => array("DataType" => "string", "MaxLength" => 50 * 8), "CategoryId" => array("DataType" => "string", "MaxLength" => 50 + 20), "Title" => array("DataType" => "string", "MaxLength" => 250 * 8), "Description" => array("DataType" => "string", "MaxLength" => 1000 * 8), "Images" => array("DataType" => "string", "MaxLength" => 1000), "Price" => array("DataType" => "number", "MaxLength" => 100), "Vat" => array("DataType" => "number", "MaxLength" => 100), "Currency" => array("DataType" => "string", "MaxLength" => 3), "Weight" => array("DataType" => "number", "MaxLength" => 100), "WeightUnit" => array("DataType" => "string", "MaxLength" => 3), "DeliveryTime" => array("DataType" => "string", "MaxLength" => 50 * 8), "DiscountExpression" => array("DataType" => "string", "MaxLength" => 250), "DiscountMessage" => array("DataType" => "string", "MaxLength" => 250 * 8))), "SMShopOrders" => array("AuthRequired" => array("Retrieve", "Update", "Delete", "RetrieveAll"), "XmlLockRequired" => array("Create", "Update", "Delete"), "XmlTimeOut" => 180, "XmlMemoryRequired" => 512, "OrderBy" => "", "Fields" => array("Id" => array("DataType" => "string", "MaxLength" => 50), "Time" => array("DataType" => "number", "MaxLength" => 15, "ForceInitialValue" => (string) (time() * 1000)), "ClientIp" => array("DataType" => "string", "MaxLength" => 45, "ForceInitialValue" => $ip), "Company" => array("DataType" => "string", "MaxLength" => 50 * 8), "FirstName" => array("DataType" => "string", "MaxLength" => 50 * 8), "LastName" => array("DataType" => "string", "MaxLength" => 50 * 8), "Address" => array("DataType" => "string", "MaxLength" => 50 * 8), "ZipCode" => array("DataType" => "string", "MaxLength" => 20), "City" => array("DataType" => "string", "MaxLength" => 50 * 8), "Email" => array("DataType" => "string", "MaxLength" => 50 * 8), "Phone" => array("DataType" => "string", "MaxLength" => 20), "Message" => array("DataType" => "string", "MaxLength" => 250 * 8), "AltCompany" => array("DataType" => "string", "MaxLength" => 50 * 8), "AltFirstName" => array("DataType" => "string", "MaxLength" => 50 * 8), "AltLastName" => array("DataType" => "string", "MaxLength" => 50 * 8), "AltAddress" => array("DataType" => "string", "MaxLength" => 50 * 8), "AltZipCode" => array("DataType" => "string", "MaxLength" => 20), "AltCity" => array("DataType" => "string", "MaxLength" => 50 * 8), "Price" => array("DataType" => "number", "MaxLength" => 100), "Vat" => array("DataType" => "number", "MaxLength" => 100), "Currency" => array("DataType" => "string", "MaxLength" => 3), "Weight" => array("DataType" => "number", "MaxLength" => 100), "WeightUnit" => array("DataType" => "string", "MaxLength" => 3), "ShippingExpense" => array("DataType" => "number", "MaxLength" => 100), "ShippingVat" => array("DataType" => "number", "MaxLength" => 100), "ShippingMessage" => array("DataType" => "string", "MaxLength" => 250 * 8), "PaymentMethod" => array("DataType" => "string", "MaxLength" => 50), "TransactionId" => array("DataType" => "string", "MaxLength" => 100), "State" => array("DataType" => "string", "MaxLength" => 20)), "Callbacks" => array("File" => dirname(__FILE__) . "/DSCallbacks/Order.php", "Functions" => array("Create" => "SMShopProcessNewOrder", "CreateCompleted" => "SMShopFinalizeNewOrder", "Retrieve" => null, "RetrieveAll" => null, "Update" => null, "Delete" => "SMShopDeleteOrderEntries"))), "SMShopOrderEntries" => array("AuthRequired" => array("Retrieve", "Update", "Delete", "RetrieveAll"), "XmlLockRequired" => array("Create", "Update", "Delete"), "XmlTimeOut" => 180, "XmlMemoryRequired" => 512, "OrderBy" => "", "Fields" => array("Id" => array("DataType" => "string", "MaxLength" => 50), "OrderId" => array("DataType" => "string", "MaxLength" => 50), "ProductId" => array("DataType" => "string", "MaxLength" => 30 * 8), "UnitPrice" => array("DataType" => "number", "MaxLength" => 100), "Vat" => array("DataType" => "number", "MaxLength" => 100), "Currency" => array("DataType" => "string", "MaxLength" => 3), "Units" => array("DataType" => "number", "MaxLength" => 100), "Discount" => array("DataType" => "number", "MaxLength" => 100), "DiscountMessage" => array("DataType" => "string", "MaxLength" => 250 * 8))));
// Functions
// Important:
// XMLHttpRequest communicates in UTF-8, always!
// UTF-8 comes in, UTF-8 must come out.
// Whenever data is passed to parts of Sitemagic,
// make sure data is transformed to ISO-8859-1!
function SMShopGetJsonData()
{
    $data = file_get_contents("php://input");
    // Read JSON data sent to server without a POST key
    $json = json_decode($data, true);
    // XMLHttpRequest always sends UTF-8 which is also what json_decode(..) expects
    $json = SMShopDecodeArrayFromUtf8ToLatin1($json);
    // Convert data to ISO-8859-1
    return $json;
}
function SMShopDecodeArrayFromUtf8ToLatin1($arr)
{