Current File : /home/k/a/r/karenpetzb/www/items/category/models.tar
UserGuest.php000060400000000170150715102030007167 0ustar00<?php
class UserGuest extends Zend_Db_Table
{
    protected $_name = 'user_guest';
    protected $_primary = 'ID';

}
?>CodeIntern.php000060400000000173150715102030007276 0ustar00<?php
class CodeIntern extends Zend_Db_Table
{
    protected $_name = 'user_cintern';
    protected $_primary = 'ID';

}
?>FichierExcel.php000060400000001550150715102030007576 0ustar00<?php
class FichierExcel {

	private $csv = Null;
	/**
	 * Cette ligne permet de cr�er les colonnes du fichers Excel
	 * Cette fonction est totalement faculative, on peut faire la m�me chose avec la
	 * fonction insertion, c'est juste une clart� pour moi
	 */
	function Colonne($file) {

		$this->csv.=$file."\n";
		return $this->csv;

	}

	/**
	 * Insertion des lignes dans le fichiers Excel, il faut introduire les donn�es sous formes de chaines
	 * de caract�re.
	 * Attention a s�parer avec une virgule.
	 */
	function Insertion($file){
		$this->csv.=$file."\r\n";
		return $this->csv;
	}

	/**
	 * fonction de sortie du fichier avec un nom sp�cifique.
	 *
	 */
	function output($NomFichier){
		
		header('Content-type: text/csv; charset=ISO-8859-1');
		header('Content-Disposition: attachment; filename='.$NomFichier.'.csv');
		
		print $this->csv;
		exit;

	}
}

?>
OptionList.php000060400000001713150715102030007351 0ustar00<?php
class OptionList extends Zend_Db_Table
{
    protected $_name = 'optionlist';
    protected $_primary = 'ID';

    
    public function getAll() {
		$result = $this->select()->order('NAME ASC')->query()->fetchAll();
		$options = array();
		foreach ($result as $option) { 
			$itemOL = new ItemOptionList();
			$itemOL->init($option);
			array_push($options, $itemOL);
		}
		return $options;
	}
    
    public function getByIdProduct($id) {
    	$select = 'SELECT ol.*
				FROM product p 
				LEFT JOIN optionlist AS ol ON p.ONSELECT_IDOPTION = ol.ID 
				WHERE p.ID = '.$id ;  
		$result = $this->getAdapter()->fetchRow($select);  
		if (!empty($result)) {
			$itemOL = new ItemOptionList();
			$itemOL->init($result); 
			return $itemOL;
		} 
		return array();
	}
	 
	public function getProductByIdOption($id) {
		$select = 'SELECT * FROM product WHERE ONSELECT_IDOPTION = '.$id ; 
		return $this->getAdapter()->fetchAll($select); 
	}
	
	
	
	
    
		
		
    
}
?>AnnonceRight.php000060400000001073150715102030007623 0ustar00<?php
class AnnonceRight extends Zend_Db_Table
{
    protected $_name = 'annonce_right';
    protected $_primary = 'ID';

    public function getAnnonces() {
    	return $this->select()->where('isSHOW = 0')->order('NOM ASC')->query()->fetchAll();
	}
	

    public function getAllAnnonces() {
    	return $this->select()->order('NOM ASC')->query()->fetchAll();
	}
	
 	public function getAnnoncesByShow($idCat) {
 		return $this->select()->where('isSHOW = 0')->where("ID_CATS LIKE '%:".$idCat.":%' OR ID_CATS LIKE '%:0:%' ")->order('NOM ASC')->query()->fetchAll();
 	}
}
?>FAQ.php000060400000002135150715102030005653 0ustar00<?php
class FAQ extends Zend_Db_Table
{
    protected $_name = 'faq';
    protected $_primary = 'ID';

    public function getLists() {
    	$sql = "
				SELECT f.ID ID, f.QUESTION QUESTION, f.REPONSE REPONSE, f.POSITION POSITION, 
				f.TYPE IDTYPE, ft.NOM NOMTYPE
				FROM faq f
				JOIN faq_type ft ON f.TYPE = ft.ID 
				WHERE f.isACTIVE = 1
				AND ft.isACTIVE = 1
				ORDER BY ft.NOM, f.POSITION ASC";
		$results = $this->getAdapter()->fetchAll($sql);
		return $results;
	}
	
	public function getListsAll() {
    	$sql = "
				SELECT f.ID ID, f.QUESTION QUESTION, f.REPONSE REPONSE, f.POSITION POSITION, 
				f.TYPE IDTYPE, ft.NOM NOMTYPE, f.isACTIVE isACTIVEFAQ, ft.isACTIVE isACTIVETYPE
				FROM faq f
				JOIN faq_type ft ON f.TYPE = ft.ID 
				ORDER BY ft.NOM, f.POSITION ASC";
		$results = $this->getAdapter()->fetchAll($sql);
		return $results;
	}
	
	public function isTypeExist($idType){
    	$sql = "
				SELECT f.ID ID
				FROM faq f
				WHERE f.TYPE = ".$idType;
		$results = $this->getAdapter()->fetchRow($sql);
		if (isset($results) && !empty($results)) {
			return true;
		}
		return false;
	}
}
?>FichierText.php000060400000001512150715102030007460 0ustar00<?php
class FichierText {

	private $csv = Null;
	/**
	 * Cette ligne permet de cr�er les colonnes du fichers Excel
	 * Cette fonction est totalement faculative, on peut faire la m�me chose avec la
	 * fonction insertion, c'est juste une clart� pour moi
	 */
	function Colonne($file) {

		$this->csv.=$file."\n";
		return $this->csv;

	}

	/**
	 * Insertion des lignes dans le fichiers Excel, il faut introduire les donn�es sous formes de chaines
	 * de caract�re.
	 * Attention a s�parer avec une virgule.
	 */
	function Insertion($file){

		$this->csv.=$file."\n";
		return $this->csv;
	}

	/**
	 * fonction de sortie du fichier avec un nom sp�cifique.
	 *
	 */
	function output($NomFichier){
		header("Content-Type: plain/text");
		header("Content-Disposition: Attachment; filename=$NomFichier.txt");
		print $this->csv;
		exit;

	}
}

?>
AnnonceCms.php000060400000001524150715102030007271 0ustar00<?php
class AnnonceCms extends Zend_Db_Table
{
    protected $_name = 'annonce_cms';
    protected $_primary = 'ID';

    public function getAnnonces() {
    	return $this->select()->where('isSHOW = 0')->order('POSITION ASC')->order('NOM ASC')->query()->fetchAll();
	}
	

    public function getAllAnnonces() {
    	return $this->select()->order('POSITION ASC')->order('NOM ASC')->query()->fetchAll();
	}

    public function getAllAnnoncesByCategory($idCat) {
    	return $this->select()->where("ID_CATS LIKE '%:".$idCat.":%' OR ID_CATS LIKE '%:0:%' ")->order('POSITION ASC')->order('NOM ASC')->query()->fetchAll();
 	}
	
 	public function getAnnoncesByShow($idCat) {
 		return $this->select()->where('isSHOW = 0')->where("ID_CATS LIKE '%:".$idCat.":%' OR ID_CATS LIKE '%:0:%' ")->order('POSITION ASC')->order('NOM ASC')->query()->fetchAll();
 	}
}
?>PromoGift.php000060400000000170150715102030007147 0ustar00<?php
class PromoGift extends Zend_Db_Table
{
    protected $_name = 'promo_gift';
    protected $_primary = 'ID';

}
?>CodeReduction.php000060400000002524150715102030007775 0ustar00<?php
class CodeReduction extends Zend_Db_Table
{
	protected $_name = 'promo_codereduction';
	protected $_primary = 'ID';

	public function getAllCodes() {
	    return $this->select()->order('DATESTART DESC')->query()->fetchAll();
	
	}
	
	public function getCodeBy($code) {
		return $this->select()->where('CODE = ?',$code)->order('DATESTART DESC')->query()->fetch();
	
	}
	
	public function getVerifyCodeBy($code) {
		$date = new Zend_Date();
		$select = "
				SELECT *
				FROM promo_codereduction
				WHERE isACTIF = 1
				AND CODE = '".$code."'
				AND DATESTART <= '".$date->toString('YYYY-MM-dd')."'
				AND DATEEND >= '".$date->toString('YYYY-MM-dd')."'";
		$results = $this->getAdapter()->fetchAll($select);
		
		$resultCode = array();
		if (isset($results) && !empty($results)) {
			foreach ($results as $result) {
				$resultCode['PRODUITREF'] = $result['PRODUITREF'];
				$resultCode['PRODUITNBR'] = $result['PRODUITNBR'];
				$resultCode['CMDTOTAL'] = $result['CMDTOTAL'];
				$resultCode['CODE'] = $result['CODE'];
				$resultCode['LIBELLE'] = $result['LIBELLE'];
				$resultCode['DATESTART'] = $result['DATESTART'];
				$resultCode['DATEEND'] = $result['DATEEND'];
				$resultCode['isACTIF'] = $result['isACTIF'];
				$resultCode['EURO'] = $result['EURO'];
				$resultCode['POUR'] = $result['POUR'];
				break;
			}
		}
		return $resultCode;
	}	
}
?>ProductChild.php000060400000010420150715102030007624 0ustar00<?php
class ProductChild extends Zend_Db_Table
{
	protected $_name = 'productchild';
	protected $_primary = 'ID';

	public function getProductChildsByIdProduct($id) {
		$select = "
					SELECT pc.ID ID ,pc.REFERENCE REFERENCE,pc.DESIGNATION DESIGNATION,pc.PRIX PRIX, pc.isPROMO isPROMO ,
					pco.VALUE OPTIONVALUE, pco.IDOPTION OPTIONID, pc.IMAGEPROMO IMAGEPROMO,pc.isDEVIS isDEVIS, pc.QUANTITYMIN QUANTITYMIN
					, p.NAVNOM PRODUCTNAVNOM, p.NOM PRODUCTNOM, p.ID PRODUCTID, p.isQTEPRIXACTIVE isQTEPRIXACTIVE, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
					, pc.POINTFIDELITE  POINTFIDELITE 
                    FROM productchild AS pc
					LEFT JOIN productchild_option AS pco ON pc.ID = pco.IDPRODUCTCHILD
					LEFT JOIN product AS p ON pc.IDPRODUCT = p.ID
			        LEFT JOIN category c ON p.IDCATEGORY = c.ID
					WHERE pc.IDPRODUCT = ".$id." 
					ORDER BY REFERENCE ASC
					";  
		return $this->getAdapter()->fetchAll($select);
	}


	public function getChildsByIdProduct($id) {
		$select = "
						SELECT pc.ID ID ,pc.REFERENCE REFERENCE, pc.POIDS POIDS, pc.DESIGNATION DESIGNATION ,pc.PRIX PRIX,pc.ETATSTOCK ETATSTOCK,
							pc.isPROMO isPROMO,pc.isDEVIS isDEVIS,pc.QUANTITYMIN QUANTITYMIN,
						pco.VALUE VALUE,pco.ID IDCHILD, pco.IDOPTION IDOPTION, pc.IMAGEPROMO IMAGEPROMO, pc.isFRANCODENIED isFRANCODENIED,
                        pc.POINTFIDELITE  POINTFIDELITE 
							FROM productchild AS pc
						LEFT JOIN productchild_option AS pco ON pc.ID = pco.IDPRODUCTCHILD
						WHERE pc.IDPRODUCT = ".$id; 
		return $this->getAdapter()->fetchAll($select);
	} 

	public function isChildReferenceExist($reference) {
		$select = "
				SELECT COUNT(pc.ID) NBR
				FROM productchild pc 
				WHERE pc.REFERENCE LIKE '".$reference."'"; 

		$result = $this->getAdapter()->fetchRow($select);

		if ($result['NBR'] == 0) {
			return false;
		}
		return true;
	}
	
	public function getChildInfo($idChild) {
		$sql = "
			SELECT p.NOM NOM, p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.ID IDPRODUCT, pic.URL URL, p.STOCK STOCK,
			pc.DESIGNATION DESIGNATION, pc.REFERENCE REFERENCE, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS, pc.POINTFIDELITE  POINTFIDELITE 
			FROM productchild pc
			LEFT JOIN product p ON p.ID = pc.IDPRODUCT
			LEFT JOIN category c ON p.IDCATEGORY = c.ID
			LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
			WHERE pc.ID = ".$idChild."
			AND p.isACTIVE = 0
			AND pic.POSITION = 1
			";
		return $this->getAdapter()->fetchRow($sql);
	}

	public function getChildsInfoByListId($stringTemp) {
		$sql = "
			SELECT p.NOM NOM,p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.ID IDPRODUCT, pic.URL URL,p.isPROMO isPROMO, pc.DESIGNATION DESIGNATION, p.STOCK STOCK,
			pc.ID IDCHILD, pc.REFERENCE REFERENCE, pc.isDEVIS isDEVIS, pc.isPROMO isPROMOCHILD, pc.PRIX PRIX, p.DATEPROMO DATEPROMO,
			p.IDCATEGORY IDCATEGORY, p.IDBREND IDBREND, p.isSHOWBREND isSHOWBREND, pc.QUANTITYMIN QUANTITYMIN, pc.POIDS POIDS, pc.isFRANCODENIED isFRANCODENIED, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
			,pc.POINTFIDELITE  POINTFIDELITE 
            FROM productchild pc
			LEFT JOIN product p ON pc.IDPRODUCT = p.ID
			LEFT JOIN category c ON p.IDCATEGORY = c.ID
			LEFT JOIN picture pic ON p.ID = pic.IDPRODUCT
			WHERE pc.ID IN ( ".$stringTemp." )
			AND p.isACTIVE = 0
			AND pic.POSITION = 1";
		return $this->getAdapter()->fetchAll($sql);
	}

	public function getChildsInfoByListProductId($idProduct) {
		$sql = "
			SELECT p.NOM NOM,p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.ID IDPRODUCT, pic.URL URL,p.isPROMO isPROMO, pc.DESIGNATION DESIGNATION, p.STOCK STOCK,
			pc.ID IDCHILD, pc.REFERENCE REFERENCE, pc.isDEVIS isDEVIS, pc.isPROMO isPROMOCHILD, pc.PRIX PRIX, p.DATEPROMO DATEPROMO,
			p.IDCATEGORY IDCATEGORY, p.IDBREND IDBREND, p.isSHOWBREND isSHOWBREND, pc.QUANTITYMIN QUANTITYMIN, pc.POIDS POIDS, pc.isFRANCODENIED isFRANCODENIED, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
			, pc.POINTFIDELITE  POINTFIDELITE 
            FROM productchild pc
			LEFT JOIN product p ON pc.IDPRODUCT = p.ID
			LEFT JOIN category c ON p.IDCATEGORY = c.ID
			LEFT JOIN picture pic ON p.ID = pic.IDPRODUCT
			WHERE p.ID = ".$idProduct;
		return $this->getAdapter()->fetchAll($sql);
	}
	
	public function getChildPriceByIdChild($idChild) {
		$sql = "
			SELECT pc.PRIX PRIX 
			FROM productchild pc 
			WHERE pc.ID = ".$idChild;
		return $this->getAdapter()->fetchRow($sql);
	}

}
?>PromoFront.php000060400000001370150715102030007351 0ustar00<?php
class PromoFront extends Zend_Db_Table
{
    protected $_name = 'promo_front';
    protected $_primary = 'ID';

    public function getListPromo() {
    	$listFrontSQL = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.PRIX PRIX,
				p.isPROMO isPROMO, pic.URL URL, sb.BREND BREND, pf.REFERENCE REFERENCE, p.IDCATEGORY IDCATEGORY
				FROM promo_front AS pf
				LEFT JOIN productchild pc ON pc.REFERENCE = pf.REFERENCE
				LEFT JOIN product p ON p.ID = pc.IDPRODUCT
				LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
				LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
				WHERE pic.POSITION = pc.IMAGEPROMO
				AND p.isACTIVE = 0
				ORDER BY pf.POSITION ASC";
		return $this->getAdapter()->fetchAll($listFrontSQL);
    }
}
?>Category2.php000060400000042203150715102030007103 0ustar00<?php
class Category2 extends Zend_Db_Table
{
	protected $_name = 'category2';
	protected $_primary = 'ID';

    public function updateTreeInLineAsPathOfChilds($idParent, $updateCurrent) { 
        
        $i = 0;
        if ($updateCurrent){
            $sqlCurrent = "SELECT c.ID ID, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS, c.IDPARENT IDPARENT, c.NAVNOM NAVNOM FROM category2 c WHERE c.ID = ".$idParent." ORDER BY c.NOM ASC ";
            $dataCurrent = $this->getAdapter()->fetchRow($sqlCurrent);  
            if ($dataCurrent) {
                $dataCurrent['NAVNOM_URLPARENTS'] = $this->getTreeInLineAsPathOf($idParent);
                $this->update($dataCurrent, 'ID = '.$idParent);
                $i++;
            }
        }
        
        $sql = "SELECT c.ID ID, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS, c.IDPARENT IDPARENT, c.NAVNOM NAVNOM FROM category2 c WHERE c.IDPARENT = ".$idParent." ORDER BY c.NOM ASC ";
        $cats =  $this->getAdapter()->fetchAll($sql);
        foreach($cats as $row)
        { 
            $row['NAVNOM_URLPARENTS'] = $this->getTreeInLineAsPathOf($row['ID']);
            $this->update($row, 'ID = '.$row['ID']);
            
            $i += $this->updateTreeInLineAsPathOfChilds($row['ID'], false);            
            $i++;
        }   
        return $i;
    }
	
	public function generateAllCategoriesMenu($idCat) {
		$dataResult = $this->computeCategoryChildToArray($idCat, 0);
		return $dataResult;
	}

	private function computeCategoryChildsOneArray($idParent, $result) {
		$dataChilds = $this->getCategoryByParent($idParent);

		$dataResult = array(
			'PARENT' => $idParent,
			'CHILDS' => $dataChilds
		);
		array_push($result, $dataResult);
		if (!empty($dataChilds) && sizeof($dataChilds) > 0) {
			foreach($dataChilds as $row) { 
				$result = $this->computeCategoryChildsOneArray($row['ID'], $result);
			}
		}
		return $result;
	}

	private function computeCategoryChildToArray($idParent, $level) {
		$dataChilds = $this->getCategoryByParent($idParent);  
		if (!empty($dataChilds) && sizeof($dataChilds) > 0) { 
			$dataReturn = array(); 
			foreach($dataChilds as $row) {                 
				$data = array(
					'CHILDS' => $this->computeCategoryChildToArray($row['ID'], $level + 1),
					'CATEGORIE' => $row,
					'LEVEL' => $level
				);
				array_push($dataReturn, $data);
			} 
			return $dataReturn;
		} else { return array(); }
	}

	private function getCategoryByParent($idParent) {
		$sql = "SELECT c.ID ID, c.NOM NOM, c.URL URL, c.NAVNOM NAVNOM,c.DESCRIPTION DESCRIPTION, c.isACTIVE isACTIVE, c.IDPARENT IDPARENT, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS FROM category2 c WHERE c.IDPARENT = ".$idParent." AND c.isACTIVE = 1";
		if ($idParent == 0) {
			$sql .= " ORDER BY c.ID ASC";
		} else {
			$sql .= " ORDER BY c.NOM ASC";
		} 
		return $this->getAdapter()->fetchAll($sql);
	}

	/**
     *
     * Getters
     *
     */
	public function getParentFirstOf($idCat) {
		$sql = "SELECT DISTINCT c0.ID ID, c0.NOM NOM, c0.IDPARENT IDPARENT , c0.NAVNOM NAVNOM
				FROM category2 AS c0
				LEFT JOIN category2 AS c1 ON c1.IDPARENT = c0.ID
				LEFT JOIN category2 AS c2 ON c2.IDPARENT = c1.ID
				LEFT JOIN category2 AS c3 ON c3.IDPARENT = c2.ID 
				LEFT JOIN category2 AS c4 ON c4.IDPARENT = c3.ID 
				LEFT JOIN category2 AS c5 ON c5.IDPARENT = c4.ID 
				LEFT JOIN category2 AS c6 ON c6.IDPARENT = c5.ID 
				LEFT JOIN category2 AS c7 ON c7.IDPARENT = c6.ID 
				LEFT JOIN category2 AS c8 ON c8.IDPARENT = c7.ID 
				LEFT JOIN category2 AS c9 ON c9.IDPARENT = c8.ID 
				LEFT JOIN category2 AS c10 ON c10.IDPARENT = c9.ID 
				WHERE ( c0.ID = ".$idCat."  
				OR c1.ID = ".$idCat." 
				OR c2.ID = ".$idCat." 
				OR c3.ID = ".$idCat." 
				OR c4.ID = ".$idCat." 
				OR c5.ID = ".$idCat." 
				OR c6.ID = ".$idCat." 
				OR c7.ID = ".$idCat." 
				OR c8.ID = ".$idCat." 
				OR c9.ID = ".$idCat." 
				OR c10.ID = ".$idCat." )
				ORDER BY c0.IDPARENT ASC 
				";
        
		return $this->getAdapter()->fetchRow($sql);
	}
    
    public function getTreeInLineAsPathOf($idCat) {
		$sql = "SELECT DISTINCT c0.ID ID, c0.NOM NOM, c0.IDPARENT IDPARENT , c0.NAVNOM NAVNOM, c0.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
				FROM category2 AS c0
				LEFT JOIN category2 AS c1 ON c1.IDPARENT = c0.ID
				LEFT JOIN category2 AS c2 ON c2.IDPARENT = c1.ID
				LEFT JOIN category2 AS c3 ON c3.IDPARENT = c2.ID 
				LEFT JOIN category2 AS c4 ON c4.IDPARENT = c3.ID 
				LEFT JOIN category2 AS c5 ON c5.IDPARENT = c4.ID 
				LEFT JOIN category2 AS c6 ON c6.IDPARENT = c5.ID 
				LEFT JOIN category2 AS c7 ON c7.IDPARENT = c6.ID 
				LEFT JOIN category2 AS c8 ON c8.IDPARENT = c7.ID 
				LEFT JOIN category2 AS c9 ON c9.IDPARENT = c8.ID 
				LEFT JOIN category2 AS c10 ON c10.IDPARENT = c9.ID 
				WHERE ( c0.ID = ".$idCat."  
				OR c1.ID = ".$idCat." 
				OR c2.ID = ".$idCat." 
				OR c3.ID = ".$idCat." 
				OR c4.ID = ".$idCat." 
				OR c5.ID = ".$idCat." 
				OR c6.ID = ".$idCat." 
				OR c7.ID = ".$idCat." 
				OR c8.ID = ".$idCat." 
				OR c9.ID = ".$idCat." 
				OR c10.ID = ".$idCat." )
				ORDER BY c0.IDPARENT ASC 
				";      
		$mylinks = array();
		$links = $this->getAdapter()->fetchAll($sql);

        $result = $links[0]['NAVNOM'];
        
        if ($links[0]['IDPARENT'] == 0) {
            $result = $links[0]['NAVNOM_URLPARENTS'];
        }
        
		$mylinks[0]['ID'] = $links[0]['ID'];
		$j=0;
		for ($i=1;$i<sizeof($links);$i++) {
			foreach ($links as $link) {
				if($link['IDPARENT'] == $mylinks[$j]['ID'] && $link['ID'] != $idCat) {
					$mylinks[$i]['ID'] = $link['ID'];
					$result .= "/".$link['NAVNOM'];
					$j++;
					break;
				}
			}
		}
		return $result;
	}
    
	public function getTreeInLineOf($idCat) {
		$sql = "SELECT DISTINCT c0.ID ID, c0.NOM NOM, c0.IDPARENT IDPARENT , c0.NAVNOM NAVNOM, c0.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
				FROM category2 AS c0
				LEFT JOIN category2 AS c1 ON c1.IDPARENT = c0.ID
				LEFT JOIN category2 AS c2 ON c2.IDPARENT = c1.ID
				LEFT JOIN category2 AS c3 ON c3.IDPARENT = c2.ID 
				LEFT JOIN category2 AS c4 ON c4.IDPARENT = c3.ID 
				LEFT JOIN category2 AS c5 ON c5.IDPARENT = c4.ID 
				LEFT JOIN category2 AS c6 ON c6.IDPARENT = c5.ID 
				LEFT JOIN category2 AS c7 ON c7.IDPARENT = c6.ID 
				LEFT JOIN category2 AS c8 ON c8.IDPARENT = c7.ID 
				LEFT JOIN category2 AS c9 ON c9.IDPARENT = c8.ID 
				LEFT JOIN category2 AS c10 ON c10.IDPARENT = c9.ID 
				WHERE ( c0.ID = ".$idCat."  
				OR c1.ID = ".$idCat." 
				OR c2.ID = ".$idCat." 
				OR c3.ID = ".$idCat." 
				OR c4.ID = ".$idCat." 
				OR c5.ID = ".$idCat." 
				OR c6.ID = ".$idCat." 
				OR c7.ID = ".$idCat." 
				OR c8.ID = ".$idCat." 
				OR c9.ID = ".$idCat." 
				OR c10.ID = ".$idCat." )
				ORDER BY c0.IDPARENT ASC 
				";
		$mylinks = array();
		$links = $this->getAdapter()->fetchAll($sql);

		$mylinks[0]['ID'] = $links[0]['ID'];
		$mylinks[0]['NOM'] = $links[0]['NOM'];
		$mylinks[0]['IDPARENT'] = $links[0]['IDPARENT'];
		$mylinks[0]['NAVNOM'] = $links[0]['NAVNOM'];
		$mylinks[0]['NAVNOM_URLPARENTS'] = $links[0]['NAVNOM_URLPARENTS'];
		$j=0;
		for ($i=1;$i<sizeof($links);$i++) {
			foreach ($links as $link) {
				if($link['IDPARENT'] == $mylinks[$j]['ID']) {
					$mylinks[$i]['ID'] = $link['ID'];
					$mylinks[$i]['NOM'] = $link['NOM'];
					$mylinks[$i]['IDPARENT'] = $link['IDPARENT'];
					$mylinks[$i]['NAVNOM'] = $link['NAVNOM'];
					$mylinks[$i]['NAVNOM_URLPARENTS'] = $link['NAVNOM_URLPARENTS'];
					$j++;
					break;
				}
			}
		}
		return $mylinks;
	}
	public function getTreeCatsOfParent($idCat) {
        
		$sql = "SELECT c0.NOM NOM0, c1.NOM NOM1,
						c0.URL URL0, c1.URL URL1,
						c0.ID ID0, c1.ID ID1,
						c0.isACTIVE isACTIVE0, c1.isACTIVE isACTIVE1,
						c0.IDPARENT IDPARENT0, c1.IDPARENT IDPARENT1,
						c0.NAVNOM NAVNOM0, c1.NAVNOM NAVNOM1,
						c0.DESCRIPTION DESCRIPTION0, c1.DESCRIPTION DESCRIPTION1,
						c0.NAVNOM_URLPARENTS NAVNOM_URLPARENTS0, c1.NAVNOM_URLPARENTS NAVNOM_URLPARENTS1
				FROM category2 AS c0
				LEFT JOIN category2 AS c1 ON c1.IDPARENT = c0.ID
				WHERE c0.IDPARENT = ".$idCat."
				ORDER BY c0.ID,c1.ID ASC;
				";
		$results = $this->getAdapter()->fetchAll($sql);
        
		$listCat = array();
		$i = 0;
		$j = 0;
		$idParent = 0;
		$isNew = true;
		$isFirst = true;
		foreach($results as $row) {
			if ($row['ID0'] != $idParent) {
				$idParent = $row['ID0'];
				$isNew = true;
				$i++;
				$j = 0 ;
				if ($isFirst) {$i = 0; $isFirst = false;}
			} else {
				$isNew = false;
			}
			if ($isNew) {
				if ($row['isACTIVE0'] == true) {
					$listCat[$i]['NOM'] = $row['NOM0'];
					$listCat[$i]['ID'] = $row['ID0'];
					$listCat[$i]['URL'] = $row['URL0'];
					$listCat[$i]['NAVNOM'] = $row['NAVNOM0'];
					$listCat[$i]['DESCRIPTION'] = $row['DESCRIPTION0'];
					$listCat[$i]['isACTIVE'] = $row['isACTIVE0'];
					$listCat[$i]['NAVNOM_URLPARENTS'] = $row['NAVNOM_URLPARENTS0'];
					$listCat[$i]['SUBS'] = array();
				}
			}

			if ($row['isACTIVE1'] == true) {
				$listCat[$i]['SUBS'][$j]['NOM'] = $row['NOM1'];
				$listCat[$i]['SUBS'][$j]['ID'] = $row['ID1'];
				$listCat[$i]['SUBS'][$j]['URL'] = $row['URL1'];
				$listCat[$i]['SUBS'][$j]['DESCRIPTION'] = $row['DESCRIPTION1'];
				$listCat[$i]['SUBS'][$j]['NAVNOM'] = $row['NAVNOM1'];
				$listCat[$i]['SUBS'][$j]['isACTIVE'] = $row['isACTIVE1'];
				$listCat[$i]['SUBS'][$j]['NAVNOM_URLPARENTS'] = $row['NAVNOM_URLPARENTS1'];
				$j++;
			}
		}
		return $listCat;
        
	}
	public function getTreeCatsOf($idCat) {
		$sql = "SELECT c0.NOM NOM0, c1.NOM NOM1,
						c0.NAVTITRENOM NAVTITRENOM0, c1.NAVTITRENOM NAVTITRENOM1,
						c0.NAVDESCRIPTION NAVDESC0, c1.NAVDESCRIPTION NAVDESC1,
						c0.URL URL0, c1.URL URL1,
						c0.ID ID0, c1.ID ID1,
						c0.IDPARENT IDPARENT0, c1.IDPARENT IDPARENT1,
						c0.NAVNOM NAVNOM0, c1.NAVNOM NAVNOM1,
						c0.DESCRIPTION DESCRIPTION0, c1.DESCRIPTION DESCRIPTION1,
						c0.KEYWORDS KEYWORDS0, c1.KEYWORDS KEYWORDS1,
						c0.CHOICEURL CHOICEURL0, c1.CHOICEURL CHOICEURL1,
						c0.CHOICEDOC CHOICEDOC0, c1.CHOICEDOC CHOICEDOC1,
						c0.isACTIVE isACTIVE0, c1.isACTIVE isACTIVE1,
						c0.NAVNOM_URLPARENTS NAVNOM_URLPARENTS0, c1.NAVNOM_URLPARENTS NAVNOM_URLPARENTS1,
						(Select count(1) from product as p where p.idcategory = c1.id and p.isactive = 0) NBPRODUCT
				FROM category2 AS c0
				LEFT JOIN category2 AS c1 ON c1.IDPARENT = c0.ID
				WHERE c0.ID = ".$idCat."  
				ORDER BY c0.NOM,c1.NOM ASC;
				";
		$results = $this->getAdapter()->fetchAll($sql);
		$listCat = array();
		$j = 0;
		$isNew = true;
		foreach($results as $row) {
			if ($isNew == true) {
				$listCat['NOM'] = $row['NOM0'];
				$listCat['NAVTITRENOM'] = $row['NAVTITRENOM0'];
				$listCat['NAVDESCRIPTION'] = $row['NAVDESC0'];
				$listCat['ID'] = $row['ID0'];
				$listCat['URL'] = $row['URL0'];
				$listCat['NAVNOM'] = $row['NAVNOM0'];
				$listCat['KEYWORDS'] = $row['KEYWORDS0'];
				$listCat['DESCRIPTION'] = $row['DESCRIPTION0'];
				$listCat['CHOICEURL'] = $row['CHOICEURL0'];
				$listCat['CHOICEDOC'] = $row['CHOICEDOC0'];
				$listCat['isACTIVE'] = $row['isACTIVE0'];
				$listCat['NAVNOM_URLPARENTS'] = $row['NAVNOM_URLPARENTS0'];
				$listCat['IDPARENT'] = $row['IDPARENT0'];
				$listCat['SUBS'] = array();
				if (!empty($row['isACTIVE1']) && $row['isACTIVE1'] == true) {
					if (!empty($row['NOM1'])) {
						$listCat['SUBS'][$j]['NOM'] = $row['NOM1'];
						$listCat['SUBS'][$j]['NAVTITRENOM'] = $row['NAVTITRENOM1'];
						$listCat['SUBS'][$j]['NAVDESCRIPTION'] = $row['NAVDESC1'];
						$listCat['SUBS'][$j]['ID'] = $row['ID1'];
						$listCat['SUBS'][$j]['URL'] = $row['URL1'];
						$listCat['SUBS'][$j]['DESCRIPTION'] = $row['DESCRIPTION1'];
						$listCat['SUBS'][$j]['KEYWORDS'] = $row['KEYWORDS1'];
						$listCat['SUBS'][$j]['NAVNOM'] = $row['NAVNOM1'];
						$listCat['SUBS'][$j]['CHOICEURL'] = $row['CHOICEURL1'];
						$listCat['SUBS'][$j]['CHOICEDOC'] = $row['CHOICEDOC1'];
						$listCat['SUBS'][$j]['isACTIVE'] = $row['isACTIVE1'];
						$listCat['SUBS'][$j]['NAVNOM_URLPARENTS'] = $row['NAVNOM_URLPARENTS1'];
						$listCat['SUBS'][$j]['NBPRODUCT'] = $row['NBPRODUCT'];
						$listCat['SUBS'][$j]['IDPARENT'] = $row['IDPARENT1'];
						$j++;
					}
				}
				$isNew = false;
			} else {
				if (!empty($row['isACTIVE1']) && $row['isACTIVE1'] == true) {
					$listCat['SUBS'][$j]['NOM'] = $row['NOM1'];
					$listCat['SUBS'][$j]['NAVTITRENOM'] = $row['NAVTITRENOM1'];
					$listCat['SUBS'][$j]['NAVDESCRIPTION'] = $row['NAVDESC1'];
					$listCat['SUBS'][$j]['ID'] = $row['ID1'];
					$listCat['SUBS'][$j]['URL'] = $row['URL1'];
					$listCat['SUBS'][$j]['DESCRIPTION'] = $row['DESCRIPTION1'];
					$listCat['SUBS'][$j]['KEYWORDS'] = $row['KEYWORDS1'];
					$listCat['SUBS'][$j]['NAVNOM'] = $row['NAVNOM1'];
					$listCat['SUBS'][$j]['CHOICEURL'] = $row['CHOICEURL1'];
					$listCat['SUBS'][$j]['CHOICEDOC'] = $row['CHOICEDOC1'];
					$listCat['SUBS'][$j]['isACTIVE'] = $row['isACTIVE1'];
					$listCat['SUBS'][$j]['NAVNOM_URLPARENTS'] = $row['NAVNOM_URLPARENTS1'];
					$listCat['SUBS'][$j]['NBPRODUCT'] = $row['NBPRODUCT'];
					$listCat['SUBS'][$j]['IDPARENT'] = $row['IDPARENT1'];
					$j++;
				}
			}

		}
		return $listCat;
	}

