linuxfront-v2-logistics/small_parcel.php

This PHP script powers the Small Parcel rate-shopping and booking page. It authenticates the user, configures the Pierbridge API endpoint, renders the HTML interface, fetches carrier rates, and provides booking forms.

Initialization & Includes 🛠️

The file begins by loading core configuration and template files:

<?php
include_once("inc/config.php");
include_once(TEMPLATE_DIR . "inc/template_meta.php");
include_once("inc/panels/meta.php");
include_once("inc/panels/header-home.php");

These bring in database credentials, session setup, HTML <head> metadata, and the site header .

Session & Authentication 🔐

  • $_SESSION['Customer_ID'] determines the current customer.
  • $_SESSION['pier_bridge_user_name'] may override the default Pierbridge login.
  • Fallbacks check vendor-specific credentials and user defaults via:
    • get_customer_small_package_vendorspecific_details()
    • getUserPierDetails()
    • getUserDefaultLocation()
  • If no valid Pierbridge login is found, the script terminates with “Permission Denied” .

API Configuration 📑

Based on the session, the script retrieves API details and constructs the endpoint:

if ($_SESSION['Customer_ID'] == '7' && false) {
    $small_package_details = get_customer_small_package_details('7');
    $api_url = $small_package_details->url . '?ApiKey=';
} else {
    $small_package_details = get_customer_small_package_details('1374');
    $api_url = "https://valmet.transtream.com/Logistics%20server/xmlservice.aspx?ApiKey=";
}
  • get_customer_small_package_details() fetches the base URL and API key reference .
  • $pier_login and $api_url pair provide authenticated access to the rate-shopping service.

HTML Structure & Assets 🖥️

The script outputs a full XHTML page beginning with:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8" />
  <title>Small Parcel</title>
  <script src="https://valmetHC.transtream.com/Common/jquery-2.1.1/jquery-2.1.1.min.js"></script>
  <!-- Additional CSS/JS includes -->
</head>
<body>
  <!-- Page content -->

This sets up the UI container, includes jQuery for AJAX, and defines the page title .

Rate Table Rendering 🔢

Once the page loads, server-side PHP loops over the $small_package_carriers array to display each carrier’s name and transit days:

<table class="table-listing">
  <thead>
    <tr>
      <th>Carrier</th>
      <th>Transit Days</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody id="fbody_small">
    <?php for ($c = 0; $c < $newcount_small; $c++): ?>
      <tr id="<?= $carrier_id . '-' . $serviceDetail ?>">
        <td><?= $small_package_carriers[$c]['Name'] ?></td>
        <td>
          <?= ($small_package_carriers[$c]['ServiceDays'] != '-1')
                ? $small_package_carriers[$c]['ServiceDays']
                : '' ?>
        </td>
        <td class="text-right">
          <!-- Booking form inserted here -->
        </td>
      </tr>
    <?php endfor; ?>
  </tbody>
</table>

This table drives the rate comparison UI .

Booking Form & Hidden Fields 📝

Each carrier row includes a <form> with hidden inputs to pass booking details to small_package.php:

<form method="post" action="small_package.php">
  <input type="hidden" name="action" value="bookthisshipment" />
  <input type="hidden" name="carrier_scac" value="<?= $carrierSCAC ?>" />
  <input type="hidden" name="net_charges"  value="<?= $Rate ?>" />
  <input type="hidden" name="service_days" value="<?= $ServiceDays ?>" />
  <!-- Additional hidden fields for fuel, PPA, origin/destination -->
  <button type="submit" class="btn btn-primary">Book</button>
</form>

This ensures all required data—SCAC, rates, transit, accessorials—travels securely via POST .

JavaScript & AJAX Integration 🔄

  • jQuery is used for any dynamic interactions (e.g., fetching new rates when parameters change).
  • Custom scripts likely trigger AJAX calls to the $api_url endpoint, parse XML/JSON, and update the DOM.

Data Flow Overview

flowchart TD
  A[User opens small_parcel.php] --> B{Session Valid?}
  B -- No --> C[Show "Permission Denied"]
  B -- Yes --> D[Determine Pierbridge login & API URL]
  D --> E[Render HTML & include JS]
  E --> F[JS/AJAX requests rates from API URL]
  F --> G[Server returns carriers & rates]
  G --> H[Populate rate table]
  H --> I[User selects carrier & clicks Book]
  I --> J[POST booking data to small_package.php]

Integration Points & Dependencies 🔗

  • small_package.php receives booking requests.
  • inc/config.php and template panels provide shared functions.
  • Core functions:
    • get_customer_small_package_details()
    • get_customer_small_package_vendorspecific_details()
    • getUserPierDetails()
    • getUserDefaultLocation()
  • Relies on session management and Pierbridge web services for rate quotes and booking.