<?php
	include "../db_connection/db_connection.php";
	include "../config/config.php";

	if($_GET['ajax_id']==1)
	{
		$cat_id=$_GET['cat_id'];
		$ot = $_GET['ot'];

		$SLCT_sk = "SELECT CONCAT(GROUP_CONCAT(DISTINCT master_cat_id),',',GROUP_CONCAT(DISTINCT parent_id)) as cad_ids FROM master_cat WHERE master_cat_id = '$cat_id' OR `parent_id`='$cat_id'";
		$QURY_sk = mysqli_query($connect,$SLCT_sk);
		$FTCH_sk = mysqli_fetch_object($QURY_sk);
		$ot_where='';
		if($ot!=''){
			$ot_where = " and operation_type='".$ot."'";
		}

		$SLCT = "SELECT * FROM design_det WHERE master_cat_id IN($FTCH_sk->cad_ids) ".$ot_where."";
		//echo $SLCT;
		$QURY = mysqli_query($connect,$SLCT);
		if(mysqli_num_rows($QURY)> 0)
		{
			$SLCT_sk = "SELECT MAX(design_no) as max_ids FROM design_det WHERE master_cat_id IN($FTCH_sk->cad_ids) ".$ot_where."";
			$QURY_sk = mysqli_query($connect,$SLCT_sk);
			$FTCH_sk = mysqli_fetch_object($QURY_sk);
			$max_id = $FTCH_sk->max_ids + 1;
		}
		else
		{
			$max_id = 1;
		}
		printf("%04d",$max_id);

 	}
	else if($_GET['ajax_id']==2)
	{
		$design_id = $_GET['design_id'];
		$ids = $_GET['ids'];

		if($_GET['statu_s']==1)
		{
			$UPDATE = "UPDATE design_det SET statu_s = 'inactive',update_dt = '$cur_time' WHERE design_det_id = '$design_id'";
			//echo $UPDATE;
			$QRY    = mysqli_query($connect,$UPDATE); 
			$statu_s = 2;
			$stss = 'Inactive';
		}
		else if($_GET['statu_s']==2)
		{
			$UPDATE = "UPDATE design_det SET statu_s = 'active',update_dt = '$cur_time' WHERE design_det_id = '$design_id'";
			$QRY    = mysqli_query($connect,$UPDATE); 
			$statu_s = 1;
			$stss = 'Active';
		}

		echo "<a href='javascript:0;' id='inactlink$ids' onfocus='foc(this.id)' onblur='stnon(this.id)' onclick='des_act_ina($design_id,$statu_s,$ids)'>".$stss."</a>";
	}
	else if($_GET['ajax_id']==3)
	{
		$design_id = base64_decode(base64_decode(base64_decode($_GET['design_id'])));
		$sub_id	   = base64_decode(base64_decode(base64_decode(base64_decode($_GET['sub_id']))));

		$UPDATE = "UPDATE design_det SET master_sub_category_id = '$sub_id',update_dt = '$cur_time' WHERE design_det_id = '$design_id'";
		echo $UPDATE;
		$QRY    = mysqli_query($connect,$UPDATE);
		echo "success";
	}
	else if($_GET['ajax_id']==4)
	{
		$dept_id = $_GET['dept_id'];
		$ids = $_GET['ids'];

		if($_GET['statu_s']==1)
		{
			$UPDATE = "UPDATE master_dept SET statu_s = 'inactive',update_dt = '$cur_time' WHERE master_dept_id = '$dept_id'";
			//echo $UPDATE;
			$QRY    = mysqli_query($connect,$UPDATE); 
			$statu_s = 2;
			$stss = 'Inactive';
		}
		else if($_GET['statu_s']==2)
		{
			$UPDATE = "UPDATE master_dept SET statu_s = 'active',update_dt = '$cur_time' WHERE master_dept_id = '$dept_id'";
			$QRY    = mysqli_query($connect,$UPDATE); 
			$statu_s = 1;
			$stss = 'active';
		}

		echo "<a href='javascript:0;' id='inactlink$ids'   onclick='dept_status($dept_id,$statu_s,$ids)'>".$stss."</a>";
	}
