| Server IP : 103.48.194.25 / Your IP : 216.73.217.33 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/pundarikanail.com-bk/wadmin/controllers/ |
Upload File : |
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Product extends MX_Controller
{
protected $_templates;
public function __construct()
{
parent::__construct();
$this->load->model('product_model','product');
$this->load->model('news_model','news');
$this->load->model('keywords_model','keywords');
$this->pre_message = "";
/*$this->permit_library->check_permit();
$this->session->set_userdata(array('Url'=>uri_string()));*/
}
// Thống kê toàn bộ gian hàng
function index()
{
$data['title'] = 'Thống kê';
$data['page'] = 'product/static';
$this->load->view("layout/skin",$data);
}
function listcat($cid=0,$start=0)
{
$data['title'] = 'Danh sách danh mục sản phẩm';
$data['add'] = 'product/addcat';
$data['start'] = $start;
$data['cid'] = $cid;
$this->create_option();
$this->categy_cache();
$type = $this->input->post('type');
if($type=="ajax")
{
/*Begin search*/
$current_router = $this->router->fetch_class();
if($this->session->userdata('current_router')&&($this->session->userdata('current_router')!=$current_router)){
$this->session->set_userdata('key_search','');
}
$this->session->set_userdata('current_router',$current_router);
$data['search_bar']= searchBar(array(),array('cn'=>'Class Name'),'product/listcat/'.$cid.'/');
if($type=='ajax')
{
$arr_search['key_search'] = $this->input->post('key_search');
$arr_search['field_search'] = $this->input->post('field_search');
$this->session->set_userdata('key_search',$arr_search['key_search']);
$this->session->set_userdata('field_search',$arr_search['field_search']);
}
else{
$arr_search['key_search']=$this->session->userdata('key_search');
$arr_search['field_search']=$this->session->userdata('field_search');
}
/*End search*/
$config['base_url'] = site.'product/listcat/'.$cid;
$config['total_rows'] = $this->product->getNumCat($cid,$arr_search);
$data['num'] = $config['total_rows'];
$config['per_page'] = 100;
$config['uri_segment'] = 4;
$config['num_links'] = 8;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['list'] = $this->product->getAllCat($cid,$config['per_page'],$start,$arr_search);
$data['message'] = $this->pre_message;
$data['page'] = 'product/cat/listcat_ajax';
$this->load->view($data['page'],$data);
}
else
{
/*Begin search*/
$current_router = $this->router->fetch_class();
if($this->session->userdata('current_router')&&($this->session->userdata('current_router')!=$current_router)){
$this->session->set_userdata('key_search','');
}
$this->session->set_userdata('current_router',$current_router);
$data['search_bar']= searchBar(array(),array('cn'=>'Class Name'),'product/listcat/'.$cid.'/');
if($type=='ajax')
{
$arr_search['key_search'] = $this->input->post('key_search');
$arr_search['field_search'] = $this->input->post('field_search');
$this->session->set_userdata('key_search',$arr_search['key_search']);
$this->session->set_userdata('field_search',$arr_search['field_search']);
}
else{
$arr_search['key_search']=$this->session->userdata('key_search');
$arr_search['field_search']=$this->session->userdata('field_search');
}
/*End search*/
$config['base_url'] = site.'product/listcat/'.$cid;
$config['total_rows'] = $this->product->countMaincat();
$data['num'] = $config['total_rows'];
$config['per_page'] = 300;
$config['uri_segment'] = 4;
$config['num_links'] = 8;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['list'] = $this->product->getMaincat();
$data['page'] = 'product/cat/listcat';
$this->load->view('layout/skin', $data);
}
}
function create_option()
{
$str = "";
$maincat = $this->product->getMaincat();
foreach($maincat as $cat):
$cat2 = $this->product->get_services($cat->CategoryID);
if($cat2)
$subcat = $this->sub_cat($cat2) ;
else
$subcat = '';
$str .= "\t".'<optgroup label="'.$cat->CategoryName.'">'.$subcat.'</optgroup>'."\n";
endforeach;
$str = '<ul id="mainmenu" class="mainmenu_nhe hidden-xs sf-menu sf-vertical sf-js-enabled sf-arrows">'."\n".$str."</ul>";
write_file(ROOT_SITE.'cache/main_menu.php', $str);
}
function sub_cat($list)
{
$str = '';
foreach($list as $cat):
$str .= "\t".'<option value="'.$cat->ProductID.'" price="'.$cat->Price.'" staff="[]">'.$cat->ProductName.'</a></option>'."\n";
endforeach;
//$str = '<ul>'."\n\t".$str."\n".'</ul>';
return $str ;
}
function addcat()
{
$data['title'] = 'Thêm mới danh mục';
$data['listmaincat'] = $this->product->getMaincat();
if(isset($_POST['bt_submit']))
{
$this->form_validation->set_rules('CategoryName','Tên danh mục','trim|required');
if($this->form_validation->run() == FALSE)
{
$this->pre_message = validation_errors();
}else{
$req = $this->form_cat();
if($this->product->savecat($req)){
$this->session->set_flashdata('message','Lưu thành công');
redirect('product/listcat');
}else{
$this->pre_message = 'Lưu không thành công';
}
}
}
$data['message'] = $this->pre_message;
$data['page'] = 'product/cat/addcat';
$this->load->view("layout/skin",$data);
}
function categy_cache()
{
$item = '';
$list = $this->product->get_category_active();
foreach ($list as $rs) :
$link_cat = $rs->CategoryAlias;
$link_img = urlimg.'category/'.$rs->CategoryImage;
$item .='<div class="item-our-services">
<div class="img-our-services"> <img itemprop="image" src="'.$link_img.'" alt="'.$rs->CategoryName.'"> </div>
<div class="title-our-services">
<div class="vertical">
<h2 itemprop="name"><a href="'.$link_cat.'" title="'.$rs->CategoryName.'">'.$rs->CategoryName.'</a></h2>
</div>
</div>
</div>'."\n";
endforeach;
write_file(ROOT_SITE.'cache/category.php', $item);
}
private function form_cat($CategoryID=0)
{
$catsub = '';
$list_sub = $this->product->getListSub($CategoryID);
foreach($list_sub as $row) :
$catsub .= $catsub? ",".$row->CategoryID : $row->CategoryID ;
if($row->cat_level<2)
{
$list_sub2 = $this->product->getListSub($row->CategoryID);
foreach($list_sub2 as $rs) :
$catsub .= $catsub? ",".$rs->CategoryID : $rs->CategoryID ;
endforeach;
}
endforeach;
$req["CategoryName"] = trim($this->input->post("CategoryName"));
$req["CategoryAlias"] = $this->input->post("CategoryAlias");
$req["ParentID"] = $this->input->post("ParentID");
$req["is_home"] = $this->input->post("is_home");
$req["cat_level"] = $this->input->post("cat_level");
$req["IsMainMenu"] = $this->input->post("IsMainMenu");
$req["Ordering"] = $this->input->post("Ordering");
$req["list_subcat"] = $catsub;
$req["metatitle"] = $this->input->post("metatitle");
$req["metadesc"] = $this->input->post("metadesc");
$req["metakey"] = $this->input->post("metakey");
$req["bl_active"] = (int)$this->input->post("bl_active");
//upload hinh anh
$lb_image = $this->input->post("CategoryImage");
if($lb_image)
{
$img_name = get_img_name($lb_image) ;
if(file_exists(ROOT_IMG.'category/'.$img_name))
{
unlink(ROOT_IMG.'category/'.$img_name);
}
$this->resize(ROOT_IMG.'/'.$lb_image,ROOT_IMG.'category/'.$img_name, 800, 800);
$req["CategoryImage"] = $img_name;
}
return $req;
}
function editcat($CategoryID=0)
{
$data['rs'] = $this->product->get_edit_cat($CategoryID);
$data['listmaincat'] = $this->product->getMaincat();
if(!empty($_POST['bt_submit']))
{
$this->form_validation->set_rules('CategoryName','Tên danh mục','trim|required');
if($this->form_validation->run() == FALSE){
$this->pre_message = validation_errors();
}else{
$req = $this->form_cat($CategoryID);
if($this->product->savecat($req,$CategoryID)){
$this->session->set_flashdata('message','Lưu thành công');
redirect('product/listcat');
}else{
$this->pre_message = 'Lưu không thành công';
}
}
}
$data['title'] = 'Cập nhật danh mục: '.$data['rs']->CategoryName;
$data['message'] = $this->pre_message;
$data['CategoryID'] = $CategoryID ;
$data['page'] = 'product/cat/editcat';
$this->load->view("layout/skin",$data);
}
function get_level()
{
$category = $this->input->post('catid') ;
$rs = $this->product->get_edit_cat($category) ;
echo $rs->cat_level ;
}
function setcat_active()
{
$cssname = $this->input->post('cssname');
$field = $this->input->post('field');
$id = $this->input->post('id');
$value = $this->input->post('value');
$value = $value? 0 : 1;
$data[$field] = $value;
$this->product->save('category',$data,'CategoryID',$id);
echo icon_open($cssname,$id,$field,$value);
}
// Xoa tang pham
function del_gifts_item()
{
$gifts_id = $this->input->post('giftsid');
$this->db->where('GiftsID',$gifts_id);
if($this->db->delete('productgifts')){
$data['msg'] = "Xóa thành công";
}else{
$data['msg'] = "Xóa không thành công";
}
echo json_encode($data);
}
function delscat()
{
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->product->delcat($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('product/listcat/'.$page);
}
function delcat($id=0,$page=0)
{
if($this->product->delcat($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('product/listcat/'.$page);
}
// move a category up
function cat_up($nwc_id=0)
{
if(is_numeric($nwc_id)){
if($this->product->move_up($nwc_id)){
$this->session->set_flashdata('message','Sắp xếp thành công');
}else{
$this->session->set_flashdata('message','Sắp xếp không thành công');
}
}
redirect('product/listcat');
}
// move a category down
function cat_down()
{
$nwc_id = $this->uri->segment(3);
if(is_numeric($nwc_id)){
if($this->product->move_down($nwc_id)){
$this->session->set_flashdata('message','Sắp xếp thành công');
}else{
$this->session->set_flashdata('message','Sắp xếp không thành công');
}
}
redirect('product/listcat');
}
/********** Product *************/
function listproduct($cid=0,$cate=0,$orderby='asc',$start=0)
{
$data['title'] = 'Danh sách sản phẩm';
$data['listcat'] = $this->product->getMaincat();
$data['add'] = 'product/addproduct';
//$data['export'] = 'product/exportExcel/'.$cid ;
/*Begin search*/
$type = $this->input->post('type');
$current_router = $this->router->fetch_class();
if($this->session->userdata('current_router')&&($this->session->userdata('current_router')!=$current_router)){
$this->session->set_userdata('key_search','');
}
$this->session->set_userdata('current_router',$current_router);
$data['search_bar']= searchBar(array(),array('TT'=>'Title'),'product/listproduct/'.$cid.'/'.$cate.'/'.$orderby);
if($type=='ajax')
{
$arr_search['key_search'] = $this->input->post('key_search');
$arr_search['field_search'] = $this->input->post('field_search');
$this->session->set_userdata('key_search',$arr_search['key_search']);
$this->session->set_userdata('field_search',$arr_search['field_search']);
}
else{
$arr_search['key_search']=$this->session->userdata('key_search');
$arr_search['field_search']=$this->session->userdata('field_search');
}
/*End search*/
$config['base_url'] = site.'product/listproduct/'.$cid.'/'.$cate.'/'.$orderby;
$config['total_rows'] = $this->product->getNumProduct($cid,$cate,$orderby,$arr_search);
$data['num'] = $config['total_rows'];
$config['per_page'] = 30;
$config['uri_segment'] = 6;
$config['num_links'] = 8;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$ord = (int) $this->input->post('orderby') ;
$data['list'] = $this->product->getAllProduct($cid,$cate,$orderby,$config['per_page'],$start, $arr_search);
$data['list_cate'] = read_file(ROOT_SITE.'cache/json-product-cungloai.php');
$data['cid'] = $cid;
$data['cate'] = $cate;
$data['orderby'] = $orderby;
$data['start'] = $start;
$data['page'] = 'product/pro/listproduct' ;
if($type=="ajax")
$this->load->view($data['page'],$data);
else
$this->load->view('layout/skin', $data);
}
function addproduct()
{
$data['title'] = 'Thêm mới sản phẩm';
$data['listcat'] = $this->product->check_parentid(0);
if(isset($_POST['bt_submit']))
{
$this->form_validation->set_rules('ProductName','Tên sản phẩm','trim|required');
$this->form_validation->set_rules('Price','Giá','trim|required');
if($this->form_validation->run())
{
$req = $this->form_product(1);
if($proid=$this->product->saveProduct($req))
{
//$this->addkeyword($proid,$req["metakey"],'product');
$this->session->set_flashdata('message','Lưu thành công');
redirect('product/listproduct');
}else{
$this->pre_message ="Lưu không thành công";
}
}
}
$data['message'] = $this->pre_message;
$data['page'] = 'product/pro/addproduct' ;
$this->load->view('layout/skin', $data);
}
private function form_product($flag=0)
{
$req["ProductCode"] = $this->input->post("ProductCode");
$req["ProductName"] = $this->input->post("ProductName");
$req["Alias"] = kodau($this->input->post('ProductName'));
$req["CategoryID"] = $this->input->post("CategoryID");
$req["Price_Old"] = to_number($this->input->post("Price_Old"));
$req["Price"] = to_number($this->input->post("Price"));
$req["Description"] = $this->input->post("Description");
$req["ProductFunc"] = $this->input->post("ProductFunc");
$req["ProductStatus"] = $this->input->post("ProductStatus");
$req["ProductStatusText"] = $this->input->post("ProductStatusText");
$req["nb_time"] = $this->input->post("nb_time");
$req["PromotionActice"] = $this->input->post("PromotionActice");
$req["PromotionInfo"] = $this->input->post("PromotionInfo");
$req["IsHome"] = (int) $this->input->post("IsHome");
$metatitle = $this->input->post("metatitle");
$metadesc = $this->input->post("metadesc");
$metakey = $this->input->post("metakey");
$req["metatitle"] = empty($metatitle)? $req["ProductName"] : $metatitle;
$req["metadesc"] = empty($metadesc)? $req["Description"] : $metadesc;
$req["metakey"] = empty($metakey)? mb_strtolower($metatitle) : mb_strtolower($metakey);
$req["LastUpdate"] = date('Y-m-d H:i:s');
if($flag) $req["CreatedDate"] = date('Y-m-d H:i:s');
$req["bl_active"] = (int)$this->input->post("bl_active");
//upload hinh anh
$img = $this->input->post("ProductImg");
if($img)
{
$img_name = get_img_name($img) ;
if($img && file_exists(ROOT_IMG.'products/800/'.$img_name))
{
@unlink(ROOT_IMG.'products/800/'.$img_name);
@unlink(ROOT_IMG.'products/500/'.$img_name);
}
fn_resize_image(ROOT_IMG.$img, ROOT_IMG.'products/500/'.$img_name, 500, 500);
$this->resize(ROOT_IMG.$img, ROOT_IMG.'products/800/'.$img_name,1000, 1000);
$req["ProductImg"] = $img_name;
}
return $req;
}
function editproduct($ProductID=0,$start=0)
{
$data['listmaincat'] = $this->product->getMaincat();
$data['listimg'] = $this->product->get_img_by_product_id($ProductID);
$rs = $this->product->get_info_product($ProductID);
$data['title'] = 'Cập nhật sản phẩm '.$rs->ProductName;
if(isset($_POST['bt_submit']))
{
$this->form_validation->set_rules('ProductName','Tên sản phẩm','trim|required');
$this->form_validation->set_rules('Price','Giá cty','trim|required');
if($this->form_validation->run())
{
$req = $this->form_product();
if($this->product->saveProduct($req,$ProductID))
{
//$this->addkeyword($ProductID,$req["metakey"],'product');
$this->session->set_flashdata('message','Lưu thành công');
redirect('product/listproduct/0/0/asc/'.$start);
}
else
{
$this->pre_message ="Lưu không thành công";
}
}
}
/*$listcat = $this->product->get_info_cat($rs->CategoryID);
$seg_cat = explode('-',$listcat);
$data['cat1'] = $seg_cat[0];
$data['cat2'] = $seg_cat[1];
$data['cat3'] = $seg_cat[2];*/
//$data['listcat'] = $this->product->getAllCat();
$data['rs'] = $rs;
$data['ProductID'] = $ProductID;
$data['message'] = $this->pre_message;
$data['page'] = 'product/pro/editproduct' ;
$this->load->view('layout/skin', $data);
}
function addkeyword($id=0,$str='',$kind='product')
{
$arr = explode(",",$str);
if(is_array($arr))
{
foreach ($arr as $a):
$a = trim($a);
$rs = $this->keywords->get_word($a);
if(empty($rs))
{
$req["keyname"] = $a;
$req["alias"] = alias($a) ;
$req["kind"] = $kind;
$req["is_hot"] = 0 ;
$req["bl_active"] = 1 ;
if($kind=='product')
$req["list_pro"] = $id;
else
$req["list_news"] = $id;
$this->keywords->save('keywords',$req);
}
else
{
if($kind=='product')
$req["list_pro"] = unique_id($rs->list_pro.','.$id);
else
$req["list_news"] = unique_id($rs->list_news.','.$id);
$this->keywords->save('keywords',$req,'kid',$rs->kid);
}
endforeach ;
}
else
{
$a = trim($a);
$rs = $this->keywords->get_word($a);
if(empty($rs))
{
$req["keyname"] = $a;
$req["kind"] = $kind;
$req["is_hot"] = 0 ;
$req["bl_active"] = 1 ;
if($kind=='product')
$req["list_pro"] = $id;
else
$req["list_news"] = $id;
$this->keywords->save('keywords',$req);
}
else
{
if($kind=='product')
$req["list_pro"] = unique_id($rs->list_pro.','.$id);
else
$req["list_news"] = unique_id($rs->list_news.','.$id);
$this->keywords->save('keywords',$req,'kid',$rs->kid);
}
}
}
//thêm hinh ảnh khi edit
function addimg($proid=0)
{
$lb_image = $this->input->post('lb_image');
$source = ROOT_IMG.$lb_image;
if($lb_image && file_exists($source))
{
//copy file
//$filename = end(explode("/",$lb_image));
$ext = pathinfo($lb_image,PATHINFO_EXTENSION);
$filename = pathinfo($lb_image,PATHINFO_FILENAME);
$filename = $filename.date("dmY-His").'.'.$ext;
$dest = ROOT_IMG.'products/800/'.$filename;
$this->resize($source, $dest,1000, 1000);
//them vao products/800
$data['ProductID'] = $proid;
$data['ImageName'] = $filename;
$data['ImagePath'] = 'products/800/';
$data['ImageType'] = $proid? 0 : 1;
$data['ImageSession'] = $proid? '' : $this->session->userdata('session_id');
$imgid = $this->product->save('productimage',$data);
//tra ve trinh duyet
$res['code'] = 1;
$res['msg'] = '';
$res['imgid'] = $imgid;
$res['filename'] = $filename;
echo json_encode($res);
}
else
{
$res['code'] = 1;
$res['msg'] = 'File không tồn tại';
echo json_encode($res);
}
}
//Xóa hình ảnh khi edit
function delimg($imgid=0,$proid=0)
{
if($imgid)
{
$rs = $this->product->get_images_id($imgid,$proid);
if($rs)
{
$img_name = $rs->ImageName;
if($img_name && file_exists(ROOT_IMG.'products/800/'.$img_name))
{
@unlink(ROOT_IMG.'products/800/'.$img_name);
}
$this->product->del('productimage','ImageID',$imgid);
$res['code'] = 1;
$res['msg'] = '';
echo json_encode($res);
exit;
}
}
$res['code'] = 1;
$res['msg'] = 'Xóa không thành công';
echo json_encode($res);
}
function resize($src, $desc, $width)
{
$this->load->library('ResizeImg');
$this->resizeimg->load($src);
$this->resizeimg->resizeToWidth($width);
$this->resizeimg->save($desc);
}
function delsproduct()
{
$page = (int)$this->input->post('page');
$catid = (int)$this->input->post('catid');
if(isset($_POST['btn_submitHN']) && ($_POST['btn_submitHN']=='OrderHN'))
{
$pid = $this->input->post('ar_pid');
$ar_pid = explode(',',$pid);
$num_pid = count($ar_pid);
for($i=0;$i<$num_pid;$i++){
$Ordering = (int)$this->input->post('OrderHN'.$ar_pid[$i]);
if($Ordering!=0)
{
$data = array(
'OrderHN' => $Ordering
);
$this->db->where('ProductID',$ar_pid[$i]);
if($this->db->update('product',$data)){
$this->session->set_flashdata('message','Sắp xếp Sản phẩm HN thành công');
}else{
$this->session->set_flashdata('message','Sắp xếp Sản phẩm HN không thành công');
}
}
}
}
if(isset($_POST['btn_submit']) && ($_POST['btn_submit']=='Lưu'))
{
$pid = $this->input->post('ar_pid');
$ar_pid = explode(',',$pid);
$num_pid = count($ar_pid);
for($i=0;$i<$num_pid;$i++){
$Ordering = (int)$this->input->post('Order'.$ar_pid[$i]);
if($Ordering!=0)
{
$data = array(
'Ordering' => $Ordering
);
$this->db->where('ProductID',$ar_pid[$i]);
if($this->db->update('product',$data)){
$this->session->set_flashdata('message','Sắp xếp thành công');
}else{
$this->session->set_flashdata('message','Sắp xếp không thành công');
}
}
}
}else{
if(!empty($_POST['ar_id']))
{
$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->product->delproduct($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('product/listproduct/'.$catid.'/'.$page);
}
function delproduct($id=0,$catid=0,$page=0)
{
if($this->product->delproduct($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('product/listproduct/'.$catid.'/'.$page);
}
function search()
{
$data['title'] = 'Kết quả tìm kiếm';
$data['add'] = 'product/addproduct';
//xuất file excel
$excel = $this->uri->segment(3) ;
if($excel=='export')
{
$cid = (int)$this->uri->segment(4) ;
$list = $this->product->getAllProductExport($cid);
ini_set('memory_limit', '100M');
memory_get_peak_usage(true);
require_once APPEXCEL.'excel/PHPExcel.php';
// Create new PHPExcel object
$this->phpexcel = new PHPExcel();
// Set properties
$this->phpexcel->getProperties()->setCreator("khonguyenlieu.vn")
->setLastModifiedBy("khonguyenlieu.vn")
->setTitle("Thong ke san pham quang cao")
->setSubject("Thong ke san pham quang cao")
->setDescription("File thong ke san pham quang cao. Author: Tran Ngoc Duoc. Website:http://khonguyenlieu.vn.") //http://360vnit.com
->setKeywords("office 2007 openxml php")
->setCategory("Thong ke san pham quang cao");
$this->phpexcel->getDefaultStyle()->getFont()->setName('Arial');
$this->phpexcel->getDefaultStyle()->getFont()->setSize(10);
// SET HEADER FILE EXCEL
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('A1', 'Thống kê giá sản phẩm ngành.');
//Pro ID
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('A3', 'Product ID');
$this->phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
//Pro Code
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('B3', 'Ngành nghề'); //ProductCode
$this->phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth(25);
// Pro Name
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('C3', 'Product Name');
$this->phpexcel->getActiveSheet()->getColumnDimension('C')->setWidth(80);
// Prie
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('D3', 'Price');
$this->phpexcel->getActiveSheet()->getColumnDimension('D')->setWidth(25);
// Price khuyen mai
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('E3', 'Price promotion');
$this->phpexcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
// Giam gia
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('F3', 'Discount');
$this->phpexcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
$i=4;
$k=1;
foreach($list as $rs):
//Pro ID
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('A'.$i, $rs->ProductID);
//Pro Code
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('B'.$i, $this->product->get_edit_cat($rs->CategoryID)->CategoryName); //$rs->ProductCode
// ProductName
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('C'.$i, $rs->ProductName);
// Price thi truong
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('D'.$i, $rs->Price);
// khuyen mai
$Pricepromo = !empty($rs->PriceCty) ? $rs->PriceCty : $rs->Price ;
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('E'.$i, $Pricepromo);
// Giam gia
$discount = !empty($rs->PriceCty) ? number_format($rs->Price - $rs->PriceCty,0,',','.') : 0 ;
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('F'.$i, $discount);
$i++;
$k++;
endforeach;
//set Font
$this->phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('A2')->getFont()->setBold(true);
// Witdh
$this->phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
$this->phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setName('Tahoma');
$this->phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(14);
$this->phpexcel->getActiveSheet()->getStyle('A2')->getFont()->setName('Tahoma');
$this->phpexcel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
// Rename sheet
$this->phpexcel->getActiveSheet()->setTitle('Banggia');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$this->phpexcel->setActiveSheetIndex(0);
$date = date('d_m_Y');
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Banggia'.$date.'.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter( $this->phpexcel, 'Excel5');
$objWriter->save('php://output');
exit;
}
$cid = empty($_POST['cid']) ? (int)$this->uri->segment(3) : (int)$_POST['cid'];
$data['export'] = 'product/export/'.$cid ;
//$data['export'] = 'product/search/export/'.$cid;
$this->session->keep_flashdata('keyword');
$ss_flash_keyword = $this->session->flashdata('keyword');
$keyword = empty($_POST['keyword']) ? $ss_flash_keyword : $_POST['keyword'];
//$ar_cid = $this->product->get_array_cat_search($cid);
while(strpos($keyword, ' ')!==false)
{
$keyword = str_replace(' ', ' ', $keyword);
$keyword = trim($keyword);
}
$this->session->set_flashdata('keyword', $keyword);
$data['listcat'] = $this->product->getMaincat();
$config['base_url'] = base_url().'product/search/'.$cid;
$config['total_rows'] = $this->product->getNumProductSea($cid,$keyword);
$data['num'] = $config['total_rows'];
$config['per_page'] = 25 ;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$ord = (int) $this->input->post('orderby') ;
$data['list'] = $this->product->getAllProductSea($cid,$keyword,$config['per_page'],$this->uri->segment('4'),$ord);
$data['pagination'] = $this->pagination->create_links();
$keyword = $this->db->escape_str($keyword);
$data['page'] = 'product/pro/search';
$this->load->view("layout/skin",$data);
}
function export($cid=0)
{
$list = $this->product->getAllProductExport($cid);
ini_set('memory_limit', '100M');
memory_get_peak_usage(true);
require_once APPEXCEL.'excel/PHPExcel.php';
// Create new PHPExcel object
$this->phpexcel = new PHPExcel();
// Set properties
$this->phpexcel->getProperties()->setCreator("khonguyenlieu.vn")
->setLastModifiedBy("khonguyenlieu.vn")
->setTitle("Thong ke san pham quang cao")
->setSubject("Thong ke san pham quang cao")
->setDescription("File thong ke san pham quang cao. Author: Tran Ngoc Duoc. Website:http://khonguyenlieu.vn.")
->setKeywords("office 2007 openxml php")
->setCategory("Thong ke san pham quang cao");
$this->phpexcel->getDefaultStyle()->getFont()->setName('Arial');
$this->phpexcel->getDefaultStyle()->getFont()->setSize(10);
// SET HEADER FILE EXCEL
//$this->phpexcel->setActiveSheetIndex(0)->setCellValue('A1', 'Thống kê giá sản phẩm ngành.');
//Pro ID
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('A3', 'Product ID');
$this->phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
//Pro Code
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('B3', 'Ngành nghề');
$this->phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth(35);
//Pro Code
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('C3', 'Hình ảnh');
$this->phpexcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
// Pro Name
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('D3', 'Product Name');
$this->phpexcel->getActiveSheet()->getColumnDimension('D')->setWidth(50);
// Prie
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('E3', 'Giá miền nam');
$this->phpexcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
// Price khuyen mai
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('F3', 'Giá miền bắc');
$this->phpexcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
// Giam gia
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('G3', 'Khuyến mãi miền nam');
$this->phpexcel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
// Giam gia
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('H3', 'Khuyến mãi Hà Nội');
$this->phpexcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
$i=4;
$k=1;
foreach($list as $rs):
//Pro ID
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('A'.$i, $rs->ProductID);
//Pro Code
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('B'.$i, $this->product->get_edit_cat($rs->CategoryID)->CategoryName);
// Product Image
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName($rs->ProductName);
$objDrawing->setDescription($rs->ProductName);
$objDrawing->setPath('../uploads/images/'.$rs->ProductImg);
$objDrawing->setCoordinates('C'.$i);
$objDrawing->setOffsetX(5);
$objDrawing->setRotation(100);
$objDrawing->setHeight(20);
$objDrawing->getShadow()->setVisible(true);
$objDrawing->getShadow()->setDirection(45);
$objDrawing->setWorksheet($this->phpexcel->getActiveSheet());
//$this->phpexcel->setActiveSheetIndex(0)->setCellValue('C'.$i, 'http://khonguyenlieu.vn/uploads/images/'.$rs->ProductImg);
// Product Name
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('D'.$i, $rs->ProductName);
// Giá miền nam
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('E'.$i, $rs->Price);
// giá miền bắc
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('F'.$i, $rs->PriceHN);
// Giam giá miền nam
//$PriceCty = !empty($rs->PriceCty) ? $rs->PriceCty : $rs->Price ;
$discount = !empty($rs->PriceCty) ? number_format($rs->Price - $rs->PriceCty,0,'','') : 0 ;
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('G'.$i, $discount);
//Giảm giá hà nội
//$PriceHN = !empty($rs->PriceHNPromo) ? $rs->PriceHNPromo : $rs->PriceHN ;
$discountHN = !empty($rs->PriceHNPromo) ? number_format($rs->PriceHN - $rs->PriceHNPromo,0,'','') : 0 ;
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('H'.$i, $discountHN);
$i++;
$k++;
endforeach;
//set Font
$this->phpexcel->getActiveSheet()->getStyle('A3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('B3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('C3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('D3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('E3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('F3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('G3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('H3')->getFont()->setBold(true);
// Witdh
//$this->phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setName('Tahoma');
//$this->phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
//$this->phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
//$this->phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(14);
//$this->phpexcel->getActiveSheet()->getStyle('A2')->getFont()->setName('Tahoma');
//$this->phpexcel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
// Rename sheet
$this->phpexcel->getActiveSheet()->setTitle('Banggia');
//Set active sheet index to the first sheet, so Excel opens this as the first sheet
$this->phpexcel->setActiveSheetIndex(0);
$date = date('d_m_Y');
// Redirect output to a client's web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Banggia'.$date.'.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter( $this->phpexcel, 'Excel5');
$objWriter->save('php://output');
exit;
}
function exportExcel($cid)
{
$cid = (int)$this->uri->segment(3) ;
$list = $this->product->getAllProduct($cid,500,0);
ini_set('memory_limit', '100M');
memory_get_peak_usage(true);
require_once APPEXCEL.'excel/PHPExcel.php';
// Create new PHPExcel object
$this->phpexcel = new PHPExcel();
// Set properties
$this->phpexcel->getProperties()->setCreator("khonguyenlieu.vn")
->setLastModifiedBy("khonguyenlieu.vn")
->setTitle("Thong ke san pham quang cao")
->setSubject("Thong ke san pham quang cao")
->setDescription("File thong ke san pham quang cao. Author: Tran Ngoc Duoc. Website:http://khonguyenlieu.vn.")
->setKeywords("office 2007 openxml php")
->setCategory("Thong ke san pham quang cao");
$this->phpexcel->getDefaultStyle()->getFont()->setName('Arial');
$this->phpexcel->getDefaultStyle()->getFont()->setSize(10);
// SET HEADER FILE EXCEL
//$this->phpexcel->setActiveSheetIndex(0)->setCellValue('A1', 'Thống kê giá sản phẩm ngành.');
//Pro ID
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('A3', 'Product ID');
$this->phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
//Pro Code
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('B3', 'Ngành nghề');
$this->phpexcel->getActiveSheet()->getColumnDimension('B')->setWidth(35);
//Pro Code
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('C3', 'Hình ảnh');
$this->phpexcel->getActiveSheet()->getColumnDimension('C')->setWidth(20);
// Pro Name
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('D3', 'Product Name');
$this->phpexcel->getActiveSheet()->getColumnDimension('D')->setWidth(50);
// Prie
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('E3', 'Giá miền nam');
$this->phpexcel->getActiveSheet()->getColumnDimension('E')->setWidth(25);
// Price khuyen mai
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('F3', 'Giá miền bắc');
$this->phpexcel->getActiveSheet()->getColumnDimension('F')->setWidth(25);
// Giam gia
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('G3', 'Khuyến mãi miền nam');
$this->phpexcel->getActiveSheet()->getColumnDimension('G')->setWidth(25);
// Giam gia
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('H3', 'Khuyến mãi Hà Nội');
$this->phpexcel->getActiveSheet()->getColumnDimension('H')->setWidth(25);
$i=4;
$k=1;
foreach($list as $rs):
//Pro ID
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('A'.$i, $rs->ProductID);
//Pro Code
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('B'.$i, $this->product->get_edit_cat($rs->CategoryID)->CategoryName);
// Product Image
if(!empty($rs->ProductImg))
{
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName($rs->ProductName);
$objDrawing->setDescription($rs->ProductName);
$objDrawing->setPath('../uploads/images/'.$rs->ProductImg);
$objDrawing->setCoordinates('C'.$i);
$objDrawing->setOffsetX(5);
$objDrawing->setRotation(100);
$objDrawing->setHeight(20);
$objDrawing->getShadow()->setVisible(true);
$objDrawing->getShadow()->setDirection(45);
$objDrawing->setWorksheet($this->phpexcel->getActiveSheet());
//$this->phpexcel->setActiveSheetIndex(0)->setCellValue('C'.$i, 'http://khonguyenlieu.vn/uploads/images/'.$rs->ProductImg);
}
// Product Name
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('D'.$i, $rs->ProductName);
// Giá miền nam
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('E'.$i, $rs->Price);
// giá miền bắc
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('F'.$i, $rs->PriceHN);
// Giam giá miền nam
//$PriceCty = !empty($rs->PriceCty) ? $rs->PriceCty : $rs->Price ;
$discount = !empty($rs->PriceCty) ? number_format($rs->Price - $rs->PriceCty,0,'','') : 0 ;
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('G'.$i, $discount);
//Giảm giá hà nội
//$PriceHN = !empty($rs->PriceHNPromo) ? $rs->PriceHNPromo : $rs->PriceHN ;
$discountHN = !empty($rs->PriceHNPromo) ? number_format($rs->PriceHN - $rs->PriceHNPromo,0,'','') : 0 ;
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('H'.$i, $discountHN);
$i++;
$k++;
endforeach;
//set Font
$this->phpexcel->getActiveSheet()->getStyle('A3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('B3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('C3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('D3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('E3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('F3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('G3')->getFont()->setBold(true);
$this->phpexcel->getActiveSheet()->getStyle('H3')->getFont()->setBold(true);
// Witdh
//$this->phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setName('Tahoma');
//$this->phpexcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
//$this->phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true);
//$this->phpexcel->getActiveSheet()->getStyle('A1')->getFont()->setSize(14);
//$this->phpexcel->getActiveSheet()->getStyle('A2')->getFont()->setName('Tahoma');
//$this->phpexcel->getActiveSheet()->getStyle('A2')->getFont()->setSize(14);
// Rename sheet
$this->phpexcel->getActiveSheet()->setTitle('Banggia');
//Set active sheet index to the first sheet, so Excel opens this as the first sheet
$this->phpexcel->setActiveSheetIndex(0);
$date = date('d_m_Y');
// Redirect output to a client's web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Banggia'.$date.'.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter( $this->phpexcel, 'Excel5');
$objWriter->save('php://output');
exit;
}
function add_img_product()
{
$session_info = $this->session->userdata('session_id');
$path = $this->input->post('path');
$ProductID = (int)$this->input->post('ProductID');
if($this->product->add_img($path,$ProductID,$session_info)){
echo $this->_load_img_product($ProductID,$session_info);
}else{
echo 'Error';
}
}
function _load_img_product($ProductID,$sesssion)
{
$list = $this->product->getListImg($ProductID,$sesssion);
$data ='<ul class="list_img">';
foreach($list as $rs):
$data .='<li><div align="center"><img src="'.base_url_site().'uploads/images/'.$rs->ImagePath.'" onclick="chosen('.$rs->ImageID.')"> <a class="delete_button" id="'.$rs->ImageID.'" href="javascript:;"> Xóa</a><span style="display: none;" id="v'.$rs->ImageID.'">'.$rs->ImagePath.'</span></div>
</li>';
endforeach;
$data .='</ul>';
$data .='
<script type="text/javascript">
$(function() {
$(".delete_button").click(function() {
if(confirm("Bạn có chắc chắn muốn xóa hình ảnh này\nĐồng ý chọn: OK\nHủy chọn: Cancel")){
var id = $(this).attr("id");
var dataString = \'id=\'+ id ;
var parent = $(this).parent();
$.ajax({
type: "POST",
url: "'.base_url().'product/delimg",
data: dataString,
cache: false,
beforeSend: function(){
parent.animate({\'backgroundColor\':\'#fb6c6c\'},300).animate({ opacity: 0.35 }, "past");;
},
success: function(){
parent.slideUp(\'slow\', function() {$(this).remove();});
}
});
}
return false;
});
});
function chosen(id)
{
if(id)
{
var vl = $(\'#v\'+id).text();
$(\'#ProductImg\').val(vl);
$(\'#main_img\').html(\'<img src="\' + urlimg + vl + \'" width="100" />\');
}
else
{
return false;
}
}
</script>
';
return $data;
}
/*function delimg()
{
$id = $this->input->post('id');
$this->db->where('ImageID',$id);
$item = $this->db->get('productimage')->row();
$images = '../uploads/images/'.$item->ImagePath;
$images_30 = '../uploads/product/30/'.$item->ImagePath;
$images_40 = '../uploads/product/40/'.$item->ImagePath;
$images_80 = '../uploads/product/80/'.$item->ImagePath;
$images_200 = '../uploads/product/200/'.$item->ImagePath;
if(file_exists($images)){
unlink($images);
}
if(file_exists($images_30)){
unlink($images_30);
}
if(file_exists($images_40)){
unlink($images_40);
}
if(file_exists($images_80)){
unlink($images_80);
}
if(file_exists($images_200)){
unlink($images_200);
}
$this->db->where('ImageID',$id);
$this->db->delete('productimage');
} */
// Promotion
function discount()
{
$data['title'] = 'Danh sách sản phẩm khuyến mãi';
$cid = (int)$this->uri->segment(3);
$data['listcat'] = $this->product->getMaincat();
$data['add'] = 'product/addproduct';
$config['base_url'] = base_url().'product/discount/'.$cid;
$config['total_rows'] = $this->product->getNumProduct($cid);
$data['num'] = $config['total_rows'];
$config['per_page'] = 30;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$data['list'] = $this->product->listpromotion($config['per_page'],$this->uri->segment('4'));
$data['pagination'] = $this->pagination->create_links();
$data['page'] = 'discount/listdiscount';
$this->load->view("layout/skin",$data);
}
function editauto()
{
if(isset($_POST['bt_submit']))
{
$this->form_validation->set_rules('ProductName','Tên sản phẩm','trim|required');
$this->form_validation->set_rules('Price','Giá cty','trim|required');
if($this->form_validation->run())
{
$ProductID = $this->input->post('ProductID');
$req = $this->form_product();
if($this->product->saveProduct($req,$ProductID))
{
$this->addkeyword($ProductID,$req["metakey"],'product');
$this->session->set_flashdata('message','Lưu thành công');
redirect('product/editauto/'.$rs->ProductID);
}
else
{
$this->pre_message ="Lưu không thành công";
}
}
}
else
{
$rs = $this->product->get_edit_product_auto();
if(empty($rs)) redirect('product/listproduct/0/0/asc/0');
$ProductID = $rs->ProductID;
$data['listmaincat'] = $this->product->getMaincat();
$data['list_manu'] = $this->product->getAllMenufacture();
$data['list_procat'] = $this->product->get_procat();
$data['listimg'] = $this->product->get_img_by_product_id($ProductID);
$data['title'] = 'Cập nhật sản phẩm '.$rs->ProductName;
$data['rs'] = $rs;
$data['ProductID'] = $ProductID;
$data['message'] = $this->pre_message;
$data['page'] = 'product/pro/editproduct_auto' ;
$this->load->view('layout/skin', $data);
}
}
}
?>