<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
	$rojmelId   = isset($_REQUEST['rojmelId']) && $_REQUEST['rojmelId'] ? $_REQUEST['rojmelId'] : 0;	 
    
    
   	 $selectParty = "SELECT partyId FROM rojmel 
	                  WHERE  rojmelId = ".$rojmelId; 
	$selectPartyRes = mysql_query($selectParty);
	if($row = mysql_fetch_array($selectPartyRes))
	{
	  $partyId   = $row['partyId'];
	  $partyType = $row['partyType'];
	  
	  $selectType = "SELECT partyType FROM party  
	                   WHERE partyId = ".$partyId;
	  $res = mysql_query($selectType);
	  if($row1 = mysql_fetch_array($res))
	  {
	    $partyType = $row1['partyType'];
		if($partyType == 'C')
		{
	      $deleteClient = "DELETE FROM client
		                     WHERE  rojmelId = ".$rojmelId;
		  $deleteClientRes = mysql_query($deleteClient);
		  if(!$deleteClientRes)
		  {
		    echo "Client Delete Fail";
		  }
		}
		else
		{
		  $deleteVepari = "DELETE FROM vepari
		                     WHERE  rojmelId = ".$rojmelId;
		  $deleteVepariRes = mysql_query($deleteVepari);
		  if(!$deleteVepariRes)
		  {
		    echo "Vepari Delete Faill";
		  }
		}
	  }
	}


    if($rojmelId > 0)
	{
	  $deleteEntry = "DELETE FROM rojmel
                        WHERE  
					 rojmelId = ".$rojmelId; 
	  $insertClientRes = mysql_query($deleteEntry);
	  if(!$insertClientRes)
	  {
	  	echo "Delete Fail";
	  }
	  else
	  {
	    header("Location:rojmelList.php");
	  }
	}  
	include("./bottom.php");
	$smarty->display("rojmelList.tpl");
}
?>