<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{

	$partyType    = isset($_REQUEST['partyType']) && $_REQUEST['partyType'] != '' ? $_REQUEST['partyType'] : "";
	$partyId      = isset($_REQUEST['partyId']) && $_REQUEST['partyId'] != '' ? $_REQUEST['partyId'] : 0;
	$partyName    = isset($_REQUEST['partyName']) && $_REQUEST['partyName'] != '' ? $_REQUEST['partyName'] : "";
	$address      = isset($_REQUEST['address']) && $_REQUEST['address'] != '' ? $_REQUEST['address'] : "";
	$mobile       = isset($_REQUEST['mobile']) && $_REQUEST['mobile'] != '' ? $_REQUEST['mobile'] : 0;
	$otherInfo    = isset($_REQUEST['otherInfo']) && $_REQUEST['otherInfo'] != '' ? $_REQUEST['otherInfo'] : "";

  if(isset($_POST['partyId']) && $_POST['partyId'] == 0)
	{
	  $insertParty = "INSERT INTO party (partyType,partyName,address,mobile,otherInfo)
	                        VALUES ('".$partyType."','".$partyName."','".addslashes($address)."',".$mobile.",'".addslashes($otherInfo)."')";
	  $insertPartyRes = mysql_query($insertParty);
	  if(!$insertPartyRes)
	  {
	  	echo "Insert Fail";
	  }
	  else
	  {
	    header("Location:party.php");
	  }
	}
	if(isset($_POST['partyId']) && $_POST['partyId'] > 0)
	{
	  $updateParty = "UPDATE party 
		                  SET partyName = '".$partyName."',
		                      address = '".$address."',
		                      mobile = '".$mobile."',
		                      otherInfo = '".$otherInfo."',
		                      partyType = '".$partyType."'
		                  WHERE partyId = ".$partyId;
	  $updatePartyRes = mysql_query($updateParty);
	  if(!$updatePartyRes)
	  {
	  	echo "Party Update Fail";
	  }
	  else
	  {
	  	header("Location:party.php");
	  }
	}
	 
	
	if(isset($_REQUEST['partyId']) && $_REQUEST['partyId'] > 0)
	{
	  $selectUpdate = "SELECT party.partyId,party.partyName,party.address,party.mobile,party.otherInfo,partyType
	                   FROM party
	              WHERE partyId = ".$_REQUEST['partyId'];
	  $selectUpdateRes = mysql_query($selectUpdate);
	  while($updateRow = mysql_fetch_array($selectUpdateRes))
	  {
	  	$partyId       = $updateRow['partyId'];
	  	$partyName     = $updateRow['partyName'];
	  	$address       = $updateRow['address'];
	  	$mobile        = $updateRow['mobile'];
	  	$otherInfo     = $updateRow['otherInfo'];
	  	$partyType     = $updateRow['partyType'];
	  }
	}
	
	
	$partyTypeValue[0] = "C";
	$partyTypeOutput[0] = "Client";
	$partyTypeValue[1] = "V";
	$partyTypeOutput[1] = "Vepari";
	$partyTypeValue[2] = "M";
	$partyTypeOutput[2] = "Mcx";
	
	include("./bottom.php");
	$smarty->assign("partyTypeOutput",$partyTypeOutput);
	$smarty->assign("partyTypeValue",$partyTypeValue);
	$smarty->assign("partyId",$partyId);
	$smarty->assign("address",$address);
	$smarty->assign("mobile",$mobile);
	$smarty->assign("partyType",$partyType);
	$smarty->assign("otherInfo",$otherInfo);
	$smarty->assign("cityMasterId",$cityMasterId);
	$smarty->assign("partyName",$partyName);
	$smarty->display("party.tpl");
}
?>