
	<?php 
	ini_set('display_errors', 0);
	
	
	session_start(); ob_start(); ?>

<?php  include 'header.php'; ?>

<?php

if(empty($_SESSION['LOGINID']) && empty($_SESSION['LOGINNM']) ){

	header("Location:index.php");
}


include("user.php");

$tab_id = mysqli_real_escape_string($connection, $_GET['ev_id']);

date_default_timezone_set('Asia/Dhaka');
$date_submit = date('Y-m-d', time());
$date_c = date('Y-m-d H:i:s', time());

$sqltab = "SELECT * FROM `events` where id='$tab_id' ";
$sqltab = mysqli_query($connection, $sqltab);
$evdatas = mysqli_fetch_object($sqltab);

									
$ddate_ph = $evdatas->d_date;
$ddate_vd = $evdatas->d_date_vd;

$max_ev = mysqli_query($connection, "SELECT max(date) max_date FROM `events` where temp_id=$temp_id;");
$max_ev = mysqli_fetch_object($max_ev);
$evndate = $max_ev->max_date;

$settingsSQL = mysqli_query($connection, "SELECT * FROM `settings` where name='delivery_policy_day' ");
$settingsSQL = mysqli_fetch_object($settingsSQL);
									
$delivery_policy_day = $settingsSQL->value;			  
$change_need_vd='yes';
$change_need_ph='yes';

$new_d_date_vd=date('Y-m-d', strtotime($date_t. ' + '.$delivery_policy_day.' days'));
$new_d_date_ph=date('Y-m-d', strtotime($date_t. ' + '.$delivery_policy_day.' days'));

if(strtotime($ddate_vd) > strtotime($new_d_date_vd)) {
    $change_need_vd='no';
}

if(strtotime($evndate) > strtotime($date_t)) {
    $change_need_vd='no';
	$change_need_ph='no';
	
} 

if(strtotime($ddate_ph) > strtotime($new_d_date_ph)) {
    $change_need_ph='no';
}





if (isset($_POST['submit_ph'])) {
	    $new_photo_selection =  mysqli_real_escape_string($connection, $_POST['photo_selection']);
		
		 $sqlUpdate = "UPDATE events SET
  photo_selection = '$new_photo_selection',
  ph_submit_date = '$date_submit'
  
												  											  
 WHERE
 id = '$tab_id'           
";
$sqlUpdate = mysqli_query($connection, $sqlUpdate);
 
 
if($change_need_ph=='yes'){
	$sqlUpdate = "UPDATE events SET
  d_date = '$new_d_date_ph',d_date_ph_set='2'  WHERE
 id = '$tab_id'           
";
$sqlUpdate = mysqli_query($connection, $sqlUpdate);	
} 
 

$sqlUpdate = "INSERT INTO `activity_log` (`id`, `user`, `activity`, `time`, `temp_id`) VALUES (NULL, '$ad_id', 'event photo updated $tab_id', '$date_c','')";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 		 
}


if (isset($_POST['submit_song'])) {
	    $new_trailer_song = $_POST['trailer_song'];
		   $new_video_songs =  mysqli_real_escape_string($connection, $_POST['video_songs']);
		     
		   
		   
		 $sqlUpdate = "UPDATE events SET
  trailer_song = '$new_trailer_song',
  video_songs = '$new_video_songs',
  song_submit_date = '$date_submit'
  
												  											  
 WHERE
 id = '$tab_id'           
";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 
$sqlUpdate = "INSERT INTO `activity_log` (`id`, `user`, `activity`, `time`, `temp_id`) VALUES (NULL, '$ad_id', 'event video updated $tab_id', '$date_c','')";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 

if($change_need_vd=='yes'){
	$sqlUpdate = "UPDATE events SET
  d_date_vd = '$new_d_date_vd',d_date_set='2'  WHERE
 id = '$tab_id'           
";
$sqlUpdate = mysqli_query($connection, $sqlUpdate);	
}


		 
}


if (isset($_POST['submit_update'])) {
	    $ev_name = $_POST['evname'];
	     $new_ev_notes = $_POST['ev_notes'];
		 $new_lock_input = $_POST['lock_input'];
		  
		   
		 $sqlUpdate = "UPDATE events SET
  diary_of = '$ev_name',
  ev_notes = '$new_ev_notes',
  lock_input = '$new_lock_input'
  
												  											  
 WHERE
 id = '$tab_id'           
";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 
$sqlUpdate = "INSERT INTO `activity_log` (`id`, `user`, `activity`, `time`, `temp_id`) VALUES (NULL, '$ad_id', 'event data updated $tab_id', '$date_c','')";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 		 
}














