linuxfront-v2-logistics/small_parcel.php

Overview

This script embeds the Pierbridge “Small Parcel” widget into the customer portal.
It fetches API credentials, validates user permissions, and dynamically loads an iframe.

⚙️ Dependencies

  • inc/config.php: Core configuration and database connection.
  • TEMPLATE_DIR/inc/template_meta.php: Page metadata and assets.
  • inc/panels/meta.php & inc/panels/header-home.php: Header UI components.
  • inc/panels/footer-home.php: Footer UI component.

Authentication & User Login

  • Initializes $pier_login from session $_SESSION['pier_bridge_user_name'].
  • Falls back to customer reference stored in $small_package_details->refrence.
  • Denies access if $pier_login remains empty.
if ($_SESSION['pier_bridge_user_name'] != '') {
    $pier_login = $_SESSION['pier_bridge_user_name'];
} else {
    $pier_login = $small_package_details->refrence;
}
if ($pier_login == '') {
    echo 'Permission Denied';
    exit;
}

🛠️ Vendor-Specific & User-Specific Overrides

  1. Vendor override

    • Calls get_customer_small_package_vendorspecific_details(customer_id)
    • If result provides ->login, it replaces $pier_login.
  2. User override

    • Fetches additional details via getUserPierDetails($_SESSION['user_id']).
    • If present, uses that pier_bridge_user_name.
    • Otherwise, checks getUserDefaultLocation() and reapplies vendor override.

🔗 URL Parameter Handling

  • Reads $_REQUEST['url']; defaults to 'url' when empty.
  • Uses this key to pick the corresponding widget URL property from $small_package_details.
$url = $_REQUEST['url'] ?: 'url';
$myWidgetUrl = $small_package_details->$url;

🖥️ HTML Structure

  • Sets XHTML transitional doctype.
  • Loads external scripts: jQuery, hubcapp.min.js, crossPageCommunication.min.js.
  • Displays an optional order prompt if order_id is provided.
  • Renders <iframe id="transtreamWidget"> to host the widget.
<p>Pier Login: <?=$pier_login?></p>
<iframe id="transtreamWidget" width="100%" height="100%" frameborder="0"></iframe>

🚀 JavaScript Widget Integration

  1. Initialize Communication
    • On window.onload, calls crossPageCommunication({ serverUrl, requestedUrls, licenseKey, userToken }).
  2. Bind Events
    • Watches for "LoadComplete" from the widget.
    • Example sends an address back via sendEvent("ReturnData", address).
  3. Load Iframe
    • On $(document).ready, sets #transtreamWidget.src = appInfo[0].appUrl.
window.onload = function() {
  appInfo = crossPageCommunication({ 
    serverUrl: '<?=$small_package_details->hc_url?>',
    requestedUrls: appUrls,
    licenseKey: '<?=$small_package_details->licenseKey?>',
    userToken: '<?=$pier_login?>'
  });
  // Bind LoadComplete…
  myWidgetConnector.bind("LoadComplete", data => {
    if (data === 'Complete') {
      myWidgetConnector.sendEvent("ReturnData", address);
    }
  });
  // On ready, set iframe src
  $(document).ready(() => {
    $('#transtreamWidget').attr('src', myWidgetInfo.appUrl);
  });
};

Flowchart of Execution

flowchart TD
  A[Include configs & templates]
  B[Fetch small_package_details<br/>& set API URL]
  C[Determine $pier_login]
  D{Is $pier_login empty?}
  E[Exit with 'Permission Denied']
  F[Vendor-specific override]
  G[User-specific override]
  H[Resolve $url parameter]
  I[Render HTML & iframe]
  J[window.onload → crossPageCommunication]
  K[Bind LoadComplete → sendEvent]
  L[document.ready → set iframe src]

  A --> B --> C --> D
  D -- Yes --> E
  D -- No --> F --> G --> H --> I --> J --> K --> L

This file acts as the bridge between the Tech Logistics portal and the Pierbridge widget, handling credentials, session logic, and seamless iframe integration.