view_app.php

This script renders the Small Parcel widget inside an authenticated page. It verifies user credentials, includes shared templates, and embeds a Transtream widget via an <iframe>. It uses cross‐page communication to securely pass session and licensing data to the widget.

⚙️ Session Validation

Ensures only logged-in Pierbridge users can access the page.

<?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;
}
?>
  • Checks $_SESSION['pier_bridge_user_name'] first.
  • Falls back to $_SESSION['pier_refrence'].
  • Exits with a message if no valid login is found.

🛠️ Template Includes

Loads configuration, metadata, and inner header panels before outputting HTML.

include_once("inc/config.php");                             // App constants, sessions 
include_once(TEMPLATE_DIR . "inc/template_meta.php");        // Page meta tags, CSS/JS injection
include_once("inc/panels/meta.php");                         // Shared JavaScript utilities
include_once("inc/panels/header-inner.php");                 // Authenticated header UI
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta charset="utf-8" />
  <title>Small Parcel</title>
  <!-- External libraries -->
  <script src="https://techlogisticsdemoHC.transtream.com/Common/jquery-2.1.1/jquery-2.1.1.min.js"></script>
  <script src="https://techlogisticsdemoHC.transtream.com/Common/js/hubcapp.min.js"></script>
  <script src="https://techlogisticsdemoHC.transtream.com/Common/js/crossPageCommunication.min.js"></script>
</head>

📦 Widget Embedding

Displays the Transtream widget in a fixed-size iframe.

<body>
  <!-- Optional prompt if an order number is provided -->
  <?php if ($_REQUEST['order_id'] != '') { ?>
    <h1>Please enter Order# <?= $_REQUEST['order_id'] ?> below and search it!</h1>
  <?php } ?>

  <iframe
    name="small_package"
    id="transtreamWidget"
    src=""
    scrolling="no"
    frameborder="0"
    width="1040"
    height="900"
  ></iframe>

🔄 Widget Initialization & Communication

Leverages crossPageCommunication to authorize and load the widget, then binds events.

<script>
  // Collect the widget URL from session
  var myWidgetUrl    = '<?=$_SESSION['viewapp_url']?>';
  var appInfo        = null;
  var appUrls        = [ myWidgetUrl ];
  var myWidgetInfo   = null;
  var myWidgetConnector = null;

  window.onload = function() {
    try {
      // Initialize cross‐page communication
      appInfo = crossPageCommunication({
        serverUrl:    '<?=$_SESSION['pier_hc_url']?>',
        requestedUrls: appUrls,
        licenseKey:   '<?=$_SESSION['licenseKey']?>',
        userToken:    '<?=$pier_login?>'
      });
    } catch (err) {
      console.log(err); // silent failure
    }

    // If initialization succeeded, bind to the widget connector
    if (appInfo && appInfo.length > 0) {
      myWidgetInfo      = appInfo[0];
      myWidgetConnector = myWidgetInfo.connector;

      // When the widget finishes loading:
      myWidgetConnector.bind("LoadComplete", function(data) {
        if (data === 'Complete') {
          // Example of sending data back to the widget
          var address = {
            attentionTo:   "Mr Shipper",
            company:       "Pierbridge",
            address1:      "67 Forest St",
            address2:      "Suite 288",
            city:          "Marlboro",
            stateProvince: "MA",
            postalCode:    "01752",
            countryCode:   "US",
            phone:         "8005551212",
            email:         "[email protected]"
          };
          console.log({address});
          myWidgetConnector.sendEvent("ReturnData", address);
        }
      });
    }
  };

  // After DOM ready, set the iframe src to load the widget
  $(document).ready(function() {
    if (myWidgetInfo && myWidgetConnector) {
      console.log('Loading widget at', myWidgetInfo.appUrl);
      $('#transtreamWidget').attr('src', myWidgetInfo.appUrl);
    }
  });
</script>

🔍 Load Flowchart

flowchart TD
  A[User opens view_app.php] --> B{Valid Session?}
  B -- Yes --> C[Include config & templates]
  C --> D[Render iframe placeholder]
  D --> E[window.onload → crossPageCommunication]
  E --> F{appInfo available?}
  F -- Yes --> G[Bind "LoadComplete" event]
  G --> H[Document ready → set iframe src]
  B -- No  --> I[Echo "Permission Denied" & exit]

📝 Summary

  • Validates user via session variables.
  • Includes shared templates (config.php, template_meta.php, panel files).
  • Renders an <iframe> placeholder for the Small Parcel widget.
  • Initializes secure cross‐page communication using crossPageCommunication.
  • Binds to widget events (e.g. LoadComplete) to exchange data.
  • Loads the widget app URL into the iframe once communication is ready.

This page serves as a host shell for the Transtream Small Parcel widget, seamlessly integrating Pierbridge authentication and licensing into the embedded application.