Viewing file: edit_articles.php (8.45 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
include('include/header.php');
include('include/conn.php');
error_reporting(E_ALL);
ini_set('display_errors', 1);
$edit_id = $_GET['art_edit'];
$edit_qry = "SELECT * FROM articles as a LEFT JOIN article_content_table as b ON a.art_id = b.art_for_id WHERE a.art_id = $edit_id";
$qryRes = mysqli_query($conn, $edit_qry);
$qryRow = mysqli_fetch_assoc($qryRes);
$admin_name = 'Unknown Admin';
$stmt = $conn->prepare("SELECT `Admin_Name` FROM `admin_login` WHERE `Admin_ID` = ?");
$stmt->bind_param("i", $qryRow['art_create_by']); // assuming Admin_ID is an integer
$stmt->execute();
$result = $stmt->get_result();
if ($result && $result->num_rows > 0) {
$row = $result->fetch_assoc();
$admin_name = $row['Admin_Name'];
}
$stmt->close();
?>
<link href="https://cdn.datatables.net/1.12.1/css/jquery.dataTables.min.css" rel="stylesheet" type="text/css">
<link href="https://cdn.datatables.net/buttons/2.2.3/css/buttons.dataTables.min.css" rel="stylesheet" type="text/css">
<style type="text/css">
.dt-buttons {
width: 50%;
}
</style>
<!-- begin MAIN PAGE CONTENT -->
<div id="page-wrapper" style="min-height:142vh;">
<div class="page-content">
<!-- begin PAGE TITLE ROW -->
<div class="row">
<div class="col-lg-12">
<div class="page-title">
Edit Articles
</div>
</div>
<div class="col-md-12">
<form action="./actions/edit_article.php" method="post" enctype="multipart/form-data">
<div class="col-md-10">
<div class="form-group">
<label for="art_title" class="">Article Title</label>
<input type="hidden" name="articleId" class="form-control" id="articleId" value="<?= $qryRow['art_id'] ?>">
<input type="text" name="art_title" class="form-control" id="art_title" value="<?= $qryRow['art_title'] ?>">
</div>
</div><br>
<div class="col-md-10">
<div class="form-group">
<label for="art_sub_title" class="">Sub Title</label>
<input type="text" name="art_sub_title" class="form-control" id="art_sub_title" value="<?= $qryRow['art_sub_title'] ?>">
</div>
</div><br>
<div class="col-md-10">
<div class="form-group">
<label for="author_name" class="">Author</label>
<input type="text" name="author_name" class="form-control" value="<?= $admin_name ?>" id="author_name">
<input type="hidden" name="author_id" value="<?= $_SESSION['admin_id'] ?>" class="form-control" id="author_name">
</div>
</div><br>
<div class="col-md-10">
<div class="form-group">
<label for="img_alp" class="">Article Image</label>
<img src="<?= $qryRow['art_image'] ?>" alt="" style="width: 150px;">
<input type="file" name="article_image" class="form-control" id="article_image" value="">
<input type="hidden" name="oldarticle_image" class="form-control" id="article_image" value="<?= $qryRow['art_image'] ?>">
</div>
</div><br>
<div class="col-md-10">
<div class="form-group">
<label for="index_table" class="">Introduction</label>
<!-- <input type="text" name="table_contents[]" class="form-control" id="index_table"> -->
<textarea name="intro" id="intro" class="form-control" value="<?= $qryRow['art_intro'] ?>"><?= $qryRow['art_intro'] ?></textarea>
</div>
</div><br>
<div class="col-md-10">
<div class="form-group">
<label for="index_table" class="">Conclusion</label>
<!-- <input type="text" name="table_contents[]" class="form-control" id="index_table"> -->
<textarea name="conclusion" id="intro" class="form-control" value="<?= $qryRow['art_conclusion'] ?>"><?= $qryRow['art_conclusion'] ?></textarea>
</div>
</div><br>
<div class="col-md-10">
<div class="form-group">
<label for="index_table" class="">Heading</label>
<input type="text" name="index_table[]" class="form-control" id="index_table" value="<?= $qryRow['art_heading_name'] ?>">
</div>
</div><br>
<div class="col-md-10">
<div class="form-group">
<label for="index_table" class=""> Contents</label>
<!-- <input type="text" name="table_contents[]" class="form-control" id="index_table"> -->
<textarea name="table_contents[]" id="table_contents" class="form-control" value="<?= $qryRow['art_body_contents'] ?>"><?= $qryRow['art_body_contents'] ?></textarea>
</div>
</div><br>
<div class="col-md-12" id="dynamic-fields">
<!-- Additional fields will be added here -->
<div class="form-group" id="items">
</div>
</div>
<div class="col-md-10" style="display: none;">
<button id="add" class="btn btn-warning text-white" type="button">Add <i class='fa fa-solid fa-plus'></i></button>
</div><br>
<div class="col-md-1">
<input type="submit" name="article_update" value="Update" class="btn btn-success text-white">
</div>
</form>
</div>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
</div>
<!-- /.page-content -->
</div>
<!-- /#page-wrapper -->
<!-- begin FOOTER -->
<?php include('include/footer.php'); ?>
<script src="https://cdn.ckeditor.com/4.16.0/standard/ckeditor.js"></script>
<script>
$("#add").click(function(e) {
$("#dynamic-fields").fadeIn("1500");
// Show the delete button
$(".delete").fadeIn("1500");
// Append a new row of code to the "#items" div
var newIndex = $(".add_index").length + 1;
$("#items").append(`
<div class="add_index">
<div class='row'>
<div class="form-group col-md-10">
<label for="index_table${newIndex}" class="">Heading</label>
<input type="text" name="index_table[]" class="form-control" id="index_table${newIndex}">
</div>
<div class="col-md-1">
<div class="form-group">
<span class='btn btn-primary mt-4 text-white delete'><i class='fa fa-solid fa-minus'></i></span>
</div>
</div>
</div>
<br>
<div class="form-group col-md-10">
<label for="table_contents${newIndex}" class="">Contents</label>
<textarea name="table_contents[]" id="table_contents${newIndex}" class="form-control"></textarea>
</div>
<br>
</div>`);
// Initialize CKEditor for the newly added textarea
CKEDITOR.replace(`table_contents${newIndex}`);
$("body").on("click", ".delete", function(e) {
// Remove the associated field when the delete button is clicked
$(this).closest(".add_index").remove();
});
});
</script>
<script>
// CKEDITOR.replace( 'term_title' );
CKEDITOR.replace('intro');
</script>
<script>
// CKEDITOR.replace( 'term_title' );
CKEDITOR.replace('conclusion');
</script>
<script>
// CKEDITOR.replace( 'term_title' );
CKEDITOR.replace('table_contents[]');
</script>
|