File: /var/www/nclive/technc/exam_list.php
<?php
include 'header.php';
// ini_set('display_errors', 1);
// ini_set('display_startup_errors', 1);
// error_reporting(E_ALL);
$host = $_SERVER['SERVER_NAME']; // domain for creating post page
$user_id = 1;
$message = ''; // for displayin error and success msgs
include('function.php'); // to make new post page
$EXAM_CATEGORY = "sp_exam_category";
$POST_TABLE = "naukri_wp_posts";
$count = "select count(*) as total from $EXAM_CATEGORY";
$sql = $db->prepare($count);
$sql->execute();
$plus = $sql->fetch();
$query = "Select cat_id, name, url_slug, img_icon, h1_title, full_name, display_order, type, status from $EXAM_CATEGORY";
$sql = $db->prepare($query);
$sql->execute();
// submit data to add exam category
if (isset($_REQUEST['postSubmit'])) {
$post_title = $_REQUEST['exm_name'];
$post_name = $_REQUEST['slug'];
$post_content = $_REQUEST['shortcode'];
$post_parent = 0;
if (empty($post_title)) {
$message = '<div class="alert alert-danger alert-dismissible fade show"><strong>Category Name Required.</strong></div>';
} else if (empty($post_name)) {
$message = '<div class="alert alert-danger alert-dismissible fade show"><strong>Url SLug Email Required.</strong></div>';
} else if (empty($post_content)) {
$message = '<div class="alert alert-danger alert-dismissible fade show"><strong>Shortcode Required.</strong></div>';
} else {
$exist_page = $db->prepare("SELECT count(ID) as countId FROM $POST_TABLE WHERE post_name = '" . $post_name . "' AND post_status='publish'");
$exist_page->execute();
$check_page = $exist_page->fetch(PDO::FETCH_ASSOC);
if ($check_page['countId'] == 0) {
createPostPages($post_title, $post_content, $post_name, $user_id, $post_parent, $host);
$message = '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button> <strong>Data submit successfully</strong></div>';
} else {
$message = '<div class="alert alert-danger"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">x</button> <strong>Page Already Exist. Enter other name. </strong></div>';
}
}
}
?>
<style>
#form .form-group label.error {
color: #FB3A3A;
display: inline-block;
margin: 0px 0 0px 0px;
padding: 0;
text-align: left;
}
</style>
<main id="main-container">
<div class="content content-narrow">
<div class="row">
<div class="col-lg-12">
<h2 class="content-heading">Exam Category List</h2>
<?php echo $message; ?>
<div class="msg"></div>
<table class="table table-striped table-hover text-capitalize">
<thead>
<tr class="danger">
<th class="text-center">S.no</th>
<th class="text-center">Category</th>
<th class="text-center">Url Slug</th>
<th class="text-center">Full name</th>
<th class="text-center">Display Order</th>
<th class="text-center">Image</th>
<th class="text-center">Type</th>
<th class="text-center">Edit</th>
<!-- <th class="text-center">Status</th> -->
<!-- <th class="text-center">Add Post</th> -->
<th class="text-center">Delete</th>
</tr>
</thead>
<tbody>
<?php
$i = '1';
while ($row = $sql->fetch()) {
if ($row['type'] == '1') {
$t = "Government Exam";
} else if ($row['type'] == '2') {
$t = "Entrance Exam";
}
$url_slug = $row['url_slug'];
$exist_page = $db->prepare("SELECT count(ID) as countId FROM $POST_TABLE WHERE post_name = '$url_slug' AND post_status='publish'");
$exist_page->execute();
$check_page = $exist_page->fetch(PDO::FETCH_ASSOC);
// echo "SELECT count(ID) as countId FROM $POST_TABLE WHERE post_name = '$url_slug' AND post_status='publish'" ;
?>
<tr>
<td class="text-center"><?php echo $i; ?></td>
<td class="text-center"><?php echo $row['name']; ?></td>
<td class="text-center"><?php echo $url_slug; ?></td>
<td class="text-center"><?php echo $row['full_name']; ?></td>
<td class="text-center"><?php echo $row['display_order']; ?></td>
<td class="text-center"><img src="images/<?php echo $row['img_icon']; ?>" style="width:50px; height:50px;"></td>
<td class="text-center"><?php echo $t; ?></td>
<td class="text-center"><a href="update_category.php?id=<?php echo $row['cat_id']; ?>"><button class="btn btn-info"> Edit </button> </a> </td>
<!-- <td class="text-center">
<button class="btn <?php //if ($row['status'] == 1) {/ echo 'btn-success';/ } else {/ echo 'btn-danger';/ }
?>" id="changeStatus<?php //echo $row['cat_id'];
?>" onclick="updateData(<?php //echo $row['cat_id'];
?>)"><?php //if ($row['status'] == 1) { echo 'Active'; } else { echo 'Deactive'; }
?></button>
</td> -->
<!-- <td class="text-center"><?php if ($check_page['countId'] == 0) { ?> <button name="add" class="btn btn-info" onclick="addData(<?php echo $row['cat_id']; ?>)" data-toggle="tooltip" title="Add post for this exam">Add Page</button> <?php } ?></td> -->
<td class="text-center"><a style="color:#fff;" href="delete.php?id=<?php echo $row['cat_id']; ?>" onclick="return confirm('Are you sure you want to delete')"><button class="btn btn-danger" data-toggle="tooltip" title="Delete this exam!" data-placement="bottom">Delete</button></a></td>
</tr>
<?php $i++;
} ?>
<tr class="danger">
<th colspan='7'>Total Category</th>
<td colspan='4'><?php echo $plus['total']; ?></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</main>
<!-- --view post detail modal------->
<div class="modal fade" id="postModal" role="dialog">
<div class="modal-dialog">
<div class="modal-content" id="post_detail">
</div>
</div>
</div>
<!---------END post MODEL----->
<script type="text/javascript">
// function selectData(id) {
// var base_url = window.location.origin;
// // $.ajax('update_exam_category.php', {
// $.ajax({
// url: "update_exam_category.php",
// type: 'POST',
// data: {
// id: id
// },
// success: function(data, status, xhr) {
// console.log(data);
// // alert(data.cat_id);
// document.getElementById('id').value = data.cat_id;
// // document.getElementById('exm_name').value = data.name;
// // document.getElementById('slug').value = data.url_slug;
// // document.getElementById('full').value = data.full_name;
// document.getElementById('display_order').value = data.display_order;
// document.getElementById('image').value = data.img_icon;
// document.getElementById('testimg').src = base_url + '/technc/images/' + data.img_icon;
// // document.getElementById('type').value = data.type;
// // if (document.getElementById('type').value == '1') {
// // document.getElementById('type').innerHTML = "Government Exam";
// // } else if (document.getElementById('type').value == '2') {
// // document.getElementById('type').innerHTML = "Entrance Exam";
// // }
// },
// error: function(jqXhr, textStatus, errorMessage) {}
// });
// // jQuery("#statusModel").modal();
// // body...
// }
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script type="text/javascript">
</script>
<script>
// to make slug from post name
function convertToSlug(str) {
str = str.replace(/[`~!@#$%^&*()_\-+=\[\]{};:'"\\|\/,.<>?\sāā//]/g, ' ').toLowerCase(); //replace all special characters | symbols with a space
str = str.replace(/^\s+|\s+$/gm, ''); // trim spaces at start and end of string
str = str.replace(/\s+/g, '-'); // replace space with dash/hyphen
document.getElementById("post_slug").value = str;
}
//view
function addData(id) {
var site = "add_new_exam_category.php";
jQuery.ajax({
url: site,
type: 'POST',
data: {
id: id
},
success: function(data) {
$('#post_detail').html(data);
$('#postModal').modal("show");
}
});
}
//status
function updateData(id) {
$('.msg').fadeIn(500);
$.ajax({
url: 'update_status.php',
type: 'post',
data: {
clickid: id,
pageid: 'category'
},
success: function(response) {
if (response == 1) {
$('#changeStatus' + id).addClass('btn-success');
$('#changeStatus' + id).removeClass('btn-danger');
$("#changeStatus" + id).html("Active");
} else {
$('#changeStatus' + id).addClass('btn-danger');
$('#changeStatus' + id).removeClass('btn-success');
$("#changeStatus" + id).html("Deactive");
}
$('.msg').html('<div class="alert alert-success"><strong>Status Updated Successfully!</strong></div>');
$('.msg').fadeOut(2000);
}
});
}
</script>
<?php include 'footer.php'; ?>