<?php
// Begin Fedex Automated Shipping Label Mod
if (!function_exists('fedex_ship_request')) {
  function fedex_ship_request($shipData,$ship_type,$order) {    
    $fed = new FedExDC($shipData[0][10],$shipData[1][498]);
    $ship_Ret = $fed->$ship_type($shipData);
    // todo: add appropriate error checking for at least some of the possible errors
    if ($error = $fed->getError()) {
      // in case the ship date is a holiday, check for the error and correct the date
      // todo: correct the date!
      if (preg_match('/FF43/',$error)) {
        echo 'You cannot schedule a pickup on a weekend or holiday! Please go back and change the pickup date.';
        die();
      } else {
        echo 'This transaction could not be completed. Please note the error message below.<br><br>';
        die("ERROR: ". $error);
      }
    } 
    // if successful, we get the tracking number, write the label *.png file to images/fedex,
    // and display the label
    else {
      $trackNum = $ship_Ret[29];
      // decode and save label, named for the tracking number
      $fed->label(DIR_FS_FEDEX_LABELS . $trackNum . '.png');        
    }
    return $trackNum;
  }
}
// End Fedex Automated Shipping Label Mod
?>