<?php  session_start(); error_reporting(0); ?>
<?php if(!isset($_SESSION['j_admin']) && !isset($_SESSION['j_admin'])){ 
    $url = urlencode("http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"); header('location:../login/?url='.$url.'');  
} ?>
<!doctype html>
<html lang="en"> 
<head>
	<?php
    require_once("../j_conn/url.php");
    require_once("../j_conn/dbc.php");
    require_once("../j_incs/functions.php");
    $page_name="Notifications";
    $page_desc="$page_name";
    $page_img="".$dir."j_files/j_img/logo/logo-meta.png";
    $page_author="$company";
    $page_keywords="".$company.", $page_name, $page_desc, ".$company_motto.", $company_desc";
    $page_url="".$dir."notifications/";
    require_once("../j_incs/metas.php");
    require_once("../j_incs/scripts-top.php");
    ?>
</head>
<body>
    
    <div class="app">
        <div class="layout">
            <?php 
            require_once("../j_incs/header.php");
            require_once("../j_incs/nav.php");
            ?>
            <!-- Page Container START -->
            <div class="page-container">
                

                <!-- Content Wrapper START -->
                <div class="main-content">
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-1"></div>
                            <div class="col-md-10">
                                <div class="page-header">
									<?php /*<h2 class="header-title"><?php echo $page_name; ?></h2>*/ ?>
									<div class="header-sub-title">
										<nav class="breadcrumb breadcrumb-dash">
											<a href="<?php echo $dir; ?>" class="breadcrumb-item"><i class="anticon anticon-dashboard m-r-5"></i>Dashboard</a>
											<!--<a class="breadcrumb-item" href="#"> </a>-->
											<span class="breadcrumb-item active"><?php echo $page_name; ?></span>
										</nav>
									</div>
								</div>
                            </div>
                        </div>
                    </div>
                     
                    
                    
                    
                    
                    <div class="container-fluid">
                        <div class="row">
                            <div class="col-md-1"></div>
                            <div class="col-md-10">
                                
                       
                     
								<div class="mail-wrapper">

									<div id="mail-list" class="mail-content" style="width:100%; padding:0px;">
									
									
									
									<div class="row d-flex align-items-center justify-content-between p-10">
										<div class="col-md-4 d-none d-md-flex align-items-baseline m-b-10">
											<div id="n_options_result"></div>
											<?php 
											/*
											<div class="checkbox d-inline-block">
												<input id="checkAll" type="checkbox">
												<label for="checkAll"></label>
											</div>
											*/
											?>
											<select class="custom-select" name="n_options">
												<option value="">Options</option>
												<option value="read">Mark all as Read</option>
												<option value="unread">Mark all as Unread</option>
											</select>
										</div>
										<div class="d-none d-md-flex align-items-center col-md-3 m-b-10">
											
											<div class="input-affix m-r-10">
												<!--<i class="prefix-icon anticon anticon-search"></i>
												<input type="text" class="form-control" placeholder="Search">-->
											</div>
											
											<a href="<?php echo $dir; ?>notifications/" class="btn btn-icon btn-default p-t-10">
												<i class="anticon anticon-reload"></i>
											</a>
										</div>
									</div>
							


									<div>
										
									


										<?php 
										if(isset($_SESSION['j_icon_admin'])){
										$limit =100;
										}else{
										$limit =100;
										}
										$offset = RMC($_GET['m']);
										if($offset<1){
											$offset = 0;
											$num = 1;
										}else{
											$num=$offset+1;
										}
										//
										$sql25="SELECT * from j_notifications WHERE 
										j_deleted < 1 AND j_user_id='".$id."'
										|| j_deleted < 1 AND j_user_id='*'
										order by j_id desc
										"; //  
										$result25 = runSQL($sql25);
										$total = mysqli_num_rows($result25);
										//
										$sql25="SELECT * from j_notifications WHERE 
										j_deleted < 1 AND j_user_id='".$id."'
										|| j_deleted < 1 AND j_user_id='*'
										order by j_id desc limit $limit offset $offset
										"; //  
										$result25 = runSQL($sql25);
										//$total = mysqli_num_rows($result25);
										//
										while($row = mysqli_fetch_array($result25)){
										$row['j_message'] = str_replace('{{name}}', $name, $row['j_message']);
										$row['j_message'] = str_replace('{{email}}', $email, $row['j_message']);
										$row['j_message'] = str_replace('{{phone}}', $phone, $row['j_message']);
										$row['j_message'] = str_replace('{{username}}', $username, $row['j_message']);
										$row['j_message'] = str_replace('{{company}}', $company, $row['j_message']);
										$row['j_message'] = str_replace('{{company_motto}}', $company_motto, $row['j_message']);
										$row['j_message'] = str_replace('{{company_address}}', $company_address, $row['j_message']);
										$row['j_message'] = str_replace('{{company_email}}', $company_email, $row['j_message']);
										$row['j_message'] = str_replace('{{company_phone}}', $company_phone, $row['j_message']);
										?>
										<div class="mail-list">
											<?php
											/*
											<div class="checkbox d-inline-block">
												<input id="mail-checkbox-1<?php echo $row['j_id']; ?>" type="checkbox">
												<label for="mail-checkbox-1<?php echo $row['j_id']; ?>"></label>
											</div>
											*/
											?>


											<?php //if($row['j_user_id']!=='*'){ ?>
											<?php //if($row['j_read']!=='1'){ ?>
											<?php if(strpos($row['j_read'],"'$id'") === false){ ?>
											<div class="checkbox d-inline-block">
												<span class="badge badge-indicator badge-success" id="read_id<?php echo ($row['j_id']); ?>"></span>
												<label for="mail-checkbox-1"></label>
											</div>
											<?php //} ?>
											<?php }else{ ?>
											<div class="checkbox d-inline-block">
												<span class="badge badge-indicator badge-success" id="read_id<?php echo ($row['j_id']); ?>" style="display:none;"></span>
												<label for="mail-checkbox-1"></label>
											</div>
											<?php } ?>


											<table style="font-size:12px;" class="table list-info submit" ref="<?php echo ($row['j_id']); ?>">
												<tr>
													<?php 
													/*
													<td class="list-sender">
														<div class="media align-items-center">
															<div class="avatar avatar-md nSender">
																<span>
																<?php echo $short_name; ?>
																</span>
															</div>
															<h6 class="m-l-10 m-b-0"><?php echo $username; ?></h6>
														</div>
													</td>
													*/
													?>  
													<td class="list-content">
														<div class="list-msg">
															<span class="list-title"><?php echo $row['j_subject']; ?></span>
															<span class="m-h-5 d-none d-lg-inline-block"> - </span>
															<span class="list-text text-gray"> <?php echo DRMC_MSG(RMC($row['j_message'])); ?> </span>
														</div>
													</td>
													<td class="list-date" style="font-size:10px;">
														<span><?php echo time_ago($row['j_date']); ?></span>
													</td>
												</tr>
											</table>


										</div>
										<?php } ?>

									</div>
									<div class="m-t-20 text-right">
										<ul class="pagination justify-content-end">
											<?php if($offset > 0){ ?>
											<li class="page-item"><a class="page-link" href="?m=<?php echo $offset-$limit; ?>">
												<i class="fas fa-chevron-left"></i> Previous</a></li>
											<?php } ?>
											<?php 
											/*
											<li class="page-item active"><a class="page-link" href="#">1</a></li>
											<li class="page-item"><a class="page-link" href="#">2</a></li>
											<li class="page-item"><a class="page-link" href="#">3</a></li>
											*/
											?>
											<?php if($total >= $offset && $total > $limit){ ?>
											<li class="page-item"><a class="page-link" href="?m=<?php echo $offset+$limit; ?>">
												Next <i class="fas fa-chevron-right"></i></a></li>
											<?php } ?>
										</ul>
									</div>
								</div>



									<!--Content-->
									<div id="mail-content" class="mail-content d-none" style="width:100%;">

										<div class="d-lg-flex align-items-center justify-content-between">
											<div class="media align-items-center m-b-15">
												<a id="back" class="text-gray m-r-15 font-size-18" href="javascript:void(0);">
													<i class="anticon anticon-left-circle"></i> Back
												</a>
											</div>
										</div>

										<div id="formresult"></div>

									</div>






									<?php
									/*
									<div id="mail-compose" class="mail-content d-none">
										<div class="p-b-15 m-r-15 d-md-none d-inline-block">
											<a class="text-dark font-size-18 mail-open-nav" href="javascript:void(0);">
												<i class="anticon anticon-menu-unfold"></i>
											</a>
										</div>
										<h5 class="m-b-20">New Message</h5>
										<form>
											<div class="form-group">
												<input type="text" class="form-control" placeholder="To">
											</div>
											<div class="form-group">
												<input type="text" class="form-control" placeholder="Subject">
											</div>
											<div id="mail-compose-editor"></div>
										</form>
										<div class="text-right m-t-25">
											<button class="m-r-10 btn btn-default mail-close-compose">Discard</button>
											<button class="btn btn-primary">Send</button>
										</div>
									</div>
									*/
									?>



								</div>
							</div>
                                            
                        </div>
                    </div>
                    
                    
                </div>
                <!-- Content Wrapper END -->

                <?php
                require_once("../j_incs/footer.php");
                ?>

            </div>
            <!-- Page Container END -->
        </div>
    </div>
    
    
    <?php
    require_once("../j_incs/scripts-bottom.php");
    ?>
    <script>
		var option_id = $("[name=n_options]");
		var option_result = $("#n_options_result");
		var read_btn = $(".badge.badge-indicator.badge-success");
			option_id.on('change',(function() {
			var option_value = option_id.val();
			if(option_value !==''){
				if(option_value =='read'){
					read_btn.hide();
				}
				if(option_value =='unread'){
					read_btn.show();
				}
				$.post("read-unread.php",
				{
					option_value:option_value,
				}, function (data){
					option_result.html(data);
				});
			}
		}));
		var button = ".submit";
		var button_val = $(button).html();
		var result = "#formresult";
		$(button).on('click',(function() {
		var ref = $(this).attr('ref');
		var read_ref = "#read_id"+ref+"";
		$(read_ref).hide();
		$(result).html("<p align='center'><i class='anticon anticon-loading'></i>  Loading...</p>");
			if(request){
				request.abort();
			}
			var request = $.ajax({
			url: '<?php echo $dir;  ?>notifications/save.php?ref='+ref+'',
			method: 'post',
			success: function (data) {
				 document.getElementById("formresult").innerHTML=data;
				var request = null;
			 }
		});
		}));
	</script>
</body>
</html>