D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
ksclnmuac
/
www
/
grievance
/
sys_admin
/
application
/
controllers
/
admin
/
Filename :
SystemAdmin.php
back
Copy
<?php /** * Controller Class For System Admin Module * * @author Softpro India Pvt. Ltd. */ defined('BASEPATH') OR exit('No direct script access allowed'); class SystemAdmin extends CI_Controller { public function __construct() { parent::__construct(); $this->load->helper('url'); $this->load->library('session'); $this->load->helper('form'); $this->load->library('form_validation'); $this->load->model("admin/SystemAdminManagement"); } public function index() { if ($this->session->userdata('logged_in')) { $viewData['allAdmins'] = $this->SystemAdminManagement->getAllAdmins()->result(); $this->load->view('admin/sys_admins', $viewData); } else { redirect("admin/"); } } public function addNewSysAdmin() { if ($this->session->userdata('logged_in')) { $this->load->view('admin/add_sys_admin'); } else { redirect("admin/"); } } public function createNewSysAdmin() { if ($this->session->userdata('logged_in')) { $this->form_validation->set_rules('admName', 'Admin Name', 'trim|required', array('required' => 'Admin Name Can Not Be Blank.')); $this->form_validation->set_rules('admUserName', 'Admin Username', 'trim|required', array('required' => 'Admin Username Can Not Be Blank')); $this->form_validation->set_rules('admEmail', 'Admin Email', 'trim|required|valid_email', array('required' => 'Admin Email Is Required.')); $this->form_validation->set_rules('admMobile', 'Admin Mobile', 'trim|required|numeric|min_length[10]|max_length[10]', array('required' => 'Admin Mobile Is Required.')); $this->form_validation->set_rules('admRole', 'Admin Role', 'required', array('required' => 'Admin Role Is Required.')); $this->form_validation->set_rules('admType', 'Admin Type', 'required', array('required' => 'Admin Type Is Required.')); $this->form_validation->set_rules('admSMSAuth', 'Admin SMS Allow Status', 'required', array('required' => 'Admin SMS Allow Status Is Required.')); if ($this->form_validation->run() == FALSE) { $this->addNewSysAdmin(); } else { $queryByUserName = $this->SystemAdminManagement->getAdminInfoByUserName($this->input->post('admUserName')); $adminInfoByUserName = $queryByUserName->result(); $queryByEmail = $this->SystemAdminManagement->getAdminInfoByEmail($this->input->post('admEmail')); $adminInfoByEmail = $queryByEmail->result(); $queryByMobile = $this->SystemAdminManagement->getAdminInfoByMobileNumber($this->input->post('admMobile')); $adminInfoByMobile = $queryByMobile->result(); if (sizeof($adminInfoByUserName)) { $this->session->set_flashdata('errorMessage', "The Requested Username Already Exits. Please choose A Different Username."); $this->addNewSysAdmin(); } else if (sizeof($adminInfoByEmail)) { $this->session->set_flashdata('errorMessage', "An Admin With This Email Already Exits. Please Try With Different Email."); $this->addNewSysAdmin(); } else if (sizeof($adminInfoByMobile)) { $this->session->set_flashdata('errorMessage', "An Admin With This Mobile Number Already Exits. Please Try With Different Mobile."); $this->addNewSysAdmin(); } else { if (empty($_FILES['profileImg']['name'])) { $profileImageNameWithPath = base_url("assets/images/adminimgs/default.png"); } else { $profileImageNameWithPath = ""; $configProfileImg['upload_path'] = './assets/images/adminimgs/'; $configProfileImg['allowed_types'] = 'jpeg|jpg|png|webp'; //$configProfileImg['max_width'] = '320'; //$configProfileImg['max_height'] = '220'; $configProfileImg['max_size'] = '800'; $configProfileImg['file_ext_tolower'] = TRUE; $configProfileImg['encrypt_name'] = TRUE; $this->load->library('upload', $configProfileImg); if (!$this->upload->do_upload('profileImg')) { $this->session->set_flashdata('errorMessage', "The Profile Image Can Not Be Uploaded As It Do Not Match With Profile Image Criteria. File Size 800 KB Max. & Allowed Extension: Only *.jpeg,*.jpg,*.png,*.webp"); $this->addNewSysAdmin(); } else { $profileImageNameWithPath = base_url("assets/images/adminimgs/") . $this->upload->data()['file_name']; $password = "12345"; $newAdminInfo = array( 'sa_name' => $this->input->post('admName'), 'sa_username' => $this->input->post('admUserName'), 'sa_password' => MD5($password), 'sa_email' => $this->input->post('admEmail'), 'sa_mobile' => $this->input->post('admMobile'), 'sa_type' => $this->input->post('admType'), 'sa_role' => $this->input->post('admRole'), 'sa_auth_sms_flag' => $this->input->post('admSMSAuth'), 'sa_image_url' => $profileImageNameWithPath, 'sa_added_on' => date("Y-m-d H:i:s"), 'sa_added_by' => $this->session->userdata('id'), 'sa_updated_on' => date("Y-m-d H:i:s"), 'sa_updated_by' => $this->session->userdata('id') ); if ($this->SystemAdminManagement->createNewAdmin($newAdminInfo)) { $this->session->set_flashdata('successMessage', 'System Admin Added Successfully.'); redirect("admin/SystemAdmin/"); } else { $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Creating System Admin. Try Later.'); $this->addNewSysAdmin(); } } } } } } else { redirect("admin/"); } } public function toggleAdminBlockStatus($sa_id, $toUpdateStatus) { if ($this->session->userdata('logged_in')) { $adminUpdateData = array( 'sa_id' => $sa_id, 'sa_active_status' => $toUpdateStatus, 'sa_updated_on' => date("Y-m-d H:i:s"), 'sa_updated_by' => $this->session->userdata('id') ); if ($this->SystemAdminManagement->updateAdminInfo($adminUpdateData)) { $this->session->set_flashdata('successMessage', 'Block Status Updated Successfully.'); redirect("admin/SystemAdmin/"); } else { $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Block Status. Try Later.'); redirect("admin/SystemAdmin/"); } } else { redirect("admin/"); } } public function deleteAdmin($sa_id) { if ($this->session->userdata('logged_in')) { $adminDeleteData = array( 'sa_id' => $sa_id, 'sa_updated_on' => date("Y-m-d H:i:s"), 'sa_updated_by' => $this->session->userdata('id'), 'sa_delete_status' => 'T' ); $this->SystemAdminManagement->updateAdminInfo($adminDeleteData); redirect("admin/SystemAdmin/"); } else { redirect("admin/"); } } public function undoDeleteAdmin($sa_id) { if ($this->session->userdata('logged_in')) { $adminUndoDeleteData = array( 'sa_id' => $sa_id, 'sa_updated_on' => date("Y-m-d H:i:s"), 'sa_updated_by' => $this->session->userdata('id'), 'sa_delete_status' => 'F' ); $this->SystemAdminManagement->updateAdminInfo($adminUndoDeleteData); redirect("admin/SystemAdmin/"); } else { redirect("admin/"); } } public function editAdmin($sa_id) { if ($this->session->userdata('logged_in')) { $viewData['admin_info'] = $this->SystemAdminManagement->getAdminInfoById($sa_id)->result()[0]; $this->load->view('admin/edit_sys_admin', $viewData); } else { redirect("admin/"); } } public function updateSysAdmin() { if ($this->session->userdata('logged_in')) { $this->form_validation->set_rules('admName', 'Admin Name', 'trim|required', array('required' => 'Admin Name Can Not Be Blank.')); $this->form_validation->set_rules('admEmail', 'Admin Email', 'trim|required|valid_email', array('required' => 'Admin Email Is Required.')); $this->form_validation->set_rules('admMobile', 'Admin Mobile', 'trim|required|numeric|min_length[10]|max_length[10]', array('required' => 'Admin Mobile Is Required.')); $this->form_validation->set_rules('admRole', 'Admin Role', 'required', array('required' => 'Admin Role Is Required.')); $this->form_validation->set_rules('admType', 'Admin Type', 'required', array('required' => 'Admin Type Is Required.')); $this->form_validation->set_rules('admSMSAuth', 'Admin SMS Allow Status', 'required', array('required' => 'Admin SMS Allow Status Is Required.')); $adminCurrentProfileImageFileName = substr($this->input->post('admProfileImgPath'), strripos($this->input->post('admProfileImgPath'), "/") + 1); if ($this->form_validation->run() == FALSE) { $this->editAdmin($this->input->post('admId')); } else { if (!$this->SystemAdminManagement->isEmailSafeUpdate($this->input->post('admId'), $this->input->post('admEmail'))) { $this->session->set_flashdata('errorMessage', "An Admin With This Email Already Exits. Please Try With Different Email."); $this->editAdmin($this->input->post('admId')); } else if (!$this->SystemAdminManagement->isMobileSafeUpdate($this->input->post('admId'), $this->input->post('admMobile'))) { $this->session->set_flashdata('errorMessage', "An Admin With This Mobile Number Already Exits. Please Try With Different Mobile."); $this->editAdmin($this->input->post('admId')); } else { if (empty($_FILES['profileImg']['name'])) { $profileImageNameWithPath = $this->input->post('admProfileImgPath'); $adminUpdateInfo = array( 'sa_id' => $this->input->post('admId'), 'sa_name' => $this->input->post('admName'), 'sa_email' => $this->input->post('admEmail'), 'sa_mobile' => $this->input->post('admMobile'), 'sa_type' => $this->input->post('admType'), 'sa_role' => $this->input->post('admRole'), 'sa_auth_sms_flag' => $this->input->post('admSMSAuth'), 'sa_image_url' => $profileImageNameWithPath, 'sa_updated_on' => date("Y-m-d H:i:s"), 'sa_updated_by' => $this->session->userdata('id') ); if ($this->SystemAdminManagement->updateAdminInfo($adminUpdateInfo)) { $this->session->set_flashdata('successMessage', 'Admin Updated Successfully.'); redirect("admin/SystemAdmin/"); } else { $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating Admin Info. Try Later.'); $this->editAdmin($this->input->post('admId')); } } else { $profileImageNameWithPath = ""; $configProfileImg['upload_path'] = './assets/images/adminimgs/'; $configProfileImg['allowed_types'] = 'jpeg|jpg|png|webp'; //$configProfileImg['max_width'] = '320'; //$configProfileImg['max_height'] = '220'; $configProfileImg['max_size'] = '800'; $configProfileImg['file_ext_tolower'] = TRUE; $configProfileImg['encrypt_name'] = TRUE; $this->load->library('upload', $configProfileImg); if (!$this->upload->do_upload('profileImg')) { $this->session->set_flashdata('errorMessage', "The Profile Image Can Not Be Uploaded As It Do Not Match With Profile Image Criteria. File Size 800 KB Max. & Allowed Extension: Only *.jpeg,*.jpg,*.png,*.webp"); $this->editAdmin($this->input->post('admId')); } else { $profileImageNameWithPath = base_url("assets/images/adminimgs/") . $this->upload->data()['file_name']; $adminUpdateInfo = array( 'sa_id' => $this->input->post('admId'), 'sa_name' => $this->input->post('admName'), 'sa_email' => $this->input->post('admEmail'), 'sa_mobile' => $this->input->post('admMobile'), 'sa_type' => $this->input->post('admType'), 'sa_role' => $this->input->post('admRole'), 'sa_auth_sms_flag' => $this->input->post('admSMSAuth'), 'sa_image_url' => $profileImageNameWithPath, 'sa_updated_on' => date("Y-m-d H:i:s"), 'sa_updated_by' => $this->session->userdata('id') ); if ($this->SystemAdminManagement->updateAdminInfo($adminUpdateInfo)) { unlink("./assets/images/adminimgs/" . $adminCurrentProfileImageFileName); $this->session->set_flashdata('successMessage', 'System Admin Updated Successfully.'); redirect("admin/SystemAdmin/"); } else { $this->session->set_flashdata('errorMessage', 'Some Error Occurred While Updating System Admin Info. Try Later.'); $this->editAdmin($this->input->post('admId')); } } } } } } else { redirect("admin/"); } } public function checkUsernameAvailability() { $requested_username = $_POST['admUserName']; $query = $this->SystemAdminManagement->getAdminInfoByUserName($requested_username); $adminInfo = $query->result(); if (sizeof($adminInfo)) { $responseData = array( 'csrfName' => $this->security->get_csrf_token_name(), 'csrfHash' => $this->security->get_csrf_hash(), 'doAvailable' => 1 ); } else { $responseData = array( 'csrfName' => $this->security->get_csrf_token_name(), 'csrfHash' => $this->security->get_csrf_hash(), 'doAvailable' => 0 ); } echo json_encode($responseData); } }