| 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 if (! defined('BASEPATH')) exit('No direct script access allowed');
class Product extends MX_Controller
{
var $module = 'product';
public function __construct()
{
parent::__construct();
$this->permit_library->check_permit();
$this->session->set_userdata(array('Url'=>uri_string()));
$this->load->model('common');
$this->load->model('category_model','category');
$this->load->model('product_model','product');
$this->load->model('keywords/keywords_model','keywords');
$this->load->config('config_ismainmenu');
$this->pre_message = "";
}
// 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';
$config['base_url'] = site.'product/listcat/'.$cid;
$config['total_rows'] = $this->product->getNumCat($cid);
$data['num'] = $config['total_rows'];
$config['per_page'] = 20;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
/*$this->create_menu();
$this->create_mainmenu();
$this->create_mobile_menu();*/
$this->left_menu_ant();
$this->create_menu_top();
$this->create_mobile_menu();
$data['list'] = $this->product->getAllCat($cid,$config['per_page'],$start);
$data['message'] = $this->pre_message;
$data['start'] = $start;
$data['page'] = 'product/cat/listcat';
$this->load->view("layout/skin",$data);
}
function create_menu_top()
{
$str = '';
$list_cap1 = $this->product->get_menu_top(9,0);
foreach($list_cap1 as $cap1):
$ul = $li = '';
$list_cap2 = $this->product->get_sub_menu_top($cap1->catid,6,0);
if($list_cap2) :
foreach($list_cap2 as $cap2):
$li.='<li class="level2"><a href="'.domain.'danh-muc/'.alias($cap2->cat_name).'-'.$cap2->catid.'.html" title="'.$cap2->cat_name.'">'.$cap2->cat_name.'</a></li>';
endforeach;
$ul = '<ul class="level1">'.$li.'</ul>';
endif;
$str.='<li class="level1 parent item"><a href="'.domain.'danh-muc/'.alias($cap1->cat_name).'-'.$cap1->catid.'.html" title="'.$cap1->cat_name.'">'.$cap1->cat_name.'</a>'.$ul.'</li>';
endforeach;
$str = '<ul class="level0">'.$str.'</ul>';
write_file(ROOT_SITE.'cache/menu_top.php', $str);
}
function left_menu_ant()
{
$str = "";
$listcat_cap1 = $this->product->get_menu_top(9,0);
foreach($listcat_cap1 as $cap1):
$strcap2 = "";
$listcat_cap2 = $this->product->get_sub_menu_top($cap1->catid,10,0);
if($listcat_cap2) :
foreach($listcat_cap2 as $cap2):
$strcap3 = "";
/*$listcat_cap3 = $this->category->get_submenu($cap2->catid);
if($listcat_cap3) :
foreach($listcat_cap3 as $cap3):
$strcap3 .= '<li><a href="'.domain.'danh-muc/'.alias($cap3->cat_name).'-'.$cap3->catid.'.html" title="'.$cap3->cat_name.'">- '.$cap3->cat_name.'</a></li>';
endforeach;
$strcap3 = '<ul class="no-bullets">'.$strcap3.'</ul>';
endif ;*/
//cap 2
$strcap2 .= '<li class="nav-item"><a class="nav-link" href="'.domain.'danh-muc/'.alias($cap2->cat_name).'-'.$cap2->catid.'.html" title="'.$cap2->cat_name.'">- '.$cap2->cat_name.'</a>'.$strcap3.'</li>';
endforeach;
$strcap2 = '<ul class="dropdown-menu">'.$strcap2.'</ul>';
endif ;
//cap 1
$str .= '<li class="nav-item active"><a class="nav-link" href="'.domain.'danh-muc/'.alias($cap1->cat_name).'-'.$cap1->catid.'.html" title="'.$cap1->cat_name.'"><i class="fa fa-caret-right" aria-hidden="true"></i>'.$cap1->cat_name.'</a>'.$strcap2.'</li>';
endforeach;
$str = '<ul class="nav navbar-pills">'.$str.'</ul>';
write_file(ROOT_SITE.'cache/left-menu-ant.php', $str);
}
/*function left_menu()
{
$str = "";
$listcat_cap1 = $this->category->getMaincat();
foreach($listcat_cap1 as $cap1):
$strcap2 = "";
$listcat_cap2 = $this->category->get_submenu($cap1->catid);
if($listcat_cap2) :
foreach($listcat_cap2 as $cap2):
$strcap3 = "";
$listcat_cap3 = $this->category->get_submenu($cap2->catid);
if($listcat_cap3) :
foreach($listcat_cap3 as $cap3):
$strcap3 .= '<li><a href="'.domain.'danh-muc/'.alias($cap3->cat_name).'-'.$cap3->catid.'.html" title="'.$cap3->cat_name.'">- '.$cap3->cat_name.'</a></li>';
endforeach;
$strcap3 = '<ul class="no-bullets">'.$strcap3.'</ul>';
endif ;
//cap 2
$strcap2 .= '<li><a href="'.domain.'danh-muc/'.alias($cap2->cat_name).'-'.$cap2->catid.'.html" title="'.$cap2->cat_name.'">- '.$cap2->cat_name.'</a>'.$strcap3.'</li>';
endforeach;
$strcap2 = '<ul class="no-bullets">'.$strcap2.'</ul>';
endif ;
//cap 1
$str .= '<li><a href="'.domain.'danh-muc/'.alias($cap1->cat_name).'-'.$cap1->catid.'.html" title="'.$cap1->cat_name.'">'.$cap1->cat_name.'</a>'.$strcap2.'</li>';
endforeach;
$str = '<ul class="no-bullets">'.$str.'</ul>';
write_file(ROOT_SITE.'cache/category-cache.php', $str);
}*/
function create_mainmenu()
{
$str = '<ul id="mega_menu" class="menu">';
$listcat_cap1 = $this->category->get_mainmenu();
foreach($listcat_cap1 as $cap1):
$cat_image = $cap1->cat_thumb? '<img src="'.urlimg.'category/thumb/'.$cap1->cat_thumb.'" alt="'.$cap1->cat_name.'" />' : '' ;
$link = domain."danh-muc/".$cap1->cat_alias."-".$cap1->catid.".html" ;
$str .= '<li class="menu-item menu-item-has-children"><a href="'.$link.'" title="'.$cap1->cat_name.'"><span class="icon">'.$cat_image.'</span>'.$cap1->cat_name.'</a>';
$listcat_cap2 = $this->category->check_parentid($cap1->catid);
if($listcat_cap2){
$str .= '<ul class="sub-menu">';
foreach($listcat_cap2 as $cap2):
$link = domain."danh-muc/".$cap2->cat_alias."-".$cap2->catid.".html" ;
$cat_image = $cap2->cat_image? '<img width="209" height="190" src="'.urlimg.'category/'.$cap2->cat_image.'" class="attachment-full size-full" alt="'.$cap2->cat_name.'" />' : '';
$str .= '<li class="menu-item"><a href="'.$link.'" title="'.$cap2->cat_name.'">'.$cap2->cat_name.'</a><div class="menu-image">'.$cat_image.'</div></li>';
endforeach;
$str .= '</ul>';
}
endforeach;
$str .= '</ul>';
write_file(ROOT_SITE.'cache/main_menu.php', $str);
}
function create_mobile_menu()
{
$str = '';
$list_cap1 = $this->product->get_menu_top();
foreach($list_cap1 as $cap1):
$ul = $li = '';
$list_cap2 = $this->product->get_sub_menu_top($cap1->catid);
if($list_cap2) :
foreach($list_cap2 as $cap2):
$li.='<li class="ng-scope"><a href="'.domain.'danh-muc/'.alias($cap2->cat_name).'-'.$cap2->catid.'.html" title="'.$cap2->cat_name.'">'.$cap2->cat_name.'</a></li>';
endforeach;
$ul = '<ul class="ul-has-child2">'.$li.'</ul>';
endif;
$str.='<li class="ng-scope ng-has-child2"><a href="'.domain.'danh-muc/'.alias($cap1->cat_name).'-'.$cap1->catid.'.html" title="'.$cap1->cat_name.'">'.$cap1->cat_name.'</a>'.$ul.'</li>';
endforeach;
$str = '<ul class="ul-has-child1">'.$str.'</ul>';
write_file(ROOT_SITE.'cache/menu_mobile.php', $str);
}
/*function create_mobile_menu()
{
$item = '';
$button_text = '<div class="mobile-nav__toggle">
<button type="button" class="icon-fallback-text mobile-nav__toggle-open">
<span class="icon icon-plus" aria-hidden="true"></span> <span class="fallback-text">See More</span>
</button>
<button type="button" class="icon-fallback-text mobile-nav__toggle-close">
<span class="icon icon-minus" aria-hidden="true"></span> <span class="fallback-text">"Đóng"</span>
</button>
</div>';
$listcat_cap1 = $this->category->get_mainmenu();
$str = '<ul class="mobile-nav supports-fontface">';
foreach($listcat_cap1 as $cap1):
$listcat_cap2 = $this->category->check_parentid($cap1->catid);
$link = domain."danh-muc/".$cap1->cat_alias."-".$cap1->catid.".html" ;
$substr = '';
if($listcat_cap2){
$substr .= '<ul class="mobile-nav__sublist">';
foreach($listcat_cap2 as $cap2):
$link1 = domain."danh-muc/".$cap2->cat_alias."-".$cap2->catid.".html" ;
$substr .= '<li class="mobile-nav__item ">
<div class="mobile-nav__has-sublist"><a href="'.$link.'" title="'.$cap2->cat_name.'" class="mobile-nav__link">'.$cap2->cat_name.'</a></div></li>';
endforeach;
$substr .= '</ul>';
$str .= '<li class="mobile-nav__item" aria-haspopup="true"><div class="mobile-nav__has-sublist"> <a href="'.$link.'" class="mobile-nav__link">'.$cap1->cat_name.'</a>'.$button_text.'</div>'.$substr.'</li>';
}
else
{
$str .= '<li class="mobile-nav__item"><a href="'.$link.'" title="'.$cap1->cat_name.'" class="mobile-nav__link">'.$cap1->cat_name.'</a>';
}
endforeach;
$str .= '</ul>';
write_file(ROOT_SITE.'cache/mobile_menu.php', $str);
}*/
/*function create_mainmenu()
{
$str = '<ul id="mega_menu" class="menu">';
$listcat_cap1 = $this->product->get_mainmenu();
foreach($listcat_cap1 as $cap1):
$cat_image = $cap1->cat_thumb? '<img src="'.urlimg.'category/thumb/'.$cap1->cat_thumb.'" alt="'.$cap1->cat_name.'" />' : '' ;
$link = domain."danh-muc/".$cap1->cat_alias."-".$cap1->catid.".html" ;
$str .= '<li id="menu-item-214" class="menu-item menu-item-has-children"><a href="'.$link.'" title="'.$cap1->cat_name.'"><span class="icon">'.$cat_image.'</span>'.$cap1->cat_name.'</a>';
$listcat_cap2 = $this->product->check_parentid($cap1->catid);
if($listcat_cap2){
$str .= '<ul class="sub-menu">';
foreach($listcat_cap2 as $cap2):
$link = domain."danh-muc/".$cap2->cat_alias."-".$cap2->catid.".html" ;
$cat_image = $cap2->cat_image? '<img width="209" height="190" src="'.urlimg.'category/'.$cap2->cat_image.'" class="attachment-full size-full" alt="'.$cap2->cat_name.'" />' : '';
$str .= '<li id="menu-item-396" class="menu-item"><a href="'.$link.'" title="'.$cap2->cat_name.'">'.$cap2->cat_name.'</a><div class="menu-image">'.$cat_image.'</div></li>';
endforeach;
$str .= '</ul>';
}
endforeach;
$str .= '</ul>';
write_file(ROOT_SITE.'cache/main_menu.php', $str);
}*/
function addcat()
{
$data['title'] = 'Thêm mới danh mục';
$data['listmaincat'] = $this->product->getMaincat();
if(!empty($_POST['bt_submit']))
{
$this->form_validation->set_rules('cat_name','Tên danh mục','trim|required');
if($this->form_validation->run() == FALSE)
{
$this->pre_message = validation_errors();
}else{
$req = $this->form_category();
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 editcat($catid=0)
{
$data['rs'] = $this->product->get_edit_cat($catid);
if(!empty($_POST['bt_submit'])){
$this->form_validation->set_rules('cat_name','Tên danh mục','trim|required');
if($this->form_validation->run() == FALSE){
$this->pre_message = validation_errors();
}else{
$req = $this->form_category();
if($this->product->saveCat($req,$catid)){
$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']->cat_name;
$data['listmaincat'] = $this->product->getMaincat();
$data['message'] = $this->pre_message;
$data['page'] = 'product/cat/editcat';
$this->load->view("layout/skin",$data);
}
private function form_category($flag=0)
{
$req["cat_name"] = $this->input->post("cat_name");
$req["cat_alias"] = alias($req["cat_name"]);
$req["parent_id"] = (int)$this->input->post("parent_id");
$req["cat_desc"] = $this->input->post("cat_desc");
$req["is_home"] = (int)$this->input->post("is_home");
$req["nb_level"] = (int)$this->input->post("nb_level");
$req["nb_order"] = (int)$this->input->post("nb_order");
$req["is_mainmenu"] = $this->input->post("is_mainmenu");
$req["bl_active"] = (int)$this->input->post("bl_active");
//for SEO
$metatitle = $this->input->post("metatitle");
$metadesc = $this->input->post("metadesc");
$metakey = $this->input->post("metakey");
$req["metatitle"] = empty($metatitle)? $req["cat_name"] :$metatitle;
$req["metadesc"] = empty($metadesc)? $req["cat_name"] : $metadesc;
$req["metakey"] = empty($metakey)? $metatitle : $metakey;
//upload hinh anh
$img = $this->input->post("cat_thumb");
if($img)
{
$img_name = end(explode('/', $img)) ;
if(file_exists(ROOT_IMG.'category/thumb/'.$img_name))
{
unlink(ROOT_IMG.'category/thumb/'.$img_name);
}
fn_resize_image(ROOT_IMG.$img, ROOT_IMG.'category/thumb/'.$img_name, 40, 35);
$req["cat_thumb"] = $img_name;
}
return $req;
}
function get_level()
{
$category = $this->input->post('catid') ;
$rs = $this->product->get_edit_cat($category) ;
echo $rs->nb_level ;
}
function addkeyword($id=0,$str='',$kind='product')
{
if(empty($str)) return ;
$arr = explode(",",$str);
if(is_array($arr))
{
foreach ($arr as $a):
$rs = $this->keywords->get_word(trim($a));
if(empty($rs))
{
$this->save_keyword($a,$kind,$id);
}
else
{
$this->upd_keyword($rs,$str,$kind,$id);
}
endforeach ;
}
else
{
$rs = $this->keywords->get_word(trim($str));
if(empty($rs))
{
$this->save_keyword($str,$kind,$id);
}
else
{
$this->upd_keyword($rs,$str,$kind,$id);
}
}
}
// Xoa tang pham
function save_keyword($str,$kind,$id=0)
{
$req["keyname"] = mb_strtolower(trim($str));
$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);
}
function upd_keyword($rs,$str,$kind,$id=0)
{
if($kind=='product')
$req["list_pro"] = $rs->list_pro.','.$id;
else
$req["list_news"] = $rs->list_news.','.$id;
$this->keywords->save('keywords',$req,'kid',$rs->kid);
}
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,$start=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/'.$start);
}
// 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=0)
{
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');
}
function set_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->common->save('category',$data,'catid',$id);
echo icon_open($cssname,$id,$field,$value);
}
function set_product()
{
$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->common->save('product',$data,'proid',$id);
echo icon_open($cssname,$id,$field,$value);
}
/**********Product*************/
function listproduct($cid=0,$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(
'pro_name'=>'Product Name',
'pro_code'=>'Product Code',
),$this->module.'/listproduct/');
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'] = base_url().'product/listproduct/'.$cid;
$config['total_rows'] = $this->product->getNumProduct($cid,$arr_search);
$data['num'] = $config['total_rows'];
$config['per_page'] = 30;
$config['uri_segment'] = 4;
$config['num_links'] = 10;
$ord = (int) $this->input->post('orderby') ;
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$data['list'] = $this->product->getAllProduct($cid,$config['per_page'],$start,$arr_search,$ord);
$data['catid'] = $cid;
$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['list_factory'] = $this->product->get_factory();
$data['listcat'] = $this->product->check_parentid(0);
$data['listimg'] = $this->product->get_img_by_session($this->session->userdata('session_id'));
if(isset($_POST['bt_submit']))
{
$this->form_validation->set_rules('pro_name','Tên sản phẩm','trim|required');
//$this->form_validation->set_rules('price','Giá','trim|required');
if($this->form_validation->run())
{
$req = $this->build_data(1);
if($this->product->saveProduct($req))
{
$this->addkeyword(0,$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);
}
function editproduct($proid=0)
{
$data['list_factory'] = $this->product->get_factory();
$data['listmaincat'] = $this->product->check_parentid(0);
$data['listimg'] = $this->product->get_img_by_product_id($proid);
$rs = $this->product->get_info_product($proid);
$data['discount'] = $discount = $this->product->get_promotion_by_proid($proid);
$data['title'] = 'Cập nhật :'.$rs->pro_name;
if(isset($_POST['bt_submit']))
{
$this->form_validation->set_rules('pro_name','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->build_data();
if($this->product->saveProduct($req, $proid))
{
$req = $this->_editpro_promo($proid);
//$row = $this->product->check_promo_exists($proid);
if($discount && !empty($req['fromdate']))
$product_id = $this->product->save('promotion',$req,'proid',$proid);
elseif(!empty($req['fromdate']))
$product_id = $this->product->save('promotion',$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";
}
}
}
$listcat = $this->product->get_info_cat($rs->catid);
$seg_cat = explode('-',$listcat);
$data['cat1'] = $seg_cat[0];
$data['cat2'] = $seg_cat[1];
$data['cat3'] = $seg_cat[2];
$data['listcat'] = $listcat;
$data['rs'] = $rs;
$data['proid'] = $proid;
$data['message'] = $this->pre_message;
$data['page'] = 'product/pro/editproduct';
$this->load->view("layout/skin",$data);
}
private function _editpro_promo($proid=0)
{
$req["proid"] = $proid;
$req["barcode"] = $this->input->post("pro_code");
$req["proname"] = $this->input->post("pro_name");
$req['fromdate'] = $this->input->post("fromdate");
$req['todate'] = $this->input->post("todate");
$req['createdate'] = date("Y-m-d");
return $req;
}
private function build_data($flag=0)
{
$req["pro_code"] = $this->input->post("pro_code");
$req["pro_name"] = $this->input->post("pro_name");
$req["pro_alias"] = alias($req["pro_name"]);
$req["factory_id"] = $this->input->post("factory_id");
$req["catid"] = $this->input->post("catid");
$req["vat"] = $this->input->post("vat");
$req["pro_type"] = $this->input->post("pro_type");
$req["pro_kind"] = $this->input->post("pro_kind");
$req["sumary"] = $this->input->post("sumary");
$req["pro_desc"] = $this->input->post("pro_desc");
$req["pro_status"] = $this->input->post("pro_status");
$req["status_text"] = $this->input->post("status_text");
$req["tailieu"] = $this->input->post("tailieu");
$req["video"] = $this->input->post("video");
$req["driver"] = $this->input->post("driver");
$req["khogiay"] = $this->input->post("khogiay");
$req["tocdo"] = $this->input->post("tocdo");
$req["congsuat"] = $this->input->post("congsuat");
$req["chucnang"] = $this->input->post("chucnang");
$req["weight"] = $this->input->post("weight");
$req["size"] = $this->input->post("size");
$req["country"] = $this->input->post("country");
$req["tinhtrang"] = $this->input->post("tinhtrang");
$req["capacity"] = $this->input->post("capacity");
$req["warranty"] = $this->input->post("warranty");
$req["notice"] = $this->input->post("notice");
$req["is_home"] = $this->input->post("is_home");
$req["is_borrow"] = $this->input->post("is_borrow");
if($flag) $reg['dt_create'] = date("Y-m-d H:i:s") ;
$reg['dt_modilfy'] = date("Y-m-d H:i:s") ;
$req["bl_active"] = $this->input->post("bl_active");
$price_old = $this->input->post("price_old");
$req["price_old"] = filter_price($price_old);
$price = $this->input->post("price");
$req["price"] = filter_price($price);
//for SEO
$metatitle = $this->input->post("metatitle");
$metadesc = $this->input->post("metadesc");
$metakey = $this->input->post("metakey");
$req["metatitle"] = empty($metatitle)? $req["pro_name"] : $metatitle;
$req["metadesc"] = empty($metadesc)? $req["pro_name"] : $metadesc;
$req["metakey"] = empty($metakey)? mb_strtolower($metatitle) : mb_strtolower($metakey);
$todate = $this->input->post("todate");
$req["is_promo"] = !empty($todate)? 1 : 0;
//upload hinh anh
$img = $this->input->post("proimg");
if($img)
{
$img_name = get_img_name($img) ;
if(file_exists(rootimg.'products/800/'.$img_name))
{
unlink(rootimg.'products/800/'.$img_name);
unlink(rootimg.'products/100/'.$img_name);
}
fn_resize_image(rootimg.$img,rootimg.'products/100/'.$img_name, 300, 300);
$this->resize(rootimg.$img, rootimg.'products/800/'.$img_name, 1000) ;
$req["proimg"] = $img_name;
}
return $req;
}
//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
$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['proid'] = $proid;
$data['ImageName'] = $filename;
$data['ImagePath'] = $lb_image;
$data['ImageType'] = 0;
$data['ImageSession'] = $this->session->userdata('session_id');
$imgid = $this->common->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->common->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++){
$nb_order = (int)$this->input->post('OrderHN'.$ar_pid[$i]);
if($nb_order!=0)
{
$data = array(
'OrderHN' => $nb_order
);
$this->db->where('proid',$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++){
$nb_order = (int)$this->input->post('Order'.$ar_pid[$i]);
if($nb_order!=0)
{
$data = array(
'nb_order' => $nb_order
);
$this->db->where('proid',$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,$start=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/'.$start);
}
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("quatangmythuat.com")
->setLastModifiedBy("quatangmythuat.com")
->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://quatangmythuat.com.") //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ề'); //pro_code
$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->proid);
//Pro Code
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('B'.$i, $this->product->get_edit_cat($rs->catid)->cat_name); //$rs->pro_code
// pro_name
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('C'.$i, $rs->pro_name);
// 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 = (int)$this->uri->segment(3) ;
$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("quatangmythuat.com")
->setLastModifiedBy("quatangmythuat.com")
->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://quatangmythuat.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('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->proid);
//Pro Code
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('B'.$i, $this->product->get_edit_cat($rs->catid)->cat_name);
// Product Image
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName($rs->pro_name);
$objDrawing->setDescription($rs->pro_name);
$objDrawing->setPath('../uploads/images/'.$rs->proimg);
$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://quatangmythuat.com/uploads/images/'.$rs->proimg);
// Product Name
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('D'.$i, $rs->pro_name);
// 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("quatangmythuat.com")
->setLastModifiedBy("quatangmythuat.com")
->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://quatangmythuat.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('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->proid);
//Pro Code
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('B'.$i, $this->product->get_edit_cat($rs->catid)->cat_name);
// Product Image
if(!empty($rs->proimg))
{
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName($rs->pro_name);
$objDrawing->setDescription($rs->pro_name);
$objDrawing->setPath('../uploads/images/'.$rs->proimg);
$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://quatangmythuat.com/uploads/images/'.$rs->proimg);
}
// Product Name
$this->phpexcel->setActiveSheetIndex(0)->setCellValue('D'.$i, $rs->pro_name);
// 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');
$proid = (int)$this->input->post('proid');
if($this->product->add_img($path,$proid,$session_info)){
echo $this->_load_img_product($proid,$session_info);
}else{
echo 'Error';
}
}
function _load_img_product($proid,$sesssion)
{
$list = $this->product->getListImg($proid,$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();
$(\'#proimg\').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 = ROOT_IMG.$item->ImagePath.$item->ImageName;
$images_800 = ROOT_IMG.'products/800/'.$item->ImagePath;
$images_100 = ROOT_IMG.'products/100/'.$item->ImagePath;
if(file_exists($images)){
unlink($images);
}
if(file_exists($images_800)){
unlink($images_800);
}
if(file_exists($images_100)){
unlink($images_100);
}
$this->db->where('ImageID',$id);
$this->db->delete('productimage');
}*/
// Promotion
function discount($cid=0,$start=0)
{
$data['add'] = 'product/addproduct';
$data['title'] = 'Danh sách sản phẩm khuyến mãi';
$data['listcat'] = $this->product->getMaincat();
$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['pagination'] = $this->pagination->create_links();
$data['list'] = $this->product->listpromotion($config['per_page'],$start);
$data['page'] = 'discount/listdiscount';
$this->load->view("layout/skin",$data);
}
function promo($proid=0)
{
$rs = $this->product->get_info_product($proid);
$rsp = $this->product->get_promotion_by_proid($rs->proid);
if(isset($_POST['bt_submit']))
{
$this->form_validation->set_rules('price','Giá khuyến mãi','trim|required');
$this->form_validation->set_rules('price_old','Giá cũ','trim|required');
if($this->form_validation->run())
{
$req = $this->_form_promo();
$row = $this->product->check_promo_exists($proid);
if($row)
$product_id = $this->product->save('promotion',$req,'proid',$proid);
else
$product_id = $this->product->save('promotion',$req);
if($product_id)
{
$this->product->update_product_promo($proid);
$this->session->set_flashdata('message','Lưu thành công');
redirect('product/promo/index');
}
else
{
$this->pre_message ="Lưu không thành công";
}
}
}
$data['rs'] = $rs;
$data['rsp'] = $rsp;
$data['proid'] = $proid;
$data['message'] = $this->pre_message;
$data['title'] = 'Khuyến mãi:'.$rs->pro_name;
$data['page'] = 'product/pro/promo';
$this->load->view("layout/skin",$data);
}
private function _form_promo($flag=0)
{
$req["proid"] = $this->input->post("proid");
$req["barcode"] = $this->input->post("barcode");
$req["proname"] = $this->input->post("proname");
$req['fromdate'] = $this->input->post("fromdate");
$req['todate'] = $this->input->post("todate");
$req['createdate'] = date("Y-m-d");
return $req;
}
}
?>