	public function getAllCategoriesByID ($idParent) {
		$sql = "
		SELECT c0.NOM NOM0, c1.NOM NOM1, c2.NOM NOM2, c3.NOM NOM3, c4.NOM NOM4, c5.NOM NOM5, 
				c6.NOM NOM6, c7.NOM NOM7, c8.NOM NOM8, c9.NOM NOM9, c10.NOM NOM10,
				c0.isACTIVE isACTIVE0, c1.isACTIVE isACTIVE1, c2.isACTIVE isACTIVE2, c3.isACTIVE isACTIVE3, c4.isACTIVE isACTIVE4, c5.isACTIVE isACTIVE5, 
				c6.isACTIVE isACTIVE6, c7.isACTIVE isACTIVE7, c8.isACTIVE isACTIVE8, c9.isACTIVE isACTIVE9, c10.isACTIVE isACTIVE10,
				c0.URL URL0, c1.URL URL1, c2.URL URL2, c3.URL URL3, c4.URL URL4, c5.URL URL5, 
				c6.URL URL6, c7.URL URL7, c8.URL URL8, c9.URL URL9, c10.URL URL10,
				c0.ID ID0, c1.ID ID1, c2.ID ID2, c3.ID ID3, c4.ID ID4, c5.ID ID5, 
				c6.ID ID6, c7.ID ID7, c8.ID ID8, c9.ID ID9, c10.ID ID10,
				c0.IDPARENT IDPARENT0, c1.IDPARENT IDPARENT1, c2.IDPARENT IDPARENT2, c3.IDPARENT IDPARENT3, c4.IDPARENT IDPARENT4, c5.IDPARENT IDPARENT5, 
				c6.IDPARENT IDPARENT6, c7.IDPARENT IDPARENT7, c8.IDPARENT IDPARENT8, c9.IDPARENT IDPARENT9, c10.IDPARENT IDPARENT10
		FROM category2 AS c0
		LEFT JOIN category2 AS c1 ON c1.IDPARENT = c0.ID
		LEFT JOIN category2 AS c2 ON c2.IDPARENT = c1.ID
		LEFT JOIN category2 AS c3 ON c3.IDPARENT = c2.ID 
		LEFT JOIN category2 AS c4 ON c4.IDPARENT = c3.ID 
		LEFT JOIN category2 AS c5 ON c5.IDPARENT = c4.ID 
		LEFT JOIN category2 AS c6 ON c6.IDPARENT = c5.ID 
		LEFT JOIN category2 AS c7 ON c7.IDPARENT = c6.ID 
		LEFT JOIN category2 AS c8 ON c8.IDPARENT = c7.ID 
		LEFT JOIN category2 AS c9 ON c9.IDPARENT = c8.ID 
		LEFT JOIN category2 AS c10 ON c10.IDPARENT = c9.ID 
		WHERE c0.IDPARENT = ".$idParent."
		ORDER BY c0.ID,c1.NOM,c2.NOM,c3.NOM,c4.NOM,c5.NOM,c6.NOM,c7.NOM,c8.NOM,c9.NOM,c10.NOM ASC;
    	"; 
		return $this->getAdapter()->fetchAll($sql);
	}
	
    public function getAllCategoriesIDByID ($idParent) {
		$sql = "
		SELECT c0.ID ID0, c1.ID ID1, c2.ID ID2, c3.ID ID3, c4.ID ID4, c5.ID ID5, 
				c6.ID ID6, c7.ID ID7, c8.ID ID8, c9.ID ID9, c10.ID ID10
		FROM category2 AS c0
		LEFT JOIN category2 AS c1 ON c1.IDPARENT = c0.ID
		LEFT JOIN category2 AS c2 ON c2.IDPARENT = c1.ID
		LEFT JOIN category2 AS c3 ON c3.IDPARENT = c2.ID 
		LEFT JOIN category2 AS c4 ON c4.IDPARENT = c3.ID 
		LEFT JOIN category2 AS c5 ON c5.IDPARENT = c4.ID 
		LEFT JOIN category2 AS c6 ON c6.IDPARENT = c5.ID 
		LEFT JOIN category2 AS c7 ON c7.IDPARENT = c6.ID 
		LEFT JOIN category2 AS c8 ON c8.IDPARENT = c7.ID 
		LEFT JOIN category2 AS c9 ON c9.IDPARENT = c8.ID 
		LEFT JOIN category2 AS c10 ON c10.IDPARENT = c9.ID 
		WHERE c0.IDPARENT = ".$idParent;   
		return $this->getAdapter()->fetchAll($sql);
	}
    
	public function getIdCatFromProductId($idProd) {
		$sql = "
		SELECT p.IDCATEGORY ID
		FROM product AS p
		WHERE p.ID = ".$idProd;
		$data = $this->getAdapter()->fetchRow($sql);
		return $data['ID'];
	}
	
	public function getAllSubsIDByIDToString($idCat) {
        if ($idCat != null && (int)$idCat > 0) {
		    $listCat = $this->getAllCategoriesIDByID($idCat);
		    $listTemp = array();
		    $value = 'ID';
		    $listCatString = $idCat;
		
		    //list of sub cats
		    foreach ($listCat as $row) {
			    for ($level=0 ; $level<11; $level++) {
				    if ((!isset($listTemp[$value.$level]) || $listTemp[$value.$level] != $row[$value.$level]) && $row[$value.$level] != null) {
					    $listTemp[$value.$level] = $row[$value.$level];
					    if ($listCatString !="") {
						    $listCatString .= ' ,'.$row[$value.$level];
					    } else {
						    $listCatString = $row[$value.$level];
					    }
				    } 
			    }
		    }
		    return $listCatString;
        }
        return "";
	}


	public function getAllCategoriesProperties() {
		$sql = "SELECT c.ID ID, c.NOM NOM, c.URL URL, c.NAVNOM NAVNOM, c.isACTIVE isACTIVE FROM category2 c ORDER BY c.NOM ASC ";
		$cats = $this->getAdapter()->fetchAll($sql);
		$data = array();
		foreach($cats as $row)
		{
			$data[$row['ID']] = array(
				'ID' => $row['ID'],
				'NOM' => $row['NOM'],
				'URL' => $row['URL'],
				'NAVNOM' => $row['NAVNOM'],
				'isACTIVE' => $row['isACTIVE']
			);
		}
		return $data;
	}

	private function getCategoryById($idCat) {
		$sql = "SELECT c.ID ID, c.NOM NOM, c.URL URL, c.NAVNOM NAVNOM FROM category2 c WHERE c.ID = ".$idCat." ORDER BY c.NOM ASC";
		$cats = $this->getAdapter()->fetchAll($sql);
		$data = array();
		foreach ($cats AS $row) {
			$data[$row['ID']] = $row['NOM'];
		}
		return $data;
	} 
}
?>AnnonceLeft.php000060400000001071150715102030007436 0ustar00<?php
class AnnonceLeft extends Zend_Db_Table
{
    protected $_name = 'annonce_left';
    protected $_primary = 'ID';

    public function getAnnonces() {
    	return $this->select()->where('isSHOW = 0')->order('NOM ASC')->query()->fetchAll();
	}
	

    public function getAllAnnonces() {
    	return $this->select()->order('NOM ASC')->query()->fetchAll();
	}
	
 	public function getAnnoncesByShow($idCat) {
 		return $this->select()->where('isSHOW = 0')->where("ID_CATS LIKE '%:".$idCat.":%' OR ID_CATS LIKE '%:0:%' ")->order('NOM ASC')->query()->fetchAll();
 	}
}
?>Picture.php000060400000000432150715102030006655 0ustar00<?php
class Picture extends Zend_Db_Table
{
    protected $_name = 'picture';
    protected $_primary = 'ID';

	public function getAllByIdProduct($id) {
    	return $this->select()->where('IDPRODUCT = '.$id)->order('POSITION ASC')->query()->fetchAll();
   }
    
    
    
    
}
?>PromoUser.php000060400000006536150715102030007210 0ustar00<?php
class PromoUser extends Zend_Db_Table
{
    protected $_name = 'promo_user';
    protected $_primary = 'ID';
    
 	/*
	 * Remise selon la marque et l'user
	 */
    public function getRemiseByMarque($idbrend, $iduser) {  try {
   		return $this->select()->where("USERIDBREND = ?", $iduser)->where("USERBRENDID = ?", $idbrend)->query()->fetch();
   		} catch (Zend_Exception $e) { return array(); }
    } 
    public function getRemiseByMarqueFull($iduser) {  try {
    	$sql = "SELECT u.NOM NOM,u.ID IDUSER, u.PRENOM PRENOM, 
				pu.ID ID, pu.REMISEEURO REMISEEURO, pu.REMISEPOUR REMISEPOUR, pu.USERIDBREND USERIDBREND, pu.USERBRENDID USERBRENDID, sb.BREND BREND, sb.IDSUPPLIER IDSUPPLIER
				FROM promo_user AS pu
				LEFT JOIN user AS u ON u.ID = pu.USERIDBREND
				LEFT JOIN supplier_brend AS sb ON sb.ID = pu.USERBRENDID
				WHERE pu.USERIDBREND IS NOT NULL
				AND pu.USERBRENDID IS NOT NULL
				AND u.ID = ".$iduser."
				ORDER BY u.NOM, u.PRENOM ASC";
		return $this->getAdapter()->fetchAll($sql); 
   		} catch (Zend_Exception $e) { return array(); }
    } 
    
 	/*
	 * Remise selon la marque et le code intern
	 */
    public function getRemiseByCodeInternMarque($idbrend, $codeintern) { try {
    	return $this->select()->where("CINTERNIDBREND = ?", $codeintern)->where("CINTERNBRENDID = ?", $idbrend)->query()->fetch();
   		} catch (Zend_Exception $e) { return array(); }
    } 
 	public function getRemiseByCodeInternMarqueFull($codeintern) { try {  
    	$sql = "SELECT pu.ID ID, pu.REMISEEURO REMISEEURO, pu.REMISEPOUR REMISEPOUR, uci.LABEL LABELINTERN, uci.CODE CODEINTERN,
			pu.CINTERNIDBREND CINTERNIDBREND, sb.BREND BREND, pu.CINTERNBRENDID CINTERNBRENDID, sb.IDSUPPLIER IDSUPPLIER, u.ID IDUSER
				FROM promo_user AS pu
				LEFT JOIN user_cintern AS uci ON uci.ID = pu.CINTERNIDBREND
				LEFT JOIN user AS u ON u.CODEINTERN = pu.CINTERNIDBREND
				LEFT JOIN supplier_brend AS sb ON sb.ID = pu.CINTERNBRENDID
				WHERE pu.CINTERNIDBREND IS NOT NULL 
				AND pu.CINTERNBRENDID IS NOT NULL 
				AND pu.CINTERNIDBREND = '".$codeintern."' 
				ORDER BY uci.CODE,sb.BREND ASC"; 
		return $this->getAdapter()->fetchAll($sql);
   		} catch (Zend_Exception $e) { return array(); }
 	}
 	/*
	 * Remise selon la date d'inscription
	 */
    public function getRemiseByDateInscription() { try {  
    	return $this->select()->where('isDATEINSCR IS NOT NULL AND isDATEINSCR = 0')->query()->fetch();
   		} catch (Zend_Exception $e) { return array(); }
    }

 	/*
	 * Remise selon l'id de l'user
	 */
    public function getRemiseByUserID($id) { try {  
    	return $this->select()->where('IDUSER IS NOT NULL AND IDUSER = ?', $id)->query()->fetch();
   		} catch (Zend_Exception $e) { return array(); }
    }
    public function getRemiseByUserIDFull($id) { try {
    	$sql = "SELECT u.NOM NOM,u.ID IDUSER, u.PRENOM PRENOM, 
				pu.ID ID, pu.REMISEEURO REMISEEURO, pu.REMISEPOUR REMISEPOUR
				FROM promo_user AS pu
				LEFT JOIN user AS u ON pu.IDUSER = u.ID
				WHERE pu.IDUSER IS NOT NULL
				AND u.ID = ".$id;  
    	return $this->getAdapter()->fetchRow($sql);
   		} catch (Zend_Exception $e) { return array(); }
    }
 	/*
	 * Remise pour la premiere commande
	 */
    public function getRemiseByIsFirstCommand() { try {  
    	return $this->select()->where('isFIRSTCMD IS NOT NULL AND isFIRSTCMD = 0')->query()->fetch();
   		} catch (Zend_Exception $e) { return array(); }
    }

    
    
    
}
?>UserNewsletter.php000060400000000202150715102030010230 0ustar00<?php
class UserNewsletter extends Zend_Db_Table
{
    protected $_name = 'user_newsletter';
    protected $_primary = 'ID';

}
?>FooterContent.php000060400000000200150715102030010024 0ustar00<?php
class FooterContent extends Zend_Db_Table
{
    protected $_name = 'footer_content';
    protected $_primary = 'ID';

}
?>ParamIp.php000060400000000172150715102030006574 0ustar00<?php
class ParamIp extends Zend_Db_Table
{
    protected $_name = 'admin_param_ip';
    protected $_primary = 'ID';

}
?>Admin.php000060400000000164150715102030006274 0ustar00<?php
class Admin extends Zend_Db_Table
{
    protected $_name = 'user_admin';
    protected $_primary = 'ID';

}
?>ProductOption.php000060400000000661150715102030010057 0ustar00<?php
class ProductOption extends Zend_Db_Table
{
    protected $_name = 'product_option';
    protected $_primary = 'ID';

	public function getOptionsByIdProduct($id) {
    	$select = "
						SELECT po.ID ID, o.NOM NOMOPTION, po.IDOPTION IDOPTION
						FROM product_option AS po
						LEFT JOIN `option` AS o ON o.ID = po.IDOPTION
						WHERE po.IDPRODUCT = ".$id;
    	return $this->getAdapter()->fetchAll($select);
    }
    
}
?>ProductAccessoire.php000060400000007521150715102030010671 0ustar00<?php
class ProductAccessoire extends Zend_Db_Table
{
    protected $_name = 'product_acc';
    protected $_primary = 'ID';
    
    
    public function getAccessoiresByProductIDOld($id, $triSql) {
    	$results = array();
    	try { 
    		$select = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM PRODNAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
							p.isPROMO isPROMO, pic.URL URL, sb.BREND BREND, sb.URL BRENDURL, COUNT(pc.REFERENCE) NBREFERENCE, 
							c.NAVNOM CATNAVNOM, p.isSHOWBREND isSHOWBREND, p.KEYWORDS KEYWORDS_PROD, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS,
                            c.NOM CATNOM, p.BOOSTED_BESTSELLER BOOSTED_BESTSELLER
							FROM product_acc pa
							LEFT JOIN product AS p ON pa.IDACCESSOIRE = p.ID 
							LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
							LEFT JOIN category c ON c.ID = p.IDCATEGORY 
							LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
							LEFT JOIN productchild pc ON pc.IDPRODUCT = p.ID 
							WHERE pa.IDPRODUCT = ".$id." 
							AND p.isACTIVE = 0
							AND pic.POSITION = 1
							GROUP BY ID
							ORDER BY ".$triSql;
    		
			$results = $this->getAdapter()->fetchAll($select);
    	} catch (Zend_Exception $e) { }
    	return $results;
    }
    
	public function getAccessoiresByProductID($id, $triSql) {
    	$results = array();
    	try {  
    		$select = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM PRODNAVNOM,pic.URL URL,
    						pc.REFERENCE REFERENCE, pc.DESIGNATION DESIGNATION, 
    						pa.ID IDACCESSOIRE , c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
                            , p.BOOSTED_BESTSELLER BOOSTED_BESTSELLER
							FROM product_acc pa
							LEFT JOIN productchild pc ON pa.REFACCESSOIRE = pc.REFERENCE
							LEFT JOIN product AS p ON pc.IDPRODUCT = p.ID 
							LEFT JOIN category c ON c.ID = p.IDCATEGORY 
							LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
							WHERE pa.IDPRODUCT = ".$id."  
							AND pic.POSITION = 1
							ORDER BY ".$triSql;
    		
			$results = $this->getAdapter()->fetchAll($select);
    	} catch (Zend_Exception $e) { }
    	return $results;
    } 
    
	public function getAccessoiresOptionsByProductID($id) {
    	$results = array();
    	try {  
    		// meme select que ProductChild->getProductChildsByIdProduct sauf que l'on recupere les accessoires
    		$select = "SELECT pc.ID ID ,pc.REFERENCE REFERENCE,pc.DESIGNATION DESIGNATION,pc.PRIX PRIX, pc.isPROMO isPROMO ,
					pco.VALUE OPTIONVALUE, pco.IDOPTION OPTIONID, pc.IMAGEPROMO IMAGEPROMO,pc.isDEVIS isDEVIS, pc.QUANTITYMIN QUANTITYMIN
					, p.NAVNOM PRODUCTNAVNOM, p.NOM PRODUCTNOM, p.ID PRODUCTID, p.isQTEPRIXACTIVE isQTEPRIXACTIVE, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
                    , p.BOOSTED_BESTSELLER BOOSTED_BESTSELLER
					FROM product_acc pa
					LEFT JOIN productchild AS pc ON pa.REFACCESSOIRE = pc.REFERENCE
					LEFT JOIN productchild_option AS pco ON pc.ID = pco.IDPRODUCTCHILD
					LEFT JOIN product AS p ON pc.IDPRODUCT = p.ID
					LEFT JOIN category c ON c.ID = p.IDCATEGORY 
					WHERE pa.IDPRODUCT = ".$id;  
			$results = $this->getAdapter()->fetchAll($select);
    	} catch (Zend_Exception $e) { } 
    	return $results;
    } 
    
    
    public function insertAccessoire($idproduct, $refaccessoire) {
    	try {
    		$select = " 
				SELECT COUNT(pa.ID) NBR
				FROM product_acc pa 
				WHERE pa.IDPRODUCT = ".$idproduct."
				AND pa.REFACCESSOIRE LIKE '".$refaccessoire."'"; 
			 
    		$result = $this->getAdapter()->fetchRow($select);
    		
    		if ($result['NBR'] == 0) { 
	    		$data = array (
	    			'IDPRODUCT' => $idproduct,
	    			'REFACCESSOIRE' => $refaccessoire
	    		);
    			$this->insert($data);
    			return true;
    		} 
    	} catch (Zend_Exception $e) { }
    	return false;
    }

    public function deleteAccessoire($idaccessoire) {
    	try {  
    		$this->delete("ID = ".$idaccessoire); 
    	} catch (Zend_Exception $e) { }
    }
    
 
}
?>ProductChildQte.php000060400000005763150715102030010314 0ustar00<?php
class ProductChildQte extends Zend_Db_Table
{
	protected $_name = 'productchild_qte';
	protected $_primary = 'ID';

	public function getCurrentLowestPrice($id, $price) { 
		try {
			$select = "SELECT MIN(pcq.PRIX) PRIX			 
					FROM productchild_qte AS pcq
					LEFT JOIN productchild AS pc ON pcq.IDPRODUCTCHILD = pc.ID
					LEFT JOIN product AS p ON pc.IDPRODUCT = p.ID 
					WHERE pcq.IDPRODUCTCHILD = ".$id."
					AND p.isQTEPRIXACTIVE = ".true;
			$result = $this->getAdapter()->fetchRow($select); 
			if (isset($result) && !empty($result) && $result['PRIX'] > 0) { return $result['PRIX']; }
		} catch (Zend_Exception $e) { } 
   		return $price;
	}
	
	public function getCurrentPrice($id, $qte, $price) { 
		try {
			$select = "SELECT pcq.PRIX PRIX			 
					FROM productchild_qte AS pcq
					LEFT JOIN productchild AS pc ON pcq.IDPRODUCTCHILD = pc.ID
					LEFT JOIN product AS p ON pc.IDPRODUCT = p.ID 
					WHERE pcq.IDPRODUCTCHILD = ".$id."
					AND pcq.MIN <= ".$qte."
					AND pcq.MAX >= ".$qte."
					AND p.isQTEPRIXACTIVE = ".true;
			$result = $this->getAdapter()->fetchRow($select); 
			if (isset($result) && !empty($result)) { return $result['PRIX']; }
		} catch (Zend_Exception $e) { } 
   		return $price;
	}
	
	public function getQteByItem($id) {
		$select = "SELECT COUNT(pcq.ID) NBR				
					FROM productchild_qte AS pcq 
					WHERE pcq.IDPRODUCTCHILD = ".$id;
		$result = $this->getAdapter()->fetchRow($select); 
		return $result['NBR'];
	}
	
	public function getAllActiveByItem($id) { 
		$select = "SELECT pc.REFERENCE REFERENCE,pc.DESIGNATION DESIGNATION,
					pcq.MIN MIN, pcq.MAX MAX, pcq.ID ID, pcq.PRIX PRIX					
					FROM productchild_qte AS pcq
					LEFT JOIN productchild AS pc ON pcq.IDPRODUCTCHILD = pc.ID
					LEFT JOIN product AS p ON pc.IDPRODUCT = p.ID 
					WHERE pcq.IDPRODUCTCHILD = ".$id." 
					AND p.isQTEPRIXACTIVE = ".true." 
					ORDER BY REFERENCE ASC, MIN ASC ";  
		return $this->getAdapter()->fetchAll($select);
	}  

	public function isPrixDegressifByProductID($id) {
		$select = "SELECT pc.REFERENCE REFERENCE,pc.DESIGNATION DESIGNATION,
					pcq.MIN MIN, pcq.MAX MAX, pcq.ID ID, pcq.PRIX PRIX,
					p.isQTEPRIXACTIVE isQTEPRIXACTIVE 				
					FROM productchild_qte AS pcq
					LEFT JOIN productchild AS pc ON pcq.IDPRODUCTCHILD = pc.ID
					LEFT JOIN product AS p ON pc.IDPRODUCT = p.ID
					WHERE p.ID = ".$id."  
					AND p.isQTEPRIXACTIVE = ".true." 
					ORDER BY REFERENCE ASC, MIN ASC ";  
		$result = $this->getAdapter()->fetchAll($select);
		if (!empty($result)) { return true; }
		return false;
	}
	
	public function getAllByProduct($id) {
		$select = "SELECT pc.REFERENCE REFERENCE,pc.DESIGNATION DESIGNATION,
					pcq.MIN MIN, pcq.MAX MAX, pcq.ID ID, pcq.PRIX PRIX,
					p.isQTEPRIXACTIVE isQTEPRIXACTIVE 				
					FROM productchild_qte AS pcq
					LEFT JOIN productchild AS pc ON pcq.IDPRODUCTCHILD = pc.ID
					LEFT JOIN product AS p ON pc.IDPRODUCT = p.ID
					WHERE p.ID = ".$id."  
					ORDER BY REFERENCE ASC, MIN ASC ";  
		return $this->getAdapter()->fetchAll($select);
	}
 
}
	 
?>LogDefault.php000060400000000172150715102030007271 0ustar00<?php
class LogDefault extends Zend_Db_Table
{
    protected $_name = 'log_default';
    protected $_primary = 'ID';

}
?>Option.php000060400000000161150715102030006511 0ustar00<?php
class Option extends Zend_Db_Table
{
    protected $_name = 'option';
    protected $_primary = 'ID';

}
?>utils/ItemCaddyType.php000060400000007122150715102030011112 0ustar00<?php
class ItemCaddyType {
	var $id;
	var $qte;

	var $idProduit;
	var $idChild;
	var $idBrend;
	var $nom;
	var $descshort;
	var $navnom;
	var $navnom_urlparents;
	var $url;
	var $designation;
	var $stock = 1;
	var $isAccessoire = 'N';
    var $selectedOption = ""; 

	var $remise_euro = 0;
	var $remise_pour = 0;
	var $isActif;
	var $reference;
	var $idcategory;
	var $promo_date; 

	var $isDevis;
	var $prix;
	var $qte_min;
	
	
	var $isPromoCaddyType = false;

	function ItemCaddyType() { }

	function getItemInfo($id, $qte, $selectedOption) {
		$userCaddyType = new UserCaddyType();
		$result = $userCaddyType->getArticleByCaddyId($id);
			
		$this->id = $id;
		$this->idChild = $result['IDCHILD'];
		$this->idBrend = $result['IDBREND'];
		$this->qte = $qte;
		$this->idProduit = $result['IDPRODUCT'];
		$this->nom = $result['NOM'];
		$this->descshort = $result['DESCSHORT'];
		$this->navnom = $result['NAVNOM'];
		$this->url = $result['URL'];
		$this->designation = $result['DESIGNATION'];
		$this->stock = $result['STOCK'];

		$this->remise_euro = $result['REMISEEURO'];
		$this->remise_pour = $result['REMISEPOUR'];
		$this->isActif = $result['isCADDYTYPE_ACTIF'];

		$this->reference = $result['REFERENCE'];
		$this->idcategory = $result['IDCATEGORY'];
		$this->promo_date = $result['DATEPROMO'];
		
		$this->isDevis = $result['isDEVIS'];
		$this->prix = $result['PRIX'];
		$this->qte_min = $result['QUANTITYMIN']; 
		$this->selectedOption = $selectedOption;
	}

	public function setLineInfo($result, $qte) {
		$this->id = $result['CADDYTYPEID'];
		$this->idChild = $result['IDCHILD'];
		$this->idBrend = $result['IDBREND'];
		$this->qte = $qte;
		$this->idProduit = $result['IDPRODUCT'];
		$this->nom = $result['NOM'];
		$this->descshort = $result['DESCSHORT'];
		$this->navnom = $result['NAVNOM'];
		$this->navnom_urlparents = $result['NAVNOM_URLPARENTS'];
		$this->url = $result['URL'];
		$this->designation = $result['DESIGNATION'];
		$this->stock = $result['STOCK'];

		$this->remise_euro = $result['REMISEEURO'];
		$this->remise_pour = $result['REMISEPOUR'];
		$this->isActif = $result['isCADDYTYPE_ACTIF'];

		$this->reference = $result['REFERENCE'];
		$this->idcategory = $result['IDCATEGORY'];
		$this->promo_date = $result['DATEPROMO'];
		
		$this->isDevis = $result['isDEVIS'];
		$this->prix = $result['PRIX'];
		$this->qte_min = $result['QUANTITYMIN']; 
		
		$selectedOption_tmp = '';
		$optionList = new OptionList();
		$item_optionsByList = $optionList->getByIdProduct($result['IDPRODUCT']);
		if (!empty($item_optionsByList) && !empty($item_optionsByList->values)) {
			foreach($item_optionsByList->values as $currentOption) {	
				$selectedOption_tmp = $currentOption;
				break;
			}
		}	 
		$this->selectedOption = $selectedOption_tmp;
	}

	public function isActif() {
		if($this->isActif == 'Y') { return true ;}
		return false;
	}

	public function isPromo() {
		if ($this->remise_euro > 0 || $this->remise_pour > 0) {  return true; }
		return false;
	}

	public function setRemise($euro, $pour) {
		if ($euro > 0) { $this->remise_euro = $euro; }
		else if ($pour > 0) { $this->remise_pour = $pour; }
	}

	public function isRemiseChanged() {
		if ($this->remise_euro > 0 || $this->remise_pour > 0) { return true; }
		return false;
	}

	public function isSurDevis() {
		if ($this->isDevis == 0) { return true; }
		return false;
	}

	public function getPrixAfterRemise() {
		if ($this->remise_euro > 0) {
			return sprintf("%.2f",$this->prix - $this->remise_euro);
		} else if ($this->remise_pour > 0) {
			return sprintf("%.2f",$this->prix - (($this->prix * $this->remise_pour) / 100));
		}
		return sprintf("%.2f",$this->prix);
	}

}

?>
utils/Facture.php000060400000011200150715102030007766 0ustar00<?php
class Facture {
 
	var $facture_fidelite_lines;
	var $facture_lines;
	var $code_reduction; 
	var $livraison;

	var $remise_command_euro = 0;
	var $remise_command_pour = 0;
	var $date_start;

