<?php
ini_set('display_errors', 'Off');
include_once("inc/db_config.php");
date_default_timezone_set('Asia/Dhaka');
 $date_c = date('Y-m-d H:i:s', time());


if (isset($_POST['ev_next'])) {
	
	$ev_next=$_POST['ev_next'];
	$ev_vdo=$_POST['ev_vdo'];
	$eventSQL = mysqli_query($connection, "SELECT state FROM `events` WHERE `id` = '$ev_next' ");
    $eventSQL = mysqli_fetch_object($eventSQL);
    $state = $eventSQL->state;

     if($ev_vdo=="yes") {
		 if($state < 2 OR $state==2 OR $state==4  OR $state==9 OR $state > 7) {$new_state=$state+1;}
		 if($state == 3 ) {$new_state=6;}	
		 if($state == 7 ) {$new_state=9;}	
         if($state == 5 ) {$new_state=8;}			 
		 if($state == 6 OR $state == 8) {$new_state=$state;}						 
									 $state_img="vd".$new_state.".jpg";
									 }
	 else {
				 if($state < 6 ) {$new_state=$state+1;}					
				 if($state == 6 OR $state > 6) {$new_state=$state;}					
									
									
									$state_img="ph".$new_state.".jpg";
	 }	
	 
	 
	 $sqlUpdate = "UPDATE events SET
  state = '$new_state',
  updated_at = '$date_c'  WHERE id = '$ev_next'    ";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 
	 
	 print "<img src='assets/images/".$state_img." ' width='300'/>";
	 
	 
	
}


if (isset($_POST['ev_prev'])) {
	
	$ev_prev=$_POST['ev_prev'];
	$ev_vdo=$_POST['ev_vdo'];
	$eventSQL = mysqli_query($connection, "SELECT state FROM `events` WHERE `id` = '$ev_prev' ");
    $eventSQL = mysqli_fetch_object($eventSQL);
    $state = $eventSQL->state;

     if($ev_vdo=="yes") {
		if($state == 0 OR $state == 7 OR $state == 4) {$new_state=$state;}
		 if($state == 1 OR $state==2 OR $state==3  OR $state==12 OR $state==11 OR $state==10 OR $state==5) {$new_state=$state-1;}
		 if($state==9) {$new_state=$state-2;}	
         if($state == 6 OR $state==8) {$new_state=$state-3;}			 
		 						 
									 $state_img="vd".$new_state.".jpg";
									 }
	 else {
				 if($state > 0 ) {$new_state=$state-1;}					
				 if($state == 0 ) {$new_state=$state;}					
									
									
									$state_img="ph".$new_state.".jpg";
	 }	
	 
	 
	 $sqlUpdate = "UPDATE events SET
  state = '$new_state',
  updated_at = '$date_c'  WHERE id = '$ev_prev'    ";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 
	 
	 print "<img src='assets/images/".$state_img." ' width='300'/>";
	 
	 
	
}



if (isset($_POST['vd_next'])) {
	
	$vd_next=$_POST['vd_next'];
	$eventSQL = mysqli_query($connection, "SELECT state FROM `events` WHERE `id` = '$vd_next' ");
    $eventSQL = mysqli_fetch_object($eventSQL);
    $state = $eventSQL->state;

	
	 if($state == 2 OR $state == 3 OR $state == 6 OR $state == 8) {$new_state=$state+2;}
	 if($state == 4 ) {$new_state=7;}
	 if($state == 5 ) {$new_state=9;}
	 if($state < 2 OR $state == 7 OR $state == 10 OR $state > 10) {$new_state=$state;}
	
	  $state_img="vd".$new_state.".jpg";
	 
	 $sqlUpdate = "UPDATE events SET
  state = '$new_state',
  updated_at = '$date_c'  WHERE id = '$vd_next'    ";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 
	 
	 print "<img src='assets/images/".$state_img." ' width='300'/>";
}



