From 0b68f38125b17c4c2a71abccdc2108968f51cc51 Mon Sep 17 00:00:00 2001 From: Misha Semenov Date: Mon, 18 Nov 2024 13:48:20 +0300 Subject: [PATCH 1/7] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=BA=D1=82=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/models/UserModel.php | 27 ++++++++++++++++++--------- application/views/user/edit.php | 6 +++++- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/application/models/UserModel.php b/application/models/UserModel.php index 8280ad3..ebcded7 100644 --- a/application/models/UserModel.php +++ b/application/models/UserModel.php @@ -67,20 +67,29 @@ public function insert() public function update() { - $sql = "UPDATE $this->tableName SET timestamp=:timestamp, login=:login, pass=:pass, email=:email WHERE id = :id"; + $sql = "UPDATE $this->tableName SET timestamp=:timestamp, login=:login, pass=:pass,salt = :salt,role = :role, email=:email WHERE id = :id"; $st = $this->pdo->prepare ( $sql ); $st->bindValue( ":timestamp", (new \DateTime('NOW'))->format('Y-m-d H:i:s'), \PDO::PARAM_STMT); $st->bindValue( ":login", $this->login, \PDO::PARAM_STR ); + if ($this->pass) + { + // Хеширование пароля + $this->salt = rand(0,1000000); + $st->bindValue( ":salt", $this->salt, \PDO::PARAM_STR ); + $this->pass .= $this->salt; + $hashPass = password_hash($this->pass, PASSWORD_BCRYPT); + $st->bindValue( ":pass", $hashPass, \PDO::PARAM_STR ); + }else { + $sqlPass = "SELECT pass, salt from $this->tableName where id = $this->id"; + $password = $this->pdo->query($sqlPass); + $pass = $password->fetch(); + $st->bindValue( ":pass", $pass['pass'], \PDO::PARAM_STR ); + $st->bindValue( ":salt", $pass['salt'], \PDO::PARAM_STR ); + } + - // Хеширование пароля - $this->salt = rand(0,1000000); - //$st->bindValue( ":salt", $this->salt, \PDO::PARAM_STR ); - //$this->pass .= $this->salt; - //$hashPass = password_hash($this->pass, PASSWORD_BCRYPT); - $st->bindValue( ":pass", $this->pass, \PDO::PARAM_STR ); - - //$st->bindValue( ":role", $this->role, \PDO::PARAM_STR ); + $st->bindValue( ":role", $this->role, \PDO::PARAM_STR ); $st->bindValue( ":email", $this->email, \PDO::PARAM_STR ); $st->bindValue( ":id", $this->id, \PDO::PARAM_INT ); $st->execute(); diff --git a/application/views/user/edit.php b/application/views/user/edit.php index dccb87c..e3fc84d 100644 --- a/application/views/user/edit.php +++ b/application/views/user/edit.php @@ -23,7 +23,11 @@
Введите e-mail

- +
Выберите роль юзера
+
From 419195fd2bb8ea2b14263eaa306ec650b029523c Mon Sep 17 00:00:00 2001 From: Misha Semenov Date: Mon, 2 Dec 2024 20:53:40 +0300 Subject: [PATCH 2/7] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=20CMS=20=D0=BD=D0=B0=20MVC=20(=D0=BD=D0=B5=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BB=D0=BD=D1=8B=D0=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 3 - application/CMSviews/admin/admin.php | 88 +++++ application/CMSviews/admin/edit/article.php | 79 ++++ application/CMSviews/admin/edit/category.php | 40 ++ .../CMSviews/admin/edit/subcategory.php | 35 ++ application/CMSviews/admin/edit/user.php | 42 +++ application/CMSviews/admin/listCategories.php | 33 ++ .../CMSviews/admin/listSubcategories.php | 35 ++ application/CMSviews/admin/listUsers.php | 42 +++ application/{views => CMSviews}/error.php | 5 +- application/CMSviews/homepage/archive.php | 41 ++ application/CMSviews/homepage/homepage.php | 78 ++++ .../CMSviews/homepage/singleArticle.php | 15 + .../CMSviews/layouts/includes/adminHeader.php | 11 + .../CMSviews/layouts/includes/footer.php | 8 + .../CMSviews/layouts/includes/header.php | 15 + application/CMSviews/layouts/main.php | 18 + application/CMSviews/login/loginForm.php | 29 ++ application/config/web.php | 17 +- application/controllers/AdminController.php | 137 +++++++ application/controllers/AjaxController.php | 17 - application/controllers/ErrorController.php | 2 +- application/controllers/HelloController.php | 28 -- .../controllers/HomepageController.php | 142 ++++++- application/controllers/LoginController.php | 57 +-- .../admin/AdminusersController.php | 128 ------- .../controllers/admin/NotesController.php | 130 ------- application/models/AllUsers.php | 37 ++ application/models/Article.php | 175 +++++++++ application/models/AuthUser.php | 39 -- application/models/BaseExampleModel.php | 25 -- application/models/Category.php | 59 +++ application/models/Connection.php | 42 +++ application/models/Note.php | 49 --- application/models/Subcategory.php | 91 +++++ application/models/User.php | 55 +++ application/models/UserModel.php | 140 ------- application/views/homepage/index.php | 15 - application/views/layouts/admin-main.php | 19 - .../views/layouts/includes/admin-main/nav.php | 49 --- .../views/layouts/includes/main/footer.php | 17 - .../views/layouts/includes/main/head.php | 19 - .../views/layouts/includes/main/nav.php | 48 --- application/views/layouts/main.php | 19 - application/views/login/index.php | 21 -- application/views/note/add.php | 25 -- application/views/note/delete.php | 17 - application/views/note/edit.php | 31 -- .../views/note/includes/admin-notes-nav.php | 24 -- application/views/note/index.php | 36 -- application/views/note/view-item.php | 24 -- application/views/user/add.php | 29 -- application/views/user/delete.php | 17 - application/views/user/edit.php | 34 -- .../views/user/includes/admin-users-nav.php | 24 -- application/views/user/index.php | 40 -- application/views/user/view-item.php | 18 - web/CSS/CMSstyle.css | 353 ++++++++++++++++++ web/JS/loaderIdentity.js | 15 + web/JS/showContent.js | 68 ++++ web/ajax/loadArticle.js | 28 ++ web/ajax/loadArticle.php | 4 + web/ajax/showContentsHandler.php | 30 ++ web/images/logo.jpg | Bin 0 -> 11734 bytes 64 files changed, 1857 insertions(+), 1154 deletions(-) create mode 100644 application/CMSviews/admin/admin.php create mode 100644 application/CMSviews/admin/edit/article.php create mode 100644 application/CMSviews/admin/edit/category.php create mode 100644 application/CMSviews/admin/edit/subcategory.php create mode 100644 application/CMSviews/admin/edit/user.php create mode 100644 application/CMSviews/admin/listCategories.php create mode 100644 application/CMSviews/admin/listSubcategories.php create mode 100644 application/CMSviews/admin/listUsers.php rename application/{views => CMSviews}/error.php (97%) create mode 100644 application/CMSviews/homepage/archive.php create mode 100644 application/CMSviews/homepage/homepage.php create mode 100644 application/CMSviews/homepage/singleArticle.php create mode 100644 application/CMSviews/layouts/includes/adminHeader.php create mode 100644 application/CMSviews/layouts/includes/footer.php create mode 100644 application/CMSviews/layouts/includes/header.php create mode 100644 application/CMSviews/layouts/main.php create mode 100644 application/CMSviews/login/loginForm.php create mode 100644 application/controllers/AdminController.php delete mode 100644 application/controllers/AjaxController.php delete mode 100644 application/controllers/HelloController.php delete mode 100644 application/controllers/admin/AdminusersController.php delete mode 100644 application/controllers/admin/NotesController.php create mode 100644 application/models/AllUsers.php create mode 100644 application/models/Article.php delete mode 100644 application/models/AuthUser.php delete mode 100644 application/models/BaseExampleModel.php create mode 100644 application/models/Category.php create mode 100644 application/models/Connection.php delete mode 100644 application/models/Note.php create mode 100644 application/models/Subcategory.php create mode 100644 application/models/User.php delete mode 100644 application/models/UserModel.php delete mode 100644 application/views/homepage/index.php delete mode 100644 application/views/layouts/admin-main.php delete mode 100644 application/views/layouts/includes/admin-main/nav.php delete mode 100644 application/views/layouts/includes/main/footer.php delete mode 100644 application/views/layouts/includes/main/head.php delete mode 100644 application/views/layouts/includes/main/nav.php delete mode 100644 application/views/layouts/main.php delete mode 100644 application/views/login/index.php delete mode 100644 application/views/note/add.php delete mode 100644 application/views/note/delete.php delete mode 100644 application/views/note/edit.php delete mode 100644 application/views/note/includes/admin-notes-nav.php delete mode 100644 application/views/note/index.php delete mode 100644 application/views/note/view-item.php delete mode 100644 application/views/user/add.php delete mode 100644 application/views/user/delete.php delete mode 100644 application/views/user/edit.php delete mode 100644 application/views/user/includes/admin-users-nav.php delete mode 100644 application/views/user/index.php delete mode 100644 application/views/user/view-item.php create mode 100644 web/CSS/CMSstyle.css create mode 100644 web/JS/loaderIdentity.js create mode 100644 web/JS/showContent.js create mode 100644 web/ajax/loadArticle.js create mode 100644 web/ajax/loadArticle.php create mode 100644 web/ajax/showContentsHandler.php create mode 100644 web/images/logo.jpg diff --git a/.vscode/launch.json b/.vscode/launch.json index 9dc6b4d..49de5b8 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,7 +1,4 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { diff --git a/application/CMSviews/admin/admin.php b/application/CMSviews/admin/admin.php new file mode 100644 index 0000000..ac55955 --- /dev/null +++ b/application/CMSviews/admin/admin.php @@ -0,0 +1,88 @@ +

All Articles

+ + +
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
Publication DateArticleCategorySubcategoryAuthorsActive
publicationDate)?> + title?> + + + + + + + categoryId)) { + echo $results['categories'][$article->categoryId]->name; + } + else { + echo "Без категории"; + }?> + + subcategoryId)){ + echo $results['subcategories'][$article->subcategoryId]->name; + } + ?> + + authors); + $counter = 0; + foreach ($article->authors as $key => $author) { + ?> + + + + activeArticle) { + echo 'Active'; + } else { + echo 'Not active'; + } + ?> +
+ +

article in total.

+ +

Add a New Article

+ + \ No newline at end of file diff --git a/application/CMSviews/admin/edit/article.php b/application/CMSviews/admin/edit/article.php new file mode 100644 index 0000000..2fd4913 --- /dev/null +++ b/application/CMSviews/admin/edit/article.php @@ -0,0 +1,79 @@ +

+ +
+ + +
+ + +
    +
  • + + +
  • + +
  • + + +
  • + +
  • + + +
  • + +
  • + + +
  • + +
  • + + +
  • +
  • + + +
  • +
  • + + " /> +
  • + +
  • + + > +
  • +
+ +
+ + +
+
+ +id) { ?> +

+ Delete This Article + +

+ \ No newline at end of file diff --git a/application/CMSviews/admin/edit/category.php b/application/CMSviews/admin/edit/category.php new file mode 100644 index 0000000..e76a837 --- /dev/null +++ b/application/CMSviews/admin/edit/category.php @@ -0,0 +1,40 @@ +

+ +
+ + + + +
+ + +
    + +
  • + + +
  • + +
  • + + +
  • + +
+ +
+ + +
+ +
+ + id ) { ?> +

+ Delete This Category + +

+ + + + diff --git a/application/CMSviews/admin/edit/subcategory.php b/application/CMSviews/admin/edit/subcategory.php new file mode 100644 index 0000000..0fbabf4 --- /dev/null +++ b/application/CMSviews/admin/edit/subcategory.php @@ -0,0 +1,35 @@ +

Article Subcategories

+ + +
+ + + + +
+ + + + + + + + + + + + + + + + + +
Subcategory nameCategory name
+ name ?> + + cat_name ?> +
+ +

categor in total.

+ +

Add a New Subcategory

diff --git a/application/CMSviews/admin/edit/user.php b/application/CMSviews/admin/edit/user.php new file mode 100644 index 0000000..d4d02ae --- /dev/null +++ b/application/CMSviews/admin/edit/user.php @@ -0,0 +1,42 @@ +

Users

+ + +
+ + + + +
+ + + + + + + + + + + + + + + + + + +
Имя пользователяАктивность
+ name?> + + active){ + echo 'Активен'; + }else{ + echo 'Неактивен'; + } + ?> +
+ +

user in total.

+ +

Add a New User

\ No newline at end of file diff --git a/application/CMSviews/admin/listCategories.php b/application/CMSviews/admin/listCategories.php new file mode 100644 index 0000000..15015dd --- /dev/null +++ b/application/CMSviews/admin/listCategories.php @@ -0,0 +1,33 @@ +

Article Categories

+ + +
+ + + + +
+ + + + + + + + + + + + + + + +
Category
+ name?> +
+ +

category in total.

+ +

Add a New Category

+ + diff --git a/application/CMSviews/admin/listSubcategories.php b/application/CMSviews/admin/listSubcategories.php new file mode 100644 index 0000000..7560e39 --- /dev/null +++ b/application/CMSviews/admin/listSubcategories.php @@ -0,0 +1,35 @@ +

Article Subcategories

+ + +
+ + + + +
+ + + + + + + + + + + + + + + + + +
Subcategory nameCategory name
+ name ?> + + cat_name ?> +
+ +

categor in total.

+ +

Add a New Subcategory

\ No newline at end of file diff --git a/application/CMSviews/admin/listUsers.php b/application/CMSviews/admin/listUsers.php new file mode 100644 index 0000000..d4d02ae --- /dev/null +++ b/application/CMSviews/admin/listUsers.php @@ -0,0 +1,42 @@ +

Users

+ + +
+ + + + +
+ + + + + + + + + + + + + + + + + + +
Имя пользователяАктивность
+ name?> + + active){ + echo 'Активен'; + }else{ + echo 'Неактивен'; + } + ?> +
+ +

user in total.

+ +

Add a New User

\ No newline at end of file diff --git a/application/views/error.php b/application/CMSviews/error.php similarity index 97% rename from application/views/error.php rename to application/CMSviews/error.php index c8a5e74..1bbfb76 100644 --- a/application/views/error.php +++ b/application/CMSviews/error.php @@ -1,4 +1,3 @@ - @@ -14,6 +13,4 @@ - - - + \ No newline at end of file diff --git a/application/CMSviews/homepage/archive.php b/application/CMSviews/homepage/archive.php new file mode 100644 index 0000000..a945b13 --- /dev/null +++ b/application/CMSviews/homepage/archive.php @@ -0,0 +1,41 @@ + + +

+ + +

description ) ?>

+ + + + +

article in total.

+ +

Return to Homepage

+ \ No newline at end of file diff --git a/application/CMSviews/homepage/homepage.php b/application/CMSviews/homepage/homepage.php new file mode 100644 index 0000000..dbdfb59 --- /dev/null +++ b/application/CMSviews/homepage/homepage.php @@ -0,0 +1,78 @@ + +

+ Article Archive + +

+ + diff --git a/application/CMSviews/homepage/singleArticle.php b/application/CMSviews/homepage/singleArticle.php new file mode 100644 index 0000000..e175ae5 --- /dev/null +++ b/application/CMSviews/homepage/singleArticle.php @@ -0,0 +1,15 @@ +

+
+
+
Authors:
+

Published on + + + in subcategory + + name) ?> + + +

+ +

Вернуться на главную страницу

\ No newline at end of file diff --git a/application/CMSviews/layouts/includes/adminHeader.php b/application/CMSviews/layouts/includes/adminHeader.php new file mode 100644 index 0000000..9e894e7 --- /dev/null +++ b/application/CMSviews/layouts/includes/adminHeader.php @@ -0,0 +1,11 @@ +
+

Widget News Admin

+

You are logged in as userName ?>. + Edit Articles + Edit Categories + Edit Subcategories + Edit Users + Log out + +

+
diff --git a/application/CMSviews/layouts/includes/footer.php b/application/CMSviews/layouts/includes/footer.php new file mode 100644 index 0000000..4750cc1 --- /dev/null +++ b/application/CMSviews/layouts/includes/footer.php @@ -0,0 +1,8 @@ + + + + + diff --git a/application/CMSviews/layouts/includes/header.php b/application/CMSviews/layouts/includes/header.php new file mode 100644 index 0000000..d8bb1ff --- /dev/null +++ b/application/CMSviews/layouts/includes/header.php @@ -0,0 +1,15 @@ + + + + <?php echo $title?> + + + + + + +
+ + + + \ No newline at end of file diff --git a/application/CMSviews/layouts/main.php b/application/CMSviews/layouts/main.php new file mode 100644 index 0000000..45a867a --- /dev/null +++ b/application/CMSviews/layouts/main.php @@ -0,0 +1,18 @@ + + +username && + $User->username != 'guest' && + preg_match('/Admin/', $_GET['route']) ==1){ + include "includes/adminHeader.php"; + } + } +?> + + \ No newline at end of file diff --git a/application/CMSviews/login/loginForm.php b/application/CMSviews/login/loginForm.php new file mode 100644 index 0000000..e63cf6c --- /dev/null +++ b/application/CMSviews/login/loginForm.php @@ -0,0 +1,29 @@ + +
+ + + +
+ + +
    + +
  • + + +
  • + +
  • + + +
  • + +
