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_loginfrom session$_SESSION['pier_bridge_user_name']. - Falls back to customer reference stored in
$small_package_details->refrence. - Denies access if
$pier_loginremains 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
-
Vendor override
- Calls
get_customer_small_package_vendorspecific_details(customer_id) - If result provides
->login, it replaces$pier_login.
- Calls
-
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.
- Fetches additional details via
🔗 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_idis 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
- Initialize Communication
- On
window.onload, callscrossPageCommunication({ serverUrl, requestedUrls, licenseKey, userToken }).
- On
- Bind Events
- Watches for
"LoadComplete"from the widget. - Example sends an address back via
sendEvent("ReturnData", address).
- Watches for
- Load Iframe
- On
$(document).ready, sets#transtreamWidget.src = appInfo[0].appUrl.
- On
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.