Here is the altered file , its set up for how I need to use it , but its commented in places and pretty generic anyway. Any problems let me know and I will see if I can help. [PHP]<?php
/**
* shipease.php
*
* @package ship @ ease
* @copyright Portions Copyright 2003-2006 Zen Cart Development Team
* @copyright Portions Copyright 2003 osCommerce
* @copyright Portions Copyright 2003 Andrew Berezin
* @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
* @version $Id: shipease.php, v 1.0 15.8.2007 5:54 James Fitch
[email protected]$
/*
TODO List
*/
require('includes/application_top.php');
@define('SHIP_EASE_DIRECTORY', 'ship/');
@define('SHIP_EASE_OUTPUT_BUFFER_MAXSIZE', 1024*1024);
@define('SHIP_EASE_USE_CPATH', 'false');
define('NL', "<br />\n");
$count=0;
require(zen_get_file_directory(DIR_WS_LANGUAGES . $_SESSION['language'] .'/', 'shipease.php', 'false'));
echo TEXT_SHIP_EASE_STARTED . NL;
echo TEXT_SHIP_EASE_FILE_LOCATION . DIR_FS_CATALOG . SHIP_EASE_DIRECTORY . SHIP_EASE_OUTPUT_FILENAME . NL;
if (isset($_GET['feed']) && $_GET['feed'] == "yes") {
if (is_dir(DIR_FS_CATALOG . SHIP_EASE_DIRECTORY)) {
if (!is_writeable(DIR_FS_CATALOG . SHIP_EASE_DIRECTORY)) {
echo ERROR_SHIP_EASE_DIRECTORY_NOT_WRITEABLE . NL;
die;
}
} else {
echo ERROR_SHIP_EASE_DIRECTORY_DOES_NOT_EXIST . NL;
die;
}
$stimer_feed = microtime_float();
@set_time_limit(0);
$output_buffer = "";
if(!zen_ship_fwrite('', 'open')) {
echo ERROR_SHIP_EASE_OPEN_FILE . NL;
die;
}
$orders_query = "SELECT *
FROM " . TABLE_ORDERS . "
ORDER BY orders_id ASC";
$stimer = microtime_float();
$orders = $db->Execute($orders_query);
$timer['$orders->mySQL'] += microtime_float()-$stimer;
while (!$orders->EOF) {
$statustoship=$orders->fields['orders_status'];
$datestatus = $orders->fields['date_purchased'];
$shiptype = $orders->fields['shipping_module_code'];
$sum=0;
$totalweight =0;
//if ($statustoship <SHIP_EASE_STATUS) { this was the original line
// the next line means it only creates the file for those orders set to SHIP_EASE_STATUS ( processing )
if ($statustoship == SHIP_EASE_STATUS) {
//if (($statustoship == SHIP_EASE_STATUS) and ($shiptype != "rm1stpacketsf")) { I use this to not ship stuff sent royalmail
$orderid=$orders->fields['orders_id'];
$proid_query="SELECT *
FROM " . TABLE_ORDERS_PRODUCTS . " as t1 WHERE t1.orders_id = $orderid";
// next line grabs the comments to output on the interlink labels
$comments_query ="SELECT comments FROM orders_status_history WHERE `orders_id` = $orderid ORDER BY orders_status_history_id
LIMIT 1";
$Orderedproduct = $db->Execute($proid_query);
// sum total weight
while (!$Orderedproduct->EOF) {
$prodid = $Orderedproduct->fields['products_id'];
$prodnum = $Orderedproduct->fields['products_quantity'];
$Ordercomments = $db->Execute($comments_query);
$actualcomment1 = substr($Ordercomments->fields['comments'], 0, 25);$Ordercomments->fields['comments'];
$actualcomment2 = substr($Ordercomments->fields['comments'], 25, 25);$Ordercomments->fields['comments'];
$proids_query="SELECT *
FROM " . TABLE_PRODUCTS." as t2 WHERE t2.products_id = $prodid ";
$Orderedproductweight = $db->Execute($proids_query) ;
$sum = $Orderedproductweight->fields['products_weight'];
$sum=$sum * $prodnum;
$totalweight=$totalweight+$sum;
$Orderedproduct->MoveNext();
}
if ($totalweight > SHIP_EASE_MINWEIGHT) {
if ($totalweight < SHIP_EASE_MAXWEIGHT) {
$stimer = microtime_float();
$orderref=$orders->fields['orders_id'];
$output = array();
$output["orderid"]="000$orderref";
$output["jobtype"]= SHIP_EASE_JOB;
$output["custacc"]= SHIP_EASE_ACC;
$output["title"] = zen_ship_sanita($orders->fields['customers_name'], true);
$output["address1"] = zen_ship_sanita($orders->fields['delivery_street_address']);
$output["address2"] = zen_ship_sanita($orders->fields['delivery_suburb']);
$output["town"] = zen_ship_sanita($orders->fields['delivery_city']);
$output["county"] = zen_ship_sanita($orders->fields['delivery_state']);
$output["Postcode"] = zen_ship_sanita($orders->fields['delivery_postcode']);
$output["Instructions"] = zen_ship_sanita($actualcomment1);
$output["Instructions2"] = zen_ship_sanita($actualcomment2);
$output["Qtyoflabels"] = SHIP_EASE_QUAN;
$output["Service"] =SHIP_EASE_CODE ;
//$output["Timeslot"] ="" ;
//$output["total_weight"] = $totalweight;
$output["total_weight"] = 1; // I set the total weight to 1kg but you can have this as teh line above
$output["Delivery_date"] = $orders->fields['date_purchased'];
$output["User_Field_1"] = zen_ship_sanita(SHIP_EASE_INFO);
$output["User_Field_2"] ="";
$output["Workstn"] ="";
$output["Email"] =zen_ship_sanita($orders->fields['customers_email_address']);
$output["Email2"] ="";
$output["Telephone"] =SHIP_EASE_TEL;
$output["Contact"] ="";
$output["Description"] ="";
$output["Currency"] ="";
$output["Consignment value"] =($orders->fields['order_total']);
$output["Country"] =zen_ship_sanita($orders->fields['delivery_country']);
$output["Insurance"] =zen_ship_sanita(SHIP_EASE_INS);
$output["Userfield 3"] ="";
$output["Userfield 4"] ="";
$output["Account"] =000;
zen_ship_fwrite($output);
$count=$count+1;
}
}
}
$stimer = microtime_float();
$orders->MoveNext();
$timer['$orders->mySQL'] += microtime_float()-$stimer;
}
zen_ship_fwrite('', 'close');
// @chmod(DIR_FS_CATALOG . SHIP_EASE_DIRECTORY . SHIP_EASE_OUTPUT_FILENAME, 0644);
$timer_feed = microtime_float()-$stimer_feed;
$percent_other = 0;
$time_other = $timer_feed;
if(SHIP_EASE_STAT === true) {
echo 'Execution time:<br />';
echo '<table cellspace="2" border="1px">';
echo '<tr><td>Function</td><td>Execution time</td><td>Percent</td></tr>';
foreach($timer as $func => $time) {
$percent_total += ($time*100)/$timer_feed;
$time_other -= $time;
echo '<tr><td>' . $func . '</td><td align="right">' . number_format($time, 6) . '</td><td align="right">' . round(($time*100)/$timer_feed, 2) . '%</td></tr>';
}
echo '<tr><td><i>Other</i></td><td align="right"><i>' . number_format($time_other, 6) . '</i></td><td align="right"><i>' . round(($time_other*100)/$timer_feed, 2) . '%</i></td></tr>';
echo '<tr><td><b>Total</b></td><td align="right"><b>' . number_format($timer_feed, 6) . '</b></td><td align="right"><b>' . round(($timer_feed*100)/$timer_feed, 2) . '%</b></td></tr>';
echo '</table>';
}
//$orders->RecordCount()
echo TEXT_SHIP_EASE_FEED_COMPLETE . ' ' . SHIP_EASE_TIME_TAKEN . ' ' . sprintf("%f " . TEXT_SHIP_EASE_FEED_SECONDS, number_format($timer_feed, 6) ) . ' ' . $count . TEXT_SHIP_EASE_FEED_RECORDS . NL;
}
function zen_ship_fwrite($output, $op='fwrite') {
global $timer;$stimer = microtime_float();
static $fp;
static $output_buffer = "";
static $title_row = false;
switch ($op) {
case 'open':
$retval = $fp = fopen(DIR_FS_CATALOG . SHIP_EASE_DIRECTORY . SHIP_EASE_OUTPUT_FILENAME, "wb");
break;
case 'fwrite':
if(!$title_row) {
$title_row = $output;
}
$buf = array();
foreach($title_row as $key=>$val) {
$buf[] = (isset($output[$key]) ? $output[$key] : '');
// var_dump($key, $output[$key]);echo '<br />';
}
$output = implode(",", $buf);
if(strlen($output_buffer) > SHIP_EASE_OUTPUT_BUFFER_MAXSIZE) {
$retval = fwrite($fp, $output_buffer, strlen($output_buffer));
$output_buffer = "";
}
//$output = rtrim($output) . "\n";
$output = rtrim($output) . "\r\n";
if(strtolower(CHARSET) != 'utf-8')
$output_buffer .= utf8_encode($output);
else
$output_buffer .= $output;
break;
case 'close':
if(strlen($output_buffer) > 0) {
$retval = fwrite($fp, $output_buffer, strlen($output_buffer));
$output_buffer = "";
}
fclose($fp);
break;
}
$timer[__FUNCTION__] += microtime_float()-$stimer;
return $retval;
}
function zen_ship_sanita($str, $rt=false) {
global $timer;$stimer = microtime_float();
$str = strip_tags($str);
$str = str_replace(array("\t" , "\n", "\r"), ' ', $str);
$str = str_replace(",", " ", $str);
$str = preg_replace('/\s\s+/', ' ', $str);
// $str = str_replace(array("®", "®", "©", "©", "™", "™"), ' ', $str);
$str = htmlentities(html_entity_decode($str));
$in = $out = array();
$in[] = "®"; $out[] = '(r)';
$in[] = "©"; $out[] = '(c)';
$in[] = "™"; $out[] = '(tm)';
// $str = str_replace($in, $out, $str);
if($rt) $str = str_replace(array('>'), ' ', $str);
$str = trim($str);
//$str = "\"$str\"";
$timer[__FUNCTION__] += microtime_float()-$stimer;
return $str;
}
function ftp_get_error_from_ob() {
$out = ob_get_contents();
ob_end_clean();
$out = str_replace(array('\\', '<!--error-->', '<br>', '<br />', "\n", 'in <b>'),array('/', '', '', '', '', ''),$out);
if(strpos($out, DIR_FS_CATALOG) !== false){
$out = substr($out, 0, strpos($out, DIR_FS_CATALOG));
}
return $out;
}
function microtime_float() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
?>[/PHP]