File: /var/www/nclive/technc/notification_for_header.php
<?php
include 'header.php';
error_reporting(E_ALL);
ini_set('display_errors', 'ON');
$user_id = $_SESSION['user_id'];
$curDate = date('Y-m-d H:i:s');
$updateExpiryNotification = "UPDATE sp_notification set status='0' where CURRENT_DATE > expiry_date";
$update = $db->prepare($updateExpiryNotification);
$update->execute();
$maxOrderQuery = $db->prepare("select max(display_order) as disp from `sp_notification`");
$maxOrderQuery->execute();
$maxOrderRes = $maxOrderQuery->fetch(PDO::FETCH_ASSOC);
$maxOrder = $maxOrderRes['disp'];
$message = '';
?>
<style>
.total_ques_div {
background-color: white;
border-color: #C8D5E0;
border-image: none;
border-style: solid;
border-width: 1px 1px 2px;
color: #1E598E;
font-weight: bold;
padding: 8px 10px;
text-decoration: none;
}
.form-table td {
padding: 0px !important;
}
.extLink {
text-decoration: none;
cursor: pointer;
}
.fancybox-skin {
margin-left: 400px !important;
width: 500px !important;
}
.form-table td {
padding: 5px !important;
font-size: 12px !important;
}
</style>
<script type="text/javascript" charset="utf8" src="assets/js/jquery-1.4.1.min.js"></script>
<script type="text/javascript" charset="utf8" src="assets/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" href="assets/css/jquery.dataTables.min.css">
<?php
if (isset($_POST['submit'])) {
$exam_id = $_REQUEST['exam'];
$title = $_REQUEST['title'];
$state_id = $_REQUEST['state_id'];
$status = $_REQUEST['status'];
$date = $_REQUEST['date'];
$user_id = $_REQUEST['user_id'];
$display_order = $_REQUEST['display_order'];
$notif_type = $_REQUEST['notif_type'];
$cus_link = trim($_REQUEST['cus_link']);
$insertquery = "INSERT INTO sp_notification SET exam_id='$exam_id', title='$title', state_id ='$state_id', expiry_date='$date',added_by='$user_id', status='$status', add_date='$curDate', display_order='$display_order', notif_type='$notif_type', custom_link='$cus_link'";
$sql = $db->prepare($insertquery);
if ($sql->execute()) {
$message = "<font style='color:green; float:left;'><h3> Insert successfully</h3></font>";
} else {
$message = "<font style='color:red; float:left;'><h3> error</h3></font>";
}
}
?>
<link href="assets/js/plugins/select2/select2.min.css" rel="stylesheet">
<main id="main-container">
<div class="content content-narrow">
<div class="row">
<div class="col-lg-12">
<h2 class="content-heading"> Add Nofitication </h2>
<div class="block">
<div class="block-header">
<ul class="block-options">
<li>
<button type="button"><i class="si si-settings"></i></button>
</li>
</ul>
<h4 class="block-title"><?php echo $message; ?></h4>
</div>
<div class="block-content block-content-narrow">
<form class="js-validation-bootstrap form-horizontal" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="col-md-2 control-label" for="val-select2">Select Exam </label>
<div class="col-md-7">
<select class="js-select2 exam-dropdown form-control" name="exam" style="width: 100%;">
<?php
$sql = $db->prepare("SELECT exam_id, exam_name FROM sp_exam ORDER by exam_id desc");
$sql->execute();
?>
<option value='0'>--Select Exam--</option>
<?php
while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {
?>
<option value="<?php echo $row['exam_id']; ?>"><?php echo $row['exam_name']; ?></option>
<?php } ?>
</select>
</div>
</div>
<input type="hidden" value="<?php echo $user_id; ?>" name="user_id">
<div class="form-group">
<label class="col-md-2 control-label" for="val-password">State:</label>
<div class="col-md-7">
<select class="js-select2 form-control" name="state_id" style="width: 100%;">
<?php
$sql = $db->prepare("SELECT state_id,state_name FROM sp_states ORDER by state_name ASC");
$sql->execute();
?>
<option value='0'>--Select State--</option>
<?php
while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {
?>
<option value="<?php echo $row['state_id']; ?>"><?php echo $row['state_name']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="val-email">Title:</label>
<div class="col-md-7">
<input class="form-control" type="text" name="title" id="title" placeholder="" />
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="val-email">Expiry Date:<span class="text-danger">*</span></label>
<div class="col-md-7">
<input class="form-control" type="date" name="date" id="date" placeholder="" required>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="val-email">Display Order:<span class="text-danger">*</span></label>
<div class="col-md-7">
<input class="form-control" type="number" name="display_order" id="display_order" value="<?php echo $maxOrder + 1; ?>" placeholder="" required>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="val-password">Status:<span class="text-danger">*</span></label>
<div class="col-md-7">
<select class="js-select2 form-control" name="status" style="width: 100%;">
<option value="1">Active</option>
<option value="0">Deactive</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="notif_type">Type:</label>
<div class="col-md-7">
<select class="js-select2 form-control" name="notif_type" id="notif_type" style="width: 100%;">
<option value="Exam">Exam</option>
<option value="Board">Board</option>
<option value="Blog">Blog</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="cus_link">Custom Link (valid for notification other then exam):</label>
<div class="col-md-7">
<input class="form-control" type="text" name="cus_link" id="cus_link" placeholder="" />
</div>
</div>
<div class="form-group">
<div class="col-md-10 col-md-offset-2">
<button class="btn btn-lg btn-primary" name="submit" type="submit">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
<div class="content content-narrow">
<div class="row">
<div class="col-lg-12">
<h2 class="content-heading">Notification List</h2>
<div class="table-responsive">
<table id="notification" class="table table-striped table-bordered dt-responsive nowrap" style="width: 100%; cellspacing: 0; f">
<thead>
<tr class="danger">
<th>Edit</th>
<th>Status</th>
<th>Order</th>
<th>Title</th>
<th>Exam Name</th>
<th>State</th>
<th>Added By</th>
<th>Expiry Date</th>
<th>Date</th>
<th>Action</th>
</tr>
</thead>
</table>
<script type="text/javascript">
jQuery.noConflict();
var msg = "'Are you sure'";
jQuery(document).ready(function() {
jQuery('.exam-dropdown').select2();
jQuery('#notification').dataTable({
"dom": "Bfrtip",
"pagingType": "full_numbers",
"processing": true,
"serverSide": true,
"responsive": true,
"ajax": "notification_for_header_data.php",
"columns": [{
"data": "id",
"render": function(data, type, row) {
return '<a href="notification_update?id=' + row.id + '" title="Edit Notification"><button class="btn btn-info"><i class="fa fa-pencil-square-o " aria-hidden="true"></i></button></a>';
}
},
{
"data": "status"
},
{
"data": "display_order"
},
{
"data": "title"
},
{
"data": "exam_name"
},
{
"data": "state_name"
},
{
"data": "username"
},
{
"data": "expiry_date"
},
{
"data": "date"
},
{
"data": "action",
"render": function(data, type, row) {
return '<button class="btn btn-default" title="Push Notification" onclick="pushNoti(' + row.id + ')"><i style="color: #e27a7a;" class="fa fa-bell-o"></i></button><button class="btn btn-danger" title="Delete Notification" onclick="deleteNoti(' + row.id + ')"><i class="fa fa-trash-o"></i></button>';
}
},
],
"bPaginate": true,
"iDisplayLength": 50,
"bProcessing": true,
"bServerSide": true,
"lengthMenu": [
[10, 50, 100, 500, 1000],
[10, 50, 100, 500, 1000]
]
});
});
</script>
</div>
</div>
</div>
</div>
</main>
<script>
function pushNoti(id) {
var r = confirm("Are you sure to Push Notifications ?");
if (r == true) {
var site = "/technc/send_push_notifications.php?noti_id=" + id + "&type=send";
jQuery.ajax({
url: site,
type: 'POST',
data: 'html',
success: function(response) {
var obj = jQuery.parseJSON(response);
if (obj.status == '1') {
alert(obj.msg);
location.reload();
} else {
alert(obj.msg);
}
}
});
} else {
return false;
}
}
function deleteNoti(id) {
var r = confirm("Are you sure to Delete Notifications ?");
if (r == true) {
var site = "/technc/send_push_notifications.php?noti_id=" + id + "&type=delete";
jQuery.ajax({
url: site,
type: 'POST',
data: 'html',
success: function(response) {
var obj = jQuery.parseJSON(response);
if (obj.status == '1') {
alert(obj.msg);
location.reload();
} else {
alert(obj.msg);
}
}
});
} else {
return false;
}
}
</script>
<?php include 'footer.php'; ?>
<script src="assets/js/plugins/select2/select2.min.js"></script>