policybot/application/controllers/Company.php

168 lines
4.3 KiB
PHP
Raw Permalink Normal View History

2021-11-30 10:56:55 +00:00
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
date_default_timezone_set('Asia/Kolkata');
class Company extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Company_model');
}
function list_company()
{
if($this->session->userdata('id')==""){redirect('admin/login');}
$data['cmp']=$this->Company_model->list_cmp();
$this->load->view('admin/company/list',$data);
}
function add_company()
{
if($this->session->userdata('id')==""){redirect('admin/login');}
if($this->input->post('cmp'))
{
$name=$this->input->post('cmpname');
//make directory
if (!is_dir('uploads/company')) {
mkdir('./uploads/company', 0777, TRUE);
}
$valid_extensions = array('jpeg', 'jpg', 'png'); // valid extensions
$path = 'uploads/company/'; // upload directory
if($_FILES['Image'])
{
$img = $_FILES['Image']['name'];
$tmp = $_FILES['Image']['tmp_name'];
// get uploaded file's extension
$ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));
// can upload same image using rand function
$final_image = "Image".rand(1000,1000000).$img;
// check's valid format
if(in_array($ext, $valid_extensions))
{
$path = $path.strtolower($final_image);
if(move_uploaded_file($tmp,$path))
{
$table="companies";
//echo $ledgername;
$values=array('name'=>$name,
'logo'=>$path,
'cdate'=>date('Y-m-d H:i:s'),
'status'=>1);
$result=$this->commonsql_model->insert_table($table,$values);
} } }
if($result)
{
$this->session->set_userdata('suc','successfully added');
redirect('admin/company');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('admin/company');
}
}
}
function cmpaction()
{
if($this->session->userdata('id')==""){redirect('admin/login');}
$type=$_POST['type']; //types like view, edit etc.,
$id=$_POST['id'];
//selecting table
$tableName="companies";
$select=array('id','name','logo');
$where=array('id'=>$id);
$data['cmp']=$this->commonsql_model->selectTable($tableName,$where,$select);
$data['type']=$type;
$this->load->view('admin/company/cmpaction',$data);
}
function edit_company($id)
{
if($this->session->userdata('id')==""){redirect('admin/login');}
if($this->input->post('cmp'))
{
$name=$this->input->post('cmpname');
$image=$this->input->post("Image");
$oldimage=$this->input->post("old_image");
if($Image=="") {
$simage=$oldimage;
}
if (!is_dir('uploads/company')) {
mkdir('./uploads/company', 0777, TRUE);
}
$valid_extensions = array('jpeg', 'jpg', 'png'); // valid extensions
$path = 'uploads/company/'; // upload directory
if($_FILES['Image']['tmp_name'])
{
$img = $_FILES['Image']['name'];
$tmp = $_FILES['Image']['tmp_name'];
// get uploaded file's extension
$ext = strtolower(pathinfo($img, PATHINFO_EXTENSION));
// can upload same image using rand function
$final_image = "Image".rand(1000,1000000).$img;
// check's valid format
if(in_array($ext, $valid_extensions))
{
$simage = $path.strtolower($final_image);
if(move_uploaded_file($tmp,$simage))
{}} }
$table="companies";
//echo $ledgername;
$values=array('name'=>$name,'logo'=>$simage,
'udate'=>date('Y-m-d H:i:s'),
'status'=>1);
$where=array("id"=>$id);
$result=$this->commonsql_model->updatetable($table,$where,$values);
if($result)
{
$this->session->set_userdata('suc','successfully updated');
redirect('admin/company');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('admin/company');
}
}
}
function delete_company($id)
{
if($this->session->userdata('id')==""){redirect('admin/login');}
if($this->input->post('yes'))
{
$table="companies";
//echo $ledgername;
$values=array(
'status'=>0);
$where=array("id"=>$id);
$result=$this->commonsql_model->updatetable($table,$where,$values);
if($result)
{
$this->session->set_userdata('suc','successfully deleted');
redirect('admin/company');
}
else
{
$this->session->set_userdata('err','Please try again');
redirect('admin/company');
}
}
}
}
?>