	var $total_poids = 0;
	var $isAncienPoids = false;
	var $isFrancoDenied = false;
	var $isCodeReduction_Product = false;

	var $total_HT_HR = 0;
	var $total_remise = 0;
	var $total_HT = 0;
	var $total_frais_port = 0;
	var $total_frais_port_pour = 0;
	var $total_HT_FP = 0;
	var $total_TVA = 0;
	var $total_TTC = 0;

	var $resteFrancoLiv;
	
	//Dans le casdes caddyType
	var $user_nom;
	var $user_prenom;
	var $user_id;
	  
	function Facture() {
		$this->facture_lines = array();
		$this->facture_fidelite_lines = array();
		$this->code_reduction = array();
		$this->livraison = array();
		 
		$this->setDateStart();
	}

	 
	public function changeTVA($newTVA) {
		$this->tva = $newTVA;
		$this->total_TVA = $this->getPrixTotalTVA(false);
		$this->total_TTC = $this->getPrixTotalTTC(false);
	}

	public function isFactureValid($type) {
		if (isset($this->facture_lines) && !empty($this->facture_lines)) { return true; }
		return false;
	}

	public function checkCodeReductionProduct($reference, $qte) {
		if (isset($this->code_reduction) && !empty($this->code_reduction)) {
			if (($reference == $this->code_reduction['PRODUITREF']) && ($qte >= $this->code_reduction['PRODUITNBR'])) {
				$this->isCodeReduction_Product = true;
			}
		}
	}

	public function getPrixCodeReduction() {
		if (isset($this->code_reduction) && !empty($this->code_reduction) && $this->code_reduction['isACTIF'] == 1 ) {
			if ($this->code_reduction['EURO'] > 0) {
				return sprintf("%.2f",$this->code_reduction['EURO']);
			}
			if ($this->code_reduction['POUR'] > 0) {
				return ($this->total_HT_HR * $this->code_reduction['POUR']) / 100;
			}
		}
		return 0;
	}

	public function getPrixRemise() {
		$result = 0;
		if ($this->remise_command_euro > 0) { $result = $this->remise_command_euro; }
		if ($this->remise_command_pour > 0) { $result += ($this->total_HT_HR * $this->remise_command_pour) / 100; }
		return sprintf("%.2f",$result);
	}

	public function getPrixTotalHT() {
		$prixRemise = $this->getPrixRemise();
		if ($prixRemise >= $this->total_HT_HR) {
			$this->remise_command_euro = 0;
			$this->remise_command_pour = 0;
			$prixRemise = 0;
		}
		return sprintf("%.2f",$this->total_HT_HR - $prixRemise);
	}

	public function getPrixTotalHT_FP($isShow) {
		if ($isShow) { return sprintf("%.2f",$this->total_HT + $this->total_frais_port, 2, ',', ' '); }
		return sprintf("%.2f",$this->total_HT + $this->total_frais_port);
	}

	public function getPrixTotalTVA($isShow) {
		if ($isShow) { return sprintf("%.2f", ($this->getPrixTotalHT_FP(false) * $this->getCurrentTva($this->date_start)) / 100, 2, ',', ' '); }
		return sprintf("%.2f", ($this->getPrixTotalHT_FP(false) * $this->getCurrentTva($this->date_start)) / 100);
	}

	public function getPrixTotalTTC($isShow) {
		if ($isShow) { return sprintf("%.2f", $this->getPrixTotalHT_FP(false) + $this->getPrixTotalTVA(false) , 2, ',', ' '); }
		return sprintf("%.2f", $this->getPrixTotalHT_FP(false) + $this->getPrixTotalTVA(false));
	}

	public function getNbArticles() {
		if (isset($this->facture_lines) && !empty($this->facture_lines)) { return count($this->facture_lines); }
		return 0;
	} 
	public function addLine($line) { 
		array_push($this->facture_lines, $line); 
	}
	public function addFideliteLine($line) { 
		array_push($this->facture_fidelite_lines, $line); 
	}

	public function toArray() {	}

	private function setDateStart() {
		$date = new Zend_Date();
		$this->date_start = $date->toString('YYYY-MM-dd HH:mm:ss');
	}
	
	private function getCurrentTva($datevalue) {
		$date = new Zend_Date();
		$date->set($datevalue);
		$result = 20;
		if (intval($date->toString('YYYY')) < 2014) {
			$result = 19.60;
		}
		return $result;
	}
	
	public function computeFactureTVA(&$facture, $paysLivraison) {
		$resultTVA = $this->getCurrentTva($facture['DATESTART']);
		
		try {
			/*if (isset($paysLivraison) && !empty($paysLivraison)) {
			 if (strcasecmp($paysLivraison, "FRANCE") != 0) {
			$resultTVA = 0;
			}
			}*/
			if (isset($facture) && !empty($facture)) {
				$facture['TVA'] = $resultTVA;
				$facture['PRIXTOTALTVA'] = sprintf("%.2f", $facture['PRIXTOTALHTFP'] * $facture['TVA']) / 100;
				
			}
		} catch(Zend_Exception $e) { }
	}
    
    public function isCarteFidelitePointsValid($sumOfUser) {
        return $this->getCarteFidelitePointsTotal() <= $sumOfUser;
    }
    public function getCarteFidelitePointsTotal() {
        $total = 0;
		foreach ($this->facture_fidelite_lines as $item) {
            $total += $item->fidelite_nbpoint;
        }
        return $total;
    }
	
}

?>utils/CaddyFidelite.php000060400000001341150715102030011074 0ustar00<?php
class CaddyFidelite {
	var $items = array(); 

	function CaddyFidelite() {
		$this->items = array(); 
	}
    
	function removeItem($idfidelite){
        $newItems = array(); 
        foreach($this->items as $item) { 
			if ($item->idFidelite != $idfidelite) {
			    array_push($newItems, $item);
			} 
		}  
        $this->items = $newItems;
    }
	function addItem($idfidelite){
		$currentItem = false;  
		foreach($this->items as $item) { 
			if ($item->idFidelite == $idfidelite) {
				$currentItem = true;  
			} 
		}    
		if ($currentItem == false) {
			$item = new ItemFidelite();
			$item->getItemInfo($idfidelite);
            if (!empty($item->nom)) {
			    array_push($this->items, $item);
            }
		} 
	} 
}

?>utils/Caddy.php000060400000011435150715102030007433 0ustar00<?php
class Caddy {
	var $items;
	var $itemsCaddyType;

	function Caddy() {
		$this->items = array();
		$this->itemsCaddyType = array();
	}
	
	private function getStorage() {
		$registry = Zend_Registry::getInstance();
		$setting = $registry->get('setting');
		return new Zend_Auth_Storage_Session($setting->session_storage);
	}
	
	function getTotalSize() {
		$result = 0;
        
		if (isset($this->items) && !empty($this->items)) { $result += sizeof($this->items); }
		
		$auth = Zend_Auth::getInstance();
		$auth->setStorage($this->getStorage());
		$storage = $auth->getStorage()->read(); 
		if ($auth->hasIdentity() && isset($storage['user']) && $storage['user']['iscaddytype'] == 'Y') {
			if (isset($this->itemsCaddyType) && !empty($this->itemsCaddyType)) { $result += sizeof($this->itemsCaddyType); }
		} 
		return $result;
	}

	function cleanUp() {
		$this->items = array();
		$this->itemsCaddyType = array();
	}

	function addItemToCaddy($idChild, $qteChild, $isAccessoire, $selectedOption){
		$currentItem = false;  
		foreach($this->items as $key => $item) { 
			if ($item->idChild == $idChild && $item->selectedOption == $selectedOption) {
				$item->qteChild = $qteChild; 
				$currentItem = true;  
			} 
		}    
		if ($currentItem == false) {
			$item = new Item();
			$item->getItemInfo($idChild, $qteChild, $isAccessoire, $selectedOption);
			array_push($this->items, $item);
		} 
	}
	function addItemToCaddyType($idCaddyType, $qte, $selectedOption){
		$currentItem = false;
		foreach($this->itemsCaddyType as $item) {
			if ($item->id == $idCaddyType && $item->selectedOption == $selectedOption) {
				$item->qte = $qte;
				$currentItem = true;
				break;
			}
		}
		if ($currentItem == false) {
			$itemCaddyType = new ItemCaddyType();
			$itemCaddyType->getItemInfo($idCaddyType, $qte, $selectedOption);
			array_push($this->itemsCaddyType, $itemCaddyType);
		}
	}
	function delItemToCaddyType($idCaddyType, $selectedOption){
		$currentKey = -1;
		foreach($this->itemsCaddyType as $key => $item) {
			if ($item->id == $idCaddyType && $item->selectedOption == $selectedOption) {
				$currentKey = $key; 
				break;
			}
		}
		if ($currentKey != -1) { unset($this->itemsCaddyType[$currentKey]); }
		if (!is_array($this->itemsCaddyType)) {  $this->itemsCaddyType = array(); }
		$tmp = $this->itemsCaddyType;
		$this->itemsCaddyType = array_values($tmp); 
	}

	function delItemToCaddy($idChild, $selectedOption){
		$currentKey = -1; 
		foreach($this->items as $key => $item) {
			if ($item->idChild == $idChild && $item->selectedOption == $selectedOption) {
				$currentKey = $key;
				break;
			}
		} 
		if ($currentKey != -1) { unset($this->items[$currentKey]); }
		if (!is_array($this->items)) {  $this->items = array(); }
		$tmp = $this->items;
		$this->items = array_values($tmp);
	}
	
	function delItemToCaddyByKey($currentKey){  
		if ($currentKey != -1) { unset($this->items[$currentKey]); }
		if (!is_array($this->items)) {  $this->items = array(); }
		$tmp = $this->items;
		$this->items = array_values($tmp);
	}

	function getQuantity($idChild) {
		if (!empty($this->items)) {
			foreach($this->items as $item) {
				if ($item->idChild == $idChild) {
					return $item->qteChild;
				}
			}
		}
		return 0;
	}

	function getItemById($idChild) {
		foreach($this->items as $item) {
			if ($item->idChild == $idChild) {
				return $item;
			}
		}
		return null;
	}

	function getItemByIdAndOption($idChild, $selectedOption) {
		foreach($this->items as $item) {
			if ($item->idChild == $idChild && $item->selectedOption == $selectedOption) {
				return $item;
			}
		}
		return null;
	}

	function getItemCaddyTypeByIdChild($idChild) {
		foreach($this->itemsCaddyType as $item) {
			if ($item->idChild == $idChild) {
				return $item;
			}
		}
		return null;
	}

	function getItemCaddyTypeByIdChildAndOption($idChild, $selectedOption) {
		foreach($this->itemsCaddyType as $item) {
			if ($item->idChild == $idChild && $item->selectedOption == $selectedOption) {
				return $item;
			}
		}
		return null;
	}

	function getCaddyTemp($userId) {

		$this->items = array();
		$caddyTemp = new CaddyTemp();
		$resultCaddy = $caddyTemp->findCaddyByUser($userId);

		if (isset($resultCaddy) && !empty($resultCaddy)) {
			foreach ($resultCaddy AS $row) {
				$item = new Item();

				$item->idChild = $row['CHILDID'];
				$item->qteChild = $row['CHILDQUANTITY'];
				$item->idProduit = $row['PRODUCTID'];
				$item->nom = $row['PRODUCTNOM'];
				$item->descshort = $row['DESCSHORT'];
				$item->navnom = $row['NAVNOM'];
				$item->url = $row['URL'];
				$item->designation = $row['DESIGNATION'];
				$item->isAccessoire = $row['isACCESSOIRE'];
				$item->selectedOption = $row['SELECTEDOPTION'];
				$item->stock = 1;

				array_push($this->items, $item);
			}
		}
	}

	function showCaddy() {
		foreach($this->items as $item) {
			print $item->toString()."<br/>";
		}
	}
}

?>utils/PromoCalculator.php000060400000032374150715102030011522 0ustar00<?php
class PromoCalculator {
	var $promoProduct;
	var $promoUser;
	var $promoCommand;

	function PromoCalculator() {
		$this->promoProduct = new PromoProduct();
		$this->promoUser = new PromoUser();
		$this->promoCommand = new PromoCommand();
	}

	public function calculEuro($prix, $remise) { return $prix - $remise; }
	public function calculPour($prix, $remise) { return $prix - (($prix * $remise) / 100); }
	public function isRemise() {

	}
	/*
	 * REMISES SUR PRODUITS
	 */

	/*
	 * Calcul du prix de la promotion selon la reference d'un produit
	 */
	private function computePrixProductByReference($factureLine) {
		if ($factureLine->isPromo()) {
			$myPromo = $this->promoProduct->getRemiseByProductReference($factureLine->item_reference);
			if ($myPromo['REMISEEURO'] > 0) {
				$factureLine->remise_euro = $myPromo['REMISEEURO'];
				//$prixPromo = $this->calculEuro($factureLine->item_prix, $myPromo['REMISEEURO']);
				//$factureLine->setPrixPromo($prixPromo);
			}
			if ($myPromo['REMISEPOUR'] > 0) {
				//$prixPromo = $this->calculPour($factureLine->item_prix, $myPromo['REMISEPOUR']);
				//$factureLine->setPrixPromo($prixPromo);
				$factureLine->remise_pour = $myPromo['REMISEPOUR'];
			}
			$factureLine->checkPrixPromo();
		}
	}

	/*
	 * Calcul du prix de la promotion selon la marque d'un produit
	 */
	private function computePrixProductByMarque($factureLine) {
		$myPromo = $this->promoProduct->getRemiseByProductBrend($factureLine->product_brend_id);
		if ($myPromo) {
			if ($myPromo['REMISEEURO'] > 0) {
				$factureLine->remise_euro = $myPromo['REMISEEURO'];
			}
			if ($myPromo['REMISEPOUR'] > 0) {
				$factureLine->remise_pour = $myPromo['REMISEPOUR'];
			}
			$factureLine->checkPrixPromo();
		}
	}


	/*
	 * Calcul du prix de la promotion selon la gamme d'un produit
	 */
	private function computePrixProductByCategory($factureLine) {
		$myPromo = $this->promoProduct->getRemiseByProductCategory($factureLine->product_category_id);
		if ($myPromo) {
			if ($myPromo['REMISEEURO'] > 0) {
				$factureLine->remise_euro = $myPromo['REMISEEURO'];
			}
			if ($myPromo['REMISEPOUR'] > 0) {
				$factureLine->remise_pour = $myPromo['REMISEPOUR'];
			}
			$factureLine->checkPrixPromo();
		}
	}

	/*
	 * Calcul du prix de la promotion d'un produit selon un nombre achete
	 */
	private function computePrixProductByQte($factureLine, $facture_lines) {
		$myPromo = $this->promoProduct->getRemisesByProductQte($factureLine->item_reference, $factureLine->item_qte);
		if ($myPromo) {
			foreach ($facture_lines AS $line) {
				foreach ($myPromo AS $promo) {
					if (($line->item_reference == $promo['CHILDREFBUY']) &&
					($line->item_qte >= $promo['CHILDREFBUYNB']) ) {
						if ($promo['REMISEEURO'] > 0) {
							$factureLine->remise_items = array(
								'NB' => $promo['CHILDREFPROMONB'],
								'REF' => $promo['CHILDREFPROMO'],
								'REMISE_EURO' => $promo['REMISEEURO'],
								'REMISE_POUR' => 0

							);
						}
						if ($promo['REMISEPOUR'] > 0) {
							$factureLine->remise_items = array(
								'NB' => $promo['CHILDREFPROMONB'],
								'REF' => $promo['CHILDREFPROMO'],
								'REMISE_POUR' => $promo['REMISEPOUR'],
								'REMISE_EURO' => 0 
							);
						}
					}
				}
			}
		}
	}

	/*
	 * Calcul du prix de la promotion selon la date d'un produit
	 */
	private function computePrixProductByDateBetween($factureLine) {
		$myPromo = $this->promoProduct->getRemiseByProductDateBetween($factureLine->product_promo_date);
		if ($myPromo) {
			if ($myPromo['REMISEEURO'] > 0) {
				$factureLine->remise_euro = $myPromo['REMISEEURO'];
			}
			if ($myPromo['REMISEPOUR'] > 0) {
				$factureLine->remise_pour = $myPromo['REMISEPOUR'];
			}
			$factureLine->checkPrixPromo();
		}
	}


	/*
	 * Calcul du prix de la remise selon la marque et l'user
	 */
	private function computePrixUserByMarque($factureLine, $userId) {
		$myPromo = $this->promoUser->getRemiseByMarque($factureLine->product_brend_id, $userId);
		if ($myPromo) {
			if ($myPromo['REMISEEURO'] > 0) {
				$factureLine->remise_euro = $myPromo['REMISEEURO'];
			}
			if ($myPromo['REMISEPOUR'] > 0) {
				$factureLine->remise_pour = $myPromo['REMISEPOUR'];
			}
			$factureLine->checkPrixPromo();
		}
	}

	/*
	 * Calcul du prix de la remise selon le code interne et la marque
	 */
	private function computePrixUserByCodeInternMarque($factureLine, $codeIntern) {
		$myPromo = $this->promoUser->getRemiseByCodeInternMarque($factureLine->product_brend_id, $codeIntern);
		if ($myPromo) {
			if ($myPromo['REMISEEURO'] > 0) {
				$factureLine->remise_euro = $myPromo['REMISEEURO'];
			}
			if ($myPromo['REMISEPOUR'] > 0) {
				$factureLine->remise_pour = $myPromo['REMISEPOUR'];
			}
			$factureLine->checkPrixPromo();
		}
	}


	/*
	 * REMISES GLOBALES
	 */

	/*
	 * Calcul du prix de la remise de la commande selon un nombre de produits
	 *
	 * CUMUL
	 */
	private function computePrixCommandByProductQte($factureLine, $facture) {
		$myPromo = $this->promoCommand->getRemiseCommandByProductQte($factureLine->item_reference, $factureLine->item_qte);
		if ($myPromo) {
			if ($myPromo['REMISEEURO'] > 0) {
				$facture->remise_command_euro += $myPromo['REMISEEURO'];
			}
			if ($myPromo['REMISEPOUR'] > 0) {
				$facture->remise_command_pour += $myPromo['REMISEPOUR'];
			}
		}
	}

	/*
	 * Calcul du prix de la remise de la commande selon le TOTAL HT
	 *
	 * CUMUL
	 */
	private function computePrixCommandByTotalHT($facture) {
		$myPromo = $this->promoCommand->getRemiseCommandByTotalHT($facture->total_HT_HR);
		if ($myPromo) {
			if ($myPromo['REMISEEURO'] > 0) {
				$facture->remise_command_euro += $myPromo['REMISEEURO'];
			}
			if ($myPromo['REMISEPOUR'] > 0) {
				$facture->remise_command_pour += $myPromo['REMISEPOUR'];
			}
		}
	}

	/*
	 * Calcul du prix de la remise de toute les commandes
	 *
	 * CUMUL
	 */
	private function computePrixCommandByAll($facture) {
		$myPromo = $this->promoCommand->getRemiseCommandByAll();
		if ($myPromo) {
			if ($myPromo['REMISEEURO'] > 0) {
				$facture->remise_command_euro += $myPromo['REMISEEURO'];
			}
			if ($myPromo['REMISEPOUR'] > 0) {
				$facture->remise_command_pour += $myPromo['REMISEPOUR'];
			}
		}
	}

	/*
	 * Calcul du prix de la remise de la commande selon la date anniversaire
	 *
	 * CUMUL
	 */
	private function computePrixUserByDateInscription($facture, $dateInsc) {
		$myPromo = $this->promoUser->getRemiseByDateInscription();
		if ($myPromo) {
			$date = new Zend_Date();
			$userDate = new Zend_Date(strtotime($dateInsc));
			if (($userDate->toString("MM") -  $date->toString("MM")) < 2 &&
			($userDate->toString("MM") -  $date->toString("MM")) > -2) {
					
				if ($myPromo['REMISEEURO'] > 0) {
					$facture->remise_command_euro += $myPromo['REMISEEURO'];
				}
				if ($myPromo['REMISEPOUR'] > 0) {
					$facture->remise_command_pour += $myPromo['REMISEPOUR'];
				}
			}
		}
	}


	/*
	 * Calcul du prix de la remise de la commande selon l'user
	 *
	 * CUMUL
	 */
	private function computePrixUserByUser($facture, $userID) {
		$myPromo = $this->promoUser->getRemiseByUserID($userID);
		if ($myPromo) {
			if ($myPromo['REMISEEURO'] > 0) {
				$facture->remise_command_euro += $myPromo['REMISEEURO'];
			}
			if ($myPromo['REMISEPOUR'] > 0) {
				$facture->remise_command_pour += $myPromo['REMISEPOUR'];
			}
		}
	}

	/*
	 * Calcul du prix de la remise de la commande si c'est la premiere
	 *
	 * CUMUL
	 */
	private function computePrixUserByIsFirstCommand($facture, $userID) {
		$myPromo = $this->promoUser->getRemiseByIsFirstCommand();
		if ($myPromo) {
			$commande = new Command();
			if (!$commande->isAlreadyBuySomething($userID)) {
				if ($myPromo['REMISEEURO'] > 0) {
					$facture->remise_command_euro += $myPromo['REMISEEURO'];
				}
				if ($myPromo['REMISEPOUR'] > 0) {
					$facture->remise_command_pour += $myPromo['REMISEPOUR'];
				}
			}
		}
	}

	/*
	 * Calcul du prix du code de reduction pour un produit
	 *
	 * UNIQUE
	 */
	private function computePrixCodeReduction($facture) {
		if (isset($facture->code_reduction) && !empty($facture->code_reduction)) {
			$codeReduction = new CodeReduction();
			$myPromo = $codeReduction->getVerifyCodeBy($facture->code_reduction['CODE']);
			if ($myPromo) {
				$facture->code_reduction = $myPromo;
				if ($facture->isCodeReduction_Product) {
					if (isset($myPromo) && !empty($myPromo) && $myPromo['isACTIF'] == 1 ) {
						if ($myPromo['EURO'] > 0) {
							$facture->remise_command_euro = $myPromo['EURO'];
						}
						if ($myPromo['POUR'] > 0) {
							$facture->remise_command_pour = $myPromo['POUR'];
						}
					}
				} else {
					if ($facture->total_HT_HR >= $myPromo['CMDTOTAL'] && $myPromo['CMDTOTAL'] > 0) {
						if ($myPromo['EURO'] > 0) {
							$facture->remise_command_euro = $myPromo['EURO'];
						}
						if ($myPromo['POUR'] > 0) {
							$facture->remise_command_pour = $myPromo['POUR'];
						}
					}
				}
				$facture->code_reduction['EURO'] = $facture->getPrixCodeReduction();
			} else { $facture->code_reduction = array(); }
		}
	}

	/*
	 * Calcul du prix restant a payer de la commande pour validation
	 *
	 * Return prix restant a payer
	 */
	public function getPrixCommandValidation($facture) {
		$result = 0;
		$myPromo = $this->promoCommand->getCommandValid();
		if ($myPromo) {
			$total_HT = $facture->getPrixTotalHT();
			if ($total_HT < $myPromo['MONTANTVALID']) {
				$result = sprintf("%.2f", $myPromo['MONTANTVALID'] - $total_HT);
			}
		}
		return $result;
	}
	public function isCommandValid($prixHT) {
		$myPromo = $this->promoCommand->getCommandValid();
		if ($myPromo) {
			if ($prixHT < $myPromo['MONTANTVALID']) {  return false ; }
		}
		return true;
	}



	public function computeAllPromos($facture, $user) {
		foreach ($facture->facture_lines AS $item) {
			if (!$item->isCaddyType) {
				if ($item->isSurDevis()) {
					$item->item_prix = 0;
				} else {
					$this->computePrixProductByReference($item);
					if (!$item->isRemiseChanged()) { $this->computePrixProductByMarque($item); }
					if (!$item->isRemiseChanged()) { $this->computePrixProductByCategory($item); }
					if (!$item->isRemiseChanged()) { $this->computePrixProductByQte($item, $facture->facture_lines); }
					if (!$item->isRemiseChanged()) { $this->computePrixProductByDateBetween($item); }


					if (isset($user) && !empty($user)) {
						$userId = $user['id'];
						$codeIntern = $user['cintern'];

						if (!empty($codeIntern)) { $this->computePrixUserByCodeInternMarque($item, $codeIntern); }
						if (!$item->isRemiseChanged()) { $this->computePrixUserByMarque($item, $userId); }
					}

					$this->computePrixCommandByProductQte($item, $facture);

					if (!empty($facture->code_reduction) && isset($facture->code_reduction['PRODUITREF']) && !empty($facture->code_reduction['PRODUITREF'])) {
						$facture->checkCodeReductionProduct($item->item_reference, $item->item_qte);
					}

					$poidsCurrent = $item->getPoidsTotal();
					if ($poidsCurrent > 0) { $facture->total_poids += $poidsCurrent ;
					} else { $facture->isAncienPoids = true;  }

					if ($item->isFrancoDenied()) { $facture->isFrancoDenied = true; }

					$facture->total_HT_HR += $item->getPrixTotalHT(true);
				}
			}
		}

		$this->computePrixCommandByTotalHT($facture);
		$this->computePrixCommandByAll($facture);
			
		if (isset($user) && !empty($user)) {
			$this->computePrixUserByDateInscription($facture, $user['dateinsc']);

			$this->computePrixUserByUser($facture, $user['id']);

			$this->computePrixUserByIsFirstCommand($facture, $user['id']);
		}
			
		$this->computePrixCodeReduction($facture);
	}

	public function computeItemsPromosCaddyType($caddyItems, $user) {
		foreach ($caddyItems AS $item) {
			if (!$item->isPromo()) {
				$promoProduct = new PromoProduct();
				$promoUser = new PromoUser();

				$myPromo = $promoProduct->getRemiseByProductReference($item->reference);
				if ($myPromo) { $item->setRemise($myPromo['REMISEEURO'], $myPromo['REMISEPOUR']); }
 
				if (!$item->isRemiseChanged()) { 
					$myPromo = $promoProduct->getRemiseByProductBrend($item->idBrend);
					if ($myPromo) { $item->setRemise($myPromo['REMISEEURO'], $myPromo['REMISEPOUR']); }
				}

				if (!$item->isRemiseChanged()) {
					$myPromo = $promoProduct->getRemiseByProductCategory($item->idcategory);
					if ($myPromo) { $item->setRemise($myPromo['REMISEEURO'], $myPromo['REMISEPOUR']); }
				}
				if (!$item->isRemiseChanged()) {
					$myPromo = $promoProduct->getRemisesByProductQte($item->reference, $item->qte);
					if ($myPromo) {
						foreach ($caddyItems AS $line) {
							foreach ($myPromo AS $promo) {
								if (($line->reference == $promo['CHILDREFBUY']) &&
								($line->qte >= $promo['CHILDREFBUYNB']) ) {
									$item->setRemise($promo['REMISEEURO'], $promo['REMISEPOUR']);
								}
							}
						}
					}
				}
				if (!$item->isRemiseChanged()) {
					$myPromo = $promoProduct->getRemiseByProductDateBetween($item->promo_date);
					if ($myPromo) { $item->setRemise($myPromo['REMISEEURO'], $myPromo['REMISEPOUR']); }
				}
				if (isset($user) && !empty($user)) {
					$userId = $user['id'];
					$codeIntern = $user['cintern'];

					if (!empty($codeIntern)) {
						$myPromo = $promoUser->getRemiseByCodeInternMarque($item->idBrend, $codeIntern);
						if ($myPromo) { $item->setRemise($myPromo['REMISEEURO'], $myPromo['REMISEPOUR']); }
					}
					if (!$item->isRemiseChanged()) {
						$myPromo = $promoUser->getRemiseByMarque($item->idBrend, $userId);
						if ($myPromo) { $item->setRemise($myPromo['REMISEEURO'], $myPromo['REMISEPOUR']); }
					}
				}
			}
		}
	}
}
?>utils/Item.php000060400000002723150715102030007305 0ustar00<?php 
class Item {
    var $idProduit;
    var $idChild;
    var $qteChild;
    var $nom;
    var $descshort;
    var $navnom;
    var $url;
    var $designation;
    var $stock = 1;
    var $isAccessoire = 'N'; 
    var $selectedOption = "";
     
    function Item() { }
    
    function getItemInfo($idChild, $qteChild, $isAccessoire, $selectedOption) {
    	$sql = "
			SELECT p.NOM NOM, p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.ID IDPRODUCT, pic.URL URL, pc.DESIGNATION DESIGNATION, p.STOCK STOCK
			FROM productchild pc
			LEFT JOIN product p ON p.ID = pc.IDPRODUCT
			LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
			WHERE pc.ID = ".$idChild."
			AND p.isACTIVE = 0
			AND pic.POSITION = 1
			";
			$productChild = new ProductChild();
			$result = $productChild->getAdapter()->fetchRow($sql);
			 
			$this->idChild = $idChild;
			$this->qteChild = $qteChild;
			$this->idProduit = $result['IDPRODUCT'];
			$this->nom = $result['NOM'];
			$this->descshort = $result['DESCSHORT'];
			$this->navnom = $result['NAVNOM'];
			$this->url = $result['URL'];
			$this->designation = $result['DESIGNATION'];
			$this->stock = $result['STOCK'];
			$this->isAccessoire = $isAccessoire;
			$this->selectedOption = $selectedOption;
    }
    
    public function toString() {
    	return $this->nom." - ".$this->idChild." : ".$this->qteChild."<br>";
    }
    
    public function isItemAccessoire() {
    	if ($this->isAccessoire == "Y") { return true; }
    	return false;
    }
}

?>
utils/UploadHandler.php000060400000027061150715102030011133 0ustar00<?php

/**
 * Do not use or reference this directly from your client-side code.
 * Instead, this should be required via the endpoint.php or endpoint-cors.php
 * file(s).
 */

class UploadHandler {

    public $allowedExtensions = array();
    public $sizeLimit = null;
    public $inputName = 'qqfile';
    public $chunksFolder = 'chunks';

    public $chunksCleanupProbability = 0.001; // Once in 1000 requests on avg
    public $chunksExpireIn = 604800; // One week

    protected $uploadName;

    /**
     * Get the original filename
     */
    public function getName(){
        if (isset($_REQUEST['qqfilename']))
            return $_REQUEST['qqfilename'];

        if (isset($_FILES[$this->inputName]))
            return $_FILES[$this->inputName]['name'];
    }

    public function getInitialFiles() {
        $initialFiles = array();

        for ($i = 0; $i < 5000; $i++) {
            array_push($initialFiles, array("name" => "name" + $i, uuid => "uuid" + $i, thumbnailUrl => "/test/dev/handlers/vendor/fineuploader/php-traditional-server/fu.png"));
        }

        return $initialFiles;
    }

    /**
     * Get the name of the uploaded file
     */
    public function getUploadName(){
        return $this->uploadName;
    }

