D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
diafrica
/
spre.dominicaninstitute.edu.ng
/
Filename :
newsevent.php
back
Copy
<?php session_start(); include 'inc/config.php'; include './inc/functions.php'; $Functions = new Functions(); if (!isset($_SESSION['manager'])) { header('location: ./admin-auth'); exit(); } $page_title; $page_title = ucfirst(basename(__FILE__, '.php')); if ($page_title === 'index') { $page_title = 'Home'; } $page_title = "Administator's Dashboard"; include 'sections/pages-header.php'; $message = ''; function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } if (isset($_GET['news_id'])) { $sn = $_GET['news_id']; $sql = "DELETE FROM news WHERE sn='$sn'"; if (mysqli_query($con, $sql)) { $message = 'News deleted successfully!'; $_GET['slider_id'] = ''; } else { $message = 'Error deleting picture: ' . mysqli_error($con); } } ?> <div class="container" style="margin-top:50px"> <div> <a href="./mod-auth"><h2>Back to Admin Dashboard</h2></a> </div> <hr> <div> <h1>Add News</h1> <?php if ( $_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['add_news']) ) { $titler = $category = $image = $dater = $ckeditor = ''; $titler = test_input($_POST['titler']); $dater = test_input($_POST['dater']); $category = test_input($_POST['category']); $ckeditor = $_POST['ckeditor']; $file_name = $_FILES['image']['name']; $file_path = 'uploads/news/' . $file_name; move_uploaded_file($_FILES['image']['tmp_name'], $file_path); $feedback = "INSERT INTO news ( titler, contenter, category, dater, image) VALUES ('$titler','$ckeditor','$category','$dater', '$file_name')"; // echo $feedback; // exit(); $run = mysqli_query($con, $feedback); if ($feedback) { echo "<div class='alert alert-success alert-dismissible' role='alert'> News Added Successfully! </div>"; } else { echo "<div class='alert alert-danger alert-dismissible' role='alert'> An error occured, please try again! </div>"; } } ?> <br> <form action="<?php echo htmlspecialchars( $_SERVER['PHP_SELF'] ); ?>" method="post" enctype="multipart/form-data"> <div class="row clearfix"> <div class="col-md-8 col-sm-12 col-xs-12"> <div class="form-group"> <input type="text" name="titler" class="form-control" placeholder="Add news title" required> </div> <div class="form-group"> <input type="text" name="category" class="form-control" placeholder="Add new Category" required> </div> <div class="form-group"> <p>News image Dimension 560 x 581</p> <input type="file" name="image" class="form-control" size="60" placeholder="news caption" required> </div> <div class="form-group"> <input type="date" name="dater" class="form-control" value="2018-07-22" required> </div> <div class="form-group"> <textarea name="ckeditor" class="form-control textarea required" ></textarea> <script> CKEDITOR.replace( 'ckeditor' ); // 850 pixels wide. config.width = '100%'; config.height = '8700px' </script> </div> <div class="form-group"> <input type="submit" name="add_news" value="Add News" class="thm-btn thm-color width-100" style="background-color:#964B00; color:white;border-color:#964B00 ;" /> </div> </div> </div> </form> </div> <hr> <div> <h1>Existing News</h1> <?php if (!empty($message)): ?> <div class='alert alert-danger alert-dismissible show' role="alert"> <?= $message ?> </div> <?php endif; ?> <?php include_once './inc/config.php'; $serial = 0; $sql = 'SELECT * FROM news'; $result = mysqli_query($con, $sql); ?> <table id="example" class="display" style="width:100%"> <thead> <tr> <th>S/N</th> <!-- <th>Images</th> --> <th>Title</th> <th>Date Added</th> <th>Actions</th> <th></th> </tr> </thead> <tbody> <?php if (mysqli_num_rows($result) > 0) { // output data of each row while ($row = mysqli_fetch_assoc($result)) { ?> <tr> <td><?= ++$serial ?></td> <!-- <td><img scr="./uploads/news/<?php // $row['image'] ?>"/></td> --> <td><?= $row['titler'] ?></td> <td><?= $row['dater'] ?></td> <td colspan="2"> <a href="edit-newsevent?news_id=<?= $row[ 'sn' ] ?>" class="btn btn-success">Edit</a> </td> <td><a href="newsevent?news_id=<?= $row[ 'sn' ] ?>" class="btn btn-danger">Delete</a> </td> </tr> <?php } } else { //echo '0 results'; } ?> </tbody> </table> </div> </div> </div> <?php include_once 'sections/footer.php'; ?>