if (isset($_POST['vd_prev'])) {
	
	$vd_prev=$_POST['vd_prev'];
	$eventSQL = mysqli_query($connection, "SELECT state FROM `events` WHERE `id` = '$vd_prev' ");
    $eventSQL = mysqli_fetch_object($eventSQL);
    $state = $eventSQL->state;

	if($state == 10 ) {$new_state=8;}
	if($state == 9 ) {$new_state=5;}
	if($state == 7 ) {$new_state=4;}
	 if($state == 4 OR $state==5 OR $state==8) {$new_state=$state-2;}
	if($state == 3 OR $state < 3 OR $state == 6 OR $state == 11  OR $state > 11) {$new_state=$state;}
	
	 $state_img="vd".$new_state.".jpg";
    	
	 
	 
	 $sqlUpdate = "UPDATE events SET
  state = '$new_state',
  updated_at = '$date_c'  WHERE id = '$vd_prev'    ";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 
	 
	 print "<img src='assets/images/".$state_img." ' width='300'/>";
}





if (isset($_POST['ph_edit_id'])) {
	
	$ph_edit_id=$_POST['ph_edit_id'];
	$ph_editor=$_POST['ph_editor'];
	
	$ph_edit_date=$_POST['ph_edit_date'];
	if($ph_edit_date==""){
		$sqlUpdate = mysqli_query($connection, "UPDATE `photo_edit` SET `date` = NULL WHERE `photo_edit`.`id` = '$ph_edit_id';"); 
		}
		else {
			$sqlUpdate = mysqli_query($connection, "UPDATE `photo_edit` SET `date` = '$ph_edit_date' WHERE `photo_edit`.`id` = '$ph_edit_id';"); 
		}
	$ph_hdd=$_POST['ph_hdd'];
	$ph_remarks=$_POST['ph_remarks'];
	$ph_rg_edit=$_POST['ph_rg_edit'];
	$ph_sp_edit=$_POST['ph_sp_edit'];
	$ph_edit_status=$_POST['ph_edit_status'];
	if($ph_edit_status==""){
		$sqlUpdate = mysqli_query($connection, "UPDATE `photo_edit` SET `status` = '' WHERE `photo_edit`.`id` = '$ph_edit_id';"); 
		}
		else {
			$sqlUpdate = mysqli_query($connection, "UPDATE `photo_edit` SET `status` = 'checked' WHERE `photo_edit`.`id` = '$ph_edit_id';"); 
		}
	
	
	
	$sqlUpdate = "UPDATE photo_edit SET
  editor = '$ph_editor',
 hdd = '$ph_hdd',
 remarks = '$ph_remarks'
 ,
 rg_edit = '$ph_rg_edit'
 ,
 sp_edit = '$ph_sp_edit'
												  											  
 WHERE
 id = '$ph_edit_id'           
";

$sqlUpdate = mysqli_query($connection, $sqlUpdate); 


	
	echo "updated";
}


















if (isset($_POST['vd_edit_id'])) {
	
	$vd_edit_id=$_POST['vd_edit_id'];
	$vd_editor=$_POST['vd_editor'];
	
	$vd_edit_date=$_POST['vd_edit_date'];
	if($vd_edit_date==""){
		$sqlUpdate = mysqli_query($connection, "UPDATE `vd_edit` SET `date` = NULL WHERE `vd_edit`.`id` = '$vd_edit_id';"); 
		}
		else {
			$sqlUpdate = mysqli_query($connection, "UPDATE `vd_edit` SET `date` = '$vd_edit_date' WHERE `vd_edit`.`id` = '$vd_edit_id';"); 
		}
	$vd_hdd=$_POST['hdd'];
	$vd_remarks=$_POST['remarks'];
	$vd_edit_status=$_POST['vd_edit_status'];
	if($vd_edit_status==""){
		$sqlUpdate = mysqli_query($connection, "UPDATE `vd_edit` SET `status` = '' WHERE `vd_edit`.`id` = '$vd_edit_id';"); 
		}
		else {
			$sqlUpdate = mysqli_query($connection, "UPDATE `vd_edit` SET `status` = 'checked' WHERE `vd_edit`.`id` = '$vd_edit_id';"); 
		}
	
	
	
	$sqlUpdate = "UPDATE vd_edit SET
  editor = '$vd_editor',
 hdd = '$vd_hdd',
 remarks = '$vd_remarks'
												  											  
 WHERE
 id = '$vd_edit_id'           
";

$sqlUpdate = mysqli_query($connection, $sqlUpdate); 


	
	echo "updated";
	
}

?>

