<?php
	//Connects to your Database
	include "../db_connection/db_connection.php";
	include "../config/config.php";		
	$page_id	=	base64_decode(base64_decode(base64_decode($_GET['page_id']))); //THIS IS PAGE ID  

if($page_id==1) 
{
		$lob		=	$_POST['lob']; 
		$lob		= 	str_replace("/", "-", $lob);
		$ot			=	$_POST['ot']; 
		if($ot==''){$ot=1; }
		$lop = 0;		
		foreach($_POST['category'] as $cat_id)
		{
			$SLCT_t = "SELECT * FROM design_det WHERE design_det_id = '$cat_id'";
			$QURY_t = mysqli_query($connect,$SLCT_t);
			$FTCH_t = mysqli_fetch_object($QURY_t);

			$INSRT_d	= "INSERT INTO show_case(`design_det_id`,`master_cat_id`, `design_no`,`show_date`, `post_dt`,`operation_type`) VALUES('$cat_id','$FTCH_t->master_cat_id','$FTCH_t->design_no','$lob','$cur_time','$ot')";
			$QURY_d		= mysqli_query($connect,$INSRT_d);		

			$UPDATE = "UPDATE design_det SET design_status = 'In Show Case',update_dt = '$cur_time' WHERE design_det_id = '$cat_id' and operation_type='$ot'";
			$QRY    = mysqli_query($connect,$UPDATE); 

			//THI IS FOR UPDATING THE Buffing Finishing STATUS
			$UPDATE_cd = "UPDATE mas_finishing SET show_status = 'yes',update_dt = '$cur_time' WHERE design_det_id = '$cat_id'";
			$QRY_cd    = mysqli_query($connect,$UPDATE_cd); 
			$lop++;
		}
?>
		<script type="text/javascript">
            window.location='../show_case_list.php';
        </script>
<?php
}
else if($page_id==2) 
{
		$lop = 1;
		$finishing_date = $_POST['finishing_date'];
		foreach($_POST['category'] as $cat_id)
		{
			$mat_name = $_POST['mat_name'][$lop];
			$mas_wt = $_POST['mas_wt'][$lop];

			$UPDATE_cd = "UPDATE mas_finishing SET `master_mat_id`='$mat_name', `mas_weight`='$mas_wt',`update_dt`='$cur_time' WHERE design_det_id = '$cat_id'";
			$QRY_cd    = mysqli_query($connect,$UPDATE_cd); 
			$lop++;	
		}

?>
	<script type="text/javascript">
		window.location='../mas_finishing_upd.php?finishing_date=<?php echo $finishing_date ?>';
	</script>
<?php
}
else if($page_id==3)
{
	$lop 		= 0;
	$templ 		= $_POST['temp_des'];
	$show_date	= $_POST['show_date'];
	$image = '';
	$len = count($_POST['category']);

	$sms_cont   = "Thahaaya launches NEW DESIGNS on various categories! Login to our ONLINE STORE & order your favorite designs For further details-9843214151";
	$sms_for = 'Promotion';
	$mobile_no = '';
	$emai = '';
	$SELECT_em="SELECT * FROM party_det WHERE statu_s='active'";
	$QUERY_em=mysqli_query($connect,$SELECT_em);
	while($FTCH_em=mysqli_fetch_object($QUERY_em))
	{
		$mobile_no .= $FTCH_em->con_no_1.",";
		$m_no = $FTCH_em->con_no_1;

		if($FTCH_em->email_id_1!='')
		{
			$emai.= $FTCH_em->email_id_1.',';
		}
		else
		{
			$emai.= '';
		}
		if($FTCH_em->email_id_2!='')
		{
			$emai.= $FTCH_em->email_id_2.',';
		}
		else
		{
			$emai.= '';
		}
		if($FTCH_em->email_id_3!='')
		{
			$emai.= $FTCH_em->email_id_3.',';
		}
		else
		{
			$emai.= '';
		}
		
		$pt_name = $FTCH_em->cmp_name;
		if($templ == 'des1')
		{
			include "../mail/design_send_mail.php";
		}
		else if($templ == 'des2')
		{
			include "../mail/design_send_mail.php";
		}
		else if($templ == 'des3')
		{
			include "../mail/design_send_mail.php";
		}
		else if($templ == 'des4')
		{
			include "../mail/design_send_mail.php";
		}
		$to_mail = rtrim($emai,",");
		$tto=$to_mail;
		$subject="Reg: New Designs";
		
		$headers = "MIME-Version: 1.0" . "\r\n";
		$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
		
		// More headers
		$headers .= 'From: Thahaayaa Sales Team <sales@thahaayaa.com>' . "\r\n";
		$headers .= 'Bcc:'.$cc_id. "\r\n";	
		mail("$tto",$subject,$mail_body,$headers);
		$emai = '';

		$sms_dett = $pt_name.' - '.$FTCH_em->party_code;
		$SLCT_SMS = "INSERT INTO `sms_tracking`(`sms_type`, `sms_for`, `sms_det_id`, `sms_details`, `sms_content`, `mobile_no`, `post_dt`) VALUES ('Showcase','$sms_for','$FTCH_em->party_det_id','$sms_dett','$sms_cont','$m_no','$cur_time')";
		$QURY_SMS = mysqli_query($connect,$SLCT_SMS);
	}
	$INSRT_d	= "UPDATE `show_case` SET  `mail_sent` =  'yes' WHERE show_date = '$show_date'";		
	$QURY_d		= mysqli_query($connect,$INSRT_d);
	
	$mob_no = rtrim($mobile_no,",");//"9894347273";//9843214151,9894347273,9843018906";//;
	if($mob_no!='')
	{
		$to = $mob_no;
		$sms   = "Thahaaya launches NEW DESIGNS on various categories! Login to our ONLINE STORE & order your favorite designs For further details-9843214151";
		$sms_url   	= 	sprintf($sms_domain, $workingkey, $to , $senderid, urlencode($sms));
		openurl($sms_url);
	}
	$SLCT_SMS = "INSERT INTO `sms_tracking`(`sms_type`, `sms_for`, `sms_det_id`, `sms_details`, `sms_content`, `mobile_no`, `post_dt`) VALUES ('Showcase','$sms_for','0','Admin','$sms_cont','9894347273','$cur_time')";
	$QURY_SMS = mysqli_query($connect,$SLCT_SMS);
?>
	<script type="text/javascript">
		window.location='../show_case_list.php';
	</script>
<?php
}
?>

