------------------------------------------------------------------
------------------ NEW INSTALL INSTRUCTIONS ----------------------
------------------------------------------------------------------
// -------------------------------------------------------------------------
// http://www.heapsoftware.com
// Created By HEAP Software 2011 All Rights Reserved
// 
// COPYRIGHT NOTICE:
// This program may be used but not modified by 
// anyone. By using this program you agree to indemnify 
// HEAP Software and any company programmers from any 
// liability.  Selling or Modifing the code for this program without prior
// written consent is expressly forbidden. Obtain permission before 
// redistributing this program over the Internet or in any 
// other medium. No part of this whole program code shall be reproduced, stored, 
// copied or modified in any way whatsoever without written permission from 
// HEAP Software. The Copyright holder, HEAP Software holds no responsibility
// for errors or omissions. No liability is assumed in any way for damages
// resulting from the use of this software. You may not sell, repackage, redistribute 
// or modify any part of the code or application, or represent it as being your own work 
// without written permission from HEAP Software. Any disagreement of this license behaves 
// as the removal of rights to use this application. HEAP Software reserves the right to modify 
// these terms and the license at any time in the current and future versions without prior notice.
// -------------------------------------------------------------------------
1.  Please make sure you are running PHP 5.2.x or higher, and Kayako Version 4.01.204 or higher
2.  Back up your WHMCS folders:
	templates/kayako
	modules/support/kayako
3.  Copy the rest of the files/folders into your WHMCS installation folder.
4.  For Kayako v4 go to step 5, for Kayako v3 go to step 6.
5.  For Kayako v4 rename the file includes/aiso-kayako-v4-settings.new.php to includes/aiso-kayako-v4-settings.php
5b. Edit the file includes/aiso-kayako-v4-settings.php and adjust the values to your ticket system, including:
	$mstrKayakoURL = "";
	$mstrAPIKey = "";
	$mstrSecretKey = "";
5c. It should look like the following replacing the URL, mykey and mysecret with your installation values.
	$mstrKayakoURL = "http://www.mydomain.com/api/index.php?";
	$mstrAPIKey = "mykey";
	$mstrSecretKey = "myseceret";
5d. Your done
6.  For Kayako v3, make sure you have the CraigBrassSystems API installed under your kayako install folder.
6b. Rename the file includes/aiso-kayako-v3-settings.new.php to includes/aiso-kayako-v3-settings.php
6c. Edit the file includes/aiso-kayako-v3-settings.php and adjust the values to your ticket system, including:
	$mstrKayakoAPIURL = "";
	$mstrAPIUsername = "";
	$mstrAPIPassword = "";
6d. It should look like the following replacing the URL, username and password with your installation values you entered into the config.php file for CraigBrassSystems API.
	$mstrKayakoAPIURL = "http://www.mydomain.com/cbsapi/index.php?wsdl";
	$mstrAPIUsername = "username";
	$mstrAPIPassword = "password";
6e. Edit the file modules/support/kayako/integrate.php and comment out the bottom line that is requiring the v4 code file. Uncomment the top require line that includes the v3 code file.
6f. Please set the Custom Filed ID from Kayako of the custom field you want the WHMCS service to be entered into using the $mintDeptCustomFieldID variable.
6g. Your done

7. If you are using a Kayako API that has an SSL cert (https) then you will need to do the following:
7b. First, you'll need to visit the URL with your web browser (Firefox recommended) in order to grab the CA certificate. Then, (in Firefox) open up the security details for the site by double-clicking on the padlock icon.
7c. Then click on "View Certificate"
7d. Bring up the "Details" tab of the cerficates page, and select the certificate at the top of the hierarchy. This is the CA certificate. If you do not select the top of the certificate hierarchy and you save it, it will not work.
7e. Then click "Export", and save the CA certificate to your computer, making sure to select the X.509 Certificate (PEM) as the save type/format.
7f. Upload the exported certificate to the WHMCS includes folder with the file name of aiso-kayako-whmcs-export.crt


To add ticket support to the client home page of WHMCS do the following:

Open and edit the following file:
templates/ACTIVE_TEMPLATE_FOLDER/clientareahome.tpl

And add to the top of the file the following lines:
{if $loggedin}
{php}
// ----------------------------------------------
// Get Kayako Ticket Details
// ----------------------------------------------
global $mblnUseEmailAddressOfAccountOwnerForTickets;
if(@!file_exists(dirname(dirname(__FILE__))."/modules/support/kayako/integrate.php"))
	require_once "modules/support/kayako/integrate.php";
else
	require_once dirname(dirname(__FILE__)) ."/modules/support/kayako/integrate.php";
if(!isset($mblnUseEmailAddressOfAccountOwnerForTickets))
	$mblnUseEmailAddressOfAccountOwnerForTickets = True;
if($mblnUseEmailAddressOfAccountOwnerForTickets == true)
	$strUserEmailAddress = $GLOBALS['clientsdetails']['email'];
else
	$strUserEmailAddress = $GLOBALS['smarty']->_tpl_vars['loggedinuser']['email'];
$aryTicketData = GetClientHomePageTicketList($strUserEmailAddress);
if(is_array($aryTicketData))
	$this->assign('tickets', $aryTicketData);
$aryCurrentClientStats = $this->get_template_vars('clientsstats');
$intOpenTicketCount = GetOpenTicketCount($strUserEmailAddress);
$aryCurrentClientStats["numactivetickets"] = $intOpenTicketCount;
$aryCurrentClientStats["numtickets"] = $intOpenTicketCount;
$this->assign('clientsstats',$aryCurrentClientStats);
// ----------------------------------------------
{/php}
{/if}

To display open ticket count under Account Statistics, open and edit the following file:
templates/ACTIVE_TEMPLATE_FOLDER/footer.tpl

And add to the top of the file the following lines:
{if $loggedin}
{php}
// ----------------------------------------------
// Get Kayako Ticket Details
// ----------------------------------------------
global $mblnUseEmailAddressOfAccountOwnerForTickets;
if(@!file_exists(dirname(dirname(__FILE__))."/modules/support/kayako/integrate.php"))
	require_once "modules/support/kayako/integrate.php";
else
	require_once dirname(dirname(__FILE__)) ."/modules/support/kayako/integrate.php";
if(!isset($mblnUseEmailAddressOfAccountOwnerForTickets))
	$mblnUseEmailAddressOfAccountOwnerForTickets = True;
if($mblnUseEmailAddressOfAccountOwnerForTickets == true)
	$strUserEmailAddress = $GLOBALS['clientsdetails']['email'];
else
	$strUserEmailAddress = $GLOBALS['smarty']->_tpl_vars['loggedinuser']['email'];
$aryCurrentClientStats = $this->get_template_vars('clientsstats');
$intOpenTicketCount = GetOpenTicketCount($strUserEmailAddress);
$aryCurrentClientStats["numtickets"] = $intOpenTicketCount;
$this->assign('clientsstats',$aryCurrentClientStats);
// ----------------------------------------------
{/php}
{/if}




Setting up Kayako v4 LoginShare for WHMCS:
1. Navigate to General Settings > Support within your WHMCS system and select "Kayako" in the Support Module dropdown to activate the module
2. Then you're ready to enable User LoginShare within the settings of your Kayako system and set the LoginShare URL to:
	http://www.yourdomain.com/whmcs/modules/support/kayako/loginshare.php