403Webshell
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/galaxynail.com/wadmin/models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/galaxynail.com/wadmin/models/Product_model.php
<?php if (! defined('BASEPATH')) exit('No direct script access allowed');
class Product_model extends CI_Model
{
	function __construct()
	{
		parent::__construct();
		$this->load->helper('img_helper');  
		$this->load->helper('str');
	}
	
	function get_services($CategoryID)
	{
		$this->db->where('CategoryID',$CategoryID);
		$this->db->order_by('Ordering','ASC');           
		$query = $this->db->get('product');
		return $query->result();
	}
	
	// Thông kê gian hang
	// Tong so san pham
	function get_total_product($bl_active)
	{
		$this->db->select('ProductID');
		$this->db->where('bl_active',$bl_active);
		return $this->db->get('product')->num_rows();
	}
	
	// Tong so binh luận
	function get_total_comment($bl_active)
	{
		$this->db->select('CommentID');
		if($bl_active!=2)
		{
			$this->db->where('bl_active',$bl_active);
		}
		return $this->db->get('productcomment')->num_rows();
	}  
	
	// Tong so don hang
	function get_total_order($Status)
	{
		$this->db->select('CartID');
		if($Status !=6){
			$this->db->where('Status',$Status);              
		}
		return $this->db->get('shoppingcart')->num_rows();
	}          
	  
	// End
	function getAllCat($cid=0,$num=20,$start=0,$arr_search=array())
	{
		/*Begin search*/
		if(isset($arr_search['key_search'])&&$arr_search['key_search']!='')
		{
			if($arr_search['field_search']=='cn')
			{
				$this->db->like('CategoryName',$arr_search['key_search']);
			}
		}
		/*End search*/
		
		$this->db->where('ParentID',$cid);
		//$this->db->where('bl_active',1);
		$this->db->order_by('CategoryName','ASC');
		$query = $this->db->get('category',$num,$start);
		return $query->result();
	}
	
	function getNumCat($cid=0,$arr_search=array())
	{
		/*Begin search*/
		if(isset($arr_search['key_search'])&&$arr_search['key_search']!='')
		{
			if($arr_search['field_search']=='cn')
			{
				$this->db->like('CategoryName',$arr_search['key_search']);
			}
		}
		/*End search*/
		
		$this->db->where('ParentID',$cid);
		//$this->db->where('bl_active',1);
		$query = $this->db->get('category');
		return $query->num_rows();
	}
	
	function get_menu_cat($menu=0,$parent=0)
	{
		$this->db->where('ParentID',$parent);
		if($menu) $this->db->where('IsMainMenu',$menu);
		$this->db->where('bl_active',1);
		$this->db->order_by('CategoryName','ASC');
		$query = $this->db->get('category');
		return $query->result();
	}
	
	function getMaincat()
	{
		//$this->db->where('bl_active',1);
		$this->db->where('ParentID',0);
		$this->db->order_by('CategoryName','ASC');
		$query = $this->db->get('category');
		return $query->result();
	}
	
	function countMaincat($bl_active=0)
	{
		//if($bl_active) $this->db->where('ParentID',0);
		$this->db->where('bl_active',1);
		$query = $this->db->get('category');
		return $query->num_rows();
	}
	
	function getListSub($CategoryID)
	{
		$this->db->where('ParentID',$CategoryID);
		$this->db->order_by('Ordering','ASC');           
		$query = $this->db->get('category');
		return $query->result();
	}
	
	
	function get_edit_cat($CategoryID)
	{
		$this->db->where('CategoryID',$CategoryID);
		$query = $this->db->get('category');
		$data = $query->row(); 
		return $data;
	} 
	
	function savecat($data,$CategoryID=0)
	{
		if($CategoryID){
			$this->db->where('CategoryID',$CategoryID);
			if($this->db->update('category',$data))
			{
				return true;
			}else{
				return false;
			}
		}else{
			if($this->db->insert('category',$data)){
				return true;
			}else{
				return false;
			}
		}
	}
	