+ +
+ +
+ +
+ + diff --git a/application/config/web.php b/application/config/web.php index 744d79f..eff5f9f 100644 --- a/application/config/web.php +++ b/application/config/web.php @@ -5,18 +5,18 @@ $config = [ 'core' => [ // подмассив используемый самим ядром фреймворка 'db' => [ - 'dns' => 'mysql:host=localhost;dbname=dbname', - 'username' => 'root', - 'password' => '1234' + 'dns' => 'mysql:host=localhost;dbname=db_cms', + 'username' => 'myuser', + 'password' => '12345' ], 'router' => [ // подсистема маршрутизация 'class' => \ItForFree\SimpleMVC\Router\WebRouter::class, - 'alias' => '@router' + 'alias' => '@router', ], 'mvc' => [ // настройки MVC 'views' => [ - 'base-template-path' => '../application/views/', - 'base-layouts-path' => '../application/views/layouts/', + 'base-template-path' => '../application/CMSviews/', + 'base-layouts-path' => '../application/CMSviews/layouts/', 'footer-path' => '', 'header-path' => '' ] @@ -28,7 +28,7 @@ => \application\handlers\UserExceptionHandler::class ], 'user' => [ // подсистема авторизации - 'class' => \application\models\AuthUser::class, + 'class' => \application\models\User::class, 'construct' => [ 'session' => '@session', 'router' => '@router' @@ -37,7 +37,8 @@ 'session' => [ // подсистема работы с сессиями 'class' => ItForFree\SimpleMVC\Session::class, 'alias' => '@session' - ] + ], + 'homepageNumArticles' => 5 ] ]; diff --git a/application/controllers/AdminController.php b/application/controllers/AdminController.php new file mode 100644 index 0000000..051ec39 --- /dev/null +++ b/application/controllers/AdminController.php @@ -0,0 +1,137 @@ +Article = new Article; + $this->Category = new Category; + $this->Subcategory = new Subcategory; + $this->Users = new AllUsers; + $this->Connection = new Connection; + } + protected function getArticles(){ + $this->articlesData = $this->Article->getList(); + $this->results['articles'] = $this->articlesData['results']; + $this->results['totalRows'] = $this->artcilesData['totalRows']; + $this->articlesData = $this->Subcategory->getList(); + $this->results['subcategories'] = array(); + foreach($this->results['subcategories'] as $subcategory){ + $this->results['subcategories'][$subcategory->id] = $subcategory; + $this->results['categories'] [$subcategory->id] = $this->Category->getById($subcategory->cat_id); + } + } + public function indexAction(){ + $this->initModelObjects(); + $this->getArticles(); + $this->view->addVar('title', $this->title); + $this->view->addVar('results', $this->results); + $this->view->render('admin/admin.php'); + } + public function viewArticleAction(){ + $this->articlesData['id'] = $_GET['articleId']; + $Article = new Article(); + $SingleArticle = $Article->getById($this->articlesData['id']); + $this->title = $SingleArticle->title . ' | ' . $this->title; + $this->results['article']['id'] = $SingleArticle->id; + $this->results['article']['title'] = $SingleArticle->title; + $this->results['article']['publicationDate'] = $SingleArticle->publicationDate; + $this->results['article']['subcategoryId'] = $SingleArticle->subcategoryId; + $this->results['article']['summary'] = $SingleArticle->summary; + $this->results['article']['content'] = $SingleArticle->content; + $this->results['article']['active'] = $SingleArticle->active; + $this->view->addVar('results', $this->results); + $this->view->addVar('title', $this->title); + $this->view->render('singleArticle/singleArticle.php'); + + } + public function listCategoriesAction(){ + $this->initModelObjects(); + $data = $this->Category->getList(); + $this->results['categories'] = $data['results']; + $this->results['totalRows'] = $data['totalRows']; + $this->results['pageTitle'] = "List of categories"; + $this->title = $this->results['pageTitle']; + $this->view->addVar('title', $this->title); + if (isset($_GET['error'])) { + if ($_GET['error'] == "categoryNotFound") + $this->results['errorMessage'] = "Error: Category not found."; + if ($_GET['error'] == "categoryContainsArticles") + $this->results['errorMessage'] = "Error: Category contains subcategories. " + . "Delete the subcategories, or assign them to another category, " + . "before deleting this category."; + } + + if (isset($_GET['status'])) { + if ($_GET['status'] == "changesSaved") + $this->results['statusMessage'] = "Your changes have been saved."; + if ($_GET['status'] == "categoryDeleted") + $this->results['statusMessage'] = "Category deleted."; + } + $this->view->addVar('results',$this->results); + $this->view->render('admin/listCategories.php'); + } + public function listSubcategoriesAction(){ + $this->initModelObjects(); + $data = $this->Subcategory->getList(); + $this->results['subcategories'] = $data['results']; + $this->results['totalRows'] = $data['totalRows']; + $this->results['pageTitle'] = "List of subcategories"; + $this->title = $this->results['pageTitle']; + $this->view->addVar('title',$this->title); + foreach ($this->results['subcategories'] as $subcategory) { + $category = $this->Category->getById($subcategory->cat_id); + $subcategory->cat_name = $category->name; + } + if (isset($_GET['error'])){ + if ($_GET['error'] == "subcategoryNotFound") + $this->results['errorMessage'] = "Error: Subcategory not found."; + if ($_GET['error'] == "subcategoryContainsArticles") + $this->results['errorMEssage'] = "Error: Subcategory contains articles"; + } + if (isset($_GET['status'])){ + if ($_GET['status'] == "changesSaved") + $this->results['statusMessage'] = "Your changes have been saved."; + if ($_GET['status'] == "subcategoryDeleted") + $this->results['statusMessage'] = "Subcategory deleted"; + } + $this->view->addVar('results', $this->results); + $this->view->render('admin/listSubcategory.php'); + } + public function listUsersAction(){ + $this->initModelObjects(); + $data = $this->Users->getList(); + $this->results['users'] = $data['results']; + $this->results['totalRows'] = $data['totalRows']; + $this->results['pageTitle'] = "User list"; + $this-> title = $this->results['pageTitle']; + $this->view->addVar('title',$this->title); + if (isset($_GET['error'])){ + if ($_GET['error'] == "userNotFound") + $this->results['errorMessage'] = "Error: User not found."; + if ($_GET['error'] == "userExist") + $this->results['errorMessage'] = "Error: User with such name is alredy exist."; + } + if (isset($_GET['status'])){ + if ($_GET['status'] == "changesSaved") + $this->results['statusMessage'] = "Your changes have been saved."; + if ($_GET['status'] == "subcategoryDeleted") + $this->results['statusMessage'] = "Subcategory deleted"; + } + $this->view->addVar('results', $this->results); + $this->view->render('admin/listUsers.php'); + } +} + + diff --git a/application/controllers/AjaxController.php b/application/controllers/AjaxController.php deleted file mode 100644 index 0d0f752..0000000 --- a/application/controllers/AjaxController.php +++ /dev/null @@ -1,17 +0,0 @@ -view->addVar('message', $exception->getMessage()); $this->view->render('error.php'); } -} +} \ No newline at end of file diff --git a/application/controllers/HelloController.php b/application/controllers/HelloController.php deleted file mode 100644 index 5a350dd..0000000 --- a/application/controllers/HelloController.php +++ /dev/null @@ -1,28 +0,0 @@ -Article = new Article; + $this->Category = new Category; + $this->Subcategory = new Subcategory; + $this->Connection = new Connection(); + $this->Users = new AllUsers(); + } + protected function getArticles() + { + $this->results['articles'] = $this->articlesData['results']; + $this->results['totalRows'] = $this->articlesData['totalRows']; + $this->articlesData = $this->Subcategory->getList(); + $this->results['subcategories'] = array(); + foreach ( $this->articlesData['results'] as $subcategory ) { + $this->results['subcategories'][$subcategory->id] = $subcategory; + $this->results['categories'][$subcategory->id] = $this->Category-> + getById($subcategory->cat_id); + } + } public function indexAction() { - $this->view->addVar('homepageTitle', $this->homepageTitle); // передаём переменную по view - $this->view->render('homepage/index.php'); + $this->initModelObjects(); + $this->articlesData = $this->Article->getList(Config::get('core.homepageNumArticles')); + $this->getArticles(); + foreach ($this->results['articles'] as $article) + { + $article->content = substr($article->content,0,100) . ' ...'; + } + $this->view->addVar('title',$this->title); + $this->view->addVar('results', $this->results); + $this->view->render('homepage/homepage.php'); + } + + public function viewArticleAction(){ + $this->initModelObjects(); + $this->articlesData['id'] = $_GET['articleId']; + $SingleArticle = $this->Article->getById($this->articlesData['id']); + $this->title = $SingleArticle->title . ' | ' . $this->title; + $this->results['article']['id'] = $SingleArticle->id; + $this->results['article']['title'] = $SingleArticle->title; + $this->results['article']['publicationDate'] = $SingleArticle->publicationDate; + $this->results['article']['subcategoryId'] = $SingleArticle->subcategoryId; + $this->results['article']['summary'] = $SingleArticle->summary; + $this->results['article']['content'] = $SingleArticle->content; + $this->results['article']['active'] = $SingleArticle->active; + $this->results['article']['subcategory'] = $this->Subcategory->getById( + $this->results['article']['subcategoryId']); + $connections = $this->Connection->getById($this->results['article']['id']); + $connectionsCount = count($connections); + + foreach ($connections as $connection) + { + $userId = $connection->user_id; + $this->results['authors'][] = $this->User->getById($userId)->name; + } + $this->view->addVar('article', $SingleArticle); + $this->view->addVar('results', $this->results); + $this->view->addVar('title', $this->title); + $this->view->render('homepage/singleArticle.php'); + + } + + public function archiveAction(){ + $this->initModelObjects(); + $this->articlesData = $this->Article->getList(100000); + $this->getArticles(); + $this->results['category'] = 0; + $this->results['subcategory'] = 0; + $this->results['pageHeading'] = "Article Archive"; + $this->title = $this->results['pageHeading'] . " | Widget News"; + + $this->view->addVar('title', $this->title); + $this->view->addVar('results', $this->results); + /*Передаем также объект категории т.к. его методы унаследованы от + * родительского класса model и не являются статическими*/ + $this->view->addVar('Category', $this->Category); + $this->view->render('homepage/archive.php'); + } + public function archiveCatAction() { + $this->initModelObjects(); + $subcategoryId = ( isset( $_GET['subcategoryId'] ) && + $_GET['subcategoryId'] ) ? (int)$_GET['subcategoryId'] : null; + $this->results['subcategory'] = $this->Subcategory->getById($subcategoryId); + $this->results['category'] = $this->Category->getById( + $this->results['subcategory']->cat_id); + $data = $this->Subcategory->getList(100000,$this->results['subcategory']->cat_id); + $articleArr = array(); + foreach($data['results'] as $subcategory){ + $articleArr[] = $this->Article->getList(100000, $subcategory->id, true); + } + $this->results['articles'] = array(); + $this->results['totalRows'] = 0; + for( $i = 0; $i < count($articleArr); $i++){ + $this->results['articles'] = array_merge($this->results['articles'], + $articleArr[$i]['results']); + $this->results['totalRows'] = $this->results['totalRows'] + + $articleArr[$i]['totalRows']; + } + if($this->results['category']){ + $this->results['pageHeading'] = $this->results['category']->name; + $this->title = $this->results['category']->name; + }else{ + $this->results['pageHeading'] = "Article Archive"; + } + $this->view->addVar('title', $this->title); + $this->view->addVar('results', $this->results); + $this->view->addVar('Category', $this->Category); + $this->view->render('homepage/archive.php'); } } - diff --git a/application/controllers/LoginController.php b/application/controllers/LoginController.php index 6869896..5a1b76b 100644 --- a/application/controllers/LoginController.php +++ b/application/controllers/LoginController.php @@ -1,57 +1,38 @@ true, 'roles' => ['?'], 'actions' => ['login']], - ['allow' => true, 'roles' => ['@'], 'actions' => ['logout']], - ]; - - /** - * Вход в систему / Выводит на экран форму для входа в систему - */ - public function loginAction() - { - if (!empty($_POST)) { + public $layoutPath = 'main.php'; + public $title = 'Admin Login'; + public $errorMessage = 'Неправильный логин или пароль'; + public function loginAction() { + $User = Config::getObject('core.user.class'); + if ($User->userName != null && $User->userName != 'guest'){ + $this->redirect(Url::link("CMSAdmin/index")); + }elseif (!empty($_POST)) { $login = $_POST['userName']; $pass = $_POST['password']; - $User = Config::getObject('core.user.class'); if($User->login($login, $pass)) { - $this->redirect(WebRouter::link("homepage/index")); - } - else { - $this->redirect(WebRouter::link("login/login&auth=deny")); + $this->redirect(Url::link("CMSAdmin/index")); + } else { + $this->redirect(Url::link("CMSLogin/login&auth=deny")); } } else { - $this->view->addVar('loginTitle', $this->loginTitle); - $this->view->render('login/index.php'); + $this->view->addVar('errorMessage', $this->errorMessage); + $this->view->addVar('title', $this->title); + $this->view->render('login/loginForm.php'); } } - - /** - * Выход из системы - */ - public function logoutAction() + public function logoutAction() { $User = Config::getObject('core.user.class'); $User->logout(); - $this->redirect(WebRouter::link("login/login")); + $this->redirect(Url::link("CMSLogin/login")); } + } - - diff --git a/application/controllers/admin/AdminusersController.php b/application/controllers/admin/AdminusersController.php deleted file mode 100644 index c0c4d27..0000000 --- a/application/controllers/admin/AdminusersController.php +++ /dev/null @@ -1,128 +0,0 @@ - true, 'roles' => ['admin']], - ['allow' => false, 'roles' => ['?', '@']], - ]; - - /** - * Основное действие контроллера - */ - public function indexAction() - { - $Adminusers = new UserModel(); - $userId = $_GET['id'] ?? null; - - if ($userId) { // если указан конктреный пользователь - $viewAdminusers = $Adminusers->getById($_GET['id']); - $this->view->addVar('viewAdminusers', $viewAdminusers); - $this->view->render('user/view-item.php'); - } else { // выводим полный список - - $users = $Adminusers->getList()['results']; - $this->view->addVar('users', $users); - $this->view->render('user/index.php'); - } - } - - /** - * Создание нового пользователя - */ - public function addAction() - { - $Url = Config::get('core.router.class'); - if (!empty($_POST)) { - if (!empty($_POST['saveNewUser'])) { - $Adminusers = new UserModel(); - $newAdminusers = $Adminusers->loadFromArray($_POST); - $newAdminusers->insert(); - $this->redirect($Url::link("admin/adminusers/index")); - } - elseif (!empty($_POST['cancel'])) { - $this->redirect($Url::link("admin/adminusers/index")); - } - } else { - $addAdminusersTitle = "Регистрация пользователя"; - $this->view->addVar('addAdminusersTitle', $addAdminusersTitle); - - $this->view->render('user/add.php'); - } - } - - /** - * Редактирование пользователя - */ - public function editAction() - { - $id = $_GET['id']; - $Url = Config::get('core.router.class'); - - if (!empty($_POST)) { // это выполняется нормально. - - if (!empty($_POST['saveChanges'] )) { - $Adminusers = new UserModel(); - $newAdminusers = $Adminusers->loadFromArray($_POST); - $newAdminusers->update(); - $this->redirect($Url::link("admin/adminusers/index&id=$id")); - } - elseif (!empty($_POST['cancel'])) { - $this->redirect($Url::link("admin/adminusers/index&id=$id")); - } - } else { - $Adminusers = new UserModel(); - $viewAdminusers = $Adminusers->getById($id); - - $editAdminusersTitle = "Редактирование данных пользователя"; - - $this->view->addVar('viewAdminusers', $viewAdminusers); - $this->view->addVar('editAdminusersTitle', $editAdminusersTitle); - - $this->view->render('user/edit.php'); - } - - } - - /** - * Удаление пользователя - */ - public function deleteAction() - { - $id = $_GET['id']; - $Url = Config::get('core.router.class'); - - if (!empty($_POST)) { - if (!empty($_POST['deleteUser'])) { - $Adminusers = new UserModel(); - $newAdminusers = $Adminusers->loadFromArray($_POST); - $newAdminusers->delete(); - - $this->redirect($Url::link("admin/adminusers/index")); - - } - elseif (!empty($_POST['cancel'])) { - $this->redirect($Url::link("admin/adminusers/edit&id=$id")); - } - } else { - - $Adminusers = new UserModel(); - $deletedAdminusers = $Adminusers->getById($id); - $deleteAdminusersTitle = "Удаление статьи"; - - $this->view->addVar('deleteAdminusersTitle', $deleteAdminusersTitle); - $this->view->addVar('deletedAdminusers', $deletedAdminusers); - - $this->view->render('user/delete.php'); - } - } -} diff --git a/application/controllers/admin/NotesController.php b/application/controllers/admin/NotesController.php deleted file mode 100644 index b3865f8..0000000 --- a/application/controllers/admin/NotesController.php +++ /dev/null @@ -1,130 +0,0 @@ -getById($_GET['id']); - $this->view->addVar('viewNotes', $viewNotes); - $this->view->render('note/view-item.php'); - } else { // выводим полный список - - $notes = $Note->getList()['results']; - $this->view->addVar('notes', $notes); - $this->view->render('note/index.php'); - } - } - - /** - * Выводит на экран форму для создания новой статьи (только для Администратора) - */ - public function addAction() - { - $Url = Config::get('core.router.class'); - if (!empty($_POST)) { - if (!empty($_POST['saveNewNote'])) { - $Note = new Note(); - $newNotes = $Note->loadFromArray($_POST); - $newNotes->insert(); - $this->redirect($Url::link("admin/notes/index")); - } - elseif (!empty($_POST['cancel'])) { - $this->redirect($Url::link("admin/notes/index")); - } - } - else { - $addNoteTitle = "Добавление новой заметки"; - $this->view->addVar('addNoteTitle', $addNoteTitle); - - $this->view->render('note/add.php'); - } - } - - /** - * Выводит на экран форму для редактирования статьи (только для Администратора) - */ - public function editAction() - { - $id = $_GET['id']; - $Url = Config::get('core.router.class'); - - if (!empty($_POST)) { // это выполняется нормально. - - if (!empty($_POST['saveChanges'] )) { - $Note = new Note(); - $newNotes = $Note->loadFromArray($_POST); - $newNotes->update(); - $this->redirect($Url::link("admin/notes/index&id=$id")); - } - elseif (!empty($_POST['cancel'])) { - $this->redirect($Url::link("admin/notes/index&id=$id")); - } - } - else { - $Note = new Note(); - $viewNotes = $Note->getById($id); - - $editNoteTitle = "Редактирование заметки"; - - $this->view->addVar('viewNotes', $viewNotes); - $this->view->addVar('editNoteTitle', $editNoteTitle); - - $this->view->render('note/edit.php'); - } - - } - - /** - * Выводит на экран предупреждение об удалении данных (только для Администратора) - */ - public function deleteAction() - { - $id = $_GET['id']; - $Url = Config::get('core.router.class'); - - if (!empty($_POST)) { - if (!empty($_POST['deleteNote'])) { - $Note = new Note(); - $newNotes = $Note->loadFromArray($_POST); - $newNotes->delete(); - - $this->redirect($Url::link("admin/notes/index")); - - } - elseif (!empty($_POST['cancel'])) { - $this->redirect($Url::link("admin/notes/edit&id=$id")); - } - } - else { - - $Note = new Note(); - $deletedNote = $Note->getById($id); - $deleteNoteTitle = "Удалить заметку?"; - - $this->view->addVar('deleteNoteTitle', $deleteNoteTitle); - $this->view->addVar('deletedNote', $deletedNote); - - $this->view->render('note/delete.php'); - } - } - - -} \ No newline at end of file diff --git a/application/models/AllUsers.php b/application/models/AllUsers.php new file mode 100644 index 0000000..272779f --- /dev/null +++ b/application/models/AllUsers.php @@ -0,0 +1,37 @@ +__construct( $params); + + // Разбираем и сохраняем дату публикации + if ( isset($params['publicationDate']) ) { + $publicationDate = explode ( '-', $params['publicationDate'] ); + + if ( count($publicationDate) == 3 ) { + list ( $y, $m, $d ) = $publicationDate; + $this->publicationDate = mktime ( 0, 0, 0, $m, $d, $y ); + } + if (isset($params['authors']) && is_array($params['authors'])){ + $this->authors = $params['authors']; + }else { + $this->authors= array(); + } + } + } + + public function getById(int $id, string $tableName = ''): ?Model { + $tableName = !empty($tableName) ? $tableName : $this->tableName; + $sql = "SELECT * FROM $tableName WHERE id = :id"; + $st = $this->pdo->prepare($sql); + $st->bindValue(":id", $id, PDO::PARAM_INT); + $st->execute(); + $row = $st->fetch(); + if ($row) { + return new static($row); + } + return null; + } + public function getList($numRows=1000000, $categoryId = null, $isSubcategory = null, $order = "publicationDate DESC") :array + { + if (!$isSubcategory) { + $categoryClause = $categoryId ? "WHERE categoryId = $categoryId" : ""; + } else { + $categoryClause = $categoryId ? "WHERE subcategoryId = $categoryId" : ""; + } + + if ($categoryClause) { + $onlyActive = $numRows < 1000000 ? "AND active = 1" : ""; + } else { + $onlyActive = $numRows < 1000000 ? "WHERE active = 1" : ""; + } + + $sql = "SELECT SQL_CALC_FOUND_ROWS *, UNIX_TIMESTAMP(publicationDate) + AS publicationDate + FROM articles $categoryClause $onlyActive + ORDER BY $order LIMIT :numRows"; + + $modelClassName = static::class; + + $st = $this->pdo->prepare($sql); + $st->bindValue( ":numRows", $numRows, \PDO::PARAM_INT ); + $st->execute(); + $list = array(); + + while ($row = $st->fetch()) { + $example = new $modelClassName($row); + $list[] = $example; + } + + $sql = "SELECT FOUND_ROWS() AS totalRows"; // получаем число выбранных строк + $totalRows = $this->pdo->query($sql)->fetch(); + return (array ("results" => $list, "totalRows" => $totalRows[0])); + } + public function insert() { + + // Есть уже у объекта Article ID? + if ( !is_null( $this->id ) ) trigger_error ( "Article::insert(): Attempt to insert an Article object that already has its ID property set (to $this->id).", E_USER_ERROR ); + + // Вставляем статью + $sql = "INSERT INTO articles ( publicationDate, categoryId,subcategoryId ,title, summary, content, active ) VALUES ( FROM_UNIXTIME(:publicationDate), :categoryId,:subcategoryId ,:title, :summary, :content, :active )"; + $st = $conn->prepare ( $sql ); + $st->bindValue( ":publicationDate", $this->publicationDate, PDO::PARAM_INT ); + $st->bindValue( ":categoryId", $this->categoryId, PDO::PARAM_INT ); + $st->bindValue( ":subcategoryId", $this->subcategoryId, PDO::PARAM_INT ); + $st->bindValue( ":title", $this->title, PDO::PARAM_STR ); + $st->bindValue( ":summary", $this->summary, PDO::PARAM_STR ); + $st->bindValue( ":content", $this->content, PDO::PARAM_STR ); + $st->bindValue( ":active", $this->activeArticle, PDO::PARAM_INT); + $st->execute(); + $this->id = $conn->lastInsertId(); + $st = $conn->prepare($sql); + $st->bindValue(":id", $this->id, PDO::PARAM_INT); + $st->execute(); + foreach ($this->authors as $user) { + $sql = "INSERT INTO users_article (user, article) VALUES (:user, :id)"; + $st = $conn->prepare($sql); + $st->bindValue(":user", $user, PDO::PARAM_INT); + $st->bindValue(":id", $this->id, PDO::PARAM_INT); + + if (!$st->execute()) { + // Логирование ошибки или вывод сообщения об ошибке + error_log("Error inserting into users_article: " . implode(", ", $st->errorInfo())); + } + } + + $conn = null; + } + + /** + * Обновляем текущий объект статьи в базе данных + */ + public function update() + { + // Есть ли у объекта статьи ID? + if (is_null($this->id)) trigger_error("Article::update(): Attempt to " + . "update an Article object that does not have its ID property " + . "set.", E_USER_ERROR); + + // Обновляем статью + $sql = "UPDATE articles SET publicationDate=FROM_UNIXTIME(:publicationDate)," + . " categoryId=:categoryId, subcategoryId=:subcategoryId," + . " title=:title, summary=:summary, content=:content," + . " active=:active WHERE id = :id"; + $st = $conn->prepare($sql); + $st->bindValue(":publicationDate", $this->publicationDate, PDO::PARAM_INT); + $st->bindValue(":categoryId", $this->categoryId, PDO::PARAM_INT); + $st->bindValue(":subcategoryId", $this->subcategoryId, PDO::PARAM_INT); + $st->bindValue(":title", $this->title, PDO::PARAM_STR); + $st->bindValue(":summary", $this->summary, PDO::PARAM_STR); + $st->bindValue(":content", $this->content, PDO::PARAM_STR); + $st->bindValue(":id", $this->id, PDO::PARAM_INT); + $st->bindValue(":active", $this->activeArticle, PDO::PARAM_INT); + $st->execute(); + $sql = "DELETE FROM users_article WHERE articles = :id"; + $st = $conn->prepare($sql); + $st->bindValue(":id", $this->id, PDO::PARAM_INT); + $st->execute(); + foreach ($this->authors as $author) { + $sql = "INSERT INTO users_article (user, articles) VALUES (:user, :id)"; + $st = $conn->prepare($sql); + $st->bindValue(":user", $author, PDO::PARAM_INT); + $st->bindValue(":id", $this->id, PDO::PARAM_INT); + $st->execute(); + } + $conn = null; + } + + + /** + * Удаляем текущий объект статьи из базы данных + */ + public function delete() : void { + + // Есть ли у объекта статьи ID? + if ( is_null( $this->id ) ) trigger_error ( "Article::delete(): Attempt to delete an Article object that does not have its ID property set.", E_USER_ERROR ); + + // Удаляем статью + $st = $conn->prepare ( "DELETE FROM articles WHERE id = :id LIMIT 1" ); + $st->bindValue( ":id", $this->id, PDO::PARAM_INT ); + $st->execute(); + $st = $conn->prepare("DELETE FROM users_article WHERE article = :id"); + $st->bindValue(":id", $this->id, PDO::PARAM_INT); + $st->execute(); + } +} \ No newline at end of file diff --git a/application/models/AuthUser.php b/application/models/AuthUser.php deleted file mode 100644 index 4aea4cd..0000000 --- a/application/models/AuthUser.php +++ /dev/null @@ -1,39 +0,0 @@ -getAuthData($login); - if (isset($siteAuthData['pass'])) { - $pass .= $siteAuthData['salt']; - $passForCheck = password_verify($pass, $siteAuthData['pass']); - if ($passForCheck) { - $result = true; - } - } - return $result; - } - - /** - * Получить роль по имени пользователя - */ - protected function getRoleByUserName($login): string { - $User = new UserModel(); - $siteAuthData = $User->getRole($login); - if (isset($siteAuthData['role'])) { - return $siteAuthData['role']; - } - } - -} diff --git a/application/models/BaseExampleModel.php b/application/models/BaseExampleModel.php deleted file mode 100644 index bb14538..0000000 --- a/application/models/BaseExampleModel.php +++ /dev/null @@ -1,25 +0,0 @@ -getById($id, $tableName); - $modelData->likes++; - $modelData->update(); - } - - public function getModelLikes($id, $tableName) //метод не узнаёт какая именно модель - { - $modelData = $this->getById($id, $tableName); - return $modelData->likes; - } -} diff --git a/application/models/Category.php b/application/models/Category.php new file mode 100644 index 0000000..f883aca --- /dev/null +++ b/application/models/Category.php @@ -0,0 +1,59 @@ +__construct( $params ); + } + public function getList($numRows=100000,$order="name ASC"):array { + + $sql = "SELECT * FROM categories ORDER BY $order LIMIT :numRows"; + $st = $this->pdo->prepare($sql); + $st->bindValue(":numRows", $numRows, \PDO::PARAM_INT); + $st->execute(); + $list = array(); + while ($row= $st->fetch()){ + $category = new Category($row); + $list[] = $category; + } + $sql = "SELECT FOUND_ROWS() AS totalRows"; + $totalRows = $this->pdo->query($sql)->fetch(); + $conn =null; + return (array("results" => $list, "totalRows" => $totalRows[0])); + } + public function insert($tableName = ''){ + $tableName = !empty($tableName) ? $tableName : $this->tableName; + $sql = "INSERT INTO $tableName (name,description) VALUES (:name,:description)"; + $st= $this->pdo->prepare($sql); + $st->bindValue(":name", $this->name, \PDO::PARAM_STR); + $st->bindValue(":description",$this->description, \PDO::PARAM_STR); + $st->execute(); + $this->id = $this->pdo->lastInsertId(); + } + public function update($tableName = ''){ + $tableName = !empty($tableName) ? $tableName : $this->tableName; + $sql = "UPDATE $tableName SET name = :name, description=:description WHERE id = :id"; + $st = $this->pdo->prepare($sql); + $st->bindValue(":name", $this->name, \PDO::PARAM_STR); + $st->bindValue(":description", $this->description, \PDO::PARAM_STR); + $st->bindValue(":id", $this->id, \PDO::PARAM_INT); + $st->execute(); + } + public function delete($tableName = ''):void{ + $tableName = !empty($tableName) ? $tableName : $this->tableName; + $st = $this->pdo->prepare("DELETE FROM $tableName WHERE id = :id LIMIT 1"); + $st->bindValue(":id", $this->id, \PDO::PARAM_INT); + $st->execute(); + } +} diff --git a/application/models/Connection.php b/application/models/Connection.php new file mode 100644 index 0000000..b988322 --- /dev/null +++ b/application/models/Connection.php @@ -0,0 +1,42 @@ +tableName; + + $sql = "SELECT * FROM $tableName where article_id = :id"; + $modelClassName = static::class; + + $st = $this->pdo->prepare($sql); + + $st->bindValue(":id", $id, \PDO::PARAM_INT); + $st->execute(); + $row = null; + while ($row = $st->fetch()) { + $example = new $modelClassName($row); + $list[] = $example; + } + return $list; + } + public function insert(){ + $sql = "INSERT INTO connections ( article_id, user_id) VALUES ( :articleId, :userId )"; + $st = $this->pdo->prepare( $sql ); + $st->bindValue( ":articleId", $this->article_id, \PDO::PARAM_INT ); + $st->bindValue( ":userId", $this->user_id, \PDO::PARAM_INT ); + $st->execute(); + $conn = null; + } +} diff --git a/application/models/Note.php b/application/models/Note.php deleted file mode 100644 index 4ea450a..0000000 --- a/application/models/Note.php +++ /dev/null @@ -1,49 +0,0 @@ -tableName (title, content, publicationDate) VALUES (:title, :content, :publicationDate)"; - $st = $this->pdo->prepare ( $sql ); - $st->bindValue( ":publicationDate", (new \DateTime('NOW'))->format('Y-m-d H:i:s'), \PDO::PARAM_STMT); - $st->bindValue( ":title", $this->title, \PDO::PARAM_STR ); - - $st->bindValue( ":content", $this->content, \PDO::PARAM_STR ); - $st->execute(); - $this->id = $this->pdo->lastInsertId(); - } - - public function update() - { - $sql = "UPDATE $this->tableName SET publicationDate=:publicationDate, title=:title, content=:content WHERE id = :id"; - $st = $this->pdo->prepare ( $sql ); - - $st->bindValue( ":publicationDate", (new \DateTime('NOW'))->format('Y-m-d H:i:s'), \PDO::PARAM_STMT); - $st->bindValue( ":title", $this->title, \PDO::PARAM_STR ); - - $st->bindValue( ":content", $this->content, \PDO::PARAM_STR ); - $st->bindValue( ":id", $this->id, \PDO::PARAM_INT ); - $st->execute(); - } -} - diff --git a/application/models/Subcategory.php b/application/models/Subcategory.php new file mode 100644 index 0000000..75f7901 --- /dev/null +++ b/application/models/Subcategory.php @@ -0,0 +1,91 @@ +__construct( $params ); + } + public function getList($numRows=1000000, $categoryId=null, $order="name ASC") : array + { + $categoryClause = $categoryId ? "WHERE cat_id = $categoryId" : ""; + + $sql = "SELECT * FROM $this->tableName $categoryClause ORDER BY $order LIMIT :numRows"; + + $st= $this->pdo->prepare($sql); + $st->bindValue(":numRows", $numRows, \PDO::PARAM_INT ); + $st->execute(); + $list = array(); + + while( $row = $st->fetch() ){ + $subcategory = new Subcategory($row); + $list[] = $subcategory; + } + + $sql = "SELECT FOUND_ROWS() AS totalRows"; + $totalRows = $this->pdo->query($sql)->fetch(); + $conn = null; + return (array("results" => $list, "totalRows" => $totalRows[0] ) ); + } + public function getCategIdByName($name){ + $sql = "SELECT id FROM categories WHERE name = :name "; + $st = $this->pdo->prepare($sql); + $st->bindValue(":name", $name, PDO::PARAM_STR); + $st->execute(); + $row = $st->fetch(); + $conn = null; + if($row){ + return $row[0]; + } + } + public function isSubcategoryExist($name) + { + $sql = "SELECT name FROM $this->tableName WHERE name = :name"; + $st = $this->pdo->prepare($sql); + $st->bindValue(":name", $name, \PDO::PARAM_STR); + $st->execute(); + return $st->fetch() !== false; + } + public function insert(){ + // Проверяем есть ли уже у обьекта Subcategory ID ? + if ( !is_null( $this->id ) ) trigger_error ( "Subcategory::insert(): " + . "Attempt to insert a Subcategory object that already has its " + . "ID property set (to $this->id).", E_USER_ERROR ); + //Вставляем субкатегорию + $sql = "INSERT INTO $this->tableName(name, cat_id) VALUES(:name, :cat_id)"; + $st = $this->pdo->prepare($sql); + $st->bindValue(":name", $this->name, \PDO::PARAM_STR ); + $st->bindValue(":cat_id", $this->cat_id, \PDO::PARAM_INT ); + $st->execute(); + $this->id = $this->pdo->lastInsertId(); + } + public function update(){ + // Проверяем есть ли уже у обьекта Subcategory ID ? + if ( is_null( $this->id ) ) trigger_error ( "Subcategory::insert(): " + . "Attempt to insert a Subcategory object that does not have its " + . "ID property set (to $this->id).", E_USER_ERROR ); + $sql = "UPDATE $this->tableName SET name=:name, cat_id=:cat_id WHERE id=:id"; + $st = $this->pdo->prepare($sql); + $st->bindValue(":name", $this->name, \PDO::PARAM_STR); + $st->bindValue(":cat_id", $this->cat_id, \PDO::PARAM_INT); + $st->bindValue(":id", $this->id, \PDO::PARAM_INT); + $st->execute(); + } + public function delete() :void { + // У объекта Subcategory есть ID? + if ( is_null( $this->id ) ) trigger_error ( "Subcategory::delete(): " + . "Attempt to delete a Subcategory object that does not have its " + . "ID property set.", E_USER_ERROR ); + $st = $this->pdo->prepare ( "DELETE FROM $this->tableName WHERE id = :id LIMIT 1" ); + $st->bindValue( ":id", $this->id, \PDO::PARAM_INT ); + $st->execute(); + + } +} diff --git a/application/models/User.php b/application/models/User.php new file mode 100644 index 0000000..9c22301 --- /dev/null +++ b/application/models/User.php @@ -0,0 +1,55 @@ +pdo->prepare($sql); + $query->bindValue( ":name", $login, \PDO::PARAM_STR); + $query->execute(); + $truePass = $query->fetch(); + if($truePass[0] == $pass){ + $result = true; + } + } + return $result; + } +} \ No newline at end of file diff --git a/application/models/UserModel.php b/application/models/UserModel.php deleted file mode 100644 index ebcded7..0000000 --- a/application/models/UserModel.php +++ /dev/null @@ -1,140 +0,0 @@ -tableName (timestamp, login, salt, pass, role, email) VALUES (:timestamp, :login, :salt, :pass, :role, :email)"; - $st = $this->pdo->prepare ( $sql ); - $st->bindValue( ":timestamp", (new \DateTime('NOW'))->format('Y-m-d H:i:s'), \PDO::PARAM_STMT); - $st->bindValue( ":login", $this->login, \PDO::PARAM_STR ); - - //Хеширование пароля - $this->salt = rand(0,1000000); - $st->bindValue( ":salt", $this->salt, \PDO::PARAM_STR ); -// \DebugPrinter::debug($this->salt); - - $this->pass .= $this->salt; - $hashPass = password_hash($this->pass, PASSWORD_BCRYPT); -// \DebugPrinter::debug($hashPass); - $st->bindValue( ":pass", $hashPass, \PDO::PARAM_STR ); - - $st->bindValue( ":role", $this->role, \PDO::PARAM_STR ); - $st->bindValue( ":email", $this->email, \PDO::PARAM_STR ); - $st->execute(); - $this->id = $this->pdo->lastInsertId(); - } - - public function update() - { - $sql = "UPDATE $this->tableName SET timestamp=:timestamp, login=:login, pass=:pass,salt = :salt,role = :role, email=:email WHERE id = :id"; - $st = $this->pdo->prepare ( $sql ); - - $st->bindValue( ":timestamp", (new \DateTime('NOW'))->format('Y-m-d H:i:s'), \PDO::PARAM_STMT); - $st->bindValue( ":login", $this->login, \PDO::PARAM_STR ); - if ($this->pass) - { - // Хеширование пароля - $this->salt = rand(0,1000000); - $st->bindValue( ":salt", $this->salt, \PDO::PARAM_STR ); - $this->pass .= $this->salt; - $hashPass = password_hash($this->pass, PASSWORD_BCRYPT); - $st->bindValue( ":pass", $hashPass, \PDO::PARAM_STR ); - }else { - $sqlPass = "SELECT pass, salt from $this->tableName where id = $this->id"; - $password = $this->pdo->query($sqlPass); - $pass = $password->fetch(); - $st->bindValue( ":pass", $pass['pass'], \PDO::PARAM_STR ); - $st->bindValue( ":salt", $pass['salt'], \PDO::PARAM_STR ); - } - - - $st->bindValue( ":role", $this->role, \PDO::PARAM_STR ); - $st->bindValue( ":email", $this->email, \PDO::PARAM_STR ); - $st->bindValue( ":id", $this->id, \PDO::PARAM_INT ); - $st->execute(); - } - - /** - * Вернёт id пользователя - * - * @return ?int - */ - public function getId() - { - if ($this->userName !== 'guest'){ - $sql = "SELECT id FROM users where login = :userName"; - $st = $this->pdo->prepare($sql); - $st -> bindValue( ":userName", $this->userName, \PDO::PARAM_STR ); - $st -> execute(); - $row = $st->fetch(); - return $row['id']; - } else { - return null; - } - } - - /** - * Проверка логина и пароля пользователя. - */ - public function getAuthData($login): ?array { - $sql = "SELECT salt, pass FROM users WHERE login = :login"; - $st = $this->pdo->prepare($sql); - $st->bindValue(":login", $login, \PDO::PARAM_STR); - $st->execute(); - $authData = $st->fetch(); - return $authData ? $authData : null; - } - - /** - * Проверяем активность пользователя. - */ - public function getRole($login): array { - $sql = "SELECT role FROM users WHERE login = :login"; - $st = $this->pdo->prepare($sql); - $st->bindValue(":login", $login, \PDO::PARAM_STR); - $st->execute(); - return $st->fetch(); - } - -} \ No newline at end of file diff --git a/application/views/homepage/index.php b/application/views/homepage/index.php deleted file mode 100644 index d34f114..0000000 --- a/application/views/homepage/index.php +++ /dev/null @@ -1,15 +0,0 @@ - -
-

-
-
-
-
-

Добро пожаловать в SimpleMVC!

-
-
\ No newline at end of file diff --git a/application/views/layouts/admin-main.php b/application/views/layouts/admin-main.php deleted file mode 100644 index 0500efb..0000000 --- a/application/views/layouts/admin-main.php +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - -
- -
- - - - diff --git a/application/views/layouts/includes/admin-main/nav.php b/application/views/layouts/includes/admin-main/nav.php deleted file mode 100644 index adf83e8..0000000 --- a/application/views/layouts/includes/admin-main/nav.php +++ /dev/null @@ -1,49 +0,0 @@ - -explainAccess("homepage/index")); - -?> - - - diff --git a/application/views/layouts/includes/main/footer.php b/application/views/layouts/includes/main/footer.php deleted file mode 100644 index 3d20dea..0000000 --- a/application/views/layouts/includes/main/footer.php +++ /dev/null @@ -1,17 +0,0 @@ - - - - diff --git a/application/views/layouts/includes/main/head.php b/application/views/layouts/includes/main/head.php deleted file mode 100644 index de3bf75..0000000 --- a/application/views/layouts/includes/main/head.php +++ /dev/null @@ -1,19 +0,0 @@ - - - - SimpleMVC | Учебный проект - -
-
- -
-
- - diff --git a/application/views/layouts/includes/main/nav.php b/application/views/layouts/includes/main/nav.php deleted file mode 100644 index 5667fc2..0000000 --- a/application/views/layouts/includes/main/nav.php +++ /dev/null @@ -1,48 +0,0 @@ - -explainAccess("admin/adminusers/index")); - -?> - - - diff --git a/application/views/layouts/main.php b/application/views/layouts/main.php deleted file mode 100644 index 42fa06f..0000000 --- a/application/views/layouts/main.php +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - -
- -
- - - - diff --git a/application/views/login/index.php b/application/views/login/index.php deleted file mode 100644 index 8138947..0000000 --- a/application/views/login/index.php +++ /dev/null @@ -1,21 +0,0 @@ -

