[ Index ]

PHP Cross Reference of osCMax 2.0.4

title

Body

[close]

/admin/ -> ship_fedex.php (source)

   1  <?php
   2  
   3  // ship_fedex.php
   4  // for managing federal express shipments
   5  // - makes a form for adding additional info about a shipment
   6  // - sends a ship request to fedex
   7  // - returns a shipping label & formats it for printing
   8  // - cancels an existing ship request
   9  // - builds a shipping manifest
  10  
  11  // debugging
  12  // setting to 1 displays the array of all shipping 
  13  // and manifest data when a ship request is made    
  14      $debug = 0;
  15  
  16    require ('includes/application_top.php');
  17    require (DIR_WS_FUNCTIONS . 'ship_fedex.php');
  18  
  19      $action = $HTTP_GET_VARS['action'];
  20      $order = $HTTP_GET_VARS['oID'];
  21      $send_email_on_shipping = 0;   //set to 0 to disable, set to 1 to enable automatic email of tracking number
  22      
  23  ////
  24  // make a new ship request
  25      
  26      if($action=='ship') {
  27  
  28          if (!$order) {
  29              die (ERROR_NO_ORDER_NUMBER);
  30              }
  31      
  32          include (DIR_WS_INCLUDES . 'abbreviate.php'); // used to abbreviate state & country names
  33          require (DIR_WS_INCLUDES . 'fedexdc.php');
  34  
  35  // array of characters we don't want in phone numbers        
  36          $unwanted = array('(',')','-','.',' '); 
  37  
  38          $transaction_code = 21; // 21 is a ship request
  39                  
  40  // get the country we're shipping from
  41          $country_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'STORE_COUNTRY'");
  42          $country_value = tep_db_fetch_array($country_query);
  43          $country = tep_get_country_name($country_value['configuration_value']);
  44  // abbreviate it for fedex (United States = US etc.)
  45          $senders_country = abbreviate_country($country);
  46  
  47  // get sender's fedex info from configuration table
  48  // (requires installation & configuration of FedEx RealTime Quotes)
  49      
  50          $fedex_vars = array (
  51              10=>'MODULE_SHIPPING_FEDEX1_ACCOUNT', // 0
  52              498=>'MODULE_SHIPPING_FEDEX1_METER',     // 1
  53              75=>'MODULE_SHIPPING_FEDEX1_WEIGHT',    // 2
  54              4=>'STORE_NAME',                                            // 3
  55              5=>'MODULE_SHIPPING_FEDEX1_ADDRESS_1',// 4
  56              6=>'MODULE_SHIPPING_FEDEX1_ADDRESS_2',// 5
  57              7=>'MODULE_SHIPPING_FEDEX1_CITY',            // 6
  58              8=>'MODULE_SHIPPING_FEDEX1_STATE',        // 7
  59              9=>'MODULE_SHIPPING_FEDEX1_POSTAL',        // 8
  60              183=>'MODULE_SHIPPING_FEDEX1_PHONE',    // 9
  61              68=>'DEFAULT_CURRENCY',                                // 10
  62              );
  63                  
  64          $i = 0;
  65          $fedex_keys = array_keys($fedex_vars);
  66                  
  67          foreach($fedex_vars as $var) {
  68              $value_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = '" . $var . "'");
  69              $value = tep_db_fetch_array($value_query);
  70              $value = $value['configuration_value'];
  71              if (($var == 'MODULE_SHIPPING_FEDEX1_ACCOUNT') && (!$value)) {
  72                  die (ERROR_FEDEX_QUOTES_NOT_INSTALLED);
  73                  }
  74          
  75  // get rid of dashes, parentheses and periods in shipper's telephone number
  76              if ($fedex_keys[$i]==183) {
  77                  $value = trim(str_replace($unwanted, '', $value));
  78                  $fedex_vars[$fedex_keys[$i]] = $value;
  79                  }
  80              else {
  81                  $fedex_vars[$fedex_keys[$i]] = $value;
  82                  }
  83              $i++;
  84              }
  85                  
  86  ////
  87  // create new FedExDC object
  88          $fed = new FedExDC($shipVars[0][10],$shipVars[1][498]);
  89      
  90  // get all information from the order record
  91          $order_query = tep_db_query("select * from orders where orders_id = $order");
  92      
  93          $order_info = tep_db_fetch_array($order_query);
  94  
  95  // abbreviate the delivery state (function is in abbreviate.php)
  96          $delivery_state = abbreviate_state($order_info['delivery_state']);
  97  
  98  // abbreviate the delivery country (function is in abbreviate.php)
  99          $delivery_country = abbreviate_country($order_info['delivery_country']);
 100  
 101  // get rid of dashes, parentheses and periods in customer's telephone number
 102          $delivery_phone = trim(str_replace($unwanted, '', $order_info['customers_telephone']));
 103  
 104  // get the transaction value
 105          $value_query = tep_db_query("select value from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $order . "' and class='ot_subtotal'");
 106          $order_value = tep_db_fetch_array($value_query);
 107          $order_value = round($order_value['value'], 0);
 108  
 109  //// some form variables        
 110          
 111  // format the form date (comes in as mm-dd-yyyy)
 112          $date_array = explode('-',$HTTP_POST_VARS['pickup_date']);
 113          $corrected_date = $date_array[2] . $date_array[0] . $date_array[1];
 114                  
 115  // determine whether the ship date is today or later
 116          if ($corrected_date == date(Ymd)) {
 117              $future = 'N'; // today
 118              }
 119          else {
 120              $future = 'Y';  // later date
 121              }
 122                  
 123  // start the array for fedex
 124          $shipData = array(
 125           0=>     $transaction_code // transaction code
 126        ,16=>   $delivery_state // delivery state
 127        ,13=>   $order_info['delivery_street_address'] // delivery address
 128        ,1273=> $HTTP_POST_VARS['packaging_type'] // packaging type (01 is customer packaging)
 129        ,1274=> $HTTP_POST_VARS['service_type'] // 
 130        ,18=>   $delivery_phone // customer's phone number
 131        ,15=>   $order_info['delivery_city']
 132        ,23=>   $HTTP_POST_VARS['bill_type'] // payment type (1 is bill to sender)
 133        ,117=>  $senders_country // sender's country
 134        ,17=>   $order_info['delivery_postcode'] // postal code it's going to
 135        ,50=>   $delivery_country // country it's going to
 136        ,11 =>    $order_info['delivery_company'] // recipient's company name
 137              ,12=>   name_case($order_info['delivery_name']) // recipient's contact name
 138        ,1333=> $HTTP_POST_VARS['dropoff_type'] // drop off type (1 is regular pickup)
 139              ,1415=> $order_value . '.00' // total order value, forced to 2 decimal places
 140        ,1368 => 2 // label type (2 is standard)
 141        ,1369 => 1 // printer type (1 is laser)
 142        ,1370 => 5 // label media (5 is plain paper)
 143        ,3002 => $HTTP_POST_VARS['package_invoice'] // invoice number
 144        ,25 => $HTTP_POST_VARS['package_reference'] // reference number
 145        ,3001 => $HTTP_POST_VARS['package_po'] // purchase order number
 146        ,38 => $HTTP_POST_VARS['package_department'] // department name
 147              ,24 => $corrected_date  // ship date                    
 148              ,1119 => $future // future day shipment
 149              ,2975 => 'Y'    // keep your fedex number off the label
 150          );
 151  
 152  // if it's home delivery (90), add the "residential delivery flag" (440)
 153          if ($HTTP_POST_VARS['service_type'] == 90) {
 154              $shipData[440] = 'Y';
 155              }
 156          else {
 157              $shipData[440] = 'N';
 158              }
 159  
 160  // if it's an oversized shipment...
 161          if ($oversized) {
 162              $shipData[3124] = $HTTP_POST_VARS['oversized'];
 163              }
 164                  
 165  ////
 166  // if there's no meter number in the database, ask for a new one
 167          if (!$fedex_vars[498]) {
 168              $fed = new FedExDC($fedex_keys[10]);
 169                          
 170  // variables needed to subscribe
 171              $requestData = array (
 172                  0 => 211, // 211 is the transaction code for a subscription request
 173                  10 => $fedex_vars[10], // account number
 174                  4003 => $fedex_vars[4], // contact name, using store name for now
 175                  4008 => $fedex_vars[5], // street address
 176                  4011 => $fedex_vars[7], // city
 177                  4012 => $fedex_vars[8], // state
 178                  4013 => $fedex_vars[9], // postal code
 179                  4014 => $senders_country, // country
 180                  4015 => $fedex_vars[183] // phone number
 181                  );
 182                          
 183              $keyRequest = $fed->subscribe($requestData);
 184  // todo: add appropriate error checking for at least some of the possible errors
 185              if ($error = $fed->getError()) {
 186                  echo '<pre>';
 187                  print_r($requestData);
 188                  echo '</pre>';
 189                  echo '<pre>';
 190                  print_r($keyRequest);
 191                  echo '</pre>';
 192                  die("ERROR: ". $error);
 193                  }
 194              else {
 195                  tep_db_query("update " . TABLE_CONFIGURATION . " set configuration_value = '" . $keyRequest[498] . "' where configuration_key = 'MODULE_SHIPPING_FEDEX1_METER'");
 196                  $fedex_vars[498] = $keyRequest[498];
 197                  }
 198              }
 199  // end meter request
 200  
 201  ////
 202  // put the form array together with the stuff from the database
 203          $shipData = $shipData+$fedex_vars;
 204  
 205  // determine shipment type (either ground or express)
 206  // (this is used in the call to fedexdc.php)
 207          if (($HTTP_POST_VARS['service_type'] == 92) or ($HTTP_POST_VARS['service_type'] == 90)) {
 208              $ship_type = 'ship_ground';
 209              }
 210          else {
 211              $ship_type = 'ship_express';
 212              }
 213  
 214  ////
 215  // request shipment(s) and post data to shipping manifest
 216  
 217          for ($i = 1; $HTTP_POST_VARS['package_num'] >= $i; $i++) {
 218              
 219  // data for shipping_manifest
 220              $manifest_data = array (
 221              delivery_id => '',
 222              orders_id => $order,
 223              delivery_name => name_case($order_info['customers_name']),
 224              delivery_company => '',
 225              delivery_address_1 => $order_info['delivery_street_address'],
 226              delivery_address_2 => '',
 227              delivery_city => $order_info['delivery_city'],
 228              delivery_state => $delivery_state,
 229              delivery_postcode => $order_info['delivery_postcode'],
 230              delivery_phone => $order_info['customers_telephone'],
 231              package_weight => $weight,
 232              package_value => $order_value,
 233              oversized => $oversized,
 234              pickup_date => $corrected_date,
 235              shipping_type => $HTTP_POST_VARS['service_type'],
 236              residential => $shipData[440],
 237              cod => '',
 238              );
 239                          
 240  // get the package weight/total weight and format it to one decimal place
 241              $total_weight = round($HTTP_POST_VARS['package_weight'], 1);
 242              $total_weight = sprintf("%01.1f", $total_weight);
 243  
 244  // deal with multiple packages
 245  
 246              if ($HTTP_POST_VARS['package_num'] > 1 ) {
 247                  $shipData[116] = $HTTP_POST_VARS['package_num'];
 248                  $shipData[1117] = $i;
 249                  $manifest_data['multiple'] = $i;
 250                          
 251                  if ($i == 1) {
 252                      if ($debug) {
 253                          $shipData[1400] = $total_weight;
 254                          $package_weight = $HTTP_POST_VARS['package_' . $i . '_weight'];
 255                          $package_weight = sprintf("%01.1f", $package_weight);
 256                          $shipData[1401] = $package_weight;
 257                          echo SHIPMENT_REQUEST_DATA . $i . ':<br><pre>';
 258                          print_r($shipData);
 259                          echo '</pre>';
 260                          $manifest_data['tracking_num'] = 'master_trackNum';
 261                          echo MANIFEST_DATA . $i . ':<br><pre>';
 262                          print_r($manifest_data);
 263                          echo '</pre>';
 264                          }
 265                      else {
 266                          $shipData[1400] = $total_weight;                        
 267                          $package_weight = round($HTTP_POST_VARS['package_' . $i . '_weight'],1);
 268                          $package_weight = sprintf("%01.1f", $package_weight);
 269                          $shipData[1401] = $package_weight;
 270                          $master_trackNum = tep_ship_request($shipData,$ship_type,$order);
 271                          $manifest_data['tracking_num'] = $master_trackNum;
 272                          }
 273                      }
 274                  else {
 275                      if ($debug) {
 276                          $shipData[1123] = 'master_trackNum';
 277                          $package_weight = $HTTP_POST_VARS['package_' . $i . '_weight'];
 278                          $package_weight = sprintf("%01.1f", $package_weight);
 279                          $shipData[1401] = $package_weight;
 280                          echo SHIPMENT_REQUEST_DATA . $i . ':<br><pre>';
 281                          print_r($shipData);
 282                          echo '</pre>';
 283                          $manifest_data['tracking_num'] = 'trackNum';
 284                          echo MANIFEST_DATA . $i . ':<br><pre>';
 285                          print_r($manifest_data);
 286                          echo '</pre>';
 287                          }
 288                      else {
 289                          $shipData[1123] = $master_trackNum;
 290                          $package_weight = round($HTTP_POST_VARS['package_' . $i . '_weight'],1);
 291                          $package_weight = sprintf("%01.1f", $package_weight);
 292                          $shipData[1401] = $package_weight;
 293                          $trackNum = tep_ship_request($shipData,$ship_type,$order);
 294                          $manifest_data['tracking_num'] = $trackNum;
 295                          }
 296                      }
 297                  }
 298  // for single package shipments
 299              elseif ($HTTP_POST_VARS['package_num'] == 1) {
 300                  if ($debug) {
 301                      $shipData[1401] = $total_weight;
 302                      echo SHIPMENT_REQUEST_DATA . $i . ':<br><pre>';
 303                      print_r($shipData);
 304                      echo '</pre>';
 305                      $manifest_data['tracking_num'] = 'master_trackNum';
 306                      echo MANIFEST_DATA . $i . ':<br><pre>';
 307                      print_r($manifest_data);
 308                      echo '</pre>';
 309                      }
 310                  else {
 311                      $shipData[1401] = $total_weight;
 312                      $master_trackNum = tep_ship_request($shipData,$ship_type,$order);
 313                      $manifest_data['tracking_num'] = $master_trackNum;
 314                      }            
 315                  }                    
 316  // post data to shipping manifest
 317              if ($debug==0) {
 318                  tep_db_perform(TABLE_SHIPPING_MANIFEST, $manifest_data);
 319                  }
 320              }
 321          
 322          if ($debug) {
 323              die(RUNNING_IN_DEBUG);
 324              }
 325                  
 326  ////
 327  // update the order record    
 328  
 329  // if there's a master tracking number, keep it with the order
 330              if ($master_trackNum) {
 331                  $trackNum = $master_trackNum;
 332                  }
 333                  
 334  // store the tracking number
 335              tep_db_query("update " . TABLE_ORDERS . " set fedex_tracking='" . $trackNum . "' where orders_id = " . $order . "");
 336                  
 337  // add comment to order history
 338              $fedex_comments = ORDER_HISTORY_DELIVERED . $trackNum;                            
 339  
 340  // ...mark the order record "delivered"...
 341              $update_status = array ('orders_status' => 3);
 342              tep_db_perform(TABLE_ORDERS, $update_status, 'update', "orders_id = '" . $order . "'");
 343  
 344              if ($send_email_on_shipping) {
 345                  $customer_notified = '1';
 346              }
 347              else {
 348                  $customer_notified = '0';
 349              }
 350                                  
 351              tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified, comments) values ('" . $order . "', '3', now(), '" . $customer_notified . "', '" . $fedex_comments  . "')");
 352  
 353  // send email automatically on shipping
 354              if ($send_email_on_shipping) {
 355                  $check_status_query = tep_db_query("select customers_name, customers_email_address, orders_status, date_purchased from " . TABLE_ORDERS . " where orders_id = '" . (int)$order . "'");
 356                  $check_status = tep_db_fetch_array($check_status_query);
 357      
 358                     if (tep_not_null($trackNum)) {
 359                      $email_notify_tracking = sprintf(EMAIL_TEXT_TRACKING_NUMBER) . "\n" . URL_TO_TRACK1 . nl2br(tep_output_string_protected($trackNum)) . "\n\n";
 360                  };
 361                  
 362                  $email_txt = STORE_NAME . "\n" . EMAIL_SEPARATOR . "\n" . EMAIL_TEXT_ORDER_NUMBER . ' ' . $order . "\n" . EMAIL_TEXT_INVOICE_URL . ' ' . tep_catalog_href_link(FILENAME_CATALOG_ACCOUNT_HISTORY_INFO, 'order_id=' . $order, 'SSL') . "\n" . EMAIL_TEXT_DATE_ORDERED . ' ' . tep_date_long($check_status['date_purchased']) . "\n\n" . $email_notify_tracking . sprintf(EMAIL_TEXT_STATUS_UPDATE, 'Shipped');
 363                  tep_mail($check_status['customers_name'], $check_status['customers_email_address'], EMAIL_TEXT_SUBJECT, $email_txt, STORE_OWNER, STORE_OWNER_EMAIL_ADDRESS);
 364              }
 365                                  
 366  // ... and display the new label without manifest entry for express shipments
 367              $ship_type_query = tep_db_query("select shipping_type from " . TABLE_SHIPPING_MANIFEST . " where orders_id = '" . $order . "'");
 368              $ship_type = tep_db_fetch_array($ship_type_query);
 369              if ($service_type < 89) {
 370                  $delete_manifest_query = tep_db_query("delete from " . TABLE_SHIPPING_MANIFEST . " where orders_id = '" . $order . "'");
 371              }
 372              tep_redirect('fedex_popup.php?num=' . $trackNum . '&oID=' . $order . '&multiple=' . $shipData[1117]);
 373      }
 374  
 375  // end ship request
 376  
 377  // if "action" is anything other than "ship," we can write out a regular admin page
 378  
 379      else {
 380  
 381  ////
 382  // cancel a scheduled shipment
 383  
 384          if($action=='cancel') {
 385          
 386              if (!$order) {
 387                  echo ERROR_NO_ORDER_SPECIFIED;
 388                  }
 389              elseif ($order) {
 390  
 391                  require (DIR_WS_INCLUDES . 'fedexdc.php');
 392                  $transaction_code = "023";
 393                  
 394  // get required config variables
 395                  $fedex_vars = array (
 396                  10=>'MODULE_SHIPPING_FEDEX1_ACCOUNT',
 397                  498=>'MODULE_SHIPPING_FEDEX1_METER'
 398                  );
 399  
 400  // determine if we're using test or production gateway
 401              $value_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FEDEX1_SERVER'");
 402              $value = tep_db_fetch_array($value_query);
 403              $fedex_gateway = $value['configuration_value'];
 404                      
 405              $i = 0;
 406              $fedex_keys = array_keys($fedex_vars);
 407                  
 408              foreach($fedex_vars as $var) {
 409                  $value_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = '" . $var . "'");
 410                  $value = tep_db_fetch_array($value_query);
 411                  $value = $value['configuration_value'];
 412          
 413                  $fedex_vars[$fedex_keys[$i]] = $value;
 414  
 415                  $i++;
 416              }                    
 417                      
 418  // create new FedExDC object
 419              $fed = new FedExDC($fedex_vars[10],$fedex_vars[498]);
 420                  
 421  // get the tracking number from the order record
 422              $fedex_tracking_query = tep_db_query("select fedex_tracking from " . TABLE_ORDERS . " where orders_id = '" . $order . "'");
 423              $r = tep_db_fetch_array($fedex_tracking_query);
 424              $fedex_tracking = $r['fedex_tracking'];
 425              
 426  // get the shipment type from the shipping manifest
 427              $ship_type_query = tep_db_query("select shipping_type from " . TABLE_SHIPPING_MANIFEST . " where orders_id = '" . $order . "'");
 428              $ship_type = tep_db_fetch_array($ship_type_query);
 429              if (($ship_type['shipping_type'] == 90) or ($ship_type['shipping_type'] == 92)) {
 430                  $ship_type = 'FDXG';
 431                  }
 432              else {
 433                  $ship_type = 'FDXE';
 434                  }
 435                  
 436  // simple array with transaction code, tracking number, carrier code
 437              $cancelData = array (
 438                  0 => $transaction_code,
 439                  1 => ORDER_NUMBER . $order, // order number, optional
 440                  29 => $fedex_tracking,
 441                  3025 => $ship_type
 442                  );
 443                  
 444              $cancelData = $fedex_keys+$cancelData;
 445                  
 446  // remove shipment data from the shipping manifest
 447              $delete_manifest_query = tep_db_query("delete from " . TABLE_SHIPPING_MANIFEST . " where orders_id = '" . $order . "'");
 448              if ($delete_manifest_query) {
 449                  }
 450              elseif (!$delete_manifest_query) {
 451                  echo COULD_NOT_DELETE_ENTRIES;
 452                  } 
 453  
 454  // cancel the shipment
 455              $cancelRet = $fed->cancel_ground($cancelData);
 456                  
 457  // todo: add appropriate error checking for at least some of the possible errors
 458              if ($error = $fed->getError()) {
 459                  die(ERROR . $error);
 460                  }
 461          
 462  // delete the tracking number from the order record
 463              $delete_trackNum = array('fedex_tracking' => '');
 464      
 465              tep_db_perform(TABLE_ORDERS, $delete_trackNum, 'update', "orders_id = '" . $order . "'");
 466  
 467  // ...mark the order record "pending"...
 468              $update_status = array ('orders_status' => 2);
 469              tep_db_perform(TABLE_ORDERS, $update_status, 'update', "orders_id = '" . $order . "'");
 470  
 471  // ...add a comment to the order history to show what we've done...
 472              $fedex_comments = ORDER_HISTORY_CANCELLED . $trackNum;
 473                      
 474              tep_db_query("insert into " . TABLE_ORDERS_STATUS_HISTORY . " (orders_id, orders_status_id, date_added, customer_notified, comments) values ('" . $order . "', 2, now(), '', '" . $fedex_comments  . "')");
 475  
 476  // ...delete the record from the manifest...
 477              tep_db_query("delete from " . TABLE_SHIPPING_MANIFEST . " where orders_id = '" . $order . "'");
 478              
 479  // ...and refresh the orders page
 480              tep_redirect(FILENAME_ORDERS . '?oID=' . $order);
 481              }
 482          }
 483  
 484  ////
 485  // make the form for additional shipment information
 486      
 487      elseif($action=='new') {
 488          $order = $HTTP_GET_VARS['oID'];
 489  
 490  // determine if we're using test or production gateway
 491          $value_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_SHIPPING_FEDEX1_SERVER'");
 492          $value = tep_db_fetch_array($value_query);
 493          $fedex_gateway = $value['configuration_value'];
 494              
 495  // arrays for shipping options; include as many or as few as you like
 496          $packaging_type = array();
 497          $packaging_type[] = array('id' => '01', 'text' => 'Other Packaging');
 498          $packaging_type[] = array('id' => '02', 'text' => 'FedEx Pak');
 499          $packaging_type[] = array('id' => '03', 'text' => 'FedEx Box');
 500          $packaging_type[] = array('id' => '04', 'text' => 'FedEx Tube');
 501          $packaging_type[] = array('id' => '06', 'text' => 'FedEx Envelope');
 502              
 503  
 504          $service_type = array();
 505          $service_type[] = array('id' => '92', 'text' => 'FedEx Ground Service');
 506          $service_type[] = array('id' => '01', 'text' => 'FedEx Priority');
 507          $service_type[] = array('id' => '03', 'text' => 'FedEx 2day');
 508          $service_type[] = array('id' => '05', 'text' => 'FedEx Standard Overnight');
 509          $service_type[] = array('id' => '06', 'text' => 'FedEx First Overnight');
 510          $service_type[] = array('id' => '20', 'text' => 'FedEx Express Saver');
 511          $service_type[] = array('id' => '70', 'text' => 'FedEx 1day Freight');
 512          $service_type[] = array('id' => '80', 'text' => 'FedEx 2day Freight');
 513          $service_type[] = array('id' => '83', 'text' => 'FedEx 3dayFreight');
 514          $service_type[] = array('id' => '90', 'text' => 'FedEx Home Delivery');
 515              
 516          $bill_type = array();
 517          $bill_type[] = array('id' => '01', 'text' => 'Bill sender (Prepaid)');
 518          $bill_type[] = array('id' => '02', 'text' => 'Bill recipient');
 519          $bill_type[] = array('id' => '03', 'text' => 'Bill third party');
 520          $bill_type[] = array('id' => '04', 'text' => 'Bill credit card');
 521          $bill_type[] = array('id' => '05', 'text' => 'Bill recipient for FedEx Ground');
 522  
 523          $dropoff_type = array();
 524          $dropoff_type[] = array('id' => 1, 'text' => 'Regular pickup');
 525          $dropoff_type[] = array('id' => 2, 'text' => 'Request courier');
 526          $dropoff_type[] = array('id' => 3, 'text' => 'Drop box');
 527          $dropoff_type[] = array('id' => 4, 'text' => 'Drop at BSC');
 528          $dropoff_type[] = array('id' => 5, 'text' => 'Drop at station');
 529  
 530          $oversized = array();
 531          $oversized[] = array('id' => 0, 'text' => '');
 532          $oversized[] = array('id' => 1, 'text' => 1);
 533          $oversized[] = array('id' => 2, 'text' => 2);
 534          $oversized[] = array('id' => 3, 'text' => 3);
 535                                  
 536  // get & format tomorrow's date for default pickup date
 537          $default_pickup_date = date('m-d-Y',strtotime('today'));
 538          
 539  // get the shipping method
 540          $shipping_query = tep_db_query("select title from " . TABLE_ORDERS_TOTAL . " where orders_id = '" . $order . "' and class='ot_shipping'");
 541          $shipping_method = tep_db_fetch_array($shipping_query);
 542          $shipping_method = trim($shipping_method['title'], ':');
 543          
 544          $shipping_method_keywords = array('90' => 'Home Delivery', 
 545                                            '92' => 'Ground Service', 
 546                                            '01' => 'Priority', 
 547                                            '03' => '2 Day Air', 
 548                                            '05' => 'Standard Overnight', 
 549                                            '06' => 'First Overnight', 
 550                                            '20' => 'Express Saver');
 551      
 552          $shipping_type='92'; // default to Fedex Ground                                  
 553          while (list($shipping_index, $shipping_keyword) = each($shipping_method_keywords)){                    
 554              if (false !== strpos($shipping_method, $shipping_keyword)){
 555                    $shipping_type=$shipping_index;
 556                    break 1;
 557              }
 558          }
 559                     
 560  // get orders information
 561          $order_query = tep_db_query("select * from orders where orders_id = $order");    
 562          $order_info = tep_db_fetch_array($order_query);
 563  
 564          // abbreviate the delivery country (function is in abbreviate.php)
 565          $delivery_country = $order_info['delivery_country'];
 566           
 567  // get the order qty and item weights
 568          $order_qty_query = tep_db_query("select * from " . TABLE_ORDERS_PRODUCTS . " where orders_id = '" . $order . "'");
 569          $order_qty = 0;
 570          $order_weight = 0;
 571          $order_item_html = '';
 572          if (tep_db_num_rows($order_qty_query)) {
 573                while ($order_qtys = tep_db_fetch_array($order_qty_query)){
 574                    $order_item_html = $order_item_html . '          <tr>' . "\n" .
 575                       '            <td class="smallText" align="center">' . $order_qtys['products_quantity'] . ' * ' .
 576                       $order_qtys['products_name'] . '</td>' . "\n" .
 577                       '            <td class="smallText" align="center">';
 578                  $order_qty = $order_qty + $order_qtys['products_quantity'];
 579                  $products_id = $order_qtys['products_id'];
 580                  $products_weight_query = tep_db_query("select * from " . TABLE_PRODUCTS . " where products_id = '" . $products_id . "'");
 581                  if (tep_db_num_rows($products_weight_query)) {
 582                      $products_weights = tep_db_fetch_array($products_weight_query);
 583                      $order_weight = $order_weight + ($order_qtys['products_quantity'] * ($products_weights['products_weight']));
 584                      $item_weights[] = $products_weights['products_weight'];
 585                  }
 586              }
 587              $order_weight = $order_weight + SHIPPING_BOX_WEIGHT;
 588              $order_weight = round($order_weight,1);
 589              $order_weight = sprintf("%01.1f", $order_weight);
 590          }
 591       }
 592  
 593  ?>
 594  <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
 595  <html <?php echo HTML_PARAMS; ?>>
 596  <head>
 597  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
 598  <title><?php echo TITLE; ?></title>
 599  <link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
 600  <script language="javascript" src="includes/general.js"></script>
 601  
 602  <script language="javascript">
 603  function validate() {
 604      weight=ship_fedex.package_weight.value;
 605      if (weight=='') {
 606          alert('<?php echo ENTER_PACKAGE_WEIGHT; ?>');
 607          event.returnValue=false;
 608          }
 609      package_num=ship_fedex.package_num.value;
 610      if (package_num=='') {
 611          alert('<?php echo ENTER_NUMBER_PACKAGES; ?>');
 612          event.returnValue=false;
 613          }
 614      }
 615  </script>
 616  
 617  </head>
 618  <body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF">
 619  <!-- header //-->
 620  <?php
 621    require (DIR_WS_INCLUDES . 'header.php');
 622  ?>
 623  <!-- header_eof //-->
 624  
 625  <!-- body //-->
 626  <table border="0" width="100%" cellspacing="2" cellpadding="2">
 627    <tr>
 628      <td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="1" cellpadding="1" class="columnLeft">
 629  <!-- left_navigation //-->
 630  <?php require (DIR_WS_INCLUDES . 'column_left.php'); ?>
 631  <!-- left_navigation_eof //-->
 632      </table></td>
 633  <!-- body_text //-->
 634      <td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="2">
 635        <tr>
 636          <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
 637  <?php
 638      // if it's a new shipment, write out the form for more data
 639      if ($action=='new') {
 640  ?>
 641            <tr>
 642              <td class="pageHeading"><?php 
 643                          echo HEADING_TITLE;
 644                          if ($order) {
 645                              echo ', ' . ORDER_NUMBER . $order;
 646                              }
 647                          elseif (!$order) {
 648                              echo ERROR_NO_ORDER_SPECIFIED;
 649                              }
 650                          ?></td>
 651              <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
 652              <td class="pageHeading" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ORDERS, 'oID=' . $order) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
 653              <?php echo $order_item_html;?>
 654  
 655            </tr>
 656          </table></td>
 657        </tr>
 658        <tr>
 659          <td>
 660                  <?php
 661                      // if quantity = 1, skip to shipping directly
 662                      if ($order_qty == 1){
 663                          echo tep_draw_form('ship_fedex', FILENAME_SHIP_FEDEX, 'cPath=' . $cPath . '&cID=' . $HTTP_GET_VARS['cID'] . '&oID=' . $order . '&action=ship', 'post', 'enctype="multipart/form-data"  onsubmit="validate();"');
 664                      }
 665                      // otherwise, go to a 2nd screen to key in individual weights
 666                      else {
 667                          echo tep_draw_form('ship_fedex', FILENAME_SHIP_FEDEX, 'cPath=' . $cPath . '&cID=' . $HTTP_GET_VARS['cID'] . '&oID=' . $order . '&action=post1', 'post', 'enctype="multipart/form-data"  onsubmit="validate();"');
 668                      }
 669                  ?>
 670                      <input type="hidden" name="order_item_html" value='<?php echo urlencode(serialize($order_item_html)); ?>'/>
 671                      <input type="hidden" name="item_weights" value='<?php echo urlencode(serialize($item_weights)); ?>'/>
 672                      <input type="hidden" name="fedex_gateway" value="<?php echo $fedex_gateway; ?>"/>
 673                      <table width="70%" border="0" cellspacing="0" cellpadding="2">
 674                <tr>
 675                  <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '15'); ?></td>
 676                </tr>
 677                            <tr>
 678                              <td class="main" align="right"><b><u>Required Fields</u></b></td>
 679                              <td></td>
 680                              <td></td>
 681                          </tr>
 682                          
 683                          <tr>
 684                              <td class="main" align="right">Number of Packages:</td>
 685                              <td class="main">&nbsp;</td>
 686                              <td class="main"><?php echo tep_draw_input_field('package_num',$order_qty,'size="2"'); ?></td>
 687                          </tr>
 688                          <tr>
 689                              <td class="main" align="right">Oversized?</td>
 690                              <td class="main">&nbsp;</td>
 691                              <td class="main"><?php echo tep_draw_pull_down_menu('oversized',$oversized); ?></td>
 692                          </tr>
 693                          <tr>
 694                              <td class="main" align="right">Packaging Type ("other" for ground shipments):</td>
 695                              <td class="main">&nbsp;</td>
 696                              <td class="main"><?php echo tep_draw_pull_down_menu('packaging_type',$packaging_type); ?></td>
 697                          </tr>
 698                          <tr>
 699                              <td class="main" align="right">Type of Service:</td>
 700                              <td class="main">&nbsp;</td>
 701                              <td class="main"><?php echo tep_draw_pull_down_menu('service_type',$service_type, $shipping_type); ?></td>
 702                          </tr>
 703                          <tr>
 704                              <td class="main" align="right">Payment Type:</td>
 705                              <td class="main">&nbsp;</td>
 706                              <td class="main"><?php echo tep_draw_pull_down_menu('bill_type',$bill_type); ?></td>
 707                          </tr>
 708                          <tr>
 709                              <td class="main" align="right">Dropoff Type:</td>
 710                              <td class="main">&nbsp;</td>
 711                              <td class="main"><?php echo tep_draw_pull_down_menu('dropoff_type',$dropoff_type); ?></td>
 712                          </tr>
 713                          <tr>
 714                              <td class="main" align="right">Pickup date (yyyymmdd):</td>
 715                              <td class="main">&nbsp;</td>
 716                              <td class="main"><?php echo tep_draw_input_field('pickup_date',$default_pickup_date,'size="9"'); ?></td>
 717                          </tr>
 718  
 719                          <tr>
 720                          <?php
 721                              if ($package_num > 1) {
 722                                  echo '<td class="main" align="right">' . TOTAL_WEIGHT . '</td>';
 723                                  }
 724                              else {
 725                                  echo '<td class="main" align="right">' . PACKAGE_WEIGHT . '</td>';
 726                                  }
 727                          ?>
 728                                  <td class="main">&nbsp;</td>
 729                                  <td class="main"><?php echo tep_draw_input_field('package_weight',(string) $order_weight,'size="2"'); ?></td>
 730                          </tr>
 731                          
 732                          <tr>
 733                            <td class="main">&nbsp;</td>
 734                          </tr>
 735                          <tr>
 736                              <td class="main" align="right"><b><u>Optional Fields</u></b></td>
 737                              <td></td>
 738                              <td></td>
 739                          </tr>
 740                          <tr>
 741                              <td class="main" align="right">Invoice #:</td>
 742                              <td class="main">&nbsp;</td>
 743                              <td class="main"><?php echo tep_draw_input_field('package_invoice','','size="33" maxlength="30"'); ?></td>
 744                          </tr>
 745                          <tr>
 746                              <td class="main" align="right">Reference #:</td>
 747                              <td class="main">&nbsp;</td>
 748                              <td class="main"><?php echo tep_draw_input_field('package_reference','','size="33" maxlength="30"'); ?></td>
 749                          </tr>
 750                          <tr>
 751                              <td class="main" align="right">Purchase Order #:</td>
 752                              <td class="main">&nbsp;</td>
 753                              <td class="main"><?php echo tep_draw_input_field('package_po',$order,'size="33" maxlength="30"'); ?></td>
 754                          </tr>
 755                          <tr>
 756                              <td class="main" align="right">Department Name:</td>
 757                              <td class="main">&nbsp;</td>
 758                              <td class="main"><?php echo tep_draw_input_field('package_department','','size="10" maxlength="10"'); ?></td>
 759                          </tr>
 760                                                                          
 761                          <tr>
 762                              <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '15'); ?></td>
 763                          </tr>
 764                          <tr>
 765                              <td>&nbsp;</td>
 766                              <td>&nbsp;</td>
 767                              <td><?php echo tep_image_submit('button_submit.gif', IMAGE_SUBMIT); ?></td>
 768                          <tr>
 769                      </table>
 770          </form>
 771  <?php
 772          }
 773          
 774      // new form accepts total weight and individual weights
 775      // if there are multiple packages
 776      elseif ($action=='post1') {
 777          $package_num = $HTTP_POST_VARS['package_num'];
 778          $order_item_html = unserialize(urldecode($HTTP_POST_VARS['order_item_html']));
 779          $item_weights = unserialize(urldecode($HTTP_POST_VARS['item_weights']));
 780  ?>        
 781            <tr>
 782              <td class="pageHeading"><?php 
 783                          echo HEADING_TITLE;
 784                          if ($order) {
 785                              echo ', ' . ORDER_NUMBER . $order;
 786                              }
 787                          elseif (!$order) {
 788                              echo ERROR_NO_ORDER_SPECIFIED;
 789                              }
 790                          ?></td>
 791              <td class="pageHeading" align="right"><?php echo tep_draw_separator('pixel_trans.gif', 1, HEADING_IMAGE_HEIGHT); ?></td>
 792              <td class="pageHeading" align="right"><?php echo '<a href="' . tep_href_link(FILENAME_ORDERS, 'oID=' . $order) . '">' . tep_image_button('button_back.gif', IMAGE_BACK) . '</a>'; ?></td>
 793              <?php echo $order_item_html;?>
 794            </tr>
 795          </table></td>
 796        </tr>
 797        <tr>
 798          <td>
 799                      <?php echo tep_draw_form('ship_fedex', FILENAME_SHIP_FEDEX, 'cPath=' . $cPath . '&cID=' . $HTTP_GET_VARS['cID'] . '&oID=' . $order . '&action=ship', 'post', 'enctype="multipart/form-data"  onsubmit="validate();"'); ?>
 800                      <input type="hidden" name="fedex_gateway" value="<?php echo $fedex_gateway; ?>"/>
 801                      <input type="hidden" name="package_num" value = "<?php echo $package_num; ?>"/>
 802                      <input type="hidden" name="oversized" value="<?php echo $HTTP_POST_VARS['oversized']; ?>"/>
 803                      <input type="hidden" name="residential" value="<?php echo $HTTP_POST_VARS['residential']; ?>"/>
 804                      <input type="hidden" name="packaging_type" value="<?php echo $HTTP_POST_VARS['packaging_type']; ?>"/>
 805                      <input type="hidden" name="service_type" value="<?php echo $HTTP_POST_VARS['service_type']; ?>"/>
 806                      <input type="hidden" name="payment_type" value="<?php echo $HTTP_POST_VARS['payment_type']; ?>"/>
 807                      <input type="hidden" name="bill_type" value="<?php echo $HTTP_POST_VARS['bill_type']; ?>"/>
 808                      <input type="hidden" name="dropoff_type" value="<?php echo $HTTP_POST_VARS['dropoff_type']; ?>"/>
 809                      <input type="hidden" name="pickup_date" value="<?php echo $HTTP_POST_VARS['pickup_date']; ?>"/>
 810                      <input type="hidden" name="package_invoice" value="<?php echo $HTTP_POST_VARS['package_invoice']; ?>"/>
 811                      <input type="hidden" name="package_reference" value="<?php echo $HTTP_POST_VARS['package_reference']; ?>"/>
 812                      <input type="hidden" name="package_po" value="<?php echo $HTTP_POST_VARS['package_po']; ?>"/>
 813                      <input type="hidden" name="package_department" value="<?php echo $HTTP_POST_VARS['package_department']; ?>"/>
 814                      <table width="70%" border="0" cellspacing="0" cellpadding="2">
 815                <tr>
 816                  <td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '15'); ?></td>
 817                </tr>
 818                          <tr>
 819                              <td class="main" align="right">
 820  <?php
 821                          if ($package_num > 1) {
 822                              echo TOTAL_WEIGHT . '</td>';
 823                              }
 824                          else {
 825                              echo PACKAGE_WEIGHT . '</td>';
 826                              }
 827  ?>
 828                              <td class="main">&nbsp;</td>
 829                              <td class="main"><?php echo tep_draw_input_field('package_weight','','size="2"'); ?></td>
 830                          </tr>
 831  
 832  <?php
 833                          if ($package_num > 1) {
 834                              echo '<tr>';
 835                              for ($i = 1; $i <= $package_num; $i++) {
 836                                  echo '<td class="main" align="right">Package #' . $i . ' Weight:</td>';
 837                                  echo '<td class="main">&nbsp;</td>';
 838                                  $item_weight_rounded = sprintf("%01.1f", array_pop($item_weights));
 839                                  echo '<td class="main">' . tep_draw_input_field('package_' . $i . '_weight', $item_weight_rounded, 'size="2"') . '</td>';
 840                                  $div = $i/3;
 841                                  if (is_int($div) && ($i != $package_num)) {
 842                                      echo '</tr><tr>';
 843                                      }
 844                                  }
 845                              echo '</tr>';
 846                          }
 847  ?>
 848                          <tr>
 849                              <td>&nbsp;</td>
 850                              <td>&nbsp;</td>
 851                              <td><?php echo tep_image_submit('button_submit.gif', IMAGE_SUBMIT); ?></td>
 852                          <tr>
 853                      </table>
 854                      </form>
 855  <?php
 856              }
 857  ?>
 858                      </td>
 859                          
 860            </tr>
 861          </table></td>
 862        </tr>
 863      </table></td>
 864  <!-- body_text_eof //-->
 865    </tr>
 866  </table>
 867  <!-- body_eof //-->
 868  
 869  <!-- footer //-->
 870  <?php require (DIR_WS_INCLUDES . 'footer.php'); ?>
 871  <!-- footer_eof //-->
 872  <br>
 873  </body>
 874  </html>
 875  <?php require (DIR_WS_INCLUDES . 'application_bottom.php'); 
 876  }
 877  ?>    


Generated: Fri Jan 1 13:43:16 2010 Cross-referenced by PHPXref 0.7