    public function combineChunks($uploadDirectory, $name = null) {
        $uuid = $_POST['qquuid'];
        if ($name === null){
            $name = $this->getName();
        }
        $targetFolder = $this->chunksFolder.DIRECTORY_SEPARATOR.$uuid;
        $totalParts = isset($_REQUEST['qqtotalparts']) ? (int)$_REQUEST['qqtotalparts'] : 1;

        $targetPath = join(DIRECTORY_SEPARATOR, array($uploadDirectory, $uuid, $name));
        $this->uploadName = $name;

        if (!file_exists($targetPath)){
            mkdir(dirname($targetPath));
        }
        $target = fopen($targetPath, 'wb');

        for ($i=0; $i<$totalParts; $i++){
            $chunk = fopen($targetFolder.DIRECTORY_SEPARATOR.$i, "rb");
            stream_copy_to_stream($chunk, $target);
            fclose($chunk);
        }

        // Success
        fclose($target);

        for ($i=0; $i<$totalParts; $i++){
            unlink($targetFolder.DIRECTORY_SEPARATOR.$i);
        }

        rmdir($targetFolder);

        if (!is_null($this->sizeLimit) && filesize($targetPath) > $this->sizeLimit) {
            unlink($targetPath);
            http_response_code(413);
            return array("success" => false, "uuid" => $uuid, "preventRetry" => true);
        }

        return array("success" => true, "uuid" => $uuid);
    }

    /**
     * Process the upload.
     * @param string $uploadDirectory Target directory.
     * @param string $name Overwrites the name of the file.
     */
    public function handleUpload($uploadDirectory, $name = null){

        if (is_writable($this->chunksFolder) &&
            1 == mt_rand(1, 1/$this->chunksCleanupProbability)){

            // Run garbage collection
            $this->cleanupChunks();
        }

        // Check that the max upload size specified in class configuration does not
        // exceed size allowed by server config
        if ($this->toBytes(ini_get('post_max_size')) < $this->sizeLimit ||
            $this->toBytes(ini_get('upload_max_filesize')) < $this->sizeLimit){
            $neededRequestSize = max(1, $this->sizeLimit / 1024 / 1024) . 'M';
            return array('error'=>"Server error. Increase post_max_size and upload_max_filesize to ".$neededRequestSize);
        }

        if ($this->isInaccessible($uploadDirectory)){
            return array('error' => "Server error. Uploads directory isn't writable");
        }

        $type = $_SERVER['CONTENT_TYPE'];
        if (isset($_SERVER['HTTP_CONTENT_TYPE'])) {
            $type = $_SERVER['HTTP_CONTENT_TYPE'];
        }

        if(!isset($type)) {
            return array('error' => "No files were uploaded.");
        } else if (strpos(strtolower($type), 'multipart/') !== 0){
            return array('error' => "Server error. Not a multipart request. Please set forceMultipart to default value (true).");
        }

        // Get size and name
        $file = $_FILES[$this->inputName];
        $size = $file['size'];
        if (isset($_REQUEST['qqtotalfilesize'])) {
            $size = $_REQUEST['qqtotalfilesize'];
        }

        if ($name === null){
            $name = $this->getName();
        }

        // Validate name
        if ($name === null || $name === ''){
            return array('error' => 'File name empty.');
        }

        // Validate file size
        if ($size == 0){
            return array('error' => 'File is empty.');
        }

        if (!is_null($this->sizeLimit) && $size > $this->sizeLimit) {
            return array('error' => 'File is too large.', 'preventRetry' => true);
        }

        // Validate file extension
        $pathinfo = pathinfo($name);
        $ext = isset($pathinfo['extension']) ? $pathinfo['extension'] : '';

        if($this->allowedExtensions && !in_array(strtolower($ext), array_map("strtolower", $this->allowedExtensions))){
            $these = implode(', ', $this->allowedExtensions);
            return array('error' => 'File has an invalid extension, it should be one of '. $these . '.');
        }

        // Save a chunk
        $totalParts = isset($_REQUEST['qqtotalparts']) ? (int)$_REQUEST['qqtotalparts'] : 1;

        $uuid = $_REQUEST['qquuid'];
        if ($totalParts > 1){
        # chunked upload

            $chunksFolder = $this->chunksFolder;
            $partIndex = (int)$_REQUEST['qqpartindex'];

            if (!is_writable($chunksFolder) && !is_executable($uploadDirectory)){
                return array('error' => "Server error. Chunks directory isn't writable or executable.");
            }

            $targetFolder = $this->chunksFolder.DIRECTORY_SEPARATOR.$uuid;

            if (!file_exists($targetFolder)){
                mkdir($targetFolder);
            }

            $target = $targetFolder.'/'.$partIndex;
            $success = move_uploaded_file($_FILES[$this->inputName]['tmp_name'], $target);

            return array("success" => $success, "uuid" => $uuid, "uploadName" => $name);

        }
        else {
        # non-chunked upload

            $target = join(DIRECTORY_SEPARATOR, array($uploadDirectory, $uuid, $name));
	
            if ($target){
                $this->uploadName = basename($target);

                if (!is_dir(dirname($target))){
                    mkdir(dirname($target));
                }
                if (move_uploaded_file($file['tmp_name'], $target)){
                    return array('success'=> true, "uuid" => $uuid, "uploadName" => $name);
                }
            }

            return array('error'=> 'Could not save uploaded file.' .
                'The upload was cancelled, or server error encountered : '.$target. ' Name : '.$name);
        }
    }

    /**
     * Process a delete.
     * @param string $uploadDirectory Target directory.
     * @params string $name Overwrites the name of the file.
     *
     */
    public function handleDelete($uploadDirectory, $name=null)
    {
        if ($this->isInaccessible($uploadDirectory)) {
            return array('error' => "Server error. Uploads directory isn't writable" . ((!$this->isWindows()) ? " or executable." : "."));
        }

        $targetFolder = $uploadDirectory;
        $url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
        $tokens = explode('/', $url);
        $uuid = $tokens[sizeof($tokens)-1];

        $target = join(DIRECTORY_SEPARATOR, array($targetFolder, $uuid));

        if (is_dir($target)){
            $this->removeDir($target);
            return array("success" => true, "uuid" => $uuid);
        } else {
            return array("success" => false,
                "error" => "File not found! Unable to delete.".$url,
                "path" => $uuid
            );
        }

    }

    /**
     * Returns a path to use with this upload. Check that the name does not exist,
     * and appends a suffix otherwise.
     * @param string $uploadDirectory Target directory
     * @param string $filename The name of the file to use.
     */
    protected function getUniqueTargetPath($uploadDirectory, $filename)
    {
        // Allow only one process at the time to get a unique file name, otherwise
        // if multiple people would upload a file with the same name at the same time
        // only the latest would be saved.

        if (function_exists('sem_acquire')){
            $lock = sem_get(ftok(__FILE__, 'u'));
            sem_acquire($lock);
        }

        $pathinfo = pathinfo($filename);
        $base = $pathinfo['filename'];
        $ext = isset($pathinfo['extension']) ? $pathinfo['extension'] : '';
        $ext = $ext == '' ? $ext : '.' . $ext;

        $unique = $base;
        $suffix = 0;

        // Get unique file name for the file, by appending random suffix.

        while (file_exists($uploadDirectory . DIRECTORY_SEPARATOR . $unique . $ext)){
            $suffix += rand(1, 999);
            $unique = $base.'-'.$suffix;
        }

        $result =  $uploadDirectory . DIRECTORY_SEPARATOR . $unique . $ext;

        // Create an empty target file
        if (!touch($result)){
            // Failed
            $result = false;
        }

        if (function_exists('sem_acquire')){
            sem_release($lock);
        }

        return $result;
    }

    /**
     * Deletes all file parts in the chunks folder for files uploaded
     * more than chunksExpireIn seconds ago
     */
    protected function cleanupChunks(){
        foreach (scandir($this->chunksFolder) as $item){
            if ($item == "." || $item == "..")
                continue;

            $path = $this->chunksFolder.DIRECTORY_SEPARATOR.$item;

            if (!is_dir($path))
                continue;

            if (time() - filemtime($path) > $this->chunksExpireIn){
                $this->removeDir($path);
            }
        }
    }

    /**
     * Removes a directory and all files contained inside
     * @param string $dir
     */
    protected function removeDir($dir){
        foreach (scandir($dir) as $item){
            if ($item == "." || $item == "..")
                continue;

            if (is_dir($item)){
                $this->removeDir($item);
            } else {
                unlink(join(DIRECTORY_SEPARATOR, array($dir, $item)));
            }

        }
        rmdir($dir);
    }

    /**
     * Converts a given size with units to bytes.
     * @param string $str
     */
    protected function toBytes($str){
        $val = trim($str);
        $last = strtolower($str[strlen($str)-1]);
        switch($last) {
            case 'g': $val *= 1024;
            case 'm': $val *= 1024;
            case 'k': $val *= 1024;
        }
        return $val;
    }

    /**
     * Determines whether a directory can be accessed.
     *
     * is_executable() is not reliable on Windows prior PHP 5.0.0
     *  (http://www.php.net/manual/en/function.is-executable.php)
     * The following tests if the current OS is Windows and if so, merely
     * checks if the folder is writable;
     * otherwise, it checks additionally for executable status (like before).
     *
     * @param string $directory The target directory to test access
     */
    protected function isInaccessible($directory) {
        $isWin = $this->isWindows();
        $folderInaccessible = ($isWin) ? !is_writable($directory) : ( !is_writable($directory) && !is_executable($directory) );
        return $folderInaccessible;
    }

    /**
     * Determines is the OS is Windows or not
     *
     * @return boolean
     */

    protected function isWindows() {
    	$isWin = (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN');
    	return $isWin;
    }

}
utils/FactureLine.php000060400000013762150715102030010615 0ustar00<?php

class FactureLine {
	var $is_fidelite = false;
	var $fidelite_nom;
	var $fidelite_nbpoint;    
	var $fidelite_id;    
    
	var $product_id;
	var $product_nom;
	var $product_descshort;
	var $product_navnom;
	var $product_navnom_urlparents;
	var $product_url;
	var $product_isPromo;
	var $product_brend_id;
	var $product_isBrend;
	var $product_category_id;
	var $product_promo_date;

	var $item_id;
	var $item_reference;
	var $item_qte;
	var $item_qte_min;
	var $item_designation;
	var $item_stock;
	var $item_poids;
	var $item_isAccessoire;
	var $item_isPromo;
	var $item_isDevis;
	var $item_isFrancoDenied;
	var $item_selectedOption = "";
	var $item_optionsByList;
	var $item_nbpointfidelite;

	var $item_prix;
	var $remise_euro = 0;
	var $remise_pour = 0;

	//Remise sur un certain nombre d'articles
	var $remise_items;
	
	//Si c'est une ligne du caddy type
	var $isCaddyType = false;
	var $caddytype_id = 0;
	var $caddytype_isActif;
	var $caddytype_qte_total = 0;


	function FactureLine() { $this->remise_items = array(); }

	public function isRemiseChanged() {
		if ($this->remise_euro > 0 || $this->remise_pour > 0) { return true; }
		return false;
	}
	
	public function getPrixRemise() {
		if ($this->remise_euro > 0) {
			return sprintf("%.2f", $this->remise_euro);
		} else if ($this->remise_pour > 0) {
			return sprintf("%.2f",($this->item_prix * $this->remise_pour) / 100);
		}
		return 0;
	}

	public function getPrixAfterRemise() {
		if ($this->remise_euro > 0) {
			return sprintf("%.2f",$this->item_prix - $this->remise_euro);
		} else if ($this->remise_pour > 0) {
			return sprintf("%.2f",$this->item_prix - (($this->item_prix * $this->remise_pour) / 100));
		}
		return sprintf("%.2f",$this->item_prix);
	}
	public function getPrixAfterRemiseOfItems() {
		if (!empty($this->remise_items)) {
			if ($this->remise_items['REMISE_EURO'] > 0) {
				return sprintf("%.2f",$this->item_prix - $this->remise_items['REMISE_EURO']);
			} else if ($this->remise_items['REMISE_POUR'] > 0) {
				return sprintf("%.2f",$this->item_prix - (($this->item_prix * $this->remise_items['REMISE_POUR']) / 100));
			}
		}
		return sprintf("%.2f",$this->item_prix);
	}

	public function getPrixTotalHT($isRemise) {
		$result = 0;
		if ($isRemise) {
			 //Pour les autres remises
			$prixAfter = $this->getPrixAfterRemise();
			$prixTotalAfter = $prixAfter * $this->item_qte;
			
			$result = $prixTotalAfter;
			//Pour la promotion X selon Y avec des qtes
			if (!empty($this->remise_items)) {
				$prixAfterSome = $this->getPrixAfterRemiseOfItems(); 
				if ($this->item_qte >= $this->remise_items['NB']) {
					$prixTotalAfterSome = ($prixAfterSome * $this->remise_items['NB']) + (($this->item_qte - $this->remise_items['NB']) * $this->item_prix);
				} 
				
				if ($prixTotalAfterSome < $prixTotalAfter) { $result = $prixTotalAfterSome; }
			} 
			return sprintf("%.2f",$result); 
		}
		return sprintf("%.2f",$this->item_prix * $this->item_qte);
	}

	public function checkPrixPromo() {
		if ($this->isRemiseChanged()) { 
			$this->product_isPromo = 0;
			$this->item_isPromo = 0; 
		}  else {
			$this->product_isPromo = 1;
			$this->item_isPromo = 1;
		}
	}

	public function getPoidsTotal() {
		return ((int)$this->item_poids) * $this->item_qte;
	}

	public function setLineInfo($row, $qte, $isAcc) {
		$this->product_id = $row['IDPRODUCT'];
		$this->product_nom = $row['NOM'];
		$this->product_descshort = $row['DESCSHORT'];
		$this->product_navnom = $row['NAVNOM'];
		$this->product_navnom_urlparents = $row['NAVNOM_URLPARENTS'];
		$this->product_url = $row['URL'];
		$this->product_isPromo = $row['isPROMO'];
		$this->product_brend_id = $row['IDBREND'];
		$this->product_isBrend = $row['isSHOWBREND'];
		$this->product_category_id = $row['IDCATEGORY'];
		$this->product_promo_date = $row['DATEPROMO'];
			
		$this->item_id = $row['IDCHILD'];
		$this->item_reference = $row['REFERENCE'];
		$this->item_designation = $row['DESIGNATION'];
		$this->item_stock  = $row['STOCK'];
		$this->item_isPromo  = $row['isPROMOCHILD'];
		$this->item_isDevis  = $row['isDEVIS'];
		$this->item_poids  = $row['POIDS'];
		$this->item_isFrancoDenied  = $row['isFRANCODENIED'];
		$this->item_qte_min  = $row['QUANTITYMIN'];
			
		/*Recuperation du prix degressif*/
		$productChildQte = new ProductChildQte();
		$currentPrice = $productChildQte->getCurrentPrice($row['IDCHILD'], $qte, $row['PRIX']);
		$this->item_prix = sprintf("%.2f",$currentPrice);
		//$this->item_prix = sprintf("%.2f",$row['PRIX']);
			
		$this->item_qte = $qte;
		$this->item_isAccessoire = $isAcc;
		
		$optionList = new OptionList();
		$this->item_optionsByList = $optionList->getByIdProduct($row['IDPRODUCT']);
		$this->item_nbpointfidelite  = $row['POINTFIDELITE'];
	}

	public function toString() {
		return $this->product_nom." - ".$this->item_id." : ".$this->item_qte."<br>";
	}

	public function isAccessoire() {
		if ($this->isAccessoire == "Y") { return true; }
		return false;
	}
	public function isPromo() {
		if ($this->item_isPromo == 0) { return true; }
		return false;
	}
	public function setPromo($value) {
		if ($value) {$this->item_isPromo = 0; } 
		else {$this->item_isPromo = 1;} 
	}
	public function setPromoCaddyType($value) {
		if ($value) {
			$this->item_isPromo = 0; 
			$this->isCaddyType = true;
			$this->item_isDevis = 1; 
		}  else {
			$this->isCaddyType = false;
			$this->caddytype_id = 0; 
		} 
	}
	 			
	public function isSurDevis() {
		if ($this->item_isDevis == 0) { return true; }
		return false;
	}
	public function isBrend() {
		if ($this->product_isBrend == 0) { return true; }
		return false;
	}
	public function isFrancoDenied() {
		if ($this->item_isFrancoDenied == 0) { return true; }
		return false;
	}
	
	public function isCaddyTypeActif() {
		if ($this->isCaddyType && $this->caddytype_isActif == 'Y') { return  true;}
		return false;
	}
    
	public function setFideliteGift($row) {
        $this->is_fidelite = true;
		$this->fidelite_nom = $row->nom;
		$this->fidelite_nbpoint = $row->nbpoint;
		$this->fidelite_id = $row->idFidelite;
    }
	public function isFideliteGift() {
		return $this->is_fidelite;
	}
}

?>
utils/ItemFidelite.php000060400000000755150715102030010756 0ustar00<?php 
class ItemFidelite { 
    var $idFidelite; 
    var $nom;  
    var $nbpoint; 
     
    function ItemFidelite() { }
    
    function getItemInfo($idfidelite) {
        $carteFidelite = new CarteFidelite();
        $result = $carteFidelite->getInfosEnableById($idfidelite);
        if (isset($result) && !empty($result)) {
            $this->nom = $result['TITRE'];
		    $this->nbpoint = $result['POINTFIDELITE'];
            $this->idFidelite = $result['ID'];
        }
    } 
}

?>
utils/ItemOptionList.php000060400000001165150715102030011331 0ustar00<?php
class ItemOptionList { 
	var $id;
	var $name;
	var $values; 
	var $valuesString;

	function ItemOptionList() {
		$this->name = '';
		$this->values = array();
	} 
	function init($option) {
		if (!empty($option)) {  
			$valeurs = explode("::", $option['VALUE']); 
		 	$this->id = $option['ID'];
		 	$this->name = $option['NAME'];
		 	$this->valuesString = $option['VALUE'];
		 	foreach ($valeurs as $opt) {  array_push($this->values, $opt); } 
		} 
	} 
	function valuesHTML() {
		$result = '';
		if (!empty($this->values)) {  
		 	foreach ($this->values as $opt) { $result .= $opt.'<br/>';} 
		} 
		return $result;
	} 
}

?>ProductCategory2.php000060400000006135150715102030010450 0ustar00<?php
class ProductCategory2 extends Zend_Db_Table
{
	protected $_name = 'category2_product';
	protected $_primary = 'ID';
 
	public function getProductsByCategoryID($id) {
		$select = "SELECT p.*, cp2.ID IDPRODCAT2, pic.URL URL
				FROM category2_product cp2
				LEFT JOIN product AS p ON cp2.IDPRODUCT = p.ID
				LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID
				WHERE cp2.IDCATEGORY = ".$id." AND p.isACTIVE = 0
				AND pic.POSITION = 1"; 
		return $this->getAdapter()->fetchAll($select);
	}
	
	public function getAllProductsByCategoryID($id) {
		$select = "SELECT p.*, cp2.ID IDPRODCAT2
				FROM category2_product cp2
				LEFT JOIN product AS p ON cp2.IDPRODUCT = p.ID
				WHERE cp2.IDCATEGORY = ".$id;
		
		return $this->getAdapter()->fetchAll($select);
	}
	
	public function getAllProductsInfoByCategoryID($id, $triSql) { 
		$select = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM PRODNAVNOM,p.NAVTITRE NAVTITRE, p.NAVDESC NAVDESC, p.DESCRIPTIONSHORT DESCSHORT, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
							p.isPROMO isPROMO, pic.URL URL, sb.BREND BREND, sb.ID BRENDID, sb.URL BRENDURL, COUNT(pc.REFERENCE) NBREFERENCE, 
							c.NAVNOM CATNAVNOM, c.ID CATID, p.isSHOWBREND isSHOWBREND, p.KEYWORDS KEYWORDS_PROD,
							p.IDCATEGORY_DUP1 IDCATEGORY_DUP1,	p.IDCATEGORY_DUP2 IDCATEGORY_DUP2, p.IDCATEGORY_DUP3 IDCATEGORY_DUP3, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS	,						
							c.NOM CATNOM, p.BOOSTED_BESTSELLER BOOSTED_BESTSELLER
                            FROM category2_product cp2
							LEFT JOIN product AS p ON cp2.IDPRODUCT = p.ID
							LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
							LEFT JOIN category2 c ON c.ID = cp2.IDCATEGORY  
							LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
							LEFT JOIN productchild pc ON pc.IDPRODUCT = p.ID
							WHERE cp2.IDCATEGORY = ".$id." 
							AND p.isACTIVE = 0
							AND pic.POSITION = 1
							GROUP BY ID
							ORDER BY ".$triSql; 
		return $this->getAdapter()->fetchAll($select);
	}
		 
	public function getAllProductsByCategoryIDList($listIds) {
		$select = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM PRODNAVNOM,p.NAVTITRE NAVTITRE, p.NAVDESC NAVDESC, p.DESCRIPTIONSHORT DESCSHORT, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
							p.isPROMO isPROMO, pic.URL URL, sb.BREND BREND, sb.ID BRENDID, sb.URL BRENDURL, COUNT(pc.REFERENCE) NBREFERENCE, 
							c.ID CATID, p.isSHOWBREND isSHOWBREND, p.KEYWORDS KEYWORDS_PROD,
							p.IDCATEGORY_DUP1 IDCATEGORY_DUP1,	p.IDCATEGORY_DUP2 IDCATEGORY_DUP2, p.IDCATEGORY_DUP3 IDCATEGORY_DUP3 
							FROM category2_product c 
							LEFT JOIN product p ON c.IDPRODUCT = p.ID
							LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
							LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
							LEFT JOIN productchild pc ON pc.IDPRODUCT = p.ID
				WHERE c.IDCATEGORY IN (".$listIds.") 
				AND p.isACTIVE = 0
				AND pic.POSITION = 1"; 
		return $this->getAdapter()->fetchAll($select);
	}
	 
	public function getAllCategoriesByProductID($id) {
		$select = "SELECT c2.*, cp2.ID IDPRODCAT2
				FROM category2_product cp2
				LEFT JOIN category2 AS c2 ON cp2.IDCATEGORY = c2.ID
				WHERE cp2.IDPRODUCT = ".$id;
		
		return $this->getAdapter()->fetchAll($select);
	}
	
	 
}
?>ClickStats.php000060400000002136150715102030007311 0ustar00<?php
class ClickStats extends Zend_Db_Table
{
    protected $_name = 'click_stats';
    protected $_primary = 'ID';
	
	public function getIPStats() {
		$select = "
				SELECT c.IP Ip, c.SOURCE Source, COUNT(c.SOURCE) NbSource
				FROM click_stats AS c
				GROUP BY c.IP, c.SOURCE
				ORDER BY NbSource DESC;";
		return $this->getAdapter()->fetchAll($select);
	}
	
	public function getSourceStats() {
		$select = "
				SELECT c.SOURCE Source, COUNT(c.SOURCE) NbSource
				FROM click_stats AS c
				GROUP BY c.SOURCE
				ORDER BY c.SOURCE ASC;";
		
		return $this->getAdapter()->fetchAll($select);
	}
	

	
	public function getClickDetail() {
		$select = "
				SELECT c.IP IP,c.DATEINSERT DATEINSERT, c.SOURCE SOURCE, c.URL URL, COUNT(c.URL) NbURL
				FROM click_stats AS c
				GROUP BY IP, URL
				ORDER BY c.URL ASC;";
		
		return $this->getAdapter()->fetchAll($select);
	}
	

	
	public function getProductDetail() {
		$select = "
				SELECT c.SOURCE SOURCE, c.URL URL, COUNT(c.URL) NbURL
				FROM click_stats AS c
				GROUP BY URL
				ORDER BY NbURL DESC;";
		
		return $this->getAdapter()->fetchAll($select);
	}
}
?>ProductChildFTFDS.php000060400000000703150715102030010416 0ustar00<?php
class ProductChildFTFDS extends Zend_Db_Table
{
    protected $_name = 'productchild_ftfds';
    protected $_primary = 'ID';

	public function getFTFDSByIdProduct($id) {
    	$select = "
						SELECT pcftfds.ID_CHILD ID_CHILD ,pcftfds.URL URL
							FROM productchild_ftfds AS pcftfds 
						LEFT JOIN productchild AS pc ON pcftfds.ID_CHILD = pc.ID
						WHERE pc.IDPRODUCT = ".$id;
    	return $this->getAdapter()->fetchAll($select);
    }
}
?>PromoCommand.php000060400000002251150715102030007636 0ustar00<?php
class PromoCommand extends Zend_Db_Table
{
    protected $_name = 'promo_command';
    protected $_primary = 'ID';

	/*
	 * Remise selon le nombre de produits
	 */
    public function getRemiseCommandByProductQte($reference, $qte) {   try {
    	return $this->select()->where("CHILDREFERENCE = ?", $reference)->where("CHILDNBR <= ?", $qte)->query()->fetch(); 
   		} catch (Zend_Exception $e) { return array(); }
    }
    
    /*
	 * Remise selon le TOTAL HT
	 */
    public function getRemiseCommandByTotalHT($totalHT) { try {
    	return $this->select()->where("MONTANTEQUAL < ?", $totalHT)->order('MONTANTEQUAL DESC')->query()->fetch(); 
   		} catch (Zend_Exception $e) { return array(); }
    }
     
    /*
	 * Remise de toute les commandes
	 */
    public function getRemiseCommandByAll() { try {
    	return $this->select()->where("isALL IS NOT NULL")->query()->fetch();  
   		} catch (Zend_Exception $e) { return array(); }
    }
     
    /*
	 * Si la commande est valid
	 */
    public function getCommandValid() { try {
    	return $this->select()->where('MONTANTVALID IS NOT NULL')->query()->fetch();  
   		} catch (Zend_Exception $e) { return array(); }
    }
     
}
?>LogAdmin.php000060400000000166150715102030006740 0ustar00<?php
class LogAdmin extends Zend_Db_Table
{
    protected $_name = 'log_admin';
    protected $_primary = 'ID';

}
?>AnnonceFrontHeader.php000060400000000600150715102030010742 0ustar00<?php
class AnnonceFrontHeader extends Zend_Db_Table
{
    protected $_name = 'annonce_front_header';
    protected $_primary = 'ID';

    public function getAnnonces() {
    	return $this->select()->where('isSHOW = 0')->order('NOM ASC')->query()->fetchAll();
	}
	

    public function getAllAnnonces() {
    	return $this->select()->order('NOM ASC')->query()->fetchAll();
	}
	
	
}
?>StatsSearch.php000060400000000617150715102030007473 0ustar00<?php
class StatsSearch extends Zend_Db_Table
{
    protected $_name = 'stats_search';
    protected $_primary = 'ID';


public function statsKeyWordYear() {
		$sql = "SELECT COUNT( 1 ) AS NB, VALUE
				FROM stats_search
				WHERE DATE( DATESTART ) >= DATE(  '".date('Y')."-01-01' ) 
				GROUP BY VALUE
				ORDER BY NB DESC 
				LIMIT 0 , 30";
		return $this->getAdapter()->fetchAll($sql);
	}
	
}
?>BlogCategory.php000060400000003517150715102030007632 0ustar00<?php
class BlogCategory extends Zend_Db_Table
{
    protected $_name = 'blogs_categories';
    protected $_primary = 'id'; 

    public function AllCategories($idParent) {

        $sql = "
		SELECT c0.title title0, c1.title title1, c2.title title2,
				c0.is_close is_close0, c1.is_close is_close1, c2.is_close is_close2,
				c0.is_publish is_publish0, c1.is_publish is_publish1, c2.is_publish is_publish2,
				c0.id id0, c1.id id1, c2.id id2,
				c0.id_parent id_parent0, c1.id_parent id_parent1, c2.id_parent id_parent2
		FROM blogs_categories AS c0
		LEFT JOIN blogs_categories AS c1 ON c1.id_parent = c0.ID
		LEFT JOIN blogs_categories AS c2 ON c2.id_parent = c1.ID
		WHERE c0.id_parent = ".$idParent."
		ORDER BY c0.id ,c1.id, c2.id ASC; "; 
		return $this->getAdapter()->fetchAll($sql);

    }
    public function getAllActivesCategories($id) {  
    	return $this->select()->where("is_publish = ?", 1)->where("id_parent = ?", $id) 
        ->order('title ASC')->query()->fetchAll(); 
	}  

         /*
    public function search($data) {  
        $title = empty($data['title']) ? "%" : "%".$data['title']."%";
    	return $this->select()->where("type = ?", $data['type'])->where("title like ?", $title)     
        ->where("is_publish = ?", $data['is_publish'])
        ->where("is_close = ?", $data['is_close'])
        ->order('title ASC')->query()->fetchAll(); 
	} 
     
    public function getAllActivesSubjects() {  
    	return $this->select()->where("type = ?", 2)->where("is_publish = ?", true)   
        ->order('title ASC')->query()->fetchAll(); 
	}   
    public function categoriesAll() {  
    	return $this->select()->where("type = ?", 1)->order('title ASC')->query()->fetchAll(); 
	}  
    public function subjectsAll() {  
    	return $this->select()->where("type = ?", 2)->order('title ASC')->query()->fetchAll(); 
	}  */
    
    
    
}
?>LivraisonPoids.php000060400000002322150715102030010207 0ustar00<?php
class LivraisonPoids extends Zend_Db_Table
{
    protected $_name = 'livraison_poids';
    protected $_primary = 'ID';

    public function getLists() {
    	return $this->select()->order('FROM ASC')->query()->fetchAll();
	}
	
	public function getGoodPrice($type, $poidsTotal) {
		$myresult = array();
		try {
			$sql = "
				SELECT lp.PRICE PRICE, lt.CMDFRANCO CMDFRANCO, lt.NOM NOMLIV
				FROM livraison_poids lp
				LEFT JOIN livraison_type lt ON lt.ID = lp.TYPE 
				WHERE lp.TYPE = ".$type."
				AND lp.FROM <= ".$poidsTotal."
				AND lp.TO >= ".$poidsTotal;
			$results = $this->getAdapter()->fetchAll($sql);
			if (isset($results) && !empty($results)) {
				foreach ($results as $result) {
					$myresult['PRICE'] = $result['PRICE'];
					$myresult['CMDFRANCO'] = $result['CMDFRANCO'];
					$myresult['NOMLIV'] = $result['NOMLIV'];
					break;
				}
			} else {
				$sql = "
					SELECT lt.CMDFRANCO CMDFRANCO, lt.NOM NOMLIV
					FROM livraison_type lt
					WHERE lt.ID = ".$type;
				$result = $this->getAdapter()->fetchRow($sql);
				$myresult['PRICE'] = 0;
				$myresult['CMDFRANCO'] = $result['CMDFRANCO'];
				$myresult['NOMLIV'] = $result['NOMLIV'];
			}
		} catch (Zend_Exception $e) {}
		return $myresult;
	}
}
?>PromoProduct.php000060400000003034150715102030007700 0ustar00<?php
class PromoProduct extends Zend_Db_Table
{
    protected $_name = 'promo_productchild';
    protected $_primary = 'ID';

    /*
	 * Promotion selon la reference d'un produit
	 */
    public function getRemiseByProductReference($reference) { 
    	try { return $this->select()->where("REFERENCE = ?", $reference)->query()->fetch();
    	} catch (Zend_Exception $e) { return array(); }
	}
    
    /*
	 * Promotion selon la marque d'un produit
	 */
    public function getRemiseByProductBrend($idbrend) {   
		try {
    		return $this->select()->where("IDBREND = ?", $idbrend)->query()->fetch();
   		} catch (Zend_Exception $e) { return array(); }
    }
    
    /*
	 * Promotion selon la category d'un produit
	 */
    public function getRemiseByProductCategory($idcategory) {  
    	try { return $this->select()->where("IDCATEGORY = ?", $idcategory)->query()->fetch();
   		} catch (Zend_Exception $e) { return array(); }
    } 
    