- -
- - -
- - -
-
- - -
- - -
- diff --git a/application/views/note/add.php b/application/views/note/add.php deleted file mode 100644 index 0c1a71c..0000000 --- a/application/views/note/add.php +++ /dev/null @@ -1,25 +0,0 @@ - - - -

- -
"> -
- - -
-
-
- -
- - -
diff --git a/application/views/note/delete.php b/application/views/note/delete.php deleted file mode 100644 index bf924e4..0000000 --- a/application/views/note/delete.php +++ /dev/null @@ -1,17 +0,0 @@ - - - - -

- -
- Вы уверены, что хотите удалить заметку? - - - -
-
\ No newline at end of file diff --git a/application/views/note/edit.php b/application/views/note/edit.php deleted file mode 100644 index dc8eeb8..0000000 --- a/application/views/note/edit.php +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - -

- -
-
Note title
- title?>>
-
Note content
-
- - - - -
\ No newline at end of file diff --git a/application/views/note/includes/admin-notes-nav.php b/application/views/note/includes/admin-notes-nav.php deleted file mode 100644 index 4ec212c..0000000 --- a/application/views/note/includes/admin-notes-nav.php +++ /dev/null @@ -1,24 +0,0 @@ -explainAccess("admin/adminusers/index")); -?> - - \ No newline at end of file diff --git a/application/views/note/index.php b/application/views/note/index.php deleted file mode 100644 index 6f98031..0000000 --- a/application/views/note/index.php +++ /dev/null @@ -1,36 +0,0 @@ - - - -

List notes

- - - - - - - - - - - - - - - - - - - - - -
ОглавлениеПосвящаетсяДата
id . ">{$note->title}" ) ?> content ?> publicationDate ?>
- - -

Список заметок пуст

- - diff --git a/application/views/note/view-item.php b/application/views/note/view-item.php deleted file mode 100644 index aa38965..0000000 --- a/application/views/note/view-item.php +++ /dev/null @@ -1,24 +0,0 @@ - - - - -

title ?> - - returnIfAllowed("admin/notes/edit", - "[Редактировать]");?> - - returnIfAllowed("admin/notes/delete", - "[Удалить]"); ?> - - -

- -

Контент: content ?>

-

Зарегестрирована: publicationDate ?>

- diff --git a/application/views/user/add.php b/application/views/user/add.php deleted file mode 100644 index f1f71d3..0000000 --- a/application/views/user/add.php +++ /dev/null @@ -1,29 +0,0 @@ - -

- -
"> - -
- - -
-
- - -
-
- - -
-
- - -
- - -
- - diff --git a/application/views/user/delete.php b/application/views/user/delete.php deleted file mode 100644 index 8712efe..0000000 --- a/application/views/user/delete.php +++ /dev/null @@ -1,17 +0,0 @@ - - - - -

- -
- Вы уверены, что хотите удалить данные пользователя? - - - -
-
diff --git a/application/views/user/edit.php b/application/views/user/edit.php deleted file mode 100644 index e3fc84d..0000000 --- a/application/views/user/edit.php +++ /dev/null @@ -1,34 +0,0 @@ - - - - - -

- - returnIfAllowed("admin/adminusers/delete", - "[Удалить]");?> - -

- -
-
Введите имя пользователя
-
-
Введите пароль
-
-
Введите e-mail
-
-
Выберите роль юзера
-
- - - -
diff --git a/application/views/user/includes/admin-users-nav.php b/application/views/user/includes/admin-users-nav.php deleted file mode 100644 index 5b0151e..0000000 --- a/application/views/user/includes/admin-users-nav.php +++ /dev/null @@ -1,24 +0,0 @@ -explainAccess("admin/adminusers/index")); -?> - - \ No newline at end of file diff --git a/application/views/user/index.php b/application/views/user/index.php deleted file mode 100644 index e11bb48..0000000 --- a/application/views/user/index.php +++ /dev/null @@ -1,40 +0,0 @@ - - - -

Список пользователей

- - - - - - - - - - - - - - - - - - - - - - - - -
idЛогинEmailЗарегистрирован
id ?> id . ">{$user->login}" ) ?> email ?> timestamp ?> returnIfAllowed("admin/adminusers/edit", - "[Редактировать]");?>
- - -

Список пользователей пуст.

- \ No newline at end of file diff --git a/application/views/user/view-item.php b/application/views/user/view-item.php deleted file mode 100644 index 298dd54..0000000 --- a/application/views/user/view-item.php +++ /dev/null @@ -1,18 +0,0 @@ - - - - -

login ?> - - returnIfAllowed("admin/adminusers/edit", - "[Редактировать]");?> - -

- -

Зарегистрирован timestamp ?>

-

E-mail: email ?>

