D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
ksclnmuac
/
public_html
/
alumni
/
application
/
controllers
/
admin
/
Filename :
Notification.php
back
Copy
<?php /** * Description of User * * @author Softpro India Pvt. Ltd. */ class Notification extends CI_Controller { //put your code here public function __construct() { parent::__construct(); $this->load->model("admin/NotificationManagement"); } public function index() { if ($this->sessionvalidator->validateSession()) { $viewData["notifications"] = $this->NotificationManagement->getNotifications()->result(); $this->load->view("admin/notifications", $viewData); } else { redirect("admin/"); } } public function createNotification() { if ($this->sessionvalidator->validateSession() && $this->sessionvalidator->getRole() == "Master Admin") { $this->load->view("admin/createNotification"); } else { redirect("admin/"); } } public function saveNotification() { if ($this->sessionvalidator->validateSession() && $this->sessionvalidator->getRole() == "Master Admin") { $this->form_validation->set_rules("title", "title", "required", array("required" => "Enter Notification Title.")); $this->form_validation->set_rules("occasion", "occasion", "required", array("required" => "Enter Notification Occasion/Festival.")); $this->form_validation->set_rules("schedule_date", "schedule date", "required", array("required" => "Select Schedule Date.")); $this->form_validation->set_rules("for", "notification for", "required", array("required" => "Select Notification For.")); $this->form_validation->set_rules("type", "notification type", "required", array("required" => "Select Notification Type.")); $this->form_validation->set_rules("content", "notification content", "required", array("required" => "Enter Notification Content.")); //$adminData=$this->session->userdata("alumni_admin_data"); if ($this->form_validation->run() == false) { $this->createNotification(); } else { $title = addslashes(trim($this->input->post("title"))); $occasion = addslashes(trim($this->input->post("occasion"))); $schedule_date = date('Y-m-d', strtotime(str_replace('/', '-', $this->input->post("schedule_date")))); $for = $this->input->post("for"); $type = $this->input->post("type"); $content = addslashes(trim($this->input->post("content"))); $url = addslashes(trim($this->input->post("url"))); $photo = ""; $icon; $notificationDetails; if (!empty($_FILES['icon']['name'])) { $fileConfig["upload_path"] = "./assets/admin/uploads/notificationImages/"; $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("icon")) { $this->session->set_flashdata("errorMessage", $this->upload->display_errors()); $this->createNotification(); } else { $this->upload->do_upload("icon"); $icon = "assets/admin/uploads/notificationImages/".$this->upload->data()["file_name"]; } } else { $icon = "assets/admin/uploads/notificationImages/bell.png"; } if (!empty($_FILES['photo']['name'])) { $fileConfig["upload_path"] = "./assets/admin/uploads/notificationImages/"; $fileConfig["allowed_types"] = "jpg|png|gif"; $fileConfig["max_size"] = "500"; $fileConfig["file_ext_tolower"] = TRUE; $fileConfig["encrypt_name"] = TRUE; $this->load->library("upload", $fileConfig); if (!$this->upload->do_upload("photo")) { $this->session->set_flashdata("errorMessage", $this->upload->display_errors()); $this->createNotification(); } else { $photo = "assets/admin/uploads/notificationImages/" . $this->upload->data()["file_name"]; //$this->upload->do_upload("photo"); $notificationDetails = array( "n_title" => $title, "n_occasion" => $occasion, "n_scheduled_date" => $schedule_date, "n_date_added" => date("Y-m-d"), "n_content" => $content, "admin_id" => $this->session->userdata("alumni_admin_data")["admin_id"], "n_url" => $url, "n_type" => $type, "n_status" => "t", "n_for" => $for, "n_icon" => $icon, "n_photo" => $photo); $inserted_id = $this->NotificationManagement->saveNotification($notificationDetails); if ($inserted_id > 0) { $this->session->set_flashdata("successMessage", "Notification Created Successfully."); redirect("admin/Notification"); } else { $this->session->set_flashdata("errorMessage", "Failed To Create Notification."); $this->createNotification(); } } } else { //photo is not uploaded in this case $notificationDetails = array( "n_title" => $title, "n_occasion" => $occasion, "n_scheduled_date" => $schedule_date, "n_date_added" => date("Y-m-d"), "n_content" => $content, "admin_id" => $this->session->userdata("alumni_admin_data")["admin_id"], "n_url" => $url, "n_type" => $type, "n_status" => "t", "n_for" => $for, "n_icon" => $icon, "n_photo" => $photo); $inserted_id = $this->NotificationManagement->saveNotification($notificationDetails); if ($inserted_id > 0) { $this->session->set_flashdata("successMessage", "Notification Created Successfully."); redirect("admin/Notification"); } else { $this->session->set_flashdata("errorMessage", "Failed To Create Notification."); $this->createNotification(); } } } } else { redirect("admin/"); } } public function getNotificationDetails() { if ($this->sessionvalidator->validateSession()) { $n_id = $_POST["n_id"]; $notification = $this->NotificationManagement->getNotificationById($n_id)->result()[0]; $type = ""; if ($notification->n_type == "G") $type = "General"; else if ($notification->n_type == "B") $type = "Birthday Wish"; else if ($notification->n_type == "M") $type = "Marriage Anniversary "; else if ($notification->n_type = "S") $type = "Special"; else if ($notification->n_type = "F") $type = "Festical Wish"; $responseData = array( 'csrfName' => $this->security->get_csrf_token_name(), 'csrfHash' => $this->security->get_csrf_hash(), 'type' => $type, 'title' => $notification->n_title, 'content' => $notification->n_content, 'occasion' => $notification->n_occasion, 'photo' => $notification->n_photo, 'icon' => $notification->n_icon, 'date_added' => date("d-m-Y", strtotime($notification->n_date_added)), 'scheduled_date' => date("d-m-Y", strtotime($notification->n_scheduled_date)), 'url' => $notification->n_url, 'for' => $notification->n_for, 'by' => $notification->admin_id ); echo json_encode($responseData); } else { redirect("admin/"); } } public function editNotification($n_id) { if ($this->sessionvalidator->validateSession()) { $notification = $this->NotificationManagement->getNotificationById($n_id)->result(); if (sizeof($notification) > 0) { $viewData["notification"] = $notification[0]; $this->load->view("admin/editNotification", $viewData); } else { $this->session->set_flashdata("errorMessage", "Failed To Load Notification Found With Such ID."); redirect("admin/Notification"); } } else { redirect("admin/"); } } public function updateNotification() { if ($this->sessionvalidator->validateSession() && $this->sessionvalidator->getRole() == "Master Admin") { $this->form_validation->set_rules("title", "title", "required", array("required" => "Enter Notification Title.")); $this->form_validation->set_rules("occasion", "occasion", "required", array("required" => "Enter Notification Occasion/Festival.")); $this->form_validation->set_rules("schedule_date", "schedule date", "required", array("required" => "Select Schedule Date.")); $this->form_validation->set_rules("for", "notification for", "required", array("required" => "Select Notification For.")); $this->form_validation->set_rules("type", "notification type", "required", array("required" => "Select Notification Type.")); $this->form_validation->set_rules("content", "notification content", "required", array("required" => "Enter Notification Content.")); $n_id = $this->input->post("n_id"); if ($this->form_validation->run() == false) { $this->editNotification($n_id); } else { $title = addslashes(trim($this->input->post("title"))); $occasion = addslashes(trim($this->input->post("occasion"))); $schedule_date = date('Y-m-d', strtotime(str_replace('/', '- ', $this->input->post("schedule_date")))); $for = $this->input->post("for"); $type = $this->input->post("type"); $content = addslashes(trim($this->input->post("content"))); $url = addslashes(trim($this->input->post("url"))); $photo = ""; $icon = ""; $notificationDetails; if (!empty($_FILES['icon']['name'])) { $fileConfig["upload_path"] = "./assets/admin/uploads/notificationImages/"; $fileConfig["allowed_types"] = "jpg|png|gif"; $fileConfig["max_size"] = "500"; $fileConfig["file_ext_tolower"] = TRUE; $fileConfig["encrypt_name"] = TRUE; $this->load->library("upload", $fileConfig); if (!$this->upload->do_upload("icon")) { $this->session->set_flashdata("errorMessage", $this->upload->display_errors()); $this->editNotification($n_id); } else { $this->upload->do_upload("icon"); $icon = "assets/admin/uploads/notificationImages/" . $this->upload->data()["file_name"]; } } else { $icon = ($this->input->post("prev_n_icon") == null || $this->input->post("prev_n_icon") == "") ? "assets/admin/uploads/notificationImages/bell.png" : $this->input->post("prev_n_icon"); } if (!empty($_FILES['photo']['name'])) { $fileConfig["upload_path"] = "./assets/admin/uploads/notificationImages/"; $fileConfig["allowed_types"] = "jpg|png|gif"; $fileConfig["max_size"] = "500"; $fileConfig["file_ext_tolower"] = TRUE; $fileConfig["encrypt_name"] = TRUE; $this->load->library("upload", $fileConfig); if (!$this->upload->do_upload("photo")) { $this->session->set_flashdata("errorMessage", $this->upload->display_errors()); $this->editNotification($n_id); } else { $photo = "assets/admin/uploads/notificationImages/" . $this->upload->data()["file_name"]; //$this->upload->do_upload("photo"); $notificationDetails = array( "n_title" => $title, "n_occasion" => $occasion, "n_scheduled_date" => $schedule_date, "n_content" => $content, "admin_id" => $this->session->userdata("alumni_admin_data")["admin_id"], "n_url" => $url, "n_type" => $type, "n_status" => "t", "n_for" => $for, "n_icon" => $icon, "n_photo" => $photo); if ($this->NotificationManagement->updateNotification($notificationDetails, $n_id)) { $this->session->set_flashdata("successMessage", "Notification Updated Successfully."); $this->index(); } else { $this->session->set_flashdata("errorMessage", "Failed To Update Notification."); $this->editNotification($n_id); } } } else { //photo is not uploaded in this case $notificationDetails = array( "n_title" => $title, "n_occasion" => $occasion, "n_scheduled_date" => $schedule_date, "n_content" => $content, "admin_id" => $this->session->userdata("alumni_admin_data")["admin_id"], "n_url" => $url, "n_type" => $type, "n_status" => "t", "n_for" => $for, "n_icon" => $icon, "n_photo" => ($this->input->post("prev_n_photo") == null || $this->input->post("prev_n_photo") == "") ? "" : $this->input->post("prev_n_photo") ); if ($this->NotificationManagement->updateNotification($notificationDetails, $n_id)) { $this->session->set_flashdata("successMessage", "Notification Updated Successfully."); $this->index(); } else { $this->session->set_flashdata("errorMessage", "Failed To Update Notification."); $this->editNotification($n_id); } } } } else { redirect("admin/"); } } public function toggleNotificationStatus($n_id, $chnagedStatus) { if ($this->sessionvalidator->validateSession()) { $notificationDetails = array( 'n_status' => $chnagedStatus ); if ($this->NotificationManagement->updateNotification($notificationDetails, $n_id)) { $this->session->set_flashdata('successMessage', 'Notification Status Updated Successfully.'); redirect("admin/Notification"); } else { $this->session->set_flashdata('errorMessage', 'Failed To Update Notification Status.'); redirect("admin/Notification"); } } else { redirect("admin/"); } } }