	function get_category_active()
	{
		$this->db->where('bl_active',1);
		$this->db->order_by('Ordering','ASC');
		$query = $this->db->get('category');
		return $query->result();
	}
	
	function delcat($id)
	{
		$ar_cat = array($id);
		$this->db->where('ParentID',$id);
		$query = $this->db->get('category');
		$list = $query->result();
		if($query->num_rows() > 0){
			foreach($list as $rs):
				array_push($ar_cat,$rs->CategoryID);
			endforeach;
			
			$this->db->where_in('ParentID',$ar_cat);
			$query1 = $this->db->get('category');
			if($query1->num_rows() > 0){
				foreach($query1->result() as $rs):
					array_push($ar_cat,$rs->CategoryID);
				endforeach;
			}
		}          
		
		$this->db->where_in('CategoryID',$ar_cat);
		$query = $this->db->delete('category');
		if($query){
			$this->db->where_in('CategoryID',$ar_cat);
			$this->db->delete('categoryproduct');
			return true;
		}else{
			return false;
		}          
	}
	
	//Danh sách các sản phẩm cùng loại
	function get_procat()
	{
		$this->db->where('bl_active',1);
		$this->db->order_by('nb_order','ASC');
		$query = $this->db->get('product_category');
		return $query->result();
	}
	
	function get_manufacture()
	{
		$this->db->where('bl_active',1);
		$query = $this->db->get('menufacture');
		$list = $query->result();
		return $list;
	}
	
	/*****Product**********/
	function getAllProduct($cid,$cate,$orderby,$num,$offset,$arr_search=array())
	{
		/*Begin search*/
		if(isset($arr_search['key_search'])&&$arr_search['key_search']!='')
		{
			if($arr_search['field_search']=='TT')
			{
				$this->db->like('ProductName',$arr_search['key_search']);
			}
		}
		/*End search*/
		
		//$this->db->select('product.*,categoryproduct.*');
		//$this->db->join('categoryproduct','categoryproduct.ProductID = product.ProductID');
		
		if($cid) 
		{
			$ar_cid = $this->get_array_cat_search($cid);
			$this->db->where_in('CategoryID',$ar_cid);
		}
		
		if($cate) $this->db->where('ProCat',$cate);
		
		//sap xep
		/*switch($orderby)
		{
			case "asc":
				$this->db->order_by('CategoryID','ASC');
				break;
			case "desc":
				$this->db->order_by('CategoryID','DESC');
				break;
			default:
				$this->db->order_by('product.LastUpdate',"DESC");
				//$this->db->order_by('product.Ordering',"ASC");
				break;
		}*/
		$this->db->order_by('product.LastUpdate',"ASC");
		$query = $this->db->get('product',$num,$offset);
		return $query->result();
	}
	
	function getNumProduct($cid,$cate,$orderby,$arr_search=array())
	{
		if($cid) $ar_cid = $this->get_array_cat_search($cid);
		
		/*Begin search*/
		if(isset($arr_search['key_search'])&&$arr_search['key_search']!='')
		{
			if($arr_search['field_search']=='TT')
			{
				$this->db->like('ProductName',$arr_search['key_search']);
			}
		}
		/*End search*/
		
		//$this->db->select('product.*,categoryproduct.*');
		//$this->db->join('categoryproduct','categoryproduct.ProductID = product.ProductID');
		
		if($cid) 
		{
			$ar_cid = $this->get_array_cat_search($cid);
			$this->db->where_in('CategoryID',$ar_cid);
		}
		if($cate) $this->db->where('ProCat',$cate);
		
		$query = $this->db->get('product');
		return $query->num_rows();
	}
	
	function get_info_product($ProductID,$arr_search=array())
	{
	  $this->db->where('product.ProductID',$ProductID);
	  $query = $this->db->get('product');
	  return $query->row();
	}
	