\ No newline at end of file diff --git a/web/CSS/CMSstyle.css b/web/CSS/CMSstyle.css new file mode 100644 index 0000000..ca0be37 --- /dev/null +++ b/web/CSS/CMSstyle.css @@ -0,0 +1,353 @@ +/* Стили для body and внешнего контейнера */ + +body { + margin: 0; + color: #333; + background-color: #00a0b0; + font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; + line-height: 1.5em; +} + +#container { + width: 960px; + background: #fff; + margin: 20px auto; + padding: 20px; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; +} + + +/* Логотип и нижний колонтитул */ + +#logo { + display: block; + width: 300px; + padding: 0 660px 20px 0; + border: none; + border-bottom: 1px solid #00a0b0; + margin-bottom: 40px; +} + +#footer { + border-top: 1px solid #00a0b0; + margin-top: 40px; + padding: 20px 0 0 0; + font-size: .8em; +} + +#loader-identity { + display : none; + float : right; +} + + +/* Заголвки */ + +h1 { + color: #eb6841; + margin-bottom: 30px; + line-height: 1.2em; +} + +h2, h2 a { + color: #edc951; +} + +h2 a { + text-decoration: none; +} + +h3.categoryDescription { + margin-top: -20px; + margin-bottom: 40px; +} + + +/* Заголовки статей */ + +#headlines { + list-style: none; + padding-left: 0; + width: 75%; +} + +#headlines li { + margin-bottom: 2em; +} + +.pubDate { + font-size: .8em; + color: #eb6841; + text-transform: uppercase; +} + +#headlines .pubDate { + display: inline-block; + width: 100px; + font-size: .5em; + vertical-align: middle; +} + +#headlines.archive .pubDate { + width: 130px; +} + +.summary { + padding-left: 100px; +} + +#headlines.archive .summary { + padding-left: 130px; +} + +.category { + font-style: italic; + font-weight: normal; + font-size: 60%; + color: #999; + display: block; + line-height: 2em; +} + +.category a { + color: #999; + text-decoration: underline; +} + +.showContent { + font-size : 14px; + float : right; +} + + +/* Заголовок для страницы администратора */ + +#adminHeader { + width: 940px; + padding: 0 10px; + border-bottom: 1px solid #00a0b0; + margin: -30px 0 40px 0; + font-size: 0.8em; +} + + +/* Стили для формы с цветным фоном, скругленными углами и тенью */ + +form { + margin: 20px auto; + padding: 40px 20px; + overflow: auto; + background: #fff4cf; + border: 1px solid #666; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + box-shadow: 0 0 .5em rgba(0, 0, 0, .8); +} + + +/* Задаем для элементов формы согласованные поля, отступы, и высоту строки */ + +form ul { + list-style: none; + margin: 0; + padding: 0; +} + +form ul li { + margin: .9em 0 0 0; + padding: 0; +} + +form * { + line-height: 1em; +} + + +/* Метки полей */ + +label { + display: block; + float: left; + clear: left; + text-align: right; + width: 15%; + padding: .4em 0 0 0; + margin: .15em .5em 0 0; +} + + +/* Поля */ + +input, select, textarea { + display: block; + margin: 0; + padding: .4em; + width: 80%; +} + +input, textarea, .date { + border: 2px solid #666; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + background: #fff; +} + +input { + font-size: .9em; +} + +select { + padding: 0; + margin-bottom: 2.5em; + position: relative; + top: .7em; +} + +textarea { + font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; + font-size: .9em; + height: 5em; + line-height: 1.5em; +} + +textarea#content { + font-family: "Courier New", courier, fixed; +} + + +/* Рамка вокруг поля с фокусом ввода */ + +form *:focus { + border: 2px solid #7c412b; + outline: none; +} + + +/* Правильно заполненное поле имеет зеленый фон */ + +input:valid, textarea:valid { + background: #efe; +} + + +/* Кнопки отправки */ + +.buttons { + text-align: center; + margin: 40px 0 0 0; +} + +input[type="submit"] { + display: inline; + margin: 0 20px; + width: 12em; + padding: 10px; + border: 2px solid #7c412b; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + color: #fff; + background: #ef7d50; + font-weight: bold; + -webkit-appearance: none; +} + +input[type="submit"]:hover, input[type="submit"]:active { + cursor: pointer; + background: #fff; + color: #ef7d50; +} + +input[type="submit"]:active { + background: #eee; + -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; + -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; + box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; +} + + +/* Таблицы */ + +table { + width: 100%; + border-collapse: collapse; +} + +tr, th, td { + padding: 10px; + margin: 0; + text-align: left; +} + +table, th { + border: 1px solid #00a0b0; +} + +th { + border-left: none; + border-right: none; + background: #ef7d50; + color: #fff; + cursor: default; +} + +tr:nth-child(odd) { + background: #fff4cf; +} + +tr:nth-child(even) { + background: #fff; +} + +tr:hover { + background: #ddd; + cursor: pointer; +} + + +/* Окна для вывода статуса и сообщений об ошибках */ + +.statusMessage, .errorMessage { + font-size: .8em; + padding: .5em; + margin: 2em 0; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + -box-shadow: 0 0 .5em rgba(0, 0, 0, .8); +} + +.statusMessage { + background-color: #2b2; + border: 1px solid #080; + color: #fff; +} + +.errorMessage { + background-color: #f22; + border: 1px solid #800; + color: #fff; +} + +ul.ajax-load { + margin-left: 0px; + padding-left: 10px; +} +ul.ajax-load li { + display: inline; /* Отображать как строчный элемент */ + margin-right: 5px; /* Отступ слева */ + border: 1px solid #000; /* Рамка вокруг текста */ + padding: 3px; /* Поля вокруг текста */ + font-size: 12px; +} diff --git a/web/JS/loaderIdentity.js b/web/JS/loaderIdentity.js new file mode 100644 index 0000000..e00b301 --- /dev/null +++ b/web/JS/loaderIdentity.js @@ -0,0 +1,15 @@ +// выводим идентификатор + function showLoaderIdentity(content) + { + let id = "#loader-identity" + content; + $(id).show("slow") + } + + // скрываем идентификатор + function hideLoaderIdentity(content) + { + let id = "#loader-identity" + content; + $(id).hide(); + } + + diff --git a/web/JS/showContent.js b/web/JS/showContent.js new file mode 100644 index 0000000..ea34d20 --- /dev/null +++ b/web/JS/showContent.js @@ -0,0 +1,68 @@ +$(function(){ + + console.log('Привет, это страый js ))'); + init_get(); + init_post(); +}); + +function init_get() +{ + $('a.ajaxArticleBodyByGet').one('click', function(){ + var contentId = $(this).attr('data-contentId'); + console.log('ID статьи = ', contentId); + showLoaderIdentity(contentId); + $.ajax({ + url:'/ajax/showContentsHandler.php?articleId=' + contentId, + dataType: 'json' + }) + .done (function(obj){ + hideLoaderIdentity(contentId); + console.log('Ответ получен'); + $('li.' + contentId).append(obj); + }) + .fail(function(xhr, status, error){ + hideLoaderIdentity(contentId); + + console.log('ajaxError xhr:', xhr); // выводим значения переменных + console.log('ajaxError status:', status); + console.log('ajaxError error:', error); + + console.log('Ошибка соединения при получении данных (GET)'); + }); + + return false; + + }); +} + +function init_post() +{ + $('a.ajaxArticleBodyByPost').one('click', function(){ + var content = $(this).attr('data-contentId'); + showLoaderIdentity(contentId); + $.ajax({ + url:'/ajax/showContentsHandler.php', + data: ({articleId: content}), + dataType: 'text', +// converters: 'json text', + method: 'POST' + }) + .done (function(obj){ + hideLoaderIdentity(contentId); + console.log('Ответ получен', obj); + $('li.' + content).append(obj); + }) + .fail(function(xhr, status, error){ + hideLoaderIdentity(contentId); + + + console.log('Ошибка соединения с сервером (POST)'); + console.log('ajaxError xhr:', xhr); // выводим значения переменных + console.log('ajaxError status:', status); + console.log('ajaxError error:', error); + }); + + return false; + + }); +} diff --git a/web/ajax/loadArticle.js b/web/ajax/loadArticle.js new file mode 100644 index 0000000..b241a0e --- /dev/null +++ b/web/ajax/loadArticle.js @@ -0,0 +1,28 @@ +$(document).ready(function() +{ + $(".loadArticle").bind("click", function(){ + let articleId = $(this).attr('data-contentId'); + $.ajax({ + + url:"ajax/loadArticle.php", + type:"POST", + data:({articleId: articleId}), + dataType:"html", + beforeSend: function() + { + let id = "#article" + articleId; + $(id).text("Загрузка данных"); + }, + success: function (data) + { + let id = "#article" + articleId; + $(id).text(data); + }, + error: function funcError() + { + let id = "#article" + articleId; + $(id).text("Ошибка!"); + } + }); + }); +}); \ No newline at end of file diff --git a/web/ajax/loadArticle.php b/web/ajax/loadArticle.php new file mode 100644 index 0000000..aa0bf12 --- /dev/null +++ b/web/ajax/loadArticle.php @@ -0,0 +1,4 @@ +content; \ No newline at end of file diff --git a/web/ajax/showContentsHandler.php b/web/ajax/showContentsHandler.php new file mode 100644 index 0000000..7e6fc05 --- /dev/null +++ b/web/ajax/showContentsHandler.php @@ -0,0 +1,30 @@ +content; +} +if (isset ($_POST['articleId'])) { + //die("Привет)"); + $article = Article::getById((int)$_POST['articleId']); + echo json_encode($article->content); +// die("Привет)"); +// $conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD ); +// +// if (isset($conn)) { +// die("Соединенте установлено"); +// } +// else { +// die("Соединение не установлено"); +// } +// $article = "WHERE Id=". (int)$_POST[articleId]; +// echo $article; +// $sql = "SELECT content FROM articles". $article; +// $contentFromDb = $conn->prepare( $sql ); +// $contentFromDb->execute(); +// $result = $contentFromDb->fetch(); +// $conn = null; +// echo json_encode($result); +} + diff --git a/web/images/logo.jpg b/web/images/logo.jpg new file mode 100644 index 0000000000000000000000000000000000000000..9409eff428643457185db8b965c83d19024ab2e1 GIT binary patch literal 11734 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 W=isr}9=S5_|AQd-|0NZ^oB3bvs}wB& literal 0 HcmV?d00001 From 6768fa53d4391f9ab7e627abf577b4f73d0ea26f Mon Sep 17 00:00:00 2001 From: Misha Semenov Date: Mon, 9 Dec 2024 17:41:49 +0300 Subject: [PATCH 3/7] Merge CMS branch into master --- application/CMSviews/admin/admin.php | 4 +- application/CMSviews/admin/edit/article.php | 2 +- application/CMSviews/admin/edit/category.php | 2 +- .../CMSviews/admin/edit/subcategory.php | 4 +- application/CMSviews/admin/edit/user.php | 4 +- application/CMSviews/admin/listCategories.php | 4 +- .../CMSviews/admin/listSubcategories.php | 4 +- application/CMSviews/admin/listUsers.php | 4 +- application/CMSviews/homepage/homepage.php | 20 +- .../CMSviews/homepage/singleArticle.php | 2 +- .../CMSviews/layouts/includes/adminHeader.php | 10 +- application/CMSviews/login/loginForm.php | 2 +- application/config/console.php | 6 +- .../controllers/HomepageController.php | 6 +- application/controllers/LoginController.php | 8 +- application/models/AllUsers.php | 85 +++- application/models/Category.php | 2 - application/models/Subcategory.php | 49 ++- web/CSS/style.css | 363 ++++++++++++++++-- 19 files changed, 486 insertions(+), 95 deletions(-) diff --git a/application/CMSviews/admin/admin.php b/application/CMSviews/admin/admin.php index ac55955..9d374b4 100644 --- a/application/CMSviews/admin/admin.php +++ b/application/CMSviews/admin/admin.php @@ -23,7 +23,7 @@ - + publicationDate)?> title?> @@ -83,6 +83,6 @@

article in total.

-

Add a New Article

+

Add a New Article

\ No newline at end of file diff --git a/application/CMSviews/admin/edit/article.php b/application/CMSviews/admin/edit/article.php index 2fd4913..2907a08 100644 --- a/application/CMSviews/admin/edit/article.php +++ b/application/CMSviews/admin/edit/article.php @@ -72,7 +72,7 @@ id) { ?> -

+

Delete This Article

diff --git a/application/CMSviews/admin/edit/category.php b/application/CMSviews/admin/edit/category.php index e76a837..4cb7b2c 100644 --- a/application/CMSviews/admin/edit/category.php +++ b/application/CMSviews/admin/edit/category.php @@ -30,7 +30,7 @@ id ) { ?> -

+

Delete This Category

diff --git a/application/CMSviews/admin/edit/subcategory.php b/application/CMSviews/admin/edit/subcategory.php index 0fbabf4..ee82eb5 100644 --- a/application/CMSviews/admin/edit/subcategory.php +++ b/application/CMSviews/admin/edit/subcategory.php @@ -17,7 +17,7 @@ - + name ?> @@ -32,4 +32,4 @@

categor in total.

-

Add a New Subcategory

+

Add a New Subcategory

diff --git a/application/CMSviews/admin/edit/user.php b/application/CMSviews/admin/edit/user.php index d4d02ae..bcfeb81 100644 --- a/application/CMSviews/admin/edit/user.php +++ b/application/CMSviews/admin/edit/user.php @@ -17,7 +17,7 @@ - + name?> @@ -39,4 +39,4 @@

user in total.

-

Add a New User

\ No newline at end of file +

Add a New User

\ No newline at end of file diff --git a/application/CMSviews/admin/listCategories.php b/application/CMSviews/admin/listCategories.php index 15015dd..e1636fb 100644 --- a/application/CMSviews/admin/listCategories.php +++ b/application/CMSviews/admin/listCategories.php @@ -16,7 +16,7 @@ - + name?> @@ -28,6 +28,6 @@

category in total.

-

Add a New Category

+

Add a New Category

diff --git a/application/CMSviews/admin/listSubcategories.php b/application/CMSviews/admin/listSubcategories.php index 7560e39..c168991 100644 --- a/application/CMSviews/admin/listSubcategories.php +++ b/application/CMSviews/admin/listSubcategories.php @@ -17,7 +17,7 @@ - + name ?> @@ -32,4 +32,4 @@

categor in total.

-

Add a New Subcategory

\ No newline at end of file +

Add a New Subcategory

\ No newline at end of file diff --git a/application/CMSviews/admin/listUsers.php b/application/CMSviews/admin/listUsers.php index d4d02ae..bcfeb81 100644 --- a/application/CMSviews/admin/listUsers.php +++ b/application/CMSviews/admin/listUsers.php @@ -17,7 +17,7 @@ - + name?> @@ -39,4 +39,4 @@

user in total.

-

Add a New User

\ No newline at end of file +

Add a New User

\ No newline at end of file diff --git a/application/CMSviews/homepage/homepage.php b/application/CMSviews/homepage/homepage.php index dbdfb59..76d2c01 100644 --- a/application/CMSviews/homepage/homepage.php +++ b/application/CMSviews/homepage/homepage.php @@ -9,14 +9,14 @@ publicationDate)?> - + title )?> categoryId) && isset($results['categories'][$article->categoryId])) { ?> Категория - + categoryId]->name)?> @@ -29,7 +29,7 @@ subcategoryId) && isset($results['subcategories'][$article->subcategoryId])) { ?> Подкатегория - subcategoryId]->name)?> @@ -45,7 +45,7 @@ $total = count($article->authors); $counter = 0; foreach($article->authors as $key =>$author){ ?> - &userId="> content50char)?>

gif
- Показать полностью + Показать полностью -

+

Article Archive

diff --git a/application/CMSviews/homepage/singleArticle.php b/application/CMSviews/homepage/singleArticle.php index e175ae5..7d9c1a4 100644 --- a/application/CMSviews/homepage/singleArticle.php +++ b/application/CMSviews/homepage/singleArticle.php @@ -6,7 +6,7 @@ in subcategory - + name) ?> diff --git a/application/CMSviews/layouts/includes/adminHeader.php b/application/CMSviews/layouts/includes/adminHeader.php index 9e894e7..2700961 100644 --- a/application/CMSviews/layouts/includes/adminHeader.php +++ b/application/CMSviews/layouts/includes/adminHeader.php @@ -1,11 +1,11 @@ diff --git a/application/CMSviews/login/loginForm.php b/application/CMSviews/login/loginForm.php index e63cf6c..6bdd576 100644 --- a/application/CMSviews/login/loginForm.php +++ b/application/CMSviews/login/loginForm.php @@ -1,5 +1,5 @@ -
+ diff --git a/application/config/console.php b/application/config/console.php index e6ac73a..8f3eba9 100644 --- a/application/config/console.php +++ b/application/config/console.php @@ -5,9 +5,9 @@ $config = [ 'core' => [ // подмассив, используемый самим ядром фреймворка 'db' => [ - 'dns' => 'mysql:host=localhost;dbname=dbname', - 'username' => 'root', - 'password' => '1234' + 'dns' => 'mysql:host=localhost;dbname=db_cms', + 'username' => 'myuser', + 'password' => '12345' ], 'router' => [ // подсистема маршрутизации 'class' => \ItForFree\SimpleMVC\Router\ConsoleRouter::class, diff --git a/application/controllers/HomepageController.php b/application/controllers/HomepageController.php index 9cfe80d..c27c83f 100644 --- a/application/controllers/HomepageController.php +++ b/application/controllers/HomepageController.php @@ -24,9 +24,9 @@ class HomepageController extends \ItForFree\SimpleMVC\MVC\Controller * Инициализация всех сущностей */ protected function initModelObjects(){ - $this->Article = new Article; - $this->Category = new Category; - $this->Subcategory = new Subcategory; + $this->Article = new Article(); + $this->Category = new Category(); + $this->Subcategory = new Subcategory(); $this->Connection = new Connection(); $this->Users = new AllUsers(); } diff --git a/application/controllers/LoginController.php b/application/controllers/LoginController.php index 5a1b76b..578d7c3 100644 --- a/application/controllers/LoginController.php +++ b/application/controllers/LoginController.php @@ -12,14 +12,14 @@ class LoginController extends \ItForFree\SimpleMVC\MVC\Controller public function loginAction() { $User = Config::getObject('core.user.class'); if ($User->userName != null && $User->userName != 'guest'){ - $this->redirect(Url::link("CMSAdmin/index")); + $this->redirect(Url::link("Admin/index")); }elseif (!empty($_POST)) { $login = $_POST['userName']; $pass = $_POST['password']; if($User->login($login, $pass)) { - $this->redirect(Url::link("CMSAdmin/index")); + $this->redirect(Url::link("Admin/index")); } else { - $this->redirect(Url::link("CMSLogin/login&auth=deny")); + $this->redirect(Url::link("Login/login&auth=deny")); } } else { @@ -32,7 +32,7 @@ public function logoutAction() { $User = Config::getObject('core.user.class'); $User->logout(); - $this->redirect(Url::link("CMSLogin/login")); + $this->redirect(Url::link("Login/login")); } } diff --git a/application/models/AllUsers.php b/application/models/AllUsers.php index 272779f..486744f 100644 --- a/application/models/AllUsers.php +++ b/application/models/AllUsers.php @@ -2,6 +2,7 @@ namespace application\models; use ItForFree\SimpleMVC\Config; +use ItForFree\SimpleMVC\MVC\Model; class AllUsers extends \ItForFree\SimpleMVC\MVC\Model { /** @@ -18,20 +19,94 @@ class AllUsers extends \ItForFree\SimpleMVC\MVC\Model /** * @var int ID пользователя из базы данных */ - public ?int $id = null; +public ?int $id = null; /** - * @var string Имя пользователя + * @var string Логин пользователя */ - public $name = null; + public $login = null; /** * @var string пароль пользователя */ - public $pass = null; + public $password = null; /** * @var bool индикатор, показывающий активен пользователь или нет */ public $active = null; -} \ No newline at end of file + + public function isUserExist($login){ + $sql = "SELECT name FROM users WHERE login = :login"; + $st = $this->pdo->prepare($sql); + $st->bindValue(":login",$login, \PDO::PARAM_STR); + $st->execute(); + if ($st->fetch()[0]){ + return true; + }else { + return false; + } + } + public function storeFormValues($params){ + $this->__construct( $params ); + } + public function getList($numRows=1000000):array + { + $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM users"; + $st = $this->pdo->query($sql); + $list = array (); + while ($row = $st->fetch()){ + $user = new User($row); + $list[] = $user; + } + $sql = "SELECT FOUND_ROWS() AS totalRows"; + $totalRows = $this->pdo->query($sql)->fetch(); + $conn = null; + return (array( + "results" =>$list, + "totalRows" => $totalRows[0] + ) + ); + } + public function insert(){ + $sql = "INSERT INTO users(login, password, active) VALUES(:login, :password, :active)"; + $st = $this->pdo->prepare($sql); + $st->bindValue(":login", $this->login, \PDO::PARAM_STR ); + $st->bindValue(":password", $this->password, \PDO::PARAM_STR ); + $st->bindValue(":active", $this->active, \PDO::PARAM_INT ); + $st->execute(); + $this->id = $this->pdo->lastInsertId(); + } + public function update() { + $sql = "UPDATE users SET login=:login, password=:password, active=:active WHERE id = :id"; + $st = $this->pdo->prepare( $sql ); + $st->bindValue( ":login", $this->login,\PDO::PARAM_STR ); + $st->bindValue( ":password", $this->password, \PDO::PARAM_STR ); + $st->bindValue( ":active", $this->active, \PDO::PARAM_INT ); + $st->bindValue( ":id", $this->userId, \PDO::PARAM_INT ); + $st->execute(); + } + public function getById(int $id, string $tableName = ''): ?Model{ + $sql = "SELECT * FROM users WHERE id = :id "; + $st = $this->pdo->prepare($sql); + $st->bindValue(":id",$id,PDO::PARAM_INT); + $st->execute(); + $row = $st->fetch(); + if ($row){ + return new User($row); + } + } + public function delete():void{ + $st = $this->pdo->prepare("DELETE FROM users WHERE login = :login LIMIT 1"); + $st->bindValue(":login",$this->login,PDO::PARAM_STR); + $st->execute(); +// $st = $this->pdo-> prepare("DELETE FROM users_aritcles WHERE user = :id"); +// $st->bindValue(":id", $this->$id,PDO::PARAM_INT); +// $st->execute(); + } + + + +} + + diff --git a/application/models/Category.php b/application/models/Category.php index f883aca..fad7dac 100644 --- a/application/models/Category.php +++ b/application/models/Category.php @@ -17,7 +17,6 @@ public function storeFormValues ($param){ $this->__construct( $params ); } public function getList($numRows=100000,$order="name ASC"):array { - $sql = "SELECT * FROM categories ORDER BY $order LIMIT :numRows"; $st = $this->pdo->prepare($sql); $st->bindValue(":numRows", $numRows, \PDO::PARAM_INT); @@ -29,7 +28,6 @@ public function getList($numRows=100000,$order="name ASC"):array { } $sql = "SELECT FOUND_ROWS() AS totalRows"; $totalRows = $this->pdo->query($sql)->fetch(); - $conn =null; return (array("results" => $list, "totalRows" => $totalRows[0])); } public function insert($tableName = ''){ diff --git a/application/models/Subcategory.php b/application/models/Subcategory.php index 75f7901..8a49ab3 100644 --- a/application/models/Subcategory.php +++ b/application/models/Subcategory.php @@ -13,27 +13,34 @@ class Subcategory extends \ItForFree\SimpleMVC\MVC\Model public function storeFormValues($params){ $this->__construct( $params ); } - public function getList($numRows=1000000, $categoryId=null, $order="name ASC") : array - { - $categoryClause = $categoryId ? "WHERE cat_id = $categoryId" : ""; - - $sql = "SELECT * FROM $this->tableName $categoryClause ORDER BY $order LIMIT :numRows"; - - $st= $this->pdo->prepare($sql); - $st->bindValue(":numRows", $numRows, \PDO::PARAM_INT ); - $st->execute(); - $list = array(); - - while( $row = $st->fetch() ){ - $subcategory = new Subcategory($row); - $list[] = $subcategory; - } - - $sql = "SELECT FOUND_ROWS() AS totalRows"; - $totalRows = $this->pdo->query($sql)->fetch(); - $conn = null; - return (array("results" => $list, "totalRows" => $totalRows[0] ) ); - } + public function getList($numRows = 1000000, $categoryId = null, $order = "name ASC") : array + { + $categoryClause = $categoryId !== null ? "WHERE cat_id = :categoryId" : ""; + $sql = "SELECT * FROM $this->tableName $categoryClause ORDER BY $order LIMIT :numRows"; + $st = $this->pdo->prepare($sql); + $st->bindValue(":numRows", $numRows, \PDO::PARAM_INT); + if ($categoryId !== null) { + $st->bindValue(":categoryId", $categoryId, \PDO::PARAM_INT); + } + $st->execute(); + $list = []; + while ($row = $st->fetch()) { + $subcategory = new Subcategory($row); + $list[] = $subcategory; + } + $totalRowsSql = "SELECT COUNT(*) AS totalRows FROM $this->tableName $categoryClause"; + $totalRowsSt = $this->pdo->prepare($totalRowsSql); + if ($categoryId !== null) { + $totalRowsSt->bindValue(":categoryId", $categoryId, \PDO::PARAM_INT); + } + $totalRowsSt->execute(); + $totalRows = $totalRowsSt->fetch(); + return [ + "results" => $list, + "totalRows" => $totalRows['totalRows'] + ]; + } + public function getCategIdByName($name){ $sql = "SELECT id FROM categories WHERE name = :name "; $st = $this->pdo->prepare($sql); diff --git a/web/CSS/style.css b/web/CSS/style.css index 80c15b2..ca0be37 100644 --- a/web/CSS/style.css +++ b/web/CSS/style.css @@ -1,42 +1,353 @@ -/* Дополнительные стили сайта (помимо самого бутстрапа) */ +/* Стили для body and внешнего контейнера */ +body { + margin: 0; + color: #333; + background-color: #00a0b0; + font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; + line-height: 1.5em; +} + +#container { + width: 960px; + background: #fff; + margin: 20px auto; + padding: 20px; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; +} -/* Футе для бутстрапа --------------------------------------------------- */ -html { - position: relative; - min-height: 100%; +/* Логотип и нижний колонтитул */ + +#logo { + display: block; + width: 300px; + padding: 0 660px 20px 0; + border: none; + border-bottom: 1px solid #00a0b0; + margin-bottom: 40px; } -body { - margin-bottom: 60px; /* Margin bottom by footer height */ + +#footer { + border-top: 1px solid #00a0b0; + margin-top: 40px; + padding: 20px 0 0 0; + font-size: .8em; +} + +#loader-identity { + display : none; + float : right; +} + + +/* Заголвки */ + +h1 { + color: #eb6841; + margin-bottom: 30px; + line-height: 1.2em; +} + +h2, h2 a { + color: #edc951; +} + +h2 a { + text-decoration: none; +} + +h3.categoryDescription { + margin-top: -20px; + margin-bottom: 40px; +} + + +/* Заголовки статей */ + +#headlines { + list-style: none; + padding-left: 0; + width: 75%; } -.footer { - position: absolute; - bottom: 0; - width: 100%; - height: 60px; /* Set the fixed height of the footer here */ - line-height: 60px; /* Vertically center the text there */ - background-color: #f5f5f5; + +#headlines li { + margin-bottom: 2em; } +.pubDate { + font-size: .8em; + color: #eb6841; + text-transform: uppercase; +} -/* Коилефт*/ -.copyleft { - -webkit-transform: scaleX(-1); - -moz-transform: scaleX(-1); - -o-transform: scaleX(-1); - -khtml-transform: scaleX(-1); - -ms-transform: scaleX(-1); - transform: scaleX(-1); - display: inline-block; +#headlines .pubDate { + display: inline-block; + width: 100px; + font-size: .5em; + vertical-align: middle; } +#headlines.archive .pubDate { + width: 130px; +} -.footer-link { - color: #17a2b8; +.summary { + padding-left: 100px; } +#headlines.archive .summary { + padding-left: 130px; +} +.category { + font-style: italic; + font-weight: normal; + font-size: 60%; + color: #999; + display: block; + line-height: 2em; +} +.category a { + color: #999; + text-decoration: underline; +} + +.showContent { + font-size : 14px; + float : right; +} + + +/* Заголовок для страницы администратора */ + +#adminHeader { + width: 940px; + padding: 0 10px; + border-bottom: 1px solid #00a0b0; + margin: -30px 0 40px 0; + font-size: 0.8em; +} + + +/* Стили для формы с цветным фоном, скругленными углами и тенью */ + +form { + margin: 20px auto; + padding: 40px 20px; + overflow: auto; + background: #fff4cf; + border: 1px solid #666; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + box-shadow: 0 0 .5em rgba(0, 0, 0, .8); +} + + +/* Задаем для элементов формы согласованные поля, отступы, и высоту строки */ + +form ul { + list-style: none; + margin: 0; + padding: 0; +} + +form ul li { + margin: .9em 0 0 0; + padding: 0; +} + +form * { + line-height: 1em; +} + + +/* Метки полей */ + +label { + display: block; + float: left; + clear: left; + text-align: right; + width: 15%; + padding: .4em 0 0 0; + margin: .15em .5em 0 0; +} + + +/* Поля */ + +input, select, textarea { + display: block; + margin: 0; + padding: .4em; + width: 80%; +} +input, textarea, .date { + border: 2px solid #666; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + background: #fff; +} + +input { + font-size: .9em; +} + +select { + padding: 0; + margin-bottom: 2.5em; + position: relative; + top: .7em; +} + +textarea { + font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; + font-size: .9em; + height: 5em; + line-height: 1.5em; +} + +textarea#content { + font-family: "Courier New", courier, fixed; +} + + +/* Рамка вокруг поля с фокусом ввода */ + +form *:focus { + border: 2px solid #7c412b; + outline: none; +} + + +/* Правильно заполненное поле имеет зеленый фон */ + +input:valid, textarea:valid { + background: #efe; +} + + +/* Кнопки отправки */ + +.buttons { + text-align: center; + margin: 40px 0 0 0; +} + +input[type="submit"] { + display: inline; + margin: 0 20px; + width: 12em; + padding: 10px; + border: 2px solid #7c412b; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + color: #fff; + background: #ef7d50; + font-weight: bold; + -webkit-appearance: none; +} + +input[type="submit"]:hover, input[type="submit"]:active { + cursor: pointer; + background: #fff; + color: #ef7d50; +} + +input[type="submit"]:active { + background: #eee; + -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; + -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; + box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; +} + + +/* Таблицы */ + +table { + width: 100%; + border-collapse: collapse; +} + +tr, th, td { + padding: 10px; + margin: 0; + text-align: left; +} + +table, th { + border: 1px solid #00a0b0; +} + +th { + border-left: none; + border-right: none; + background: #ef7d50; + color: #fff; + cursor: default; +} + +tr:nth-child(odd) { + background: #fff4cf; +} + +tr:nth-child(even) { + background: #fff; +} + +tr:hover { + background: #ddd; + cursor: pointer; +} + + +/* Окна для вывода статуса и сообщений об ошибках */ + +.statusMessage, .errorMessage { + font-size: .8em; + padding: .5em; + margin: 2em 0; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + -box-shadow: 0 0 .5em rgba(0, 0, 0, .8); +} + +.statusMessage { + background-color: #2b2; + border: 1px solid #080; + color: #fff; +} + +.errorMessage { + background-color: #f22; + border: 1px solid #800; + color: #fff; +} + +ul.ajax-load { + margin-left: 0px; + padding-left: 10px; +} +ul.ajax-load li { + display: inline; /* Отображать как строчный элемент */ + margin-right: 5px; /* Отступ слева */ + border: 1px solid #000; /* Рамка вокруг текста */ + padding: 3px; /* Поля вокруг текста */ + font-size: 12px; +} From 9bc12b9bcb4efa77fd90e6114e66e6f3e88f8405 Mon Sep 17 00:00:00 2001 From: Misha Semenov Date: Wed, 8 Jan 2025 19:46:20 +0300 Subject: [PATCH 4/7] fix --- application/CMSviews/admin/admin.php | 119 +++++++------- application/CMSviews/admin/edit/article.php | 8 +- application/CMSviews/admin/edit/category.php | 37 +++-- .../CMSviews/admin/edit/subcategory.php | 35 ++--- application/CMSviews/admin/edit/user.php | 67 ++++---- application/CMSviews/admin/listCategories.php | 65 ++++---- .../CMSviews/admin/listSubcategories.php | 5 +- application/CMSviews/admin/listUsers.php | 57 ++++--- application/CMSviews/homepage/archive.php | 23 +-- application/CMSviews/homepage/homepage.php | 54 +++---- .../CMSviews/homepage/singleArticle.php | 19 +-- .../CMSviews/homepage/viewArticleCategory.php | 34 ++++ .../homepage/viewArticleSubcategory.php | 35 +++++ .../CMSviews/layouts/includes/adminHeader.php | 11 +- .../CMSviews/layouts/includes/footer.php | 12 +- .../CMSviews/layouts/includes/header.php | 9 +- application/CMSviews/login/loginForm.php | 2 +- application/config/web.php | 11 +- application/controllers/AdminController.php | 4 +- .../controllers/HomepageController.php | 146 +++++++++++++++--- application/controllers/LoginController.php | 67 ++++---- application/models/AllUsers.php | 23 +++ application/models/Article.php | 113 +++++++++----- application/models/Category.php | 24 ++- application/models/Subcategory.php | 38 ++++- application/models/User.php | 84 +++++----- 26 files changed, 688 insertions(+), 414 deletions(-) create mode 100644 application/CMSviews/homepage/viewArticleCategory.php create mode 100644 application/CMSviews/homepage/viewArticleSubcategory.php diff --git a/application/CMSviews/admin/admin.php b/application/CMSviews/admin/admin.php index 9d374b4..67b60bd 100644 --- a/application/CMSviews/admin/admin.php +++ b/application/CMSviews/admin/admin.php @@ -1,88 +1,79 @@

All Articles

- -
- - + +
+ - -
- + +
+ - - - - - - - - - +
Publication DateArticleCategorySubcategoryAuthorsActive
+ + + + + + + + - - - - - + + - + - - + + - - + ?> + + + + + -
Publication DateArticleCategorySubcategoryAuthorsActive
publicationDate)?> +
publicationDate)?> title?> - - - - - - + categoryId)) { echo $results['categories'][$article->categoryId]->name; } else { - echo "Без категории"; - }?> - - subcategoryId)){ - echo $results['subcategories'][$article->subcategoryId]->name; - } - ?> - - authors); - $counter = 0; - foreach ($article->authors as $key => $author) { + echo "Без категории"; + } + ?> + + subcategoryId)){ + echo $results['subcategories'][$article->subcategoryId]->name; + } + ?> + + authors); + $counter = 0; + foreach ($article->authors as $key => $author) { ?> - - "> + - - activeArticle) { - echo 'Active'; - } else { - echo 'Not active'; - } - ?> -
+ activeArticle) { + echo 'Active'; + } else { + echo 'Not active'; + } + ?> +
- -

article in total.

+ -

Add a New Article

+

article in total.

- \ No newline at end of file +

Add a New Article

diff --git a/application/CMSviews/admin/edit/article.php b/application/CMSviews/admin/edit/article.php index 2907a08..2f46236 100644 --- a/application/CMSviews/admin/edit/article.php +++ b/application/CMSviews/admin/edit/article.php @@ -72,8 +72,8 @@ id) { ?> -

- Delete This Article - +

+ Delete This Article +

- \ No newline at end of file + diff --git a/application/CMSviews/admin/edit/category.php b/application/CMSviews/admin/edit/category.php index 4cb7b2c..17586c0 100644 --- a/application/CMSviews/admin/edit/category.php +++ b/application/CMSviews/admin/edit/category.php @@ -1,40 +1,39 @@

-
- - + + + -
+
-
    +
      -
    • +
    • -
    • + -
    • +
    • -
    • + -
    +
-
- - -
+
+ + +
-
+ - id ) { ?> -

+id ) { ?> +

Delete This Category

- + - diff --git a/application/CMSviews/admin/edit/subcategory.php b/application/CMSviews/admin/edit/subcategory.php index ee82eb5..d3bff91 100644 --- a/application/CMSviews/admin/edit/subcategory.php +++ b/application/CMSviews/admin/edit/subcategory.php @@ -1,35 +1,34 @@

Article Subcategories

-
+
- -
+
- - - - + + + + - + - - - - + + + + - +
Subcategory nameCategory name
Subcategory nameCategory name
- name ?> - - cat_name ?> -
+ name ?> + + cat_name ?> +

categor in total.

-

Add a New Subcategory

+

Add a New Subcategory

diff --git a/application/CMSviews/admin/edit/user.php b/application/CMSviews/admin/edit/user.php index bcfeb81..af96be8 100644 --- a/application/CMSviews/admin/edit/user.php +++ b/application/CMSviews/admin/edit/user.php @@ -1,42 +1,41 @@

Users

- -
- - - - -
- - - - - - - + +
+ + + +
+ + +
Имя пользователяАктивность
+ + + + + + + + + - - - - - - - + + -
Имя пользователяАктивность
+ name ?> +
- name?> - - active){ - echo 'Активен'; - }else{ - echo 'Неактивен'; - } - ?> -
+ active) { + echo 'Активен'; + } else { + echo 'Неактивен'; + } + ?> +
+ -

user in total.

+

user in total.

-

Add a New User

\ No newline at end of file +

Add a New User

diff --git a/application/CMSviews/admin/listCategories.php b/application/CMSviews/admin/listCategories.php index e1636fb..e308e33 100644 --- a/application/CMSviews/admin/listCategories.php +++ b/application/CMSviews/admin/listCategories.php @@ -1,33 +1,32 @@ -

Article Categories

- - -
- - - - -
- - - - - - - - - - - - - - - -
Category
- name?> -
- -

category in total.

- -

Add a New Category

- - +

Article Categories

+ + +
+ + + +
+ + + + + + + + + + + + + + + +
Category
+ name?> +
+ +

category in total.

+ +

Add a New Category

+ + diff --git a/application/CMSviews/admin/listSubcategories.php b/application/CMSviews/admin/listSubcategories.php index c168991..3ff8d91 100644 --- a/application/CMSviews/admin/listSubcategories.php +++ b/application/CMSviews/admin/listSubcategories.php @@ -4,7 +4,6 @@
-
@@ -17,7 +16,7 @@ - + name ?> @@ -32,4 +31,4 @@

categor in total.

-

Add a New Subcategory

\ No newline at end of file +

Add a New Subcategory

diff --git a/application/CMSviews/admin/listUsers.php b/application/CMSviews/admin/listUsers.php index bcfeb81..1a81c0d 100644 --- a/application/CMSviews/admin/listUsers.php +++ b/application/CMSviews/admin/listUsers.php @@ -1,42 +1,41 @@

Users

- -
- + +
+ + +
+ - -
- + + + + + -
Имя пользователяАктивность
- - - - - - - + - - - + + + + -
Имя пользователяАктивность
+
name?> - - active){ - echo 'Активен'; - }else{ - echo 'Неактивен'; - } - ?> -
+ active){ + echo 'Активен'; + }else{ + echo 'Неактивен'; + } + ?> +
+ -

