diff --git a/assets/css/style.css b/assets/css/style.css index 2d09eea..2a16473 100644 --- a/assets/css/style.css +++ b/assets/css/style.css @@ -507,7 +507,7 @@ input { .article .title { line-height: 24px; font-weight: bold; - color: #3a3a3a; + color: #3a3a3a; } .article .text { @@ -519,7 +519,7 @@ input { height: 180px; } -.article .text img { +.article .text img, .container-search img { display: none; } @@ -672,10 +672,7 @@ label{ -o-transition: 200ms; transition: 200ms; box-shadow: 1px 1px 30px 1px lightgrey; -} -.next:hover{ - color: #007bff; - box-shadow: 1px 1px 30px 1px rgba(0,163,249,0.3); + color:#000; } .filtre { @@ -886,7 +883,7 @@ label{ } } -form.login > input { +form.login > input, form.login > a { /* text-align: center; */ display: block; margin: auto; @@ -903,9 +900,8 @@ form.login >input[type="submit"], form.login > a { border: none; } -form.login > a { - left: -28%; - margin-top: 65px; +form.login a { + width: 106px; } a:hover { diff --git a/assets/html/includes/head.html b/assets/html/includes/head.html index c64afab..5c9d673 100644 --- a/assets/html/includes/head.html +++ b/assets/html/includes/head.html @@ -9,3 +9,4 @@ + diff --git a/assets/html/post.html b/assets/html/post.html index d56bc83..431b4dd 100644 --- a/assets/html/post.html +++ b/assets/html/post.html @@ -44,10 +44,10 @@

Plus d'articles

Catégories

-
dev
-
digi
-
ops
-
devops
+ dev + digi + ops + devops

Tags

@@ -58,6 +58,11 @@ + + + + +

Dans le même thème

diff --git a/assets/html/user_edit.html b/assets/html/user_edit.html index 5063870..1f2799f 100644 --- a/assets/html/user_edit.html +++ b/assets/html/user_edit.html @@ -17,16 +17,15 @@

Créer un utilisateur

-
diff --git a/assets/js/script.js b/assets/js/script.js index b0b9518..392b5f1 100644 --- a/assets/js/script.js +++ b/assets/js/script.js @@ -107,19 +107,6 @@ var submit = () => { } } http.send(data); - // var url = './'; - // var params = "title="+ title.value +"&category=" + category.value + "&content=" + major.innerHTML + "&tags=" + tglst; - // http.open('POST', url, true); - - // //Send the proper header information along with the request - // http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); - - // console.log(major.innerHTML); - - - // http.send(params); - - } if(document.querySelector(".addTag") != null) { @@ -131,13 +118,13 @@ document.querySelector("#search + button").addEventListener("click", function() window.location = window.location.pathname + "?term=" + document.querySelector("#search").value; }); -document.querySelectorAll(".int-search .filtre").forEach(function(el) { +document.querySelectorAll(".filtre").forEach(function(el) { el.addEventListener("click", function() { var tagW = new URL(window.location).searchParams.get("tag"); var tag = (tagW != null ? "&tag=" + tagW : ""); var termW = new URL(window.location).searchParams.get("term"); var term = (termW != null ? "&term=" + termW : ""); - window.location = window.location.pathname + "?category=" + this.getAttribute("data-category") + tag + term; + window.location = "/search/?category=" + this.getAttribute("data-category") + tag + term; }) }) diff --git a/assets/php/Controller.php b/assets/php/Controller.php index 78f519b..72c214c 100644 --- a/assets/php/Controller.php +++ b/assets/php/Controller.php @@ -40,9 +40,9 @@ class Controller { // return $instance->$function(); } } elseif ($arr[0] === "editor" && isset($cl) && $cl == $class) { - if(!isset($_SESSION["author"]) || (isset($_SESSION["author"]) && ($_SESSION["author"]->getRole() != "ROLE_EDITOR" && $_SESSION["author"]->getRole() != "ROLE_ADMIN"))) header("Location: /login/?redirect=".$_SERVER["REQUEST_URI"]); + if(!isset($_SESSION["author"]) || (isset($_SESSION["author"]) && ($_SESSION["author"]->getRole() != "ROLE_EDITOR" && $_SESSION["author"]->getRole() != "ROLE_ADMIN"))) header("Location: /login/"); } elseif($arr[0] === "admin" && isset($cl) && $cl ==$class) { - if(!isset($_SESSION["author"]) || (isset($_SESSION["author"]) && $_SESSION["author"]->getRole() != "ROLE_ADMIN")) header("Location: /login/?redirect=".$_SERVER["REQUEST_URI"]); + if(!isset($_SESSION["author"]) || (isset($_SESSION["author"]) && $_SESSION["author"]->getRole() != "ROLE_ADMIN")) header("Location: /login/"); } elseif($arr[0] === "title" && isset($cl) && $cl == $class) { array_shift($arr); $_GET['page_title'] = join(" ", $arr); diff --git a/assets/php/Controller/LoginController.php b/assets/php/Controller/LoginController.php index a185197..0f38154 100644 --- a/assets/php/Controller/LoginController.php +++ b/assets/php/Controller/LoginController.php @@ -19,7 +19,6 @@ class LoginController extends Controller { $user = Author::getByUsername($_POST["username"]); if($user->checkPassword($_POST["password"])) { $_SESSION["author"] = $user; - if(isset($_GET["redirect"])) header("Location: " . $_GET["redirect"]); header("Location: /"); } else var_dump("login incorreect"); diff --git a/assets/php/Controller/PostController.php b/assets/php/Controller/PostController.php index 7da8432..e8bdfe2 100644 --- a/assets/php/Controller/PostController.php +++ b/assets/php/Controller/PostController.php @@ -81,6 +81,15 @@ class PostController extends Controller { return file_get_contents(DIR."/html/post.html"); } + /** + * @route /^\/post\/[0-9]+\/delete\/$/ + * @title Article + */ + public function delete() { + Post::remove(Post::get($_GET["post"])); + header("Location: /"); + } + /** * @route /^\/post\/[0-9]+\/upload\/$/ */ diff --git a/assets/php/Controller/UserController.php b/assets/php/Controller/UserController.php index 7bd5342..4083a1d 100644 --- a/assets/php/Controller/UserController.php +++ b/assets/php/Controller/UserController.php @@ -36,13 +36,35 @@ class UserController extends Controller { } /** - * @route /\/users\/edit\/[0-9]+\/$/ + * @route /\/users\/[0-9]+\/edit\/$/ * @admin * @title Modifier un utilisateur */ public function editUser() { - $_GET['edit_user'] = explode("/", $_GET["page"])[3]; - return \file_get_contents(DIR."/html/user_edit.html"); + var_dump($_POST); + $_GET['edit_user'] = explode("/", $_GET["page"])[2]; + + if(isset($_POST["username"]) && isset($_POST["password"]) && isset($_POST["job"]) && isset($_POST["role"])) { + $user = Author::get($_GET["edit_user"]); + $user->setUsername($_POST["username"]); + if($_POST["password"] != '') $user->setPassword($_POST["password"]); + $user->setRole($_POST["role"]); + var_dump($user); + Author::update($user); + // header("Location: /users/"); + } + return file_get_contents(DIR."/html/user_edit.html"); + } + + /** + * @route /\/users\/[0-9]+\/delete\/$/ + * @admin + * @title Modifier un utilisateur + */ + public function deleteUser() { + $_GET['edit_user'] = explode("/", $_GET["page"])[2]; + Author::remove(Author::get($_GET["edit_user"])); + header("Location: /users/"); } diff --git a/assets/php/Tags/UserEditor.php b/assets/php/Tags/UserEditor.php index 01e5e59..a4f8ecc 100644 --- a/assets/php/Tags/UserEditor.php +++ b/assets/php/Tags/UserEditor.php @@ -6,80 +6,41 @@ use App\DB\Category; use DateTime; use App\DB\Tag; use App\DB\Post; +use App\DB\Author; class UserEditor extends \App\Tags\Tag { public function render() { - if($_GET["post"] == "new") $_GET["post"] = null; - elseif(isset($_GET["post"])) $post = Post::get($_GET["post"]); + $user = Author::get($_GET["edit_user"]); //recuperation de la balise de base (pouet) - $pok = $this->getElement(); + $el = $this->getElement(); //recuperation du document (necessaire a la création de balises $doc = $this->getDoc(); - $type = $pok->getAttribute("element"); + $type = $el->getAttribute("element"); switch ($type) { case 'role': foreach (array("Utilisateur" => "ROLE_USER", "Editeur" =>"ROLE_EDITOR", "Admin" => "ROLE_ADMIN") as $key => $value) { $opt = $doc->createElement("option"); $opt->setAttribute("value", $value); + if($user->getRole() == $value) $opt->setAttribute("selected", "selected"); $opt->appendChild($doc->createTextNode($key)); - $el->parentNode->appendChild(); - } - $option = $doc->createElement("option"); - $text = $doc->createTextNode("Categorie"); - $option->setAttribute("value", "1"); - $option->setAttribute("disabled", "true"); - if(!isset($post)) $option->setAttribute("selected", "selected"); - $option->appendChild($text); - $pok->parentNode->insertBefore($option, $pok); - foreach (Category::list() as $cat) { - $option = $doc->createElement("option"); - $text = $doc->createTextNode($cat->getName()); - $option->appendChild($text); - $option->setAttribute("value", $cat->getId()); - if(isset($post) && $post->getCategory()->getId() == $cat->getId()) $option->setAttribute("selected", "selected"); - $pok->parentNode->insertBefore($option, $pok); + $el->parentNode->appendChild($opt); } break; - case 'datetime': - if(isset($post)) $txt = $post->getDateTime(); - else $txt = (new DateTime())->format('d/m/Y H:i:s'); - $pok->parentNode->insertBefore($doc->createTextNode($txt), $pok); - break; - case 'content': - $tarea = $doc->createElement("textarea"); - if(isset($post)) $tarea->appendChild($doc->createTextNode($post->getContent())); - $tarea->setAttribute("style", "width: 100%; min-height: 200px"); - $pok->parentNode->insertBefore($tarea, $pok); - break; - case 'title': + case 'username': $input = $doc->createElement("input"); - $input->setAttribute("style", "width: 100%"); - $input->setAttribute("placeholder", "titre"); - if(isset($post)) $input->setAttribute("value", $post->getTitle()); - $pok->parentNode->insertBefore($input, $pok); + $input->setAttribute("value", $user->getUsername()); + $input->setAttribute("name", "username"); + $el->parentNode->insertBefore($input, $el); + break; + case 'job': + $input = $doc->createElement("input"); + $input->setAttribute("value", $user->getJob()); + $input->setAttribute("name", "job"); + $el->parentNode->insertBefore($input, $el); break; - case 'tags': - foreach (Tag::list() as $el) { - $tg = $doc->createElement("input"); - $tg->setAttribute("id", $el->getId()); - $tg->setAttribute("type", "checkbox"); - $tg->setAttribute("data-text", $el->getName()); - if(isset($post)) { - if(in_array($el, $post->getTags())) $tg->setAttribute("checked", "checked"); - } - $txt = $doc->createElement("label"); - $txt->appendChild($doc->createTextNode($el->getName())); - $txt->setAttribute("for", $el->getId()); - $pok->parentNode->insertBefore($tg, $pok); - $pok->parentNode->insertBefore($txt, $pok); - } - $btn = $doc->createElement("button"); - $btn->appendChild($doc->createTextNode("Add Tag")); - $btn->setAttribute("class", "addTag"); - $pok->parentNode->insertBefore($btn, $pok); default: # code... break; diff --git a/assets/php/Tags/Users.php b/assets/php/Tags/Users.php index d434837..72d20b2 100644 --- a/assets/php/Tags/Users.php +++ b/assets/php/Tags/Users.php @@ -12,6 +12,7 @@ class Users extends Tag { $parent = $el->parentNode; foreach (Author::list(true, 1000) as $user) { $pok = $el->childNodes->item(0)->cloneNode(true); + $pok->setAttribute("onclick", "window.location = window.location + '" . $user->getId() . "/edit/'"); $parent->insertBefore($pok, $el); diff --git a/assets/php/db/Author.php b/assets/php/db/Author.php index b4b0279..a8b90b4 100644 --- a/assets/php/db/Author.php +++ b/assets/php/db/Author.php @@ -12,7 +12,7 @@ class Author { private $password; - private $job; + private $job = "Aprenant"; private $role = "ROLE_USER"; @@ -134,15 +134,16 @@ class Author { } public static function remove(Author $author) { - Functions::connect()->prepare("DELETE FROM author WHERE id=:id")->execute(array(":id" => $author->getId())); + Functions::connect()->prepare("DELETE FROM users WHERE id=:id")->execute(array(":id" => $author->getId())); } public static function update(Author $author) { - Functions::connect()->prepare("UPDATE author SET name=':name', password=':password', job=':job' WHERE id=:id")->execute(array( + Functions::connect()->prepare("UPDATE users SET username=:username, password=:password, job=:job, role=:role WHERE id=:id")->execute(array( ":username" => $author->getUsername(), ":password" => $author->getPassword(), ":job" => $author->getJob(), + ":role" => $author->getRole(), ":id" => $author->getId() )); } diff --git a/assets/php/db/Post.php b/assets/php/db/Post.php index 15f9afb..993e864 100644 --- a/assets/php/db/Post.php +++ b/assets/php/db/Post.php @@ -286,7 +286,16 @@ class Post { * */ public static function remove(Post $post) { - Functions::connect()->prepare("DELETE FROM posts WHERE id=:id")->execute(array(":id" => $post->getId())); + + $id = $post->getId(); + + $prepared = Functions::connect()->prepare("DELETE FROM post_tag WHERE post_id=:id"); + $prepared->bindValue(":id", $id, PDO::PARAM_INT); + $prepared->execute(); + + $prepared = Functions::connect()->prepare("DELETE FROM posts WHERE id=:id"); + $prepared->bindValue(":id", $id, PDO::PARAM_INT); + $prepared->execute(); }