	function get_info_product_kind()
	{
		$this->db->select('type_name, template');
		$this->db->order_by('type_name',"asc");
		$query = $this->db->get('producttype');
		return $query->result();
	}
	
	
	
	function get_info_cat($CategoryID)
	{
		$list = '';
		$info_cat = $this->check_category($CategoryID);
		$cat1 = $info_cat->CategoryID;
		if($info_cat->ParentID != 0){
			$cat2 =$info_cat->ParentID;
			$info_cat1 = $this->check_category($info_cat->ParentID);
			if($info_cat1->ParentID !=0){
				$cat3 = $info_cat1->ParentID;
				return $cat3.'-'.$cat2.'-'.$cat1;
			}else{
				return $cat2.'-'.$cat1.'-0';
			}
		}else{
			return $cat1.'-0-0';
		}
	}
	
	function delproduct($id)
	{
		$this->db->where_in('ProductID',$id);
		$query = $this->db->delete('product');
		if($query)
		{
			$this->db->where('ProductID',$id);
			$this->db->delete('productpromotion');                
			$this->db->where('ProductID',$id);
			$this->db->delete('productimage');                 
			return true;
		}
		else
		{
			return false;
		}          
	}      
	
	/***********SEARCH**************/
	function get_array_cat_search($CategoryID)
	{
	  $ar_cat = array($CategoryID);
	  $info_cat = $this->check_parentid($CategoryID);	// cat_level 2
	  if(count($info_cat) > 0)
	  {
		  foreach($info_cat as $rs):
				array_push($ar_cat,$rs->CategoryID); 
				$info_cat1 = $this->check_parentid($rs->CategoryID);	// cat_level 3
				if(count($info_cat1) > 0)
				{
					foreach($info_cat1 as $rs1):
						array_push($ar_cat,$rs1->CategoryID);
						$info_cat2 = $this->check_parentid($rs1->CategoryID);	// cat_level 4
						if(count($info_cat2) > 0)
						{
							foreach($info_cat2 as $rs2):
								array_push($ar_cat,$rs2->CategoryID);
							endforeach;
						}   
					endforeach;
				}                 
		  endforeach;
	
	  }
	  return $ar_cat;
	}
	
	function getAllProductExport($cid,$keyword='')
	{
	  $ar_cid = $this->get_array_cat_search($cid);
	  $this->db->select('product.*,categoryproduct.*');
	  $this->db->join('categoryproduct','categoryproduct.ProductID = product.ProductID');
	  if($cid!=0){
		  $this->db->where_in('categoryproduct.CategoryID',$ar_cid);
	  }
	  if($keyword!=''){
		  $this->db->like('product.ProductName',$keyword);
	  }
	  
	  $query = $this->db->get('product');
	  return $query->result();
	}
	
	function getAllProductSea($cid, $keyword, $num, $offset, $ord=0)
	{
	  $promo = (int) $this->input->post('promo');
	  
	  $ar_cid = $this->get_array_cat_search($cid);			
	  //trit($ar_cid);
	  
	  $this->db->select('product.*,categoryproduct.*');
	  $this->db->join('categoryproduct','categoryproduct.ProductID = product.ProductID');
	  
	  if(!empty($promo)) $this->db->where('product.IsHome',$promo);
	  
	  if($cid!=0){
		  $this->db->where_in('categoryproduct.CategoryID',$ar_cid);
	  }
	  if($keyword!=''){
		  $this->db->like('product.ProductName',$keyword);
	  }
	  
	  switch($ord)
	  {
		case 1 :
			$this->db->order_by('product.Ordering',"ASC"); break ;
		case 2 :
			$this->db->order_by('product.LastUpdate',"DESC"); break ;
		case 3 :
			$this->db->order_by('product.Price',"ASC"); break ;
		case 4 :
			$this->db->order_by('product.PriceHN',"ASC"); break ;	
		case 5 :
			$this->db->order_by('product.OrderHN',"ASC"); break ;		
		default :
			$this->db->order_by('product.LastUpdate',"DESC"); break ;  
	  }
	  
	  $query = $this->db->get('product',$num,$offset);
	  return $query->result();
	}
	
