report_app.php
Purpose: Hosts the Small Parcel Report App by embedding a Transtream/Pierbridge widget within an authenticated PHP page.
Overview
This script serves as a secure container for the Small Parcel “Report App” widget. It:
- Verifies user permissions via session variables 🔒
- Loads global configuration and shared templates 📦
- Renders an
<iframe>pointing to the external widget URL - Establishes a cross-page communication channel to exchange events and data
🔒 Permissions & Session Check
Ensures only authenticated Pierbridge users access the report app.
<?php
$pier_login = '';
if ($_SESSION['pier_bridge_user_name'] != '') {
$pier_login = $_SESSION['pier_bridge_user_name'];
} else {
$pier_login = $_SESSION['pier_refrence'];
}
if ($pier_login == '') {
echo 'Permission Denied';
exit;
}
?>
- pier_bridge_user_name: Primary identifier
- pier_refrence: Fallback reference
- Denies access if neither is set
📦 Includes & Dependencies
| File | Purpose |
|---|---|
| inc/config.php | Site-wide constants & session start |
| TEMPLATE_DIR/inc/template_meta.php | HTML <head> metadata (SEO, CSS/JS links) |
| inc/panels/meta.php | Common <meta> tags and scripts |
| inc/panels/header-inner.php | Inner-page header/navigation |
| inc/panels/footer-home.php | Standard footer |
include_once("inc/config.php");
include_once(TEMPLATE_DIR . "inc/template_meta.php");
include_once("inc/panels/meta.php");
include_once("inc/panels/header-inner.php");
...
include_once("inc/panels/footer-home.php");
These build the shared layout and configuration
📄 HTML Structure
- DOCTYPE &
<html>: XHTML 1.0 Transitional <head>:<meta charset="utf-8"><title>Small Parcel</title>- jQuery, HubCAPP, and crossPageCommunication scripts
<body>:- Optional order prompt
<iframe id="transtreamWidget">for the widget- In-page
<script>to wire up the widget
<iframe
id="transtreamWidget"
name="small_package"
src=""
scrolling="no"
frameborder="0"
width="1040"
height="900">
</iframe>
🔗 Widget Initialization & Communication
Establishes a messaging channel between host page and widget iframe.
// Prepare
var myWidgetUrl = '<?=$_SESSION['pier_url']?>';
var appUrls = [ myWidgetUrl ];
var appInfo, myWidgetInfo, myWidgetConnector;
// On window load: initialize crossPageCommunication
window.onload = function() {
appInfo = crossPageCommunication({
serverUrl: '<?=$_SESSION['pier_hc_url']?>',
requestedUrls: appUrls,
licenseKey: '<?=$_SESSION['licenseKey']?>',
userToken: '<?=$pier_login?>'
});
if (appInfo && appInfo.length) {
myWidgetInfo = appInfo[0];
myWidgetConnector = myWidgetInfo.connector;
// Listen for widget load completion
myWidgetConnector.bind("LoadComplete", function(data) {
if (data === 'Complete') {
var address = { /* …address fields… */ };
myWidgetConnector.sendEvent("ReturnData", address);
}
});
}
// On DOM ready: set iframe src
$(document).ready(function() {
$('#transtreamWidget').attr('src', myWidgetInfo.appUrl);
});
};
- crossPageCommunication bootstraps a secure channel
- LoadComplete event triggers data push
- ReturnData sends an address object 🔗
Widget Flow Diagram
sequenceDiagram
participant Host as report_app.php
participant CPC as crossPageCommunication
participant Widget as iframe
Host->>CPC: init({ serverUrl, URLs, licenseKey, userToken })
CPC-->>Host: [{ appUrl, connector }]
Host->>Widget: set src = appUrl
Widget-->>Host: LoadComplete event
Host->>Widget: sendEvent("ReturnData", address)
⚙️ Session Variables Used
| Variable | Description |
|---|---|
| pier_bridge_user_name | Pierbridge login name |
| pier_refrence | Pierbridge reference fallback |
| pier_url | Widget application URL |
| pier_hc_url | Host connector service URL |
| licenseKey | Widget license key |
These are set upstream during user authentication
🛠️ How to Deploy
- Configure Pierbridge credentials in the database so that
inc/config.phppicks them up into$_SESSION. - Ensure TEMPLATE_DIR and site constants are correct.
- Grant users the
small_packagefeature flag ($_SESSION['small_package'] == 'Y') to display the menu links. - Place
report_app.phpunderlinuxfront-v2-logistics/. - Access via
small_parcel.php?url=report_appfrom within the secured app.
End of Documentation 🚀