public function route($params) { $userManager = new UserManager(); $user = $userManager->returnUser(); if (!$user) { $this->redirect("login"); } switch ($user['role']) { case 2: $this->view = 'admin_dashboard'; break; case 1: $reviewManager = new ReviewManager(); $this->data['no_reviewed'] = $reviewManager->return_no_reviewed($user['id_user']); $this->data['reviewed'] = $reviewManager->return_reviewed($user['id_user']); $this->view = 'reviewer_dashboard'; break; case 0: default: $this->view = 'author_dashboard'; break; } $header_menu = 'login_bar'; $this->data['title_html'] = 'Hlavní panel'; $this->head['title_html'] = $this->data['title_html']; $this->header_menu = $header_menu; }
/** * @return SS_HTTPResponse */ public function approveReview() { try { $review_id = intval($this->request->param('REVIEW_ID')); $this->review_manager->toggleApproved($review_id); return $this->updated(); } catch (NotFoundEntityException $ex1) { SS_Log::log($ex1, SS_Log::ERR); return $this->notFound($ex1->getMessage()); } catch (Exception $ex) { SS_Log::log($ex, SS_Log::ERR); return $this->serverError(); } }
public function route($params) { $articleManager = new ArticleManager(); $userManager = new UserManager(); $user = $userManager->returnUser(); $this->data['title_html'] = ""; $header_menu = 'login_bar'; if (!$user) { $this->addMessage("Pro tuto akci je nutné se přihlásit"); $this->redirect("login"); } $this->header_menu = $header_menu; if (empty($params[0])) { $this->redirect("dashboard"); } switch ($params[0]) { case 'new': $this->checkUser(0); $_POST = NULL; $this->data['title_html'] = 'Nový článek'; $this->view = 'new_article'; break; case 'my': $this->data['title_html'] = 'Mé články'; $this->checkUser(0); if (isset($params[1])) { $article = $articleManager->return_article($params[1]); //var_dump($article); $this->data['id_article'] = $article['id_article']; $this->data['title'] = $article['title']; $this->data['authors'] = $article['authors']; $this->data['notes'] = $article['notes']; $this->data['link_pdf'] = $article['link_pdf']; $this->view = 'my_article'; } else { //$this->data['articles'] = $articleManager->return_all_articles(); $this->data['articles'] = $articleManager->return_my_articles($user['id_user']); $this->view = 'my_articles'; } break; case 'add': $this->checkUser(0); $this->data['title'] = $_POST['title']; $article = DBmodel::fromPOST(Article::class); // ověřím vyplnění zaslaných dat if ($article) { $articleManager = new ArticleManager(); $res = $articleManager->get_last_id()->fetch(); $id = "_1"; if ($res) { $id = "_" . ($res['id_article'] + 1); } $file_ok = 0; $target_dir = "pdf/"; $target_name = explode(".", $_FILES["link_pdf"]["name"])[0] . $id; $target_extension = explode(".", $_FILES["link_pdf"]["name"])[1]; $target_file = $target_dir . $target_name . "." . $target_extension; if ($target_extension != "pdf") { $this->addMessage("Nahraný dokument není ve formátu pdf"); } else { // je to pdf if (move_uploaded_file($_FILES["link_pdf"]["tmp_name"], $target_file)) { $this->addMessage("Dokument byl úspěšně nahrán na server"); $file_ok = 1; } else { $file_ok = 0; $this->addMessage("Chyba při nahrávání dokumentu na server"); } } if ($file_ok) { $article->link_pdf = $target_file; $articleManager->add_new_article($article, $user['id_user']); $this->addMessage("Článek byl úspěšně přidán"); } else { $this->addMessage("PDF dokument se nepodařilo nahrát na server <b>" . $_FILES["link_pdf"]["name"] . "</b>"); } $this->redirect("article/my"); } else { $this->addMessage("Článek nebyl přidán kvůli nevyplněným údajům"); } $this->data['title'] = $_POST['title']; $this->view = 'new_article'; break; case 'remove': $this->checkUser(0); $articleManager->delete_article_database($params[1], $user['id_user']); $this->redirect("article/my"); break; case 'manager': $this->data['title_html'] = 'Správa článků'; $this->checkUser(2); $articles = $articleManager->return_all_articles_w_reviews(); // final articles $fa = array(); foreach ($articles as $key => $a) { if (!isset($fa[$a['id_article']])) { $fa[$a['id_article']] = $a->toArray(); $fa[$a['id_article']]['reviews'] = []; } if ($a['id_review'] != null) { $fa[$a['id_article']]['reviews'][] = $a; } if (count($fa[$a['id_article']]['reviews']) == 3) { if ($fa[$a['id_article']]['reviews'][0]['accepted']) { $fa[$a['id_article']]['can_accept'] = "<span class='accepted'>Schváleno!</span>"; } else { $fa[$a['id_article']]['can_accept'] = '<input type="submit" class="btn btn-primary btn-block" value="Schválit">'; } //die(); } else { $fa[$a['id_article']]['can_accept'] = "<span class='accepted-no'>Nedostatek recenzí</span>"; } } $this->data['users'] = $userManager->return_all_users_by_role(1); $this->data['articles'] = $fa; $this->view = 'articles_editor'; break; case 'review': $this->data['title_html'] = 'Recenze článku'; if (!isset($params[1])) { $this->redirect("dashboard"); } $article = $articleManager->return_article($params[1]); $this->data['title'] = $article['title']; $this->data['authors'] = $article['authors']; $this->data['notes'] = $article['notes']; $this->data['link_pdf'] = $article['link_pdf']; $this->data['article_id_article'] = $params[1]; $this->view = 'review_article'; break; case 'add-review': $this->checkUser(1); $review = DBmodel::fromPOST(Review::class); // ověřím vyplnění zaslaných dat if ($review) { $reviewManager = new ReviewManager(); $reviewManager->add_review($review, $user['id_user']); $this->addMessage("Recenze byla úspěšně odeslána"); $this->redirect("dashboard"); } else { $this->addMessage("Recenze nebyla přidána kvůli neyplněným údajům"); } break; case 'remove-review': $this->checkUser(2); $reviewManager = new ReviewManager(); $reviewManager->delete_review($params[1]); $this->redirect("article/manager"); break; case 'add-reviewer': $this->checkUser(2); $reviewManager = new ReviewManager(); if ($reviewManager->add_reviewer($_POST['id_article'], $_POST['reviewer'])) { $this->addMessage("Recenzent byl úspěšně přidělen"); } else { $this->addMessage("Vybraný recenzent má již tento článek přidělen"); } $this->redirect("article/manager"); break; case 'accept': $this->checkUser(2); $accept = DBmodel::fromPOST(Accept::class); // ověřím vyplnění zaslaných dat if ($accept) { $reviewManager = new ReviewManager(); $reviewManager->accept_reviews($accept); $this->addMessage("Recenze byly úspěšně schváleny"); } else { $this->addMessage("Recenze nemohly být schváleny, protože jich není dostatečný počet: <b>3</b>"); } $this->redirect("article/manager"); break; case 'update': // editace článku $this->data['title_html'] = 'Úprava článku'; $this->checkUser(0); $article = DBmodel::fromPOST(Article::class); // ověřím vyplnění zaslaných dat if ($article) { $articleManager->update_article($article, $_POST['id_article']); $this->addMessage("Článek byl úspěšně upraven"); } else { $this->addMessage("Článek nebyl upraven kvůli nevyplněným údajům"); } $this->redirect("article/my/" . $_POST['id_article']); break; case 'upload': // nahrání nového PDF $this->checkUser(0); $articleManager = new ArticleManager(); $res = $articleManager->get_last_id()->fetch(); $id = "_1"; if ($res) { $id = "_" . $res['id_article']; } $target_dir = "pdf/"; $target_name = explode(".", $_FILES["fileToUpload"]["name"])[0] . $id; $target_extension = explode(".", $_FILES["fileToUpload"]["name"])[1]; $target_file = $target_dir . $target_name . "." . $target_extension; if (isset($_POST["submit"])) { if ($target_extension != "pdf") { $this->addMessage("Nahraný dokument není ve formátu pdf"); } else { // je to pdf if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { $articleManager->update_article_file($target_name . "." . $target_extension, $_POST['id_article']); $this->addMessage("Dokument byl úspěšně nahrán na server"); } else { $this->addMessage("Chyba při nahrávání dokumentu na server"); } } } $this->redirect("article/my/" . $_POST['id_article']); break; default: $this->redirect("dashboard"); break; } $this->head['title_html'] = $this->data['title_html']; }