| Server IP : 103.48.194.25 / Your IP : 216.73.217.98 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 : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/cannguyenlong.com-bk/public_html/webadmin/controllers/ |
Upload File : |
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Menufacture extends MX_Controller
{
protected $_templates;
function __construct()
{
parent::__construct();
$this->load->model('menufacture_model','menufacture');
$this->load->config('config_manufacture');
$this->load->config('config_ismainmenu');
$this->load->config('config_mshop');
$this->mshop = $this->config->item('mshop');
$this->pre_message = "";
//$this->session->set_userdata(array('Url'=>uri_string()));
}
function index()
{
//$this->write_file_config();
$this->create_manufactory();
$data['title'] = 'Danh sách hãng sản xuất';
$data['add'] = 'menufacture/add';
$config['base_url'] = site.'menufacture/index/';
$config['total_rows'] = $this->menufacture->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['pagination'] = $this->pagination->create_links();
$data['list'] = $this->menufacture->getAllMenufacture($config['per_page'],$this->uri->segment('3'));
$data['page'] = 'menufacture/list';
$this->load->view("templates/skin",$data);
}
function write_file_config()
{
$str = "<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');\n/**\n* Cache file for config_manufacture.\n* Date: ".date('d/m/y H:i:s').".\n**/";
$str .= "\n";
$list = $this->menufacture->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->MenufactureName);
$img = str_replace("'","\'",$rs->MenufactureImg);
//$link = $rs->BannerLink;
$str .= "\n\$config['manufac_id_$k'] = '$rs->MenufactureID';";
$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*/\n/* Location: ./cf/config_manufacture.php */";
write_file('../cf/config_manufacture.php', $str);
}
function add()
{
$data['title'] = 'Thêm mới hãng sản xuất';
if(!empty($_POST['bt_submit']))
{
$this->form_validation->set_rules('MenufactureName','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->menufacture->save($req)){
$this->session->set_flashdata('message','Lưu thành công');
redirect('menufacture/index');
}else{
$this->pre_message = 'Lưu không thành công';
}
}
}
$data['message'] = $this->pre_message;
$data['page'] = 'menufacture/add';
$this->load->view("templates/skin",$data);
}
private function build_data($flag=0)
{
$req["MenufactureName"] = $this->input->post("MenufactureName");
//for SEO
$metatitle = $this->input->post("metatitle");
$metadesc = $this->input->post("metadesc");
$metakey = $this->input->post("metakey");
$req["metatitle"] = empty($metatitle)? str_limit($req["pro_name"],70) : $metatitle;
$req["metadesc"] = empty($metadesc)? str_limit($req["sumary"],160) : $metadesc;
$req["metakey"] = empty($metakey)? $metatitle : $metakey;
//upload hinh anh
$lb_image = $this->input->post("MenufactureImg");
if($lb_image)
{
$img_name = end(explode('/', $lb_image)) ;
if(file_exists(ROOT_IMG.'manufactory/'.$img_name))
{
unlink(ROOT_IMG.'manufactory/'.$img_name);
}
fn_resize_image(ROOT_IMG.'/'.$lb_image,ROOT_IMG.'manufactory/'.$img_name, 800, 800);
$req["MenufactureImg"] = $img_name;
}
return $req;
}
function edit($id=0)
{
$data['id'] = $id;
$data['rs'] = $this->menufacture->get_menufacture_by_id($id);
$data['title'] = 'Thêm mới hãng sản xuất: '.$data['rs']->MenufactureName;
if(!empty($_POST['bt_submit']))
{
$this->form_validation->set_rules('MenufactureName','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->menufacture->save($req,$id))
{
$this->session->set_flashdata('message','Lưu thành công');
redirect('menufacture/index');
}else{
$this->pre_message = 'Lưu không thành công';
}
}
}
$data['message'] = $this->pre_message;
$data['page'] = 'menufacture/edit';
$this->load->view("templates/skin",$data);
}
function del($id=0,$start=0)
{
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('menufacture/index/'.$page);
}
else
{
if($this->menufacture->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('menufacture/index/'.$start);
}
}
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->menufacture->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('menufacture/index/'.$page);
}
function create_manufactory()
{
$str = '';
$list = $this->menufacture->get_menuright();
foreach($list as $rs):
$linkto = domain.'thuong-hieu/'.alias($rs->MenufactureName).'-'.$rs->MenufactureID.'.html';
$str .= '<li><a href="'.$linkto.'" title="'.$rs->MenufactureName.'">'.$rs->MenufactureName.'</a></li>';
endforeach ;
$str = '<ul>'."\n\t".$str."\n".'</ul>';
write_file(ROOT_SITE.'cache/manufactory.php', $str);
}
function check_product_manufacture($MenufactureID)
{
$list = $this->db->get_where('product',array('MenufactureID'=>$MenufactureID))->num_rows();
if($list > 0){
return false;
}else{
return true;
}
}
}
?>