this is whole script:
1 )
{
$cr_sql .= " OR ( o.orders_id > {$sub_crit[0]} AND o.orders_id < $sub_crit[1]) ";
}
else
{
$cr_sql .= " OR o.orders_id = {$cr_element}";
}
}
$cr_sql = ' (' . trim($cr_sql, ' OR') . ') ';
}
if ( $_POST['orders_date_start'] )
{
$cr_sql .= ( $cr_sql ) ? ' AND ' : '';
$cr_sql .= " (o.date_purchased > '{$_POST['orders_date_start']}' AND o.date_purchased < '{$_POST['orders_date_end']}') ";
}
if ( $_POST['orders_status'] )
{
$cr_sql .= ( $cr_sql ) ? ' AND ' : '';
$cr_sql .= " o.orders_status = {$_POST['orders_status']}";
}
// Create node object
function new_node($parent, $title, $attributes = false, $contents = false)
{
global $dom;
// Creating node
$node = $dom->createElement($title);
// Adding attributes if available
if ( is_array($attributes) )
{
if ( @count($attributes) > 0 )
{
foreach ( $attributes as $name => $value )
{
$node->setAttribute($name, $value);
}
}
}
elseif ( is_string($attributes) )
{
$node->setAttribute('n', $attributes);
}
if ( $contents )
{
$node_text = $dom->createCDATASection($contents);
$node->appendChild($node_text);
}
if ( is_object($parent) )
{
$parent->appendChild($node);
}
return $node;
}
// Initializng DOM object
$dom = new DomDocument('1.0', 'ISO-8859-1');
// Creating root element
$root = new_node($dom, "pacsoftonline");
// meta
//$root_meta = new_node($root, 'meta');
//new_node($root_meta, 'val', 'printer', '');
// Getting orders list
$orders_sql = tep_db_query("SELECT *, o.orders_id as orders_id FROM orders o LEFT JOIN orders_total ot ON (o.orders_id = ot.orders_id AND ot.class = 'ot_shipping') WHERE ($cr_sql)");
while ( $order_row = tep_db_fetch_array($orders_sql) )
{
$order_info = $order_row;
// Converting encoding
foreach ( $order_info as $key => $val )
{
echo iconv_get_encoding($val);
$order_info[$key] = iconv('ISO-8859-1', 'UTF-8', $val);
}
$order_info['customers_postcode'] = str_replace(' ', '', ( $order_info['delivery_postcode']) ? $order_info['delivery_postcode'] : $order_info['customers_postcode']);
if ( strlen($order_info['customers_postcode']) > 5 )
{
continue;
}
$t_name = ( $order_info['delivery_name'] ) ? $order_info['delivery_name'] : $order_info['customers_name'];
// Receiver
$root_receiver = new_node($root, 'receiver', array('rcvid' => $order_info['orders_id']));
if ( $order_info['customers_company'] )
{
new_node($root_receiver, 'val', "name", $order_info['customers_company']);
new_node($root_receiver, 'val', "address1", $t_name);
new_node($root_receiver, 'val', "address2", ( $order_info['delivery_street_address'] ) ? $order_info['delivery_street_address'] : $order_info['customers_street_address'] );
}
else
{
new_node($root_receiver, 'val', "name", $t_name);
new_node($root_receiver, 'val', "address1", ( $order_info['delivery_street_address'] ) ? $order_info['delivery_street_address'] : $order_info['customers_street_address'] );
}
new_node($root_receiver, 'val', "zipcode", $order_info['customers_postcode'] );
new_node($root_receiver, 'val', "city", ( $order_info['delivery_city'] ) ? $order_info['delivery_city'] : $order_info['customers_city']);
new_node($root_receiver, 'val', "country", PACSOFT_COUNTRY);
//new_node($root_receiver, 'val', "contact", $order_info['delivery_name']);
new_node($root_receiver, 'val', "phone", $order_info['customers_telephone']);
//new_node($root_receiver, 'val', "fax", '');
//new_node($root_receiver, 'val', "orgno", $order_info['']);
//new_node($root_receiver, 'val', "doorcode", $order_info['']);
//new_node($root_receiver, 'val', "email", $order_info['customers_email_address']);
//new_node($root_receiver, 'val', "sms", $order_info['']);
// Shipment
$root_shipment = new_node($root, 'shipment', array('orderno' => $order_info['orders_id']));
new_node($root_shipment, 'val', "from", PACSOFT_SENDER_ID);
new_node($root_shipment, 'val', "to", $order_info['orders_id']);
//new_node($root_shipment, 'val', "freetext1", $order_info['']);
//new_node($root_shipment, 'val', "freetext2", $order_info['']);
//new_node($root_shipment, 'val', "freetext3", $order_info['']);
//new_node($root_shipment, 'val', "freetext4", $order_info['']);
new_node($root_shipment, 'val', "reference", $order_info['orders_id']);
new_node($root_shipment, 'val', "referencebarcode", $order_info['orders_id']);
// Shipment :: service
$root_shipment_service = new_node($root_shipment, 'service', array('srvid' => PACSOFT_SHIPMENT_SERVICE_ID));
//new_node($root_shipment_service, 'val', "returnlabel", PACSOFT_RETURN_LABEL);
//new_node($root_shipment_service, 'val', "sourcecode", $order_info['']);
$root_shipment_service_addon = new_node($root_shipment_service, 'addon', array('adnid' => 'notltr'));
if ( iconv('UTF-8', 'ISO-8859-1', $order_info['payment_method']) == 'Postförskott' )
{
$root_shipment_service_addon = new_node($root_shipment_service, 'addon', array('adnid' => 'cod'));
$orders_total_sql = tep_db_query("SELECT value FROM orders_total WHERE class = 'ot_total' AND orders_id = {$order_info['orders_id']}");
$orders_total = tep_db_fetch_array($orders_total_sql);
new_node($root_shipment_service_addon, 'val', "amount", number_format($orders_total['value'], 2, '.', ''));
//new_node($root_shipment_service_addon, 'val', "custno", $order_info['']);
new_node($root_shipment_service_addon, 'val', "reference", $order_info['orders_id']);
//new_node($root_shipment_service_addon, 'val', "misc", $order_info['']);
}
// Shipment :: ufonline
//$root_shipment_ufonline = new_node($root_shipment, 'ufonline');
//$root_shipment_ufonline_option = new_node($root_shipment_ufonline, 'option', array('optid' => 'enot'));
//new_node($root_shipment_ufonline_option, 'val', "message", $order_info['']);
// Shipment :: container
$root_shipment_container = new_node($root_shipment, 'container', array('type' => 'parcel'));
new_node($root_shipment_container, 'val', "copies", 1);
//new_node($root_shipment_container, 'val', "weight", $order_info['']);
//new_node($root_shipment_container, 'val', "contents", 'stuff');
//new_node($root_shipment_container, 'val', "customssource", $order_info['']);
//new_node($root_shipment_container, 'val', "customsunit", $order_info['currency']);
//new_node($root_shipment_container, 'val', "customsvalue", number_format($order_info['currency_value'], 2));
//new_node($root_shipment_container, 'val', "statno", $order_info['']);
// Appending all XML content to DOM object
$dom->appendChild($root);
}
// Genereating output
// Deleting old files in emprorary directory
if (is_dir('pacsoft/files/'))
{
if ($dh = opendir('pacsoft/files/'))
{
// 3 days old timestamp
$cur_time = time() - 24*60*60*3;
while (($file = readdir($dh)) !== false)
{
if ( strpos($file, '.xml') )
{
if ( (int)@filectime('pacsoft/files/' . $file) < $cur_time )
{
unlink('pacsoft/files/' . $file);
}
}
}
closedir($dh);
}
}
$file_xml = 'pacsoft/files/' . uniqid('pacsoft_order_') . '.xml';
$dom->save($file_xml);
// Sending a file to user's browser for downloading
header('HTTP/1.1 200 OK');
header('Status: 200 OK');
header('Accept-Ranges: bytes');
header('Content-Type: text/xml');
header('Content-Disposition: attachment; filename="http://www.neptunsat.com/isadminthere/' . $file_xml . '"');
echo file_get_contents($file_xml);
?>
|