user in total.

+

user in total.

-

Add a New User

\ No newline at end of file +

Add a New User

diff --git a/application/CMSviews/homepage/archive.php b/application/CMSviews/homepage/archive.php index a945b13..c1770f0 100644 --- a/application/CMSviews/homepage/archive.php +++ b/application/CMSviews/homepage/archive.php @@ -1,6 +1,6 @@ - - -

+

description ) ?>

@@ -15,15 +15,21 @@ publicationDate)?> - + title )?> - categoryId ) { ?> + subcategoryId ) { ?> + + in + + getById($results['subcategories'][$article->subcategoryId]->cat_id)->name ) ?> + + in - - categoryId]->name ) ?> + + subcategoryId]->name ) ?> @@ -37,5 +43,4 @@

article in total.

-

Return to Homepage

- \ No newline at end of file +

Return to Homepage

\ No newline at end of file diff --git a/application/CMSviews/homepage/homepage.php b/application/CMSviews/homepage/homepage.php index 76d2c01..69cd055 100644 --- a/application/CMSviews/homepage/homepage.php +++ b/application/CMSviews/homepage/homepage.php @@ -1,35 +1,36 @@ - -

- Article Archive - -

- - +

Article Archive

diff --git a/application/CMSviews/homepage/singleArticle.php b/application/CMSviews/homepage/singleArticle.php index 7d9c1a4..e203cd0 100644 --- a/application/CMSviews/homepage/singleArticle.php +++ b/application/CMSviews/homepage/singleArticle.php @@ -1,15 +1,16 @@

-
Authors:
-

Published on +

Subcategory:

+
+ Authors: + +
+ +

Published on

- - in subcategory - - name) ?> - -

-

Вернуться на главную страницу

\ No newline at end of file +

Return to Homepage

\ No newline at end of file diff --git a/application/CMSviews/homepage/viewArticleCategory.php b/application/CMSviews/homepage/viewArticleCategory.php new file mode 100644 index 0000000..6ba5dfa --- /dev/null +++ b/application/CMSviews/homepage/viewArticleCategory.php @@ -0,0 +1,34 @@ + +

+ description) ?> +

+ + + + +

article in total.

+

Return to Homepage

\ No newline at end of file diff --git a/application/CMSviews/homepage/viewArticleSubcategory.php b/application/CMSviews/homepage/viewArticleSubcategory.php new file mode 100644 index 0000000..9c1c05e --- /dev/null +++ b/application/CMSviews/homepage/viewArticleSubcategory.php @@ -0,0 +1,35 @@ + +

+ description) ?> +

+ + + + +

article in total.

+

Return to Homepage

