ACC SHELL

Path : /srv/www/vhosts/marevva/crossroadsfoundation/
File Upload :
Current File : /srv/www/vhosts/marevva/crossroadsfoundation/class.crProductList.php

<?php

include_once( 'functions.php' );

class crProductList
{
	
	private $db;
	private $productListDB;
	private $categoryURL;
	private $categoryTitle;
	private $categoryText;
	private $categoryTextBottom;
	
	private $categoryType;
	private $showFilter;
	
	// --------------------------------------------------------------------------------
	
	public function __construct( $db )
	{
		$this->db = $db;
		$this->categoryTitle = '';
		$this->categoryText = '';
		$this->categoryTextBottom = '';
		$this->categoryType = 1;
		$this->showFilter = true;
	}
	
	// --------------------------------------------------------------------------------
	
	public function load( $categoryURL, $manufacturerURL = '' )
	{
		$filterManufacturerQuery = '';
		$manufacturers = $this->db->getAllItems( 'manufacturer' );
		$first = true;
		foreach ( $manufacturers as $manufacturer )
		{
			if ( isset( $_COOKIE[ ('filter_manufacturer'.$manufacturer['ID']) ] ) && ( $_COOKIE[ ('filter_manufacturer'.$manufacturer['ID']) ] == 'true' ) )
			{
				if ( $first )
				{
					$first = false;
					$filterManufacturerQuery .= ' `manufacturerID`='.$manufacturer['ID'] . ' ';
				}
				else
				{
					$filterManufacturerQuery .= ' OR `manufacturerID`='.$manufacturer['ID'] . ' ';
				}
			}			
		}
		if ( $filterManufacturerQuery != '' )
		{
			$filterManufacturerQuery = ' AND ( ' . $filterManufacturerQuery . ') ';
		}
		
		if ( $manufacturerURL != '' )
		{
			$manufacturerURLitem = $this->db->getItemWhere( 'manufacturer', " WHERE `url`='" . $manufacturerURL . "' " );
			$filterManufacturerQuery = ' AND ( `manufacturerID`='.$manufacturerURLitem['ID'] . ') ';
		}
		
		$this->categoryURL = $categoryURL;
		
		if ( $categoryURL == 'produkty' )
		{
			$this->productListDB = $this->db->getAllItems( 'product', " ORDER BY `position` ASC " );
			$this->categoryTitle = 'Produkty';
		}
		if ( ( $categoryURL == '' ) && ( $manufacturerURL != '' ) )
		{
			$this->showFilter = false;
			$this->categoryURL = $manufacturerURL;
			$this->categoryTitle = $manufacturerURLitem['title'];
			$this->categoryText = $manufacturerURLitem['text'];
			$this->categoryTextBottom = $manufacturerURLitem['textBottom'];
			$this->categoryType = 1;
			$products =  $this->db->getAllItems( 'product', " WHERE `manufacturerID`=" . $manufacturerURLitem['ID'] );
			if ( count( $products ) > 0 )
			{
				foreach ( $products as $product )
				{
					include_once( 'class.crProduct.php' );
						$_product = new crProduct( $this->db );
						$_product->loadByID( $product['ID'] );
						
					$product['priceSort'] = $_product->getPriceInVAT();
					
					$this->productListDB[] = $product;
				}
				
				if ( isset( $_COOKIE['filter_orderBy'] ) )
				{
					if ( $_COOKIE['filter_orderBy'] == 1 )
						$this->productListDB = array_sort( $this->productListDB, 'priceSort', 'SORT_ASC' );
					if ( $_COOKIE['filter_orderBy'] == 2 )
						$this->productListDB = array_sort( $this->productListDB, 'priceSort', 'SORT_DESC' );	
				}
				else
				{
					$this->productListDB = array_sort( $this->productListDB, 'position', 'SORT_ASC' );
				}
			}
		}
		else
		{
			$category = $this->db->getItemWhere( 'category', " WHERE `url`='" . $categoryURL . "' " );
			if ( isset( $category['ID'] ) )
			{
				$this->categoryTitle = $category['title'];
				$this->categoryText = $category['text'];
				$this->categoryTextBottom = $category['textBottom'];
				$this->categoryType = $category['type'];
				$productCategories =  $this->db->getAllItems( 'productCategory', " WHERE `categoryID`=" . $category['ID'] );
				if ( count( $productCategories ) > 0 )
				{
					foreach ( $productCategories as $productCategory )
					{
						$item = $this->db->getItemWhere( 'product', " WHERE `ID`=".$productCategory['productID'] .  $filterManufacturerQuery );
										
						//$item = $this->db->getItem( 'product', $productCategory['productID'] );
						if ( $item )
						{
							include_once( 'class.crProduct.php' );
								$_product = new crProduct( $this->db );
								$_product->loadByID( $item['ID'] );
								
							$item['priceSort'] = $_product->getPriceInVAT();
							
							
							$this->productListDB[] = $item;
						}
					}
					
					if ( isset( $_COOKIE['filter_orderBy'] ) )
					{
						if ( $_COOKIE['filter_orderBy'] == 1 )
							$this->productListDB = array_sort( $this->productListDB, 'priceSort', 'SORT_ASC' );
						if ( $_COOKIE['filter_orderBy'] == 2 )
							$this->productListDB = array_sort( $this->productListDB, 'priceSort', 'SORT_DESC' );	
					}
					else
					{
						$this->productListDB = array_sort( $this->productListDB, 'position', 'SORT_ASC' );
					}
				}
			}
			else
			{
				$this->productListDB = array();
			}
		}
		
		if ( count( $this->productListDB ) > 0 )
		{						
			return true;
		}
		else
		{
			return false;
		}
		
	}
	
