|
Server : LiteSpeed System : Linux terra.hostitbro.com 5.14.0-611.54.3.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Thu May 7 16:31:24 EDT 2026 x86_64 User : outerorb ( 1091) PHP Version : 8.1.34 Disable Function : mail Directory : /home2/outerorb/crm.outerorbittech.com/application/controllers/ | |
|
Path: /home2/outerorb/crm.outerorbittech.com/application/controllers/Employee.php
Size: 7.77 KB
Permissions: 0664
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Employee extends CI_Controller
{
function __construct()
{
parent::__construct();
checklogin();
}
public function add_emp()
{
$data['title'] = 'Add Employee';
if ($this->input->post()) {
$data = $this->input->post();
$upload_path = './uploads';
$allowed_types = 'gif|jpg|jpeg|png';
if ($_FILES['image']['name'] != '') {
$path = upload_file("image", $upload_path, $allowed_types, time());
$data['image'] = $path['path'];
}
$data['created_at'] = date('Y-m-d H:i:s');
$data['status'] = 0;
$password = $data['password'];
unset($data['password']);
unset($data['same']);
$inc = $this->db->insert('emp', $data);
$id = $this->db->insert_id();
if ($inc == true) {
$ar['username'] = $data['fname'] . $id;
$ar['mobile'] = $data['mobile'];
$ar['name'] = $data['fname'] . ' ' . $data['mname'] . ' ' . $data['lname'];
$ar['email'] = $data['email'];
$salt = random_string('alnum', 16);
$ar['password'] = md5($password . SITE_SALT . $salt);
$ar['vp'] = $password;
$ar['role'] = '3';
$ar['emp_id'] = $id;
$ar['salt'] = $salt;
$asr['status'] = 1;
$asr['created_on'] = date('Y-m-d H:i:s');
$this->db->insert('users', $ar);
$this->session->set_flashdata('msg', "Saved Succesfully!");
} else {
$this->session->set_flashdata('err_msg', $inc['message']);
}
redirect('employee/add_emp');
}
$this->template->load('pages/emp', 'add_emp', $data);
}
public function emp_list()
{
$data['title'] = 'Employee List';
$data['datatable'] = true;
$data['emp'] = $this->Master_model->get_employees();
$this->template->load('pages/emp', 'emp_list', $data);
}
public function edit_emp($id = false)
{
if ($id != '') {
$data['title'] = 'Update Profile';
$data['e'] = $this->db->get_where('emp', array('id' => $id))->row_array();
$this->template->load('pages/emp', 'edit_emp', $data);
}
}
public function employee_edit()
{
$data = $this->input->post();
$upload_path = './uploads';
$allowed_types = 'gif|jpg|jpeg|png';
if ($_FILES['image']['name'] != '') {
$path = upload_file("image", $upload_path, $allowed_types, time());
$data['image'] = $path['path'];
}
$this->db->where('id', $data['id']);
$up = $this->db->update('emp', $data);
if ($up == true) {
$ar['username'] = $data['fname'] . $data['id'];
$ar['mobile'] = $data['mobile'];
$ar['name'] = $data['fname'] . ' ' . $data['mname'] . ' ' . $data['lname'];
$ar['email'] = $data['email'];
$this->db->where('id', $data['id']);
$this->db->update('users', $ar);
$this->session->set_flashdata('msg', "Updated Succesfully!");
} else {
$this->session->set_flashdata('err_msg', $up['message']);
}
redirect('employee/emp_list');
}
public function state()
{
$id = $this->input->post('cn');
$st = $this->Master_model->state($id);
$ar = '';
foreach ($st as $s) {
$ar .= "<option value=" . $s->id . ">" . $s->state_name . "</option>";
}
echo $ar;
}
public function city()
{
$id = $this->input->post('st');
$st = $this->Master_model->cities($id);
$ar = '';
foreach ($st as $s) {
$ar .= "<option value=" . $s->id . ">" . $s->city_name . "</option>";
}
echo $ar;
}
public function terminate($id = false)
{
if ($id != '') {
$ar['status'] = 2;
$this->db->where('id', $id);
$up = $this->db->update('emp', $ar);
if ($up == true) {
$this->session->set_flashdata('msg', "Updated Succesfully!");
} else {
$this->session->set_flashdata('err_msg', $up['message']);
}
}
redirect('employee/emp_list');
}
public function approve_now($id = false)
{
if ($id != '') {
$ar['status'] = 1;
$this->db->where('emp_id', $id);
$up = $this->db->update('users', $ar);
if ($up == true) {
$this->db->where('id', $id);
$up = $this->db->update('emp', $ar);
$this->session->set_flashdata('msg', "Updated Succesfully!");
} else {
$this->session->set_flashdata('err_msg', $up['message']);
}
}
redirect('employee/emp_list');
}
public function add_user()
{
$data['title'] = 'Add User';
$this->template->load('pages/user', 'add_user', $data);
}
public function save_user()
{
if ($this->input->post()) {
$ar = $this->input->post();
unset($ar['save']);
$ar['created_at'] = date('Y-m-d H:i:s');
$ins = $this->db->insert('register', $ar);
if ($ins == true) {
$this->session->set_flashdata('msg', "Submited Succesfully!");
} else {
$this->session->set_flashdata('err_msg', $ins['message']);
}
redirect('employee/add_user');
}
}
public function user_list()
{
$data['title'] = 'Users List';
$data['user'] = $this->db->get_where('register')->result_array();
$this->template->load('pages/user', 'user_list', $data);
}
public function edit_user($id = false)
{
$user = $this->db->get_where('register', array('id' => $id))->row_array();
$data['title'] = 'Edit User';
$data['user'] = $user;
if ($this->input->post()) {
$ar = $this->input->post();
$id = $ar['id'];
$this->db->where('id', $ar['id']);
$up = $this->db->update('register', $ar);
if ($up == true) {
$this->session->set_flashdata('msg', "Updated Succesfully!");
} else {
$this->session->set_flashdata('err_msg', $up['message']);
}
redirect('employee/user_list');
}
$this->template->load('pages/user', 'edit_user', $data);
}
public function delete_user($id = false)
{
$this->db->where('id', $id);
$up = $this->db->delete('register');
if ($up == true) {
$this->session->set_flashdata('msg', "Deleted Succesfully!");
} else {
$this->session->set_flashdata('err_msg', $up['message']);
}
redirect('employee/user_list');
}
public function block_user($id = false)
{
$ar['status'] = 0;
$this->db->where('id', $id);
$s = $this->db->update('register', $ar);
if ($s == true) {
$this->session->set_flashdata('msg', "Blocked Succesfully!");
} else {
$this->session->set_flashdata('err_msg', $s['message']);
}
redirect('employee/user_list');
}
public function unblock_user($id = false)
{
$ar['status'] = 1;
$this->db->where('id', $id);
$s = $this->db->update('register', $ar);
if ($s == true) {
$this->session->set_flashdata('msg', "Unblocked Succesfully!");
} else {
$this->session->set_flashdata('err_msg', $s['message']);
}
redirect('employee/user_list');
}
}