<?php
include "header.php";

if($post_url == "manage-announcement" || empty($post_url)):
?>

<div id="content" class="main-content">

	<div class="layout-px-spacing">
		<div class="row layout-top-spacing" id="cancel-row">
  
			<div class="col-xl-12 col-lg-12 col-sm-12 layout-spacing m-auto">
			
			<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 ">
				<h1 class="title-4"> Announcements </h1>
				<div class="btn-toolbar mb-2 mb-md-0">
					<div class="btn-group mr-2">
					
						<a href="?preg=post-announcement" class="btn btn-icon bg-primary text-white">
						<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-plus-circle"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="16"></line><line x1="8" y1="12" x2="16" y2="12"></line></svg>
						&nbsp; Post New </a>
						
					</div>
				</div>
			</div>
	
			
			<div class="row">
				<div class="col-xl-12 col-lg-12 col-sm-12 m-auto">
							
				<div class="widget-content widget-content-area br-6">	
					
					<div class="table-responsive mb-4 mt-4">
						<table id="events_tbrecs" class="table table-stripped caption-top" style="width:100%">
							
							<thead>
								<tr>
									<th width="55%">Post</th>
									<th width="15%" class="text-center vertical-align">Show</th>
									<th width="15%" class="text-center vertical-align">End</th>
									<th width="15%" class="text-center vertical-align"  data-sortable="false">Action</th>
								</tr>
							</thead>
						</table>
					</div>
					
						
				</div>
				</div>	
				</div>
		
			</div>

		</div>

	</div>

</div>
  
<script type="text/javascript" language="javascript" >

$(document).ready(function(){

	var userdataTable = $('#events_tbrecs').DataTable({
		
		"processing": true,
		"serverSide": true,
		"order": [],
		"ajax":{
			url:"actions/fetch_announcements.php",
			type:"POST"
		},
		"oLanguage": {
                "oPaginate": { "sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>', "sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>' },
                "sInfo": "Showing _START_ to _END_ of _TOTAL_ Events",
                "sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
                "sSearchPlaceholder": "Search title...",
               "sLengthMenu": "Results :  _MENU_",
				"sInfoFiltered": "",
            },
		
		"stripeClasses": [],
		"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
		"pageLength": 10,
		drawCallback: function () { $('.dataTables_paginate > .pagination').addClass(' pagination-style-13 pagination-bordered mb-5'); }
	
	});
	
})

</script>	
	
<?php
elseif($post_url == "post-announcement" || $post_url == "edit-announcement"):

$prd_ft = "";
if(!empty($prd))
{
	$chk_prd_rc = $db_con->prepare("SELECT * FROM announcedpost WHERE ap_id = '$prd' ");
	$chk_prd_rc->execute();
	$prd_ft = $chk_prd_rc->fetch();	 
	$prd_count = $chk_prd_rc->rowCount();
		
	if($prd_count == 0)
	{
		echo "<script>window.location.href ='announcement?preg=manage-announcement'</script>";
	}
}	
?>
<div id="content" class="main-content">

	<div class="layout-px-spacing">
		<div class="row layout-top-spacing" id="cancel-row">
  
			<div class="col-xl-12 col-lg-12 col-sm-12 layout-spacing m-auto">
			
			<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 ">
				<h1 class="title-4"> Post New</h1>
				<div class="btn-toolbar mb-2 mb-md-0">
					<div class="btn-group mr-2">
					
						<a href="?preg=manage-announcement" class="btn btn-icon bg-primary text-white">
						<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-copy"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>
						&nbsp; All Posts</a>
						
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-xl-10 col-lg-10 col-sm-12 m-auto">
				
				<div class="widget-content widget-content-area br-6">	
					
					<form class="text-left" method="post" action="" id="mkpost_form" autocomplete="" enctype="multipart/form-data">
					
							
						<div class="widget-content widget-content-area shadow-none">
							
							<div class="row">
							    <div class="col-md-12">
							        <div class="form-group">
        								<label class="text-dark font-weight-bold">Title <code>*</code>  </label>
        								<input type="text" name="posttitle" class="form-control" required value="<?= (!empty($prd_ft)) ? $prd_ft['anp_title']:''; ?>"/>
        								<span id="" class="error_here"></span>
        							</div>
							    </div>
								
								<?php /*<div class="col-md-4">
									<div class="form-group">
										<label class="text-dark font-weight-bold">Upload Image</label>
										<input type="file"  name="pics_a"  id="pic_a" class="form-control for_image" accept="image/jpeg, image/png, image/jpg" />
										<span id="img_error" class="error_here"></span>
									</div>
								</div>*/ ?>
							</div>
							
							<?= (!empty($prd_ft)) ? '<input type="hidden" name="pstrec" value="'.$prd_ft['ap_id'].'" />' : ''; ?>
						
							<div class="row">
							    
								<div class="col-md-6">
									<div class="form-group">
										<label class="text-dark font-weight-bold">Display Date <code>*</code>  </label>
										<input type="date" name="annoucedate" class="form-control" required value="<?= (!empty($prd_ft)) ? date('Y-m-d', strtotime($prd_ft['anp_date'])) :  date('Y-m-d'); ?>"/>
										<span id="" class="error_here"></span>
									</div> 
								</div>
								
								<div class="col-md-6">
									<div class="form-group">
										<label class="text-dark font-weight-bold">Expiry Date <code>*</code>  </label>
										<input type="date" name="expirydate" class="form-control" required value="<?= (!empty($prd_ft)) ? date('Y-m-d', strtotime($prd_ft['anp_expiry'])) :  date('Y-m-d'); ?>"/>
										<span id="" class="error_here"></span>
									</div>
								</div>
								
							</div>
							
							<input type="hidden" id="setbk" value="<?= $post_url; ?>" name="post_info" />
							
							<div class="form-group">
							<label class="text-dark font-weight-bold">Announcement<code>*</code> </label>
								<textarea name="anouncebrief" class="form-control" id="brief" required maxlength="200"><?= (!empty($prd_ft)) ? $prd_ft['anp_info']:''; ?></textarea>
								<span id="" class="error_here"></span>
							</div>
							
							
						<div class="row form-group mt-3">
							<div class="col-md-12 text-center">
								<button type="submit" class="btn btn-primary"  id="button_tbpst">Submit</button>
							</div>
						</div>
					</form>
					
				</div>
				</div>	
			</div>
		
			</div>

		</div>

	</div>

</div>
  
<script type="text/javascript" language="javascript" >

$(document).ready(function(){

$("#mkpost_form").on('submit',function(e) {
		e.preventDefault();	 
		
		var rev = $('#mkpost_form');
		
			$.ajax({
				url: 'actions/create_annmnt.php',
				type: 'POST',
				data:  new FormData(this),
				contentType: false,
				cache: false,
				processData:false,
				dataType:"json",
				beforeSend: function()
				{	
					$("#button_tbpst").html('submiting <span class="spinner-grow-sm text-white ml-2 align-self-center loader-sm"></span>');
					$("#button_tbpst").attr('disabled', 'disabled');
				},
				success: function(data)
					{
						donejob(data.runstt,data.errorreason);
						$("#button_tbpst").html('Submit');
						$("#button_tbpst").attr('disabled', false);
						
						if(data.runstt == "grant" && $("#setbk").val() == "post-announcement"){
							rev.trigger('reset');	
						}
						else if(data.errorform != "")
						{
							$("#pic_"+data.errorform).siblings("span").text(data.errorreason);
							
						}
					}
			});
    });	
})
</script>


</div>
<?php
endif;
include "footer.php"; 
?>