| Server IP : 103.48.194.25 / Your IP : 216.73.216.74 Web Server : Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.4.33 System : Linux VMHostDefault 3.10.0-1160.42.2.el7.x86_64 #1 SMP Tue Sep 7 14:49:57 UTC 2021 x86_64 User : sieuthimay ( 1016) PHP Version : 8.2.20 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/hocthongminh.net-bk/public_html/webadmin/components/product/controllers/ |
Upload File : |
<?php
class Factory extends MX_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('factory_model','factory');
$this->load->helper('img_helper');
$this->pre_message = "";
$this->permit_library->check_permit(1);
$this->session->set_userdata(array('Url'=>uri_string()));
}
function index()
{
$data['title'] = 'Danh sách hãng sản xuất';
$data['add'] = 'product/factory/add';
$config['base_url'] = base_url().'factory/index/';
$config['total_rows'] = $this->factory->getNumMenufacture();
$data['num'] = $config['total_rows'];
$config['per_page'] = 20;
$config['num_links'] = 30; // so phan trang hien thi
$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$data['list'] = $this->factory->getAllMenufacture($config['per_page'],$this->uri->segment('3'));
$data['pagination'] = $this->pagination->create_links();
$data['page'] = 'factory/index';
$this->load->view("layout/skin",$data);
}
function add()
{
$data['title'] = 'Thêm mới hãng sản xuất';
if(!empty($_POST['bt_submit']))
{
$this->form_validation->set_rules('factory_name','Tên hãng sản xuất','trim|required');
if($this->form_validation->run() == FALSE)
{
$this->pre_message = validation_errors();
}
else
{
$req = $this->build_data();
if($this->factory->save($req)){
$this->session->set_flashdata('message','Lưu thành công');
redirect('product/factory/index');
}else{
$this->pre_message = 'Lưu không thành công';
}
}
}
$data['message'] = $this->pre_message;
$data['page'] = 'factory/add';
$this->load->view("layout/skin",$data);
}
function edit($id=0)
{
$data['id'] = (int)$id;
$data['rs'] = $this->factory->get_menufacture_by_id($data['id']);
$data['title'] = 'Thêm mới hãng sản xuất: '.$data['rs']->factory_name;
if(!empty($_POST['bt_submit']))
{
$this->form_validation->set_rules('factory_name','Tên hãng sản xuất','trim|required');
if($this->form_validation->run() == FALSE)
{
$this->pre_message = validation_errors();
}
else
{
$req = $this->build_data();
if($this->factory->save($req,$id))
{
$this->session->set_flashdata('message','Lưu thành công');
redirect('product/factory/index');
}else{
$this->pre_message = 'Lưu không thành công';
}
}
}
$data['message'] = $this->pre_message;
$data['page'] = 'factory/edit';
$this->load->view("layout/skin",$data);
}
private function build_data($flag=0)
{
$req["factory_name"] = $this->input->post("factory_name");
$req["bl_active"] = (int)$this->input->post("bl_active");
//upload hinh anh
$img = $this->input->post("factory_img");
$img_name = end(explode('/', $img)) ;
if($img)
{
if(file_exists(ROOT_IMG.'manufacture/'.$img_name))
{
unlink(ROOT_IMG.'manufacture/'.$img_name);
}
fn_resize_image(ROOT_IMG.$img, ROOT_IMG.'manufacture/'.$img_name, 120, 100);
$req["factory_img"] = $img_name;
}
return $req;
}
function del()
{
$id = $this->uri->segment(3);
$page = $this->uri->segment(4);
if(!$this->check_product_manufacture($id))
{
$this->session->set_flashdata('message','Không thể xóa. Vì đã có sản phẩm trong nhà sản xuất này');
redirect('factory/index/'.$page);
}
else
{
if($this->factory->delete($id))
$this->session->set_flashdata('message','Đã xóa thành công');
else $this->session->set_flashdata('message','Xóa không thành công');
redirect('factory/index/'.$page);
}
}
function dels()
{
if(!empty($_POST['ar_id']))
{
$page = (int)$this->input->post('page');
$ar_id = $this->input->post('ar_id');
//if(!empty($_POST['btn_submit']))
//{
for($i = 0; $i < sizeof($ar_id); $i ++) {
if ($ar_id[$i]){
if(!$this->check_product_manufacture($ar_id[$i])){
$this->session->set_flashdata('message','Không thể xóa. Vì đã có sản phẩm trong nhà sản xuất này');
}else{
if($this->factory->delete($ar_id[$i]))
$this->session->set_flashdata('message','Đã xóa thành công');
else $this->session->set_flashdata('message','Xóa không thành công');
}
}
}
//}
}
redirect('factory/index/'.$page);
}
function check_product_manufacture($factory_id)
{
$list = $this->db->get_where('product',array('factory_id'=>$factory_id))->num_rows();
if($list > 0)
{
return false;
}else{
return true;
}
}
function write_file_config()
{
$str = "<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');\n/**\n* Cache file for config_manufacture fyi.vn.\n* Date: ".date('d/m/y H:i:s').".\n**/";
$str .= "\n";
$list = $this->factory->get_all_manufacture_write_file();
$total = count($list);
$str .= "\n\$config['manufac_total'] = '$total';";
$k=1;
for($i=0;$i < count($list);$i++){
$rs = $list[$i];
$title = str_replace("'","\'",$rs->factory_name);
$img = str_replace("'","\'",$rs->factory_img);
//$link = $rs->BannerLink;
$str .= "\n\$config['manufac_title_$k'] = '$title';";
$str .= "\n\$config['manufac_img_$k'] = '$img';";
//$str .= "\n\$config['probanner_link_$k'] = '$link';";
$k++;
}
$str .= "\n\n/* End of file config_manufacture fyi.vn*/\n/* Location: ./cf/config_manufacture.php */";
write_file('../cf/config_manufacture.php', $str);
}
}
?>