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

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

<?php
ini_set('display_errors', 0);

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

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


include("user.php");

if(isset($_GET['status']))
{     $nstatus = $_GET['status'];
}

if(isset($_GET['mark_read']))
{     $mark_read = $_GET['mark_read'];

    if($mark_read=="yes"){
		$sql="UPDATE `notifications` SET `status` = '0' WHERE `notifications`.`status` = 1 ";
		$sqlUpdate = mysqli_query($connection, $sql); 

date_default_timezone_set('Asia/Dhaka');
$date_c = date('Y-m-d H:i:s', time());
$sqlUpdate = "INSERT INTO `activity_log` (`id`, `user`, `activity`, `time`) VALUES (NULL, '$ad_id', 'marked all notification status read', '$date_c')";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 
		
	}
}
if(isset($_POST['noti_id']))
{     $noti_id = $_POST['noti_id'];

foreach ($noti_id as $nid){ 
  
  
  $sqlUpdate = "UPDATE notifications SET
  status = '0'
												  											  
 WHERE
 id = '$nid'           
";

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

date_default_timezone_set('Asia/Dhaka');
$date_c = date('Y-m-d H:i:s', time());
$sqlUpdate = "INSERT INTO `activity_log` (`id`, `user`, `activity`, `time`) VALUES (NULL, '$ad_id', 'marked notification status read', '$date_c')";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 	
  
  
  
  
  
  
  
  
} 

}

?>