	function getNumProductSea($cid,$keyword)
	{
		$ar_cid = $this->get_array_cat_search($cid);
		
		$this->db->select('product.*,categoryproduct.*');
		$this->db->join('categoryproduct','categoryproduct.ProductID = product.ProductID');
		if($cid!=0){
			$this->db->where_in('categoryproduct.CategoryID',$ar_cid);
		}
		if($keyword!=''){
			$this->db->like('product.ProductName',$keyword);
		}          
		$query = $this->db->get('product');
		return $query->num_rows();
	}
	
	function check_category($CategoryID)
	{
		$this->db->where('CategoryID',$CategoryID);
		$query = $this->db->get('category');
		return $query->row();
	} 
	
	function check_parentid($CategoryID)
	{    
		$this->db->where('ParentID',$CategoryID);
		$this->db->order_by('Ordering','ASC');
		$query = $this->db->get('category');
		return $query->result();          
	}
	
	function saveProduct($data,$ProductID=0)
	{
		if($ProductID)
		{
			// Update products
			$this->db->where('ProductID',$ProductID);
			if($this->db->update('product',$data))
			{
				return $ProductID;
			}else{
				return false;
			}
		}
		else
		{
			// Add new products
			if($this->db->insert('product',$data))
			{
				$ProductID_new = $this->db->insert_id();
				
				//Cập nhật thông tin hình ảnh
				$session_info = $this->session->userdata('session_id');
				$list_img_se = $this->get_img_by_session($session_info);
				
				$data_img = array(
					'ProductID' => $ProductID_new,
					'ImageSession' => ''
				);
				$this->db->where('ImageSession',$session_info);
				$this->db->update('productimage',$data_img);
				
				return $ProductID_new;
		  	}
		  	else
		  	{
			  	return false;
		  	}
	  	}
	}
	
	function resize($src, $desc, $width)
	{
		$this->load->library('ResizeImg');
		$this->resizeimg->load($src);
		$this->resizeimg->resizeToWidth($width);
		$this->resizeimg->save($desc);
	}
	
	function save($tbl, $data, $name='', $id=0)
	{
		if($name)
		{
			$this->db->where($name, $id) ;
			if($this->db->update($tbl, $data))
				return $id ;
			else return false;
		}
		else
		{
			if($this->db->insert($tbl,$data))
				return $this->db->insert_id();
			else return false;
		}
	}
	
	//**********************************************************************************************
	function get_images_id($ImageID,$ProductID)
	{
		$this->db->where('ImageID',$ImageID);
		$this->db->where('ProductID',$ProductID);
		$query = $this->db->get('productimage') ;
		return $query->row();
	}
	
	function del($tbl, $name, $id)
	{
		if($id){
			$this->db->where($name, $id) ;
			$this->db->delete($tbl) ;
		}
	}
	
	function get_img_by_session($session)
	{
		$this->db->where('ImageSession',$session);
		$query = $this->db->get('productimage');
		return $query->result();
	}
	
	function get_img_by_product_id($ProductID)
	{
		$this->db->where('ProductID',$ProductID);
		return $this->db->get('productimage')->result();
	}
	
	function add_img($path,$ProductID,$session)
	{
		if($path!=''){
			fn_resize_image(ROOT_IMG.'images/'.$path,ROOT_IMG.'product/420/'.$path,1000,1000);
			fn_resize_image(ROOT_IMG.'images/'.$path,ROOT_IMG.'product/120/'.$path,200,200);
			
			//image_thumb($ProductID,$path,55,45);
			
			$data = array(
				'ImagePath' => $path,
				'ProductID' => (int)$ProductID,
				'ImageSession' => ($ProductID!=0)?'':$session
			);
			$this->db->insert('productimage',$data);
		}
		return true;
	}
	