$sqltab = "SELECT * FROM `events` where id='$tab_id' ";

$sqltab = mysqli_query($connection, $sqltab);
while ($list = mysqli_fetch_object($sqltab)) {

                                   $evname = $list->diary_of;
								   $lock_input = $list->lock_input; if($lock_input==1){$lock_status="checked";}
									$trailer = $list->trailer_song;
									$photo_selection = $list->photo_selection;
									$video_songs = $list->video_songs;
									$ev_notes = $list->ev_notes;
									$ev_value = $list->ev_value;
									 $videoincluded=$list->videoincluded;
									 $ph_submit_date=$list->ph_submit_date;
									 $song_submit_date=$list->song_submit_date;
									 
									if($videoincluded=="checked") {$vdo_button="yes"; }
}


?>



<table cellpadding='3' height='' cellspacing='0' align='left'> 
											
											 
									<form action="song_list.php?ev_id=<?php echo $tab_id; ?>" method="post">
											<tr>
											<td>  </td> 
											
											<td>  &nbsp; Event Name </td>  
											<td> <input type="text" name="evname" size="50" class="form-control input-focus" placeholder="Event Name" value="<?php echo $evname; ?>"> 
											</td>
											 
										
											</tr>
											
											<tr>
											<td>  </td> 
											
											<td>  &nbsp; Notes </td>  
											<td> <input type="text" name="ev_notes" class="form-control input-focus" size="50" placeholder="notes" value="<?php echo $ev_notes; ?>">  
											</td>
											</tr>
											<tr>
											<td>  </td> 
											<td>  &nbsp; Lock Input (mark to lock) </td>  
											<td> <input type="checkbox" <?php echo $lock_status; ?> name="lock_input" value="1" class="form-control input-focus" size="50" >  
											</td>
											 
										
											</tr>
											
											
												<tr>
											<td>  </td> 
											
												<td> </td>  
												<td> <input type="submit" name="submit_update" value="Update"> </td>   
											</td>
											 
										
											</tr>
											
											</form>	 
											
											<form action="song_list.php?ev_id=<?php echo $tab_id; ?>" method="post">
											<tr>
											<td>  </td> 
											
											<td>  &nbsp; Photo No's By comma (,) </td>  
											<td> <input type="text"  name="photo_selection" size="50" class="form-control input-focus" placeholder="1,2,3.." value="<?php echo $photo_selection; ?>"> 
											</td>
											 </tr>
											 <tr>
											<td>  </td> 
											
											<td>  &nbsp; Photo submission Date </td>  
											<td> <input type="date" disabled name="photo submission"  class="form-control input-focus" placeholder="" value="<?php echo $ph_submit_date; ?>"> 
											</td>
											 </tr>
											 <tr>
											<td>  </td> 
											
												<td> </td>  
												<td> <input type="submit" name="submit_ph" value="Update"> </td>   
											</td>
											 
										
											</tr>
											</form>	
											 
											 
											 <?php if($vdo_button=="yes") { ?>
											<form action="song_list.php?ev_id=<?php echo $tab_id; ?>" method="post">
											
											<tr>
											<td>  </td> 
											
											<td>  &nbsp; Trailer Song </td>  
											<td> <input type="text"  name="trailer_song" size="50" class="form-control input-focus" placeholder="http://youtube.com/" value="<?php echo $trailer; ?>"> 
											</td>
											 </tr>
											 <tr>
											<td>  </td> 
										    <td>  &nbsp; Videos Songs </td>  
											<td> <textarea name="video_songs" class="form-control input-focus" rows="10" cols="40" ><?php echo $video_songs; ?></textarea>
											</td>
											</tr>
											 <tr>
											<td>  </td> 
											
											<td>  &nbsp; Song submission Date </td>  
											<td> <input type="date" disabled name="song submission"  class="form-control input-focus" placeholder="" value="<?php echo $song_submit_date; ?>"> 
											</td>
											 </tr>
											 
											 <tr>
											<td>  </td> 
											
												<td> </td>  
												<td> <input type="submit" name="submit_song" value="Update"> </td>   
											</td>
											 
										
											</tr>
											</form>	
											 <?php } ?>
											 
											  
											 
								</table>





	
	

											
											
					