update DataBase name
This commit is contained in:
parent
c8b0b098ae
commit
a88d8eddae
13 changed files with 118 additions and 125 deletions
1
activities/Admin/Admin.php
Normal file → Executable file
1
activities/Admin/Admin.php
Normal file → Executable file
|
@ -5,6 +5,7 @@ namespace Admin;
|
|||
use Auth\Auth;
|
||||
|
||||
|
||||
|
||||
class Admin{
|
||||
|
||||
function __construct(){
|
||||
|
|
2
activities/Admin/Banner.php
Normal file → Executable file
2
activities/Admin/Banner.php
Normal file → Executable file
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Admin;
|
||||
|
||||
use database\Database;
|
||||
use database\DataBase;
|
||||
|
||||
class Banner extends Admin{
|
||||
|
||||
|
|
12
activities/Admin/Category.php
Normal file → Executable file
12
activities/Admin/Category.php
Normal file → Executable file
|
@ -2,14 +2,14 @@
|
|||
|
||||
namespace Admin;
|
||||
|
||||
use Database\Database;
|
||||
use Database\DataBase;
|
||||
|
||||
class Category extends Admin{
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
$categories = $db->select("SELECT * FROM categories");
|
||||
require_once (BASE_PATH . '/template/admin/category/index.php');
|
||||
}
|
||||
|
@ -21,28 +21,28 @@ class Category extends Admin{
|
|||
}
|
||||
|
||||
public function store($request){
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
$db->insert('categories', array_keys($request), $request);
|
||||
$this->redirect('admin/category');
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
$category = $db->select("SELECT * FROM categories WHERE id = ?", [$id])->fetch();
|
||||
require_once (BASE_PATH . '/template/admin/category/edit.php');
|
||||
}
|
||||
|
||||
public function update($request, $id)
|
||||
{
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
$db->update('categories', $id, array_keys($request), $request);
|
||||
$this->redirect('admin/category');
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
$db->delete('categories', $id);
|
||||
$this->redirectBack();
|
||||
}
|
||||
|
|
2
activities/Admin/Comment.php
Normal file → Executable file
2
activities/Admin/Comment.php
Normal file → Executable file
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Admin;
|
||||
|
||||
use database\Database;
|
||||
use database\DataBase;
|
||||
|
||||
class Comment extends Admin{
|
||||
|
||||
|
|
0
activities/Admin/Dashboard.php
Normal file → Executable file
0
activities/Admin/Dashboard.php
Normal file → Executable file
2
activities/Admin/Menu.php
Normal file → Executable file
2
activities/Admin/Menu.php
Normal file → Executable file
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Admin;
|
||||
|
||||
use database\Database;
|
||||
use database\DataBase;
|
||||
|
||||
class Menu extends Admin{
|
||||
|
||||
|
|
194
activities/Admin/Post.php
Normal file → Executable file
194
activities/Admin/Post.php
Normal file → Executable file
|
@ -2,119 +2,111 @@
|
|||
|
||||
namespace Admin;
|
||||
|
||||
use Database\Database;
|
||||
use Database\DataBase;
|
||||
|
||||
class Post extends Admin{
|
||||
|
||||
|
||||
public function index()
|
||||
{
|
||||
$db = new Database();
|
||||
$posts = $db->select("SELECT * FROM posts");
|
||||
require_once (BASE_PATH . '/template/admin/post/index.php');
|
||||
}
|
||||
class Post extends Admin
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$db = new DataBase();
|
||||
$posts = $db->select("SELECT * FROM posts");
|
||||
require_once BASE_PATH . '/template/admin/post/index.php';
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$db = new Database();
|
||||
$categories = $db->select('SELECT * FROM categories');
|
||||
require_once (BASE_PATH . '/template/admin/post/create.php');
|
||||
}
|
||||
{
|
||||
$db = new DataBase();
|
||||
$categories = $db->select('SELECT * FROM categories');
|
||||
require_once BASE_PATH . '/template/admin/post/create.php';
|
||||
}
|
||||
|
||||
public function store($request){
|
||||
$realTimestamp = substr($request['published_at'], 0, 10);
|
||||
$request['published_at'] = date("Y-m-d H:i:s", (int)$realTimestamp);
|
||||
$db = new Database();
|
||||
if($request['cat_id'] != null){
|
||||
$request['image'] = $this->saveImage($request['image'], 'post-image');
|
||||
if($request['image']){
|
||||
$request = array_merge($request, ['user_id' => 1]);
|
||||
$db->insert('posts', array_keys($request), $request);
|
||||
$this->redirect('admin/post');
|
||||
}
|
||||
else{
|
||||
$this->redirect('admin/post');
|
||||
}
|
||||
}
|
||||
else{
|
||||
$this->redirect('admin/post');
|
||||
}
|
||||
public function store($request)
|
||||
{
|
||||
$realTimestamp = substr($request['published_at'], 0, 10);
|
||||
$request['published_at'] = date("Y-m-d H:i:s", (int) $realTimestamp);
|
||||
$db = new DataBase();
|
||||
if ($request['cat_id'] != null) {
|
||||
$request['image'] = $this->saveImage($request['image'], 'post-image');
|
||||
if ($request['image']) {
|
||||
$request = array_merge($request, ['user_id' => 1]);
|
||||
$posts = $db->insert('posts', array_keys($request), $request);
|
||||
$this->redirect('admin/post');
|
||||
} else {
|
||||
$this->redirect('admin/post');
|
||||
}
|
||||
} else {
|
||||
$this->redirect('admin/post');
|
||||
}
|
||||
}
|
||||
|
||||
public function edit($id)
|
||||
{
|
||||
$db = new Database();
|
||||
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
|
||||
$categories = $db->select('SELECT * FROM categories');
|
||||
require_once (BASE_PATH . '/template/admin/post/edit.php');
|
||||
}
|
||||
public function edit($id)
|
||||
{
|
||||
$db = new DataBase();
|
||||
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
|
||||
$categories = $db->select('SELECT * FROM categories');
|
||||
require_once BASE_PATH . '/template/admin/post/edit.php';
|
||||
}
|
||||
|
||||
public function update($request, $id)
|
||||
{
|
||||
$realTimestamp = substr($request['published_at'], 0, 10);
|
||||
$request['published_at'] = date("Y-m-d H:i:s", (int)$realTimestamp);
|
||||
$db = new Database();
|
||||
if ($request['cat_id'] != null) {
|
||||
if($request['image']['tmp_name'] != null){
|
||||
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
|
||||
$this->removeImage($post['image']);
|
||||
$request['image'] = $this->saveImage($request['image'], 'post-image');
|
||||
}
|
||||
else{
|
||||
unset($request['image']);
|
||||
}
|
||||
$request = array_merge($request, ['user_id' => 1]);
|
||||
$db->update('posts', $id, array_keys($request), $request);
|
||||
$this->redirect('admin/post');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$db = new Database();
|
||||
public function update($request, $id)
|
||||
{
|
||||
$realTimestamp = substr($request['published_at'], 0, 10);
|
||||
$request['published_at'] = date("Y-m-d H:i:s", (int) $realTimestamp);
|
||||
$db = new DataBase();
|
||||
if ($request['cat_id'] != null) {
|
||||
if ($request['image']['tmp_name'] != null) {
|
||||
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
|
||||
$this->removeImage($post['image']);
|
||||
$db->delete('posts', $id);
|
||||
$this->redirectBack();
|
||||
$request['image'] = $this->saveImage($request['image'], 'post-image');
|
||||
} else {
|
||||
unset($request['image']);
|
||||
}
|
||||
$request = array_merge($request, ['user_id' => 1]);
|
||||
$db->update('posts', $id, array_keys($request), $request);
|
||||
$this->redirect('admin/post');
|
||||
}
|
||||
|
||||
public function breakingNews($id)
|
||||
{
|
||||
$db = new Database();
|
||||
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
|
||||
if(empty($post))
|
||||
{
|
||||
$this->redirectBack();
|
||||
}
|
||||
|
||||
if($post['breaking_news'] == 1) {
|
||||
$db->update('posts', $id, ['breaking_news'], [2]);
|
||||
}
|
||||
else{
|
||||
$db->update('posts', $id, ['breaking_news'], [1]);
|
||||
}
|
||||
$this->redirectBack();
|
||||
}
|
||||
|
||||
public function selected($id)
|
||||
{
|
||||
$db = new Database();
|
||||
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
|
||||
if(empty($post))
|
||||
{
|
||||
$this->redirectBack();
|
||||
}
|
||||
|
||||
if($post['selected'] == 1) {
|
||||
$db->update('posts', $id, ['selected'], [2]);
|
||||
}
|
||||
else{
|
||||
$db->update('posts', $id, ['selected'], [1]);
|
||||
}
|
||||
$this->redirectBack();
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$db = new DataBase();
|
||||
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
|
||||
$this->removeImage($post['image']);
|
||||
$db->delete('posts', $id);
|
||||
$this->redirectBack();
|
||||
}
|
||||
|
||||
public function breakingNews($id)
|
||||
{
|
||||
$db = new DataBase();
|
||||
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
|
||||
if (empty($post)) {
|
||||
$this->redirectBack();
|
||||
}
|
||||
|
||||
if ($post['breaking_news'] == 1) {
|
||||
$db->update('posts', $id, ['breaking_news'], [2]);
|
||||
} else {
|
||||
$db->update('posts', $id, ['breaking_news'], [1]);
|
||||
}
|
||||
$this->redirectBack();
|
||||
}
|
||||
|
||||
}
|
||||
public function selected($id)
|
||||
{
|
||||
$db = new DataBase();
|
||||
$post = $db->select("SELECT * FROM posts WHERE id = ?", [$id])->fetch();
|
||||
if (empty($post)) {
|
||||
$this->redirectBack();
|
||||
}
|
||||
|
||||
if ($post['selected'] == 1) {
|
||||
$db->update('posts', $id, ['selected'], [2]);
|
||||
} else {
|
||||
$db->update('posts', $id, ['selected'], [1]);
|
||||
}
|
||||
$this->redirectBack();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
2
activities/Admin/User.php
Normal file → Executable file
2
activities/Admin/User.php
Normal file → Executable file
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Admin;
|
||||
|
||||
use database\Database;
|
||||
use database\DataBase;
|
||||
|
||||
class User extends Admin{
|
||||
|
||||
|
|
0
activities/Admin/WebSetting.php
Normal file → Executable file
0
activities/Admin/WebSetting.php
Normal file → Executable file
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Auth;
|
||||
|
||||
use Database\Database;
|
||||
use Database\DataBase;
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
|
@ -93,7 +93,7 @@ class Auth
|
|||
flash('register_error', 'The email entered is not valid');
|
||||
$this->redirectBack();
|
||||
} else {
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
$user = $db->select("SELECT * FROM users WHERE email = ?", [$request['email']])->fetch();
|
||||
if ($user != null) {
|
||||
flash('register_error', 'Email already exists');
|
||||
|
@ -120,7 +120,7 @@ class Auth
|
|||
|
||||
public function activation($verifyToken)
|
||||
{
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
$user = $db->select("SELECT * FROM users WHERE verify_token = ? AND is_active = 0", [$verifyToken])->fetch();
|
||||
if ($user == null) {
|
||||
$this->redirect('login');
|
||||
|
@ -141,7 +141,7 @@ class Auth
|
|||
flash('login_error', 'All fields are required');
|
||||
$this->redirectBack();
|
||||
} else {
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
$user = $db->select("SELECT * FROM users WHERE email = ?", [$request['email']])->fetch();
|
||||
if ($user != null) {
|
||||
if (password_verify($request['password'], $user['password']) && $user['is_active'] == 1) {
|
||||
|
@ -162,7 +162,7 @@ class Auth
|
|||
public function checkAdmin()
|
||||
{
|
||||
if (isset($_SESSION['user'])) {
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
$user = $db->select("SELECT * FROM users WHERE id = ?", [$_SESSION['user']])->fetch();
|
||||
if ($user != null) {
|
||||
if ($user['permission'] != 'admin') {
|
||||
|
@ -211,7 +211,7 @@ class Auth
|
|||
flash('forgot_error', 'The entered email is not correct');
|
||||
$this->redirectBack();
|
||||
} else {
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
$user = $db->select("SELECT * FROM users WHERE email = ?", [$request['email']])->fetch();
|
||||
if ($user == null) {
|
||||
flash('forgot_error', 'There is no email entered');
|
||||
|
@ -243,7 +243,7 @@ class Auth
|
|||
flash('reset_error', 'The password must not be less than 8 characters or the password must not be empty');
|
||||
$this->redirectBack();
|
||||
} else {
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
$user = $db->select("SELECT * FROM users WHERE forgot_token = ?", [$forgot_token])->fetch();
|
||||
if ($user == null) {
|
||||
flash('reset_error', 'User with this profile was not found');
|
||||
|
|
|
@ -2,13 +2,13 @@
|
|||
|
||||
namespace App;
|
||||
|
||||
use Database\Database;
|
||||
use Database\DataBase;
|
||||
|
||||
class Home{
|
||||
|
||||
public function index()
|
||||
{
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
|
||||
$setting = $db->select('SELECT * FROM websetting')->fetch();
|
||||
|
||||
|
@ -35,7 +35,7 @@ class Home{
|
|||
public function show($id)
|
||||
{
|
||||
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
|
||||
|
||||
$post =$db->select('SELECT posts.*, (SELECT COUNT(*) FROM comments WHERE comments.post_id = posts.id) AS comments_count, (SELECT username FROM users WHERE users.id = posts.user_id) AS username, (SELECT name FROM categories WHERE categories.id = posts.cat_id) AS category FROM posts WHERE id = ?', [$id])->fetch();
|
||||
|
@ -67,7 +67,7 @@ class Home{
|
|||
{
|
||||
if($_SESSION['user'] != null)
|
||||
{
|
||||
$db = new Database();
|
||||
$db = new DataBase();
|
||||
$db->insert('comments', ['user_id', 'post_id', 'comment'], [$_SESSION['user'], $request['post_id'], $request['comment']]);
|
||||
$this->redirectBack();
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Database;
|
|||
use Exception;
|
||||
use PDO;
|
||||
|
||||
class Database
|
||||
class DataBase
|
||||
{
|
||||
|
||||
private $connection;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
use Database\Database;
|
||||
use Database\DataBase;
|
||||
|
||||
class CreateDB extends Database
|
||||
class CreateDB extends DataBase
|
||||
{
|
||||
|
||||
private $queries = [
|
||||
|
|
Loading…
Reference in a new issue