<?php include('lib/config.php');?>
<?php       
    //===============================================================  
	 
    $toDay = date("Y-m-d");
    $cDateTime = date("mdYHis");
    
    $shid = isset($_POST['shid'])?$_POST['shid']:'';
	
	$name = isset($_POST['name'])?$_POST['name']:'';  
    $abbreviation = isset($_POST['abbreviation'])?$_POST['abbreviation']:'';
    $areas_of_operations = isset($_POST['areas_of_operations'])?$_POST['areas_of_operations']:'';
	$pwd_oriented = isset($_REQUEST['pwd_oriented'])?$_REQUEST['pwd_oriented']:'N';
    $address = isset($_POST['address'])?$_POST['address']:'';
    $focal_person = isset($_POST['focal_person'])?$_POST['focal_person']:'';    
    $tel_no = isset($_POST['tel_no'])?$_POST['tel_no']:'';
    $email = isset($_POST['email'])?$_POST['email']:'';
	$website_url = isset($_POST['website_url'])?$_POST['website_url']:'';
    $category_id = isset($_POST['category_id'])?$_POST['category_id']:'';
    $description = isset($_POST['description'])?$_POST['description']:'';
	$is_high_priority = isset($_REQUEST['is_high_priority'])?$_REQUEST['is_high_priority']:'0';

    $important_for_sh = isset($_POST['important_for_sh'])?$_POST['important_for_sh']:'';
    $sh_contribute = isset($_POST['sh_contribute'])?$_POST['sh_contribute']:'';
    $sh_block = isset($_POST['sh_block'])?$_POST['sh_block']:'';

    $sh_issues_concerns = isset($_POST['sh_issues_concerns'])?$_POST['sh_issues_concerns']:'';

    $sh_summary_interaction = isset($_POST['sh_summary_interaction'])?$_POST['sh_summary_interaction']:'';

    $orientation_sh_interest = isset($_POST['orientation_sh_interest'])?$_POST['orientation_sh_interest']:'';
    $orientation_sh_interest_ranking = isset($_POST['orientation_sh_interest_ranking'])?$_POST['orientation_sh_interest_ranking']:'';
    $orientation_sh_influence = isset($_POST['orientation_sh_influence'])?$_POST['orientation_sh_influence']:'';
    $sh_initial_orientation = isset($_POST['sh_initial_orientation'])?$_POST['sh_initial_orientation']:'';
	$sh_current_orientation = isset($_POST['sh_current_orientation'])?$_POST['sh_current_orientation']:'';
    $sh_desired_orientation = isset($_POST['sh_desired_orientation'])?$_POST['sh_desired_orientation']:'';
	//===============================================================
	//============== Uploading Files ===========================
	//===============================================================
	$oldDocfile = isset($_POST['old_sh_logo'])?$_POST['old_sh_logo']:'';
	
	$uploaddir = 'uploads/stake-holders/';
	
	if(isset($_FILES['sh_logo']['name']) && $_FILES['sh_logo']['name'] != '')
	{			
		$docarr = explode(".", $_FILES['sh_logo']['name']);						
		$docfile = $docarr[0]."_".$cDateTime.'.'.$docarr[1];
		$upload = $uploaddir . $docfile;
		if(move_uploaded_file($_FILES['sh_logo']['tmp_name'], $upload))
		{
			@unlink("uploads/stake-holders/$oldImgfile");			
			$oldDocfile = $docfile;
		}	
	}
    //===============================================================
    //============== Add record =====================================
    //===============================================================
    if(isset($_POST['action']) && $_POST['action'] =='save')
    { 		
		$insQry = "INSERT INTO ".TBL_STAKEHOLDERS." SET 
        name='".addslashes($name)."',
        abbreviation='".addslashes($abbreviation)."',
		sh_logo='".addslashes($oldDocfile)."',		
        areas_of_operations='".addslashes($areas_of_operations)."',
		pwd_oriented='".addslashes($pwd_oriented)."',
        address='".addslashes($address)."',
        focal_person='".addslashes($focal_person)."',
        tel_no='".addslashes($tel_no)."',
        email='".addslashes($email)."',
		website_url='".addslashes($website_url)."',
        category_id='".addslashes($category_id)."',
        description='".addslashes($description)."',
		is_high_priority='".addslashes($is_high_priority)."',
		date_added='".$toDay."' ";        
        $response = $con->insertRecords($insQry, __FILE__,__LINE__);
		$shid = mysqli_insert_id($dbcon);
        
        if($response===TRUE )
		{
            //----------------------------------------------------
			if(!empty($_POST['files'])) 
			{ 				
				foreach($_POST['files'] as $file)
				{
					//-------------------- Dept info ----------------
					$selQry_file_dept = "SELECT department_id FROM ".TBL_FILES." WHERE id = '".$file."' LIMIT 1";
					$fileDeptInfo =  $con->getSingleRow($selQry_file_dept, __FILE__,__LINE__);
					$dept_id = isset($fileDeptInfo['department_id'])?$fileDeptInfo['department_id']:'';
					
					if(!empty($_POST['depts']))
					{
						if(in_array($dept_id,$_POST['depts']))
						{
							$is_dept_checked = '1';
						}
						else
						{
							$is_dept_checked = '0';
						}
					}
					else
					{
						$is_dept_checked = '0';
					}
					
					//-----------------------------------------------
					
					$insQry_files = "INSERT INTO ".TBL_STAKEHOLDERS_DEPTS_FILES." SET stakerholder_id='".$shid."',dept_id='".$dept_id."',is_dept_checked='".$is_dept_checked."',file_id='".$file."' ";
					$errNo_files = $con->insertRecords($insQry_files, __FILE__,__LINE__);
				}
			}
			//----------------------------------------------------
			$return_arr[] = array("message" => 'ok');
		}
        else
            $return_arr[] = array("message" => 'err');
                    
        echo json_encode($return_arr);
    }
	//===============================================================
    //============== Update S1 ======================================
    //===============================================================
    elseif(isset($_POST['action']) && $_POST['action'] =='updateS1')
    {	
		$insQry = "UPDATE ".TBL_STAKEHOLDERS." SET 
        name='".addslashes($name)."',
        abbreviation='".addslashes($abbreviation)."',
		sh_logo='".addslashes($oldDocfile)."',		
        areas_of_operations='".addslashes($areas_of_operations)."',
		pwd_oriented='".addslashes($pwd_oriented)."',
        address='".addslashes($address)."',
        focal_person='".addslashes($focal_person)."',
        tel_no='".addslashes($tel_no)."',
        email='".addslashes($email)."',
		website_url='".addslashes($website_url)."',
        category_id='".addslashes($category_id)."',
        description='".addslashes($description)."',
		is_high_priority='".addslashes($is_high_priority)."',
		date_modified='".$toDay."' 		
		WHERE id = '".$shid."' LIMIT 1 ";        
        $response = $con->insertRecords($insQry, __FILE__,__LINE__);
        
        if($response===TRUE )
		{
            //----------------------------------------------------
			if(!empty($_POST['files'])) 
			{    
				//------------------ Delete Old ---------------
				$delQry = "DELETE FROM ".TBL_STAKEHOLDERS_DEPTS_FILES." WHERE stakerholder_id = '".$shid."' ";
				$errNo = $con->deleteRecords($delQry, __FILE__,__LINE__);
				//---------------------------------------------				
				foreach($_POST['files'] as $file)
				{
					//-------------------- Dept info ----------------
					$selQry_file_dept = "SELECT department_id FROM ".TBL_FILES." WHERE id = '".$file."' LIMIT 1";
					$fileDeptInfo =  $con->getSingleRow($selQry_file_dept, __FILE__,__LINE__);
					$dept_id = isset($fileDeptInfo['department_id'])?$fileDeptInfo['department_id']:'';
					
					if(!empty($_POST['depts']))
					{
						if(in_array($dept_id,$_POST['depts']))
						{
							$is_dept_checked = '1';
						}
						else
						{
							$is_dept_checked = '0';
						}
					}
					else
					{
						$is_dept_checked = '0';
					}					
					//-----------------------------------------------
					
					$insQry_files = "INSERT INTO ".TBL_STAKEHOLDERS_DEPTS_FILES." SET stakerholder_id='".$shid."',dept_id='".$dept_id."',is_dept_checked='".$is_dept_checked."',file_id='".$file."' ";
					$errNo_files = $con->insertRecords($insQry_files, __FILE__,__LINE__);
				}
			}
			//----------------------------------------------------
			$return_arr[] = array("message" => 'ok');
		}	
        else
            $return_arr[] = array("message" => 'err');
                    
        echo json_encode($return_arr);
    }
	//===============================================================
    //============== Update S2 ======================================
    //===============================================================
    elseif(isset($_POST['action']) && $_POST['action'] =='updateS2')
    { 
        $insQry = "UPDATE ".TBL_STAKEHOLDERS." SET 
        name='".addslashes($name)."',
        abbreviation='".addslashes($abbreviation)."',
		sh_logo='".addslashes($oldDocfile)."',		
        areas_of_operations='".addslashes($areas_of_operations)."',
		pwd_oriented='".addslashes($pwd_oriented)."',
        address='".addslashes($address)."',
        focal_person='".addslashes($focal_person)."',
        tel_no='".addslashes($tel_no)."',
        email='".addslashes($email)."',
		website_url='".addslashes($website_url)."',
        category_id='".addslashes($category_id)."',
        description='".addslashes($description)."',
		is_high_priority='".addslashes($is_high_priority)."',
		important_for_sh='".addslashes($important_for_sh)."',
        sh_contribute='".addslashes($sh_contribute)."',
        sh_block='".addslashes($sh_block)."',
        sh_issues_concerns='".addslashes($sh_issues_concerns)."',
		sh_summary_interaction='".addslashes($sh_summary_interaction)."',
		date_modified='".$toDay."' 		
		WHERE id = '".$shid."' LIMIT 1 ";        
        $response = $con->insertRecords($insQry, __FILE__,__LINE__);
        
        if($response===TRUE )
		{
            //----------------------------------------------------
			if(!empty($_POST['files'])) 
			{    
				//------------------ Delete Old ---------------
				$delQry = "DELETE FROM ".TBL_STAKEHOLDERS_DEPTS_FILES." WHERE stakerholder_id = '".$shid."' ";
				$errNo = $con->deleteRecords($delQry, __FILE__,__LINE__);
				//---------------------------------------------
				
				foreach($_POST['files'] as $file)
				{
					//-------------------- Dept info ----------------
					$selQry_file_dept = "SELECT department_id FROM ".TBL_FILES." WHERE id = '".$file."' LIMIT 1";
					$fileDeptInfo =  $con->getSingleRow($selQry_file_dept, __FILE__,__LINE__);
					$dept_id = isset($fileDeptInfo['department_id'])?$fileDeptInfo['department_id']:'';
					
					if(!empty($_POST['depts']))
					{
						if(in_array($dept_id,$_POST['depts']))
						{
							$is_dept_checked = '1';
						}
						else
						{
							$is_dept_checked = '0';
						}
					}
					else
					{
						$is_dept_checked = '0';
					}
					
					//-----------------------------------------------
					
					$insQry_files = "INSERT INTO ".TBL_STAKEHOLDERS_DEPTS_FILES." SET stakerholder_id='".$shid."',dept_id='".$dept_id."',is_dept_checked='".$is_dept_checked."',file_id='".$file."' ";
					$errNo_files = $con->insertRecords($insQry_files, __FILE__,__LINE__);
				}
			}
			//----------------------------------------------------
			$return_arr[] = array("message" => 'ok');
		}
        else
            $return_arr[] = array("message" => 'err');
                    
        echo json_encode($return_arr);
    }
    //===============================================================
    //============== Update S3 ======================================
    //===============================================================
    elseif(isset($_POST['action']) && $_POST['action'] =='updateS3')
    { 		
		$updQry = "UPDATE ".TBL_STAKEHOLDERS." SET 
        name='".addslashes($name)."',
        abbreviation='".addslashes($abbreviation)."',
		sh_logo='".addslashes($oldDocfile)."',
        areas_of_operations='".addslashes($areas_of_operations)."',
		pwd_oriented='".addslashes($pwd_oriented)."',
        address='".addslashes($address)."',
        focal_person='".addslashes($focal_person)."',
        tel_no='".addslashes($tel_no)."',
        email='".addslashes($email)."',
		website_url='".addslashes($website_url)."',
        category_id='".addslashes($category_id)."',
        description='".addslashes($description)."',	
		is_high_priority='".addslashes($is_high_priority)."',	
        important_for_sh='".addslashes($important_for_sh)."',
        sh_contribute='".addslashes($sh_contribute)."',
        sh_block='".addslashes($sh_block)."',		
        sh_issues_concerns='".addslashes($sh_issues_concerns)."',		
        sh_summary_interaction='".addslashes($sh_summary_interaction)."',		
        orientation_sh_interest='".addslashes($orientation_sh_interest)."',
        orientation_sh_interest_ranking='".addslashes($orientation_sh_interest_ranking)."',
		orientation_sh_influence='".addslashes($orientation_sh_influence)."',
		sh_initial_orientation='".addslashes($sh_initial_orientation)."',
        sh_current_orientation='".addslashes($sh_current_orientation)."',
        sh_desired_orientation='".addslashes($sh_desired_orientation)."',
		date_modified='".$toDay."' 		
		WHERE id = '".$shid."' LIMIT 1";
		
		$errNo = $con->updateRecords($updQry, __FILE__,__LINE__);
        
        if($errNo===TRUE )
		{
            //----------------------------------------------------
			if(!empty($_POST['files'])) 
			{    
				//------------------ Delete Old ---------------
				$delQry = "DELETE FROM ".TBL_STAKEHOLDERS_DEPTS_FILES." WHERE stakerholder_id = '".$shid."' ";
				$errNo = $con->deleteRecords($delQry, __FILE__,__LINE__);
				//---------------------------------------------
				
				foreach($_POST['files'] as $file)
				{
					//-------------------- Dept info ----------------
					$selQry_file_dept = "SELECT department_id FROM ".TBL_FILES." WHERE id = '".$file."' LIMIT 1";
					$fileDeptInfo =  $con->getSingleRow($selQry_file_dept, __FILE__,__LINE__);
					$dept_id = isset($fileDeptInfo['department_id'])?$fileDeptInfo['department_id']:'';
					
					if(!empty($_POST['depts']))
					{
						if(in_array($dept_id,$_POST['depts']))
						{
							$is_dept_checked = '1';
						}
						else
						{
							$is_dept_checked = '0';
						}
					}
					else
					{
						$is_dept_checked = '0';
					}
					
					//-----------------------------------------------
					
					$insQry_files = "INSERT INTO ".TBL_STAKEHOLDERS_DEPTS_FILES." SET stakerholder_id='".$shid."',dept_id='".$dept_id."',is_dept_checked='".$is_dept_checked."',file_id='".$file."' ";
					$errNo_files = $con->insertRecords($insQry_files, __FILE__,__LINE__);
				}
			}
			//----------------------------------------------------
			
			$selQuery_map_det_sel = "SELECT * FROM ".TBL_MAPPINGS_DETAILS." WHERE sh_id = '".$shid."';";
			$mapdetInfo = $con->getMultiRow($selQuery_map_det_sel);	
			if($mapdetInfo)
			{
				//--------------- Update Initial Orienttion ----------------
				$updQry_map_det_co = "UPDATE ".TBL_MAPPINGS_DETAILS." SET 
				node_color = '".addslashes($sh_current_orientation)."',
				node_size = '".addslashes($orientation_sh_influence)."',
				modified = '".$toDay."' 		
				WHERE sh_id = '".$shid."' 
				AND orientation_type = 'I' LIMIT 1";
				$errNo_co = $con->updateRecords($updQry_map_det_co, __FILE__,__LINE__);
				//--------------- Update Current Orienttion ----------------
				$updQry_map_det_co = "UPDATE ".TBL_MAPPINGS_DETAILS." SET 
				node_color = '".addslashes($sh_current_orientation)."',
				node_size = '".addslashes($orientation_sh_influence)."',
				modified = '".$toDay."' 		
				WHERE sh_id = '".$shid."' 
				AND orientation_type = 'C' LIMIT 1";
				$errNo_co = $con->updateRecords($updQry_map_det_co, __FILE__,__LINE__);
				//--------------- Update Desired Orienttion ----------------
				$updQry_map_det_do = "UPDATE ".TBL_MAPPINGS_DETAILS." SET 
				node_color = '".addslashes($sh_desired_orientation)."',
				node_size = '".addslashes($orientation_sh_influence)."',
				modified = '".$toDay."' 		
				WHERE sh_id = '".$shid."' 
				AND orientation_type = 'D' LIMIT 1";
				$errNo_do = $con->updateRecords($updQry_map_det_do, __FILE__,__LINE__);
				//-------------------------------------------------
			}
			//-----------------------------------------------------------
			$return_arr[] = array("message" => 'ok');
		}
        else
		{
            $return_arr[] = array("message" => 'err');
		}
                    
        echo json_encode($return_arr);
    }
	 //==============================================================
    //============== Update S4 ======================================
    //===============================================================
    elseif(isset($_POST['action']) && $_POST['action'] =='updateS4')
    { 		
		$updQry = "UPDATE ".TBL_STAKEHOLDERS." SET 
        name='".addslashes($name)."',
        abbreviation='".addslashes($abbreviation)."',
		sh_logo='".addslashes($oldDocfile)."',
        areas_of_operations='".addslashes($areas_of_operations)."',
		pwd_oriented='".addslashes($pwd_oriented)."',
        address='".addslashes($address)."',
        focal_person='".addslashes($focal_person)."',
        tel_no='".addslashes($tel_no)."',
        email='".addslashes($email)."',
		website_url='".addslashes($website_url)."',
        category_id='".addslashes($category_id)."',
        description='".addslashes($description)."',
		is_high_priority='".addslashes($is_high_priority)."',		
        important_for_sh='".addslashes($important_for_sh)."',
        sh_contribute='".addslashes($sh_contribute)."',
        sh_block='".addslashes($sh_block)."',		
        sh_issues_concerns='".addslashes($sh_issues_concerns)."',		
        sh_summary_interaction='".addslashes($sh_summary_interaction)."',		
        orientation_sh_interest='".addslashes($orientation_sh_interest)."',
        orientation_sh_interest_ranking='".addslashes($orientation_sh_interest_ranking)."',
		orientation_sh_influence='".addslashes($orientation_sh_influence)."',
		sh_initial_orientation='".addslashes($sh_initial_orientation)."',
        sh_current_orientation='".addslashes($sh_current_orientation)."',
        sh_desired_orientation='".addslashes($sh_desired_orientation)."',
		date_modified='".$toDay."' 		
		WHERE id = '".$shid."' LIMIT 1";
		
		$errNo = $con->updateRecords($updQry, __FILE__,__LINE__);
        
        if($errNo===TRUE )
		{
            //----------------------------------------------------
			if(!empty($_POST['files'])) 
			{    
				//------------------ Delete Old ---------------
				$delQry = "DELETE FROM ".TBL_STAKEHOLDERS_DEPTS_FILES." WHERE stakerholder_id = '".$shid."' ";
				$errNo = $con->deleteRecords($delQry, __FILE__,__LINE__);
				//---------------------------------------------
				
				foreach($_POST['files'] as $file)
				{
					//-------------------- Dept info ----------------
					$selQry_file_dept = "SELECT department_id FROM ".TBL_FILES." WHERE id = '".$file."' LIMIT 1";
					$fileDeptInfo =  $con->getSingleRow($selQry_file_dept, __FILE__,__LINE__);
					$dept_id = isset($fileDeptInfo['department_id'])?$fileDeptInfo['department_id']:'';
					
					if(!empty($_POST['depts']))
					{
						if(in_array($dept_id,$_POST['depts']))
						{
							$is_dept_checked = '1';
						}
						else
						{
							$is_dept_checked = '0';
						}
					}
					else
					{
						$is_dept_checked = '0';
					}
					
					//-----------------------------------------------
					
					$insQry_files = "INSERT INTO ".TBL_STAKEHOLDERS_DEPTS_FILES." SET stakerholder_id='".$shid."',dept_id='".$dept_id."',is_dept_checked='".$is_dept_checked."',file_id='".$file."' ";
					$errNo_files = $con->insertRecords($insQry_files, __FILE__,__LINE__);
				}
			}
			//----------------------------------------------------
			
			$selQuery_map_det_sel = "SELECT * FROM ".TBL_MAPPINGS_DETAILS." WHERE sh_id = '".$shid."';";
			$mapdetInfo = $con->getMultiRow($selQuery_map_det_sel);	
			if($mapdetInfo)
			{
				//--------------- Update Initial Orienttion ----------------
				$updQry_map_det_co = "UPDATE ".TBL_MAPPINGS_DETAILS." SET 
				node_color = '".addslashes($sh_current_orientation)."',
				node_size = '".addslashes($orientation_sh_influence)."',
				modified = '".$toDay."' 		
				WHERE sh_id = '".$shid."' 
				AND orientation_type = 'I' LIMIT 1";
				$errNo_co = $con->updateRecords($updQry_map_det_co, __FILE__,__LINE__);
				//--------------- Update Current Orienttion ----------------
				$updQry_map_det_co = "UPDATE ".TBL_MAPPINGS_DETAILS." SET 
				node_color = '".addslashes($sh_current_orientation)."',
				node_size = '".addslashes($orientation_sh_influence)."',
				modified = '".$toDay."' 		
				WHERE sh_id = '".$shid."' 
				AND orientation_type = 'C' LIMIT 1";
				$errNo_co = $con->updateRecords($updQry_map_det_co, __FILE__,__LINE__);
				//--------------- Update Desired Orienttion ----------------
				$updQry_map_det_do = "UPDATE ".TBL_MAPPINGS_DETAILS." SET 
				node_color = '".addslashes($sh_desired_orientation)."',
				node_size = '".addslashes($orientation_sh_influence)."',
				modified = '".$toDay."' 		
				WHERE sh_id = '".$shid."' 
				AND orientation_type = 'D' LIMIT 1";
				$errNo_do = $con->updateRecords($updQry_map_det_do, __FILE__,__LINE__);
				//-------------------------------------------------
			}
			//-----------------------------------------------------------
			$return_arr[] = array("message" => 'ok',"shid"=>$shid);
		}
        else
		{
            $return_arr[] = array("message" => 'err',"shid"=>$shid);
		}
                    
        echo json_encode($return_arr);
    }
	//===============================================================
    //============== Update record ==================================
    //===============================================================
    elseif(isset($_POST['action']) && $_POST['action'] =='rankSH')
    { 		
		$rankIDS = isset($_POST['rankIDS'])?$_POST['rankIDS']:'';
				
		if(!empty($rankIDS))
		{
			$shid = $rankIDS;		
				
			//--------------------------------
			$selSH = "SELECT * FROM ".TBL_STAKEHOLDERS." WHERE id='".$shid."'";
			$cshInfo = $con->getSingleRow($selSH);
					
			$sh_name = $cshInfo['abbreviation'];
			//------------------- Initial Orientation -------------------
			$sh_node_color_ini = isset($cshInfo['sh_current_orientation'])?$cshInfo['sh_current_orientation']:'red';
			$sh_node_size_ini = isset($cshInfo['orientation_sh_influence'])?$cshInfo['orientation_sh_influence']:'7';
			$sh_orientation_type_ini = 'I';
			
			$sh_node_positionX_ini = "131.87871347731";
			$sh_node_positionY_ini = "615";
			$sh_node_positionX2_ini = "139.89064861573";
			$sh_node_positionY2_ini = "623";
			$sh_node_width_ini = "8.0119351384251";
			$sh_node_height_ini = "8";
			$sh_node_positionCX_ini = "135.88468104652";
			$sh_node_positionCY_ini = "619";
			//------------------- Current Orientation -------------------
			$sh_node_color_cur = isset($cshInfo['sh_current_orientation'])?$cshInfo['sh_current_orientation']:'red';
			$sh_node_size_cur = isset($cshInfo['orientation_sh_influence'])?$cshInfo['orientation_sh_influence']:'7';
			$sh_orientation_type_cur = 'C';
			
			$sh_node_positionX_cur = "596.90855132337";
			$sh_node_positionY_cur = "541";
			$sh_node_positionX2_cur = "604.92048646179";
			$sh_node_positionY2_cur = "549";
			$sh_node_width_cur = "8.0119351384251";
			$sh_node_height_cur = "8";
			$sh_node_positionCX_cur = "600.91451889258";
			$sh_node_positionCY_cur = "545";
			//------------------- Desired Orientation -------------------
			$sh_node_color_des = isset($cshInfo['sh_desired_orientation'])?$cshInfo['sh_desired_orientation']:'green';
			$sh_node_size_des = isset($cshInfo['orientation_sh_influence'])?$cshInfo['orientation_sh_influence']:'7';
			$sh_orientation_type_des = 'D';
			
			$sh_node_positionX_des = "406.86677833888";
			$sh_node_positionY_des = "623";
			$sh_node_positionX2_des = "414.87871347731";
			$sh_node_positionY2_des = "631";
			$sh_node_width_des = "8.0119351384251";
			$sh_node_height_des = "8";
			$sh_node_positionCX_des = "410.87274590809";
			$sh_node_positionCY_des = "627";
			//-----------------------------------------------------------
			
			//-------------------------------------------------------------				
			$selSH_mapdetinfo = "SELECT * FROM ".TBL_MAPPINGS_DETAILS." WHERE sh_id='".$shid."'";
			$cshmapdetInfo = $con->getSingleRow($selSH_mapdetinfo);	
			//-------------------------------------------------------------
			if($cshmapdetInfo)
			{
				//$updQry = "UPDATE ".TBL_STAKEHOLDERS." SET is_ranked='0' WHERE id = '".$shid."' LIMIT 1";		
				//$errNo = $con->updateRecords($updQry, __FILE__,__LINE__);
				
				$response = TRUE;
			}
			else
			{
				$updQry = "UPDATE ".TBL_STAKEHOLDERS." SET is_ranked='1' WHERE id = '".$shid."' LIMIT 1";		
				$errNo = $con->updateRecords($updQry, __FILE__,__LINE__);
				
				//---------------------- Initial Orientation ------------------
				$insQry_cur = "INSERT INTO ".TBL_MAPPINGS_DETAILS." SET 
					map_id='1',
					sh_id='".addslashes($shid)."',
					orientation_type='".addslashes($sh_orientation_type_ini)."',
					node_color='".addslashes($sh_node_color_ini)."',		
					node_size='".addslashes($sh_node_size_ini)."',
					node_positionX='".addslashes($sh_node_positionX_ini)."',
					node_positionY='".addslashes($sh_node_positionY_ini)."',
					node_positionX2='".addslashes($sh_node_positionX2_ini)."',
					node_positionY2='".addslashes($sh_node_positionY2_ini)."',
					node_width='".addslashes($sh_node_width_ini)."',
					node_height='".addslashes($sh_node_height_ini)."',
					node_positionCX='".addslashes($sh_node_positionCX_ini)."',
					node_positionCY='".addslashes($sh_node_positionCY_ini)."',
					date_added='".$toDay."' ";					
				$response_cur = $con->insertRecords($insQry_cur, __FILE__,__LINE__);
				//---------------------- Current Orientation ------------------
				$insQry_cur = "INSERT INTO ".TBL_MAPPINGS_DETAILS." SET 
					map_id='1',
					sh_id='".addslashes($shid)."',
					orientation_type='".addslashes($sh_orientation_type_cur)."',
					node_color='".addslashes($sh_node_color_cur)."',		
					node_size='".addslashes($sh_node_size_cur)."',
					node_positionX='".addslashes($sh_node_positionX_cur)."',
					node_positionY='".addslashes($sh_node_positionY_cur)."',
					node_positionX2='".addslashes($sh_node_positionX2_cur)."',
					node_positionY2='".addslashes($sh_node_positionY2_cur)."',
					node_width='".addslashes($sh_node_width_cur)."',
					node_height='".addslashes($sh_node_height_cur)."',
					node_positionCX='".addslashes($sh_node_positionCX_cur)."',
					node_positionCY='".addslashes($sh_node_positionCY_cur)."',
					date_added='".$toDay."' ";					
				$response_cur = $con->insertRecords($insQry_cur, __FILE__,__LINE__);
				//---------------------- Desired Orientation ------------------
				$insQry_des = "INSERT INTO ".TBL_MAPPINGS_DETAILS." SET 
					map_id='1',
					sh_id='".addslashes($shid)."',
					orientation_type='".addslashes($sh_orientation_type_des)."',
					node_color='".addslashes($sh_node_color_des)."',		
					node_size='".addslashes($sh_node_size_des)."',
					node_positionX='".addslashes($sh_node_positionX_des)."',
					node_positionY='".addslashes($sh_node_positionY_des)."',
					node_positionX2='".addslashes($sh_node_positionX2_des)."',
					node_positionY2='".addslashes($sh_node_positionY2_des)."',
					node_width='".addslashes($sh_node_width_des)."',
					node_height='".addslashes($sh_node_height_des)."',
					node_positionCX='".addslashes($sh_node_positionCX_des)."',
					node_positionCY='".addslashes($sh_node_positionCY_des)."',
					date_added='".$toDay."' ";					
				$response_des = $con->insertRecords($insQry_des, __FILE__,__LINE__);
				//-------------------------------------------------------------
				$response = TRUE;
			}
		}
        
        if($response===TRUE)
            $return_arr[] = array("message" => 'ok',"shid" => $shid);
        else
            $return_arr[] = array("message" => 'err',"shid" => $shid);
                    
        echo json_encode($return_arr);
    }
	//===============================================================
	//============== Delete SH record ===============================
	//===============================================================
	elseif(isset($_POST['action']) && $_POST['action'] =='deleteSH')
	{		
		$query_del = "DELETE FROM ".TBL_STAKEHOLDERS." WHERE id = '$_POST[shid]' LIMIT 1";
		$errNo = $con->deleteRecords($query_del);
				
		if($errNo===TRUE )
            $return_arr[] = array("message" => 'ok');
        else
            $return_arr[] = array("message" => 'err');
                    
        echo json_encode($return_arr);
	}		
	//===============================================================
	//============== Delete SHCat record ============================
	//===============================================================
	elseif(isset($_POST['action']) && $_POST['action'] =='deleteSHCat')
	{		
		$query_del = "DELETE FROM ".TBL_CATEGORIES." WHERE category_id = '$_POST[catid]' LIMIT 1";
		$errNo = $con->deleteRecords($query_del);
				
		if($errNo===TRUE )
            $return_arr[] = array("message" => 'ok');
        else
            $return_arr[] = array("message" => 'err');
                    
        echo json_encode($return_arr);
	}
?>