<?php
include("include/dbcommon.php");
$params = (array)my_json_decode(postvalue('params'));
$buttId = $params['buttId'];

// proccess table events
if($buttId=='Menu')
{	
	include("include/My_Home_variables.php");
	buttonHandler_Menu($params);		
}
if($buttId=='Menu1')
{	
	include("include/My_Home_variables.php");
	buttonHandler_Menu1($params);		
}
if($buttId=='Logoff')
{	
	include("include/My_Home_variables.php");
	buttonHandler_Logoff($params);		
}
if($buttId=='Edit_Details')
{	
	include("include/My_Home_variables.php");
	buttonHandler_Edit_Details($params);		
}

// proccess non table events
// create table and non table handlers

function buttonHandler_Menu($params) 
{
	global $strTableName;
	$result = array();
	$keys = array();
	// if sended array of keys
	if (postvalue('keys'))
	{
		$postKeys = (array)my_json_decode(postvalue('keys'));
		
		$tKeysNamesArr = GetTableKeys($strTableName);
		
		if (postvalue('isManyKeys'))
		{
			foreach ($postKeys as $ind=>$value)
			{
				$keys[$ind] = array();
				$recKeyArr = explode('&', $value);
				for($j=0;$j<count($tKeysNamesArr);$j++)
				{
					$keys[$ind][$tKeysNamesArr[$j]] = $recKeyArr[$j];
				}
			}
		}
		elseif(count($postKeys))
		{			
			for($j=0;$j<count($tKeysNamesArr);$j++)
			{
				$keys[$tKeysNamesArr[$j]] = @$postKeys[$j];
			}
		}				
	}
	
	// Put your code here.
$result["txt"] = $params["txt"]." world!";
;
	echo my_json_encode($result);
}
function buttonHandler_Menu1($params) 
{
	global $strTableName;
	$result = array();
	$keys = array();
	// if sended array of keys
	if (postvalue('keys'))
	{
		$postKeys = (array)my_json_decode(postvalue('keys'));
		
		$tKeysNamesArr = GetTableKeys($strTableName);
		
		if (postvalue('isManyKeys'))
		{
			foreach ($postKeys as $ind=>$value)
			{
				$keys[$ind] = array();
				$recKeyArr = explode('&', $value);
				for($j=0;$j<count($tKeysNamesArr);$j++)
				{
					$keys[$ind][$tKeysNamesArr[$j]] = $recKeyArr[$j];
				}
			}
		}
		elseif(count($postKeys))
		{			
			for($j=0;$j<count($tKeysNamesArr);$j++)
			{
				$keys[$tKeysNamesArr[$j]] = @$postKeys[$j];
			}
		}				
	}
	
	// Put your code here.
$result["txt"] = $params["txt"]." Ready!";
;
	echo my_json_encode($result);
}
function buttonHandler_Logoff($params) 
{
	global $strTableName;
	$result = array();
	$keys = array();
	// if sended array of keys
	if (postvalue('keys'))
	{
		$postKeys = (array)my_json_decode(postvalue('keys'));
		
		$tKeysNamesArr = GetTableKeys($strTableName);
		
		if (postvalue('isManyKeys'))
		{
			foreach ($postKeys as $ind=>$value)
			{
				$keys[$ind] = array();
				$recKeyArr = explode('&', $value);
				for($j=0;$j<count($tKeysNamesArr);$j++)
				{
					$keys[$ind][$tKeysNamesArr[$j]] = $recKeyArr[$j];
				}
			}
		}
		elseif(count($postKeys))
		{			
			for($j=0;$j<count($tKeysNamesArr);$j++)
			{
				$keys[$tKeysNamesArr[$j]] = @$postKeys[$j];
			}
		}				
	}
	
	// Put your code here.
$result["txt"] = $params["txt"]." out!";
;
	echo my_json_encode($result);
}
function buttonHandler_Edit_Details($params) 
{
	global $strTableName;
	$result = array();
	$keys = array();
	// if sended array of keys
	if (postvalue('keys'))
	{
		$postKeys = (array)my_json_decode(postvalue('keys'));
		
		$tKeysNamesArr = GetTableKeys($strTableName);
		
		if (postvalue('isManyKeys'))
		{
			foreach ($postKeys as $ind=>$value)
			{
				$keys[$ind] = array();
				$recKeyArr = explode('&', $value);
				for($j=0;$j<count($tKeysNamesArr);$j++)
				{
					$keys[$ind][$tKeysNamesArr[$j]] = $recKeyArr[$j];
				}
			}
		}
		elseif(count($postKeys))
		{			
			for($j=0;$j<count($tKeysNamesArr);$j++)
			{
				$keys[$tKeysNamesArr[$j]] = @$postKeys[$j];
			}
		}				
	}
	
	// Put your code here.
$result["txt"] = $params["txt"]." world!";
;
	echo my_json_encode($result);
}
?>
