Difference between revisions of "Creating Pages"

From WHMCS Documentation

Line 3: Line 3:
 
To get started, simply copy & paste the code below into a new PHP file and save it in the main WHMCS directory.
 
To get started, simply copy & paste the code below into a new PHP file and save it in the main WHMCS directory.
  
 +
'''*Updated for Version 5.2*'''
 +
 +
<source lang="php">
 
  <?php
 
  <?php
 
   
 
   
 
  define("CLIENTAREA",true);
 
  define("CLIENTAREA",true);
  //define("FORCESSL",true); # Uncomment to force the page to use https://
+
  //define("FORCESSL",true); // Uncomment to force the page to use https://
 
   
 
   
  require("dbconnect.php");
+
  require("init.php");
require("includes/functions.php");
 
require("includes/clientareafunctions.php");
 
 
   
 
   
  $pagetitle = $_LANG['clientareatitle'];
+
  $ca = new WHMCS_ClientArea();
$breadcrumbnav = '<a href="index.php">'.$_LANG['globalsystemname'].'</a>';
 
$breadcrumbnav .= ' > <a href="mypage.php">My Page</a>';  
 
 
   
 
   
  <nowiki>initialiseClientArea($pagetitle,'',$breadcrumbnav);</nowiki>
+
  $ca->setPageTitle("Your Page Title Goes Here");
 
   
 
   
 +
$ca->addToBreadCrumb('index.php',$whmcs->get_lang('globalsystemname'));
 +
$ca->addToBreadCrumb('mypage.php','Your Custom Page Name');
 +
 +
$ca->initPage();
 +
 +
//$ca->requireLogin(); // Uncomment this line to require a login to access this page
 +
 
  # To assign variables to the template system use the following syntax.
 
  # To assign variables to the template system use the following syntax.
 
  # These can then be referenced using {$variablename} in the template.
 
  # These can then be referenced using {$variablename} in the template.
 
   
 
   
  $smartyvalues["variablename"] = $value;  
+
  $ca->assign('variablename', $value);
+
 
 
  # Check login status
 
  # Check login status
  if ($_SESSION['uid']) {
+
  if ($ca->isLoggedIn()) {
 
   
 
   
 
   # User is logged in - put any code you like here
 
   # User is logged in - put any code you like here
Line 30: Line 36:
 
   # Here's an example to get the currently logged in clients first name
 
   # Here's an example to get the currently logged in clients first name
 
   
 
   
   $result = mysql_query("SELECT firstname FROM tblclients WHERE id=".(int)$_SESSION['uid']);
+
   $result = mysql_query("SELECT firstname FROM tblclients WHERE id=".$ca->getUserID());
 
   $data = mysql_fetch_array($result);
 
   $data = mysql_fetch_array($result);
 
   $clientname = $data[0];
 
   $clientname = $data[0];
   $smartyvalues["clientname"] = $clientname;
+
 +
   $ca->assign('clientname', $clientname);
 
   
 
   
 
  } else {
 
  } else {
Line 43: Line 50:
 
  # Define the template filename to be used without the .tpl extension
 
  # Define the template filename to be used without the .tpl extension
 
   
 
   
  $templatefile = "custompage";  
+
  $ca->setTemplate('mypage');
 
   
 
   
  outputClientArea($templatefile);
+
  $ca->output();
 
   
 
   
 
  ?>
 
  ?>
 +
</source>
  
 
This example above shows you the required layout of a custom page.  It demonstrates:
 
This example above shows you the required layout of a custom page.  It demonstrates:

Revision as of 20:28, 12 March 2013

Creating your own custom pages for WHMCS is simple. You can use this to extend the client area, for example building your whole site around WHMCS, or creating custom pages to provide additional functionality to your clients.

To get started, simply copy & paste the code below into a new PHP file and save it in the main WHMCS directory.

*Updated for Version 5.2*

 <?php
 
 define("CLIENTAREA",true);
 //define("FORCESSL",true); // Uncomment to force the page to use https://
 
 require("init.php");
 
 $ca = new WHMCS_ClientArea();
 
 $ca->setPageTitle("Your Page Title Goes Here");
 
 $ca->addToBreadCrumb('index.php',$whmcs->get_lang('globalsystemname'));
 $ca->addToBreadCrumb('mypage.php','Your Custom Page Name');
 
 $ca->initPage();
 
 //$ca->requireLogin(); // Uncomment this line to require a login to access this page

 # To assign variables to the template system use the following syntax.
 # These can then be referenced using {$variablename} in the template.
 
 $ca->assign('variablename', $value);

 # Check login status
 if ($ca->isLoggedIn()) {
 
   # User is logged in - put any code you like here
 
   # Here's an example to get the currently logged in clients first name
 
   $result = mysql_query("SELECT firstname FROM tblclients WHERE id=".$ca->getUserID());
   $data = mysql_fetch_array($result);
   $clientname = $data[0];
 
   $ca->assign('clientname', $clientname);
 
 } else {
 
   # User is not logged in
 
 }
 
 # Define the template filename to be used without the .tpl extension
 
 $ca->setTemplate('mypage');
 
 $ca->output();
 
 ?>

This example above shows you the required layout of a custom page. It demonstrates:

  • How to initiate the page
  • How to force the page to use SSL (FORCESSL)
  • How to reference the language file variables ($_LANG)
  • How to check if a user is logged in ($_SESSION['uid'])
  • How to define template variables ($templatevars)
  • And how to set the template to use and then output it

The template file you define should be a filename in your active WHMCS system template folder, so for the example above the path would be /templates/default/custompage.tpl

Now when you're ready to test, upload both the PHP and TPL file to the appropriate folders and then visit the PHP file in the root WHMCS directory to run.