<?php session_start(); ob_start(); ?>

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

<?php

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

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


include("user.php");

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



?>

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Edit Event</title>
    <!-- ================= Favicon ================== -->
    <!-- Standard -->
    <link rel="shortcut icon" href="http://placehold.it/64.png/000/fff">
    <!-- Retina iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="144x144" href="http://placehold.it/144.png/000/fff">
    <!-- Retina iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="114x114" href="http://placehold.it/114.png/000/fff">
    <!-- Standard iPad Touch Icon-->
    <link rel="apple-touch-icon" sizes="72x72" href="http://placehold.it/72.png/000/fff">
    <!-- Standard iPhone Touch Icon-->
    <link rel="apple-touch-icon" sizes="57x57" href="http://placehold.it/57.png/000/fff">
    <!-- Styles -->
     <link href="assets/css/lib/data-table/buttons.bootstrap.min.css" rel="stylesheet" />
    <link href="assets/css/lib/font-awesome.min.css" rel="stylesheet">
    <link href="assets/css/lib/themify-icons.css" rel="stylesheet">
    <link href="assets/css/lib/owl.carousel.min.css" rel="stylesheet" />
    <link href="assets/css/lib/owl.theme.default.min.css" rel="stylesheet" />
    <link href="assets/css/lib/weather-icons.css" rel="stylesheet" />
    <link href="assets/css/lib/menubar/sidebar.css" rel="stylesheet">
    <link href="assets/css/lib/bootstrap.min.css" rel="stylesheet">
    <link href="assets/css/lib/unix.css" rel="stylesheet">
    <link href="assets/css/style.css" rel="stylesheet">
	   <link href="assets/css/lib/select2/select2.min.css" rel="stylesheet">
</head>