	function getListImg($ProductID,$session)
	{
	  if($ProductID != 0){
		  $this->db->where('ProductID',$ProductID);
		  $query = $this->db->get('productimage');
		  return $query->result();
	  }else{
		  $this->db->where('ImageSession',$session);
		  $query = $this->db->get('productimage');
		  return $query->result();              
	  }
	}
	// ********************************************************************************************  
	function move_up($id_nwc)
	{
		// move a category one cat_level up
		// get this one's properties
		$this_one = $this->get_cat_info($id_nwc);
		// get this id_nwc's weight
		$this_order = $this_one->Ordering;
		$this_pid   = $this_one->ParentID;
		// do nothing if this one is the first item
		if($this_order > 1){
			// get the first nearest lighter item
			$sql = "SELECT CategoryID, Ordering FROM category WHERE (Ordering < '$this_order') AND ParentID = $this_pid ORDER BY Ordering DESC LIMIT 0,1";
			$replaced = $this->db->query($sql)->row();
			// switch their weights
			$swap_id = $replaced->CategoryID;
			$swap_order = $replaced->Ordering;
			$this->db->query("UPDATE category SET Ordering ='$swap_order' WHERE CategoryID='$id_nwc'");
			$this->db->query("UPDATE category SET Ordering ='$this_order' WHERE CategoryID='$swap_id'");
		
			return TRUE;
		}
		return FALSE;
	}
	
	function move_down($id_nwc)
	{
		// move a category one cat_level down
		// get this one's properties
		$this_one = $this->get_cat_info($id_nwc);
		// get this id_nwc's weight
		$this_order = $this_one->Ordering;
		$this_pid   = $this_one->ParentID;
		// do nothing if this one is the last item
		$heaviest = $this->get_heaviest($this_pid);
		if($this_order <  $heaviest){
			// get the first heavier item
			$sql = "SELECT CategoryID, Ordering FROM category WHERE (Ordering > '$this_order') AND ParentID = $this_pid ORDER BY Ordering ASC LIMIT 0,1";
			$replaced = $this->db->query($sql)->row();
			// switch their weights
			$swap_id = $replaced->CategoryID;
			$swap_order = $replaced->Ordering;
			$this->db->query("UPDATE category SET Ordering ='$swap_order' WHERE CategoryID='$id_nwc'");
			$this->db->query("UPDATE category SET Ordering ='$this_order' WHERE CategoryID='$swap_id'");
		
			return TRUE;
		}
		return FALSE;
	}
	
	function get_cat_info($id_nwc)
	{
		// get a category info
		// input : $cat_id, single value
		// return : a row
		$search['CategoryID'] = $id_nwc;
		$rs = $this->db->get_where("category", $search, 1);
		return $rs->num_rows() ? $rs->row() : false;
		// to be revised: what if $id_nwc is not existing?
	}
	
	function get_heaviest($nwc_pid)
	{
		// get heaviest item in a branch (nwc_pid)
		$sql = "SELECT MAX(ordering) AS ordering FROM category WHERE ParentID ='$nwc_pid'";
		return $this->db->query($sql)->first_row()->ordering;
	}    
	
	// Promotion
	function listpromotion($num,$offset)
	{
		$this->db->select('productdiscount.*, product.*');
		$this->db->join('product','product.ProductID = productdiscount.ProductID');
		$this->db->where('productdiscount.DiscountNumber !=',0);         
		$this->db->order_by('productdiscount.DiscountEndDate',"DESC");
		$query = $this->db->get('productdiscount',$num,$offset);
		return $query->result();
	}
	
	function get_edit_product_auto()
	{
		$this->db->where('metakey <>','');
		$this->db->where('LastUpdate <','2020-05-30 00:00:00');
		$this->db->where('bl_active',1);
		$this->db->order_by('LastUpdate',"DESC");
		$query = $this->db->get('product',1,0);
		return $query->row();
	}
}
?>

Youez - 2016 - github.com/yon3zu
LinuXploit