McGansWebsite/admin/application/controllers/Faculty.php

245 lines
6.6 KiB
PHP
Raw Permalink Normal View History

2023-01-05 12:19:39 +00:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Faculty extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Faculty_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 faculty_list()
{
if($this->session->userdata('id')==""){redirect('');}
$data['fac']=$this->Faculty_model->list_fa();
$this->load->view('faculty/faculty_list',$data);
2023-01-05 12:19:39 +00:00
}
public function viewFaculty($id)
{
if($this->session->userdata('id')==""){redirect('');}
$data['viewFaculty']=$this->Faculty_model->viewFaculty($id);
//echo $this->db->last_query();exit;
$this->load->view('faculty/view_faculty',$data);
}
2023-01-05 12:19:39 +00:00
function add_faculty()
{
if($this->session->userdata('id')==""){redirect('');}
$currentUser=$this->session->userdata('id');
2023-01-05 12:19:39 +00:00
$this->load->view('faculty/add_faculty');
if($this->input->post('submit'))
{
$faculty=$this->input->post('facultyId');
2023-01-05 12:19:39 +00:00
$name=$this->input->post('name');
$email=$this->input->post('email');
$date=$this->input->post('date');
2023-01-05 12:19:39 +00:00
$gender=$this->input->post('gender');
$number=$this->input->post('mobileNumber');
2023-01-05 12:19:39 +00:00
$address=$this->input->post('address');
2023-01-06 07:23:42 +00:00
$desi=$this->input->post('designation');
$f_img=$this->input->post('image');
2023-01-05 12:19:39 +00:00
//echo $date.'-------'.$dateofbirth;exit;
//$banner_image=$this->input->post('banner_image');
if (!is_dir('uploads/faculty')) {
mkdir('./uploads/faculty', 0777, TRUE);
}
if(file_exists($_FILES['image']['tmp_name']))
{
$temp_user_img=$_FILES['image']['tmp_name'];
$f_img=str_replace(' ', '_', $_FILES["image"]["name"]);
$allowed = array('png,jpeg,jpg');
$extension1 = pathinfo($f_img, PATHINFO_EXTENSION);
$f_img=date('ymdhi').'.'.$extension1;
$targetPath='./uploads/faculty/';
$targetFile=$targetPath.$f_img;
move_uploaded_file($temp_user_img, $targetFile);
}
2023-01-05 12:19:39 +00:00
$table="faculty";
$values=array('facultyId'=>$faculty,
2023-01-05 12:19:39 +00:00
'name'=>$name,
'email'=>$email,
'dob'=>$date,
2023-01-05 12:19:39 +00:00
'gender'=>$gender,
'mobileNumber'=>$number,
2023-01-05 12:19:39 +00:00
'address'=>$address,
2023-01-06 07:23:42 +00:00
'designation'=>$desi,
'image'=>$f_img,
2023-01-08 20:46:58 +00:00
'createdOn'=>date('Y-m-d'),
'createdBy'=>$currentUser,
2023-01-05 12:19:39 +00:00
'status'=>1);
$result=$this->Commonsql_model->insert_table($table,$values);
$facultyId=$this->db->insert_id();
$table="employee";
$values=array('roleId'=>3,
'typeId'=>$facultyId,
'name'=>$name,
'email'=>$email,
'mobileNumber'=>$number,
'address'=>$address,
'image'=>$f_img,
'username'=>$name,
'password'=>md5($number),
'createdOn'=>date('Y-m-d'),
'createdBy'=>$currentUser,
'status'=>1);
$result=$this->Commonsql_model->insert_table($table,$values);
2023-01-05 12:19:39 +00:00
if($result)
{
$this->session->set_userdata('suc','successfully added');
redirect('faculty');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('faculty');
}
}
}
function editFaculty($id)
2023-01-05 12:19:39 +00:00
{
if($this->session->userdata('id')==""){redirect('');}
$currentUser=$this->session->userdata('id');
2023-01-05 12:19:39 +00:00
$data['fac']=$this->Faculty_model->get_fac($id);
$data['employee']=$this->Faculty_model->get_employee($id);
2023-01-05 12:19:39 +00:00
$this->load->view('faculty/edit_faculty',$data);
if($this->input->post('submit'))
{
$facultyId=$this->input->post('facultyId');
2023-01-05 12:19:39 +00:00
$name=$this->input->post('name');
$email=$this->input->post('email');
$gender=$this->input->post('gender');
$number=$this->input->post('mobileNumber');
$dob=$this->input->post('dob');
2023-01-05 12:19:39 +00:00
$address=$this->input->post('address');
2023-01-06 07:23:42 +00:00
$desi=$this->input->post('designation');
$image=$this->input->post('image');
$hiddenImage=$this->input->post('hiddenImage');
$employeeId=$this->input->post('employeeId');
2023-01-05 12:19:39 +00:00
if($image==""){$newImage=$hiddenImage;}
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('ymdhi').'.'.$extension1;
$targetPath='./uploads/faculty/';
$targetFile=$targetPath.$newImage;
move_uploaded_file($temp_user_img, $targetFile);
}
2023-01-05 12:19:39 +00:00
$table="faculty";
$where=array("id"=>$id);
$values=array('facultyId'=>$facultyId,
2023-01-05 12:19:39 +00:00
'name'=>$name,
'email'=>$email,
'dob'=>$dob,
2023-01-05 12:19:39 +00:00
'gender'=>$gender,
'mobileNumber'=>$number,
2023-01-05 12:19:39 +00:00
'address'=>$address,
2023-01-06 07:23:42 +00:00
'designation'=>$desi,
'image'=>$newImage,
2023-01-08 20:46:58 +00:00
'updatedOn'=>date('Y-m-d'),
'updatedBy'=>$currentUser);
2023-01-05 12:19:39 +00:00
$result=$this->Commonsql_model->updateTable($table,$where,$values);
$table="employee";
$where=array("id"=>$employeeId);
$values=array('name'=>$name,
'email'=>$email,
'mobileNumber'=>$number,
'address'=>$address,
'image'=>$newImage,
'username'=>$name,
'password'=>md5($number),
'createdOn'=>date('Y-m-d'),
'updatedOn'=>date('Y-m-d'),
'updatedBy'=>$currentUser);
$result=$this->Commonsql_model->updateTable($table,$where,$values);
2023-01-05 12:19:39 +00:00
if($result)
{
$this->session->set_userdata('suc','successfully Updated');
redirect('faculty');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('faculty');
}
2023-01-05 12:19:39 +00:00
}
}
function deleteFaculty()
2023-01-05 12:19:39 +00:00
{
if($this->session->userdata('id')==""){redirect('');}
$currentUser=$this->session->userdata('id');
2023-01-05 12:19:39 +00:00
if($this->input->post('submit'))
{
$facultyId=$this->input->post('facultyId');
2023-01-05 12:19:39 +00:00
$table="faculty";
$where=array("id"=>$facultyId);
$values=array('status'=>0,'updatedOn'=>date('Y-m-d'),'updatedBy'=>$currentUser);
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('faculty');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('faculty');
}
2023-01-05 12:19:39 +00:00
}
}
}