linuxfront-v2-logistics/inc/panels/subheader.php
This panel renders a customer-switcher sub-header for admin users, allowing them to quickly switch context between related customer accounts. Currently, the entire block is wrapped in HTML comments, so it’s inactive by default.
🔍 Purpose
- Provide a drop-down menu of all companies related to the current customer.
- Temporarily assume primary_user context to fetch the full customer tree.
- Post the selection to
cs_login.phpto re-login as the chosen customer.
⚙️ Dependencies & Interactions
- PHP Sessions
$_SESSION['login_as']: Tracks current login role.$_SESSION['Customer_ID']: Identifies the active customer.
- GenerateCustomersTreeDDL
Renders the<select>element with nested options of related customers . - cs_login.php
Handles the switch-user action and redirects appropriately.
| Variable | Description |
|---|---|
$_SESSION['login_as'] |
Current login role ("primary_user", etc.) |
$_SESSION['Customer_ID'] |
ID of the customer whose context is active |
$ComboWhere |
SQL filter for related companies |
$topHeaderComboBox |
HTML <select> generated by GenerateCustomersTreeDDL |
🧩 Code Walkthrough
1. HTML Comment Block
<!---
<div class="mw-bottomstrip 123">
<?php /* echo '<pre>'; print_r($_SESSION); exit; */ ?>
...
</div>
---->
The entire UI and PHP logic is wrapped in HTML comments, disabling it by default.
2. Session Role Management
<?php
$login_as = $_SESSION['login_as'];
$_SESSION['login_as'] = "primary_user";
$Customer_ID = $_SESSION['Customer_ID'];
?>
- Saves the original
login_as. - Overrides it to
"primary_user"to ensure full access when building the tree.
3. Dropdown Generation
<?php
$ComboWhere = "customer_id IN (
SELECT company_id
FROM customers_relations
WHERE customer_id = $Customer_ID
)";
$topHeaderComboBox = GenerateCustomersTreeDDL(
'customer_id',
$ComboWhere,
$Customer_ID,
'',
'class="top-bar-select-menu"'
);
?>
- Builds a WHERE clause to fetch all companies linked to the current customer.
- Calls GenerateCustomersTreeDDL to output a
<select>with those companies .
4. Form & Submission
<form method="post"
name="top_header_companies_frm"
id="top_header_companies_frm"
action="cs_login.php">
<input type="hidden" name="action" value="customer_id" />
<input type="hidden" name="rforPage" value="start_quote_v3.php" />
<input type="hidden" name="header_view" value="1" />
<a href="javascript:{};" id="submit-auto-login-frm" style="float:right;">
<img src="images/common/go.gif" alt="Go" />
</a>
<?=$topHeaderComboBox?>
</form>
- Hidden inputs control backend behavior:
action=customer_idrforPage=start_quote_v3.phpheader_view=1
- The Go link (
id="submit-auto-login-frm") triggers form submission via JavaScript.
5. Session Reset
<?php
$_SESSION['login_as'] = $login_as;
?>
Restores the original login_as value to avoid side effects elsewhere.
📂 Related Files
- right_nav2.php
Side-panel version for switching location_id instead ofcustomer_id. - cs_login.php
Endpoint that re-authenticates as the selected customer (seecs_login_cors/cs_login_top.phpfor the CORS-enabled implementation).
🚀 Integration & Usage
- Include this sub-header in page templates when
header_view=1is set. - Empowers master users to impersonate or switch between company accounts without logging out.