Hi there,

I am using the Mailing Labels mod. I have customized it to work with Canada Post's shipping software so that I can just import the shipping information right into Canada Post, which saves a LOT of time! However, the Canada Post import specs require that I use 2 digit country and state/province codes in the import file. The Mailing Labels mod is pulling that info from fields in the Orders table, which are the full words, e.g. Canada, California. Is there some way to get the mod to change the full words to the codes so I don't have to manually do it every time?

This is my modified mailinglabels.php file:
<?php
// GPL license - see license.txt

require('includes/application_top.php');

// csv settings
define("CSV_SEPARATOR", ",");
define("CSV_NEWLINE", "\r\n");

// not submitted, so show form to submit
if (!$submitted || $submitted != 1)
{
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<link rel="stylesheet" type="text/css" href="includes/cssjsmenuhover.css" media="all" id="hoverJS">
<script language="javascript" src="includes/menu.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script type="text/javascript">
<!--
function init()
{
cssjsmenu('navbar');
if (document.getElementById)
{
var kill = document.getElementById('hoverJS');
kill.disabled = true;
}
}
// -->
</script>
</head>
<body onload="init()">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
<tr>
<td>
<div class="pageHeading"><?php echo HEADING_TITLE; ?></div>

<form method="GET" action="<?php echo $PHP_SELF; ?>">
<table border="0" cellpadding="3">
<tr>
<td><?php echo TEXT_START_ORDER_NUM; ?></td>
<td><input name="start" size="5" value="<?php echo $start; ?>">
</tr>
<tr>
<td><?php echo TEXT_END_ORDER_NUM; ?></td>
<td><input name="end" size="5" value="<?php echo $end; ?>">
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="<?php echo BUTTON_GENERATE; ?>"></td>
</tr>
</table>
<input type="hidden" name="submitted" value="1">
</form>

</td>
</tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php
}
// submitted so generate csv
else
{
generatecsv($start, $end);
}

// generates csv file from $start order to $end order, inclusive
function generatecsv($start, $end)
{
global $db;

$sql = "SELECT * ";
$sql .= "FROM " . TABLE_ORDERS . " ";
$sql .= "WHERE orders_id >= $start
AND orders_id <= $end";

$orders = $db->Execute($sql);

header("Pragma: cache");
header("Content-Type: text/comma-separated-values");
header("Content-Disposition: attachment; filename=" . FILENAME_SHIPPING_ADDRESSES);
echo CSV_TITLE_RECORD.CSV_SEPARATOR;
echo CSV_TITLE_ORDER.CSV_SEPARATOR;
echo CSV_TITLE_CLIENT.CSV_SEPARATOR;
echo CSV_TITLE_TITLE.CSV_SEPARATOR;
echo CSV_TITLE_NAME.CSV_SEPARATOR;
echo CSV_TITLE_LNAME.CSV_SEPARATOR;
echo CSV_TITLE_DEPT.CSV_SEPARATOR;
echo CSV_TITLE_COMPANY.CSV_SEPARATOR;
echo CSV_TITLE_ADDLADDRESS.CSV_SEPARATOR;
echo CSV_TITLE_STREET.CSV_SEPARATOR;
echo CSV_TITLE_SUBURB.CSV_SEPARATOR;
echo CSV_TITLE_CITY.CSV_SEPARATOR;
echo CSV_TITLE_STATE.CSV_SEPARATOR;
echo CSV_TITLE_POSTCODE.CSV_SEPARATOR;
echo CSV_TITLE_COUNTRY.CSV_SEPARATOR;
echo CSV_TITLE_PHONE.CSV_SEPARATOR;
echo CSV_TITLE_FAX.CSV_SEPARATOR;
echo CSV_TITLE_EMAIL.CSV_SEPARATOR;
echo CSV_TITLE_WEIGHT.CSV_NEWLINE;

while (!$orders->EOF)
{
echo quote(2).CSV_SEPARATOR;
echo quote($orders->fields['orders_id']).CSV_SEPARATOR;
echo quote($orders->fields['customers_id']).CSV_SEPARATOR;
echo quote(0).CSV_SEPARATOR;
echo quote($orders->fields['delivery_name']).CSV_SEPARATOR;
echo quote(0).CSV_SEPARATOR;
echo quote(0).CSV_SEPARATOR;
echo quote($orders->fields['delivery_company']).CSV_SEPARATOR;
echo quote(0).CSV_SEPARATOR;
echo quote($orders->fields['delivery_street_address']).CSV_SEPARATOR;
echo quote($orders->fields['delivery_suburb']).CSV_SEPARATOR;
echo quote($orders->fields['delivery_city']).CSV_SEPARATOR;
echo quote($orders->fields['delivery_state']).CSV_SEPARATOR;
echo quote($orders->fields['delivery_postcode']).CSV_SEPARATOR;
echo quote($orders->fields['delivery_country']).CSV_SEPARATOR;
echo quote($orders->fields['customers_telephone']).CSV_SEPARATOR;
echo quote(0).CSV_SEPARATOR;
echo quote($orders->fields['customers_email_address']).CSV_SEPARATOR;
echo quote(0).CSV_NEWLINE;

$orders->MoveNext();
}
}

// returns the name for a shipping status
function getorderstatus($statusid)
{
global $db;

$query = "select * from " . TABLE_ORDERS_STATUS . " where orders_status_id = $statusid";

$statii = $db->Execute($query);

while (!$statii->EOF)
{
return $statii->fields['orders_status_name'];
}

return $statusid;
}

// formats a value suitable for including in a csv file
function quote($value)
{
// if quote mark in string then escape with another quote mark
// then put in quote marks and return
if (strstr($value, "\"") !== FALSE)
{
$value = ereg_replace("\"", "\"\"", $value);
return "\"$value\"";
}

// if seperator in string then put in quote marks
if (strstr($value, CSV_SEPARATOR) !== FALSE)
{
return "\"$value\"";
}

return $value;
}

require(DIR_WS_INCLUDES . 'application_bottom.php');

?>
Thanks!