\ No newline at end of file diff --git a/application/CMSviews/layouts/includes/adminHeader.php b/application/CMSviews/layouts/includes/adminHeader.php index 2700961..04da784 100644 --- a/application/CMSviews/layouts/includes/adminHeader.php +++ b/application/CMSviews/layouts/includes/adminHeader.php @@ -1,11 +1,10 @@ diff --git a/application/CMSviews/layouts/includes/footer.php b/application/CMSviews/layouts/includes/footer.php index 4750cc1..d656d26 100644 --- a/application/CMSviews/layouts/includes/footer.php +++ b/application/CMSviews/layouts/includes/footer.php @@ -1,8 +1,8 @@ - + -
- + + diff --git a/application/CMSviews/layouts/includes/header.php b/application/CMSviews/layouts/includes/header.php index d8bb1ff..2649e6e 100644 --- a/application/CMSviews/layouts/includes/header.php +++ b/application/CMSviews/layouts/includes/header.php @@ -1,6 +1,10 @@ + + + + <?php echo $title?> @@ -9,7 +13,4 @@
- - - - \ No newline at end of file + diff --git a/application/CMSviews/login/loginForm.php b/application/CMSviews/login/loginForm.php index 6bdd576..fc5f039 100644 --- a/application/CMSviews/login/loginForm.php +++ b/application/CMSviews/login/loginForm.php @@ -1,5 +1,5 @@ -
+ diff --git a/application/config/web.php b/application/config/web.php index eff5f9f..f01ca03 100644 --- a/application/config/web.php +++ b/application/config/web.php @@ -38,7 +38,16 @@ 'class' => ItForFree\SimpleMVC\Session::class, 'alias' => '@session' ], - 'homepageNumArticles' => 5 + 'subcategory' => [ // подсистема работы с сессиями + 'class' => \application\models\Subcategory::class + ], + + 'homepageNumArticles' => 5, + 'homepageNumSubcategories' => 5, + 'homepageNumArticlesPerSubcategory' =>5, + 'admin' => [ + 'username' => 'admin', // Укажите имя пользователя администратора + ] ] ]; diff --git a/application/controllers/AdminController.php b/application/controllers/AdminController.php index 051ec39..edbdccd 100644 --- a/application/controllers/AdminController.php +++ b/application/controllers/AdminController.php @@ -29,7 +29,7 @@ protected function getArticles(){ $this->results['subcategories'] = array(); foreach($this->results['subcategories'] as $subcategory){ $this->results['subcategories'][$subcategory->id] = $subcategory; - $this->results['categories'] [$subcategory->id] = $this->Category->getById($subcategory->cat_id); + $this->results['categories'] [$subcategory->id] = $this->Category->getById($subcategory->categoryId); } } public function indexAction(){ @@ -91,7 +91,7 @@ public function listSubcategoriesAction(){ $this->title = $this->results['pageTitle']; $this->view->addVar('title',$this->title); foreach ($this->results['subcategories'] as $subcategory) { - $category = $this->Category->getById($subcategory->cat_id); + $category = $this->Category->getById($subcategory->categoryId); $subcategory->cat_name = $category->name; } if (isset($_GET['error'])){ diff --git a/application/controllers/HomepageController.php b/application/controllers/HomepageController.php index c27c83f..95a2ad1 100644 --- a/application/controllers/HomepageController.php +++ b/application/controllers/HomepageController.php @@ -12,6 +12,7 @@ class HomepageController extends \ItForFree\SimpleMVC\MVC\Controller public string $layoutPath = 'main.php'; public $title = 'CMS на PHP'; public $articlesData = array(); + public $subcategoriesData = array(); public $results = array(); public $Article = null; public $Category = null; @@ -30,18 +31,35 @@ protected function initModelObjects(){ $this->Connection = new Connection(); $this->Users = new AllUsers(); } - protected function getArticles() - { - $this->results['articles'] = $this->articlesData['results']; - $this->results['totalRows'] = $this->articlesData['totalRows']; - $this->articlesData = $this->Subcategory->getList(); - $this->results['subcategories'] = array(); - foreach ( $this->articlesData['results'] as $subcategory ) { - $this->results['subcategories'][$subcategory->id] = $subcategory; - $this->results['categories'][$subcategory->id] = $this->Category-> - getById($subcategory->cat_id); - } + public function getArticles() { + $this->initModelObjects(); + $this->articlesData = $this->Article->getList(Config::get('core.homepageNumArticles')); + + $this->results['articles'] = $this->articlesData['results']; + $this->results['totalRows'] = $this->articlesData['totalRows']; + + $subcategoriesData = $this->Subcategory->getList(); + $categoriesData = $this->Category->getList(); + + $this->results['subcategories'] = array(); + $this->results['categories'] = array(); + + + foreach ($categoriesData['results'] as $category) { + $this->results['categories'][$category->id] = $category; + } + + + // Проходим по подкатегориям и получаем данные + foreach ($subcategoriesData['results'] as $subcategory) { + $this->results['subcategories'][$subcategory->id] = $subcategory; } +} + + + + + public function indexAction() { $this->initModelObjects(); @@ -49,7 +67,7 @@ public function indexAction() $this->getArticles(); foreach ($this->results['articles'] as $article) { - $article->content = substr($article->content,0,100) . ' ...'; + $article->content = substr($article->content,0,50) . ' ...'; } $this->view->addVar('title',$this->title); $this->view->addVar('results', $this->results); @@ -58,20 +76,24 @@ public function indexAction() public function viewArticleAction(){ $this->initModelObjects(); - $this->articlesData['id'] = $_GET['articleId']; + if (!isset($_GET['articleId']) || !is_numeric($_GET['articleId'])) { + throw new \Exception("Invalid or missing articleId in the request."); + } + $this->articlesData['id'] = (int) $_GET['articleId']; $SingleArticle = $this->Article->getById($this->articlesData['id']); $this->title = $SingleArticle->title . ' | ' . $this->title; - $this->results['article']['id'] = $SingleArticle->id; - $this->results['article']['title'] = $SingleArticle->title; - $this->results['article']['publicationDate'] = $SingleArticle->publicationDate; - $this->results['article']['subcategoryId'] = $SingleArticle->subcategoryId; - $this->results['article']['summary'] = $SingleArticle->summary; - $this->results['article']['content'] = $SingleArticle->content; - $this->results['article']['active'] = $SingleArticle->active; - $this->results['article']['subcategory'] = $this->Subcategory->getById( - $this->results['article']['subcategoryId']); + $this->results['article'] = [ + 'id' => $SingleArticle->id, + 'title' => $SingleArticle->title, + 'publicationDate' => $SingleArticle->publicationDate, + 'subcategoryId' => $SingleArticle->subcategoryId, + 'summary' => $SingleArticle->summary, + 'content' => $SingleArticle->content, + 'active' => $SingleArticle->active, + 'subcategory' => $this->Subcategory->getById($SingleArticle->subcategoryId) + ]; $connections = $this->Connection->getById($this->results['article']['id']); - $connectionsCount = count($connections); + $this->results['authors'] = []; foreach ($connections as $connection) { @@ -107,8 +129,8 @@ public function archiveCatAction() { $_GET['subcategoryId'] ) ? (int)$_GET['subcategoryId'] : null; $this->results['subcategory'] = $this->Subcategory->getById($subcategoryId); $this->results['category'] = $this->Category->getById( - $this->results['subcategory']->cat_id); - $data = $this->Subcategory->getList(100000,$this->results['subcategory']->cat_id); + $this->results['subcategory']->categoryId); + $data = $this->Subcategory->getList(100000,$this->results['subcategory']->categoryId); $articleArr = array(); foreach($data['results'] as $subcategory){ $articleArr[] = $this->Article->getList(100000, $subcategory->id, true); @@ -132,4 +154,78 @@ public function archiveCatAction() { $this->view->addVar('Category', $this->Category); $this->view->render('homepage/archive.php'); } + public function singleArticleAction() +{ + $this->initModelObjects(); + + if (empty($_GET['articleId'])) { + throw new InvalidArgumentException('ID статьи обязателен.'); + } + + $articleId = (int) $_GET['articleId']; + + $article = $this->Article->getById($articleId); + if (!$article) { + throw new NotFoundException('Статья не найдена.'); + } + $authorsData = $this->Article->getAuthors($articleId); + $authors = $authorsData['authors'] ?? 'Не указано'; + $this->title = $article->title . ' | ' . $this->title; + + $subcategory = $this->Subcategory->getById($article->subcategoryId); + $subcategoryName = $subcategory ? $subcategory->name : 'Подкатегория не указана'; + + $this->results['article'] = [ + 'id' => $article->id, + 'title' => $article->title, + 'publicationDate' => $article->publicationDate, + 'subcategoryId' => $article->subcategoryId, + 'summary' => $article->summary, + 'content' => $article->content, + 'active' => $article->active, + 'subcategory' => $subcategoryName, + 'authors' => $authors, + ]; + $this->view->addVar('results', $this->results); + $this->view->addVar('title', $this->title); + $this->view->render('homepage/singleArticle.php'); +} + +public function viewArticleSubcategoryAction() { + $this->initModelObjects(); + + $subcategoryId = isset($_GET['subcategoryId']) ? (int) $_GET['subcategoryId'] : null; + + if (!$subcategoryId) { + $this->view->addVar('title', 'Subcategory not found'); + $this->view->render('homepage/error.php'); + return; + } + $articlesData = $this->Article->getList(100, null, false, $subcategoryId); + + $this->results['articles'] = $articlesData['results']; + $this->results['totalRows'] = $articlesData['totalRows']; + $this->results['subcategory'] = $this->Subcategory->getById($subcategoryId); + + $this->view->addVar('title', $this->results['subcategory']->name ?? 'Articles'); + $this->view->addVar('results', $this->results); + $this->view->addVar('Subcategory', $this->Subcategory); + + $this->view->render('homepage/viewArticleSubcategory.php'); +} +public function viewArticleCategoryAction() +{ + $this->initModelObjects(); + $categoryId = isset($_GET['categoryId']) ? (int)$_GET['categoryId'] : null; + $articlesData = $this->Article->getList(100, null, false, $categoryId); + $this->results['articles'] = $articlesData['results']; + $this->results['totalRows'] = $articlesData['totalRows']; + $this->results['category'] = $this->Category->getById($categoryId); + $this->view->addVar('title', $this->results['category']->name ?? 'Articles'); + $this->view->addVar('results', $this->results); + $this->view->addVar('Category', $this->Category); + $this->view->render('homepage/viewArticleCategory.php'); +} + + } diff --git a/application/controllers/LoginController.php b/application/controllers/LoginController.php index 578d7c3..6ca2601 100644 --- a/application/controllers/LoginController.php +++ b/application/controllers/LoginController.php @@ -1,38 +1,53 @@ userName != null && $User->userName != 'guest'){ - $this->redirect(Url::link("Admin/index")); - }elseif (!empty($_POST)) { - $login = $_POST['userName']; - $pass = $_POST['password']; - if($User->login($login, $pass)) { - $this->redirect(Url::link("Admin/index")); - } else { - $this->redirect(Url::link("Login/login&auth=deny")); - } + + public function loginAction() { + $User = Config::getObject('core.user.class'); + + // Проверка, если пользователь уже авторизован + if (isset($_SESSION['user']) && $_SESSION['user'] != 'guest') { + $this->redirect(WebRouter::link("Admin/index")); + } + + if (!empty($_POST)) { + $login = $_POST['login']; + $pass = $_POST['password']; + + // Пытаемся выполнить вход с использованием checkAuthData + if ($User->checkAuthData($login, $pass)) { + // Успешный вход, сохраняем информацию в сессии + $_SESSION['user'] = $login; // Можно сохранить логин или другие данные пользователя + $this->redirect(WebRouter::link("Admin/index")); + } else { + // Неудачный вход, передаем сообщение в сессию + $_SESSION['errorMessage'] = $this->errorMessage; + $this->redirect(WebRouter::link("Login/login")); // Перенаправление на страницу входа } - else { - $this->view->addVar('errorMessage', $this->errorMessage); - $this->view->addVar('title', $this->title); - $this->view->render('login/loginForm.php'); + } else { + // Передаем ошибки и заголовок в представление + if (isset($_SESSION['errorMessage'])) { + $this->view->addVar('errorMessage', $_SESSION['errorMessage']); + unset($_SESSION['errorMessage']); } + + $this->view->addVar('title', $this->title); + $this->view->render('login/loginForm.php'); } - public function logoutAction() - { - $User = Config::getObject('core.user.class'); - $User->logout(); - $this->redirect(Url::link("Login/login")); - } - +} + +public function logoutAction() { + // Очищаем сессию при выходе + session_destroy(); + $this->redirect(WebRouter::link("Login/login")); +} + } diff --git a/application/models/AllUsers.php b/application/models/AllUsers.php index 486744f..76ca2f2 100644 --- a/application/models/AllUsers.php +++ b/application/models/AllUsers.php @@ -104,6 +104,29 @@ public function delete():void{ // $st->bindValue(":id", $this->$id,PDO::PARAM_INT); // $st->execute(); } + public function getAuthData($login): ?array { + $sql = "SELECT pass FROM users WHERE login = :login"; + $st = $this->pdo->prepare($sql); + $st->bindValue(":login", $login, \PDO::PARAM_STR); + $st->execute(); + return $st->fetch(); // Возвращаем только данные для пароля + } + + public function checkAuthData($login, $password): bool { + $sql = "SELECT pass FROM users WHERE login = :login"; + $st = $this->pdo->prepare($sql); + $st->bindValue(":login", $login, \PDO::PARAM_STR); + $st->execute(); + $authData = $st->fetch(); + + // Проверяем, совпадает ли пароль + if ($authData && password_verify($password, $authData['pass'])) { + return true; + } else { + return false; + } + } + diff --git a/application/models/Article.php b/application/models/Article.php index 77e18e3..2a70b29 100644 --- a/application/models/Article.php +++ b/application/models/Article.php @@ -10,9 +10,11 @@ class Article extends \ItForFree\SimpleMVC\MVC\Model public $title = null; public $subcategoryId = null; public $summary = null; + public $categoryId = null; public $content = null; public $active = null; public $articleId = null; + public $autors = null; public function storeFormValues ( $params ) { // Сохраняем все параметры @@ -34,36 +36,64 @@ public function storeFormValues ( $params ) { } } - public function getById(int $id, string $tableName = ''): ?Model { + public function getById(int $id, string $tableName = ''): ?Model + { $tableName = !empty($tableName) ? $tableName : $this->tableName; - $sql = "SELECT * FROM $tableName WHERE id = :id"; - $st = $this->pdo->prepare($sql); - $st->bindValue(":id", $id, PDO::PARAM_INT); + + $sql = "SELECT * FROM $tableName where id = :id"; + $modelClassName = static::class; + + $st = $this->pdo->prepare($sql); + + $st->bindValue(":id", $id, \PDO::PARAM_INT); $st->execute(); $row = $st->fetch(); - if ($row) { - return new static($row); + + if ($row) { + return new $modelClassName( $row ); + } else { + return null; } - return null; } - public function getList($numRows=1000000, $categoryId = null, $isSubcategory = null, $order = "publicationDate DESC") :array + public function getList($numRows=1000000, $categoryId = null, $useActiveValue = false,$subcategoryId = null,$authorsId = null, $order = "publicationDate DESC") :array { - if (!$isSubcategory) { - $categoryClause = $categoryId ? "WHERE categoryId = $categoryId" : ""; - } else { - $categoryClause = $categoryId ? "WHERE subcategoryId = $categoryId" : ""; - } - - if ($categoryClause) { - $onlyActive = $numRows < 1000000 ? "AND active = 1" : ""; - } else { - $onlyActive = $numRows < 1000000 ? "WHERE active = 1" : ""; - } + if($useActiveValue === false) { + if($categoryId) { + $categoryClause = "WHERE categoryId = :categoryId"; + } elseif($subcategoryId) { + $categoryClause = "wHERE subcategoryId = $subcategoryId"; + } else { + $categoryClause= ""; + } + } else { + if($categoryId) { + $categoryClause = "WHERE categoryId = :categoryId " + . "AND active = $useActiveValue"; + } elseif($subcategoryId) { + $categoryClause = "WHERE subcategoryId = $subcategoryId " + . "AND active = $useActiveValue"; + } elseif($author){ + $categoryClause = "WHERE user = $author " + . "AND active = $useActiveValue"; + + } + else { + $categoryClause = "WHERE active = " . $useActiveValue; + } + } - $sql = "SELECT SQL_CALC_FOUND_ROWS *, UNIX_TIMESTAMP(publicationDate) - AS publicationDate - FROM articles $categoryClause $onlyActive - ORDER BY $order LIMIT :numRows"; + $sql = "SELECT SQL_CALC_FOUND_ROWS a.*, + UNIX_TIMESTAMP(a.publicationDate) AS publicationDate, + GROUP_CONCAT(users.login SEPARATOR ', ') AS users_login + FROM articles AS a + LEFT JOIN users_article AS t1 ON a.id = t1.articles + LEFT JOIN users ON users.id = t1.user + $categoryClause + GROUP BY a.id + ORDER BY $order + LIMIT :numRows"; + + $modelClassName = static::class; @@ -77,10 +107,26 @@ public function getList($numRows=1000000, $categoryId = null, $isSubcategory = n $list[] = $example; } - $sql = "SELECT FOUND_ROWS() AS totalRows"; // получаем число выбранных строк + $sql = "SELECT FOUND_ROWS() AS totalRows"; $totalRows = $this->pdo->query($sql)->fetch(); return (array ("results" => $list, "totalRows" => $totalRows[0])); } + public function getAuthors($articleId): array +{ + $sql = " + SELECT GROUP_CONCAT(users.login SEPARATOR ', ') AS users_name + FROM users + JOIN users_article ON users.id = users_article.user + WHERE users_article.articles = 1 + "; + $st = $this->pdo->prepare($sql); + $st->execute(); + $result = $st->fetch(); + return ['authors' => $result['users_name'] ?? '']; +} + + + public function insert() { // Есть уже у объекта Article ID? @@ -88,7 +134,7 @@ public function insert() { // Вставляем статью $sql = "INSERT INTO articles ( publicationDate, categoryId,subcategoryId ,title, summary, content, active ) VALUES ( FROM_UNIXTIME(:publicationDate), :categoryId,:subcategoryId ,:title, :summary, :content, :active )"; - $st = $conn->prepare ( $sql ); + $st = $this->pdo->prepare ( $sql ); $st->bindValue( ":publicationDate", $this->publicationDate, PDO::PARAM_INT ); $st->bindValue( ":categoryId", $this->categoryId, PDO::PARAM_INT ); $st->bindValue( ":subcategoryId", $this->subcategoryId, PDO::PARAM_INT ); @@ -97,13 +143,13 @@ public function insert() { $st->bindValue( ":content", $this->content, PDO::PARAM_STR ); $st->bindValue( ":active", $this->activeArticle, PDO::PARAM_INT); $st->execute(); - $this->id = $conn->lastInsertId(); - $st = $conn->prepare($sql); + $this->id = $this->pdo->lastInsertId(); + $st = $this->pdo->prepare($sql); $st->bindValue(":id", $this->id, PDO::PARAM_INT); $st->execute(); foreach ($this->authors as $user) { $sql = "INSERT INTO users_article (user, article) VALUES (:user, :id)"; - $st = $conn->prepare($sql); + $st = $this->pdo->prepare($sql); $st->bindValue(":user", $user, PDO::PARAM_INT); $st->bindValue(":id", $this->id, PDO::PARAM_INT); @@ -112,8 +158,6 @@ public function insert() { error_log("Error inserting into users_article: " . implode(", ", $st->errorInfo())); } } - - $conn = null; } /** @@ -131,7 +175,7 @@ public function update() . " categoryId=:categoryId, subcategoryId=:subcategoryId," . " title=:title, summary=:summary, content=:content," . " active=:active WHERE id = :id"; - $st = $conn->prepare($sql); + $st = $this->pdo->prepare($sql); $st->bindValue(":publicationDate", $this->publicationDate, PDO::PARAM_INT); $st->bindValue(":categoryId", $this->categoryId, PDO::PARAM_INT); $st->bindValue(":subcategoryId", $this->subcategoryId, PDO::PARAM_INT); @@ -142,7 +186,7 @@ public function update() $st->bindValue(":active", $this->activeArticle, PDO::PARAM_INT); $st->execute(); $sql = "DELETE FROM users_article WHERE articles = :id"; - $st = $conn->prepare($sql); + $st = $this->pdo->prepare($sql); $st->bindValue(":id", $this->id, PDO::PARAM_INT); $st->execute(); foreach ($this->authors as $author) { @@ -152,7 +196,6 @@ public function update() $st->bindValue(":id", $this->id, PDO::PARAM_INT); $st->execute(); } - $conn = null; } @@ -165,10 +208,10 @@ public function delete() : void { if ( is_null( $this->id ) ) trigger_error ( "Article::delete(): Attempt to delete an Article object that does not have its ID property set.", E_USER_ERROR ); // Удаляем статью - $st = $conn->prepare ( "DELETE FROM articles WHERE id = :id LIMIT 1" ); + $st = $this->pdo->prepare ( "DELETE FROM articles WHERE id = :id LIMIT 1" ); $st->bindValue( ":id", $this->id, PDO::PARAM_INT ); $st->execute(); - $st = $conn->prepare("DELETE FROM users_article WHERE article = :id"); + $st = $this->pdo->prepare("DELETE FROM users_article WHERE article = :id"); $st->bindValue(":id", $this->id, PDO::PARAM_INT); $st->execute(); } diff --git a/application/models/Category.php b/application/models/Category.php index fad7dac..8f0f6ac 100644 --- a/application/models/Category.php +++ b/application/models/Category.php @@ -16,6 +16,25 @@ class Category extends \ItForFree\SimpleMVC\MVC\Model public function storeFormValues ($param){ $this->__construct( $params ); } + public function getById(int $id, string $tableName = ''): ?Model + { + $tableName = !empty($tableName) ? $tableName : $this->tableName; + + $sql = "SELECT * FROM $tableName where id = :id"; + $modelClassName = static::class; + + $st = $this->pdo->prepare($sql); + + $st->bindValue(":id", $id, \PDO::PARAM_INT); + $st->execute(); + $row = $st->fetch(); + + if ($row) { + return new $modelClassName( $row ); + } else { + return null; + } + } public function getList($numRows=100000,$order="name ASC"):array { $sql = "SELECT * FROM categories ORDER BY $order LIMIT :numRows"; $st = $this->pdo->prepare($sql); @@ -28,7 +47,10 @@ public function getList($numRows=100000,$order="name ASC"):array { } $sql = "SELECT FOUND_ROWS() AS totalRows"; $totalRows = $this->pdo->query($sql)->fetch(); - return (array("results" => $list, "totalRows" => $totalRows[0])); + return [ + "results" => $list, + "totalRows" => $totalRows['totalRows'] + ]; } public function insert($tableName = ''){ $tableName = !empty($tableName) ? $tableName : $this->tableName; diff --git a/application/models/Subcategory.php b/application/models/Subcategory.php index 8a49ab3..67b2602 100644 --- a/application/models/Subcategory.php +++ b/application/models/Subcategory.php @@ -9,13 +9,14 @@ class Subcategory extends \ItForFree\SimpleMVC\MVC\Model public string $tableName = 'subcategories'; public ?int $id = null; public $name = null; - public $cat_id = null; + public $description = null; + public $categoryId = null; public function storeFormValues($params){ $this->__construct( $params ); } public function getList($numRows = 1000000, $categoryId = null, $order = "name ASC") : array { - $categoryClause = $categoryId !== null ? "WHERE cat_id = :categoryId" : ""; + $categoryClause = $categoryId !== null ? "WHERE categoryId = :categoryId" : ""; $sql = "SELECT * FROM $this->tableName $categoryClause ORDER BY $order LIMIT :numRows"; $st = $this->pdo->prepare($sql); $st->bindValue(":numRows", $numRows, \PDO::PARAM_INT); @@ -40,11 +41,32 @@ public function getList($numRows = 1000000, $categoryId = null, $order = "name A "totalRows" => $totalRows['totalRows'] ]; } - + + #[\Override] + public function getById(int $id, string $tableName = ''): ?Model + { + $tableName = !empty($tableName) ? $tableName : $this->tableName; + + $sql = "SELECT * FROM $tableName where id = :id"; + $modelClassName = static::class; + + $st = $this->pdo->prepare($sql); + + $st->bindValue(":id", $id, \PDO::PARAM_INT); + $st->execute(); + $row = $st->fetch(); + + if ($row) { + return new $modelClassName( $row ); + } else { + return null; + } + } + public function getCategIdByName($name){ $sql = "SELECT id FROM categories WHERE name = :name "; $st = $this->pdo->prepare($sql); - $st->bindValue(":name", $name, PDO::PARAM_STR); + $st->bindValue(":name", $name, \PDO::PARAM_STR); $st->execute(); $row = $st->fetch(); $conn = null; @@ -66,10 +88,10 @@ public function insert(){ . "Attempt to insert a Subcategory object that already has its " . "ID property set (to $this->id).", E_USER_ERROR ); //Вставляем субкатегорию - $sql = "INSERT INTO $this->tableName(name, cat_id) VALUES(:name, :cat_id)"; + $sql = "INSERT INTO $this->tableName(name, categoryId) VALUES(:name, :categoryId)"; $st = $this->pdo->prepare($sql); $st->bindValue(":name", $this->name, \PDO::PARAM_STR ); - $st->bindValue(":cat_id", $this->cat_id, \PDO::PARAM_INT ); + $st->bindValue(":categoryId", $this->categoryId, \PDO::PARAM_INT ); $st->execute(); $this->id = $this->pdo->lastInsertId(); } @@ -78,10 +100,10 @@ public function update(){ if ( is_null( $this->id ) ) trigger_error ( "Subcategory::insert(): " . "Attempt to insert a Subcategory object that does not have its " . "ID property set (to $this->id).", E_USER_ERROR ); - $sql = "UPDATE $this->tableName SET name=:name, cat_id=:cat_id WHERE id=:id"; + $sql = "UPDATE $this->tableName SET name=:name, categoryId=:categoryId WHERE id=:id"; $st = $this->pdo->prepare($sql); $st->bindValue(":name", $this->name, \PDO::PARAM_STR); - $st->bindValue(":cat_id", $this->cat_id, \PDO::PARAM_INT); + $st->bindValue(":categoryId", $this->categoryId, \PDO::PARAM_INT); $st->bindValue(":id", $this->id, \PDO::PARAM_INT); $st->execute(); } diff --git a/application/models/User.php b/application/models/User.php index 9c22301..77b3636 100644 --- a/application/models/User.php +++ b/application/models/User.php @@ -1,55 +1,43 @@ pdo->prepare($sql); - $query->bindValue( ":name", $login, \PDO::PARAM_STR); - $query->execute(); - $truePass = $query->fetch(); - if($truePass[0] == $pass){ - $result = true; - } - } - return $result; - } -} \ No newline at end of file + public string $tableName = 'users'; + public string $orderBy = 'name ASC'; + + protected function getRoleByUserName(string $userName): string { + if( $userName == Config::get('core.admin.username') ){ + return $userName; + } else { + return "authorized"; + } + } + protected function checkAuthData(string $login, string $pass): bool + { + $result = false; + + if ($login == Config::get('core.admin.username')) { + // Проверка для админа + if ($pass == Config::get('core.admin.password')) { + $result = true; + } + } else { + // Проверка для обычного пользователя + $sql = "SELECT pass, active FROM users WHERE name = :name;"; + $query = $this->pdo->prepare($sql); + $query->bindValue(":name", $login, \PDO::PARAM_STR); + $query->execute(); + $truePass = $query->fetch(); + if ($truePass && $truePass['pass'] == $pass && $truePass['active'] == 1) { + $result = true; // Учет поля активного пользователя + } + } + + return $result; + } +} From 6b3072ff11eeb3df7e1ce170ca9b61b2076ce511 Mon Sep 17 00:00:00 2001 From: Misha Semenov Date: Sat, 11 Jan 2025 15:24:32 +0300 Subject: [PATCH 5/7] fix authors --- application/CMSviews/admin/admin.php | 4 +- application/CMSviews/homepage/archive.php | 1 - application/CMSviews/homepage/homepage.php | 135 +++++++++--------- .../CMSviews/homepage/singleArticle.php | 2 +- .../CMSviews/homepage/viewArticleAuthors.php | 23 +++ application/controllers/AdminController.php | 21 ++- .../controllers/HomepageController.php | 24 +++- application/models/AllUsers.php | 69 +++++---- application/models/Article.php | 135 +++++++++++------- application/models/Connection.php | 2 +- 10 files changed, 252 insertions(+), 164 deletions(-) create mode 100644 application/CMSviews/homepage/viewArticleAuthors.php diff --git a/application/CMSviews/admin/admin.php b/application/CMSviews/admin/admin.php index 67b60bd..7ada8af 100644 --- a/application/CMSviews/admin/admin.php +++ b/application/CMSviews/admin/admin.php @@ -28,7 +28,7 @@ categoryId)) { - echo $results['categories'][$article->categoryId]->name; + echo $results['category'][$article->categoryId]; } else { echo "Без категории"; @@ -38,7 +38,7 @@ subcategoryId)){ - echo $results['subcategories'][$article->subcategoryId]->name; + echo $results['subcategory'][$article->subcategoryId]; } ?> diff --git a/application/CMSviews/homepage/archive.php b/application/CMSviews/homepage/archive.php index c1770f0..f8692a9 100644 --- a/application/CMSviews/homepage/archive.php +++ b/application/CMSviews/homepage/archive.php @@ -1,5 +1,4 @@

diff --git a/application/CMSviews/homepage/homepage.php b/application/CMSviews/homepage/homepage.php index 69cd055..4e55534 100644 --- a/application/CMSviews/homepage/homepage.php +++ b/application/CMSviews/homepage/homepage.php @@ -1,74 +1,81 @@ -
  • - -

    - - publicationDate)?> +foreach ($results['articles'] as $article) { +?> +
  • + +

    + + publicationDate)?> + + + + title )?> + + + categoryId) && array_key_exists($article->categoryId, $results['categories'])) { ?> + + Категория + + categoryId]->name) ?> + + + + + + - - title )?> - + subcategoryId) && array_key_exists($article->subcategoryId, $results['subcategories'])) { ?> + + Подкатегория + + subcategoryId]->name)?> + + + + + + + - categoryId) && array_key_exists($article->categoryId, $results['categories'])) { ?> - - Категория - - categoryId]->name) ?> - - - - - - - + id) && isset($results['authors'][$article->id]) && !empty($results['authors'][$article->id])) { ?> + + Авторы: + id]; + $authorsLinks = []; + // Проверяем, если это не пустой массив + if (is_array($authors)) { + // Проходим по авторам и выводим их ссылки + foreach ($authors as $authorId => $authorLogin) { + $authorsLinks[] = '' . htmlspecialchars($authorLogin) . ''; + } + } else { + // Если авторов всего один, просто добавляем ссылку для него + $authorsLinks[] = '' . htmlspecialchars($authors) . ''; + } - subcategoryId) && array_key_exists($article->subcategoryId, $results['subcategories'])) { ?> - - Подкатегория - - subcategoryId]->name)?> - + echo implode(', ', $authorsLinks); + ?> - - - - - - authors)) { ?> - - Авторы: - authors); - $counter = 0; - foreach($article->authors as $key =>$author){ ?> - - - - - -

    - -

    content)?>

    - gif - + + +
  • + +

    content)?>

    + gif + - Показать полностью -
  • - + Показать полностью + +

    Article Archive

    diff --git a/application/CMSviews/homepage/singleArticle.php b/application/CMSviews/homepage/singleArticle.php index e203cd0..4dd6f12 100644 --- a/application/CMSviews/homepage/singleArticle.php +++ b/application/CMSviews/homepage/singleArticle.php @@ -1,5 +1,5 @@

    -
    +

    Subcategory:

    diff --git a/application/CMSviews/homepage/viewArticleAuthors.php b/application/CMSviews/homepage/viewArticleAuthors.php new file mode 100644 index 0000000..f4023b5 --- /dev/null +++ b/application/CMSviews/homepage/viewArticleAuthors.php @@ -0,0 +1,23 @@ + +

    Статьи автора login)?>

    +
      + + +
    • +

      + + publicationDate)?> + + + title)?> + +

      +

      summary)?>

      +
    • + +
    +

    article in total.

    +

    Return to Homepage

    + diff --git a/application/controllers/AdminController.php b/application/controllers/AdminController.php index edbdccd..494f28a 100644 --- a/application/controllers/AdminController.php +++ b/application/controllers/AdminController.php @@ -4,6 +4,9 @@ use ItForFree\SimpleMVC\Url; use application\models\Article; use application\models\AllUsers; +use application\models\Category; +use application\models\Subcategory; +use application\models\Connection; class AdminController extends \ItForFree\SimpleMVC\MVC\Controller { public $articlesData = array(); @@ -24,13 +27,19 @@ protected function initModelObjects(){ protected function getArticles(){ $this->articlesData = $this->Article->getList(); $this->results['articles'] = $this->articlesData['results']; - $this->results['totalRows'] = $this->artcilesData['totalRows']; - $this->articlesData = $this->Subcategory->getList(); - $this->results['subcategories'] = array(); - foreach($this->results['subcategories'] as $subcategory){ - $this->results['subcategories'][$subcategory->id] = $subcategory; - $this->results['categories'] [$subcategory->id] = $this->Category->getById($subcategory->categoryId); + $this->results['totalRows'] = $this->articlesData['totalRows']; + + $categoriesData = $this->Category->getList(); + foreach ($categoriesData['results'] as $category){ + $this->results['category'][$category->id] = $category->name; } + + $subcategoryData = $this->Subcategory->getList(); + foreach($subcategoryData['results'] as $subcategory){ + $this->results['subcategory'][$subcategory->id] = $subcategory->name; + $this->results['categories']['$subcategory->id'] = $this->Category->getById($subcategory->categoryId); + } + } public function indexAction(){ $this->initModelObjects(); diff --git a/application/controllers/HomepageController.php b/application/controllers/HomepageController.php index 95a2ad1..8f7cad8 100644 --- a/application/controllers/HomepageController.php +++ b/application/controllers/HomepageController.php @@ -40,20 +40,24 @@ public function getArticles() { $subcategoriesData = $this->Subcategory->getList(); $categoriesData = $this->Category->getList(); + $this->results['subcategories'] = array(); $this->results['categories'] = array(); - + $this->results['authors'] = array(); foreach ($categoriesData['results'] as $category) { $this->results['categories'][$category->id] = $category; } - - + // Проходим по подкатегориям и получаем данные foreach ($subcategoriesData['results'] as $subcategory) { $this->results['subcategories'][$subcategory->id] = $subcategory; } + foreach ($this->articlesData['results'] as $article) { + $authorsData = $this->Article->getAuthors($article->id); // Получаем авторов для статьи + $this->results['authors'][$article->id] = $authorsData['authors']; // Сохраняем авторов по ID статьи + } } @@ -226,6 +230,18 @@ public function viewArticleCategoryAction() $this->view->addVar('Category', $this->Category); $this->view->render('homepage/viewArticleCategory.php'); } - +public function viewArticleAuthorsAction() +{ + $this->initModelObjects(); + $authorsId = isset($_GET['authorsId']) ? (int)($_GET['authorsId']) : null; + $articlesData = $this->Article->getList(100,null,false,$authorsId); + $this->results['articles'] = $articlesData['results']; + $this->results['totalRows'] = $articlesData['totalRows']; + $this->results['authors'] = $this->Users->getById($authorsId); + $this->view->addVar('title', $this->results['authors']->login ?? 'Articles' ); + $this->view->addVar('results', $this->results); + $this->view->addVar('Users', $this->Category); + $this->view->render('homepage/viewArticleAuthors.php'); +} } diff --git a/application/models/AllUsers.php b/application/models/AllUsers.php index 76ca2f2..66dfae6 100644 --- a/application/models/AllUsers.php +++ b/application/models/AllUsers.php @@ -19,7 +19,7 @@ class AllUsers extends \ItForFree\SimpleMVC\MVC\Model /** * @var int ID пользователя из базы данных */ -public ?int $id = null; + public ?int $id = null; /** * @var string Логин пользователя @@ -47,27 +47,27 @@ public function isUserExist($login){ return false; } } - public function storeFormValues($params){ - $this->__construct( $params ); - } - public function getList($numRows=1000000):array - { - $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM users"; - $st = $this->pdo->query($sql); - $list = array (); - while ($row = $st->fetch()){ - $user = new User($row); - $list[] = $user; + public function storeFormValues($params){ + $this->__construct( $params ); } - $sql = "SELECT FOUND_ROWS() AS totalRows"; - $totalRows = $this->pdo->query($sql)->fetch(); - $conn = null; - return (array( - "results" =>$list, - "totalRows" => $totalRows[0] - ) - ); - } + + public function getList($numRows=1000000):array + { + $sql = "SELECT * FROM users"; + $st = $this->pdo->query($sql); + $list = array (); + while ($row = $st->fetch()){ + $user = new AllUsers($row); + $list[] = $user; + } + $sql = "SELECT FOUND_ROWS() AS totalRows"; + $totalRows = $this->pdo->query($sql)->fetch(); + return (array( + "results" =>$list, + "totalRows" => $totalRows[0] + ) + ); + } public function insert(){ $sql = "INSERT INTO users(login, password, active) VALUES(:login, :password, :active)"; $st = $this->pdo->prepare($sql); @@ -86,16 +86,25 @@ public function update() { $st->bindValue( ":id", $this->userId, \PDO::PARAM_INT ); $st->execute(); } - public function getById(int $id, string $tableName = ''): ?Model{ - $sql = "SELECT * FROM users WHERE id = :id "; - $st = $this->pdo->prepare($sql); - $st->bindValue(":id",$id,PDO::PARAM_INT); - $st->execute(); - $row = $st->fetch(); - if ($row){ - return new User($row); - } + public function getById(int $id, string $tableName = ''): ?Model + { + $tableName = !empty($tableName) ? $tableName : $this->tableName; + + $sql = "SELECT * FROM $tableName where id = :id"; + $modelClassName = static::class; + + $st = $this->pdo->prepare($sql); + + $st->bindValue(":id", $id, \PDO::PARAM_INT); + $st->execute(); + $row = $st->fetch(); + + if ($row) { + return new $modelClassName( $row ); + } else { + return null; } + } public function delete():void{ $st = $this->pdo->prepare("DELETE FROM users WHERE login = :login LIMIT 1"); $st->bindValue(":login",$this->login,PDO::PARAM_STR); diff --git a/application/models/Article.php b/application/models/Article.php index 2a70b29..8951e59 100644 --- a/application/models/Article.php +++ b/application/models/Article.php @@ -6,6 +6,7 @@ class Article extends \ItForFree\SimpleMVC\MVC\Model { public string $tableName = 'articles'; + public $articleId = null; public $publicationDate = null; public $title = null; public $subcategoryId = null; @@ -13,8 +14,8 @@ class Article extends \ItForFree\SimpleMVC\MVC\Model public $categoryId = null; public $content = null; public $active = null; - public $articleId = null; - public $autors = null; + public $authors = null; + public function storeFormValues ( $params ) { // Сохраняем все параметры @@ -55,71 +56,95 @@ public function getById(int $id, string $tableName = ''): ?Model return null; } } - public function getList($numRows=1000000, $categoryId = null, $useActiveValue = false,$subcategoryId = null,$authorsId = null, $order = "publicationDate DESC") :array - { - if($useActiveValue === false) { - if($categoryId) { - $categoryClause = "WHERE categoryId = :categoryId"; - } elseif($subcategoryId) { - $categoryClause = "wHERE subcategoryId = $subcategoryId"; - } else { - $categoryClause= ""; - } - } else { - if($categoryId) { - $categoryClause = "WHERE categoryId = :categoryId " - . "AND active = $useActiveValue"; - } elseif($subcategoryId) { - $categoryClause = "WHERE subcategoryId = $subcategoryId " - . "AND active = $useActiveValue"; - } elseif($author){ - $categoryClause = "WHERE user = $author " - . "AND active = $useActiveValue"; - - } - else { - $categoryClause = "WHERE active = " . $useActiveValue; - } - } - - $sql = "SELECT SQL_CALC_FOUND_ROWS a.*, - UNIX_TIMESTAMP(a.publicationDate) AS publicationDate, - GROUP_CONCAT(users.login SEPARATOR ', ') AS users_login - FROM articles AS a - LEFT JOIN users_article AS t1 ON a.id = t1.articles - LEFT JOIN users ON users.id = t1.user - $categoryClause - GROUP BY a.id - ORDER BY $order - LIMIT :numRows"; + public function getList( + $numRows = 1000000, + $categoryId = null, + $useActiveValue = false, + $subcategoryId = null, + $authorsId = null, + $order = "publicationDate DESC" +): array { + // Формируем условия WHERE + $conditions = []; + if ($useActiveValue !== false) { + $conditions[] = "a.active = :active"; + } + if ($categoryId) { + $conditions[] = "a.categoryId = :categoryId"; + } + if ($subcategoryId) { + $conditions[] = "a.subcategoryId = :subcategoryId"; + } + if ($authorsId) { + $conditions[] = "t1.user = :authorsId"; + } + $categoryClause = $conditions ? "WHERE " . implode(" AND ", $conditions) : ""; + // SQL-запрос + $sql = "SELECT SQL_CALC_FOUND_ROWS a.*, + UNIX_TIMESTAMP(a.publicationDate) AS publicationDate, + GROUP_CONCAT(authors.login SEPARATOR ', ') AS authors_login + FROM articles AS a + LEFT JOIN users_article AS t1 ON a.id = t1.articles + LEFT JOIN users AS authors ON authors.id = t1.user + $categoryClause + GROUP BY a.id + ORDER BY $order + LIMIT :numRows"; + + // Подготовка и выполнение запроса + $st = $this->pdo->prepare($sql); + if ($useActiveValue !== false) { + $st->bindValue(":active", $useActiveValue, \PDO::PARAM_INT); + } + if ($categoryId) { + $st->bindValue(":categoryId", $categoryId, \PDO::PARAM_INT); + } + if ($subcategoryId) { + $st->bindValue(":subcategoryId", $subcategoryId, \PDO::PARAM_INT); + } + if ($authorsId) { + $st->bindValue(":authorsId", $authorsId, \PDO::PARAM_INT); + } + $st->bindValue(":numRows", $numRows, \PDO::PARAM_INT); + $st->execute(); - + // Формируем список результатов + $list = []; + while ($row = $st->fetch()) { $modelClassName = static::class; - - $st = $this->pdo->prepare($sql); - $st->bindValue( ":numRows", $numRows, \PDO::PARAM_INT ); - $st->execute(); - $list = array(); - - while ($row = $st->fetch()) { - $example = new $modelClassName($row); - $list[] = $example; + $example = new $modelClassName($row); + // Добавляем авторов как массив + if (isset($row['authors_login']) && !empty($row['authors_login'])) { + $example->authors = explode(', ', $row['authors_login']); + } else { + $example->authors = []; } - - $sql = "SELECT FOUND_ROWS() AS totalRows"; - $totalRows = $this->pdo->query($sql)->fetch(); - return (array ("results" => $list, "totalRows" => $totalRows[0])); + $list[] = $example; } - public function getAuthors($articleId): array + + // Получаем общее количество строк + $sql = "SELECT FOUND_ROWS() AS totalRows"; + $totalRows = $this->pdo->query($sql)->fetch(); + + // Возвращаем массив с результатами и количеством строк + return [ + "results" => $list, + "totalRows" => $totalRows[0] + ]; +} + + + public function getAuthors($articleId): array { $sql = " SELECT GROUP_CONCAT(users.login SEPARATOR ', ') AS users_name FROM users JOIN users_article ON users.id = users_article.user - WHERE users_article.articles = 1 + WHERE users_article.articles = :articleId "; $st = $this->pdo->prepare($sql); + $st->bindValue(':articleId', $articleId, \PDO::PARAM_INT); $st->execute(); $result = $st->fetch(); return ['authors' => $result['users_name'] ?? '']; diff --git a/application/models/Connection.php b/application/models/Connection.php index b988322..1792f94 100644 --- a/application/models/Connection.php +++ b/application/models/Connection.php @@ -22,7 +22,7 @@ public function getById($id, $tableName = '') : ?Model{ $st = $this->pdo->prepare($sql); - $st->bindValue(":id", $id, \PDO::PARAM_INT); + $st->bindValue(":id", $id, PDO::PARAM_INT); $st->execute(); $row = null; while ($row = $st->fetch()) { From 580377e959c7beb95490cec463c3eb86452ee10d Mon Sep 17 00:00:00 2001 From: Misha Semenov Date: Wed, 15 Jan 2025 17:17:24 +0300 Subject: [PATCH 6/7] fix css and add edit --- application/CMSviews/admin/admin.php | 16 ++- application/CMSviews/admin/edit/article.php | 16 +-- application/CMSviews/admin/edit/category.php | 16 ++- .../CMSviews/admin/edit/subcategory.php | 84 ++++++++++------ application/CMSviews/admin/edit/user.php | 86 ++++++++-------- application/CMSviews/admin/listCategories.php | 2 - .../CMSviews/admin/listSubcategories.php | 4 - application/CMSviews/admin/listUsers.php | 3 +- application/CMSviews/homepage/homepage.php | 3 +- .../CMSviews/homepage/viewArticleAuthors.php | 2 +- .../CMSviews/layouts/includes/header.php | 3 +- application/CMSviews/layouts/main.php | 5 +- application/controllers/AdminController.php | 97 ++++++++++++++++++- .../controllers/HomepageController.php | 4 +- application/models/Article.php | 6 -- assets/CustomCSSAsset.php | 24 +++++ 16 files changed, 246 insertions(+), 125 deletions(-) create mode 100644 assets/CustomCSSAsset.php diff --git a/application/CMSviews/admin/admin.php b/application/CMSviews/admin/admin.php index 7ada8af..b75fa76 100644 --- a/application/CMSviews/admin/admin.php +++ b/application/CMSviews/admin/admin.php @@ -1,5 +1,4 @@

    All Articles

    -
    @@ -60,14 +59,13 @@ - activeArticle) { - echo 'Active'; - } else { - echo 'Not active'; - } - ?> - + active == 1) ? 'Active' : 'Not active'; + ?> + + + diff --git a/application/CMSviews/admin/edit/article.php b/application/CMSviews/admin/edit/article.php index 2f46236..69636c9 100644 --- a/application/CMSviews/admin/edit/article.php +++ b/application/CMSviews/admin/edit/article.php @@ -1,5 +1,5 @@

    - + @@ -9,24 +9,24 @@
    • - +
    • - +
    • - +
    • @@ -36,7 +36,7 @@ > + active ? 'checked' : '' ?>>
    diff --git a/application/CMSviews/admin/edit/category.php b/application/CMSviews/admin/edit/category.php index 17586c0..01e9182 100644 --- a/application/CMSviews/admin/edit/category.php +++ b/application/CMSviews/admin/edit/category.php @@ -1,8 +1,7 @@ -

    +

    - - - + +
    @@ -12,12 +11,12 @@
  • - +
  • - +
  • @@ -29,11 +28,10 @@ -id ) { ?> -

    +id ) { ?> +

    Delete This Category

    - diff --git a/application/CMSviews/admin/edit/subcategory.php b/application/CMSviews/admin/edit/subcategory.php index d3bff91..f4f173d 100644 --- a/application/CMSviews/admin/edit/subcategory.php +++ b/application/CMSviews/admin/edit/subcategory.php @@ -1,34 +1,54 @@ -

    Article Subcategories

    - - -
    - - - -
    - - - - - - - - - - - - - - +

    + + + + + +
    - -
    Subcategory nameCategory name
    - name ?> - - cat_name ?> -
    - -

    categor in total.

    - -

    Add a New Subcategory

    + +
      +
    • + + +
    • + +
    • + + +
    • +
    • + + + +
    • +
        + +
        + + +
        + + + + id ) { ?> +

        + Delete This Subcategory +

        + \ No newline at end of file diff --git a/application/CMSviews/admin/edit/user.php b/application/CMSviews/admin/edit/user.php index af96be8..432723f 100644 --- a/application/CMSviews/admin/edit/user.php +++ b/application/CMSviews/admin/edit/user.php @@ -1,41 +1,47 @@ -

        Users

        - - -
        - - - -
        - - - - - - - - - - - - - - - - +

        + + + +
        + +
          +
        • + + +
        • +
        • + + +
        • + +
        • + + active == 1) { + echo 'checked = "checked"'; + } + ?> + > +
        • +
        +
        + + +
        + + login) { ?> +

        + Delete This User +

        - -
        Имя пользователяАктивность
        - name ?> - - active) { - echo 'Активен'; - } else { - echo 'Неактивен'; - } - ?> -
        - -

        user in total.

        - -

        Add a New User

        diff --git a/application/CMSviews/admin/listCategories.php b/application/CMSviews/admin/listCategories.php index e308e33..748af84 100644 --- a/application/CMSviews/admin/listCategories.php +++ b/application/CMSviews/admin/listCategories.php @@ -28,5 +28,3 @@

        category in total.

        Add a New Category

        - - diff --git a/application/CMSviews/admin/listSubcategories.php b/application/CMSviews/admin/listSubcategories.php index 3ff8d91..3455dc4 100644 --- a/application/CMSviews/admin/listSubcategories.php +++ b/application/CMSviews/admin/listSubcategories.php @@ -11,7 +11,6 @@ - @@ -20,9 +19,6 @@ - diff --git a/application/CMSviews/admin/listUsers.php b/application/CMSviews/admin/listUsers.php index 1a81c0d..6d65367 100644 --- a/application/CMSviews/admin/listUsers.php +++ b/application/CMSviews/admin/listUsers.php @@ -1,5 +1,4 @@

        Users

        -
        @@ -18,7 +17,7 @@
        Subcategory nameCategory name
        name ?> - cat_name ?> -
        - name?> + login?> diff --git a/application/CMSviews/homepage/homepage.php b/application/CMSviews/homepage/homepage.php index 4e55534..cf8a1dc 100644 --- a/application/CMSviews/homepage/homepage.php +++ b/application/CMSviews/homepage/homepage.php @@ -47,9 +47,8 @@ $authors = $results['authors'][$article->id]; $authorsLinks = []; - // Проверяем, если это не пустой массив if (is_array($authors)) { - // Проходим по авторам и выводим их ссылки + foreach ($authors as $authorId => $authorLogin) { $authorsLinks[] = '' . htmlspecialchars($authorLogin) . ''; } diff --git a/application/CMSviews/homepage/viewArticleAuthors.php b/application/CMSviews/homepage/viewArticleAuthors.php index f4023b5..c976f5e 100644 --- a/application/CMSviews/homepage/viewArticleAuthors.php +++ b/application/CMSviews/homepage/viewArticleAuthors.php @@ -1,4 +1,4 @@ - +

        Статьи автора login)?>

          diff --git a/application/CMSviews/layouts/includes/header.php b/application/CMSviews/layouts/includes/header.php index 2649e6e..864b353 100644 --- a/application/CMSviews/layouts/includes/header.php +++ b/application/CMSviews/layouts/includes/header.php @@ -6,7 +6,8 @@ <?php echo $title?> - + + diff --git a/application/CMSviews/layouts/main.php b/application/CMSviews/layouts/main.php index 45a867a..0605230 100644 --- a/application/CMSviews/layouts/main.php +++ b/application/CMSviews/layouts/main.php @@ -4,12 +4,13 @@ $User = Config::getObject('core.user.class'); use application\models\Category; ?> - + username && $User->username != 'guest' && - preg_match('/Admin/', $_GET['route']) ==1){ + preg_match('/admin/', $_GET['route']) ==1){ include "includes/adminHeader.php"; } } diff --git a/application/controllers/AdminController.php b/application/controllers/AdminController.php index 494f28a..80902d5 100644 --- a/application/controllers/AdminController.php +++ b/application/controllers/AdminController.php @@ -65,6 +65,97 @@ public function viewArticleAction(){ $this->view->render('singleArticle/singleArticle.php'); } + public function editArticleAction (){ + $this->initModelObjects(); + $this->results['pageTitle'] = "Edit article"; + $articleId = isset($_GET['articleId']) ? (int)($_GET['articleId']) : null; + $article = $this->Article->getById($articleId); + if ($_SERVER['REQUEST_METHOD'] == 'POST'){ + $title = $_POST['title']; + $summary = $_POST['summary']; + $content = $_POST['content']; + $categoryId = $_POST['categoryId']; + $subcategoryId = $_POST['subcategoryId']; + $publicationDate = $_POST['publicationDate']; + $active = isset($_POST['active']) ? 1 : 0; + $authors = $_POST['$authors']; + + $article->title = $title; + $article->summary = $summary; + $article->content = $content; + $article->categoryId = $categoryId; + $article->subcategoryId = $subcategoryId; + $article->publicationDate = $publicationDate; + $article->active = $active; + $article->authors = $authors ; + $this->Article->update($article); + } + $this->results['article'] = $article; + $this->results['categories'] = $this->Category->getList()['results']; + $this->results['subcategories'] = $this->Subcategory->getList()['results']; + $this->view->addVar('results', $this->results); + $this->view->render('admin/edit/article.php'); + } + public function editCategoryAction (){ + $this->initModelObjects(); + $this->results['pageTitle'] = "Edit category"; + $categoryId = isset($_GET['categoryId']) ? (int)($_GET['categoryId']) : null; + $category = $this->Category->getById($categoryId); + if ($_SERVER['REQUEST_METHOD'] == 'POST'){ + $name = $_POST['name']; + $description = $_POST['description']; + + $category->name = $name; + $category->description = $description; + $this->Category->update($category); + } + $this->results['categories'] = $this->Category->getById($categoryId); + $this->results['formAction'] = 'editCategory&categoryId=' . $categoryId; + $this->view->addVar('results',$this->results); + $this->view->render('admin/edit/category.php'); + } + public function editSubcategoryAction(){ + $this->initModelObjects(); + $this->results['pageTitle'] = "Edit subcategory"; + $subcategoryId = isset($_GET['subcategoryId']) ? (int)($_GET['subcategoryId']) : null; + $subcategory = $this->Subcategory->getById($subcategoryId); + if ($_SERVER['REQUEST_METHOD'] == 'POST'){ + $name = $_POST['name']; + $description = $_POST['description']; + $categoryId = $_POST['categoryId']; + + $subcategory->name = $name; + $subcategory->description = $description; + $subcategory->categoryId = $categoryId; + $this->Subcategory->update($subcategory); + } + $this->results['subcategories'] = $this->Subcategory->getById($subcategoryId); + $this->results['categories'] = $this->Category->getList() ['results']; + $this->results['formAction'] = 'editSubcategory&subcategoryId=' . $subcategoryId; + $this->view->addVar('results',$this->results); + $this->view->render('admin/edit/subcategory.php'); + } + public function editUserAction(){ + $this->initModelObjects(); + $this->results['pageTitle'] = "Edit User"; + $userId = isset($_GET['userId']) ? (int)($_GET['userId']) : null; + $user = $this->Users->getById($userId); + if ($_SERVER['REQUEST_METHOD'] == 'POST'){ + $login = $_POST['login']; + $password = $_POST['password']; + $active = $_POST['active']; + + $user->login = $login; + $user->password = $password; + $user->active = $active; + $this->Users->update($user); + } + $this->results['users'] = $this->Users->getById($userId); + $this->results['formAction'] = "editUser&userId=" . $userId; + $this->view->addVar('results',$this->results); + $this->view->render('admin/edit/user.php'); + } + public function listCategoriesAction(){ $this->initModelObjects(); $data = $this->Category->getList(); @@ -99,10 +190,6 @@ public function listSubcategoriesAction(){ $this->results['pageTitle'] = "List of subcategories"; $this->title = $this->results['pageTitle']; $this->view->addVar('title',$this->title); - foreach ($this->results['subcategories'] as $subcategory) { - $category = $this->Category->getById($subcategory->categoryId); - $subcategory->cat_name = $category->name; - } if (isset($_GET['error'])){ if ($_GET['error'] == "subcategoryNotFound") $this->results['errorMessage'] = "Error: Subcategory not found."; @@ -116,7 +203,7 @@ public function listSubcategoriesAction(){ $this->results['statusMessage'] = "Subcategory deleted"; } $this->view->addVar('results', $this->results); - $this->view->render('admin/listSubcategory.php'); + $this->view->render('admin/listSubcategories.php'); } public function listUsersAction(){ $this->initModelObjects(); diff --git a/application/controllers/HomepageController.php b/application/controllers/HomepageController.php index 8f7cad8..6ba6a28 100644 --- a/application/controllers/HomepageController.php +++ b/application/controllers/HomepageController.php @@ -55,8 +55,8 @@ public function getArticles() { $this->results['subcategories'][$subcategory->id] = $subcategory; } foreach ($this->articlesData['results'] as $article) { - $authorsData = $this->Article->getAuthors($article->id); // Получаем авторов для статьи - $this->results['authors'][$article->id] = $authorsData['authors']; // Сохраняем авторов по ID статьи + $authorsData = $this->Article->getAuthors($article->id); + $this->results['authors'][$article->id] = $authorsData['authors']; } } diff --git a/application/models/Article.php b/application/models/Article.php index 8951e59..37305a8 100644 --- a/application/models/Article.php +++ b/application/models/Article.php @@ -80,7 +80,6 @@ public function getList( } $categoryClause = $conditions ? "WHERE " . implode(" AND ", $conditions) : ""; - // SQL-запрос $sql = "SELECT SQL_CALC_FOUND_ROWS a.*, UNIX_TIMESTAMP(a.publicationDate) AS publicationDate, GROUP_CONCAT(authors.login SEPARATOR ', ') AS authors_login @@ -108,13 +107,10 @@ public function getList( } $st->bindValue(":numRows", $numRows, \PDO::PARAM_INT); $st->execute(); - - // Формируем список результатов $list = []; while ($row = $st->fetch()) { $modelClassName = static::class; $example = new $modelClassName($row); - // Добавляем авторов как массив if (isset($row['authors_login']) && !empty($row['authors_login'])) { $example->authors = explode(', ', $row['authors_login']); } else { @@ -133,8 +129,6 @@ public function getList( "totalRows" => $totalRows[0] ]; } - - public function getAuthors($articleId): array { $sql = " diff --git a/assets/CustomCSSAsset.php b/assets/CustomCSSAsset.php new file mode 100644 index 0000000..2ddb0f3 --- /dev/null +++ b/assets/CustomCSSAsset.php @@ -0,0 +1,24 @@ + Date: Thu, 23 Jan 2025 16:20:39 +0300 Subject: [PATCH 7/7] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20?= =?UTF-8?q?=D0=B0=D0=B4=D0=BC=D0=B8=D0=BD=D0=BA=D1=83=20=D0=B8=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B0=D0=B2=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/CMSviews/admin/admin.php | 2 +- application/CMSviews/admin/edit/article.php | 27 +- application/CMSviews/admin/edit/category.php | 30 +- .../CMSviews/admin/edit/subcategory.php | 23 +- application/CMSviews/admin/edit/user.php | 20 +- application/CMSviews/homepage/archive.php | 58 ++- application/CMSviews/homepage/homepage.php | 47 +-- .../CMSviews/homepage/viewArticleCategory.php | 6 +- .../CMSviews/layouts/includes/adminHeader.php | 3 - .../CMSviews/layouts/includes/footer.php | 2 +- .../CMSviews/layouts/includes/header.php | 2 + application/CMSviews/layouts/main.php | 19 +- application/CMSviews/login/loginForm.php | 8 +- application/config/web.php | 7 +- application/controllers/AdminController.php | 133 ++++++- .../controllers/HomepageController.php | 17 +- application/controllers/LoginController.php | 51 ++- application/models/AllUsers.php | 31 +- application/models/Article.php | 16 +- application/models/Category.php | 37 +- application/models/Subcategory.php | 19 +- application/models/User.php | 22 +- web/CSS/style.css | 346 ++++++++++-------- 23 files changed, 534 insertions(+), 392 deletions(-) diff --git a/application/CMSviews/admin/admin.php b/application/CMSviews/admin/admin.php index b75fa76..e1b86a5 100644 --- a/application/CMSviews/admin/admin.php +++ b/application/CMSviews/admin/admin.php @@ -2,7 +2,7 @@
          - +
          diff --git a/application/CMSviews/admin/edit/article.php b/application/CMSviews/admin/edit/article.php index 69636c9..61d2724 100644 --- a/application/CMSviews/admin/edit/article.php +++ b/application/CMSviews/admin/edit/article.php @@ -1,7 +1,11 @@

          - -
          - + + + + id): ?> + +
          @@ -9,17 +13,17 @@
          • - +
          • - +
          • - +
          • @@ -43,12 +47,12 @@
          • - - - + @@ -56,7 +60,8 @@
          • - " /> + +
          • diff --git a/application/CMSviews/admin/edit/category.php b/application/CMSviews/admin/edit/category.php index 01e9182..6dd8f01 100644 --- a/application/CMSviews/admin/edit/category.php +++ b/application/CMSviews/admin/edit/category.php @@ -1,37 +1,39 @@ -

            +

            - - + - + id): ?> + + + +
              -
            • - +
            • - +
            • -
            - +
            -
          • -id ) { ?> -

            +id): ?> +

            + Delete This Category

            - - + diff --git a/application/CMSviews/admin/edit/subcategory.php b/application/CMSviews/admin/edit/subcategory.php index f4f173d..81dca87 100644 --- a/application/CMSviews/admin/edit/subcategory.php +++ b/application/CMSviews/admin/edit/subcategory.php @@ -1,9 +1,16 @@

            -
            - + + + id): ?> + + + + +
            + @@ -46,9 +53,9 @@
            id ) { ?> -

            - Delete This Subcategory -

            +

            + + Delete This Subcategory + +

            \ No newline at end of file diff --git a/application/CMSviews/admin/edit/user.php b/application/CMSviews/admin/edit/user.php index 432723f..15e06ba 100644 --- a/application/CMSviews/admin/edit/user.php +++ b/application/CMSviews/admin/edit/user.php @@ -1,8 +1,10 @@

            -
            - + + + id): ?> + +
            @@ -39,9 +41,9 @@
            login) { ?> -

            - Delete This User -

            +

            + + Delete This User + +

            diff --git a/application/CMSviews/homepage/archive.php b/application/CMSviews/homepage/archive.php index f8692a9..4d8b999 100644 --- a/application/CMSviews/homepage/archive.php +++ b/application/CMSviews/homepage/archive.php @@ -1,45 +1,37 @@ -

            - - -

            description ) ?>

            - - +

            article in total.

            -

            article in total.

            +

            Return to Homepage

            -

            Return to Homepage

            \ No newline at end of file diff --git a/application/CMSviews/homepage/homepage.php b/application/CMSviews/homepage/homepage.php index cf8a1dc..8437c60 100644 --- a/application/CMSviews/homepage/homepage.php +++ b/application/CMSviews/homepage/homepage.php @@ -39,41 +39,42 @@ id) && isset($results['authors'][$article->id]) && !empty($results['authors'][$article->id])) { ?> - - Авторы: - id]; - $authorsLinks = []; + if (isset($article->id) && isset($results['authors'][$article->id]) && !empty($results['authors'][$article->id])) { ?> + + Авторы: + id]; + $authorsLinks = []; - if (is_array($authors)) { - - foreach ($authors as $authorId => $authorLogin) { - $authorsLinks[] = '' . htmlspecialchars($authorLogin) . ''; - } - } else { - // Если авторов всего один, просто добавляем ссылку для него - $authorsLinks[] = '' . htmlspecialchars($authors) . ''; + if (is_array($authors)) { + foreach ($authors as $authorId => $author) { + // Предполагаем, что свойство login является строкой + $authorsLinks[] = '' . htmlspecialchars($author->login) . ''; } + } else { + // Если автор только один + $authorsLinks[] = '' . htmlspecialchars($authors->login) . ''; + } - echo implode(', ', $authorsLinks); - ?> - + echo implode(', ', $authorsLinks); + ?> + + +

            content)?>

            gif - Показать полностью + Показать полностью
          diff --git a/application/CMSviews/homepage/viewArticleCategory.php b/application/CMSviews/homepage/viewArticleCategory.php index 6ba5dfa..0bb4b24 100644 --- a/application/CMSviews/homepage/viewArticleCategory.php +++ b/application/CMSviews/homepage/viewArticleCategory.php @@ -1,7 +1,7 @@ +if ($results['categories']) { ?>

          - description) ?> + description) ?>

          @@ -16,7 +16,7 @@ title) ?> - categoryId && isset($results['categories'][$article->categoryId])) { ?> + categoryId && isset($results['categories'][$article->categoryId])) { ?> in diff --git a/application/CMSviews/layouts/includes/adminHeader.php b/application/CMSviews/layouts/includes/adminHeader.php index 04da784..20af138 100644 --- a/application/CMSviews/layouts/includes/adminHeader.php +++ b/application/CMSviews/layouts/includes/adminHeader.php @@ -1,10 +1,7 @@ diff --git a/application/CMSviews/layouts/includes/footer.php b/application/CMSviews/layouts/includes/footer.php index d656d26..f042f19 100644 --- a/application/CMSviews/layouts/includes/footer.php +++ b/application/CMSviews/layouts/includes/footer.php @@ -1,5 +1,5 @@ diff --git a/application/CMSviews/layouts/includes/header.php b/application/CMSviews/layouts/includes/header.php index 864b353..d9a9892 100644 --- a/application/CMSviews/layouts/includes/header.php +++ b/application/CMSviews/layouts/includes/header.php @@ -15,3 +15,5 @@
          +

          You are logged in as userName ?>. + Log out \ No newline at end of file diff --git a/application/CMSviews/layouts/main.php b/application/CMSviews/layouts/main.php index 0605230..e63c80d 100644 --- a/application/CMSviews/layouts/main.php +++ b/application/CMSviews/layouts/main.php @@ -4,16 +4,15 @@ $User = Config::getObject('core.user.class'); use application\models\Category; ?> - + username && - $User->username != 'guest' && - preg_match('/admin/', $_GET['route']) ==1){ - include "includes/adminHeader.php"; - } - } +if( isset($_GET['route'])){ + if($User->userName == 'admin' && + $User->userName != 'guest' && + preg_match('/Admin/', $_GET['route']) == 1){ + include "includes/adminHeader.php"; + } +} ?> - \ No newline at end of file + diff --git a/application/CMSviews/login/loginForm.php b/application/CMSviews/login/loginForm.php index fc5f039..93eaf14 100644 --- a/application/CMSviews/login/loginForm.php +++ b/application/CMSviews/login/loginForm.php @@ -2,15 +2,15 @@

          - -
          - + +
          +
          • - +
          • diff --git a/application/config/web.php b/application/config/web.php index f01ca03..2fb4117 100644 --- a/application/config/web.php +++ b/application/config/web.php @@ -42,11 +42,12 @@ 'class' => \application\models\Subcategory::class ], - 'homepageNumArticles' => 5, - 'homepageNumSubcategories' => 5, - 'homepageNumArticlesPerSubcategory' =>5, + 'homepageNumArticles' => 25, + 'homepageNumSubcategories' => 25, + 'homepageNumArticlesPerSubcategory' =>25, 'admin' => [ 'username' => 'admin', // Укажите имя пользователя администратора + 'password' => 1234, ] ] ]; diff --git a/application/controllers/AdminController.php b/application/controllers/AdminController.php index 80902d5..3ef0c13 100644 --- a/application/controllers/AdminController.php +++ b/application/controllers/AdminController.php @@ -39,7 +39,10 @@ protected function getArticles(){ $this->results['subcategory'][$subcategory->id] = $subcategory->name; $this->results['categories']['$subcategory->id'] = $this->Category->getById($subcategory->categoryId); } - + $authorsData = $this->Users->getList(); + foreach ($authorsData['results'] as $author){ + $this->results['authors'][$author->id] = $author->login; + } } public function indexAction(){ $this->initModelObjects(); @@ -68,7 +71,7 @@ public function viewArticleAction(){ public function editArticleAction (){ $this->initModelObjects(); $this->results['pageTitle'] = "Edit article"; - $articleId = isset($_GET['articleId']) ? (int)($_GET['articleId']) : null; + $articleId = isset($_GET['articleId']) ? ($_GET['articleId']) : null; $article = $this->Article->getById($articleId); if ($_SERVER['REQUEST_METHOD'] == 'POST'){ $title = $_POST['title']; @@ -93,30 +96,38 @@ public function editArticleAction (){ $this->results['article'] = $article; $this->results['categories'] = $this->Category->getList()['results']; $this->results['subcategories'] = $this->Subcategory->getList()['results']; + $this->results['users'] = $this->Users->getList()['results']; + $this->view->addVar('results', $this->results); $this->view->render('admin/edit/article.php'); } public function editCategoryAction (){ $this->initModelObjects(); - $this->results['pageTitle'] = "Edit category"; + $this->results['pageTitle'] = "Edit categories"; + $this->title = $this->results['pageTitle']; $categoryId = isset($_GET['categoryId']) ? (int)($_GET['categoryId']) : null; $category = $this->Category->getById($categoryId); - if ($_SERVER['REQUEST_METHOD'] == 'POST'){ + if ($_SERVER['REQUEST_METHOD'] == 'POST') { $name = $_POST['name']; $description = $_POST['description']; - + $category->name = $name; $category->description = $description; + + echo ("Updating category: " . print_r($category, true)); // Проверяем содержимое $this->Category->update($category); } + $this->results['categories'] = $this->Category->getById($categoryId); $this->results['formAction'] = 'editCategory&categoryId=' . $categoryId; + $this->view->addVar('title', $this->title); $this->view->addVar('results',$this->results); $this->view->render('admin/edit/category.php'); } public function editSubcategoryAction(){ $this->initModelObjects(); - $this->results['pageTitle'] = "Edit subcategory"; + $this->results['pageTitle'] = "Edit of subcategory"; + $this->title = $this->results['pageTitle']; $subcategoryId = isset($_GET['subcategoryId']) ? (int)($_GET['subcategoryId']) : null; $subcategory = $this->Subcategory->getById($subcategoryId); if ($_SERVER['REQUEST_METHOD'] == 'POST'){ @@ -132,12 +143,14 @@ public function editSubcategoryAction(){ $this->results['subcategories'] = $this->Subcategory->getById($subcategoryId); $this->results['categories'] = $this->Category->getList() ['results']; $this->results['formAction'] = 'editSubcategory&subcategoryId=' . $subcategoryId; + $this->view->addVar('title',$this->title); $this->view->addVar('results',$this->results); $this->view->render('admin/edit/subcategory.php'); } public function editUserAction(){ $this->initModelObjects(); $this->results['pageTitle'] = "Edit User"; + $this->title = $this->results['pageTitle']; $userId = isset($_GET['userId']) ? (int)($_GET['userId']) : null; $user = $this->Users->getById($userId); if ($_SERVER['REQUEST_METHOD'] == 'POST'){ @@ -152,6 +165,7 @@ public function editUserAction(){ } $this->results['users'] = $this->Users->getById($userId); $this->results['formAction'] = "editUser&userId=" . $userId; + $this->view->addVar('title',$this->title); $this->view->addVar('results',$this->results); $this->view->render('admin/edit/user.php'); } @@ -228,6 +242,113 @@ public function listUsersAction(){ $this->view->addVar('results', $this->results); $this->view->render('admin/listUsers.php'); } + public function newCategoryAction(){ + $this->initModelObjects(); + $this->results['pageTitle'] = "Add categories"; + $this->title = $this->results['pageTitle']; + if (isset($_POST['saveChanges'])){ + $category = $this->Category; + $category->storeFormValues($_POST); + $category->insert(); + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/listCategories')); + } elseif (isset($_POST['cancel'])){ + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/listCategories')); + } else { + $this->results['categories'] = $this->Category; + $this->view->addVar('results', $this->results); + $this->view->render('admin/edit/category.php'); + } + } + public function deleteCategoryAction(){ + $this->initModelObjects(); + $categoryId = $_GET['categoryId'] ?? null; + if (!$categoryId){ + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/listCategories') . '&error=missingId'); + return; + } + $category = $this->Category->getById($categoryId); + if (!$category){ + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/listCategories') . '&error=notFound'); + return; + } + $this->Category->id = $categoryId; + $this->Category->delete(); + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/listCategories')); + } + public function newSubcategoryAction(){ + $this->initModelObjects(); + $this->results['pageTitle'] = "Add subcategory"; + $this->title = $this->results['pageTitle']; + if (isset($_POST['saveChanges'])){ + $subcategory = $this->Subcategory; + $subcategory->storeFormValues($_POST); + $subcategory->insert(); + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/listSubcategories')); + }elseif (isset ($_POST['cancel'])) { + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/listCategories')); + } else { + $this->results['subcategories'] = $this->Subcategory; + $this->results['categories'] = $this->Category->getList() ['results']; + $this->view->addVar('results', $this->results); + $this->view->render('admin/edit/subcategory.php'); + } + } + public function deleteSubcategoryAction(){ + $this->initModelObjects(); + $subcategoryId = $_GET['subcategoryId'] ?? null; + $subcategory = $this->Subcategory->getById($subcategoryId); + $this->Subcategory->id = $subcategoryId; + $this->Subcategory->delete(); + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/listSubcategories')); + } + public function newUserAction(){ + $this->initModelObjects(); + $this->results['pageTitle'] = "Add new author"; + $this->title = $this->results['pageTitle']; + if (isset($_POST['saveChanges'])){ + $user = $this->Users; + $_POST['active'] = isset($_POST['active']) ? 1 : 0; + $user->storeFormValues($_POST); + $user->insert(); + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/listUsers')); + } elseif (isset($_POST['cancel'])){ + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/listUsers')); + } else { + $this->results['users'] = $this->Users; + $this->view->addVar('results', $this->results); + $this->view->render('admin/edit/user.php'); + } + } + public function deleteUserAction(){ + $this->initModelObjects(); + $this->results['pageTitle'] = "Delete user"; + $this->title = $this->results['pageTitle']; + $userId = $_GET['userId'] ?? null; + $user = $this->Users->getById($userId); + $this->Users->id = $userId; + $this->Users->delete(); + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/listUsers')); + } + public function newArticleAction(){ + $this->initModelObjects(); + $this->results['pageTitle'] = "Add new article"; + $this->title = $this->results['pageTitle']; + if (isset($_POST['saveChanges'])){ + $article = $this->Article; + $article->storeFormValues($_POST); + $article->insert(); + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/admin.php')); + } elseif (isset($_POST['cancel'])){ + $this->redirect(\ItForFree\SimpleMVC\Router\WebRouter::link('admin/admin.php')); + } else { + $this->results['article'] = $this->Article; + $this->results['categories'] = $this->Category->getList() ['results']; + $this->results['subcategories'] = $this->Subcategory->getList() ['results']; + $this->results['users'] = $this->Users->getList() ['results']; + $this->view->addVar('results', $this->results); + $this->view->render('admin/edit/article.php'); + } + } } diff --git a/application/controllers/HomepageController.php b/application/controllers/HomepageController.php index 6ba6a28..a54e290 100644 --- a/application/controllers/HomepageController.php +++ b/application/controllers/HomepageController.php @@ -40,6 +40,7 @@ public function getArticles() { $subcategoriesData = $this->Subcategory->getList(); $categoriesData = $this->Category->getList(); + $authorsData = $this->Users->getList(); $this->results['subcategories'] = array(); @@ -50,13 +51,11 @@ public function getArticles() { $this->results['categories'][$category->id] = $category; } - // Проходим по подкатегориям и получаем данные foreach ($subcategoriesData['results'] as $subcategory) { $this->results['subcategories'][$subcategory->id] = $subcategory; } - foreach ($this->articlesData['results'] as $article) { - $authorsData = $this->Article->getAuthors($article->id); - $this->results['authors'][$article->id] = $authorsData['authors']; + foreach ($authorsData['results'] as $author) { + $this->results['authors'][$author->id] = $author; } } @@ -122,8 +121,6 @@ public function archiveAction(){ $this->view->addVar('title', $this->title); $this->view->addVar('results', $this->results); - /*Передаем также объект категории т.к. его методы унаследованы от - * родительского класса model и не являются статическими*/ $this->view->addVar('Category', $this->Category); $this->view->render('homepage/archive.php'); } @@ -205,7 +202,7 @@ public function viewArticleSubcategoryAction() { $this->view->render('homepage/error.php'); return; } - $articlesData = $this->Article->getList(100, null, false, $subcategoryId); + $articlesData = $this->Article->getList(10000,null,1,$subcategoryId); $this->results['articles'] = $articlesData['results']; $this->results['totalRows'] = $articlesData['totalRows']; @@ -221,11 +218,11 @@ public function viewArticleCategoryAction() { $this->initModelObjects(); $categoryId = isset($_GET['categoryId']) ? (int)$_GET['categoryId'] : null; - $articlesData = $this->Article->getList(100, null, false, $categoryId); + $articlesData = $this->Article->getList(10000,$categoryId,1); $this->results['articles'] = $articlesData['results']; $this->results['totalRows'] = $articlesData['totalRows']; - $this->results['category'] = $this->Category->getById($categoryId); - $this->view->addVar('title', $this->results['category']->name ?? 'Articles'); + $this->results['categories'] = $this->Category->getById($categoryId); + $this->view->addVar('title', $this->results['categories']->name ?? 'Articles'); $this->view->addVar('results', $this->results); $this->view->addVar('Category', $this->Category); $this->view->render('homepage/viewArticleCategory.php'); diff --git a/application/controllers/LoginController.php b/application/controllers/LoginController.php index 6ca2601..9005fea 100644 --- a/application/controllers/LoginController.php +++ b/application/controllers/LoginController.php @@ -10,39 +10,30 @@ class LoginController extends \ItForFree\SimpleMVC\MVC\Controller public $title = 'Admin Login'; public $errorMessage = 'Неправильный логин или пароль'; - public function loginAction() { - $User = Config::getObject('core.user.class'); - - // Проверка, если пользователь уже авторизован - if (isset($_SESSION['user']) && $_SESSION['user'] != 'guest') { - $this->redirect(WebRouter::link("Admin/index")); - } - - if (!empty($_POST)) { - $login = $_POST['login']; - $pass = $_POST['password']; - - // Пытаемся выполнить вход с использованием checkAuthData - if ($User->checkAuthData($login, $pass)) { - // Успешный вход, сохраняем информацию в сессии - $_SESSION['user'] = $login; // Можно сохранить логин или другие данные пользователя - $this->redirect(WebRouter::link("Admin/index")); - } else { - // Неудачный вход, передаем сообщение в сессию - $_SESSION['errorMessage'] = $this->errorMessage; - $this->redirect(WebRouter::link("Login/login")); // Перенаправление на страницу входа + public function loginAction() + { + $User = Config::getObject('core.user.class'); + + if($User->userName != null && $User->userName != 'guest'){ + $this->redirect(WebRouter::link("Admin/index")); + } elseif (!empty($_POST)) { + $login = $_POST['userName']; + $pass = $_POST['password']; + if($User->login($login, $pass)) { + $this->redirect(WebRouter::link("Admin/index")); + } + else { + $this->view->addVar('errorMessage', 'Неверное имя пользователя или пароль.'); + $this->redirect(WebRouter::link("Login/login&auth=deny")); + } } - } else { - // Передаем ошибки и заголовок в представление - if (isset($_SESSION['errorMessage'])) { - $this->view->addVar('errorMessage', $_SESSION['errorMessage']); - unset($_SESSION['errorMessage']); + else { + $this->view->addVar('errorMessage', $this->errorMessage); + $this->view->addVar('title', $this->title); + $this->view->render('login/loginForm.php'); } - - $this->view->addVar('title', $this->title); - $this->view->render('login/loginForm.php'); } -} + public function logoutAction() { // Очищаем сессию при выходе diff --git a/application/models/AllUsers.php b/application/models/AllUsers.php index 66dfae6..0092cee 100644 --- a/application/models/AllUsers.php +++ b/application/models/AllUsers.php @@ -77,13 +77,13 @@ public function insert(){ $st->execute(); $this->id = $this->pdo->lastInsertId(); } - public function update() { - $sql = "UPDATE users SET login=:login, password=:password, active=:active WHERE id = :id"; + public function update($user) { + $sql = "UPDATE $this->tableName SET login=:login, password=:password, active=:active WHERE id = :id"; $st = $this->pdo->prepare( $sql ); - $st->bindValue( ":login", $this->login,\PDO::PARAM_STR ); - $st->bindValue( ":password", $this->password, \PDO::PARAM_STR ); - $st->bindValue( ":active", $this->active, \PDO::PARAM_INT ); - $st->bindValue( ":id", $this->userId, \PDO::PARAM_INT ); + $st->bindValue( ":login", $user->login,\PDO::PARAM_STR ); + $st->bindValue( ":password", $user->password, \PDO::PARAM_STR ); + $st->bindValue( ":active", $user->active, \PDO::PARAM_INT ); + $st->bindValue( ":id", $user->id, \PDO::PARAM_INT ); $st->execute(); } public function getById(int $id, string $tableName = ''): ?Model @@ -106,29 +106,28 @@ public function getById(int $id, string $tableName = ''): ?Model } } public function delete():void{ - $st = $this->pdo->prepare("DELETE FROM users WHERE login = :login LIMIT 1"); - $st->bindValue(":login",$this->login,PDO::PARAM_STR); + $st = $this->pdo->prepare("DELETE FROM users WHERE id = :id LIMIT 1"); + $st->bindValue(":id",$this->id,\PDO::PARAM_STR); + $st->execute(); + $st = $this->pdo-> prepare("DELETE FROM users_article WHERE user = :id"); + $st->bindValue(":id", $this->id,\PDO::PARAM_INT); $st->execute(); -// $st = $this->pdo-> prepare("DELETE FROM users_aritcles WHERE user = :id"); -// $st->bindValue(":id", $this->$id,PDO::PARAM_INT); -// $st->execute(); } + public function getAuthData($login): ?array { - $sql = "SELECT pass FROM users WHERE login = :login"; + $sql = "SELECT password,active FROM users WHERE login = :login"; $st = $this->pdo->prepare($sql); $st->bindValue(":login", $login, \PDO::PARAM_STR); $st->execute(); - return $st->fetch(); // Возвращаем только данные для пароля + return $st->fetch(); } public function checkAuthData($login, $password): bool { - $sql = "SELECT pass FROM users WHERE login = :login"; + $sql = "SELECT password FROM users WHERE login = :login"; $st = $this->pdo->prepare($sql); $st->bindValue(":login", $login, \PDO::PARAM_STR); $st->execute(); $authData = $st->fetch(); - - // Проверяем, совпадает ли пароль if ($authData && password_verify($password, $authData['pass'])) { return true; } else { diff --git a/application/models/Article.php b/application/models/Article.php index 37305a8..edc9203 100644 --- a/application/models/Article.php +++ b/application/models/Article.php @@ -6,7 +6,7 @@ class Article extends \ItForFree\SimpleMVC\MVC\Model { public string $tableName = 'articles'; - public $articleId = null; + public $publicationDate = null; public $title = null; public $subcategoryId = null; @@ -154,13 +154,13 @@ public function insert() { // Вставляем статью $sql = "INSERT INTO articles ( publicationDate, categoryId,subcategoryId ,title, summary, content, active ) VALUES ( FROM_UNIXTIME(:publicationDate), :categoryId,:subcategoryId ,:title, :summary, :content, :active )"; $st = $this->pdo->prepare ( $sql ); - $st->bindValue( ":publicationDate", $this->publicationDate, PDO::PARAM_INT ); - $st->bindValue( ":categoryId", $this->categoryId, PDO::PARAM_INT ); - $st->bindValue( ":subcategoryId", $this->subcategoryId, PDO::PARAM_INT ); - $st->bindValue( ":title", $this->title, PDO::PARAM_STR ); - $st->bindValue( ":summary", $this->summary, PDO::PARAM_STR ); - $st->bindValue( ":content", $this->content, PDO::PARAM_STR ); - $st->bindValue( ":active", $this->activeArticle, PDO::PARAM_INT); + $st->bindValue( ":publicationDate", $this->publicationDate, \PDO::PARAM_INT ); + $st->bindValue( ":categoryId", $this->categoryId, \PDO::PARAM_INT ); + $st->bindValue( ":subcategoryId", $this->subcategoryId, \PDO::PARAM_INT ); + $st->bindValue( ":title", $this->title, \PDO::PARAM_STR ); + $st->bindValue( ":summary", $this->summary, \PDO::PARAM_STR ); + $st->bindValue( ":content", $this->content, \PDO::PARAM_STR ); + $st->bindValue( ":active", $this->active, \PDO::PARAM_INT); $st->execute(); $this->id = $this->pdo->lastInsertId(); $st = $this->pdo->prepare($sql); diff --git a/application/models/Category.php b/application/models/Category.php index 8f0f6ac..30e5f36 100644 --- a/application/models/Category.php +++ b/application/models/Category.php @@ -13,7 +13,7 @@ class Category extends \ItForFree\SimpleMVC\MVC\Model public $name = null; public $description = null; public string $orderBy = 'name ASC'; - public function storeFormValues ($param){ + public function storeFormValues ($params){ $this->__construct( $params ); } public function getById(int $id, string $tableName = ''): ?Model @@ -52,27 +52,34 @@ public function getList($numRows=100000,$order="name ASC"):array { "totalRows" => $totalRows['totalRows'] ]; } - public function insert($tableName = ''){ - $tableName = !empty($tableName) ? $tableName : $this->tableName; - $sql = "INSERT INTO $tableName (name,description) VALUES (:name,:description)"; + public function insert(){ + $sql = "INSERT INTO $this->tableName (name,description) VALUES (:name,:description)"; $st= $this->pdo->prepare($sql); $st->bindValue(":name", $this->name, \PDO::PARAM_STR); $st->bindValue(":description",$this->description, \PDO::PARAM_STR); $st->execute(); $this->id = $this->pdo->lastInsertId(); } - public function update($tableName = ''){ - $tableName = !empty($tableName) ? $tableName : $this->tableName; - $sql = "UPDATE $tableName SET name = :name, description=:description WHERE id = :id"; - $st = $this->pdo->prepare($sql); - $st->bindValue(":name", $this->name, \PDO::PARAM_STR); - $st->bindValue(":description", $this->description, \PDO::PARAM_STR); - $st->bindValue(":id", $this->id, \PDO::PARAM_INT); - $st->execute(); + public function update($category) { + $sql = "UPDATE $this->tableName SET name = :name, description = :description WHERE id = :id"; + $st = $this->pdo->prepare($sql); + + // Связываем параметры + $st->bindValue(":name", $category->name, \PDO::PARAM_STR); + $st->bindValue(":description", $category->description, \PDO::PARAM_STR); + $st->bindValue(":id", $category->id, \PDO::PARAM_INT); + + // Отладка запроса перед выполнением + if ($st->execute()) { + echo "Запрос успешно выполнен."; + } else { + echo "Ошибка выполнения запроса:"; + print_r($st->errorInfo()); } - public function delete($tableName = ''):void{ - $tableName = !empty($tableName) ? $tableName : $this->tableName; - $st = $this->pdo->prepare("DELETE FROM $tableName WHERE id = :id LIMIT 1"); +} + + public function delete():void{ + $st = $this->pdo->prepare("DELETE FROM $this->tableName WHERE id = :id LIMIT 1"); $st->bindValue(":id", $this->id, \PDO::PARAM_INT); $st->execute(); } diff --git a/application/models/Subcategory.php b/application/models/Subcategory.php index 67b2602..0f93b51 100644 --- a/application/models/Subcategory.php +++ b/application/models/Subcategory.php @@ -87,24 +87,21 @@ public function insert(){ if ( !is_null( $this->id ) ) trigger_error ( "Subcategory::insert(): " . "Attempt to insert a Subcategory object that already has its " . "ID property set (to $this->id).", E_USER_ERROR ); - //Вставляем субкатегорию - $sql = "INSERT INTO $this->tableName(name, categoryId) VALUES(:name, :categoryId)"; + $sql = "INSERT INTO $this->tableName(name,description ,categoryId) VALUES(:name,:description ,:categoryId)"; $st = $this->pdo->prepare($sql); $st->bindValue(":name", $this->name, \PDO::PARAM_STR ); + $st->bindValue(":description",$this->description, \PDO::PARAM_STR); $st->bindValue(":categoryId", $this->categoryId, \PDO::PARAM_INT ); $st->execute(); $this->id = $this->pdo->lastInsertId(); } - public function update(){ - // Проверяем есть ли уже у обьекта Subcategory ID ? - if ( is_null( $this->id ) ) trigger_error ( "Subcategory::insert(): " - . "Attempt to insert a Subcategory object that does not have its " - . "ID property set (to $this->id).", E_USER_ERROR ); - $sql = "UPDATE $this->tableName SET name=:name, categoryId=:categoryId WHERE id=:id"; + public function update($subcategory){ + $sql = "UPDATE $this->tableName SET name=:name, description = :description, categoryId=:categoryId WHERE id=:id"; $st = $this->pdo->prepare($sql); - $st->bindValue(":name", $this->name, \PDO::PARAM_STR); - $st->bindValue(":categoryId", $this->categoryId, \PDO::PARAM_INT); - $st->bindValue(":id", $this->id, \PDO::PARAM_INT); + $st->bindValue(":name", $subcategory->name, \PDO::PARAM_STR); + $st->bindValue(":description", $subcategory->description, \PDO::PARAM_STR); + $st->bindValue(":categoryId", $subcategory->categoryId, \PDO::PARAM_INT); + $st->bindValue(":id", $subcategory->id, \PDO::PARAM_INT); $st->execute(); } public function delete() :void { diff --git a/application/models/User.php b/application/models/User.php index 77b3636..e0551c3 100644 --- a/application/models/User.php +++ b/application/models/User.php @@ -17,27 +17,21 @@ protected function getRoleByUserName(string $userName): string { return "authorized"; } } - protected function checkAuthData(string $login, string $pass): bool + + public function checkAuthData(string $login, string $pass): bool { $result = false; - + $User = new AllUsers(); if ($login == Config::get('core.admin.username')) { - // Проверка для админа if ($pass == Config::get('core.admin.password')) { - $result = true; - } + $result = true; + } } else { - // Проверка для обычного пользователя - $sql = "SELECT pass, active FROM users WHERE name = :name;"; - $query = $this->pdo->prepare($sql); - $query->bindValue(":name", $login, \PDO::PARAM_STR); - $query->execute(); - $truePass = $query->fetch(); - if ($truePass && $truePass['pass'] == $pass && $truePass['active'] == 1) { - $result = true; // Учет поля активного пользователя + $authData = $User->getAuthData($login); + if ($authData && $authData['password'] == $pass && $authData['active'] == 1){ + $result = true; } } - return $result; } } diff --git a/web/CSS/style.css b/web/CSS/style.css index ca0be37..9bfce4e 100644 --- a/web/CSS/style.css +++ b/web/CSS/style.css @@ -1,43 +1,43 @@ /* Стили для body and внешнего контейнера */ - + body { - margin: 0; - color: #333; - background-color: #00a0b0; - font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; - line-height: 1.5em; + margin: 0; + color: #333; + background-color: #00a0b0; + font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; + line-height: 1.5em; } #container { - width: 960px; - background: #fff; - margin: 20px auto; - padding: 20px; - -moz-border-radius: 5px; - -webkit-border-radius: 5px; - border-radius: 5px; + width: 960px; + background: #fff; + margin: 20px auto; + padding: 20px; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; } /* Логотип и нижний колонтитул */ #logo { - display: block; - width: 300px; - padding: 0 660px 20px 0; - border: none; - border-bottom: 1px solid #00a0b0; - margin-bottom: 40px; + display: block; + width: 300px; + padding: 0 660px 20px 0; + border: none; + border-bottom: 1px solid #00a0b0; + margin-bottom: 40px; } #footer { - border-top: 1px solid #00a0b0; - margin-top: 40px; - padding: 20px 0 0 0; - font-size: .8em; + border-top: 1px solid #00a0b0; + margin-top: 40px; + padding: 20px 0 0 0; + font-size: .8em; } -#loader-identity { +.loader-identity { display : none; float : right; } @@ -46,76 +46,99 @@ body { /* Заголвки */ h1 { - color: #eb6841; - margin-bottom: 30px; - line-height: 1.2em; + color: #eb6841; + margin-bottom: 30px; + line-height: 1.2em; } h2, h2 a { - color: #edc951; + color: #edc951; } h2 a { - text-decoration: none; + text-decoration: none; } h3.categoryDescription { - margin-top: -20px; - margin-bottom: 40px; + margin-top: -20px; + margin-bottom: 40px; } /* Заголовки статей */ #headlines { - list-style: none; - padding-left: 0; - width: 75%; + list-style: none; + padding-left: 0; + width: 75%; } #headlines li { - margin-bottom: 2em; + margin-bottom: 2em; } .pubDate { - font-size: .8em; - color: #eb6841; - text-transform: uppercase; + font-size: .8em; + color: #eb6841; + text-transform: uppercase; } #headlines .pubDate { - display: inline-block; - width: 100px; - font-size: .5em; - vertical-align: middle; + display: inline-block; + width: 100px; + font-size: .5em; + vertical-align: middle; } #headlines.archive .pubDate { - width: 130px; + width: 130px; } .summary { - padding-left: 100px; + padding-left: 100px; } #headlines.archive .summary { - padding-left: 130px; + padding-left: 130px; } .category { - font-style: italic; - font-weight: normal; - font-size: 60%; - color: #999; - display: block; - line-height: 2em; + font-style: italic; + font-weight: normal; + font-size: 60%; + color: #999; + display: block; + line-height: 2em; } .category a { - color: #999; - text-decoration: underline; + color: #999; + text-decoration: underline; +} +.subcategory { + font-style: italic; + font-weight: normal; + font-size: 60%; + color: #999; + display: block; + line-height: 2em; +} +.subcategory a { + color: #999; + text-decoration: underline; +} +.authors{ + font-style: italic; + font-weight: normal; + font-size: 60%; + color: #999; + display: block; + line-height: 2em; +} +.authors a { + color: #999; + text-decoration: underline; } - .showContent { font-size : 14px; float : right; @@ -125,219 +148,219 @@ h3.categoryDescription { /* Заголовок для страницы администратора */ #adminHeader { - width: 940px; - padding: 0 10px; - border-bottom: 1px solid #00a0b0; - margin: -30px 0 40px 0; - font-size: 0.8em; + width: 940px; + padding: 0 10px; + border-bottom: 1px solid #00a0b0; + margin: -30px 0 40px 0; + font-size: 0.8em; } /* Стили для формы с цветным фоном, скругленными углами и тенью */ form { - margin: 20px auto; - padding: 40px 20px; - overflow: auto; - background: #fff4cf; - border: 1px solid #666; - -moz-border-radius: 5px; - -webkit-border-radius: 5px; - border-radius: 5px; - -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); - -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); - box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + margin: 20px auto; + padding: 40px 20px; + overflow: auto; + background: #fff4cf; + border: 1px solid #666; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + box-shadow: 0 0 .5em rgba(0, 0, 0, .8); } /* Задаем для элементов формы согласованные поля, отступы, и высоту строки */ form ul { - list-style: none; - margin: 0; - padding: 0; + list-style: none; + margin: 0; + padding: 0; } form ul li { - margin: .9em 0 0 0; - padding: 0; + margin: .9em 0 0 0; + padding: 0; } form * { - line-height: 1em; + line-height: 1em; } /* Метки полей */ label { - display: block; - float: left; - clear: left; - text-align: right; - width: 15%; - padding: .4em 0 0 0; - margin: .15em .5em 0 0; + display: block; + float: left; + clear: left; + text-align: right; + width: 15%; + padding: .4em 0 0 0; + margin: .15em .5em 0 0; } /* Поля */ input, select, textarea { - display: block; - margin: 0; - padding: .4em; - width: 80%; + display: block; + margin: 0; + padding: .4em; + width: 80%; } input, textarea, .date { - border: 2px solid #666; - -moz-border-radius: 5px; - -webkit-border-radius: 5px; - border-radius: 5px; - background: #fff; + border: 2px solid #666; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + background: #fff; } input { - font-size: .9em; + font-size: .9em; } select { - padding: 0; - margin-bottom: 2.5em; - position: relative; - top: .7em; + padding: 0; + margin-bottom: 2.5em; + position: relative; + top: .7em; } textarea { - font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; - font-size: .9em; - height: 5em; - line-height: 1.5em; + font-family: "Trebuchet MS", Arial, Helvetica, sans-serif; + font-size: .9em; + height: 5em; + line-height: 1.5em; } textarea#content { - font-family: "Courier New", courier, fixed; + font-family: "Courier New", courier, fixed; } /* Рамка вокруг поля с фокусом ввода */ form *:focus { - border: 2px solid #7c412b; - outline: none; + border: 2px solid #7c412b; + outline: none; } /* Правильно заполненное поле имеет зеленый фон */ input:valid, textarea:valid { - background: #efe; + background: #efe; } /* Кнопки отправки */ .buttons { - text-align: center; - margin: 40px 0 0 0; + text-align: center; + margin: 40px 0 0 0; } input[type="submit"] { - display: inline; - margin: 0 20px; - width: 12em; - padding: 10px; - border: 2px solid #7c412b; - -moz-border-radius: 5px; - -webkit-border-radius: 5px; - border-radius: 5px; - -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); - -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); - box-shadow: 0 0 .5em rgba(0, 0, 0, .8); - color: #fff; - background: #ef7d50; - font-weight: bold; - -webkit-appearance: none; + display: inline; + margin: 0 20px; + width: 12em; + padding: 10px; + border: 2px solid #7c412b; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + color: #fff; + background: #ef7d50; + font-weight: bold; + -webkit-appearance: none; } input[type="submit"]:hover, input[type="submit"]:active { - cursor: pointer; - background: #fff; - color: #ef7d50; + cursor: pointer; + background: #fff; + color: #ef7d50; } input[type="submit"]:active { - background: #eee; - -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; - -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; - box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; + background: #eee; + -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; + -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; + box-shadow: 0 0 .5em rgba(0, 0, 0, .8) inset; } /* Таблицы */ table { - width: 100%; - border-collapse: collapse; + width: 100%; + border-collapse: collapse; } tr, th, td { - padding: 10px; - margin: 0; - text-align: left; + padding: 10px; + margin: 0; + text-align: left; } table, th { - border: 1px solid #00a0b0; + border: 1px solid #00a0b0; } th { - border-left: none; - border-right: none; - background: #ef7d50; - color: #fff; - cursor: default; + border-left: none; + border-right: none; + background: #ef7d50; + color: #fff; + cursor: default; } tr:nth-child(odd) { - background: #fff4cf; + background: #fff4cf; } tr:nth-child(even) { - background: #fff; + background: #fff; } tr:hover { - background: #ddd; - cursor: pointer; + background: #ddd; + cursor: pointer; } /* Окна для вывода статуса и сообщений об ошибках */ .statusMessage, .errorMessage { - font-size: .8em; - padding: .5em; - margin: 2em 0; - -moz-border-radius: 5px; - -webkit-border-radius: 5px; - border-radius: 5px; - -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); - -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); - -box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + font-size: .8em; + padding: .5em; + margin: 2em 0; + -moz-border-radius: 5px; + -webkit-border-radius: 5px; + border-radius: 5px; + -moz-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + -webkit-box-shadow: 0 0 .5em rgba(0, 0, 0, .8); + -box-shadow: 0 0 .5em rgba(0, 0, 0, .8); } .statusMessage { - background-color: #2b2; - border: 1px solid #080; - color: #fff; + background-color: #2b2; + border: 1px solid #080; + color: #fff; } .errorMessage { - background-color: #f22; - border: 1px solid #800; - color: #fff; + background-color: #f22; + border: 1px solid #800; + color: #fff; } ul.ajax-load { @@ -351,3 +374,8 @@ ul.ajax-load li { padding: 3px; /* Поля вокруг текста */ font-size: 12px; } +checkboxActivity { + width: 25px; + height: 25px; + cursor: pointer; + } \ No newline at end of file