    /*
	 * Promotion selon la qte d'un produit
	 */
    public function getRemisesByProductQte($reference, $qte) {
    	try { return $this->select()->where("CHILDREFPROMO = ?", $reference)->where("CHILDREFPROMONB <= ?", $qte)->query()->fetchAll();
   		} catch (Zend_Exception $e) { return array(); } 
	 }
    
    /*
	 * Promotion selon la date de promotion d'un produit
	 */
    public function getRemiseByProductDateBetween($date) {
    	try { return $this->select()->where("DATEPROMOSTART <= ?", $date)->where("DATEPROMOEND >= ?", $date)->query()->fetch(); 
   		} catch (Zend_Exception $e) { return array(); }
	 }
}
?>AnnonceGallerie.php000060400000001205150715102030010267 0ustar00<?php
class AnnonceGallerie extends Zend_Db_Table
{
    protected $_name = 'annonce_gallery';
    protected $_primary = 'ID';

    public function getAnnonces() {
    	return $this->select()->where('isSHOW = 0')->order('POSITION ASC')->order('NOM ASC')->query()->fetchAll();
	}
	

    public function getAllAnnonces() {
    	return $this->select()->order('POSITION ASC')->order('NOM ASC')->query()->fetchAll();
	}
	
 	public function getAnnoncesByShow($idCat) {
 		return $this->select()->where('isSHOW = 0')->where("ID_CATS LIKE '%:".$idCat.":%' OR ID_CATS LIKE '%:0:%' ")->order('POSITION ASC')->order('NOM ASC')->query()->fetchAll();
 	}
}
?>User.php000060400000000607150715102030006164 0ustar00<?php
class User extends Zend_Db_Table
{
    protected $_name = 'user';
    protected $_primary = 'ID';

 	public function getUserByID($userID) {   
    	$result = $this->select()->where("ID = ?", $userID)->query()->fetch();	
        
        $carteFidelite = new CarteFidelite();
        $result['POINTFIDELITE'] = $carteFidelite->getInfosByUser($userID);
        return $result;
    }
}
?>UserCaddyType.php000060400000020117150715102030007771 0ustar00<?php
class UserCaddyType extends Zend_Db_Table
{
	protected $_name = 'user_caddytype';
	protected $_primary = 'ID';

	/*
	 * Recupere le caddy
	 */
	public function getCaddyTypeByUser($iduser) {
		return $this->select()->where("USERID = ?", $iduser)->query()->fetchAll();
	}

	public function getArticleByCaddyIdList($idList) {
		$sql = "SELECT uct.ID CADDYTYPEID, uct.REFERENCE REFERENCE, uct.USERID USERID, uct.REMISEEURO REMISEEURO, uct.REMISEPOUR REMISEPOUR, uct.isACTIF isCADDYTYPE_ACTIF,
    			u.NOM USERNOM, u.PRENOM USERPRENOM, 
    			pc.ID IDCHILD, pc.isDEVIS isDEVIS, pc.isPROMO isPROMOCHILD, pc.PRIX PRIX, pc.DESIGNATION DESIGNATION, 
    			pc.QUANTITYMIN QUANTITYMIN, pc.POIDS POIDS, pc.isFRANCODENIED isFRANCODENIED,
				p.NOM NOM,p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.ID IDPRODUCT, pic.URL URL,p.isPROMO isPROMO,
    			p.STOCK STOCK, p.IDCATEGORY IDCATEGORY, p.IDBREND IDBREND, p.isSHOWBREND isSHOWBREND, p.DATEPROMO DATEPROMO, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS,
				pc.POINTFIDELITE POINTFIDELITE 
                FROM user_caddytype AS uct
				LEFT JOIN user AS u ON uct.USERID = u.ID 
				LEFT JOIN productchild AS pc ON uct.REFERENCE = pc.REFERENCE
				LEFT JOIN product p ON pc.IDPRODUCT = p.ID
				LEFT JOIN category c ON p.IDCATEGORY= c.ID
				LEFT JOIN picture pic ON pc.IDPRODUCT = pic.IDPRODUCT
				WHERE uct.ID IN (".$idList.") 
				AND pic.POSITION = 1
				AND uct.isACTIF = 'Y' 
				AND p.isACTIVE = 0 
				ORDER BY uct.REFERENCE ASC";   
		return $this->getAdapter()->fetchAll($sql);
	}


	public function getArticleByCaddyId($id) {
		$sql = "SELECT uct.ID CADDYTYPEID, uct.REFERENCE REFERENCE, uct.USERID USERID, uct.REMISEEURO REMISEEURO, uct.REMISEPOUR REMISEPOUR, uct.isACTIF isCADDYTYPE_ACTIF,
    			u.NOM USERNOM, u.PRENOM USERPRENOM, 
    			pc.ID IDCHILD, pc.isDEVIS isDEVIS, pc.isPROMO isPROMOCHILD, pc.PRIX PRIX, pc.DESIGNATION DESIGNATION, 
    			pc.QUANTITYMIN QUANTITYMIN, pc.POIDS POIDS, pc.isFRANCODENIED isFRANCODENIED,
				p.NOM NOM,p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.ID IDPRODUCT, pic.URL URL,p.isPROMO isPROMO,
    			p.STOCK STOCK, p.IDCATEGORY IDCATEGORY, p.IDBREND IDBREND, p.isSHOWBREND isSHOWBREND, p.DATEPROMO DATEPROMO, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
				,pc.POINTFIDELITE POINTFIDELITE 
                FROM user_caddytype AS uct
				LEFT JOIN user AS u ON uct.USERID = u.ID 
				LEFT JOIN productchild AS pc ON uct.REFERENCE = pc.REFERENCE
				LEFT JOIN product p ON pc.IDPRODUCT = p.ID
			    LEFT JOIN category c ON p.IDCATEGORY = c.ID
				LEFT JOIN picture pic ON pc.IDPRODUCT = pic.IDPRODUCT
				WHERE uct.ID = ".$id." 
				AND pic.POSITION = 1
				AND uct.isACTIF = 'Y' 
				AND p.isACTIVE = 0
				ORDER BY uct.REFERENCE ASC"; 
		return $this->getAdapter()->fetchRow($sql);
	}

	public function getCaddyTypeByUserFull($iduser) {
		$sql = "SELECT uct.ID CADDYTYPEID, uct.REFERENCE REFERENCE, uct.USERID USERID, uct.REMISEEURO REMISEEURO, uct.REMISEPOUR REMISEPOUR, uct.isACTIF isCADDYTYPE_ACTIF,
    			u.NOM USERNOM, u.PRENOM USERPRENOM, 
    			pc.ID IDCHILD, pc.isDEVIS isDEVIS, pc.isPROMO isPROMOCHILD, pc.PRIX PRIX, pc.DESIGNATION DESIGNATION, 
    			pc.QUANTITYMIN QUANTITYMIN, pc.POIDS POIDS, pc.isFRANCODENIED isFRANCODENIED,
				p.NOM NOM,p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.ID IDPRODUCT, pic.URL URL,p.isPROMO isPROMO,
    			p.STOCK STOCK, p.IDCATEGORY IDCATEGORY, p.IDBREND IDBREND, p.isSHOWBREND isSHOWBREND, p.DATEPROMO DATEPROMO, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
				,pc.POINTFIDELITE POINTFIDELITE 
                FROM user_caddytype AS uct
				LEFT JOIN user AS u ON uct.USERID = u.ID 
				LEFT JOIN productchild AS pc ON uct.REFERENCE = pc.REFERENCE
				LEFT JOIN product p ON pc.IDPRODUCT = p.ID
			    LEFT JOIN category c ON p.IDCATEGORY = c.ID
				LEFT JOIN picture pic ON pc.IDPRODUCT = pic.IDPRODUCT
				WHERE uct.USERID = ".$iduser." 
				AND pic.POSITION = 1
				ORDER BY uct.REFERENCE ASC"; 
		return $this->getAdapter()->fetchAll($sql);
	}
	public function getCaddyTypeActiveByUserFull($iduser) { 
		$sql = "SELECT uct.ID CADDYTYPEID, uct.REFERENCE REFERENCE, uct.USERID USERID, uct.REMISEEURO REMISEEURO, uct.REMISEPOUR REMISEPOUR, uct.isACTIF isCADDYTYPE_ACTIF,
    			u.NOM USERNOM, u.PRENOM USERPRENOM, 
    			pc.ID IDCHILD, pc.isDEVIS isDEVIS, pc.isPROMO isPROMOCHILD, pc.PRIX PRIX, pc.DESIGNATION DESIGNATION, 
    			pc.QUANTITYMIN QUANTITYMIN, pc.POIDS POIDS, pc.isFRANCODENIED isFRANCODENIED,
				p.NOM NOM,p.NAVNOM NAVNOM, p.DESCRIPTIONSHORT DESCSHORT, p.ID IDPRODUCT, pic.URL URL,p.isPROMO isPROMO,
    			p.STOCK STOCK, p.IDCATEGORY IDCATEGORY, p.IDBREND IDBREND, p.isSHOWBREND isSHOWBREND, p.DATEPROMO DATEPROMO, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
				,pc.POINTFIDELITE POINTFIDELITE 
                FROM user_caddytype AS uct
				LEFT JOIN user AS u ON uct.USERID = u.ID 
				LEFT JOIN productchild AS pc ON uct.REFERENCE = pc.REFERENCE
				LEFT JOIN product p ON pc.IDPRODUCT = p.ID
			    LEFT JOIN category c ON p.IDCATEGORY = c.ID
				LEFT JOIN picture pic ON pc.IDPRODUCT = pic.IDPRODUCT
				WHERE uct.USERID = ".$iduser." 
				AND pic.POSITION = 1
				AND uct.isACTIF = 'Y'
				AND p.isACTIVE = 0 
				ORDER BY uct.REMISEEURO DESC,uct.REMISEPOUR DESC "; 
		return $this->getAdapter()->fetchAll($sql);
	}

	public function computeCaddyTypeByUser($iduser, $isQteTotal) {
		$results = $this->getCaddyTypeByUserFull($iduser);
		if ($results) {
			$facture = new Facture();
			$command = new Command();
			foreach ($results as $row) {
				if (empty($facture->user_id)) {
					$facture->user_id = $row['USERID'];
					$facture->user_nom = $row['USERNOM'];
					$facture->user_prenom = $row['USERPRENOM'];
				}
					
				$factureLine = new FactureLine();
				$factureLine->setLineInfo($row, 0, "N");
				$factureLine->isCaddyType = true;
				$factureLine->caddytype_id = $row['CADDYTYPEID'];
				$factureLine->caddytype_isActif = $row['isCADDYTYPE_ACTIF'];
				if ($isQteTotal) {
					$factureLine->caddytype_qte_total = $command->getTotalQteByReferenceAndUser($iduser, $factureLine->item_reference);
				}

				if ($row['REMISEEURO'] > 0) { $factureLine->remise_euro = $row['REMISEEURO']; $factureLine->setPromo(true);}
				else if ($row['REMISEPOUR'] > 0) { $factureLine->remise_pour = $row['REMISEPOUR']; $factureLine->setPromo(true);}
				else {$factureLine->setPromo(false);}

				$facture->addLine($factureLine);
			}
			return $facture;
		}
		return false;
	}

	public function computeFrontCaddyTypeByUser($user, $caddy, $isPromo) {
		$results = $this->getCaddyTypeActiveByUserFull($user['id']);
		if ($results) {
			$itemsListType = array();
			foreach ($results as $row) {
				$itemCaddyType = new ItemCaddyType();
				$itemCaddyType->setLineInfo($row, 0);
				
				if ($itemCaddyType->isPromo()) {
					$itemCaddyType->isPromoCaddyType = true;
					if (!empty($caddy) && !empty($caddy->itemsCaddyType)) {
						foreach ($caddy->itemsCaddyType as $caddyLine) {
							if ($caddyLine->id == $row['CADDYTYPEID']) {
								$itemCaddyType->qte = $caddyLine->qte;
								break;
							}
						}
					}
				} else {
					//On recup la qte du caddy normal
					if (!empty($caddy) && !empty($caddy->items)) {
						foreach ($caddy->items as $caddyLine) {
							if ($caddyLine->idChild == $row['IDCHILD']) {
								$itemCaddyType->qte = $caddyLine->qteChild;
								break;
							}
						}
					}
				}
				array_push($itemsListType, $itemCaddyType);
			}
				
			if ($isPromo && isset($itemsListType) && !empty($itemsListType)) {
				$promo = new PromoCalculator();
				$promo->computeItemsPromosCaddyType($itemsListType, $user);
			}
			return $itemsListType;
		}
		return false;
	}

	public function addNewUserItem($reference, $userid) {
		if (!empty($reference) &&  (int)$userid > 0 ) {
			if (!$this->isReferenceExist($reference, $userid)) {
				$data = array (
 		 						'REFERENCE' => $reference,
								'USERID' => $userid,
								'REMISEEURO' => 0,
						 		'REMISEPOUR' => 0,
						 		'isACTIF' => 'Y' 
						 		);
						 		$this->insert($data);
			}
		}
	}

	public function isReferenceExist($reference, $userid) {
		$result = $this->select()->where("USERID = ?", $userid)->where("REFERENCE = ?", $reference)->query()->fetch();
		if ($result) { return true; }
		return false;
	}
}
?>PaypalPaiement.php000060400000000202150715102030010146 0ustar00<?php
class PaypalPaiement extends Zend_Db_Table
{
    protected $_name = 'paiement_paypal';
    protected $_primary = 'ID';

}
?>KeyMap.php000060400000023301150715102030006430 0ustar00<?php
class KeyMap extends Zend_Db_Table
{
    protected $_name = 'key_map';
    protected $_primary = 'ID';

	public function getKeyCleaned($words, $nb) {
		$result = explode(",", $words);
		return array_slice($result, 0, $nb, true);
	}

    public function getKeyByPositionAndCatId($idCat, $listIds) {    
    	$selectCat = "
				SELECT c.NOM CAT_NOM, c.NAVNOM CAT_NAVNOM, c.DESCRIPTION CAT_DESCRIPTION, c.ID CAT_ID, c.KEYWORDS KEYWORDS, c.NAVNOM_URLPARENTS CAT_NAVNOM_URLPARENTS
				FROM category AS c
				WHERE c.ID IN (".$listIds.")
				GROUP BY c.ID
				LIMIT 0 , 10;";
    	$result =  $this->getAdapter()->fetchAll($selectCat);
    	

    	$catIds = explode(",", $listIds);
    	if (sizeof($catIds) == 1) {
    		$selectProd = "
				SELECT c.NOM CAT_NOM, c.NAVNOM CAT_NAVNOM, c.DESCRIPTION CAT_DESCRIPTION, c.ID CAT_ID, p.KEYWORDS KEYWORDS,
				p.NAVNOM PROD_NAVNOM, p.ID PROD_ID, c.NAVNOM_URLPARENTS CAT_NAVNOM_URLPARENTS
    				FROM category AS c
				LEFT JOIN product AS p ON p.IDCATEGORY = c.ID
    			WHERE c.ID = ".$idCat." 
				LIMIT 0 , 10;";
    		$result2 = $this->getAdapter()->fetchAll($selectProd);
    		$result = array_merge((array)$result, (array)$result2);
    	}
    	return $result;
    }
    
	public function getAllByPOSITION() {
		$selectCat = "
				SELECT k.ID ID, k.CATID CATID, k.POSITION POSITION, k.SIZE SIZE,k.COLOR COLOR, k.TYPE TYPE, k.isSHOW isSHOW,
				c.NOM CAT_NOM, c.NAVNOM CAT_NAVNOM, c.DESCRIPTION CAT_DESCRIPTION
				FROM key_map AS k
				LEFT JOIN category AS c ON c.ID = k.CATID
				WHERE k.isSHOW = 1 AND 
				k.TYPE = 'CAT'
				ORDER BY k.POSITION ASC
				LIMIT 0 , 20;";
		
		$selectBrend = "
				SELECT k.ID ID, k.BRENDID BRENDID, k.POSITION POSITION, k.SIZE SIZE,k.COLOR COLOR, k.TYPE TYPE, k.isSHOW isSHOW,
				b.BREND BREND_NOM
				FROM key_map AS k
				LEFT JOIN supplier_brend AS b ON b.ID = k.BRENDID
				WHERE k.isSHOW = 1 AND 
				k.TYPE = 'BREND'
				ORDER BY k.POSITION ASC
				LIMIT 0 , 20;";

			$listCat = $this->getAdapter()->fetchAll($selectCat);
			
			$listMap = array();
			$i = 0;	
					
			foreach ($listCat as $row) {
				$listMap[$i]['ID'] = $row['ID'];
				$listMap[$i]['CATID'] = $row['CATID'];
				$listMap[$i]['SIZE'] = $row['SIZE'];
				$listMap[$i]['TYPE'] = $row['TYPE'];
				$listMap[$i]['isSHOW'] = $row['isSHOW'];
				$listMap[$i]['COLOR'] = $row['COLOR'];
				$listMap[$i]['CAT_NAVNOM'] = $row['CAT_NAVNOM'];
				$listMap[$i]['CAT_DESCRIPTION'] = $row['CAT_DESCRIPTION'];
				$listMap[$i]['TITRE'] = $row['CAT_NOM'];
				$i++;
			}
			
			$listBrend = $this->getAdapter()->fetchAll($selectBrend);
			foreach ($listBrend as $row) {
				$listMap[$i]['ID'] = $row['ID'];
				$listMap[$i]['BRENDID'] = $row['BRENDID'];
				$listMap[$i]['SIZE'] = $row['SIZE'];
				$listMap[$i]['TYPE'] = $row['TYPE'];
				$listMap[$i]['COLOR'] = $row['COLOR'];
				$listMap[$i]['isSHOW'] = $row['isSHOW'];
				$listMap[$i]['TITRE'] = $row['BREND_NOM'];
				$i++;
			}
		return $listMap;
	}
	
public function getAllByCAT() {
		$select = "
				SELECT k.ID ID, k.CATID CATID, k.POSITION POSITION,k.COLOR COLOR, k.SIZE SIZE, k.TYPE TYPE, k.isSHOW isSHOW, k.VIEW VIEW,
				c.NOM CAT_NOM, c.NAVNOM CAT_NAVNOM, c.DESCRIPTION CAT_DESCRIPTION
				FROM key_map AS k
				LEFT JOIN category AS c ON c.ID = k.CATID
				ORDER BY c.NOM ASC";
		
			$listTemp = $this->getAdapter()->fetchAll($select);
			
			$listMap = array();
			foreach ($listTemp as $row) {
					$listMap[$row['CATID']]['ID'] = $row['ID'];
					$listMap[$row['CATID']]['CATID'] = $row['CATID'];
					$listMap[$row['CATID']]['POSITION'] = $row['POSITION'];
					$listMap[$row['CATID']]['SIZE'] = $row['SIZE'];
					$listMap[$row['CATID']]['TYPE'] = $row['TYPE'];
					$listMap[$row['CATID']]['isSHOW'] = $row['isSHOW'];
					$listMap[$row['CATID']]['COLOR'] = $row['COLOR'];
					$listMap[$row['CATID']]['VIEW'] = $row['VIEW'];
					$listMap[$row['CATID']]['CAT_NOM'] = $row['CAT_NOM'];
					$listMap[$row['CATID']]['CAT_NAVNOM'] = $row['CAT_NAVNOM'];
					$listMap[$row['CATID']]['CAT_DESCRIPTION'] = $row['CAT_DESCRIPTION'];
			}
			return $listMap;
	}
	

public function getAllByBREND() {
		$select = "
				SELECT k.ID ID, k.BRENDID BRENDID, k.POSITION POSITION,k.COLOR COLOR, k.SIZE SIZE, k.TYPE TYPE, k.isSHOW isSHOW, k.VIEW VIEW,
				b.BREND BREND_NOM
				FROM key_map AS k
				LEFT JOIN supplier_brend AS b ON b.ID = k.BRENDID
				ORDER BY b.BREND ASC;";
		
			$listTemp = $this->getAdapter()->fetchAll($select);
			
			$listMap = array();
			foreach ($listTemp as $row) {					
					$listMap[$row['BRENDID']]['ID'] = $row['ID'];
					$listMap[$row['BRENDID']]['BRENDID'] = $row['BRENDID'];
					$listMap[$row['BRENDID']]['POSITION'] = $row['POSITION'];
					$listMap[$row['BRENDID']]['SIZE'] = $row['SIZE'];
					$listMap[$row['BRENDID']]['TYPE'] = $row['TYPE'];
					$listMap[$row['BRENDID']]['COLOR'] = $row['COLOR'];
					$listMap[$row['BRENDID']]['VIEW'] = $row['VIEW'];
					$listMap[$row['BRENDID']]['isSHOW'] = $row['isSHOW'];
					$listMap[$row['BRENDID']]['BREND_NOM'] = $row['BREND_NOM'];
			}
			return $listMap;
	}

public function getKeyByCatID($catID) {
		$select = "
				SELECT k.ID ID, k.CATID CATID, k.BRENDID BRENDID,k.COLOR COLOR, k.POSITION POSITION, k.SIZE SIZE, k.TYPE TYPE, k.isSHOW isSHOW,
				c.NOM CAT_NOM, c.NAVNOM CAT_NAVNOM, c.DESCRIPTION CAT_DESCRIPTION
				FROM key_map AS k
				LEFT JOIN category AS c ON c.ID = k.CATID
				WHERE k.CATID = ".$catID." 
				ORDER BY c.NOM ASC";

			$key = $this->getAdapter()->fetchRow($select);
						
			return $key;
	}
public function getKeyByBrendID($brendID) {
		$select = "
				SELECT k.ID ID, k.BRENDID BRENDID,k.COLOR COLOR, k.POSITION POSITION, k.SIZE SIZE, k.TYPE TYPE, k.isSHOW isSHOW,
				b.BREND BREND_NOM
				FROM key_map AS k
				LEFT JOIN supplier_brend AS b ON b.ID = k.BRENDID
				WHERE k.BRENDID = ".$brendID." 
				ORDER BY b.BREND ASC";

			$key = $this->getAdapter()->fetchRow($select);
			
			return $key;
	}

	private function computeKeySize($view) {
		if ($view < 1000) { return 10; }
		if ($view < 1500) { return 15; }
		if ($view < 2000) { return 20; }
		if ($view < 2500) { return 25; }
		if ($view < 3000) { return 30; }
		if ($view < 3500) { return 35; }
		return 40;
	}
	
	private function computeUrl() {
		
		    $controllerName = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
            $actionName = Zend_Controller_Front::getInstance()->getRequest()->getActionName();
            $paramArray = Zend_Controller_Front::getInstance()->getRequest()->getParams();
            $params = '';
            $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
            foreach($paramArray as $key => $value) {
                if($key <> "module" && $key <> "controller" && $key <> "action") {
                    $params .= $key . "/" . $value . "/";
                }
            }
            $url = $baseUrl."/" . $controllerName . "/" . $actionName . "/" . $params;
            
            return $url;	
	}
	
	private function computeSource() {
		
		    $paramArray = Zend_Controller_Front::getInstance()->getRequest()->getParams();
            $source = '';
            foreach($paramArray as $key => $value) {
                if ($key == "source") {
                	$source = $value;
                }
            }
            $result = 'Lien Direct';
            if ($source == 'hellopro') {
            	$result = "Redirection : Hello Pro";
            } 
            return $result;	
	}
	
	private function isIpBan($ip) {
		$paramIp = new ParamIp();
		$sql = "SELECT * FROM admin_param_ip WHERE isBAN = 1 AND IP = '".$ip."'";
		$result = $paramIp->getAdapter()->fetchAll($sql);
		
		if (!empty($result)) {
			return true;
		} 
		return false;
	}
private function logMe($message , $level) {
		$loggerDefault = Zend_Registry::get('loggerDefault');
		if ($level == 'info') {
			$loggerDefault->info($message);
		} elseif ($level == 'err') {
			$loggerDefault->err($message);
		} elseif ($level == 'warn') {
			$loggerDefault->warn($message);
		} elseif ($level == 'crit') {
			$loggerDefault->crit($message);
		}
	}
	
	public function updateCatEntry($catId) {
		$currentIp = $_SERVER['REMOTE_ADDR'];
		if (!$this->isIpBan($currentIp)) {	
			$select = "SELECT k.VIEW VIEW FROM key_map AS k WHERE k.CATID = ".$catId;
			$result = $this->getAdapter()->fetchRow($select);
			$view = ((int)$result['VIEW'])+1;
			//$size = $this->computeKeySize($view);
			$url = $this->computeUrl();
			
			$date = new Zend_Date();
			
			//$this->logMe("Click Cat : IP : ".$currentIp." <br> VIEW : ".$view." <br>  URL : ".$url." <br> DATE : ".$date->toString('YYYY-MM-dd HH:mm:ss')." <br> IDCAT : ".$catId,'info');
						
			if (!empty($result)) {
				$data = array(
		          'VIEW'  => $view
				   //'SIZE' => $size
		      	);
		        $this->getAdapter()->update('key_map', $data, 'CATID = '.$catId);
			}
			
			$clickStats = new ClickStats();
			$data = array(
		          'URL'  => $url,
				   'IP' => $currentIp,
					'DATEINSERT' => $date->toString('YYYY-MM-dd HH:mm:ss'),
					'SOURCE' => $this->computeSource()
		      	);
			$clickStats->insert($data);
		}
	}
	
	public function updateBrendEntry($brendId) {
		
		$currentIp = $_SERVER['REMOTE_ADDR'];
		if (!$this->isIpBan($currentIp)) {	
		
		$select = "SELECT k.VIEW VIEW FROM key_map AS k WHERE k.BRENDID = ".$brendId;
		$result = $this->getAdapter()->fetchRow($select);
		$view = ((int)$result['VIEW'])+1;
		//$size = $this->computeKeySize($view);
		
		$url = $this->computeUrl();
			$date = new Zend_Date();
		//$this->logMe("Click Brend : IP : ".$currentIp." <br> VIEW : ".$view." <br>  URL : ".$url." <br> DATE : ".$date->toString('YYYY-MM-dd HH:mm:ss')." <br> IDBREND : ".$brendId,'info');
			
		
		if (!empty($result)) {
			$data = array(
	          'VIEW'      => $view
			  // 'SIZE' => $size
	      	);
	        $this->getAdapter()->update('key_map', $data, 'BRENDID = '.$brendId);
		}
		}
	}
	
}
?>ProductAnnexe.php000060400000003546150715102030010032 0ustar00<?php
class ProductAnnexe extends Zend_Db_Table
{
	protected $_name = 'product_annexe';
	protected $_primary = 'ID';

	public function getAnnexesByProductID($id, $triSql) {
		$results = array();
		try {
			$select = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM NAVNOM,p.NAVTITRE NAVTITRE, p.NAVDESC NAVDESC, p.DESCRIPTIONSHORT DESCSHORT, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
							p.isPROMO isPROMO, pic.URL URL, sb.BREND BREND, sb.URL BRENDURL, COUNT(pc.REFERENCE) NBREFERENCE, 
							c.NAVNOM CATNAVNOM, p.isSHOWBREND isSHOWBREND, p.KEYWORDS KEYWORDS_PROD, c.ID CATID, sb.ID BRENDID, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS,
                            c.NOM CATNOM, p.BOOSTED_BESTSELLER BOOSTED_BESTSELLER 
							FROM product_annexe pa
							LEFT JOIN product AS p ON pa.IDANNEXE = p.ID 
							LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
							LEFT JOIN category c ON c.ID = p.IDCATEGORY 
							LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
							LEFT JOIN productchild pc ON pc.IDPRODUCT = p.ID 
							WHERE pa.IDPRODUCT = ".$id." 
							AND p.isACTIVE = 0
							AND pic.POSITION = 1
							GROUP BY ID
							ORDER BY ".$triSql;

			$results = $this->getAdapter()->fetchAll($select);
		} catch (Zend_Exception $e) { }
		return $results;
	}

	public function insertAnnexe($idproduct, $idannexe) {
		try {
			$select = "
				SELECT COUNT(pa.ID) NBR
				FROM product_annexe pa 
				WHERE pa.IDPRODUCT = ".$idproduct."
				AND pa.IDANNEXE = ".$idannexe; 
				
			$result = $this->getAdapter()->fetchRow($select);

			if ($result['NBR'] == 0) {
				$data = array (
	    			'IDPRODUCT' => $idproduct,
	    			'IDANNEXE' => $idannexe
				);
				$this->insert($data);
			}
		} catch (Zend_Exception $e) { }
	}

	public function deleteAnnexe($idproduct, $idannexe) {
		try {
			$this->delete("IDPRODUCT = ".$idproduct." AND IDANNEXE = ".$idannexe);
		} catch (Zend_Exception $e) { }
	}
}
?>AnnonceFooter.php000060400000000552150715102030010005 0ustar00<?php
class AnnonceFooter extends Zend_Db_Table
{
    protected $_name = 'annonce_footer';
    protected $_primary = 'ID';

    public function getAnnoncesByShow($isShow, $controller) {
    	return $this->select()->where('isSHOW = '.$isShow)->where("CONT_NAME LIKE '%".$controller."%' ")->order('isSHOW ASC')->order('TITRE ASC')->query()->fetchAll();
	}
	
	
}
?>CarteFidelite.php000060400000006775150715102030007766 0ustar00<?php
class CarteFidelite extends Zend_Db_Table
{
    protected $_name = 'carte_fidelite';
    protected $_primary = 'ID';

    public function getAnnoncesByShow($isShow) {
    	return $this->select()->where('isSHOW = '.$isShow)->order('isSHOW ASC')->order('POINTFIDELITE ASC')->query()->fetchAll();
	}
    
    public function isAnnonceAvailableForUser($iduser, $idFidelite) {
        $infoUser = $this->getInfosByUser($iduser);
        $sql = "select count(*) TOTAL from carte_fidelite cf
        where cf.POINTFIDELITE <= ".$infoUser['POINTFIDELITETOTAL']." 
        and cf.isSHOW = 1 
        and cf.ID = ".$idFidelite." 
        order by cf.POINTFIDELITE asc";
		$result = $this->getAdapter()->fetchRow($sql);
        if (isset($result) && $result['TOTAL'] > 0) {return true;}        
        return false;
	}
    
    public function getAnnoncesByAvailability($iduser) {
        $infoUser = $this->getInfosByUser($iduser);
        $sql = "select cf.* from carte_fidelite cf
        where cf.POINTFIDELITE <= ".$infoUser['POINTFIDELITETOTAL']." 
        and cf.isSHOW = 1 
        order by cf.POINTFIDELITE asc";
		return $this->getAdapter()->fetchAll($sql);
	}
    
    public function getAnnoncesByAvailabilityWithoutCurrent($iduser) {
        $infoUser = $this->getInfosByUser($iduser);
        $sql = "select cf.* from carte_fidelite cf
        where cf.POINTFIDELITE > ".$infoUser['POINTFIDELITETOTAL']." 
        and cf.isSHOW = 1 
        order by cf.POINTFIDELITE asc";
		return $this->getAdapter()->fetchAll($sql);
	}
    
