Commit 6d808a55 authored by Vikrant Rajan's avatar Vikrant Rajan
Browse files

Initial commit

parents
Pipeline #146 failed with stages
<?php
Class ConnectToDB {
// connect to DB
// static function is to call function elsewhere without creating an instance of the object/class
var $connect;
public function __construct($connect){
$this->con = $connect;
}
static function con() {
$conDetails = parse_ini_file("/var/www/entguide/entguide.ini");
$connect = mysqli_connect( $conDetails['server'], $conDetails['user'], $conDetails['pass'], $conDetails['db'] );
if(!$connect)
{die('ERROR connecting to DB'.mysqli_connect_error());}
return $connect;
// $oDb = new ConnectToDB($connect);
// return $oDb;
}
}
?>
<?php include("DBentguide/db.php"); ?>
<?php include("includes/header.php"); ?>
<!-- NAVIGATION -->
<?php include("includes/navigation.php"); ?>
<?php include("functions/functions.php"); ?>
<div class="container">
<div class="row aboutus">
<div class="col-lg-8 col-md-8">
<div class="aboutus_graphics">
<h1>About <img src="imgs/logo-06.png" alt=""></h1>
<img class="aboutusgraphic" src="imgs/aboutus.png" alt="">
</div>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quas cum maxime eligendi veniam quibusdam esse
placeat, totam, omnis reiciendis facere assumenda dignissimos cumque quisquam atque autem, sequi
laboriosam
alias velit? Lorem, ipsum dolor sit amet consectetur adipisicing elit. Porro est quisquam minima nemo
corrupti quam tempora commodi quae aliquam neque. Odit temporibus ratione ad blanditiis nam iste
quibusdam
expedita in.</p>
<p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Quas cum maxime eligendi veniam quibusdam esse
placeat, totam, omnis reiciendis facere assumenda dignissimos cumque quisquam atque autem, sequi
laboriosam
alias velit? Lorem, ipsum dolor sit amet consectetur adipisicing elit. Porro est quisquam minima nemo
corrupti quam tempora commodi quae aliquam neque. Odit temporibus ratione ad blanditiis nam iste
quibusdam
expedita in.</p>
</div>
<?php include("includes/sidebar.php"); ?>
</div>
</div>
<?php include("includes/footer.php"); ?>
File added
<!-- /.row -->
<div class="row">
<div class="col-lg-3 col-md-6">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-file-text fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class='huge'>12</div>
<div>Posts</div>
</div>
</div>
</div>
<a href="posts.php">
<div class="panel-footer">
<span class="pull-left">View Details</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-green">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-comments fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class='huge'>23</div>
<div>Comments</div>
</div>
</div>
</div>
<a href="comments.php">
<div class="panel-footer">
<span class="pull-left">View Details</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-yellow">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-user fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class='huge'>23</div>
<div> Users</div>
</div>
</div>
</div>
<a href="users.php">
<div class="panel-footer">
<span class="pull-left">View Details</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
<div class="col-lg-3 col-md-6">
<div class="panel panel-red">
<div class="panel-heading">
<div class="row">
<div class="col-xs-3">
<i class="fa fa-list fa-5x"></i>
</div>
<div class="col-xs-9 text-right">
<div class='huge'>13</div>
<div>Categories</div>
</div>
</div>
</div>
<a href="categories.php">
<div class="panel-footer">
<span class="pull-left">View Details</span>
<span class="pull-right"><i class="fa fa-arrow-circle-right"></i></span>
<div class="clearfix"></div>
</div>
</a>
</div>
</div>
</div>
<!-- /.row -->
\ No newline at end of file
<?php include "includes/admin_header.php" ?>
<div id="wrapper">
<!-- Navigation -->
<?php include "includes/admin_navigation.php" ?>
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
Welcome to Admin
<small><?php echo $_SESSION['user_name']; ?></small>
</h1>
<div class="col-xs-6">
<?php Categories::insertCategories(); ?>
<form action="" method="post">
<div class="form-group">
<label for="cat_title">Add Category</label>
<input type="text" class="form-control" name="cat_title">
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit" value="Add Category">
</div>
</form>
<?php Categories::editCategories(); ?>
</div> <!-- ADD CATEGORY FORM -->
<div class="col-xs-6">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>Category Title</th>
</tr>
</thead>
<tbody>
<?php Categories::findAllCategories(); ?>
<?php Categories::deleteCategories(); ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
<?php include("includes/admin_footer.php"); ?>
\ No newline at end of file
<?php
Class Categories extends QueryCheck
{
public static function insertCategories() {
if(isset($_POST['submit'])) {
$catTitle = $_POST['cat_title'];
if($catTitle == "" || empty($catTitle)) {
echo "<h3>This Field Should Not Be Empty</h3>";
} else {
$query = "INSERT INTO categories(cat_title) ";
$query .= "VALUE('{$catTitle}')";
$createCategory = mysqli_query(ConnectToDB::con(), $query);
if(!$createCategory) {
die("QUERY FAILED" . mysqli_error(ConnectToDB::con()));
}
}
}
}
public static function findAllCategories() {
$query = "SELECT * FROM categories";
$selectCategories = mysqli_query(ConnectToDB::con(), $query);
while($row = mysqli_fetch_assoc($selectCategories)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo "<tr>";
echo "<td>{$cat_id}</td>";
echo "<td>{$cat_title}</td>";
echo "<td><a href='categories.php?edit={$cat_id}'>Edit</a></td>";
echo "<td><a href='categories.php?delete={$cat_id}'>Delete</a></td>";
echo "</tr>";
}
}
public static function deleteCategories() {
if(isset($_GET['delete'])){
$catID = $_GET['delete'];
$query = "DELETE FROM categories WHERE cat_id = {$catID}";
$deleteQuery = mysqli_query(ConnectToDB::con(), $query);
header("Location: categories.php");
}
}
public static function editCategories() {
// UPDATE AND INCLUDE QUERY
if(isset($_GET['edit'])){
$cat_id = $_GET['edit'];
include "includes/update_categories.php";
}
}
public static function updateCategories() {
if(isset($_GET['edit'])){
$cat_id = $_GET['edit'];
$query = "SELECT * FROM categories WHERE cat_id = '{$cat_id}'";
$selectCategoriesID = mysqli_query(ConnectToDB::con(), $query);
while($row = mysqli_fetch_assoc($selectCategoriesID)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
?>
<input value="<?php if(isset($cat_title)){echo $cat_title;} ?> " type="text" class="form-control" name="cat_title">
<?php } }?>
<?php
if(isset($_POST['update_category'])){
$catTitle = $_POST['cat_title'];
$query = "UPDATE categories SET cat_title = '{$catTitle}' WHERE cat_id = {$cat_id} ";
$updateQuery = mysqli_query(ConnectToDB::con(), $query);
header("Location: categories.php");
if(!$updateQuery){
die("QUERY FAILED" . mysqli_error(ConnectToDB::con()));
}
}
}
public static function checkCategoryStatus() {
$query = "SELECT * FROM categories";
$selectCategories = mysqli_query(ConnectToDB::con(), $query);
QueryCheck::confirmQuery($selectCategories);
return $selectCategories;
}
}
?>
\ No newline at end of file
<?php
Class Comments {
public static function pager() {
$comment_query_count = "SELECT * FROM comments";
$find_count = mysqli_query(ConnectToDB::con(), $comment_query_count);
$count = mysqli_num_rows($find_count);
$count = ceil($count / 5);
for($i =1; $i <= $count; $i++) {
echo "<li><a href='comments.php?page={$i}'>{$i}</a></li>";
}
}
public static function showComments() {
if(isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = "";
}
if($page == "" || $page == 1) {
$page_1 = 0;
} else {
$page_1 = ($page * 5) - 5;
}
$query = "SELECT * FROM comments LIMIT $page_1, 5 ";
$select_comments = mysqli_query(ConnectToDB::con(), $query);
while($row = mysqli_fetch_assoc($select_comments)){
$comment_id = $row['comment_id'];
$comment_post_id = $row['comment_post_id'];
$comment_author= $row['comment_author'];
$comment_content = $row['comment_content'];
$comment_email = $row['comment_email'];
$comment_status = $row['comment_status'];
$comment_date = $row['comment_date'];
echo "<tr>";
if($comment_status == 'Approved') {
echo "<td class='text-success bg-success'>{$comment_id}</td>";
echo "<td class='text-success bg-success'>{$comment_author}</td>";
echo "<td class='text-success bg-success'>{$comment_content}</td>";
echo "<td class='text-success bg-success'>{$comment_email}</td>";
echo "<td class='text-success bg-success'>{$comment_status}</td>";
$query = "SELECT * from posts WHERE post_id = $comment_post_id";
$select_post_id_query = mysqli_query(ConnectToDB::con(),$query);
while($row = mysqli_fetch_assoc($select_post_id_query)){
$post_id = $row['post_id'];
$post_title = $row['post_title'];
echo "<td class='text-success bg-success'><a href='../post.php?p_id=$post_id'>$post_title</a></td>";
}
echo "<td class='text-success bg-success'>{$comment_date}</td>";
echo "<td class='text-success bg-success'><a href='comments.php?approve=$comment_id'>Approve</a></td>";
echo "<td class='text-success bg-success'><a href='comments.php?unapprove=$comment_id'>Unapprove</a></td>";
echo "<td class='text-success bg-success'><a onClick=\"javascript: return confirm('Are you sure you want to delete this?');\" href='comments.php?delete=$comment_id'>Delete</a></td>";
echo "</tr>";
} else {
echo "<td>{$comment_id}</td>";
echo "<td>{$comment_author}</td>";
echo "<td>{$comment_content}</td>";
echo "<td>{$comment_email}</td>";
echo "<td>{$comment_status}</td>";
$query = "SELECT * from posts WHERE post_id = $comment_post_id";
$select_post_id_query = mysqli_query(ConnectToDB::con(),$query);
while($row = mysqli_fetch_assoc($select_post_id_query)){
$post_id = $row['post_id'];
$post_title = $row['post_title'];
echo "<td><a href='../post.php?p_id=$post_id'>$post_title</a></td>";
}
echo "<td>{$comment_date}</td>";
echo "<td><a href='comments.php?approve=$comment_id'>Approve</a></td>";
echo "<td><a href='comments.php?unapprove=$comment_id'>Unapprove</a></td>";
echo "<td><a onClick=\"javascript: return confirm('Are you sure you want to delete this?');\" href='comments.php?delete=$comment_id'>Delete</a></td>";
}
echo "</tr>";
}
if(isset($_GET['approve'])){
echo "<p class='text-success bg-success'>Comment Has Been Approved</p>";
} else if(isset($_GET['unapprove'])){
echo "<p class='text-danger bg-danger'>Comment Has Been Unapproved</p>";
}
}
public static function updateComments() {
if(isset($_GET['delete'])){
$the_comment_id = $_GET['delete'];
$query = "DELETE FROM comments WHERE comment_id = {$the_comment_id}";
$delete_query = mysqli_query(ConnectToDB::con(), $query);
if($delete_query) {
echo "<h2>The comment has been deleted</h2>";
}
// header("location: comments.php");
}
if(isset($_GET['unapprove'])){
$the_comment_id = $_GET['unapprove'];
$query = "UPDATE comments SET comment_status = 'Unapproved' WHERE comment_id = $the_comment_id";
$unapprove_comment_query = mysqli_query(ConnectToDB::con(), $query);
// header("location: comments.php");
}
if(isset($_GET['approve'])){
$the_comment_id = $_GET['approve'];
$query = "UPDATE comments SET comment_status = 'Approved' WHERE comment_id = $the_comment_id";
$approve_comment_query = mysqli_query(ConnectToDB::con(), $query);
// header("location: comments.php");
}
}
}
?>
\ No newline at end of file
<?php
Class Posts
{
public static function pager() {
$post_query_count = "SELECT * FROM posts";
$find_count = mysqli_query(ConnectToDB::con(), $post_query_count);
$count = mysqli_num_rows($find_count);
$count = ceil($count / 5);
for($i =1; $i <= $count; $i++) {
echo "<li><a href='posts.php?page={$i}'>{$i}</a></li>";
}
}
public static function showPosts() {
if(isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = "";
}
if($page == "" || $page == 1) {
$page_1 = 0;
} else {
$page_1 = ($page * 5) - 5;
}
$query = "SELECT * FROM posts LIMIT $page_1, 5 ";
$select_posts = mysqli_query(ConnectToDB::con(), $query);
while($row = mysqli_fetch_assoc($select_posts)){
$post_id = $row['post_id'];
$post_author = $row['post_author'];
$post_title = $row['post_title'];
$post_category_id = $row['post_category_id'];
$post_status = $row['post_status'];
$post_image = $row['post_image'];
$post_tags = $row['post_tags'];
$post_comment_count = $row['post_comment_count'];
$post_date = $row['post_date'];
$post_views_count = $row['post_views_count'];
echo "<tr>";
?>
<td><input class='checkBoxes' id='selectAllBoxes' type='checkbox' name='checkBoxArray[]'
value='<?php echo $post_id; ?>'></td>
<?php
if($post_status == 'Published') {
echo "<td class='text-success bg-success'>{$post_id}</td>";
echo "<td class='text-success bg-success'>{$post_author}</td>";
echo "<td class='text-success bg-success'>{$post_title}</td>";
$query = "SELECT * FROM categories WHERE cat_id = '{$post_category_id}'";
$selectCategoriesID = mysqli_query(ConnectToDB::con(), $query);
while($row = mysqli_fetch_assoc($selectCategoriesID)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo "<td class='text-success bg-success'>{$cat_title}</td>";
}
// echo "<td>{$post_category_id}</td>";
echo "<td class='text-success bg-success'>{$post_status}</td>";
echo "<td class='text-success bg-success'><img width='100' src='../imgs/{$post_image}' alt='Entguide'></td>";
echo "<td class='text-success bg-success'>{$post_tags}</td>";
echo "<td class='text-success bg-success'>{$post_comment_count}</td>";
echo "<td class='text-success bg-success'>{$post_date}</td>";
echo "<td class='text-success bg-success'><a onClick=\"javascript: return confirm('Are you sure you want to reset the view count for {$post_title}?');\" href='posts.php?reset={$post_id}'>{$post_views_count}</a></td>";
echo "<td class='text-success bg-success'><a href='../post.php?p_id={$post_id}'>View Post</a></td>";
echo "<td class='text-success bg-success'><a href='posts.php?source=edit_post&p_id={$post_id}'>Edit</a></td>";
echo "<td class='text-success bg-success'><a onClick=\"javascript: return confirm('Are you sure you want to delete this?');\" href='posts.php?delete={$post_id}'>Delete</a></td>";
} else {
echo "<td>{$post_id}</td>";
echo "<td>{$post_author}</td>";
echo "<td>{$post_title}</td>";
$query = "SELECT * FROM categories WHERE cat_id = '{$post_category_id}'";
$selectCategoriesID = mysqli_query(ConnectToDB::con(), $query);
while($row = mysqli_fetch_assoc($selectCategoriesID)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo "<td>{$cat_title}</td>";
}
// echo "<td>{$post_category_id}</td>";
echo "<td>{$post_status}</td>";
echo "<td><img width='100' src='../imgs/{$post_image}' alt='Entguide'></td>";
echo "<td>{$post_tags}</td>";
echo "<td>{$post_comment_count}</td>";
echo "<td>{$post_date}</td>";
echo "<td><a onClick=\"javascript: return confirm('Are you sure you want to reset the view count for {$post_title}?');\" href='posts.php?reset={$post_id}'>{$post_views_count}</a></td>";
echo "<td><a href='../post.php?p_id={$post_id}'>View Post</a></td>";
echo "<td><a href='posts.php?source=edit_post&p_id={$post_id}'>Edit</a></td>";
echo "<td><a onClick=\"javascript: return confirm('Are you sure you want to delete this?');\" href='posts.php?delete={$post_id}'>Delete</a></td>";
}
echo "</tr>";
}
}
public static function bulkCheckPosts()
{
if(isset($_POST['checkBoxArray']))
{
foreach($_POST['checkBoxArray'] as $postIdValue)
{
$bulkOptions = $_POST['bulk_options'];
switch($bulkOptions) {
case 'reset';
// $reset_post_id = $_GET['reset'];
$query = "UPDATE posts SET post_views_count = 0 WHERE post_id =" . mysqli_real_escape_string(ConnectToDB::con(), $postIdValue) . " ";
$reset_query = mysqli_query(ConnectToDB::con(), $query);
QueryCheck::confirmQuery($reset_query);
echo "<p class='text-success bg-success'>Post View Count Reset</p>";
break;
case 'Published';
$query = "UPDATE posts SET post_status = '{$bulkOptions}' WHERE post_id = {$postIdValue} ";
$update_published_status = mysqli_query(ConnectToDB::con(), $query);
QueryCheck::confirmQuery($update_published_status);
echo "<p class='text-success bg-success'>Post Published</p>";
break;
case 'Draft';
$query = "UPDATE posts SET post_status = '{$bulkOptions}' WHERE post_id = {$postIdValue} ";
$update_draft_status = mysqli_query(ConnectToDB::con(), $query);
QueryCheck::confirmQuery($update_draft_status);
echo "<p class='text-success bg-success'>Post Updated</p>";
break;
case 'delete';
$query = "DELETE FROM posts WHERE post_id = {$postIdValue} ";
$delete_status = mysqli_query(ConnectToDB::con(), $query);
QueryCheck::confirmQuery($delete_status);
echo "<p class='text-success bg-success'>Post Deleted</p>";
break;
}
}
}
}
public static function resetPostViews()
{
if(isset($_GET['reset']))
{
// $reset_post_id = $_GET['reset'];
// $query = "UPDATE posts SET post_views_count = 0 WHERE post_id =" . mysqli_real_escape_string(ConnectToDb::con(), $re