<body>

    
	
	  <?php include("sidebar.php"); ?>
	
	
    <!-- /# sidebar -->
     <?php include("top.php"); ?>
	<!-- /# topebar --> 
	
	
    <div class="content-wrap">
        <div class="main">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-8 p-r-0 title-margin-right">
                        <div class="page-header">
                            <div class="page-title">
                                <h1>Hello, <span>Welcome Here</span></h1>
                            </div>
                        </div>
                    </div>
                    <!-- /# column -->
                    <div class="col-lg-4 p-l-0 title-margin-left">
                        <div class="page-header">
                            <div class="page-title">
                                <ol class="breadcrumb text-right">
                                    <li><a href="#">Dashboard</a></li>
                                    <li class="active">Home</li>
                                </ol>
                            </div>
                        </div>
                    </div>
                    <!-- /# column -->
                </div>
                <!-- /# row -->
				
					<?php if ($user_type==1){ ?>
				
                <section id="main-content">
				
				
			
				
				
				
				
				
				<div class="row">
				
				        <div class="col-lg-12">
						
						<div class="panel panel-info m-t-15">
                                            <div class="panel-heading">Event Edit</div>
                                            <div class="panel-body">
											
											<?php
	$edit_id = $_GET["edit_id"];

	
if (isset($_POST['submit'])) {
									  
 
 
								    $new_date = $_POST['date'];
								$old_date = $_POST['old_date'];
									 $new_diary_of = $_POST['diary_of'];
									//$new_event_type = $_POST['event_type'];
									$new_venue = $_POST['venue'];
									$new_time = $_POST['time'];
									$new_ph_package = $_POST['ph_package'];
									
									
									if(isset($_POST['pr'])){
                                    $new_pr = $_POST['pr'];
                                    }else{
                                     $new_pr = NULL;#default value
                                    }
									
									
									
									if(isset($_POST['vd'])){
                                    $new_vd = $_POST['vd'];
                                    }else{
                                     $new_vd = NULL;#default value
                                    }
									
									$new_photographers = $_POST['ph_ids'];
									$new_photographers=array_unique($new_photographers);
									$new_photographers = implode(',', $new_photographers);
									//$new_ph_names = $_POST['name'];
									
									$first_comma= $new_photographers[0];
									if($first_comma==","){
										$new_photographers = substr($new_photographers, 1);
									}
									$last_comma= $new_photographers[-1];
									if($last_comma==","){
										$new_photographers = substr_replace($new_photographers ,"",-1);
									}
									//$new_ph_names = $_POST['name'];
									
									$new_vd_package = $_POST['vd_package'];
									$new_videographers = $_POST['vd_ids'];
										$new_videographers=array_unique($new_videographers);
									$new_videographers = implode(',', $new_videographers);
									
									
									$first_commav= $new_videographers[0];
									if($first_commav==","){
										$new_videographers = substr($new_videographers, 1);
									}
									$last_commav= $new_videographers[-1];
									if($last_commav==","){ 
									  $new_videographers = substr_replace($new_videographers ,"",-1);
									}
									//$new_vd_names = $_POST['name'];
									
									 $new_asst = $_POST['asst'];
									 $new_makeover = $_POST['makeover'];
									 $new_ev_notes = $_POST['ev_notes'];
										
										// $ph_namesArray = explode(',', $ph_names);
										//$photographersArray = explode(',', $photographers);
										//$vd_namesArray = explode(',', $vd_names);
										//$videographersArray = explode(',', $videographers);										
//**												  
												  
$sqlUpdate = "UPDATE events SET
  date = '$new_date',
  diary_of = '$new_diary_of',
 venue = '$new_venue',
 time = '$new_time',
 ph_package = '$new_ph_package',
 pr = '$new_pr',
 videoincluded = '$new_vd',
 photographers = '$new_photographers',
 vd_package = '$new_vd_package',
 videographers = '$new_videographers',
 asst = '$new_asst',
 makeover = '$new_makeover',
 ev_notes = '$new_ev_notes',
 updated_at = '$date_c'
												  											  
 WHERE
 id = '$edit_id'           
";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 
			

$sqlUpdate = "INSERT INTO `events_log` (`id`, `ev_id`,`prev_date`, `new_date`, `details`, `user`, `added_at`) VALUES (NULL, '$edit_id','$old_date', '$new_date', 'Event Updated', '$u_name', '$date_c' );";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 
			
 echo "<div>
 </br>
 </div>";
 include_once('updated.html');									  
}





$eventSQL = mysqli_query($connection, "SELECT v1.* , GROUP_CONCAT(v2.name ORDER BY v2.id) as vd_names FROM (SELECT p1.* , GROUP_CONCAT(p2.name ORDER BY p2.id) as ph_names FROM (select a1.* , a2.name as event_type from (SELECT t1.*, t2.name as client_name, t2.booking_id, t2.cell_1,t2.cell_2 FROM `events` as t1 left join bookings as t2 on t1.temp_id=t2.id order by t1.date) as a1 left join event_types as a2 on a1.type=a2.id) as p1 left join artists as p2 ON FIND_IN_SET(p2.id, p1.photographers) group by p1.id) as v1 left join artists as v2 ON FIND_IN_SET(v2.id, v1.videographers) WHERE v1.id='$edit_id' group by v1.id ");
$eventSQL = mysqli_fetch_object($eventSQL);
									
                                    $idn = $eventSQL->id;
								    $date = $eventSQL->date;
									$name = $eventSQL->client_name;
									$diary_of = $eventSQL->diary_of;
									$booking_id = $eventSQL->booking_id;
									$cell_1 = $eventSQL->cell_1;
									$cell_2 = $eventSQL->cell_2;
									$event_type = $eventSQL->event_type;
									$venue = $eventSQL->venue;
									$time = $eventSQL->time;
									$ph_package = $eventSQL->ph_package;
									$pr = $eventSQL->pr;
									$vd = $eventSQL->videoincluded;
									$photographers = $eventSQL->photographers;
									$ph_names = $eventSQL->ph_names;
									$vd_package = $eventSQL->vd_package;
									$videographers = $eventSQL->videographers;
									$vd_names = $eventSQL->vd_names;
									
									 $asst = $eventSQL->asst;
									 $makeover = $eventSQL->makeover;
									 	$ev_notes = $eventSQL->ev_notes;
										
										$ph_namesArray = explode(',', $ph_names);
										$photographersArray = explode(',', $photographers);
										asort($photographersArray);
										$vd_namesArray = explode(',', $vd_names);
										$videographersArray = explode(',', $videographers);
										asort($videographersArray);
											?>
						
                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card alert">
                                <div class="card-body">
                                    <div class="form-validation">
								
                                        <form class="form-valide" action="#" method="post">
										    <div class="form-group row">
                                                <label class="col-lg-4 col-form-label" for=""> Date   </label>
                                                <div class="col-lg-8">
                                                       <input type="date" class="form-control calendar bg-ash" placeholder="dd/mm/yyyy" value="<?php echo "$date"; ?>" name="date">
                                               
                                                </div>
                                            </div>
											
										    <div class="form-group row">
                                                <label class="col-lg-4 col-form-label" > Time   </label>
                                                <div class="col-lg-8">
                                                       <input type="time" class="form-control calendar bg-ash" placeholder="" value="<?php echo "$time"; ?>"  name="time">
                                               
                                                </div>
                                            </div>
										
											<div class="form-group row">
                                                <label class="col-lg-4 col-form-label" > Diary of   </label>
                                                <div class="col-lg-8">
                                                    <input type="text" class="form-control"  name="diary_of" value="<?php echo "$diary_of"; ?>" placeholder="diary of">
                                                </div>
                                            </div>
											
											
											
										    <div class="form-group row">
                                                <label class="col-lg-4 col-form-label" > Venue   </label>
                                                <div class="col-lg-8">
                                                    <input type="text" class="form-control"  name="venue" value="<?php echo "$venue"; ?>" placeholder="Venue">
                                                </div>
                                            </div>
											
											 <div class="form-group row">
                                                <label class="col-lg-4 col-form-label" > PR   </label>
                                                <div class="col-lg-8">
                                                    <input type="checkbox" <?php echo "$pr"; ?> name="pr" value="checked">
                                                </div>
                                            </div>
											 <div class="form-group row">
                                                <label class="col-lg-4 col-form-label" > Video Included   </label>
                                                <div class="col-lg-8">
                                                    <input type="checkbox" <?php echo "$vd"; ?> name="vd" value="checked">
                                                </div>
                                            </div>
										    <div class="form-group row">
                                                <label class="col-lg-4 col-form-label" > Photo Package   </label>
                                                <div class="col-lg-8">
                                                    <input type="text" class="form-control" name="ph_package" value="<?php echo "$ph_package"; ?>" placeholder="Photo Package">
                                                </div>
                                            </div>
											
											
											
											<div class="form-group row">
                                                <label class="col-lg-4 col-form-label" >Photographer  </label>
                                                <div class="col-lg-6">
                                                     <select class="form-control bg-ash border-none select2" multiple="multiple" data-placeholder="Select a Photographer" style="width: 100%;" name="ph_ids[]">
            <option></option>
                                              																
																			<?php 

$q=0;
foreach ($photographersArray as $photographer)
{
        echo '<option value="'.$photographer.'" selected>'.$ph_namesArray[$q].'</option>';
		$q=$q+1;
}
?>
 
 



											
												
												<?php 
												
												
												


                               
                                $sqlSelectMem = "SELECT * FROM `artists` where type='Photographer' ";

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


                               while ($list = mysqli_fetch_object($sqlSelectMem)) {

                                    
                                   
                                    $name = $list->name;
									$idtn = $list->id;
                                   
                                ?>
												
												
                                                       
														<option value="<?php echo $idtn;  ?>"> <?php echo $name;  ?>  </option>
														
							   <?php } ?>
                                                    </select>
                                                </div>
                                            </div>
											
											
											 <div class="form-group row">
                                                <label class="col-lg-4 col-form-label" > Video Package   </label>
                                                <div class="col-lg-8">
                                                    <input type="text" class="form-control"  name="vd_package" value="<?php echo "$vd_package"; ?>" placeholder="Video Package">
                                                </div>
                                            </div>
											
											
											<div class="form-group row">
                                                <label class="col-lg-4 col-form-label" >Videographer  </label>
                                                <div class="col-lg-6">
                                                     <select class="form-control bg-ash border-none select2" multiple="multiple" data-placeholder="Select a Videographer" style="width: 100%;" name="vd_ids[]">
            <option></option>
                                              																
										<?php 

$q=0;
foreach ($videographersArray as $videographer)
{
        echo '<option value="'.$videographer.'" selected>'.$vd_namesArray[$q].'</option>';
		$q=$q+1;
}
?>
 
 



											
												
												<?php 
												
												
												


                               
                                $sqlSelectMem = "SELECT * FROM `artists` where type='Videographer' ";

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


                               while ($list = mysqli_fetch_object($sqlSelectMem)) {

                                    
                                   
                                    $name = $list->name;
									$idtn = $list->id;
                                   
                                ?>
												
												
                                                       
														<option value="<?php echo $idtn;  ?>"> <?php echo $name;  ?>  </option>
														
							   <?php } ?>
                                                    </select>
                                                </div>
                                            </div>
											
											 <div class="form-group row">
                                                <label class="col-lg-4 col-form-label" > Asst   </label>
                                                <div class="col-lg-8">
                                                    <input type="text" class="form-control" name="asst" value="<?php echo "$asst"; ?>" placeholder="Asst">
                                                </div>
                                            </div>
											
											 <div class="form-group row">
                                                <label class="col-lg-4 col-form-label" > Notes   </label>
                                                <div class="col-lg-8">
                                                    <input type="text" class="form-control" name="ev_notes" value="<?php echo "$ev_notes"; ?>" placeholder="Notes">
                                                </div>
                                            </div>
											
											<div class="form-group row">
                                                <label class="col-lg-4 col-form-label" for="val-username"> MakeOver   </label>
                                                <div class="col-lg-8">
                                                    <input type="text" class="form-control" id="val-username" name="makeover" value="<?php echo "$makeover"; ?>" placeholder="MakeOver">
                                                </div>
                                            </div>
											
											
											
											
											
											
											
                                          
                                            <div class="form-group row">
											 <label class="col-lg-4 col-form-label" for="val-username">    </label>
                                                <div class="col-lg-8 ml-auto">
												    <input type="hidden"  value="<?php echo $date;  ?>" name="old_date" >
                                                    <button type="submit" name="submit" class="btn btn-primary">Submit</button>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                                  



                                   


							 </div> </div>
							
                        </div>
				
				
                        <!-- /# column -->
                        
                    </div>
				
				
				
				
				
                    <!-- /# row -->
                   
				   
				   
				           <?php include("footer.php"); ?>
						   
						   
                </section>
				
				
					<?php } ?>
            </div>
        </div>
    </div>

    <div id="search">
        <button type="button" class="close">×</button>
        <form>
            <input type="search" value="" placeholder="type keyword(s) here" />
            <button type="submit" class="btn btn-primary">Search</button>
        </form>
    </div>


    </div>
    <script src="assets/js/lib/jquery.min.js"></script>
    <!-- jquery vendor -->
    <script src="assets/js/lib/jquery.nanoscroller.min.js"></script>
    <!-- nano scroller -->
    <script src="assets/js/lib/menubar/sidebar.js"></script>
    <script src="assets/js/lib/preloader/pace.min.js"></script>
    <!-- sidebar -->
    <script src="assets/js/lib/bootstrap.min.js"></script>
    <!-- bootstrap -->
   
    <script src="assets/js/scripts.js"></script>
	
	 <script src="assets/js/lib/data-table/datatables.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.dataTables.min.js"></script>
    <script src="assets/js/lib/data-table/dataTables.buttons.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.flash.min.js"></script>
    <script src="assets/js/lib/data-table/jszip.min.js"></script>
    <script src="assets/js/lib/data-table/pdfmake.min.js"></script>
    <script src="assets/js/lib/data-table/vfs_fonts.js"></script>
    <script src="assets/js/lib/data-table/buttons.html5.min.js"></script>
    <script src="assets/js/lib/data-table/buttons.print.min.js"></script>
    <script src="assets/js/lib/data-table/datatables-init.js"></script>
	
	<script>
        $(document).ready(function() {
            $('.select2').select2();
        });
    </script>

		 <script src="assets/js/lib/select2/select2.full.min.js"></script>
		 
		 
</body>

</html>