    public function getInfosByUser($userID) {
        $sql = "SELECT IFNULL(sum(cf.NBPOINT), 0) POINTFIDELITETOTAL, count(1) NBPRODUCTTOTAL 
        FROM command_fidelite  as cf 
        LEFT JOIN command as c on c.id = cf.idcommand
        WHERE c.iduser = ".$userID;
        
        $sqlProd = "SELECT IFNULL(sum(cp.POINTFIDELITE), 0) POINTFIDELITETOTAL, IFNULL(sum(cp.POINTFIDELITESUM), 0) POINTFIDELITESUMTOTAL
        FROM command  as c
        LEFT JOIN command_product as cp on c.id = cp.idcommand 
        WHERE cp.POINTFIDELITE > 0
        and  c.iduser = ".$userID;
		
        $resultUser = $this->getAdapter()->fetchRow($sql);
        $resultProd = $this->getAdapter()->fetchRow($sqlProd);
        
        $result = array();
        if ($this->isSumOfProducts()) {
            $result['POINTFIDELITETOTAL'] = $resultProd['POINTFIDELITESUMTOTAL'] - $resultUser['POINTFIDELITETOTAL'];
        } else {
            $result['POINTFIDELITETOTAL'] = $resultProd['POINTFIDELITETOTAL'] - $resultUser['POINTFIDELITETOTAL'];
        }
        if ($result['POINTFIDELITETOTAL'] < 0) {
            $result['POINTFIDELITETOTAL'] = 0;
        }
        $result['NBPRODUCTTOTAL'] = $resultUser['NBPRODUCTTOTAL'];
        return $result;
	}
    
    
    public function getCommandUserCarteFidelite($id) {
        $sql = "SELECT c.* 
        FROM command c 
		INNER JOIN command_product AS cp ON cp.IDCOMMAND = c.ID 
		INNER JOIN command_fidelite AS cf ON cf.IDCOMMAND = c.ID 
        WHERE c.IDUSER = ".$id."
        GROUP BY c.id
        ORDER BY c.DATESTART desc";       
        return $this->getAdapter()->fetchAll($sql);
    }
    
    private function isSumOfProducts() {
        $registry = Zend_Registry::getInstance();
		$setting = $registry->get('setting');
        return $setting->carte_fidelite_sum_product_enabled;
    }
    
    public function getInfosEnableById($idFidelite) {
        $sql = "SELECT * FROM carte_fidelite WHERE id = ".$idFidelite." AND isSHOW = 1";
		return $this->getAdapter()->fetchRow($sql);
	}
    
    
}
?>CaddyTemp.php000060400000000605150715102030007116 0ustar00<?php
class CaddyTemp extends Zend_Db_Table
{
	protected $_name = 'caddy_temp';
	protected $_primary = 'ID';
	 
	public function findCaddyByUser($idUser) {
		$select = "SELECT ct.* FROM caddy_temp ct
				LEFT JOIN product AS p ON p.ID = ct.PRODUCTID
				WHERE USERID = ".$idUser."
				AND p.isACTIVE = 0
				ORDER BY DATEINS ASC";  
		return $this->getAdapter()->fetchAll($select);
	}
}
?>OptionProfil.php000060400000000477150715102030007677 0ustar00<?php
class OptionProfil extends Zend_Db_Table
{
    protected $_name = 'optionprofil';
    protected $_primary = 'ID';

	public function getProfils() {
		$select = "
				SELECT p.ID ID, p.NOM NOM, p.OPTS OPTS
				FROM optionprofil AS p
				ORDER BY NOM ASC;";
		return $this->getAdapter()->fetchAll($select);
	}
	
}
?>CommandFidelite.php000060400000000206150715102030010265 0ustar00<?php
class CommandFidelite extends Zend_Db_Table
{
    protected $_name = 'command_fidelite';
    protected $_primary = 'ID';
 	
}
?>BotDetector.php000060400000001521150715102030007460 0ustar00<?php  
class BotDetector {
	var $name;
	var $bot_list;

	function BotDetector() { 
		$this->bot_list = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
					"looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
					"Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
					"crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
					"msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
					"Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
					"Mediapartners-Google", "Sogou web spider", "WebAlta Crawler",
					"VoilaBot", "bingbot", "bot", "spider");  
	}

	public function isBot($User_Agent){  
		$result = 'ERROR';
		foreach($this->bot_list as $bot) { 
			if(preg_match("/".$bot."/i", $User_Agent)) { 
				$result = $bot; 
				break;
			}
		} 
		return $result; 
	} 
}

?>BlogComment.php000060400000003153150715102030007453 0ustar00<?php
class BlogComment extends Zend_Db_Table
{
    protected $_name = 'blogs_comments';
    protected $_primary = 'id'; 
        
    public function search($data) {  
        $select = " SELECT b.*, c.title category_name
				FROM blogs_comments b
				LEFT JOIN blogs_subjects AS s ON s.id = b.id_subject 
				LEFT JOIN blogs_categories AS c ON c.id = s.id_category
				WHERE "; 
        $select .= " b.is_publish = ".$data['is_publish'];     
        $select .= " AND c.is_close = ".$data['is_close'];     
        $select .= " AND s.is_close = ".$data['is_close'];    
         
        if (!empty($data['message'])) {   
            $select .= " AND b.message like '%".$data['message']."%'";    
        }
        
        $id_category =0;
        if ($data['id_subject'] > 0) {
            $id_category = $data['id_subject'];
        }     
        if ($id_category > 0) { 
            $select .= " AND b.id_subject = ".$id_category;
        } 
        $select .= " ORDER BY b.date_updated desc";  
		return $this->getAdapter()->fetchAll($select);
	}      

    public function AllCommentsBy($id) {  
        $select = " SELECT b.*, c.title category_name, c.is_close is_close_category, s.is_close is_close_subject
				FROM blogs_comments b
				LEFT JOIN blogs_subjects AS s ON s.id = b.id_subject 
				LEFT JOIN blogs_categories AS c ON c.id = s.id_category
				WHERE "; 
        $select .= " b.id_subject = ".$id;   
        $select .= " AND b.is_publish = 1";   
        $select .= " AND c.is_publish = 1";    
        $select .= " ORDER BY b.date_updated DESC ";  
		return $this->getAdapter()->fetchAll($select);
	}   

    
    
}
?>BlogSubject.php000060400000002711150715102030007447 0ustar00<?php
class BlogSubject extends Zend_Db_Table
{
    protected $_name = 'blogs_subjects';
    protected $_primary = 'id'; 
    
    public function AllSubjects() {
        $select = " SELECT b.*, c.title category_name
				FROM blogs_subjects b
				LEFT JOIN blogs_categories AS c ON c.id = b.id_category 
				 ORDER BY category_name ASC, b.title ASC "; 

		return $this->getAdapter()->fetchAll($select);
    }

    public function getPostBySearch($data) {  
      $select = " SELECT b.*, c.title category_name
				FROM blogs_subjects b
				LEFT JOIN blogs_categories AS c ON c.id = b.id_category 
				WHERE  b.is_close = ".$data['is_close']; 
        $select .= " AND b.is_publish = ".$data['is_publish']; 
        if ($data['id_category'] > 0) { 
            $select .= " AND b.id_category = ".$data['id_category'] ;
        }       
        if (!empty($data['title'])) {
            $select .= " AND b.title like '%".$data['title']."%'";
        }
        $select .= " ORDER BY b.date_updated DESC "; 

		return $this->getAdapter()->fetchAll($select);
	}    
    public function AllSubjectsBy($id) { 
            $select = " SELECT b.*, c.title category_name
				FROM blogs_subjects b
				LEFT JOIN blogs_categories AS c ON c.id = b.id_category 
                WHERE b.id_category = ".$id."
                AND c.is_publish = 1
                AND b.is_publish = 1
				 ORDER BY category_name ASC, b.title ASC "; 
		return $this->getAdapter()->fetchAll($select);
    } 
    
}
?>AnnonceContent.php000060400000000455150715102030010163 0ustar00<?php
class AnnonceContent extends Zend_Db_Table
{
    protected $_name = 'annonce_content';
    protected $_primary = 'ID';

    public function getAnnoncesByShow($isShow) {
    	return $this->select()->where('isSHOW = '.$isShow)->order('isSHOW ASC')->order('TITRE ASC')->query()->fetchAll();
	}
}
?>Command.php000060400000042175150715102030006632 0ustar00<?php
class Command extends Zend_Db_Table
{
	protected $_name = 'command';
	protected $_primary = 'ID';
    
    public function getCommandAsFacture($id) {
    $sql = "
					SELECT c.REFERENCE REFERENCE,c.ID ID, c.PRIXTOTALTTC TOTALTTC,c.PRIXTOTALHTFP TOTALHTFP, c.PRIXFRAISPORTPOUR FRAISPORTPOUR, c.PRIXFRAISPORT FRAISPORT,  c.PRIXTOTALHT TOTALHT, c.PRIXTOTALHTHR TOTALHTHR, c.PRIXREMISEEUR REMISEEUR,
					c.STATUT STATUT , c.DATESTART DATESTART,c.DATEEND DATEEND, c.LIV_RAISONSOCIAL LIVRAISONSOCIAL, c.LIV_ADRESSE LIVADRESSE, c.LIV_CP LIVCP, c.LIV_VILLE LIVVILLE, 
					c.LIV_PAYS LIVPAYS, c.FACT_RAISONSOCIAL FACTRAISONSOCIAL, c.FACT_ADRESSE FACTADRESSE, c.FACT_CP FACTCP , c.FACT_VILLE FACTVILLE , c.FACT_PAYS FACTPAYS, c.PAYMENT_STATUS PAYMENT_STATUS,c.TXN_ID TXN_ID, 
					cp.CHILDID CHILDID, cp.CHILDREF CHILDREF,cp.CHILDisPROMO CHILDisPROMO,cp.CHILDisDEVIS CHILDisDEVIS, cp.CHILDPRIX CHILDPRIX, cp.CHILDQUANTITY CHILDQUANTITY, cp.CHILDPROMOPRIX CHILDPROMOPRIX, cp.CHILDPRIXTOTAL CHILDPRIXTOTAL, cp.CHILDPRIXREMISE CHILDPRIXREMISE,
					cp.CHILDREMISEPRIXTAUXE CHILDREMISEPRIXTAUXE, cp.CHILDREMISEPRIXTAUXP CHILDREMISEPRIXTAUXP,
					p.ID PRODUCTID, p.NOM PRODUCTNOM, p.NAVNOM PRODUCTNAVNOM, pc.DESIGNATION DESIGNATION, p.STOCK STOCK,
					c.USER_NOM USERNOM, c.USER_PRENOM USERPRENOM, c.USER_TEL USERTEL, c.USER_FAX USERFAX, c.USER_EMAIL USEREMAIL, c.USER_MODEPAIEMENT USERMODEPAIEMENT, c.USER_NUMCOMPTE USERNUMCOMPTE,
					c.LIV_NOM LIV_NOM, c.CODEREDUCTION CODEREDUCTION, c.IDUSER IDUSER,
					cp.SELECTEDOPTION SELECTEDOPTION, c.USER_MODEPAIEMENT_TYPE USER_MODEPAIEMENT_TYPE, c.USER_MODEPAIEMENT_LABEL USER_MODEPAIEMENT_LABEL, c.DELIVERY_TRACKINGLINK DELIVERY_TRACKINGLINK,
                    c.DELIVERY_TRACKINGNUMBER DELIVERY_TRACKINGNUMBER, cat.NAVNOM_URLPARENTS NAVNOM_URLPARENTS, cp.ID IDLINE
					FROM command c 
					LEFT JOIN command_product AS cp ON cp.IDCOMMAND = c.ID 
					LEFT JOIN product AS p ON p.ID = cp.PRODUCTID
					LEFT JOIN category AS cat ON p.IDCATEGORY = cat.ID
					LEFT JOIN productchild AS pc ON pc.ID = cp.CHILDID
					WHERE c.ID = ".$id."
					ORDER BY pc.REFERENCE ASC
					";

        $resultCommande = $this->getAdapter()->fetchAll($sql);
        $myCommand = array();
        $myCommand['CADDY'] = array();
        $myCommand['CADDYFIDELITE'] = array();
        $i = 0;
        $idCommand = 0;

        foreach ($resultCommande AS $row) {
            if ($i == 0) {

                $myCommand['REFERENCE'] = $row['REFERENCE'];
                $myCommand['ID'] = $row['ID'];
                $idCommand = $row['ID'];
                
                $myCommand['PRIXTOTALTTC'] = sprintf("%.2f", $row['TOTALTTC']);
                $myCommand['PRIXTOTALHTFP'] = sprintf("%.2f", $row['TOTALHTFP']);
                $myCommand['PRIXFRAISPORTPOUR'] = $row['FRAISPORTPOUR'];
                $myCommand['PRIXFRAISPORT'] = sprintf("%.2f", $row['FRAISPORT']);
                $myCommand['PRIXTOTALHT'] = sprintf("%.2f", $row['TOTALHT']);
                $myCommand['PRIXTOTALHTHR'] = sprintf("%.2f", $row['TOTALHTHR']);
                $myCommand['PRIXREMISEEUR'] = sprintf("%.2f", $row['REMISEEUR']);
                $myCommand['DATESTART'] = $row['DATESTART'];
                $myCommand['DELIVERY_TRACKINGLINK'] = $row['DELIVERY_TRACKINGLINK'];
                $myCommand['DELIVERY_TRACKINGNUMBER'] = $row['DELIVERY_TRACKINGNUMBER'];

                $myCommand = $this->computeFactureTVA($myCommand, $row['LIVPAYS']);

                $myCommand['PAYMENT_STATUS'] = $row['PAYMENT_STATUS'];
                $myCommand['TXN_ID'] = $row['TXN_ID'];
                $myCommand['STATUT'] = $row['STATUT'];
                $myCommand['DATEEND'] = $row['DATEEND'];
                $myCommand['LIV_RAISONSOCIAL'] = $row['LIVRAISONSOCIAL'];
                $myCommand['LIV_ADRESSE'] = $row['LIVADRESSE'];
                $myCommand['LIV_CP'] = $row['LIVCP'];
                $myCommand['LIV_VILLE'] = $row['LIVVILLE'];
                $myCommand['LIV_PAYS'] = $row['LIVPAYS'];
                $myCommand['FACT_RAISONSOCIAL'] = $row['FACTRAISONSOCIAL'];
                $myCommand['FACT_ADRESSE'] = $row['FACTADRESSE'];
                $myCommand['FACT_CP'] = $row['FACTCP'];
                $myCommand['FACT_VILLE'] = $row['FACTVILLE'];
                $myCommand['FACT_PAYS'] = $row['FACTPAYS'];
                $myCommand['USER_NOM'] = $row['USERNOM'];
                $myCommand['USER_PRENOM'] = $row['USERPRENOM'];
                $myCommand['USER_TEL'] = $row['USERTEL'];
                $myCommand['USER_FAX'] = $row['USERFAX'];
                $myCommand['USER_EMAIL'] = $row['USEREMAIL'];
                $myCommand['USER_ID'] = $row['IDUSER'];

                $myCommand['USER_NUMCOMPTE'] = $row['USERNUMCOMPTE'];
                $myCommand['USER_MODEPAIEMENT'] = $row['USERMODEPAIEMENT'];
                $myCommand['LIV_NOM'] = $row['LIV_NOM'];
                $myCommand['CODEREDUCTION'] = $row['CODEREDUCTION'];
                $myCommand['USER_MODEPAIEMENT_TYPE'] = $row['USER_MODEPAIEMENT_TYPE'];
                $myCommand['USER_MODEPAIEMENT_LABEL'] = $row['USER_MODEPAIEMENT_LABEL'];
            }

            $myCommand['CADDY'][$i]['IDLINE'] = $row['IDLINE'];
            $myCommand['CADDY'][$i]['ID'] = $row['CHILDID'];
            $myCommand['CADDY'][$i]['REFERENCE'] = $row['CHILDREF'];
            $myCommand['CADDY'][$i]['DESIGNATION'] = $row['DESIGNATION'];
            $myCommand['CADDY'][$i]['isPROMO'] = $row['CHILDisPROMO'];
            $myCommand['CADDY'][$i]['isDEVIS'] = $row['CHILDisDEVIS'];
            $myCommand['CADDY'][$i]['PRIX'] = sprintf("%.2f", $row['CHILDPRIX']);
            $myCommand['CADDY'][$i]['QUANTITY'] = $row['CHILDQUANTITY'];
            $myCommand['CADDY'][$i]['PROMOPRIX'] = sprintf("%.2f", $row['CHILDPROMOPRIX']);
            $myCommand['CADDY'][$i]['PRIXTOTAL'] = sprintf("%.2f", $row['CHILDPRIXTOTAL']);
            $myCommand['CADDY'][$i]['REMISEPRIX'] = sprintf("%.2f", $row['CHILDPRIXREMISE']);
            $myCommand['CADDY'][$i]['REMISEPRIXTAUXE'] = sprintf("%.2f", $row['CHILDREMISEPRIXTAUXE']);
            $myCommand['CADDY'][$i]['REMISEPRIXTAUXP'] = $row['CHILDREMISEPRIXTAUXP'];
            $myCommand['CADDY'][$i]['PRODUCTID'] = $row['PRODUCTID'];
            $myCommand['CADDY'][$i]['PRODUCTNOM'] = $row['PRODUCTNOM'];
            $myCommand['CADDY'][$i]['STOCK'] = $row['STOCK'];
            $myCommand['CADDY'][$i]['SELECTEDOPTION'] = $row['SELECTEDOPTION'];

            $myCommand['CADDY'][$i]['NAVPRODUCTNOM'] = $row['PRODUCTNAVNOM'];
            $myCommand['CADDY'][$i]['NAVNOM_URLPARENTS'] = $row['NAVNOM_URLPARENTS'];

            $i++;
        }
        
        $i = 0;
		$resultCommandeFidelite = $this->findCommandFideliteByUserAndRef($idCommand);
		foreach ($resultCommandeFidelite AS $row) {
			$myCommand['CADDYFIDELITE'][$i]['IDFIDELITE'] = $row['IDFIDELITE'];
			$myCommand['CADDYFIDELITE'][$i]['NOM'] = $row['NOM'];
			$myCommand['CADDYFIDELITE'][$i]['NBPOINT'] = $row['NBPOINT'];
            $i++;
        }
                    
        return $myCommand;
    }
    
	private function computeFactureTVA($facture, $paysLivraison) {
		$fact = new Facture();
		$fact->computeFactureTVA($facture, $paysLivraison);
		return $facture;
	}


	/*
	 * STATISTIQUES 
	 * */
	public function statsBestSellForYear() {
		$sql = "SELECT p.NOM AS PROD_NOM, pc.REFERENCE AS REFERENCE, cat.NOM AS CAT_NOM, COUNT( 1 ) AS NB_CMD, SUM( cp.CHILDPRIXTOTAL ) AS TOTAL, SUM( cp.CHILDQUANTITY ) AS NB
				FROM command c
				LEFT JOIN command_product AS cp ON cp.IDCOMMAND = c.ID
				LEFT JOIN product AS p ON p.ID = cp.PRODUCTID
				LEFT JOIN category AS cat ON p.IDCATEGORY = cat.ID
				LEFT JOIN productchild AS pc ON pc.ID = cp.CHILDID
				WHERE DATE( c.DATESTART ) >= DATE(  '".date('Y')."-01-01' ) 
                AND c.STATUT <> 0 
				GROUP BY pc.REFERENCE
				ORDER BY TOTAL DESC 
				LIMIT 0 , 10";
		return $this->getAdapter()->fetchAll($sql);
	}
	public function statsBestSellForMonth() {
		$sql = "SELECT p.NOM AS PROD_NOM, pc.REFERENCE AS REFERENCE, cat.NOM AS CAT_NOM, COUNT( 1 ) AS NB_CMD, SUM( cp.CHILDPRIXTOTAL ) AS TOTAL, SUM( cp.CHILDQUANTITY ) AS NB
				FROM command c
				LEFT JOIN command_product AS cp ON cp.IDCOMMAND = c.ID
				LEFT JOIN product AS p ON p.ID = cp.PRODUCTID
				LEFT JOIN category AS cat ON p.IDCATEGORY = cat.ID
				LEFT JOIN productchild AS pc ON pc.ID = cp.CHILDID
				WHERE DATE( c.DATESTART ) >= DATE(  '".date('Y')."-".date('m')."-01' ) 
                AND c.STATUT <> 0 
				GROUP BY pc.REFERENCE
				ORDER BY TOTAL DESC 
				LIMIT 0 , 10";
		return $this->getAdapter()->fetchAll($sql);
	}
	
	public function statsNbProductYear() {
		$sql = "SELECT p.NOM AS PROD_NOM, pc.REFERENCE AS REFERENCE, cat.NOM AS CAT_NOM, COUNT( 1 ) AS NB_CMD, SUM( cp.CHILDPRIXTOTAL ) AS TOTAL, SUM( cp.CHILDQUANTITY ) AS NB
				FROM command c
				LEFT JOIN command_product AS cp ON cp.IDCOMMAND = c.ID
				LEFT JOIN product AS p ON p.ID = cp.PRODUCTID
				LEFT JOIN category AS cat ON p.IDCATEGORY = cat.ID
				LEFT JOIN productchild AS pc ON pc.ID = cp.CHILDID
				WHERE DATE( c.DATESTART ) >= DATE(  '".date('Y')."-01-01' ) 
                AND c.STATUT <> 0 
				GROUP BY pc.REFERENCE
				ORDER BY NB DESC 
				LIMIT 0 , 10";
		return $this->getAdapter()->fetchAll($sql);
	}
	
	public function statsNbProductMonth() {
		$sql = "SELECT p.NOM AS PROD_NOM, pc.REFERENCE AS REFERENCE, cat.NOM AS CAT_NOM, COUNT( 1 ) AS NB_CMD, SUM( cp.CHILDPRIXTOTAL ) AS TOTAL, SUM( cp.CHILDQUANTITY ) AS NB
				FROM command c
				LEFT JOIN command_product AS cp ON cp.IDCOMMAND = c.ID
				LEFT JOIN product AS p ON p.ID = cp.PRODUCTID
				LEFT JOIN category AS cat ON p.IDCATEGORY = cat.ID
				LEFT JOIN productchild AS pc ON pc.ID = cp.CHILDID
				WHERE DATE( c.DATESTART ) >= DATE(  '".date('Y')."-".date('m')."-01' ) 
                AND c.STATUT <> 0 
				GROUP BY pc.REFERENCE
				ORDER BY NB DESC 
				LIMIT 0 , 10";
		return $this->getAdapter()->fetchAll($sql);
	}
	
	public function statsCategoryCmdYear() {
		$sql = "SELECT cat.NOM AS CAT_NOM, COUNT( 1 ) AS NB_CMD, SUM( cp.CHILDPRIXTOTAL ) AS TOTAL
				FROM command c
				LEFT JOIN command_product AS cp ON cp.IDCOMMAND = c.ID
				LEFT JOIN product AS p ON p.ID = cp.PRODUCTID
				LEFT JOIN category AS cat ON p.IDCATEGORY = cat.ID
				LEFT JOIN productchild AS pc ON pc.ID = cp.CHILDID
				WHERE DATE( c.DATESTART ) >= DATE(  '".date('Y')."-01-01' ) 
                AND c.STATUT <> 0 
				GROUP BY CAT_NOM
				ORDER BY NB_CMD DESC 
				LIMIT 0 , 10";
		return $this->getAdapter()->fetchAll($sql);
	}
	
	public function statsCategoryCmdMonth() {
		$sql = "SELECT cat.NOM AS CAT_NOM, COUNT( 1 ) AS NB_CMD, SUM( cp.CHILDPRIXTOTAL ) AS TOTAL
				FROM command c
				LEFT JOIN command_product AS cp ON cp.IDCOMMAND = c.ID
				LEFT JOIN product AS p ON p.ID = cp.PRODUCTID
				LEFT JOIN category AS cat ON p.IDCATEGORY = cat.ID
				LEFT JOIN productchild AS pc ON pc.ID = cp.CHILDID
				WHERE DATE( c.DATESTART ) >= DATE(  '".date('Y')."-".date('m')."-01' ) 
                AND c.STATUT <> 0 
				GROUP BY CAT_NOM
				ORDER BY NB_CMD DESC 
				LIMIT 0 , 10";
		return $this->getAdapter()->fetchAll($sql);
	}
	
	/*-------------------------------------------*/
	
	public function deleteDevisByUser($idUser, $idDevis) { 	
		if ($this->isExistDevisOrCommand($idUser, $idDevis)) {
			$commandProduct = new CommandProduct(); 
			$commandProduct->delete('IDCOMMAND = '.$idDevis); 
			$this->delete('ID = '.$idDevis); 
			return 'OK';
		} else { return 'USER';}
		return 'NOK';
	}
	
	private function isExistDevisOrCommand($idUser, $idDevisCommand) {
		$sql = "SELECT COUNT(c.id) NBR FROM command c  
				WHERE c.IDUSER = ".$idUser." 
				AND c.ID = ".$idDevisCommand;  
		$result = $this->getAdapter()->fetchRow($sql);  
		if (isset($result) && !empty($result) && $result['NBR'] > 0) { return true; }
		return false;
	}
	
	public function findCommandsByUser($idUser) {  
		$select = "SELECT c.* FROM command c
				WHERE c.STATUT IN (1, 2, 3, 4) 
				AND c.IDUSER = ".$idUser." 
				ORDER BY DATESTART DESC";
		return $this->getAdapter()->fetchAll($select);
	}
	public function findDevisByUser($idUser) {  
		$select = "SELECT c.* FROM command c
				WHERE c.STATUT IN (10, 11) 
				AND c.IDUSER = ".$idUser." 
				ORDER BY DATESTART DESC";
		return $this->getAdapter()->fetchAll($select);
	}
	
	public function findCommandsByMultiSearch($isValidating, $search) {
		$select = "SELECT c.* FROM command c WHERE "; 
		if ($isValidating) {
			$select .= " STATUT = 0 ";
		} else {
			$select .= " STATUT <> 0 ";
		}
		$select .= " AND (REFERENCE LIKE '%".$search."%' "; 
		$select .= " OR USER_NOM LIKE '%".$search."%' "; 
		$select .= " OR USER_PRENOM LIKE '%".$search."%' "; 
		$select .= " OR USER_EMAIL LIKE '%".$search."%' )"; 
		return $this->getAdapter()->fetchAll($select);
	}
	
	public function findCommandsByStatut($statut, $order) {
		$select = "SELECT c.* FROM command c
				WHERE STATUT = ".$statut." 
				ORDER BY ".$order;
		return $this->getAdapter()->fetchAll($select);
	}
	
	public function findCommandFideliteByUserAndRef($idCommand) {
		$sql = "
					SELECT cf.*
					FROM command_fidelite AS cf 
					WHERE cf.IDCOMMAND = ".$idCommand." 
					ORDER BY cf.NBPOINT ASC
					";

		return $this->getAdapter()->fetchAll($sql);
	}
    
	public function findCommandByUserAndRef($idUser, $ref) {
		$sql = "
					SELECT c.REFERENCE REFERENCE,c.ID ID, c.PRIXTOTALTTC TOTALTTC,c.PRIXTOTALHTFP TOTALHTFP, c.PRIXFRAISPORTPOUR FRAISPORTPOUR, c.PRIXFRAISPORT FRAISPORT,  c.PRIXTOTALHT TOTALHT, c.PRIXTOTALHTHR TOTALHTHR, c.PRIXREMISEEUR REMISEEUR,
					c.STATUT STATUT , c.DATESTART DATESTART, c.LIV_RAISONSOCIAL LIVRAISONSOCIAL, c.LIV_ADRESSE LIVADRESSE, c.LIV_CP LIVCP, c.LIV_VILLE LIVVILLE, 
					c.LIV_PAYS LIVPAYS, c.FACT_RAISONSOCIAL FACTRAISONSOCIAL, c.FACT_ADRESSE FACTADRESSE, c.FACT_CP FACTCP , c.FACT_VILLE FACTVILLE , c.FACT_PAYS FACTPAYS, 
					cp.CHILDID CHILDID, cp.CHILDREF CHILDREF,cp.CHILDisPROMO CHILDisPROMO,cp.CHILDisDEVIS CHILDisDEVIS, cp.CHILDPRIX CHILDPRIX, cp.CHILDQUANTITY CHILDQUANTITY, cp.CHILDPROMOPRIX CHILDPROMOPRIX, cp.CHILDPRIXTOTAL CHILDPRIXTOTAL, cp.CHILDPRIXREMISE CHILDPRIXREMISE, pc.DESIGNATION DESIGNATION,
					cp.CHILDREMISEPRIXTAUXE CHILDREMISEPRIXTAUXE, cp.CHILDREMISEPRIXTAUXP CHILDREMISEPRIXTAUXP,
					p.ID PRODUCTID, p.NOM PRODUCTNOM,p.NAVNOM PRODUCTNAVNOM,  p.STOCK STOCK,
					c.USER_NOM USERNOM, c.USER_PRENOM USERPRENOM, c.USER_TEL USERTEL, c.USER_FAX USERFAX, c.USER_EMAIL USEREMAIL, c.USER_MODEPAIEMENT USERMODEPAIEMENT, c.USER_NUMCOMPTE USERNUMCOMPTE, 
					c.LIV_NOM LIV_NOM, c.CODEREDUCTION CODEREDUCTION,
					cp.SELECTEDOPTION SELECTEDOPTION, c.USER_MODEPAIEMENT_TYPE USER_MODEPAIEMENT_TYPE, c.USER_MODEPAIEMENT_LABEL USER_MODEPAIEMENT_LABEL, cat.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
					FROM command c 
					LEFT JOIN command_product AS cp ON cp.IDCOMMAND = c.ID 
					LEFT JOIN product AS p ON p.ID = cp.PRODUCTID
			        LEFT JOIN category cat ON p.IDCATEGORY = cat.ID
					LEFT JOIN productchild AS pc ON pc.ID = cp.CHILDID
					WHERE c.IDUSER = ".$idUser." 
					AND c.REFERENCE = '".$ref."'
					ORDER BY pc.REFERENCE ASC
					";

		return $this->getAdapter()->fetchAll($sql);
	}
	

	public function findCommandCaddyRetrieve($idUser, $ref) {
		$sql = "
					SELECT c.REFERENCE REFERENCE,c.ID ID, 
					c.LIV_RAISONSOCIAL LIVRAISONSOCIAL, c.LIV_ADRESSE LIVADRESSE, c.LIV_CP LIVCP, c.LIV_VILLE LIVVILLE, 
					c.LIV_PAYS LIVPAYS, c.FACT_RAISONSOCIAL FACTRAISONSOCIAL, c.FACT_ADRESSE FACTADRESSE, c.FACT_CP FACTCP , c.FACT_VILLE FACTVILLE , c.FACT_PAYS FACTPAYS, 
					cp.CHILDID CHILDID, cp.CHILDREF CHILDREF,cp.CHILDisPROMO CHILDisPROMO,cp.CHILDisDEVIS CHILDisDEVIS, cp.CHILDPRIX CHILDPRIX, cp.CHILDQUANTITY CHILDQUANTITY, cp.CHILDPROMOPRIX CHILDPROMOPRIX, cp.CHILDPRIXTOTAL CHILDPRIXTOTAL, cp.CHILDPRIXREMISE CHILDPRIXREMISE, pc.DESIGNATION DESIGNATION,
					cp.CHILDREMISEPRIXTAUXE CHILDREMISEPRIXTAUXE, cp.CHILDREMISEPRIXTAUXP CHILDREMISEPRIXTAUXP,
					p.ID PRODUCTID, p.NOM PRODUCTNOM, p.NAVNOM PRODUCTNAVNOM, p.DESCRIPTIONSHORT DESCSHORT, pic.URL URL, p.STOCK STOCK, 
					c.USER_NOM USERNOM, c.USER_PRENOM USERPRENOM, c.USER_TEL USERTEL, c.USER_FAX USERFAX, c.USER_EMAIL USEREMAIL, c.USER_MODEPAIEMENT USERMODEPAIEMENT, c.USER_NUMCOMPTE USERNUMCOMPTE, 
					c.LIV_NOM LIV_NOM, cp.SELECTEDOPTION SELECTEDOPTION, cat.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
					FROM command c 
					LEFT JOIN command_product AS cp ON cp.IDCOMMAND = c.ID 
					LEFT JOIN product AS p ON p.ID = cp.PRODUCTID
			        LEFT JOIN category cat ON p.IDCATEGORY = cat.ID
					LEFT JOIN productchild AS pc ON pc.ID = cp.CHILDID
					LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
					WHERE c.IDUSER = ".$idUser." 
					AND c.REFERENCE = '".$ref."'
					AND pic.POSITION = 1
					ORDER BY pc.REFERENCE ASC
					"; 
		return $this->getAdapter()->fetchAll($sql);
	} 
	
