CMS Page Renderer (📄 cms.php)

This script powers the static CMS pages of the Tech Logistics site. It validates the requested page key, loads the corresponding content from the database cache, injects global templates (header, footer, meta), and renders two AJAX-driven contact forms with client-side validation.

Dependencies

Include Purpose
inc/config.php Starts session, defines constants, builds $staticPagesArray from static_pages table
TEMPLATE_DIR/inc/template_meta.php Injects global <meta> tags, CSS & JS assets
inc/panels/meta.php Adds page-specific meta elements (charset, viewport)
inc/panels/header-home.php Site header and primary navigation bar
inc/panels/footer-home.php Site footer with links, social icons, and chat widget
request_consultation_email.php ↑ AJAX endpoint for “Request Consultation” form
send_quote.php ↑ AJAX endpoint for “Get a Quote” form

Request Flow

flowchart TD
  A[User hits cms.php?p=page_key] --> B{Load<br>$staticPagesArray}
  B -->|Missing key| C[Redirect to index.php]
  B -->|Valid key| D[Set<br>$currentcmsPageArray]
  D --> E[Render Head<br>(meta, CSS, JS)]
  E --> F[Include Header<br> & Breadcrumbs]
  F --> G[Output<br>Page Title & Text]
  G --> H[Initialize Forms<br>& JS Validation]
  H --> I[Include Footer]
  I --> J[End]

This flowchart outlines how cms.php validates the page key, includes global templates, outputs the content, and wires up AJAX forms.

Configuration & Page Data

All static pages come from the static_pages table. On every request, inc/config.php runs:

$staticPagesArray = [];
$cmsPagesRes = Query(
  "SELECT * FROM `static_pages` WHERE portal = '".Encode(PORTAL)."' 
   AND is_active = 'Y' ORDER BY page_order"
);
while($row = GetObj($cmsPagesRes)) {
    $staticPagesArray[$row->page_key] = object_2_array($row);
    $TEMPLATE[$row->page_key . ".php"] = '';
}

This populates $staticPagesArray keyed by page_key for quick lookup .

Initialization & Validation

At the top of cms.php, the script:

<?php
include_once("inc/config.php");
if (empty($currentcmsPage) || empty($staticPagesArray[$currentcmsPage])) {
    header("Location: index.php");
    exit;
}
$currentcmsPageArray = $staticPagesArray[$currentcmsPage];
?>
  • Includes global config.
  • Checks whether $currentcmsPage exists and is active.
  • Redirects invalid requests to the homepage.

Head Section: Metadata & Scripts

Within <head>…</head>, the file:

  • Includes global meta and template metadata.
  • Defines a CSS rule for .error in forms.
  • Registers two jQuery Validate setups:
    • #mail form for general inquiries (request_consultation_email.php).
    • #request_consultation_email form for quote requests (send_quote.php).
<script>
$(document).ready(function(){
  $("#mail").validate({ /* rules & AJAX submit */ });
  $("#request_consultation_email").validate({ /* rules & AJAX submit */ });
});
</script>

Form Handling & AJAX

  • Client-side Validation: Uses jQuery Validate plugin.
  • submitHandler: Serializes the form and posts via AJAX.
  • Response Handling: On 'Success', shows a success banner; otherwise, shows an error.
Form ID Endpoint Purpose
#mail request_consultation_email.php Contact form
#request_consultation_email send_quote.php Get-a-quote form

For legal and “About Us” pages (privacy_policy, terms_and_conditions, notification_of_infringement_dmca_policy, about_us), the script:

  • Sets $cms_breadcrumb to true when a customer is logged in.
  • Injects a breadcrumb section above the main content:
    <section class="breadcrumb-container">
      <nav aria-label="breadcrumb">…</nav>
    </section>
    
  • Wraps the page content in a container with .cms-pages.

Content Rendering

Inside the <body>:

  • Header: Chooses header-home.php with or without breadcrumb based on session.
  • Title: Renders <h2><?= Decode($page_name) ?></h2>.
  • Body Text: Echoes <?= Decode($page_text) ?> from DB.
  • Conditional Closing Tags: Closes wrapper divs for pages using the special layout.

Finally, the script includes the global footer:

include_once("inc/panels/footer-home.php");

This adds site-wide links, social icons, and the support chat widget.


By orchestrating configuration, template includes, and AJAX-driven forms, cms.php delivers a flexible CMS page renderer without a heavy framework, ensuring consistency across all static pages.