	// --------------------------------------------------------------------------------
	
	public function getTitle()
	{
		return $this->categoryTitle;
	}
	
	// --------------------------------------------------------------------------------
	
	public function count()
	{
		return count( $this->productListDB );
	}
	
	
	// --------------------------------------------------------------------------------
	
	public function getType()
	{
		return $this->categoryType;
	}
	
	// --------------------------------------------------------------------------------
	
	public function show( $etsHTMLteplate, $imageDir, $imagesDir, $productsPerLine, $showFilter = true )
	{
		$returnString = '';
		$data = new stdClass();
		
		$data->categoryTitle = $this->categoryTitle;
		$data->categoryText = $this->categoryText;
		$data->categoryTextBottom = $this->categoryTextBottom;
		$cleanCategoryURL = $this->categoryURL;
		$data->categoryURL = '/' . $this->categoryURL;
	
		if ( $this->count() > 0 )
		{
			$il = 0;
			
			for ( $pi = 0; $pi < $this->count(); $pi++ )
			{
				$product = $this->productListDB[ $pi ];
			
				if ( $product['visibility'] == 1 )
				{
					$data->products[ $pi ] = new stdClass();
					
					//$data->products[ $pi ]->url = '/' . $this->categoryURL . '/' . $product['url'];
					$data->products[ $pi ]->title = $product['title'];
					$data->products[ $pi ]->subtitle = $product['subtitle'];
					
					switch ( $this->categoryType )
					{
						case '1': 	$data->products[ $pi ]->text = nl2br(shortenText( fuckOffOrphans(( strip_tags( $product['text'] ) )), 350 )); break;
						case '2': 	$data->products[ $pi ]->text = nl2br(shortenText( fuckOffOrphans(( strip_tags( $product['text'] ) )), 100 )); break;
						case '3': 	$data->products[ $pi ]->text = nl2br(shortenText( fuckOffOrphans(( strip_tags( $product['text'] ) )), 600 )); break;
					}
					
					include_once( 'class.crProduct.php' );
					$_product = new crProduct( $this->db );
					$_product->loadByID( $product['ID'] );
					
					$data->products[ $pi ]->url = $_product->getURL( $cleanCategoryURL );
					
					$data->products[ $pi ]->price = $_product->getPriceInVAT();
					
					$data->products[ $pi ]->freshType = $_product->getPriceType();
					
					$data->products[ $pi ]->priceOld = 0;
					$data->products[ $pi ]->priceSale = 0;
					$data->products[ $pi ]->priceDiff = 0;
					if ( $_product->getPriceSale() != 0 )
					{
						$data->products[ $pi ]->priceOld = $_product->getPriceInVAT(false);
						$data->products[ $pi ]->priceSale = $product['sleva'];
						$data->products[ $pi ]->priceDiff = $data->products[ $pi ]->priceOld - $data->products[ $pi ]->price;
					}
					$data->products[ $pi ]->priceOld = number_format( (float)$data->products[ $pi ]->priceOld, 0, '.', ' ' );
					$data->products[ $pi ]->priceSale = number_format( (float)$data->products[ $pi ]->priceSale, 0, '.', ' ' );
					$data->products[ $pi ]->priceDiff = number_format( (float)$data->products[ $pi ]->priceDiff, 0, '.', ' ' );
					$data->products[ $pi ]->price = number_format( (float)$data->products[ $pi ]->price, 0, '.', ' ' );
					
					if ( $product['image'] != '' )
					{
						$data->products[ $pi ]->imgSrc = $imageDir . '/small/' . $product['image'];
						$data->products[ $pi ]->imgSrcLarge = $imageDir . '/large/' . $product['image'];
						$data->products[ $pi ]->imgSrcFull = $imageDir . '/full/' . $product['image'];
					}
					else
						$data->products[ $pi ]->imgSrc = '';
						
					/*$images = $this->db->getAllItems( 'mediaItem', " WHERE `ownerID`=" . $product['ID'] );
					$imagesCount = count( $images );
					for ( $i = 0; $i < $imagesCount; $i++ )
					{
						$image = $images[ $i ];
						$data->products[ $pi ]->images[ $i ]->imgSrc = $imagesDir . '/' . $product['ID'] . '/thumbs/' . $image['fileName'];
						$data->products[ $pi ]->images[ $i ]->imgSrcFull = $imagesDir . '/' . $product['ID'] . '/' . $image['fileName'];
					}*/
					
					$il++;
					if ( $il == $productsPerLine )
					{
						$il = 0;
						$data->products[ $pi ]->separator = true;
					}
					else
					{
						$data->products[ $pi ]->separator = false;				
					}
					
				}
			}
			
			$data->noProducts = false;
		}
		else
		{
			$data->noProducts = true;
		}
		
		if ( $showFilter )
		{
			if ( $this->showFilter )
			{
				$data->showFilter = true;
				
				$manufacturers = $this->db->getAllItems( 'manufacturer' );
				$mi = 0;
				foreach( $manufacturers as $manufacturer )
				{
					$mi++;
					
					$data->manufacturer[ $mi ]->ID = $manufacturer['ID'];
					$data->manufacturer[ $mi ]->title = $manufacturer['title'];
					
					$data->manufacturer[ $mi ]->checked = false;
					if ( isset( $_COOKIE[ ('filter_manufacturer'.$manufacturer['ID']) ] ) && ( $_COOKIE[ ('filter_manufacturer'.$manufacturer['ID']) ] == 'true' ) )
					{
						$data->manufacturer[ $mi ]->checked = true;
					}
				}
			}
			
			$data->filterCategoryURL = $this->categoryURL;
			
			//skryt vyrobce
			$data->showFilter = false;
			
			$serverFullPath = '/srv/www/vhosts/marevva/crossroadsfoundation/';
			$data->filter = sprintt( $data, $serverFullPath."parts/product-filter.html" );
			
			//$returnString .= print_r( $_COOKIE, true );
		}
		
		$returnString .= sprintt( $data, $etsHTMLteplate );
		
		return $returnString;
	}
	