	public function isAlreadyBuySomething($userID) { 
		$result = $this->select()->where('IDUSER =  ?', $userID)->where('STATUT IN (?)', array(2, 3))->query()->fetch();
		if ($result) { return true ; }
		return false;
    }
    
    
	public function getTotalQteByReferenceAndUser($idUser, $reference) {
		$sql = "SELECT SUM(cp.CHILDQUANTITY) NBR
					FROM command c 
					LEFT JOIN command_product AS cp ON c.ID = cp.IDCOMMAND  
					WHERE c.IDUSER = ".$idUser." 
					AND cp.CHILDREF = '".$reference."'
					AND c.STATUT IN (2 , 3)";  
		$result = $this->getAdapter()->fetchRow($sql);
		if ((int)$result['NBR'] > 0) { return $result['NBR']; } 
		return 0;
	}
	
}
?>LivraisonType.php000060400000001272150715102030010055 0ustar00<?php
class LivraisonType extends Zend_Db_Table
{
    protected $_name = 'livraison_type';
    protected $_primary = 'ID';

    public function getTypes() {
    	return $this->select()->order('NOM ASC')->query()->fetchAll();
	}

	public function getInfoById($type) {
		$myresult = array();
		try {
			$sql = "
				SELECT lt.CMDFRANCO CMDFRANCO, lt.NOM NOMLIV, lt.ID ID
				FROM livraison_type lt
				WHERE lt.ID = ".$type;
			$result = $this->getAdapter()->fetchRow($sql); 
			if (!empty($result)) {
				$myresult['CMDFRANCO'] = $result['CMDFRANCO'];
				$myresult['NOMLIV'] = $result['NOMLIV'];
				$myresult['ID'] = $result['ID'];
			}
		} catch (Zend_Exception $e) {}
		return $myresult;
	}
}
?>AnnonceGallery.php000060400000001540150715102030010144 0ustar00<?php
class AnnonceGallery extends Zend_Db_Table
{
    protected $_name = 'annonce_gallery';
    protected $_primary = 'ID';

    public function getAnnonces() {
    	return $this->select()->where('isSHOW = 0')->order('POSITION ASC')->order('NOM ASC')->query()->fetchAll();
	}
	

    public function getAllAnnonces() {
    	return $this->select()->order('POSITION ASC')->order('NOM ASC')->query()->fetchAll();
	}
    
    public function getAllAnnoncesByCategory($idCat) {
    	return $this->select()->where("ID_CATS LIKE '%:".$idCat.":%' OR ID_CATS LIKE '%:0:%' ")->order('POSITION ASC')->order('NOM ASC')->query()->fetchAll();
 	}
	
 	public function getAnnoncesByShow($idCat) {
 		return $this->select()->where('isSHOW = 0')->where("ID_CATS LIKE '%:".$idCat.":%' OR ID_CATS LIKE '%:0:%' ")->order('POSITION ASC')->order('NOM ASC')->query()->fetchAll();
 	}
}
?>FAQType.php000060400000000535150715102030006517 0ustar00<?php
class FAQType extends Zend_Db_Table
{
    protected $_name = 'faq_type';
    protected $_primary = 'ID';

    public function getTypes() {
    	return $this->select()->where('isACTIVE', 1)->order('NOM ASC')->query()->fetchAll();
	}
    public function getTypesAll() {
    	return $this->select()->order('NOM ASC')->query()->fetchAll();
	}
}
?>Product.php000060400000047076150715102030006701 0ustar00<?php
class Product extends Zend_Db_Table
{
	protected $_name = 'product';
	protected $_primary = 'ID';

	public function updateByCategory($idCategory, $data) {
		return $this->update($data, 'IDCATEGORY = '.$idCategory);
	}
  
	private function getProductForIndexationFull($id) {
		$select = "
				SELECT p.ID ID, p.NOM NOM, p.NAVNOM NAVNOM,p.NAVTITRE NAVTITRE, p.NAVDESC NAVDESC,p.KEYWORDS KEYWORDS, p.DESCRIPTIONSHORT DESCSHORT, p.DESCRIPTIONLONG DESCLONG, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
				p.DOCNAME DOCNAME, p.DOCURL DOCURL, p.IDBREND IDBREND, p.STOCK STOCK,
				p.isPROMO isPROMO, pic.URL URL, sb.BREND BREND, sb.URL BRENDURL, p.IDCATEGORY IDCATEGORY,
				p.DESCRIPTIONTECH DESCTECH, p.DESCRIPTIONNORME DESCNORME, p.isSHOWBREND isSHOWBREND,
				o.NOM NOMOPTION, o.ID IDOPTION,  p.isQTEPRIXACTIVE isQTEPRIXACTIVE, p.ONSELECT_IDOPTION ONSELECT_IDOPTION , 
                c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS, c.NAVNOM CATNAVNOM, c.NOM CATNOM, p.BOOSTED_BESTSELLER BOOSTED_BESTSELLER
				FROM product p
				LEFT JOIN product_option AS po ON po.IDPRODUCT = p.ID
				LEFT JOIN category c ON c.ID = p.IDCATEGORY 
				LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
				LEFT JOIN `option` AS o ON o.ID = po.IDOPTION
				LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
				WHERE p.ID = ".$id."
				AND p.isACTIVE = 0
				"; 
		return $this->getAdapter()->fetchAll($select);
	}

    /* SITE */
	public function calculateLowestPrice($idProduct) {
		$myFacture = new Facture();
		
		
		$productChild = new ProductChild();
		$productChildQte = new ProductChildQte();
		
		
		$results = $productChild->getChildsInfoByListProductId($idProduct);
		$lastPrice = null;
		$lastFactureLine = null;
		foreach ($results AS $row) {
			$factureLine = new FactureLine();
			$factureLine->setLineInfo($row, 1, 0);
			
			$currentPrice = $productChildQte->getCurrentLowestPrice($row['IDCHILD'], $row['PRIX']);
			$factureLine->item_prix = sprintf("%.2f",$currentPrice);		
			$factureLine->setPromoCaddyType(false);
		
			if ($lastFactureLine == null || $factureLine->item_prix < $lastFactureLine->item_prix) {
				$lastFactureLine = $factureLine;
			}
			
		}
		if ($lastFactureLine != null) {
			$myFacture->addLine($lastFactureLine); 
			
			$promo = new PromoCalculator();
			$promo->computeAllPromos($myFacture, null);
				 
			return $myFacture->getPrixTotalHT();
		}
		return sprintf("%.2f",0);		
	}
	
	public function getProductById($id) {
		$select = "
				SELECT p.ID ID, p.NOM NOM, p.NAVNOM NAVNOM,p.NAVTITRE NAVTITRE, p.NAVDESC NAVDESC,p.KEYWORDS KEYWORDS, p.DESCRIPTIONSHORT DESCSHORT, p.DESCRIPTIONLONG DESCLONG, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
				p.DOCNAME DOCNAME, p.DOCURL DOCURL, p.IDBREND IDBREND, p.STOCK STOCK,
				p.isPROMO isPROMO, pic.URL URL, sb.BREND BREND, sb.URL BRENDURL, p.IDCATEGORY IDCATEGORY,
				p.DESCRIPTIONTECH DESCTECH, p.DESCRIPTIONNORME DESCNORME, p.isSHOWBREND isSHOWBREND,
				o.NOM NOMOPTION, o.ID IDOPTION,  p.isQTEPRIXACTIVE isQTEPRIXACTIVE, p.ONSELECT_IDOPTION ONSELECT_IDOPTION , 
                c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS, c.NAVNOM CATNAVNOM, c.NOM CATNOM, p.BOOSTED_BESTSELLER BOOSTED_BESTSELLER
				FROM product p
				LEFT JOIN product_option AS po ON po.IDPRODUCT = p.ID
				LEFT JOIN category c ON c.ID = p.IDCATEGORY 
				LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
				LEFT JOIN `option` AS o ON o.ID = po.IDOPTION
				LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
				WHERE p.ID = ".$id." 
				AND p.isACTIVE = 0
				"; 
		return $this->getAdapter()->fetchAll($select);
	}

	public function getProductsByIdCategory($id, $triSql) {

		$select = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM PRODNAVNOM,p.NAVTITRE NAVTITRE, p.NAVDESC NAVDESC, p.DESCRIPTIONSHORT DESCSHORT, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
							p.isPROMO isPROMO, pic.URL URL, sb.BREND BREND, sb.ID BRENDID, sb.URL BRENDURL, COUNT(pc.REFERENCE) NBREFERENCE, 
							c.NAVNOM CATNAVNOM, c.ID CATID, p.isSHOWBREND isSHOWBREND, p.KEYWORDS KEYWORDS_PROD,
							p.IDCATEGORY_DUP1 IDCATEGORY_DUP1,	p.IDCATEGORY_DUP2 IDCATEGORY_DUP2, p.IDCATEGORY_DUP3 IDCATEGORY_DUP3, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS,
							c.NOM CATNOM, p.BOOSTED_BESTSELLER BOOSTED_BESTSELLER
							FROM product p
							LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
							LEFT JOIN category c ON c.ID = p.IDCATEGORY 
							LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
							LEFT JOIN productchild pc ON pc.IDPRODUCT = p.ID
							WHERE (p.IDCATEGORY = ".$id." OR
							p.IDCATEGORY_DUP1 = ".$id." OR
							p.IDCATEGORY_DUP2 = ".$id." OR
							p.IDCATEGORY_DUP3 = ".$id." )
							AND p.isACTIVE = 0
							AND p.STOCK <> 4
							AND pic.POSITION = 1
							GROUP BY ID
							ORDER BY ".$triSql; 
		return $this->getAdapter()->fetchAll($select);
	}

	public function getBoostedHome($user) {

		$select = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM PRODNAVNOM,p.NAVTITRE NAVTITRE, p.NAVDESC NAVDESC, p.DESCRIPTIONSHORT DESCSHORT, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
							p.isPROMO isPROMO, pic.URL URL, sb.BREND BREND, sb.ID BRENDID, sb.URL BRENDURL, COUNT(pc.REFERENCE) NBREFERENCE, 
							c.NAVNOM CATNAVNOM, c.ID CATID, p.isSHOWBREND isSHOWBREND, p.KEYWORDS KEYWORDS_PROD,
							p.IDCATEGORY_DUP1 IDCATEGORY_DUP1,	p.IDCATEGORY_DUP2 IDCATEGORY_DUP2, p.IDCATEGORY_DUP3 IDCATEGORY_DUP3, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS,
							c.NOM CATNOM, p.BOOSTED_BESTSELLER BOOSTED_BESTSELLER
							FROM product p
							LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
							LEFT JOIN category c ON c.ID = p.IDCATEGORY 
							LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
							LEFT JOIN productchild pc ON pc.IDPRODUCT = p.ID
							WHERE p.isACTIVE = 0
							AND pic.POSITION = 1
							AND p.BOOSTED_HOME > 0 
							GROUP BY ID
							ORDER BY p.BOOSTED_HOME asc, p.PRIX asc"; 
		$data =  $this->getAdapter()->fetchAll($select);
        return $this->computeProductListToShow($data, $user);        
	}

	public function getAllTreeSubProductsByCatId($id) {
		$category = new Category(); 
		$listIds = $category->getAllSubsIDByIDToString($id);  
		if (!empty($listIds)) {
			$select = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM PRODNAVNOM,p.NAVTITRE NAVTITRE, p.NAVDESC NAVDESC, p.DESCRIPTIONSHORT DESCSHORT, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
							p.isPROMO isPROMO, pic.URL URL, sb.BREND BREND, sb.ID BRENDID, sb.URL BRENDURL, COUNT(pc.REFERENCE) NBREFERENCE, 
							c.NAVNOM CATNAVNOM, c.ID CATID, p.isSHOWBREND isSHOWBREND, p.KEYWORDS KEYWORDS_PROD,
							p.IDCATEGORY_DUP1 IDCATEGORY_DUP1,	p.IDCATEGORY_DUP2 IDCATEGORY_DUP2, p.IDCATEGORY_DUP3 IDCATEGORY_DUP3 , c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS,
							c.NOM CATNOM, p.BOOSTED_BESTSELLER BOOSTED_BESTSELLER
							FROM product p
							LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
							LEFT JOIN category c ON c.ID = p.IDCATEGORY 
							LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
							LEFT JOIN productchild pc ON pc.IDPRODUCT = p.ID
							WHERE p.IDCATEGORY IN (".$listIds.")
							AND p.isACTIVE = 0
							AND p.STOCK <> 4
							AND pic.POSITION = 1
							GROUP BY ID
							ORDER BY CATNOM ASC
							LIMIT 0 , 30;"; 
			return $this->getAdapter()->fetchAll($select);
		}
		return array();
	}

	public function getAllProductsBestSellerByCatId($id) {
    
        $category = new Category();
        $idCats = $category->getListIdFromParent($id);
     
        $select = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM PRODNAVNOM,p.NAVTITRE NAVTITRE, p.NAVDESC NAVDESC, p.DESCRIPTIONSHORT DESCSHORT, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
					p.isPROMO isPROMO, pic.URL URL, sb.BREND BREND, sb.ID BRENDID, sb.URL BRENDURL, '0' as NBREFERENCE, 
					c.NAVNOM CATNAVNOM, c.ID CATID, p.isSHOWBREND isSHOWBREND, p.KEYWORDS KEYWORDS_PROD,
					p.IDCATEGORY_DUP1 IDCATEGORY_DUP1,	p.IDCATEGORY_DUP2 IDCATEGORY_DUP2, p.IDCATEGORY_DUP3 IDCATEGORY_DUP3 , c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS,
                    c.NOM CATNOM, p.BOOSTED_BESTSELLER BOOSTED_BESTSELLER
					FROM product p
					LEFT JOIN picture pic ON p.ID = pic.IDPRODUCT
					LEFT JOIN category c ON p.IDCATEGORY  = c.ID 
					LEFT JOIN supplier_brend sb ON p.IDBREND =  sb.ID 
					LEFT JOIN productchild pc ON p.ID = pc.IDPRODUCT
					WHERE p.IDCATEGORY in (".$idCats.") 
					AND p.isACTIVE = 0
					AND p.STOCK <> 4
					AND pic.POSITION = 1 
                    GROUP BY ID
					ORDER BY BOOSTED_BESTSELLER ASC, p.PRIX ASC
					LIMIT 0 , 12";   
		return $this->getAdapter()->fetchAll($select);
	}

	public function getProductsBySearch($keyTemp) {
		$keys = '';
		$keys = explode(" ",$keyTemp);
		$sql = "SELECT p.ID ID, p.NOM NOM,p.NAVNOM PRODNAVNOM,p.NAVTITRE NAVTITRE, p.NAVDESC NAVDESC, p.DESCRIPTIONSHORT DESCSHORT, p.PRIX PRIX, p.isDEVIS isDEVISPRODUCT,
							p.isPROMO isPROMO, pic.URL URL, sb.BREND BREND, sb.ID BRENDID, sb.URL BRENDURL, COUNT(pc.REFERENCE) NBREFERENCE, 
							c.NAVNOM CATNAVNOM, c.ID CATID, p.isSHOWBREND isSHOWBREND, p.KEYWORDS KEYWORDS_PROD,
							p.IDCATEGORY_DUP1 IDCATEGORY_DUP1,	p.IDCATEGORY_DUP2 IDCATEGORY_DUP2, p.IDCATEGORY_DUP3 IDCATEGORY_DUP3, c.NAVNOM_URLPARENTS NAVNOM_URLPARENTS,
							c.NOM CATNOM, p.BOOSTED_BESTSELLER BOOSTED_BESTSELLER
							FROM product p
							LEFT JOIN picture pic ON pic.IDPRODUCT = p.ID 
							LEFT JOIN category c ON c.ID = p.IDCATEGORY 
							LEFT JOIN supplier_brend sb ON sb.ID = p.IDBREND
							LEFT JOIN productchild pc ON pc.IDPRODUCT = p.ID		
			WHERE ";
		if ($keys!='') {
			$sql .= " (";
			$sql .= $this->computeStatementSearch($keys, "p.NOM");
			$sql .= " OR ";
			$sql .= $this->computeStatementSearch($keys, "p.DESCRIPTIONSHORT");
			$sql .= " OR ";
			$sql .= " p.KEYWORDS LIKE '%".$keyTemp."%' ";
			$sql .= " OR ";
			$sql .= $this->computeStatementSearch($keys, "pc.REFERENCE");
			$sql .= " ) AND ";
		}
		$sql .= " p.isACTIVE = 0
                AND p.STOCK <> 4
				AND pic.POSITION = 1
				GROUP BY p.ID
				ORDER BY p.NOM ASC";
		
		return $this->getAdapter()->fetchAll($sql);
	}
	

	private function computeStatementSearch($keys, $attribut) {
		$sqlProduct = " ".$attribut." LIKE '";
		foreach ($keys as $key) {
			$sqlProduct .= "%".$key."%";
		}
		$sqlProduct .= "'";
		return $sqlProduct;
	
	}
	
	public function isInCategorySubsidiaire($idProduct,$idCat) {
		$category = new Category2(); 		
		$sql = "(SELECT cp.IDCATEGORY FROM category2_product cp WHERE cp.IDPRODUCT = ".$idProduct.")";
		$sqlParentFirst = "SELECT DISTINCT c0.ID ID
				FROM category2 AS c0
				LEFT JOIN category2 AS c1 ON c1.IDPARENT = c0.ID
				LEFT JOIN category2 AS c2 ON c2.IDPARENT = c1.ID
				LEFT JOIN category2 AS c3 ON c3.IDPARENT = c2.ID 
				LEFT JOIN category2 AS c4 ON c4.IDPARENT = c3.ID 
				LEFT JOIN category2 AS c5 ON c5.IDPARENT = c4.ID 
				LEFT JOIN category2 AS c6 ON c6.IDPARENT = c5.ID 
				LEFT JOIN category2 AS c7 ON c7.IDPARENT = c6.ID 
				LEFT JOIN category2 AS c8 ON c8.IDPARENT = c7.ID 
				LEFT JOIN category2 AS c9 ON c9.IDPARENT = c8.ID 
				LEFT JOIN category2 AS c10 ON c10.IDPARENT = c9.ID 
				WHERE ( c0.ID = ".$idCat."  
				OR c1.ID = ".$idCat." 
				OR c2.ID = ".$idCat." 
				OR c3.ID = ".$idCat." 
				OR c4.ID = ".$idCat." 
				OR c5.ID = ".$idCat." 
				OR c6.ID = ".$idCat." 
				OR c7.ID = ".$idCat." 
				OR c8.ID = ".$idCat." 
				OR c9.ID = ".$idCat." 
				OR c10.ID = ".$idCat." )
				AND (c0.ID in ".$sql." 
				OR c1.ID in ".$sql." 
				OR c2.ID in ".$sql." 
				OR c3.ID in ".$sql." 
				OR c4.ID in ".$sql." 
				OR c5.ID in ".$sql." 
				OR c6.ID in ".$sql." 
				OR c7.ID in ".$sql." 
				OR c8.ID in ".$sql." 
				OR c9.ID in ".$sql." 
				OR c10.ID in ".$sql." )
				ORDER BY c0.IDPARENT ASC";
		$list = $category->fetchRow($sqlParentFirst);  		 
		return empty($list) ? false : true;
	}


	public function getAllTreeSubProductsByCatIdForPromotion($idCat) {
		$category = new Category2(); 
		$listIds = $category->getAllSubsIDByIDToString($idCat);  
		if (!empty($listIds)) {
			$productCategory = new ProductCategory2();
			return $productCategory->getAllProductsByCategoryIDList($listIds);
		}
		return array();
	}
	
	public function getProductsByIdCategoryForPromotion($id, $triSql) {
		$productCategory = new ProductCategory2();
		return $productCategory->getAllProductsInfoByCategoryID($id, $triSql);
	}
	
	private function computeProductListToShow($list, $user) {
		try {
			$listProducts = array();
			$metakeywords = '';

			$isAllPromos = false;
			$currentPromoAll = array();
			$currentPromo = array();
			$listUserCodeInternIdBrendFound = array();
			$listUserCodeInternIdBrends = array();
			$listIdBrendFound = array();
			$listUserIdBrendFound = array();
			$listUserIdBrends = array();
			$listIdBrends = array();
			$promoCalculator = new PromoCalculator();
			$promoProduct = new PromoProduct();
			$promoUser = new PromoUser();
			$product= new Product();

			if (!empty($list)) {
				$idCategory = $list[0]['CATID'];
				$myPromo = $promoProduct->getRemiseByProductCategory($idCategory);
				if ($this->isPromoActive($myPromo)) { $isAllPromos = true; $currentPromoAll = $myPromo; }
			}
			$productChildQte = new ProductChildQte();

			foreach ($list AS $row) {
				$currentProduct = array();
				$currentProduct['ID'] = $row['ID'];
				$currentProduct['NOM'] = $row['NOM'];
				//$currentProduct['DESCSHORT'] = $this->cutString($row['DESCSHORT'], 80);
				$currentProduct['DESCSHORT'] = $row['DESCSHORT'];
				$currentProduct['URL'] = $row['URL'];
				$currentProduct['BREND'] = $row['BREND'];
				$currentProduct['isSHOWBREND'] = $row['isSHOWBREND'];
				$currentProduct['BRENDURL'] = $row['BRENDURL'];
				$currentProduct['NBREFERENCE'] = $row['NBREFERENCE'];
				$currentProduct['isDEVISPRODUCT'] = $row['isDEVISPRODUCT'];
                $currentProduct['NAVNOM_URLPARENTS'] = $this->computeUrlNavigationParent($row);
				$currentProduct['BOOSTED_BESTSELLER'] = $row['BOOSTED_BESTSELLER'];

				if (isset($row['NAVNOM'])) {
					$navnom = $row['NAVNOM'];
				} else {
					$navnom = $row['PRODNAVNOM'];
				}

				$currentProduct['NAVNOM'] = $this->verifyNavigationString($navnom, $row['NOM'], '');

				$currentProduct['NAVTITRE'] = $row['NAVTITRE'];
				$currentProduct['NAVDESC'] = $row['NAVDESC'];

				$isFirst = false;

				if (empty($metakeywords)) {
					$metakeywords .= $row['KEYWORDS_PROD'];
				} else {
					$metakeywords .= ','.$row['KEYWORDS_PROD'];
				}

				$currentProduct['isPROMO'] = $row['isPROMO'];
				$currentProduct['PRIX'] = $row['PRIX'];

				/*
                 * PRIX DEGRESSIF
                 */
				$currentProduct['isPRIXDEGRESSIF'] = $productChildQte->isPrixDegressifByProductID($row['ID']);
                
				/*
                 * CALCUL PROMO
                 */
				$idBrend = $row['BRENDID'];

				if (!in_array($idBrend, $listIdBrends, true)) {
					$myPromo = $promoProduct->getRemiseByProductBrend($idBrend);
					array_push($listIdBrends, $idBrend);
					if ($this->isPromoActive($myPromo)) { array_push($listIdBrendFound, array('ID' => $idBrend, 'PROMO' => $myPromo)); }
				}
				if ($row['isPROMO'] == 1) {
					$isRemise = false;
					if (in_array($idBrend, $listIdBrends, true)) {
						foreach ($listIdBrendFound as $brendPromos) {
							if ($brendPromos['ID'] == $idBrend) {
								$currentProduct['isPROMO'] = 0;
								$currentPromo = $brendPromos['PROMO'];
								if ($currentPromo['REMISEEURO'] > 0) {
									$currentProduct['PRIX'] = $promoCalculator->calculEuro($row['PRIX'], $currentPromo['REMISEEURO']);
									$isRemise = true;
								}
								if ($currentPromo['REMISEPOUR'] > 0) {
									$currentProduct['PRIX'] = $promoCalculator->calculPour($row['PRIX'], $currentPromo['REMISEPOUR']);
									$isRemise = true;
								}
								break;
							}
						}
					}
					if ($isAllPromos && !empty($currentPromoAll) && !$isRemise ) {
						$currentProduct['isPROMO'] = 0;
						if ($currentPromoAll['REMISEEURO'] > 0) {
							$currentProduct['PRIX'] = $promoCalculator->calculEuro($row['PRIX'], $currentPromoAll['REMISEEURO']);
						}
						if ($currentPromoAll['REMISEPOUR'] > 0) {
							$currentProduct['PRIX'] = $promoCalculator->calculPour($row['PRIX'], $currentPromoAll['REMISEPOUR']);
						}
					}
				}
				if (isset($user) && !empty($user)) {
					$userId = $user['id'];
					$codeIntern = $user['cintern'];
					$isRemise = false;

					if (!empty($codeIntern)) {
						if (!in_array($idBrend.'-'.$codeIntern, $listUserCodeInternIdBrends, true)) {
							$myPromo = $promoUser->getRemiseByCodeInternMarque($idBrend, $codeIntern);
							array_push($listUserCodeInternIdBrends, $idBrend.'-'.$codeIntern);
							if ($this->isPromoActive($myPromo)) { array_push($listUserCodeInternIdBrendFound, array('ID' => $idBrend, 'CODE' => $codeIntern, 'PROMO' => $myPromo)); }
						}
						if (in_array($idBrend.'-'.$codeIntern, $listUserCodeInternIdBrends, true)) {
							foreach ($listUserCodeInternIdBrendFound as $brendPromos) {
								if ($brendPromos['ID'] == $idBrend && $brendPromos['CODE'] == $codeIntern ) {
									$currentProduct['isPROMO'] = 0;
									$currentPromo = $brendPromos['PROMO'];
									if ($currentPromo['REMISEEURO'] > 0) {
										$currentProduct['PRIX'] = $promoCalculator->calculEuro($row['PRIX'], $currentPromo['REMISEEURO']);
										$isRemise = true;
									}
									if ($currentPromo['REMISEPOUR'] > 0) {
										$currentProduct['PRIX'] = $promoCalculator->calculPour($row['PRIX'], $currentPromo['REMISEPOUR']);
										$isRemise = true;
									}
									break;
								}
							}
						}
					}
					if (!$isRemise) {
						if (!in_array($idBrend, $listUserIdBrends, true)) {
							$myPromo = $promoUser->getRemiseByMarque($idBrend, $userId);
							array_push($listUserIdBrends, $idBrend);
							if ($this->isPromoActive($myPromo)) { array_push($listUserIdBrendFound, array('ID' => $idBrend, 'PROMO' => $myPromo)); }
						}
						if (in_array($idBrend, $listUserIdBrends, true)) {
							foreach ($listUserIdBrendFound as $brendPromos) {
								if ($brendPromos['ID'] == $idBrend) {
									$currentProduct['isPROMO'] = 0;
									$currentPromo = $brendPromos['PROMO'];
									if ($currentPromo['REMISEEURO'] > 0) {
										$currentProduct['PRIX'] = $promoCalculator->calculEuro($row['PRIX'], $currentPromo['REMISEEURO']);
										$isRemise = true;
									}
									if ($currentPromo['REMISEPOUR'] > 0) {
										$currentProduct['PRIX'] = $promoCalculator->calculPour($row['PRIX'], $currentPromo['REMISEPOUR']);
										$isRemise = true;
									}
									break;
								}
							}
						}
					}
				}


				if ($currentProduct['PRIX'] <= 0 ) { $currentProduct['PRIX'] = $row['PRIX']; }
                
				$currentProduct['PRIXLOWEST'] = $product->calculateLowestPrice($currentProduct['ID']);
				array_push($listProducts, $currentProduct);
			}
			return $result = array( 'PRODUCTS' => $listProducts, 'META_KEY' =>  $metakeywords);
		}
        catch (Zend_Exception $e) {
		}
		return $result = array( 'PRODUCTS' => array(), 'META_KEY' =>  '');
	}
	

	private function isPromoActive($myPromo) {
		if ($myPromo) {
			if ($myPromo['REMISEEURO'] > 0) { return true; }
			if ($myPromo['REMISEPOUR'] > 0) { return true; }
		}
		return false;
	}
    
    
    
    private function computeUrlNavigationParent($row) {
        return $row['NAVNOM_URLPARENTS']."/".$row['CATNAVNOM'];
    }
    
    

	protected function verifyNavigationString($navnom, $nom, $suffix) {
		if (empty($navnom)) {
			return $suffix.$this->generateNavigationString($nom);
		} else {
			$filter = new Zend_Filter_Word_DashToSeparator();
			$navnom = $filter->filter($navnom);
			return $suffix.$this->generateNavigationString($navnom);
		}
	}

	protected function generateNavigationString($value) {
		$filter = new Zend_Filter();
		$filter->addFilter(new Zend_Filter_StripTags())
		->addFilter(new Zend_Filter_StringTrim())
		->addFilter(new Zend_Filter_StringToLower())
		->addFilter(new Zend_Filter_CustomAccent())
		->addFilter(new Zend_Filter_Word_SeparatorToDash());
		$result = $filter->filter($value);
        
        return preg_replace('/[^A-Za-z0-9\-\/]/', '', $result);
	}
}
	 
?>SupplierBrend.php000060400000002226150715102030010023 0ustar00<?php
class SupplierBrend extends Zend_Db_Table
{
    protected $_name = 'supplier_brend';
    protected $_primary = 'ID';

    
    
    public function getAllBrends() {
		$sql = "SELECT sb.BREND BREND, sb.URL URL, sb.ID IDBREND, s.DESCRIPTIONSHORT DESCRIPTIONSHORT, s.DESCRIPTIONLONG DESCRIPTIONLONG
				FROM supplier_brend sb
                LEFT JOIN supplier AS s ON s.ID = sb.IDSUPPLIER";
		return $this->getAdapter()->fetchAll($sql);
	}
    
