<?php
/**
 * email_fedex.php
 *
 * @package fedex automated shipping labels
 * @copyright Copyright 2007-2008 Numinix Technology http://www.numinix.com
 * @copyright Portions Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: email_fedex.php, v 1.00 03.31.2008 16:12:59 numinix $
 * @author Numinix Technology
 */
  require('includes/application_top.php'); 
  
  // get values
  $image_file = DIR_WS_FEDEX_LABELS . $_GET['num'] . '.png';
  if (function_exists('handle_image')) { 
    $image_width = (675 * (int)MODULE_SHIPPING_FEDEX_RESOLUTION)/100;
    $image_file = handle_image($image_file, '', $image_width, '', '');
  }
  $orders_id = $_GET['oID'];
  // get shipping method
  $orders_query = "SELECT sm.shipping_type, o.customers_email_address, o.customers_name 
                   FROM " . TABLE_ORDERS . " o
                   LEFT JOIN " . TABLE_SHIPPING_MANIFEST . " sm ON (o.orders_id = sm.orders_id)
                   WHERE o.orders_id = " . $orders_id . " LIMIT 1;";
  $orders = $db->Execute($orders_query);
  while(!$orders->EOF) {
    $shipping_method = $orders->fields['shipping_type'];
    $customers_name = $orders->fields['customers_name'];
    $customers_email_address = $orders->fields['customers_email_address'];
    $orders->MoveNext();
    break;
  }
  // debug
  /*
  echo 'shipping method: ' . $shipping_method . '<br />';
  echo 'customers name: ' . $customers_name . '<br />';
  echo 'customers email: ' . $customers_email_address;
  die();
  */
  
  $block = array();
  // compare shipping methods
  if ($shipping_method == 90 || $shipping_method == 92) {
    // use ground template
    $template_type = 'ground';
    $email = str_replace(array('<p>', '</p>'), "\n", EMAIL_GROUND_INTRO) . "\n\n" . sprintf(str_replace(array('<p>', '</p>'), "\n", EMAIL_GROUND_CONTENT), '<a href="' . $image_file . '">shipping label (' . $image_file . ')</a>') . "\n\n" . str_replace('\n','',STORE_NAME);
    $block['EMAIL_GROUND_INTRO'] = EMAIL_GROUND_INTRO;
    $block['EMAIL_GROUND_CONTENT'] = sprintf(EMAIL_GROUND_CONTENT, '<a href="' . $image_file . '">shipping label (' . $image_file . ')</a>');
  } else {
    // use express template
    $template_type = 'express';
    $email = str_replace(array('<p>', '</p>'), "\n", EMAIL_EXPRESS_INTRO) . "\n\n" . sprintf(str_replace(array('<p>', '</p>'), "\n", EMAIL_EXPRESS_CONTENT), '<a href="' . $image_file . '">shipping label (' . $image_file . ')</a>') . "\n\n" . str_replace('\n','',STORE_NAME);
    $block['EMAIL_EXPRESS_INTRO'] = EMAIL_EXPRESS_INTRO;
    $block['EMAIL_EXPRESS_CONTENT'] = sprintf(EMAIL_EXPRESS_CONTENT, '<a href="' . $image_file . '">shipping label (' . $image_file . ')</a>');   
  }
  $block['EMAIL_CONTACT_OWNER'] = str_replace('\n','',STORE_NAME);
           
  zen_mail($customers_name, $customers_email_address, 'Message from ' . STORE_NAME, $email, STORE_NAME, STORE_OWNER_EMAIL_ADDRESS, $block, 'fedex_' . $template_type);
?>
<!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 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 //-->
<?php  
  echo '<p><strong>Email successfully sent to ' . $customers_email_address . '</strong></p>'; 
?>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>