2023-01-05 12:19:39 +00:00
|
|
|
<?php
|
|
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
|
|
|
|
class Department extends CI_Controller {
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->load->model('Department_model');
|
|
|
|
$this->load->model('Commonsql_model');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Index Page for this controller.
|
|
|
|
*
|
|
|
|
* Maps to the following URL
|
|
|
|
* http://example.com/index.php/welcome
|
|
|
|
* - or -
|
|
|
|
* http://example.com/index.php/welcome/index
|
|
|
|
* - or -
|
|
|
|
* Since this controller is set as the default controller in
|
|
|
|
* config/routes.php, it's displayed at http://example.com/
|
|
|
|
*
|
|
|
|
* So any other public methods not prefixed with an underscore will
|
|
|
|
* map to /index.php/welcome/<method_name>
|
|
|
|
* @see https://codeigniter.com/user_guide/general/urls.html
|
|
|
|
*/
|
|
|
|
public function department_list()
|
|
|
|
{
|
2023-01-21 13:41:47 +00:00
|
|
|
if($this->session->userdata('id')==""){redirect('');}
|
2023-01-05 12:19:39 +00:00
|
|
|
$data['dep']=$this->Department_model->dep_list();
|
|
|
|
$this->load->view('department/department_list',$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function add_department()
|
|
|
|
{
|
2023-01-21 13:41:47 +00:00
|
|
|
if($this->session->userdata('id')==""){redirect('');}
|
2023-01-06 07:23:42 +00:00
|
|
|
$this->load->view('department/add_department');
|
2023-01-05 12:19:39 +00:00
|
|
|
if($this->input->post('submit'))
|
|
|
|
{
|
2023-01-08 20:46:58 +00:00
|
|
|
$name=$this->input->post('name');
|
|
|
|
$code=$this->input->post('code');
|
2023-01-06 07:23:42 +00:00
|
|
|
$year=$this->input->post('year');
|
2023-01-21 13:41:47 +00:00
|
|
|
|
|
|
|
if (!is_dir('uploads/department')) {
|
|
|
|
mkdir('./uploads/department', 0777, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(file_exists($_FILES['depImage']['tmp_name']))
|
|
|
|
{
|
|
|
|
$temp_user_img=$_FILES['depImage']['tmp_name'];
|
|
|
|
$user_img=str_replace(' ', '_', $_FILES["depImage"]["name"]);
|
|
|
|
$allowed = array('png,jpeg,jpg');
|
|
|
|
$extension1 = pathinfo($user_img, PATHINFO_EXTENSION);
|
|
|
|
$user_img=date('ymdhis').'.'.$extension1;
|
|
|
|
$targetPath='./uploads/department/';
|
|
|
|
$targetFile=$targetPath.$user_img;
|
|
|
|
move_uploaded_file($temp_user_img, $targetFile);
|
|
|
|
}
|
2023-01-05 12:19:39 +00:00
|
|
|
|
|
|
|
$table="department";
|
|
|
|
|
2023-01-08 20:46:58 +00:00
|
|
|
$values=array('name'=>$name,
|
|
|
|
'code'=>$code,
|
2023-01-06 07:23:42 +00:00
|
|
|
'year'=>$year,
|
2023-01-21 13:41:47 +00:00
|
|
|
'image'=>$user_img,
|
2023-01-11 07:17:57 +00:00
|
|
|
'createdOn'=>date('Y-m-d'),
|
2023-01-08 20:46:58 +00:00
|
|
|
'createdBy'=>1,
|
2023-01-05 12:19:39 +00:00
|
|
|
'status'=>1);
|
|
|
|
|
|
|
|
$result=$this->Commonsql_model->insert_table($table,$values);
|
|
|
|
if($result)
|
|
|
|
{
|
|
|
|
$this->session->set_userdata('suc','successfully added');
|
|
|
|
redirect('department');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->session->set_userdata('err','Please try again');
|
|
|
|
redirect('department');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-21 13:41:47 +00:00
|
|
|
function editDepartment($id)
|
2023-01-05 12:19:39 +00:00
|
|
|
{
|
|
|
|
if($this->input->post('submit'))
|
|
|
|
{
|
2023-01-08 20:46:58 +00:00
|
|
|
$name=$this->input->post('name');
|
|
|
|
$code=$this->input->post('code');
|
|
|
|
$year=$this->input->post('year');
|
2023-01-11 07:17:57 +00:00
|
|
|
$image=$this->input->post('image');
|
2023-01-21 13:41:47 +00:00
|
|
|
$hiddenImage=$this->input->post('hiddenImage');
|
2023-01-11 07:17:57 +00:00
|
|
|
//$primaryid=$this->input->post('hiddendepid');
|
2023-01-21 13:41:47 +00:00
|
|
|
if($image=="")
|
|
|
|
{
|
|
|
|
$newImage=$hiddenImage;
|
|
|
|
}
|
2023-01-05 12:19:39 +00:00
|
|
|
|
2023-01-21 13:41:47 +00:00
|
|
|
if(file_exists($_FILES['image']['tmp_name']))
|
|
|
|
{
|
|
|
|
$temp_user_img=$_FILES['image']['tmp_name'];
|
|
|
|
$newImage=str_replace(' ', '_', $_FILES["image"]["name"]);
|
|
|
|
$allowed = array('png,jpeg,jpg');
|
|
|
|
$extension1 = pathinfo($newImage, PATHINFO_EXTENSION);
|
|
|
|
$newImage=date('ymdhis').'.'.$extension1;
|
|
|
|
$targetPath='./uploads/department/';
|
|
|
|
$targetFile=$targetPath.$newImage;
|
|
|
|
move_uploaded_file($temp_user_img, $targetFile);
|
|
|
|
}
|
2023-01-05 12:19:39 +00:00
|
|
|
$table="department";
|
2023-01-11 07:17:57 +00:00
|
|
|
$where=array("id"=>$id);
|
2023-01-08 20:46:58 +00:00
|
|
|
$values=array('name'=>$name,
|
|
|
|
'code'=>$code,
|
|
|
|
'year'=>$year,
|
2023-01-21 13:41:47 +00:00
|
|
|
'image'=>$newImage,
|
2023-01-11 07:17:57 +00:00
|
|
|
'updatedOn'=>date('Y-m-d'),
|
2023-01-08 20:46:58 +00:00
|
|
|
'updatedBy'=>1,
|
2023-01-05 12:19:39 +00:00
|
|
|
'status'=>1);
|
|
|
|
|
|
|
|
$result=$this->Commonsql_model->updateTable($table,$where,$values);
|
|
|
|
//echo $this->db->last_query();exit;
|
|
|
|
if($result)
|
|
|
|
|
|
|
|
{
|
|
|
|
$this->session->set_userdata('suc','successfully Updated');
|
|
|
|
redirect('department');
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->session->set_userdata('err','Please try again');
|
|
|
|
redirect('department');
|
|
|
|
}
|
2023-01-11 07:17:57 +00:00
|
|
|
|
2023-01-05 12:19:39 +00:00
|
|
|
}
|
2023-01-21 13:41:47 +00:00
|
|
|
$data['dep']=$this->Department_model->get_dep($id);
|
|
|
|
//echo $this->db->last_query();exit;
|
|
|
|
$this->load->view('department/edit_department',$data);
|
2023-01-05 12:19:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-21 13:41:47 +00:00
|
|
|
function deleteDepartment()
|
2023-01-05 12:19:39 +00:00
|
|
|
{
|
|
|
|
if($this->input->post('submit'))
|
|
|
|
{
|
2023-01-21 13:41:47 +00:00
|
|
|
$departmentId=$this->input->post('departmentId');
|
2023-01-11 07:17:57 +00:00
|
|
|
//echo $id ; exit;
|
2023-01-05 12:19:39 +00:00
|
|
|
$table="department";
|
2023-01-21 13:41:47 +00:00
|
|
|
$where=array("id"=>$departmentId);
|
2023-01-11 07:17:57 +00:00
|
|
|
$values=array('status'=>0);
|
2023-01-05 12:19:39 +00:00
|
|
|
|
|
|
|
$result=$this->Commonsql_model->updateTable($table,$where,$values);
|
|
|
|
if($result)
|
|
|
|
{
|
|
|
|
$this->session->set_userdata('suc','successfully deleted');
|
|
|
|
redirect('department');
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->session->set_userdata('err','Please try again');
|
|
|
|
redirect('department');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|