<?php
add_hook('ClientAreaPage', 1, function($templateVariables)
{
	require_once('../wp-load.php');
	require_once('../wp-content/themes/ActiveHost/whmcs-header.php');
	function show_sticky(){
		if(function_exists( 'ot_get_option' ) && ot_get_option('show_sticky_menu')=="on"){
			return 'yes';
		}else{
			return 'no';
		}
	}
	function topbar(){
		ob_start();
		require_once('../wp-content/themes/ActiveHost/topbar.php');
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}
	function logoarea(){
		ob_start();
		require_once('../wp-content/themes/ActiveHost/logoarea.php');
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}
	function thebody_class(){
		ob_start();
		body_class();
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}
	function the_footer(){
		ob_start();
		get_template_part('footer');
		$output = ob_get_contents();
		ob_end_clean();
		return $output;
	}
	if(isset($templateVariables["products"]) && is_array($templateVariables["products"])){
	foreach($templateVariables["products"] as $key => $product){
		$planid = str_replace("!@", "" , $product["features"]["ID"]);
		$templateVariables["products"][$key]["color"]= get_field("color", $planid);
	}
	}
    // Define new variables to send to the template.
    return array(
        'bloginfoname' => get_bloginfo('name'),
		'bloginfohtml' => get_bloginfo('html_type'),
		'bloginfochars' => get_bloginfo('charset'),
		'bloginfoversion' => get_bloginfo('version'),
		'bloginforss2' => get_bloginfo('rss2_url'),
		'bloginforss1' => get_bloginfo('rss_url'),
		'bloginfoatom' => get_bloginfo('atom_url'),
		'bloginfoping'=> get_bloginfo('pingback_url'),
		'wp_head' => wp_head(),
		'body_class' => thebody_class(),
		'show_sticky' => show_sticky(),
		'topbar' => topbar(),
		'logoarea' => logoarea(),
		'the_footer' => the_footer(),
		'products' => $templateVariables["products"]
    );
});
add_hook('ClientAreaPageHome', 1, function($templateVariables)
{
		global $whmcsmysql;
		
		if(isset($templateVariables['clientsdetails']['userid'])){
		$userid = $templateVariables['clientsdetails']['userid'];
		$result = mysql_query("SELECT * FROM tblemails WHERE userid =$userid LIMIT 5", $whmcsmysql);
		$emails= array();
		while ($data = mysql_fetch_array($result)) {
		 array_push($emails, $data);
		}
		
		$result = mysql_query("SELECT * FROM tbldomains WHERE userid =$userid", $whmcsmysql);
		$domains= array();
		while ($data = mysql_fetch_array($result)) {
		 array_push($domains, $data);
		}
		
		$result = mysql_query("SELECT *,tblhosting.id as serviceid FROM tblhosting,tblproducts WHERE userid =$userid AND tblhosting.packageid= tblproducts.id", $whmcsmysql);
		$services= array();
		while ($data = mysql_fetch_array($result)) {
		 array_push($services, $data);
		}
		$currency = getCurrency($userid);
		foreach($services as $key=>$service){
			$services[$key]["amount"] = formatCurrency($services[$key]["amount"]);
			$groupid = $service["gid"];
			$result = mysql_query("SELECT * FROM tblproductgroups WHERE id = $groupid", $whmcsmysql);
			$data = mysql_fetch_array($result);
			$services[$key]["group"] = $data["name"];
		}
		$templateVariables['services'] = $services;
		 return array(
        'domains' =>$domains,
		'emails' =>$emails,
		'services' =>$services,
   		 );
		}

});