	// --------------------------------------------------------------------------------
	
	public function showSearchResults( $searchQuery, $etsHTMLteplate, $imageDir )
	{
		$data->searchQuery = $searchQuery;
		
		$searchResults_products = $this->db->getSearchResults( $searchQuery, 'product', " `visibility`=1 ", 0, 'title', 'text'/*, 'price'*/ );
	
		if ( count( $searchResults_products ) > 0 )
		{
			$pi = 1;
			
			foreach ( $searchResults_products as $searchResults_product ) 
			{
				$data->item[ $pi ] = new stdClass();
				
				$data->item[ $pi ]->number = $pi;
				
				$data->item[ $pi ]->title = $searchResults_product['title'];
				
				$data->item[ $pi ]->category = '<em style="color:#ccc;">nezaƙazeno</em>';
				$categoryURL = 'produkty';
				$productCategory = $this->db->getItemWhere( 'productCategory', " WHERE `productID`=" . $searchResults_product['ID'] );
				if ( isset( $productCategory['ID'] ) )
				{
					$category = $this->db->getItem( 'category', $productCategory['categoryID'] );
					$categoryURL = $category['url'];
					$data->item[ $pi ]->category = $category['title'];
				}
				$data->item[ $pi ]->url = '/' . $categoryURL . '/' . $searchResults_product['url'];
				
				include_once( 'class.crProduct.php' );
					$_product = new crProduct( $this->db );
					$_product->loadByID( $searchResults_product['ID'] );
					
				$data->item[ $pi ]->price = number_format( (float)$_product->getPriceInVAT(), 0, '.', ' ' );
				
				if ( $searchResults_product['image'] != '' )
					$data->item[ $pi ]->imgSrc = $imageDir . '/medium/' . $searchResults_product['image'];
					
				$pi++;
			}
		}
		
		return sprintt( $data, $etsHTMLteplate );
	}
}

?>

ACC SHELL 2018