    public function getAllShowableBrends() {
		$sql = "SELECT sb.BREND BREND, sb.URL URL, sb.ID IDBREND, s.DESCRIPTIONSHORT DESCRIPTIONSHORT, s.DESCRIPTIONLONG DESCRIPTIONLONG
				FROM supplier_brend sb
                LEFT JOIN supplier AS s ON s.ID = sb.IDSUPPLIER
                WHERE IS_SHOW_BREND_PAGE = 1";
		return $this->getAdapter()->fetchAll($sql);
	}
    
    
    public function getBrendByID($id) {
		$sql = "SELECT sb.BREND BREND, sb.URL URL, sb.ID IDBREND, s.DESCRIPTIONSHORT DESCRIPTIONSHORT, s.DESCRIPTIONLONG DESCRIPTIONLONG
				FROM supplier_brend sb
                LEFT JOIN supplier AS s ON s.ID = sb.IDSUPPLIER
                WHERE sb.ID = ".$id;
		return $this->getAdapter()->fetchRow($sql);
	}
}
?>Category.php000060400000047714150715102030007035 0ustar00<?php
class Category extends Zend_Db_Table
{
	protected $_name = 'category';
	protected $_primary = 'ID';

    
    public function getListIdFromParent($idCat) {
    
        $sql = "SELECT c0.ID ID, c1.ID ID1, c2.ID ID2, c3.ID ID3, c4.ID ID4
				    FROM category AS c0
				    LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
				    LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
				    LEFT JOIN category AS c3 ON c3.IDPARENT = c2.ID 
				    LEFT JOIN category AS c4 ON c4.IDPARENT = c3.ID 
				    WHERE (c0.ID = ".$idCat."  
				    OR c1.ID = ".$idCat." 
				    OR c2.ID = ".$idCat." 
				    OR c3.ID = ".$idCat." 
				    OR c4.ID = ".$idCat.")"; 
	    $result = $idCat;
	    $catsAllCheck = "/".$idCat."/";
	    $list = $this->getAdapter()->fetchAll($sql);
        foreach ($list as $cat) {
            if (!empty($cat['ID']) && strpos($catsAllCheck,"/".$cat['ID']."/") === false) {
		        $result .= ",".$cat['ID'];
                $catsAllCheck .= "/".$cat['ID']."/";
            }
            if (!empty($cat['ID1']) && strpos($catsAllCheck,"/".$cat['ID1']."/") === false) {
		        $result .= ",".$cat['ID1'];
                $catsAllCheck .= "/".$cat['ID1']."/";
            }
            if (!empty($cat['ID2']) && strpos($catsAllCheck,"/".$cat['ID2']."/") === false) {
		        $result .= ",".$cat['ID2'];
                $catsAllCheck .= "/".$cat['ID2']."/";
            }
            if (!empty($cat['ID3']) && strpos($catsAllCheck,"/".$cat['ID3']."/") === false) {
		        $result .= ",".$cat['ID3'];
                $catsAllCheck .= "/".$cat['ID3']."/";
            }
            if (!empty($cat['ID4']) && strpos($catsAllCheck,"/".$cat['ID4']."/") === false) {
		        $result .= ",".$cat['ID4'];
                $catsAllCheck .= "/".$cat['ID4']."/";
            }
	    }
        return $result;
    }
    public function updateTreeInLineAsPathOfChilds($idParent, $updateCurrent) { 
        
        $i = 0;
        if ($updateCurrent){
            $sqlCurrent = "SELECT c.* FROM category c WHERE c.ID = ".$idParent." ORDER BY c.NOM ASC ";
            $dataCurrent = $this->getAdapter()->fetchRow($sqlCurrent);  
            if ($dataCurrent) {
                $dataCurrent['NAVNOM_URLPARENTS'] = $this->getTreeInLineAsPathOf($idParent);
                $this->update($dataCurrent, 'ID = '.$idParent);
                $i++;
            }
        }
        
        $sql = "SELECT c.* FROM category c WHERE c.IDPARENT = ".$idParent." ORDER BY c.NOM ASC ";
        $cats =  $this->getAdapter()->fetchAll($sql);
        foreach($cats as $row)
        { 
            $row['NAVNOM_URLPARENTS'] = $this->getTreeInLineAsPathOf($row['ID']);
            $this->update($row, 'ID = '.$row['ID']);
            
            $i += $this->updateTreeInLineAsPathOfChilds($row['ID'], false);            
            $i++;
        }   
        return $i;
    }

	public function generateAllCategoriesMenu($idCat) {
		$dataResult = $this->computeCategoryChildToArray($idCat, 0);
		return $dataResult;
	}

	private function computeCategoryChildsOneArray($idParent, $result) {
		$dataChilds = $this->getCategoryByParent($idParent);

		$dataResult = array(
			'PARENT' => $idParent,
			'CHILDS' => $dataChilds
		);
		array_push($result, $dataResult);
		if (!empty($dataChilds) && sizeof($dataChilds) > 0) {
			foreach($dataChilds as $row) { 
				$result = $this->computeCategoryChildsOneArray($row['ID'], $result);
			}
		}
		return $result;
	}

	private function computeCategoryChildToArray($idParent, $level) {
		$dataChilds = $this->getCategoryByParent($idParent);  
		if (!empty($dataChilds) && sizeof($dataChilds) > 0) { 
			$dataReturn = array(); 
			foreach($dataChilds as $row) {                 
				$data = array(
					'CHILDS' => $this->computeCategoryChildToArray($row['ID'], $level + 1),
					'CATEGORIE' => $row,
					'LEVEL' => $level
				);
				array_push($dataReturn, $data);
			} 
			return $dataReturn;
		} else { return array(); }
	}

	private function getCategoryByParent($idParent) {
		$sql = "SELECT c.* FROM category c WHERE c.IDPARENT = ".$idParent." AND c.isACTIVE = 1";

		if ($idParent == 0) {
			$sql .= " ORDER BY c.POSITION ASC, c.ID ASC";
		} else {
			$sql .= " ORDER BY c.POSITION ASC, c.NOM ASC";
		} 
		return $this->getAdapter()->fetchAll($sql);
	}

	/**
	 *
	 * Getters
	 *
	 */
	public function getParentFirstOf($idCat) {
		$sql = "SELECT DISTINCT c0.ID ID, c0.NOM NOM, c0.IDPARENT IDPARENT , c0.NAVNOM NAVNOM
				FROM category AS c0
				LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
				LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
				LEFT JOIN category AS c3 ON c3.IDPARENT = c2.ID 
				LEFT JOIN category AS c4 ON c4.IDPARENT = c3.ID 
				LEFT JOIN category AS c5 ON c5.IDPARENT = c4.ID 
				LEFT JOIN category AS c6 ON c6.IDPARENT = c5.ID 
				LEFT JOIN category AS c7 ON c7.IDPARENT = c6.ID 
				LEFT JOIN category AS c8 ON c8.IDPARENT = c7.ID 
				LEFT JOIN category AS c9 ON c9.IDPARENT = c8.ID 
				LEFT JOIN category AS c10 ON c10.IDPARENT = c9.ID 
				WHERE ( c0.ID = ".$idCat."  
				OR c1.ID = ".$idCat." 
				OR c2.ID = ".$idCat." 
				OR c3.ID = ".$idCat." 
				OR c4.ID = ".$idCat." 
				OR c5.ID = ".$idCat." 
				OR c6.ID = ".$idCat." 
				OR c7.ID = ".$idCat." 
				OR c8.ID = ".$idCat." 
				OR c9.ID = ".$idCat." 
				OR c10.ID = ".$idCat." )
				ORDER BY c0.IDPARENT ASC 
				";
			
		return $this->getAdapter()->fetchRow($sql);
	}
    
    public function getTreeInLineAsPathOf($idCat) {
		$sql = "SELECT DISTINCT c0.ID ID, c0.NOM NOM, c0.IDPARENT IDPARENT , c0.NAVNOM NAVNOM, c0.NAVNOM_URLPARENTS NAVNOM_URLPARENTS
				FROM category AS c0
				LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
				LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
				LEFT JOIN category AS c3 ON c3.IDPARENT = c2.ID 
				LEFT JOIN category AS c4 ON c4.IDPARENT = c3.ID 
				LEFT JOIN category AS c5 ON c5.IDPARENT = c4.ID 
				LEFT JOIN category AS c6 ON c6.IDPARENT = c5.ID 
				LEFT JOIN category AS c7 ON c7.IDPARENT = c6.ID 
				LEFT JOIN category AS c8 ON c8.IDPARENT = c7.ID 
				LEFT JOIN category AS c9 ON c9.IDPARENT = c8.ID 
				LEFT JOIN category AS c10 ON c10.IDPARENT = c9.ID 
				WHERE ( c0.ID = ".$idCat."  
				OR c1.ID = ".$idCat." 
				OR c2.ID = ".$idCat." 
				OR c3.ID = ".$idCat." 
				OR c4.ID = ".$idCat." 
				OR c5.ID = ".$idCat." 
				OR c6.ID = ".$idCat." 
				OR c7.ID = ".$idCat." 
				OR c8.ID = ".$idCat." 
				OR c9.ID = ".$idCat." 
				OR c10.ID = ".$idCat." )
				ORDER BY c0.IDPARENT ASC 
				"; 

		$mylinks = array();
		$links = $this->getAdapter()->fetchAll($sql);

        if (empty($links)) {
            return '';
        }

        $result = $links[0]['NAVNOM'];
        
        if ($links[0]['IDPARENT'] == 0) {
            $result = $links[0]['NAVNOM_URLPARENTS'];
        }
        
		$mylinks[0]['ID'] = $links[0]['ID'];
		$j=0;
		for ($i=1;$i<sizeof($links);$i++) {
			foreach ($links as $link) {
				if($link['IDPARENT'] == $mylinks[$j]['ID'] && $link['ID'] != $idCat) {
					$mylinks[$i]['ID'] = $link['ID'];                    
                    $result .= "/".$link['NAVNOM'];                    
					$j++;
					break;
				}
			}
		}
		return $result;
	}
    
	public function getTreeInLineOf($idCat) {
		$sql = "SELECT DISTINCT c0.*
				FROM category AS c0
				LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
				LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
				LEFT JOIN category AS c3 ON c3.IDPARENT = c2.ID 
				LEFT JOIN category AS c4 ON c4.IDPARENT = c3.ID 
				LEFT JOIN category AS c5 ON c5.IDPARENT = c4.ID 
				LEFT JOIN category AS c6 ON c6.IDPARENT = c5.ID 
				LEFT JOIN category AS c7 ON c7.IDPARENT = c6.ID 
				LEFT JOIN category AS c8 ON c8.IDPARENT = c7.ID 
				LEFT JOIN category AS c9 ON c9.IDPARENT = c8.ID 
				LEFT JOIN category AS c10 ON c10.IDPARENT = c9.ID 
				WHERE ( c0.ID = ".$idCat."  
				OR c1.ID = ".$idCat." 
				OR c2.ID = ".$idCat." 
				OR c3.ID = ".$idCat." 
				OR c4.ID = ".$idCat." 
				OR c5.ID = ".$idCat." 
				OR c6.ID = ".$idCat." 
				OR c7.ID = ".$idCat." 
				OR c8.ID = ".$idCat." 
				OR c9.ID = ".$idCat." 
				OR c10.ID = ".$idCat." )
				ORDER BY c0.IDPARENT ASC 
				";
		$mylinks = array();
		$links = $this->getAdapter()->fetchAll($sql);

		$mylinks[0]['ID'] = $links[0]['ID'];
		$mylinks[0]['NOM'] = $links[0]['NOM'];
		$mylinks[0]['IDPARENT'] = $links[0]['IDPARENT'];
		$mylinks[0]['NAVNOM'] = $links[0]['NAVNOM'];
		$mylinks[0]['NAVNOM_URLPARENTS'] = $links[0]['NAVNOM_URLPARENTS'];
		$j=0;
		for ($i=1;$i<sizeof($links);$i++) {
			foreach ($links as $link) {
				if($link['IDPARENT'] == $mylinks[$j]['ID']) {
					$mylinks[$i]['ID'] = $link['ID'];
					$mylinks[$i]['NOM'] = $link['NOM'];
					$mylinks[$i]['IDPARENT'] = $link['IDPARENT'];
					$mylinks[$i]['NAVNOM'] = $link['NAVNOM'];
					$mylinks[$i]['NAVNOM_URLPARENTS'] = $link['NAVNOM_URLPARENTS'];
					$j++;
					break;
				}
			}
		}
		return $mylinks;
	}
	public function getTreeCatsOfParent($idCat) {
			
		$sql = "SELECT c0.NOM NOM0, c1.NOM NOM1,
						c0.URL URL0, c1.URL URL1,
						c0.URL_SLIDE URLSLIDE0, c1.URL_SLIDE URLSLIDE1,
						c0.ID ID0, c1.ID ID1,
						c0.isACTIVE isACTIVE0, c1.isACTIVE isACTIVE1,
						c0.IDPARENT IDPARENT0, c1.IDPARENT IDPARENT1,
						c0.NAVNOM NAVNOM0, c1.NAVNOM NAVNOM1,
						c0.DESCRIPTION DESCRIPTION0, c1.DESCRIPTION DESCRIPTION1,
						c0.DESCRIPTIONLONG DESCRIPTIONLONG0, c1.DESCRIPTIONLONG DESCRIPTIONLONG1,
						c0.NAVNOM_URLPARENTS NAVNOM_URLPARENTS0, c1.NAVNOM_URLPARENTS NAVNOM_URLPARENTS1
				FROM category AS c0
				LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
				WHERE c0.IDPARENT = ".$idCat."
				ORDER BY c0.ID,c1.ID ASC;
				";
		$results = $this->getAdapter()->fetchAll($sql);
			
		$listCat = array();
		$i = 0;
		$j = 0;
		$idParent = 0;
		$isNew = true;
		$isFirst = true;
		foreach($results as $row) {
			if ($row['ID0'] != $idParent) {
				$idParent = $row['ID0'];
				$isNew = true;
				$i++;
				$j = 0 ;
				if ($isFirst) {$i = 0; $isFirst = false;}
			} else {
				$isNew = false;
			}
			if ($isNew) {
				if ($row['isACTIVE0'] == true) {
					$listCat[$i]['NOM'] = $row['NOM0'];
					$listCat[$i]['ID'] = $row['ID0'];
					$listCat[$i]['URL'] = $row['URL0'];
					$listCat[$i]['URL_SLIDE'] = $row['URLSLIDE0'];
					$listCat[$i]['NAVNOM'] = $row['NAVNOM0'];
					$listCat[$i]['DESCRIPTION'] = $row['DESCRIPTION0'];
					$listCat[$i]['DESCRIPTIONLONG'] = $row['DESCRIPTIONLONG0'];
					$listCat[$i]['isACTIVE'] = $row['isACTIVE0'];
					$listCat[$i]['NAVNOM_URLPARENTS'] = $row['NAVNOM_URLPARENTS0'];
					$listCat[$i]['SUBS'] = array();
				}
			}

			if ($row['isACTIVE1'] == true) {
				$listCat[$i]['SUBS'][$j]['NOM'] = $row['NOM1'];
				$listCat[$i]['SUBS'][$j]['ID'] = $row['ID1'];
				$listCat[$i]['SUBS'][$j]['URL'] = $row['URL1'];
				$listCat[$i]['SUBS'][$j]['URL_SLIDE'] = $row['URLSLIDE1'];
				$listCat[$i]['SUBS'][$j]['DESCRIPTION'] = $row['DESCRIPTION1'];
				$listCat[$i]['SUBS'][$j]['DESCRIPTIONLONG'] = $row['DESCRIPTIONLONG1'];
				$listCat[$i]['SUBS'][$j]['NAVNOM'] = $row['NAVNOM1'];
				$listCat[$i]['SUBS'][$j]['isACTIVE'] = $row['isACTIVE1'];
				$listCat[$i]['SUBS'][$j]['NAVNOM_URLPARENTS'] = $row['NAVNOM_URLPARENTS1'];
				$j++;
			}
		}
		return $listCat;
			
	}
    
    private function getTreeCatsOfWithLevelCompute(&$listCat, $row, $index) {
        $listCat['NOM'] = $row["NOM".$index];
		$listCat['NAVTITRENOM'] = $row['NAVTITRENOM'.$index];
		$listCat['NAVDESCRIPTION'] = $row['NAVDESC'.$index];
		$listCat['ID'] = $row['ID'.$index];
		$listCat['URL'] = $row['URL'.$index];
		$listCat['URL_SLIDE'] = $row['URLSLIDE'.$index];
		$listCat['NAVNOM'] = $row['NAVNOM'.$index];
		$listCat['KEYWORDS'] = $row['KEYWORDS'.$index];
		$listCat['DESCRIPTION'] = $row['DESCRIPTION'.$index];
		$listCat['DESCRIPTIONLONG'] = $row['DESCRIPTIONLONG'.$index];
		$listCat['DESCRIPTIONSHORT'] = $row['DESCRIPTIONSHORT'.$index];
		$listCat['CHOICEURL'] = $row['CHOICEURL'.$index];
		$listCat['CHOICEDOC'] = $row['CHOICEDOC'.$index];
		$listCat['isACTIVE'] = $row['isACTIVE'.$index];
		$listCat['IDPARENT'] = $row['IDPARENT'.$index];
		$listCat['NAVNOM_URLPARENTS'] = $row['NAVNOM_URLPARENTS'.$index];
		$listCat['NBPRODUCT'] = $row['NBPRODUCT'];
    }
    
    
	public function getTreeCatsOfWithLevel($idCat, $isSubLevels) {
        $sql = "SELECT c0.NOM NOM0, c1.NOM NOM1,
						c0.NAVTITRENOM NAVTITRENOM0, c1.NAVTITRENOM NAVTITRENOM1,
						c0.NAVDESCRIPTION NAVDESC0, c1.NAVDESCRIPTION NAVDESC1,
						c0.URL URL0, c1.URL URL1,
						c0.URL_SLIDE URLSLIDE0, c1.URL_SLIDE URLSLIDE1,
						c0.ID ID0, c1.ID ID1,
						c0.IDPARENT IDPARENT0, c1.IDPARENT IDPARENT1,
						c0.NAVNOM NAVNOM0, c1.NAVNOM NAVNOM1,
						c0.DESCRIPTION DESCRIPTION0, c1.DESCRIPTION DESCRIPTION1,
						c0.DESCRIPTIONLONG DESCRIPTIONLONG0, c1.DESCRIPTIONLONG DESCRIPTIONLONG1,
						c0.DESCRIPTIONSHORT DESCRIPTIONSHORT0, c1.DESCRIPTIONSHORT DESCRIPTIONSHORT1,
						c0.KEYWORDS KEYWORDS0, c1.KEYWORDS KEYWORDS1,
						c0.CHOICEURL CHOICEURL0, c1.CHOICEURL CHOICEURL1,
						c0.CHOICEDOC CHOICEDOC0, c1.CHOICEDOC CHOICEDOC1,
						c0.isACTIVE isACTIVE0, c1.isACTIVE isACTIVE1,
						c0.NAVNOM_URLPARENTS NAVNOM_URLPARENTS0, c1.NAVNOM_URLPARENTS NAVNOM_URLPARENTS1,
						(Select count(1) from product as p where p.idcategory = c1.id and p.isactive = 0) NBPRODUCT";
				
        if ($isSubLevels) {
            $sql .= ", c2.NOM NOM2,
                    c2.NAVTITRENOM NAVTITRENOM2, 
                    c2.NAVDESCRIPTION NAVDESC2, 
                    c2.URL URL2, 
                    c2.URL_SLIDE URLSLIDE2, 
                    c2.ID ID2,  
                    c2.IDPARENT IDPARENT2, 
                    c2.NAVNOM NAVNOM2,  
                    c2.DESCRIPTION DESCRIPTION2,  
                    c2.DESCRIPTIONLONG DESCRIPTIONLONG2, 
                    c2.DESCRIPTIONSHORT DESCRIPTIONSHORT2, 
                    c2.KEYWORDS KEYWORDS2, 
                    c2.CHOICEURL CHOICEURL2, 
                    c2.CHOICEDOC CHOICEDOC2, 
                    c2.isACTIVE isACTIVE2, 
                    c2.NAVNOM_URLPARENTS NAVNOM_URLPARENTS2
                FROM category AS c0
				LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
				LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
				WHERE c0.ID = ".$idCat."  
				ORDER BY c0.POSITION ASC,c1.POSITION,c2.POSITION ASC;
				";
        } else {
            $sql .= " FROM category AS c0
				LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
				WHERE c0.ID = ".$idCat."  
				ORDER BY c0.POSITION ASC,c1.POSITION ASC;
				";
        }
         
		$results = $this->getAdapter()->fetchAll($sql);
		$listCat = array();
		$listCat['SUBS'] = array();
		$j = -1;
        $k = -1;
        $lastLvl0 = 0;
        $lastLvl1 = 0;
        $lastLvl2 = 0;
		foreach($results as $row) {
            if ($lastLvl0 != $row['ID0']) {
                $this->getTreeCatsOfWithLevelCompute($listCat, $row, "0");
                $lastLvl0 = $row['ID0'];
            }
                
			if (!empty($row['isACTIVE1']) && $row['isACTIVE1'] == true && !empty($row['NOM1'])) {
                if ($lastLvl1 != $row['ID1']) {
				    $j++; 
                    $listCat['SUBS'][$j] = array();
                    $this->getTreeCatsOfWithLevelCompute($listCat['SUBS'][$j], $row, "1");
                    $lastLvl1 = $row['ID1'];
                }
                if ($isSubLevels && $lastLvl2 != $row['ID2']) {
                    if (!empty($row['isACTIVE2']) && $row['isACTIVE2'] == true && !empty($row['NOM2'])) {
                        $k++;
				        $listCat['SUBS'][$j]['SUBS'][$k] = array();
                        $this->getTreeCatsOfWithLevelCompute($listCat['SUBS'][$j]['SUBS'][$k], $row, "2");
                        $lastLvl2 = $row['ID2'];
                    }
                }
			}
		}
		return $listCat;
    }
    
	public function getTreeCatsOf($idCat) {
		return $this->getTreeCatsOfWithLevel($idCat, false);
	}

	public function getAllCategoriesByID ($idParent) {
		$sql = "
		SELECT c0.NOM NOM0, c1.NOM NOM1, c2.NOM NOM2, c3.NOM NOM3, c4.NOM NOM4, c5.NOM NOM5, 
				c6.NOM NOM6, c7.NOM NOM7, c8.NOM NOM8, c9.NOM NOM9, c10.NOM NOM10,
				c0.isACTIVE isACTIVE0, c1.isACTIVE isACTIVE1, c2.isACTIVE isACTIVE2, c3.isACTIVE isACTIVE3, c4.isACTIVE isACTIVE4, c5.isACTIVE isACTIVE5, 
				c6.isACTIVE isACTIVE6, c7.isACTIVE isACTIVE7, c8.isACTIVE isACTIVE8, c9.isACTIVE isACTIVE9, c10.isACTIVE isACTIVE10,
				c0.URL URL0, c1.URL URL1, c2.URL URL2, c3.URL URL3, c4.URL URL4, c5.URL URL5, 
				c6.URL URL6, c7.URL URL7, c8.URL URL8, c9.URL URL9, c10.URL URL10,
				c0.ID ID0, c1.ID ID1, c2.ID ID2, c3.ID ID3, c4.ID ID4, c5.ID ID5, 
				c6.ID ID6, c7.ID ID7, c8.ID ID8, c9.ID ID9, c10.ID ID10,
				c0.IDPARENT IDPARENT0, c1.IDPARENT IDPARENT1, c2.IDPARENT IDPARENT2, c3.IDPARENT IDPARENT3, c4.IDPARENT IDPARENT4, c5.IDPARENT IDPARENT5, 
				c6.IDPARENT IDPARENT6, c7.IDPARENT IDPARENT7, c8.IDPARENT IDPARENT8, c9.IDPARENT IDPARENT9, c10.IDPARENT IDPARENT10
		FROM category AS c0
		LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
		LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
		LEFT JOIN category AS c3 ON c3.IDPARENT = c2.ID 
		LEFT JOIN category AS c4 ON c4.IDPARENT = c3.ID 
		LEFT JOIN category AS c5 ON c5.IDPARENT = c4.ID 
		LEFT JOIN category AS c6 ON c6.IDPARENT = c5.ID 
		LEFT JOIN category AS c7 ON c7.IDPARENT = c6.ID 
		LEFT JOIN category AS c8 ON c8.IDPARENT = c7.ID 
		LEFT JOIN category AS c9 ON c9.IDPARENT = c8.ID 
		LEFT JOIN category AS c10 ON c10.IDPARENT = c9.ID 
		WHERE c0.IDPARENT = ".$idParent."
		ORDER BY c0.ID,c1.POSITION,c2.POSITION,c3.POSITION,c4.POSITION,c5.POSITION,c6.POSITION,c7.POSITION,c8.POSITION,c9.POSITION,c10.POSITION ASC;
    	"; 
		return $this->getAdapter()->fetchAll($sql);
	}
	
public function getAllCategoriesIDByID ($idParent) {
		$sql = "
		SELECT c0.ID ID0, c1.ID ID1, c2.ID ID2, c3.ID ID3, c4.ID ID4, c5.ID ID5, 
				c6.ID ID6, c7.ID ID7, c8.ID ID8, c9.ID ID9, c10.ID ID10
		FROM category AS c0
		LEFT JOIN category AS c1 ON c1.IDPARENT = c0.ID
		LEFT JOIN category AS c2 ON c2.IDPARENT = c1.ID
		LEFT JOIN category AS c3 ON c3.IDPARENT = c2.ID 
		LEFT JOIN category AS c4 ON c4.IDPARENT = c3.ID 
		LEFT JOIN category AS c5 ON c5.IDPARENT = c4.ID 
		LEFT JOIN category AS c6 ON c6.IDPARENT = c5.ID 
		LEFT JOIN category AS c7 ON c7.IDPARENT = c6.ID 
		LEFT JOIN category AS c8 ON c8.IDPARENT = c7.ID 
		LEFT JOIN category AS c9 ON c9.IDPARENT = c8.ID 
		LEFT JOIN category AS c10 ON c10.IDPARENT = c9.ID 
		WHERE c0.IDPARENT = ".$idParent;   
		return $this->getAdapter()->fetchAll($sql);
	}
 
	public function getIdCatFromProductId($idProd) {
		$sql = "
		SELECT p.IDCATEGORY ID
		FROM product AS p
		WHERE p.ID = ".$idProd;
		$data = $this->getAdapter()->fetchRow($sql);
		return $data['ID'];
	}
	
	public function getAllSubsIDByIDToString($idCat) {
        if ($idCat != null && (int)$idCat > 0) {
		    $listCat = $this->getAllCategoriesIDByID($idCat);
		    $listTemp = array();
		    $value = 'ID';
		    $listCatString = $idCat;
		
		    //list of sub cats
		    foreach ($listCat as $row) {
			    for ($level=0 ; $level<11; $level++) {
				    if ((!isset($listTemp[$value.$level]) || $listTemp[$value.$level] != $row[$value.$level]) && $row[$value.$level] != null) {
					    $listTemp[$value.$level] = $row[$value.$level];
					    if ($listCatString !="") {
						    $listCatString .= ' ,'.$row[$value.$level];
					    } else {
						    $listCatString = $row[$value.$level];
					    }
				    } 
			    }
		    }
		    return $listCatString;
        } 
        return "";
	}


	public function getAllCategoriesProperties() {
		$sql = "SELECT c.* FROM category c ORDER BY c.NOM ASC ";
		$cats = $this->getAdapter()->fetchAll($sql);
		$data = array();
		foreach($cats as $row)
		{
			$data[$row['ID']] = array(
				'ID' => $row['ID'],
				'NOM' => $row['NOM'],
				'URL' => $row['URL'],
				'NAVNOM' => $row['NAVNOM'],
				'isACTIVE' => $row['isACTIVE']
			);
		}
		return $data;
	}

	private function getCategoryById($idCat) {
		$sql = "SELECT c.* FROM category c WHERE c.ID = ".$idCat." ORDER BY c.NOM ASC";
		$cats = $this->getAdapter()->fetchAll($sql);
		$data = array();
		foreach ($cats AS $row) {
			$data[$row['ID']] = $row['NOM'];
		}
		return $data;
	}
     
    public function canBeMigrate($id) {
    	$sql = "
		SELECT count(*) TOTAL
		FROM category AS c
		WHERE c.isACTIVE = 0 AND c.IDPARENT = ".$id;
		$data = $this->getAdapter()->fetchRow($sql); 
    	return (int)$data['TOTAL'] == 0;
	}
    
}
?>CommandProduct.php000060400000000204150715102030010156 0ustar00<?php
class CommandProduct extends Zend_Db_Table
{
    protected $_name = 'command_product';
    protected $_primary = 'ID';
 	
}
?>KeyWord.php000060400000001437150715102030006634 0ustar00<?php
class KeyWord extends Zend_Db_Table
{
    protected $_name = 'key_word';
    protected $_primary = 'ID';

    public function getLists() {
    	return $this->select()->order('KEYWORD ASC')->query()->fetchAll();
	}
	 
	public function isExist($word) {  
		$sql = "
			SELECT k.*
			FROM key_word k 
			WHERE k.KEYWORD = '".$word."'";
		$results = $this->getAdapter()->fetchAll($sql);
		if (isset($results) && !empty($results)) { return true; }
		return false;
	}
	
	public function findByKeyword($word) {  
		$sql = "
			SELECT k.KEYWORD as KEYWORD
			FROM key_word k 
			WHERE k.KEYWORD LIKE '%".$word."%'
			LIMIT 20";
		$results = $this->getAdapter()->fetchAll($sql);
		$result = array();
		foreach ($results as $row) {
			array_push($result, $row['KEYWORD']);
		} 
		return $result;
	}
}
?>ProductChildOption.php000060400000000212150715102030011013 0ustar00<?php
class ProductChildOption extends Zend_Db_Table
{
    protected $_name = 'productchild_option';
    protected $_primary = 'ID';

}
?>Pays.php000060400000000473150715102030006163 0ustar00<?php
class Pays extends Zend_Db_Table
{
    protected $_name = 'pays_fr';
    protected $_primary = 'ID';
	
	public function getPaysFR() {
		$select = "SELECT p.ID ID, p.PAYS PAYS, p.CODE CODE, p.LOCAL LOCAL
				FROM pays_fr AS p
				ORDER BY PAYS ASC;";
		
		return $this->getAdapter()->fetchAll($select);
	}
}
?>CategoryTypeTri.php000060400000002313150715102030010340 0ustar00<?php
class CategoryTypeTri extends Zend_Db_Table
{
    protected $_name = 'category_type_tri';
    protected $_primary = 'ID';
 
    public function getListTriByCategory($idcat) { 
    	try { return $this->select()->where("IDCATEGORY = ?", $idcat)->query()->fetchAll();
    	} catch (Zend_Exception $e) { return array(); }
	}
	
	public function getListTriByCategoryInOneRow($idcat) {
		try { 
			$list = $this->getListTriByCategory($idcat);
			if (!empty($list)) { 
				$data = array();
				foreach ($list as $row) {
					if (!empty($row['TITRE'])) { $data['TITRE_'.$row['TYPE'].'_'.$row['IDTRI']] = $row['TITRE']; }
					if (!empty($row['DESCRIPTION'])) { $data['DESC_'.$row['TYPE'].'_'.$row['IDTRI']] = $row['DESCRIPTION']; }
					if (!empty($row['KEYWORDS'])) { $data['KEYWORD_'.$row['TYPE'].'_'.$row['IDTRI']] = $row['KEYWORDS']; } 
				}
				return $data;
			}
    	} catch (Zend_Exception $e) { return array(); }
    	return array();
	} 
	
	public function getInfoByCatTypeTri($idcat, $type, $idtri) {
		try {  
			return $this->select()->where("IDCATEGORY = ?", $idcat)
			->where("TYPE = ?", $type)
			->where("IDTRI = ?", $idtri)
			->query()->fetch(); 
		} catch (Zend_Exception $e) { return array(); }
	}
     
}
?>Supplier.php000060400000000165150715102030007050 0ustar00<?php
class Supplier extends Zend_Db_Table
{
    protected $_name = 'supplier';
    protected $_primary = 'ID';

}
?>