tech4biz/admin/blog-list.php
2024-10-24 17:20:08 +05:30

305 lines
18 KiB
PHP

<?PHP
require_once "./db/config.php";
require_once "./includes/functions.php";
if (!isset($_SESSION["loggedAdmin"]) || empty($_SESSION["loggedAdmin"])) {
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}";
header("location: login.php?redirect_to=$actual_link");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tech4Biz - Category Manage</title>
<?PHP include "./includes/links.php"; ?>
<link href="https://fonts.googleapis.com/css?family=Rubik:400,400i,500,500i,700,700i&amp;display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i,900&amp;display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="./assets/css/font-awesome.css">
<!-- ico-font-->
<link rel="stylesheet" type="text/css" href="./assets/css/vendors/icofont.css">
<!-- Themify icon-->
<link rel="stylesheet" type="text/css" href="./assets/css/vendors/themify.css">
<!-- Flag icon-->
<link rel="stylesheet" type="text/css" href="./assets/css/vendors/flag-icon.css">
<!-- Feather icon-->
<link rel="stylesheet" type="text/css" href="./assets/css/vendors/feather-icon.css">
<!-- Plugins css start-->
<link rel="stylesheet" type="text/css" href="./assets/css/vendors/scrollbar.css">
<link rel="stylesheet" type="text/css" href="./assets/css/vendors/datatables.css">
<!-- Plugins css Ends-->
<!-- Bootstrap css-->
<link rel="stylesheet" type="text/css" href="./assets/css/vendors/bootstrap.css">
<!-- App css-->
<link rel="stylesheet" type="text/css" href="./assets/css/style.css">
<link id="color" rel="stylesheet" href="./assets/css/color-1.css" media="screen">
<!-- Responsive css-->
<link rel="stylesheet" type="text/css" href="./assets/css/responsive.css">
<style>
.flex-justify-column {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
</style>
<script src="./assets/js/ckeditor.js"></script>
</head>
<body>
<?PHP include "./includes/loader.php"; ?>
<div class="tap-top"><i data-feather="chevrons-up"></i></div>
<div class="page-wrapper compact-wrapper" id="pageWrapper">
<?PHP include "./includes/header.php"; ?>
<div class="page-body-wrapper">
<?PHP include "./includes/sidebar.php"; ?>
<div class="page-body">
<div class="container-fluid">
<div class="row">
<div class="col-sm-12">
<div class="card mt-3">
<div class="job-title-admin">
<h3>Blog List</h3>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#exampleModal" >Add Blog</button>
</div>
<div class="card-body">
<div class="table-responsive">
<table class="display" id="advance-1">
<thead>
<tr>
<th>Category</th>
<th>Sub Category</th>
<th>Blog Read Time</th>
<th>Blog Title</th>
<th>Developer Name</th>
<th>Created Date</th>
<th>Updated Date</th>
<th>Header Image</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$careersData = $connection->query("SELECT * FROM `blogs_data` ");
foreach ($careersData as $val) {
?>
<tr>
<td><?php echo $val['category_id']; ?></td>
<td><?php echo $val['category_sub_id']; ?></td>
<td><?php echo $val['blog_read_time']; ?></td>
<td><?php echo $val['blog_title']; ?></td>
<td><?php echo $val['developer_id']; ?></td>
<td>
<?php
$timestamp = strtotime($val['blog_created_date']);
echo date('d-n-Y', $timestamp);
?>
</td>
<td>
<?php
$timestamp = strtotime($val['blog_updated_date']);
echo date('d-n-Y', $timestamp);
?>
</td>
<td class="text-center">
<img src="./blog_image/<?php echo $val['blog_header_image']; ?>" alt="<?php echo $val['blog_header_image']; ?>" style="display: block;width: 72px;">
</td>
<td>
<div class="job-list-action">
<span class="job-list-action-icon" >
<svg onclick='editModel(<?php echo json_encode($val);?>)' xmlns="http://www.w3.org/2000/svg" width="41.4" height="41.45" viewBox="0 0 41.4 41.45">
<path id="edit_square_FILL0_wght400_GRAD0_opsz48" d="M9,47.4a2.878,2.878,0,0,1-2.1-.9A2.878,2.878,0,0,1,6,44.4v-30a2.878,2.878,0,0,1,.9-2.1A2.878,2.878,0,0,1,9,11.4H29.25l-3,3H9v30H39V27l3-3V44.4a3.076,3.076,0,0,1-3,3ZM24,29.4Zm9.1-17.6,2.15,2.1L21,28.1v4.3h4.25l14.3-14.3,2.1,2.1L26.5,35.4H18V26.9Zm8.55,8.4L33.1,11.8l5-5a2.883,2.883,0,0,1,2.125-.85,2.8,2.8,0,0,1,2.125.9l4.2,4.25a2.992,2.992,0,0,1,.85,2.125,2.746,2.746,0,0,1-.9,2.075Z" transform="translate(-6 -5.95)"/>
</svg>
</span>
<span class="job-list-action-icon">
<svg onclick='deleteModel(<?php echo json_encode($val['blog_ref_id']);?>)' xmlns="http://www.w3.org/2000/svg" width="32" height="36" viewBox="0 0 32 36">
<path id="Path_1" data-name="Path 1" d="M13.05,42a2.988,2.988,0,0,1-3-3V10.5H8v-3h9.4V6H30.6V7.5H40v3H37.95V39a3.076,3.076,0,0,1-3,3Zm21.9-31.5H13.05V39h21.9ZM18.35,34.7h3V14.75h-3Zm8.3,0h3V14.75h-3ZM13.05,10.5v0Z" transform="translate(-8 -6)"/>
</svg>
</span>
</div>
</td>
</tr>
<?php }?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-width">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Blog</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form id="addBlogPost" name="addBlogPost" method="post" autocomplete="off">
<div class="mb-3 form-group">
<label for="blog_title" class="col-form-label">Blog Title <span>*</span></label>
<input type="text" class="form-control" name="blog_title" id="blog_title" />
<input type="hidden" class="form-control" name="blog_ref_id" id="blog_ref_id" />
<div class="help-block with-errors"></div>
</div>
<div class="mb-3 form-group">
<label for="blog_header_image" class="col-form-label">Blog Header Image <span>*</span></label>
<input type="file" class="form-control" name="blog_header_image" id="blog_header_image" />
<div class="help-block with-errors"></div>
</div>
<div class="mb-3 d-flex justify-content-between">
<div class="w-48 form-group">
<label for="category_id" class="col-form-label">Category <span>*</span></label>
<input type="text" class="form-control" name="category_id" id="category_id" />
<div class="help-block with-errors"></div>
</div>
<div class="w-48 form-group">
<label for="category_sub_id" class="col-form-label">Sub Category <span>*</span></label>
<input type="text" class="form-control" name="category_sub_id" id="category_sub_id" />
<div class="help-block with-errors"></div>
</div>
</div>
<div class="mb-3 d-flex justify-content-between">
<div class="w-48 form-group">
<label for="blog_read_time" class="col-form-label">Blog Read Time <span>*</span></label>
<input type="text" class="form-control" name="blog_read_time" id="blog_read_time" />
<div class="help-block with-errors"></div>
</div>
<div class="w-48 form-group">
<label for="developer_id" class="col-form-label">Developer Name <span>*</span></label>
<input type="text" class="form-control" name="developer_id" id="developer_id" />
<div class="help-block with-errors"></div>
</div>
</div>
<div class="mb-3 form-group">
<label for="blog_details_content" class="col-form-label">Blog Description <span>*</span></label>
<textarea class="form-control" id="editor" name="blog_details_content" rows="8"></textarea>
<div class="help-block with-errors"></div>
</div>
<div class="modal-footer form-group">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button class="btn btn-primary" type="submit" name="sendBlogPost" id="sendBlogPost">Submit</button>
</div>
<div id="msgSubmit" class="h3 text-center hidden"></div>
</form>
</div>
</div>
</div>
</div>
<?PHP include './includes/footer.php'; ?>
</div>
</div>
<script>
var fileInput = document.getElementById('blog_header_image');
var file = fileInput.files[0];
// Create a new FileReader object
var reader = new FileReader();
// Set the onload function to convert the image to base64 when loaded
reader.onload = function(event) {
// Get the base64 data URL
var base64String = btoa(event.target.result);
// Use the base64 data in your code
console.log('base64Image=======',base64String);
};
// Read the image file as a binary string
reader.readAsBinaryString(file);
</script>
<?PHP include './includes/scripts.php'; ?>
<script src="./assets/js/jquery.validate.min.js"></script>
<script src="./assets/js/jquery-3.5.1.min.js"></script>
<script src="./assets/js/bootstrap/bootstrap.bundle.min.js"></script>
<script src="./assets/js/icons/feather-icon/feather.min.js"></script>
<script src="./assets/js/icons/feather-icon/feather-icon.js"></script>
<script src="./assets/js/scrollbar/simplebar.js"></script>
<script src="./assets/js/scrollbar/custom.js"></script>
<script src="./assets/js/config.js"></script>
<script src="./assets/js/sidebar-menu.js"></script>
<script src="./assets/js/datatable/datatables/jquery.dataTables.min.js"></script>
<script src="./assets/js/datatable/datatables/datatable.custom.js"></script>
<script src="./assets/js/script.js"></script>
<script src="./assets/js/add-blog-form-validation-custom.js"></script>
<script src="./assets/js/add_blog_data.js"></script>
<script>
var editor1;
ClassicEditor
.create( document.querySelector( '#editor' ) ).then(editor => {
editor1 = editor;
})
.catch( error => {
console.error( error );
} );
function editModel(params) {
$("#blog_header_image").val(params.blog_header_image);
$("#id").val(params.id);
$("#blog_ref_id").val(params.blog_ref_id);
$("#category_id").val(params.category_id);
$("#category_sub_id").val(params.category_sub_id);
$("#blog_read_time").val(params.blog_read_time);
$("#blog_title").val(params.blog_title);
$("#developer_id").val(params.developer_id);
$("#blog_details_content").html(params.blog_details_content);
$("#blog_created_date").val(params.blog_created_date.split(" ")[0]);
$("#blog_updated_date").val(params.blog_updated_date.split(" ")[0]);
$("#exampleModal").modal('show');
editor1.setData(params.job_description);
var modalTitle = exampleModal.querySelector('.modal-title')
var modalBodyInput = exampleModal.querySelector('.modal-body input')
modalTitle.textContent = 'Edit Blog Post'
}
function deleteModel(blog_ref_id){
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
type: "POST",
url: "./api/add_blog_data.php",
data: "api_type=delete&blog_ref_id=" + blog_ref_id,
success: function (text) {
let data = JSON.parse(text)
if (data.status == 200) {
Swal.fire(
'Deleted!',
'Your blog has been deleted.',
'success'
)
// setTimeout(() => {
// window.location.reload();
// }, 1000);
} else {
formError();
submitMSG(false, text);
}
}
});
}
})
}
var exampleModal = document.getElementById('exampleModal')
exampleModal.addEventListener('show.bs.modal', function (event) {
var button = event.relatedTarget
var recipient = button.getAttribute('data-bs-whatever')
var modalTitle = exampleModal.querySelector('.modal-title')
var modalBodyInput = exampleModal.querySelector('.modal-body input')
modalTitle.textContent = 'Add Blog Post '
modalBodyInput.value = recipient
})
</script>
</body>
</html>