<!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>Notifications</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">
</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">Notifications</div>
                                            <div class="panel-body">
						
								

								  
								  
								  
								  
								  <?php
								  
								  
								  if (isset($_POST['read'])) {
										 $nid=$_POST['nid'];
										 $sqlUpdate = "UPDATE notifications SET
  status = '0'
												  											  
 WHERE
 id = '$nid'           
";

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

date_default_timezone_set('Asia/Dhaka');
$date_c = date('Y-m-d H:i:s', time());
$sqlUpdate = "INSERT INTO `activity_log` (`id`, `user`, `activity`, `time`) VALUES (NULL, '$ad_id', 'marked notification status read', '$date_c')";
$sqlUpdate = mysqli_query($connection, $sqlUpdate); 											 
											
										      echo "<div>
											 </br>
											 </div>";
											 include_once('updated.html');
									}
								  
							
								  
								  ?>
								  
								  
								  
								  
								  
								  
								  
								  
								  
                                    <div class="row">
                        <div class="col-lg-12">
                            <div class="card alert">
							
							
							
							
							
							
							
							
							
							
							
                               
								
								
								
								
								
								
								
								
								
							<?php if ($user_type==1){  ?>
							
							
								  <div class="row">
								 <div class="col-sm-2">  <div class="span3"> <a href="notifications.php?status=unread"> <span class="badge badge-danger">Unread Only</span></a>  <a href="notifications.php"> <span class="badge badge-primary">All</span>  </a>   <a href="notifications.php?status=unread&mark_read=yes"> <span class="badge badge-warning" onclick="return confirm('Are you sure?')" >Mark All Read</span></a> 
							 </div>  </div>
								
								</div>
									<form action='notifications.php?status=unread' method='post'>
								 <div class="bootstrap-data-table-panel">
                                    <div class="table-responsive">
                                        <table  class="table table-striped table-bordered">
                                            <thead>
                                                <tr>
												      <th>SL.</th>
                                                     <th>Details</th>
													
													<th>Status</th>
													
													<th>Assigned At</th>
													<th>Added At</th>
													 <th>Diary of</th>
													  <th>Booking ID</th>
													  <th>Customer</th>
													  <th>Rg Editor</th>
													  <th>SP Editor</th>
													  <th>V.Editor</th>
													   <th>Event ID</th>
													   
													<th>Updated At</th>
													<th>Mark Read</th>
													
                                                </tr>
                                            </thead>
                                            <tbody>
											
											<?php
$sl=0;
						$sqlSelectedLG = "select g1.*,g2.name rg_editor_name, g3.name sp_editor_name,g4.name vd_editor_name from (SELECT t1.*,t3.booking_name,t2.date ev_date,t2.temp_id,t3.booking_id,t3.name customer,t4.date ph_date,t4.editor,t4.sp_editor,t5.editor vd_editor,t5.date vd_date FROM `notifications` as t1 left join events as t2 on t1.ev_id=t2.id left join bookings as t3 on t2.temp_id=t3.id left join photo_edit as t4 on t1.ev_id=t4.event_id left join vd_edit as t5 on t1.ev_id=t5.event_id order by t1.added_at desc limit 100) as g1 left join users as g2 on g1.editor=g2.id left join users as g3 on g1.sp_editor=g3.id left join users as g4 on g1.vd_editor=g4.id";
						
						if($nstatus =="unread"){
							$sqlSelectedLG = "select *  from (select g1.*,g2.name rg_editor_name, g3.name sp_editor_name,g4.name vd_editor_name from (SELECT t1.*,t3.booking_name,t2.date ev_date,t2.temp_id,t3.booking_id,t3.name customer,t4.date ph_date,t4.editor,t4.sp_editor,t5.editor vd_editor,t5.date vd_date FROM `notifications` as t1 left join events as t2 on t1.ev_id=t2.id left join bookings as t3 on t2.temp_id=t3.id left join photo_edit as t4 on t1.ev_id=t4.event_id left join vd_edit as t5 on t1.ev_id=t5.event_id order by t1.added_at desc limit 100) as g1 left join users as g2 on g1.editor=g2.id left join users as g3 on g1.sp_editor=g3.id left join users as g4 on g1.vd_editor=g4.id) as j1 where j1.status=1";
						}

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

                                    
                                   
                                    $idn = $list->id;
									$ev_date = $list->ev_date;
									$ph_date = $list->ph_date;
									$vd_date = $list->vd_date;
									$details = $list->details;
									$diary_of = $list->booking_name;
									$booking_id = $list->booking_id;
									$temp_id = $list->temp_id;
									$customer = $list->customer;
									$rg_editor_name = $list->rg_editor_name;
									$sp_editor_name = $list->sp_editor_name;
									$vd_editor_name = $list->vd_editor_name;
									
									
									$ev_id = $list->ev_id;
									 $status = $list->status;
								   $added_at = $list->added_at;
									$updated_at = $list->updated_at;
									 $type = $list->type;
									
									if($type=="1"){$ass_date=$ph_date;}
									if($type=="2"){$ass_date=$vd_date;}
									
									
									if($status=="0"){$n_status='read';}
									if($status=="1"){$n_status='Unread';}
									
									
										$sl=$sl+1;
								
                                    
                                   
                                ?>
											
											
										
											
                                                <tr>
												    <td> <?php echo $sl;  ?> 
													
														</td>
												
                                                    <td>  <?php echo $details;  ?> </td>
													  <td><?php echo $n_status;  ?></td>
													    <td><?php echo $ass_date;  ?></td>
													   <td><?php echo $added_at;  ?></td>
													     <td><?php echo $diary_of;  ?></td>
														   <td><a href="booking_details.php?id=<?php echo $temp_id;  ?>"> <?php echo $booking_id;  ?> </a></td>
														       <td><?php echo $customer;  ?></td>
															    <td><?php echo $rg_editor_name;  ?></td>
																 <td><?php echo $sp_editor_name;  ?></td>
																  <td><?php echo $vd_editor_name;  ?></td>
															  <td><?php echo $ev_id;  ?></td>
															 
                                                    <td><?php echo $updated_at;  ?></td>
                                                  
														<td> 
<?php if($status=="1"){  ?>


											<?php if($nstatus=="unread") { ?> 
                                                
												<input type="checkbox" name="noti_id[]" value="<?php echo $idn;  ?>"/>

													<?php } ?>		
												
													 </td>
													
<?php } ?>
													
													
                                                </tr>
                                                
												
<?php } ?>			
												
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
									<button class="btn done btn-success btn-md" onclick="return confirm('Are you sure you want to mark all this read?');" type="submit" name='all_read' >Mark Selected Read</button>
									
									
								</form>
							
							<?php } ?>			
							
								
                            </div>
                            <!-- /# card -->
                        </div>
                        <!-- /# column -->
                    </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 action="search.php">
            <input type="search" name="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>



</body>

</html>