public function createReply() { // Create needed instances $formval = new FormHelper(); $session = new SessionHelper(); $thisuser = new User(); $newpost = new Post(); $postModel = new PostModel(); $toppostid = $formval->testInput($_POST['toppost_id']); $toppost = new Post($toppostid); $currentcategory = new Category($toppost->category_id); // Grab all data // It's a reply so no title $newpost->title = ''; $newpost->contents = $formval->testInput($_POST['contents']); // It's a reply so insert the toppost id $newpost->post_relation_id = $toppostid; // The post_relation_id takes care of showing this post under the right toppost $newpost->category_id = $toppost->category_id; $newpost->user_id = $thisuser->id; $newpost->date_created = time(); // Validate if contents is not empty $formval->fieldEmpty('Contents', $newpost->contents); if ($formval->formErrors()) { $session->setMessage('Please provide contents', 3); redirectTo(BASE_URL . 'index.php?c=user&a=viewcreatereply&id=' . $toppostid); } // The action of createTopPost would be the same as createReply if ($currentcategory->is_locked != 1 && $postModel->createTopPost($newpost)) { $session->setMessage('Reply posted', 4); redirectTo(BASE_URL . 'index.php?c=user&a=viewpost&id=' . $toppostid); } else { if ($currentcategory->is_locked == 1) { $session->setMessage('Reply not created, category is locked', 2); } else { $session->setMessage('Reply not created', 3); } redirectTo(BASE_URL . 'index.php?c=user&a=viewpost&id=' . $toppostid); } }
private function _authenticate() { $session = new SessionHelper(); $formval = new FormHelper(); // Captcha include_once BASE_URI . 'app/vendor/securimage/securimage.php'; $securimage = new Securimage(); if ($securimage->check($formval->testInput($_POST['captcha_code'])) == false) { $session->setMessage('Verification code was incorrect, please try again', 3); return false; } $username = $formval->testInput($_POST['username']); $password = $formval->testInput($_POST['password']); $usermodel = new UserModel(); if ($usermodel->authenticateUser($username, $password)) { return true; } else { $session->setMessage('Username / password incorrect or acount inactive', 3); return false; } }
public function editCategoryLocked() { $session = new SessionHelper(); $formval = new FormHelper(); // Id of the category being changed $id = $formval->testInput($_POST['id']); $categorymodel = new CategoryModel(); if ($formval->testInput($_POST['lock'])) { if ($categorymodel->changeLocked($id, 1)) { $session->setMessage('Setting changed', 4); redirectTo(BASE_URL . 'index.php?c=user&a=editcategory&id=' . $id); } else { $session->setMessage('Setting not changed', 3); redirectTo(BASE_URL . 'index.php?c=user&a=editcategory&id=' . $id); } } elseif ($formval->testInput($_POST['unlock'])) { if ($categorymodel->changeLocked($id, 0)) { $session->setMessage('Setting changed', 4); redirectTo(BASE_URL . 'index.php?c=user&a=editcategory&id=' . $id); } else { $session->setMessage('Setting not changed', 3); redirectTo(BASE_URL . 'index.php?c=user&a=editcategory&id=' . $id); } } else { $session->setMessage('Setting not changed', 3); redirectTo(BASE_URL . 'index.php?c=user&a=editcategory&id=' . $id); } }