public function go()
 {
     if (isset($_GET['id'])) {
         $id = $_GET['id'];
     }
     if (isset($_GET['source']) && $_GET['source'] == "new") {
         $this->addSuccessMessage("Article has been added succesfully");
     }
     if (isset($_POST['submit'])) {
         if ($_POST['title'] == '') {
             $this->addErrorMessage("Title of the article should not be empty");
         } elseif (!isset($_POST['is_published'])) {
             $this->addErrorMessage("Please tell if the article has been published successfully?");
         } elseif ($_POST['content'] == '') {
             $this->addErrorMessage("Article post should not be empty");
         } else {
             $this->title = $_POST['title'];
             $this->is_published = $_POST['is_published'];
             $this->content = $_POST['content'];
             $this->last_modified = date("Y-m-d H-i-s");
             $this->last_modified_by = Session::getLoggedInUser();
             ArticleBackend::updateArticle($id, $this->title, $this->content, $this->last_modified, $this->last_modified_by);
             $this->addSuccessMessage("Article has been updated succesfully");
         }
     }
     $article = ArticleBackend::getArticle($id);
     $this->setViewTemplate('editarticle.tpl');
     $this->addToView('article', $article[0]);
     $this->generateView();
     if (isset($_POST['deletesubmit'])) {
         ArticleBackend::deleteArticle($id);
         header('Location:' . SOURCE_ROOT_PATH . "admin/pages/articlemanager.php?source=del");
     }
 }
 public function go()
 {
     if (isset($_GET['source']) && $_GET['source'] == "del") {
         $this->addSuccessMessage("Article has been deleted succesfully");
     }
     if (isset($_GET['search']) && isset($_GET['category']) && $_GET['search'] != '' && $_GET['category'] != '') {
         $total_pages = ArticleBackend::getNumberofArticles($_GET['search'], $_GET['category']);
     } else {
         $total_pages = ArticleBackend::getNumberOfArticles();
     }
     $targetpage = SOURCE_ROOT_PATH . "admin/pages/articlemanager.php";
     $stages = 5;
     $page = 0;
     if (isset($_GET['page'])) {
         $page = $_GET['page'];
     }
     if (isset($_GET['limit']) && $_GET['limit'] != "") {
         $limit = $_GET['limit'];
     } else {
         $limit = 25;
     }
     if ($page) {
         $start = ($page - 1) * $limit;
     } else {
         $start = 0;
     }
     // Initial page num setup
     if ($page == 0) {
         $page = 1;
     }
     $prev = $page - 1;
     $next = $page + 1;
     $lastpage = ceil($total_pages / $limit);
     $LastPagem1 = $lastpage - 1;
     $pagination = array('lastpage' => $lastpage, 'page' => $page, 'targetpage' => $targetpage, 'prev' => $prev, 'next' => $next, 'stages' => $stages, 'last_page_m1' => $LastPagem1);
     if (isset($_GET['search']) && isset($_GET['category']) && $_GET['search'] != '' && $_GET['category'] != '') {
         $articles = ArticleBackend::getNArticles($start, $limit, $_GET['search'], $_GET['category']);
     } else {
         $articles = ArticleBackend::getNarticles($start, $limit);
     }
     $this->addToView('articles', $articles);
     $this->addToView('total_pages', $total_pages);
     $this->addToView('pagination', $pagination);
     $this->setViewTemplate('articlemanager.tpl');
     $this->generateView();
 }
 public function go()
 {
     $this->setViewTemplate('editor.tpl');
     if (isset($_POST['submit'])) {
         if ($_POST['title'] == '') {
             $this->addErrorMessage("Title of the article should not be empty");
         } elseif (!isset($_POST['is_published'])) {
             $this->addErrorMessage("Please tell if the article has been published successfully?");
         } elseif ($_POST['content'] == '') {
             $this->addErrorMessage("Article post should not be empty");
         } else {
             $this->created_by = Session::getLoggedInUser();
             $this->title = $_POST['title'];
             $this->is_published = $_POST['is_published'];
             $this->content = $_POST['content'];
             $this->date_posted = date("Y-m-d H:i:s");
             ArticleBackend::addArticle($this->title, $this->content, $this->date_posted, $this->created_by, $this->is_published);
             $this->addSuccessMessage("Article has been added succesfully");
             $id = ArticleBackend::insertId();
             header('Location: ' . SOURCE_ROOT_PATH . "admin/pages/editarticle.php?id={$id}&source=new");
         }
     }
     $this->generateView();
 }