Current File : /home/karenpetzb/application/modules/backoffice/controllers/ProductController.php
<?php
class Backoffice_ProductController extends Modules_Backoffice_Controllers_MainController
{

	public function init()
	{
		$this->view->title = "Administration";
		$this->view->currentMenu = "Product";

		$this->isConnectedWithRole('isProduct'); 
	}
	public function indexAction()
	{
		$this->_forward('/list');

	}
    
    private function indexproductById($id) {
       try {    
			if ($id > 0) {
                try
                {      
                    if (empty($this->FeatureElasticSearchWsdl) || empty($this->FeatureElasticSearchUsername) || empty($this->FeatureElasticSearchKey)) {
		                return ;
                    }
                    $soapClient = $this->getSoapClient($this->FeatureElasticSearchWsdl);
                    $request = $this->getSoapHeader($this->FeatureElasticSearchUsername, $this->FeatureElasticSearchKey);
                    $request->ProductId = $id;
                
                    $parameters = new stdClass();
                    $parameters->request = $request;
                    $soapClient->PushProduct($parameters);
                    $soapClient = null; 
                }
                catch (SoapFault $fault)
                {
					$this->log('SOAP : indexproductById : '.$fault->faultcode.' '.$fault->faultstring,'err'); 
                }   
            }
		}
        catch (Zend_Exception $e) {
			$this->log($e->getMessage(),'err'); 
		}  
    }
    
    public function indexproductAction() {
       try {    
			$id = (int)$this->_request->getParam('id');
			if ($id > 0) {
                $soapClient = $this->getSoapClient($this->FeatureElasticSearchWsdl);
                $result = new stdClass();
                try
                {     
                    $request = $this->getSoapHeader($this->FeatureElasticSearchUsername, $this->FeatureElasticSearchKey);
                    $request->ProductId = $id;
                
                    $parameters = new stdClass();
                    $parameters->request = $request;
                    $result = $soapClient->PushProduct($parameters);
                }
                catch (SoapFault $fault)
                {
					$this->log('SOAP : indexProductAction : '.$fault->faultcode.' '.$fault->faultstring,'err'); 
                }
                $soapClient = null;    
            }
		}
        catch (Zend_Exception $e) {
			$this->log($e->getMessage(),'err'); 
		} 
		$this->_forward('/edit');
    }
	 
	public function uploadpicsAction() {
		if(!empty($_FILES['file']) && !empty($_FILES['file']['name'])) {
			$nomOrigine = $_FILES['file']['name'];
			$elementsChemin = pathinfo($nomOrigine);
			$extensionFichier = strtolower($elementsChemin['extension']);
			$extensionsAutorisees = array("jpeg", "jpg", "gif", "png");
			if (!(in_array($extensionFichier, $extensionsAutorisees))) {
				$this->view->messageError = "Le fichier n'a pas l'extension attendue";
			} else {
				// Copie dans le repertoire du script avec un nom
				$repertoireDestination = 'items/product/'.$this->_request->getParam('idcat').'/';
				$this->checkDirectoryExist($repertoireDestination);
				
				/*$date = new Zend_Date();					
				$nomDestination = $date->toString('dd-MM-YYYY_HH-mm-ss').".".$extensionFichier;*/
                
				$nomDestination = $this->generateNavigationString($elementsChemin['filename']).".".$extensionFichier;
                $fileoriginal = $repertoireDestination.$nomDestination;
                
				$adminNamespace = $this->getSession();
				if (move_uploaded_file($_FILES["file"]["tmp_name"],$fileoriginal)) {
					try {
						$picture = new Picture();
						$data = array (
					 		'URL' => $fileoriginal,
					 		'IDPRODUCT' => $this->_request->getParam('id'),
							'POSITION' => $adminNamespace->imgPosDefault
						);
						$picture->insert($data);

						$messageSuccess = "L'image a �t� ajout�e";
                        
                        //Resize picture
                        $info = getimagesize($fileoriginal) ;
                        list($width_old, $height_old) = $info;
                        $maxwidth = $this->FeaturePictureResizeWidth;
                        $maxheight = $this->FeaturePictureResizeHeight;
                            
                        if ($width_old > $maxwidth || $height_old > $maxheight) {     
                            Utils_Tool::smart_resize_image($fileoriginal , null, $maxwidth , $maxheight , true , $fileoriginal , true , false ,50 );
                            $messageSuccess .= " et redimensionn�e.";
                        }  
                           
                        $this->view->messageSuccess = $messageSuccess; 
					} catch (Exception $e) {
						$this->view->messageError = $e->getMessage();
					}
				} else {
					$this->view->messageError = "Le fichier n'a pas �t� upload�";
				}
			}
		}
		$this->_forward('/edit');
	}

	public function editpictureAction() {

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->isPost()) {
			$params = $this->_request->getPost();
			try {
				$picture = new Picture();
				for ($i=0; $i<$params['nbrImg']; $i++) {
					$data = array (
					 		'POSITION' => $params['position'.$i],
					 		'STRING1' => $params['string1_'.$i],
					 		'STRING2' => $params['string2_'.$i]
					);
					$picture->update($data,'ID = '.$params['id'.$i]);
				}
				$this->view->messageSuccess = "Les images ont �t� modifi�es";

			} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
				$this->view->messageError = $e->getMessage();
			}
		}
		$this->_forward('/edit');

	}
	public function setpictureAction() {

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->isPost()) {
			$params = $this->_request->getPost();
			try {
				$picture = new Picture();
				$adminNamespace = $this->getSession();
				$data = array (
					 		'URL' => $params['picture'],
					 		'IDPRODUCT' => $this->_request->getParam('id'),
							'POSITION' => $adminNamespace->imgPosDefault,
					 		'STRING1' => '',
					 		'STRING2' => ''
							
					 		);
					 		$picture->insert($data);
					 		$this->view->messageSuccess = "Les images ont �t� modifi�es";
			} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
				$this->view->messageError = $e->getMessage();
			}
		}
		$this->_forward('/edit');

	}
	public function delpictureAction() {

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->getParam('pic')) {
			$id = (int)$this->_request->getParam('pic');
			if ($id > 0) {
				try {
					$picture = new Picture();
					$picture->delete('ID = '.$id);

					$this->view->messageSuccess = "L'image a �t� supprim�e";

				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
				}
			}
		}
		$this->_forward('/edit');

	}
	public function erasepictureAction() {

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->isPost()) {
			$params = $this->_request->getPost();
			try {
				$product = new Product();
				$sql = "
						SELECT p.NOM NOM, p.ID ID 
						FROM product AS p
						LEFT JOIN picture AS pic ON pic.IDPRODUCT = p.ID
						WHERE pic.URL = '".$params['picture']."' 
						AND p.ID <> ".$params['id'];
				$isExistProduct = $product->getAdapter()->fetchRow($sql);

				$pic = new Picture();
				if (!$isExistProduct) {
					unlink($params['picture']);
					$this->view->messageSuccess = "L'image a �t� supprim�e definitivement";
				} else {
					if ($isExistProduct['ID'] == $params['id']) {
						unlink($params['picture']);
						$pic->delete('URL LIKE ?',$params['picture']);
						$this->view->messageSuccess = "L'image a �t� supprim�e definitivement";
					} else {
						$this->view->messageError = "L'image est utilis�e par : ".$isExistProduct['NOM'];
					}
				}

			} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
				$this->view->messageError = $e->getMessage();
			}
		}
		$this->_forward('/edit');

	}
	public function searchAction()
	{
		$this->view->titlePage = "Recherche avanc�e des produits";

		$supplierBrend = new SupplierBrend();
		$this->view->listbrend = $supplierBrend->fetchAll($supplierBrend->select()->order('BREND ASC'));

		$adminNamespace = $this->getSession();
			
		$option = new Option();
		$this->view->listoption = $option->fetchAll();
		$this->view->listSearch = array();
		if ($this->_request->isPost() || isset($adminNamespace->searchCategory)) {

			$params = $this->_request->getParams();

			$filter = new Zend_Filter_StringTrim();

			$nomtemp = $filter->filter($params['search']);

			if (empty($nomtemp)) { $nomtemp = '%'; } else { $nomtemp = '%'.$nomtemp.'%'; }
			if (!empty($params['prixMin']) && !empty($params['prixMax'])) { $params['prix'] = 'BETWEEN '.(float)$params['prixMin'].' AND '.(float)$params['prixMax'] ; }
			
			$product = new Product();
			$select = "
				SELECT DISTINCT p.NOM NOM, p.DESCRIPTIONSHORT DESCRIPTIONSHORT, p.PRIX PRIX, p.ID ID, p.isACTIVE isACTIVE, p.isPROMO isPROMO
				FROM product AS p
				LEFT JOIN productchild AS pc ON pc.IDPRODUCT = p.ID
				LEFT JOIN productchild_option AS pco ON pco.IDPRODUCTCHILD = pc.ID
				LEFT JOIN product_option AS po ON po.IDPRODUCT = p.ID ";
			if (!empty($params['image']) && $params['image']==0) { $select .= "LEFT JOIN picture AS pic ON pic.IDPRODUCT = p.ID "; }
			
			$select .= "WHERE (p.NOM LIKE '".$nomtemp."' OR pc.REFERENCE LIKE '".$nomtemp."' OR pc.DESIGNATION LIKE '".$nomtemp."') ";
			// Requete trop longue avec : OR p.DESCRIPTIONSHORT LIKE '".$nomtemp."' OR p.DESCRIPTIONTECH LIKE '".$nomtemp."' OR p.DESCRIPTIONLONG LIKE '".$nomtemp."' OR p.DESCRIPTIONNORME LIKE '".$nomtemp."'
		
			if (!empty($params['prixMin']) && !empty($params['prixMax'])) { $select .= "AND (pc.PRIX >= ".$params['prixMin']." AND p.PRIX <= ".$params['prixMax'].") "; }
			if (!empty($params['prixMin']) && empty($params['prixMax'])) { $select .= "AND pc.PRIX >= ".$params['prixMin']." "; }
			if (empty($params['prixMin']) && !empty($params['prixMax'])) { $select .= "AND pc.PRIX <= ".$params['prixMax']." "; }			
			if (!empty($params['image']) && $params['image']==0) { $select .= "AND pic.POSITION = 1 "; }
			if (!empty($params['image']) && $params['image']==1) { $select .= "AND NOT EXISTS ( SELECT * FROM picture pic WHERE pic.IDPRODUCT = p.ID AND pic.POSITION = 1) "; }			
			if (!empty($params['idcategorySearch']) && $params['idcategorySearch']!='All') { $select .= "AND p.IDCATEGORY = ".$params['idcategorySearch'].' '; }
			if (!empty($params['active']) && $params['active']!=2) { $select .= "AND p.isACTIVE LIKE '".$params['active']."' "; }
			if (!empty($params['activePromo']) && $params['activePromo']!=2) { $select .= "AND p.isPROMO LIKE '".$params['activePromo']."' "; }
			if (!empty($params['idbrend']) && $params['idbrend']!='All') { $select .= "AND p.IDBREND = ".$params['idbrend']." "; }
			if (!empty($params['etatstock']) && $params['etatstock']!=3) { $select .= "AND pc.ETATSTOCK LIKE '".$params['etatstock']."' "; }
			if (!empty($params['optionId']) && $params['optionId']!='All') { $select .= "AND pco.IDOPTION LIKE '".$params['optionId']."' "; }
			if (!empty($params['optionValue'])) { $select .= "AND pco.VALUE LIKE '".$params['optionValue']."' "; }

			$select .= "ORDER BY NOM ASC";
			
			try {
				$picture = new Picture();
				$sql = $picture->fetchAll('POSITION = 1');
				$listpics = array();
				foreach ($sql as $row) {
					$listpics[$row['IDPRODUCT']] = $row['URL'];
				}
				$this->view->listproductpicture = $listpics;
					
				$listTemp = $product->getAdapter()->fetchAll($select);
				$this->view->listSearch = $listTemp;
				if ($nomtemp == '%') {
					$nomtemp = '';
				}
				$params['search'] = $filter->filter($params['search']);
				if (!empty($params['search']) && empty($params['idcategorySearch'])) {
					$params = array (
				 		'search' => $params['search'],
				 		'prixMin' => '',
				 		'prixMax' => '',
				 		'active' => '2',
				 		'image' => '2',
				 		'activePromo' => '2',
				 		'idbrend' => 'All',
				 		'etatstock' => '3',
				 		'optionId' => 'All',
				 		'optionValue' => '',
				 		'idcategorySearch' => 'All'
				 		);	
				}
				
				$this->view->populateForm = $params;

				$this->view->messageSuccess = count($listTemp).' Resultats';
				$this->view->messageError = "";

			} catch (Exception $e) {
				$this->log($e->getMessage(),'err');
				$this->view->messageSuccess = "";
				$this->view->messageError = $e->getMessage().' <br><br>'.$select;
			}
		} else {

			$params = array (
			 		'search' => '',
			 		'prixMin' => '',
			 		'prixMax' => '',
			 		'active' => '2',
			 		'image' => '2',
			 		'activePromo' => '2',
			 		'idbrend' => 'All',
			 		'etatstock' => '3',
			 		'optionId' => 'All',
			 		'optionValue' => '',
			 		'idcategorySearch' => 'All'
			 		);
			 		$this->view->populateForm = $params ;
		}
	}

	public function listAction()
	{
		$this->view->titlePage = "Rechercher des produits";
		$adminNamespace = $this->getSession();
			
		//Gestion des tris
		$table = 'NOM';
		$tri = 'ASC';
		$this->view->searchCategory = 0;
		$this->view->listproducts = array();
		if ($this->_request->isPost() || isset($adminNamespace->searchCategory)) {
			if ($this->_request->getParam('categorySearch') != null) {
				$adminNamespace->searchCategory = $this->_request->getParam('categorySearch');
				
				$adminNamespace->searchCategoryActive = "1";
				if ($this->_request->getParam('isActive') != null) {
					$adminNamespace->searchCategoryActive = "0";
				}
			}
			$isActive = $adminNamespace->searchCategoryActive;
			$id = $adminNamespace->searchCategory;
			$this->view->searchCategory = $id;
			$this->view->searchCategoryActive = $adminNamespace->searchCategoryActive;

			//Appel model pour listing

			$category = new Category();
			$select = "
				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.ID = ".$id;

			$listTemp = $category->getAdapter()->fetchAll($select);
			$listTemp2 = array();
			$listCat = "";

			foreach ($listTemp as $row) {
				for ($level=0 ; $level<11; $level++) {
					if ((!isset($listTemp2['ID'.$level]) || $listTemp2['ID'.$level] != $row['ID'.$level]) && $row['ID'.$level] != null) {
						$listTemp2['ID'.$level] = $row['ID'.$level];
						if ($listCat!="") {
							$listCat .= ' ,'.$row['ID'.$level];
						} else {
							$listCat = $row['ID'.$level];
						}
					}
				}
			}

			$select = "SELECT ID, NOM, DESCRIPTIONSHORT, PRIX, isACTIVE, isPROMO, IDCATEGORY
			FROM product 
			WHERE IDCATEGORY IN (".$listCat.")
			AND isACTIVE = ".$isActive."
			ORDER BY NOM ASC"; 
 
			$product = new Product();
			$listprods = $product->getAdapter()->fetchAll($select);

			$this->view->messageSuccess = sizeof($listprods)." resultats";
			$picture = new Picture();
			$sql = $picture->fetchAll('POSITION = 1');
			$listpics = array();
			foreach ($sql as $row) {
				$listpics[$row['IDPRODUCT']] = $row['URL'];
			}
			$this->view->listproductpicture = $listpics;
			$this->view->listproducts = $listprods;
		}
	}

	public function editlistAction () {
		if ($this->_request->isPost()) {
			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty())
			-> addValidator(new Zend_Validate_StringLength(3));

			//get the form params
			$params = $this->_request->getPost();


			$data = array (
			 		'NOM' => $filter->filter($params['nom']),
			 		'DESCRIPTIONSHORT' => $filter->filter($params['descshort']),
			 		'PRIX' => $filter->filter($params['prix'])
			);

			if ($validator->isValid($data['NOM']) &&
			$validator->isValid($data['DESCRIPTIONSHORT']) &&
			$validator->isValid($data['PRIX'])
			) {
					
				try {
					$product = new Product();
					$product->update($data, 'ID = '.$params['productid']);

					$this->view->messageSuccess = "Le produit a �t� mis a jour";

				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
					$this->_forward('/list');
				}
			} else {
				foreach ($validator->getErrors() as $errorCode) {
					$this->view->messageError .=  $this->getErrorValidator($errorCode);
				}
			}
		}
		$this->_forward('/list');

	}

	public function addAction()
	{
			
		$this->view->titlePage = "Ajouter un produit";
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

			
		$supplierBrend = new SupplierBrend();
		$this->view->listbrend = $supplierBrend->fetchAll($supplierBrend->select()->order('BREND ASC'));

			
		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty());

			//get the form params
			$params = $this->_request->getPost();

			$date = new Zend_Date();

			$navtemp = $filter->filter($params['nom']);
			$navnom =  $this->generateNavigationString($navtemp);
			$keywords =  $this->generateKeyWords($navtemp);

			$data = array (
			 		'NOM' => $navtemp,
			 		'NAVNOM' => $navnom,
			 		'KEYWORDS' => $keywords,
					'NAVTITRE' => $navtemp,
					'NAVDESC' => $params['descshort'],
			 		'DESCRIPTIONSHORT' => $params['descshort'],
			 		'DESCRIPTIONLONG' => $params['desclong'],
			 		'PRIX' => $filter->filter($params['prix']),
			 		'isACTIVE' => $filter->filter($params['active']),
					'DATEPROMO' => $date->toString('YYYY-MM-dd'),
			 		'isPROMO' => '1',
			 		'IDBREND' => $filter->filter($params['idbrend']),
			 		'IDCATEGORY' => $filter->filter($params['idcategory'])
			);

			if ($validator->isValid($data['NOM']) &&
			$validator->isValid($data['NAVNOM']) &&
			$validator->isValid($data['DESCRIPTIONSHORT']) &&
			$validator->isValid($data['DESCRIPTIONLONG']) &&
			$validator->isValid($data['PRIX'])
			) {
				if ($data['IDBREND'] != 0) {
					try {
						$product = new Product();
						$product->insert($data);
							
						$this->view->messageSuccess = "Le produit a �t� ajout�";
							
						$lastId = $product->getAdapter()->lastInsertId();
						$this->_redirect('/backoffice/product/edit/showProduct/'.$lastId);
							
					} catch (Zend_Exception $e) {
						$this->log($e->getMessage(), 'err');
						$this->view->populateForm = $data;
					}
				} else {
					$this->view->messageError = "S�l�ctionner une marque";

					$this->view->populateForm = $data;
				}
			} else {
				foreach ($validator->getErrors() as $errorCode) {
					$this->view->messageError .=  $this->getErrorValidator($errorCode);
				}
				$this->view->populateForm = $data;
			}

		} else {
			$temp = array (
		 			'NOM' => '',
			 		'DESCRIPTIONSHORT' => '',
			 		'DESCRIPTIONLONG' => '',
			 		'PRIX' => '',
			 		'IDBREND' => '',
			 		'IDCATEGORY' => '',
			 		'isACTIVE' => '1',
			 		'isPROMO' => '1'
			 		);
			 		$this->view->populateForm = $temp;
		}
	}

    private function computeUrlNavigationParent($row) {
        return $row['NAVNOM_URLPARENTS']."/".$row['NAVNOM'];
    }
    
	public function editAction()
	{
		try {
			$this->view->titlePage = "Modifier un Produit";
			$isProcuctEnable = true;
	
			$supplierBrend = new SupplierBrend();
			$this->view->listbrend = $supplierBrend->fetchAll($supplierBrend->select()->order('BREND ASC'));
	
			$option = new Option();
			$this->view->listoption = $option->select()->order('NOM ASC')->query()->fetchAll();
	
			$optionList = new OptionList();
			$this->view->optionsbylist = $optionList->getAll();
					
			$category2 = new Category2();
			$this->view->listallcategories2 = $category2->getAllCategoriesByID(0);
				
			$adminNamespace = $this->getSession();
	
			$id = 0;
	
			if ((int)$this->_request->getParam('showProduct') != null) {
				$id = (int)$this->_request->getParam('showProduct');
			}  else if ((int)$this->_request->getParam('id') != null) {
				$id = (int)$this->_request->getParam('id');
			}
			if ($id > 0) {
				$picture = new Picture();
				$listPicture = $picture->fetchAll('IDPRODUCT = '.$id);
				$this->view->listPicture = $listPicture;
				
				$productChildQte = new ProductChildQte();
				$this->view->productChildQte = $productChildQte->getAllByProduct($id);
	
				$product = new Product();	
				$row = $product->fetchRow('ID = '.$id);
				if ($row) {
	
					$currentProduct = $row->toArray();  
					$currentProduct['ONSELECT_OPTION'] = $optionList->getByIdProduct($id);
					$currentProduct['PRIXLOWEST'] = $product->calculateLowestPrice($id);
                                        
                    $category = new Category();
                    $currentCategory = $category->fetchRow('ID = '.$currentProduct['IDCATEGORY']);
					$currentProduct['NAVNOM_URLPARENTS'] = $this->computeUrlNavigationParent($currentCategory);
                    
					$this->view->populateForm = $currentProduct;
	
					
					if ($currentProduct['isACTIVE'] == 1) {
						$isProcuctEnable = false;
					}
                    $isProductOutOfStock = false;
					if ($currentProduct['STOCK'] == 4) {
						$isProductOutOfStock = true;
					}
	
					$productCategory = new ProductCategory2();
					$this->view->productCategories = $productCategory->getAllCategoriesByProductID($id);
	
					if ($listPicture->count()<1) {
						$this->view->messageError = "Aucune image n'est configur�e";
						$adminNamespace->imgPosDefault = 1;
						$isProcuctEnable = false;
					} else {
						$isOK = false;
						foreach ($listPicture as $pic) {
							if ($pic->POSITION == 1) {
								$isOK = true;
								break;
							}
						}
						if (!$isOK) {
							$this->view->messageError = "L'image principale n'est pas d�finie (1)";
							$adminNamespace->imgPosDefault = 1;
							//$isProcuctEnable = false;
						} else {
							$adminNamespace->imgPosDefault = $listPicture->count() + 1;
	
						}
	
					}
	
					$this->view->isProcuctEnable = $isProcuctEnable; 
					$this->view->isProductOutOfStock = $isProductOutOfStock; 
                    
					$productOption = new ProductOption();
					$this->view->listproductoption = $productOption->getOptionsByIdProduct($id);
	
					 
					$productChild = new ProductChild();
					$listProduct = $productChild->getChildsByIdProduct($id);
	
					$listChild = array(); 
					for ($i = 0; $i<sizeof($listProduct); $i++) {
						$listChild[$listProduct[$i]['ID']]['ID'] = $listProduct[$i]['ID'];
						$listChild[$listProduct[$i]['ID']]['REFERENCE'] = $listProduct[$i]['REFERENCE'];
						$listChild[$listProduct[$i]['ID']]['POIDS'] = $listProduct[$i]['POIDS'];
						$listChild[$listProduct[$i]['ID']]['DESIGNATION'] = $listProduct[$i]['DESIGNATION'];
						$listChild[$listProduct[$i]['ID']]['PRIX'] = $listProduct[$i]['PRIX'];
						$listChild[$listProduct[$i]['ID']]['ETATSTOCK'] = $listProduct[$i]['ETATSTOCK'];
						$listChild[$listProduct[$i]['ID']]['isDEVIS'] = $listProduct[$i]['isDEVIS'];
						$listChild[$listProduct[$i]['ID']]['isFRANCODENIED'] = $listProduct[$i]['isFRANCODENIED'];
						$listChild[$listProduct[$i]['ID']]['QUANTITYMIN'] = $listProduct[$i]['QUANTITYMIN'];
						$listChild[$listProduct[$i]['ID']]['isPROMO'] = $listProduct[$i]['isPROMO'];
						$listChild[$listProduct[$i]['ID']]['POINTFIDELITE'] = $listProduct[$i]['POINTFIDELITE'];
	  
						$listChild[$listProduct[$i]['ID']]['IMAGEPROMO'] = $listProduct[$i]['IMAGEPROMO'];
	
						$listChild[$listProduct[$i]['ID']]['OPTION_VALUE_'.$listProduct[$i]['IDOPTION']] = $listProduct[$i]['VALUE'];
						$listChild[$listProduct[$i]['ID']]['OPTION_ID_'.$listProduct[$i]['IDOPTION']] = $listProduct[$i]['IDCHILD'];
					 
					}
					$this->view->listChild = $listChild; 
	
					$childFTFDS = new ProductChildFTFDS();
					$listFTFDS = $childFTFDS->getFTFDSByIdProduct($id);
					$this->view->listFTFDS = $listFTFDS;
	
	
					$productAccessoire = new ProductAccessoire();
					$listAccessoires = $productAccessoire->getAccessoiresByProductID($id, 'pa.REFACCESSOIRE ASC');
					$this->view->listAccessoires = $listAccessoires;
	
					$productAnnexe = new ProductAnnexe();
					$listAnnexes = $productAnnexe->getAnnexesByProductID($id, 'NOM ASC');;
					$this->view->listAnnexes = $listAnnexes;
	
					$this->view->currentProduct = $id;
	
	
					$paramsXML = array(
					'PRODUCT' => $currentProduct,  
				 	'PICS'=> $listPicture, 
					);
					$this->view->siteMapShow = $this->generateSiteMapShow($paramsXML, $currentProduct['NAVNOM_URLPARENTS']);
				} else {
					$this->_forward('/list');
				}
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err'); 
		}
	}

	private function generateSiteMapShow($params, $navParentUrl) {
		$navnoms = array();
		$product = $params['PRODUCT'];

		$filter = new Zend_Filter();
		$filter	->addFilter(new Zend_Filter_StripTags())
		->addFilter(new Zend_Filter_StringTrim());

		array_push($navnoms, str_replace("page/","",$filter->filter($product['NAVNOM'])));
		array_push($navnoms, str_replace("page/","",$filter->filter($product['CUSTOM_NAVNOM1'])));
		array_push($navnoms, str_replace("page/","",$filter->filter($product['CUSTOM_NAVNOM2'])));
		array_push($navnoms, str_replace("page/","",$filter->filter($product['CUSTOM_NAVNOM3'])));
			
		$br = "<br/>";
		$tab = "&nbsp;&nbsp;&nbsp;";
		$tab2 = $tab.$tab.$tab;
		$url = "";

		foreach ($navnoms as $navnom) {
			if (!empty($navnom)) {
				$url .= $br.htmlentities("<url>");
				$url .= $br.$tab;
				$url .= htmlentities("<loc>".$this->baseUrl_SiteCommerceUrl."/".Utils_Tool::getFormattedUrlProduct($navParentUrl, $navnom, $product['ID'])."</loc>");
				$url .= $br;
				foreach($params['PICS'] as $row) {
					$url .= $tab.htmlentities("<image:image>");
					$url .= $br.$tab2;
					$url .= htmlentities("<image:loc>".$this->baseUrl_SiteCommerceUrl."/".$row['URL']."</image:loc>");

					if (!empty($row['STRING1'])) {
						$url .= $br.$tab2;
						$url .= htmlentities("<image:title>".$row['STRING1']."</image:title>");
					}

					if (!empty($row['STRING2'])) {
						$url .= $br.$tab2;
						$url .= htmlentities("<image:caption>".$row['STRING2']."</image:caption>");
					}
					$url .= $br.$tab;
					$url .= htmlentities("</image:image>");
					$url .= $br;
				}
				$url .= htmlentities("</url>");
			}
		}

		return $url;
	}

	public function editproductAction()
	{

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty());

			//valideurs pour les chaines
			$validator2 = new Zend_Validate();
			$validator2 -> addValidator(new Zend_Validate_NotEmpty());

			//get the form params
			$params = $this->_request->getPost();

			$isDevisProduct = 1;
			if (isset($params['devisonproduct']) && $params['devisonproduct']) {
				$isDevisProduct = 0;
			}

			$data = array (
			 		'NOM' => $filter->filter($params['nom']), 
			 		'DESCRIPTIONSHORT' => $params['descshort'],
			 		'DESCRIPTIONLONG' => $params['desclong'],
			 		'DESCRIPTIONTECH' => $params['desctech'],
			 		'DESCRIPTIONNORME' => $params['descnorme'],
			 		'PRIX' => $filter->filter($params['prix']),
			 		'isACTIVE' => $filter->filter($params['active']),
			 		'IDCATEGORY' => (int)$filter->filter($params['idcategory']),
			 		'DATEPROMO' => $params['sd'],
			 		'ID' => $filter->filter($params['id']),
			 		'IDBREND' => $filter->filter($params['idbrend']),
					'isSHOWBREND' => $filter->filter($params['showbrend']),
					'isDEVIS' => $isDevisProduct,
					'STOCK' => (int)$params['stock'] ,
					'BOOSTED_HOME' => (int)$params['boostedhome'],
					'BOOSTED_BESTSELLER' => (int)$params['boostedbestseller']
			);


			if ($validator->isValid($data['NOM']) &&
			$validator->isValid($data['DESCRIPTIONSHORT']) &&
			$validator->isValid($data['DESCRIPTIONLONG']) &&
			$validator2->isValid($data['PRIX'])
			) {
				try {

					$product = new Product();
					$product->update($data, 'ID = '.$data['ID']);

					$this->view->messageSuccess = "Le produit a �t� modifi�";

					$this->log("Le produit a �t� modifi� : ".$data['ID'],'info');
                    $this->indexproductById($data['ID']);
                
				} catch (Zend_Exception $e) {

					$this->log($e->getMessage(),'err');
					$this->view->messageError = "V�rifier les param�tres";

					$this->view->populateForm = $data;
				}
			} else {
				foreach ($validator->getErrors() as $errorCode) {
					$this->view->messageError =  $this->getErrorValidator($errorCode);
				}
			}
		}
		$this->_forward('/edit');
	}

	public function editproductcategoriesAction()
	{

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty())
			-> addValidator(new Zend_Validate_StringLength(3));

			//valideurs pour les chaines
			$validator2 = new Zend_Validate();
			$validator2 -> addValidator(new Zend_Validate_NotEmpty());

			//get the form params
			$params = $this->_request->getPost();

			try {
				$id = (int) $params['id'];
				$data = array (
				 		'ID' => $id,
				 		'IDCATEGORY_DUP1' => (int)$filter->filter($params['idcategory_duplicat1']),
				 		'IDCATEGORY_DUP2' => (int)$filter->filter($params['idcategory_duplicat2']),
				 		'IDCATEGORY_DUP3' => (int)$filter->filter($params['idcategory_duplicat3']) 
				);

				$product = new Product();
				$product->update($data, 'ID = '.$id);

				if (!empty($params['idcategory_promosolde'])) {
					$productCategory = new ProductCategory2();
					$productCategory->delete('IDPRODUCT = '.$id);
					foreach ($params['idcategory_promosolde'] as $row) {
						if ((int)$row > 0) {
							$dataTemp = array ('IDPRODUCT' => $id, 'IDCATEGORY' => (int)$row);
							$productCategory->insert($dataTemp);
						}
					}
				}
					
				$this->view->messageSuccess = "Les cat�gories ont �t� modifi�es";

				$this->log("Les cat�gories ont �t� modifi�es : ".$id,'info');
			} catch (Zend_Exception $e) {

				$this->log($e->getMessage(),'err');
				$this->view->messageError = "Les cat�gories n'ont pas �t� modifi�es";

				$this->view->populateForm = $data;
			}
		}
		$this->_forward('/edit');
	}

	public function editproductkeywordscleanAction()
	{

		$this->view->messageSuccess = "";
		$this->view->messageError = "";


		//get the form params
		$id = (int)$this->_request->getParam('id');

		$data = array ( 'KEYWORDS' => ''  );
			
		try {
			if ($id > 0) {
				$product = new Product();
				$product->update($data, 'ID = '.$id);

				$this->view->messageSuccess = "Les mots cl�s ont �t� modifi�s";

				$this->log("Les mots cl�s ont �t� modifi�s : ".$id,'info');
			}
		} catch (Zend_Exception $e) {

			$this->log($e->getMessage(),'err');
			$this->view->messageError = "Les mots cl�s n'ont pas �t� modifi�s";
		}

		$this->_forward('/edit');
	}

	public function editproductkeywordsAction()
	{
		try {
			$this->view->messageSuccess = "";
			$this->view->messageError = "";

			if ($this->_request->isPost()) {

				//valideurs pour les chaines
				$validator = new Zend_Validate();
				$validator -> addValidator(new Zend_Validate_NotEmpty())
				-> addValidator(new Zend_Validate_StringLength(3));

				//get the form params
				$params = $this->_request->getPost();

				$keywords =  $this->generateKeyWords($params['nom']);

				$data = array ( 'KEYWORDS' => $keywords  );

				if ($validator->isValid($data['KEYWORDS']))  {
					$id = (int)$params['id'];
					if ($id > 0) {
						$product = new Product();
						$product->update($data, 'ID = '.$id);

						$this->view->messageSuccess = "Les mots cl�s ont �t� modifi�s";

						$this->log("Les mots cl�s ont �t� modifi�s : ".$id,'info');
					}
				} else {
					foreach ($validator->getErrors() as $errorCode) {
						$this->view->messageError .=  $this->getErrorValidator($errorCode);
					}
				}
			}
		} catch (Zend_Exception $e) {

			$this->log($e->getMessage(),'err');
			$this->view->messageError = "Les mots cl�s n'ont pas �t� modifi�s";
		}
		$this->_forward('/edit');
	}

	public function delAction() {

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->getParam('id')) {
			$id = (int)$this->_request->getParam('id');
			if ($id > 0) {
				try {
					$product = new Product();
					$productOtion = new ProductOption();
					$productChild = new ProductChild();
					$productChildOption = new ProductChildOption();
					$productAccessoire = new ProductAccessoire();
					$picture = new Picture();

					$childs = $productChild->fetchAll('IDPRODUCT = '.$id);

					foreach ($childs as $row) {
						$productChildOption->delete('IDPRODUCTCHILD = '.$row->ID);
						$productAccessoire->delete('REFACCESSOIRE = "'.$row->REFERENCE.'"');
					}
					$productChild->delete('IDPRODUCT = '.$id);
					$picture->delete('IDPRODUCT = '.$id);
					$productOtion->delete('IDPRODUCT = '.$id);
					$product->delete('ID = '.$id);

					$this->view->messageSuccess = "Le produit a �t� supprim�";

					$this->log("Le produit a �t� supprim�",'info');
				} catch (Zend_Exception $e) {

					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
				}
			}
		}
		$this->_forward('/list');

	}

	public function editchildAction()
	{
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty())
			-> addValidator(new Zend_Validate_StringLength(3));

			//valideurs pour les chaines
			$validator2 = new Zend_Validate();
			$validator2 -> addValidator(new Zend_Validate_NotEmpty());

			//get the form params
			$params = $this->_request->getPost();

			$date = new Zend_Date();

			$isDevisPrice = 1;
			if (isset($params['devisprice']) && $params['devisprice']) {
				$isDevisPrice = 0;
			}

			$quantiteMin = (int)$params['quantiteMin'];
			if ($quantiteMin == 0) {
				$quantiteMin = 1;
			}

			$dataChild = array (
			 		'REFERENCE' => $filter->filter($params['reference']),
			 		'DESIGNATION' => $filter->filter($params['designation']),
			 		'PRIX' => $filter->filter($params['prixNormal']),
			 		'ETATSTOCK' => $filter->filter($params['etatstock']),
			 		'QUANTITYMIN' => $filter->filter($quantiteMin),
					'isDEVIS' => $isDevisPrice,
			 		'IMAGEPROMO' => $filter->filter($params['imagePromo']),
			 		'DATEMODIF' => $date->toString('YYYY-MM-dd HH:mm:ss'),
			 		'IDPRODUCT' => (int)$this->_request->getParam('id')
			);
			$listOption = unserialize($params['listOption']);

			if ($validator->isValid($dataChild['REFERENCE']) &&
			$validator2->isValid($dataChild['PRIX'])&&
			$validator->isValid($dataChild['DESIGNATION'])
			) {

				try {
					$productChild = new ProductChild();
					$productChild->update($dataChild, 'ID = '.$params['idchild']);

					$productChildOption = new ProductChildOption();
					foreach ($listOption as $option) {
						$dataOption = array (
						 		'IDPRODUCTCHILD' => $params['idchild'],
						 		'IDOPTION' => $option,
						 		'VALUE' => $params['option'.$option]
						);
						$isOk = $productChildOption->update($dataOption,'IDPRODUCTCHILD = '.$params['idchild'].' AND IDOPTION = '.$option);
						if (!$isOk) {

							$productChildOption->delete('IDPRODUCTCHILD = '.$params['idchild'].' AND IDOPTION = '.$option);
							$productChildOption->insert($dataOption);
						}
					}


					$this->view->messageSuccess = "Le produit a ete modifie";

					$this->log("Le produit child a ete modifie : ".$params['idchild'],'info');
                    
				} catch (Zend_Exception $e) {

					$this->log($e->getMessage(),'err');
					$this->view->messageError = "La r�f�rence existe d�ja";

					$this->view->populateChild = $dataChild;
					$this->_forward('/edit');
				}
			} else {
				foreach ($validator->getErrors() as $errorCode) {
					$this->view->messageError .=  $this->getErrorValidator($errorCode);
				}
				$this->view->populateChild = $dataChild;
			}

		}
		$this->_forward('/edit');
	}
	public function editchildsAction()
	{
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//get the form params
			$params = $this->_request->getPost();

			for ($index = 0; $index < $params['nbRows']; $index++) {
				if (isset($params[$index."reference"]) && !empty($params[$index."reference"]) &&
				isset($params[$index."designation"]) && !empty($params[$index."designation"])
				) {
					$optionsValues = array();
					$listOption = unserialize($params['listOption']);
					foreach ($listOption as $option) {
						$optionsValues['option'.$option] = $params[$index."option".$option];
					}
					$isDevisPrice = 1;
					if (isset($params[$index.'devisprice']) && $params[$index.'devisprice']) {
						$isDevisPrice = 0;
					}

					$isFrancoDenied = 1;
					if (isset($params[$index.'francodenied']) && $params[$index.'francodenied']) {
						$isFrancoDenied = 0;
					}

					$this->editSingleChild($index,
					$params,
					$isDevisPrice,
					$isFrancoDenied,
					$listOption,
					$optionsValues,
					(int)$this->_request->getParam('id'));
				}
			}


		}
		$this->_forward('/edit');
	}
	private function editSingleChild($line, $paramsRequest,  $isDevisPrice,$isFrancoDenied,  $listOption, $optionsValues, $idProduct) {

		$idChild = $paramsRequest[$line.'idchild'];
		$quantity = $paramsRequest[$line.'quantiteMin'];
		$reference = $paramsRequest[$line.'reference'];
		$poids = $paramsRequest[$line.'poids'];
		$designation = $paramsRequest[$line.'designation'];
		$prixNormal =$paramsRequest[$line.'prixNormal'] ;
		$etatstock = $paramsRequest[$line.'etatstock'];
		$imagePromo = $paramsRequest[$line.'imagePromo'];

        $pointFidelite = 0;
        if (isset($paramsRequest[$line.'pointFidelite'])) {
            $pointFidelite = (int)$paramsRequest[$line.'pointFidelite'];
        }

		//filtres pour changer les chaines
		$filter = new Zend_Filter();
		$filter	->addFilter(new Zend_Filter_StripTags())
		->addFilter(new Zend_Filter_StringTrim());

		//valideurs pour les chaines
		$validator = new Zend_Validate();
		$validator -> addValidator(new Zend_Validate_NotEmpty())
		-> addValidator(new Zend_Validate_StringLength(3));

		//valideurs pour les chaines
		$validator2 = new Zend_Validate();
		$validator2 -> addValidator(new Zend_Validate_NotEmpty());

		$quantiteMin = (int)$quantity;
		if ($quantiteMin == 0) {
			$quantiteMin = 1;
		}
		$date = new Zend_Date();
		$adminNamespace = $this->getSession();
		$dataChildReturn = array (
		$line.'REFERENCE' => $filter->filter($reference),
		$line.'POIDS' => $filter->filter($poids),
		$line.'DESIGNATION' => $designation,
		$line.'PRIX' => $filter->filter($prixNormal),
		$line.'ETATSTOCK' => $filter->filter($etatstock),
		$line.'QUANTITYMIN' => $filter->filter($quantiteMin),
		$line.'isDEVIS' => $isDevisPrice,
		$line.'isFRANCODENIED' => $isFrancoDenied,
		$line.'IMAGEPROMO' => $filter->filter($imagePromo),
		$line.'DATEMODIF' => $date->toString('YYYY-MM-dd HH:mm:ss'),
		$line.'IDPRODUCT' => $idProduct,
		$line.'POINTFIDELITE' => $pointFidelite
		);

		$dataChild = array (
		 		'REFERENCE' => $filter->filter($reference),
		 		'POIDS' => $filter->filter($poids),
		 		'DESIGNATION' => $designation,
		 		'PRIX' => $filter->filter($prixNormal),
		 		'ETATSTOCK' => $filter->filter($etatstock),
		 		'QUANTITYMIN' => $filter->filter($quantiteMin),
		 		'isDEVIS' => $isDevisPrice,
		 		'isFRANCODENIED' => $isFrancoDenied,
		 		'IMAGEPROMO' => $filter->filter($imagePromo),
		 		'DATEMODIF' => $date->toString('YYYY-MM-dd HH:mm:ss'),
		 		'IDPRODUCT' => $idProduct ,
		 		'POINTFIDELITE' => $pointFidelite 
		);

		if ($validator->isValid($dataChild['REFERENCE']) &&
		$validator2->isValid($dataChild['PRIX'])&&
		$validator->isValid($dataChild['DESIGNATION'])
		) {
			try {

				$productChild = new ProductChild();
				$productChild->update($dataChild, 'ID = '.$idChild);

				$productChildOption = new ProductChildOption();
				foreach ($listOption as $option) {
					$dataOption = array (
					 		'IDPRODUCTCHILD' => $idChild,
					 		'IDOPTION' => $option,
					 		'VALUE' => $optionsValues['option'.$option]
					);
					$isOk = $productChildOption->update($dataOption,'IDPRODUCTCHILD = '.$idChild.' AND IDOPTION = '.$option);
					if (!$isOk) {
						$productChildOption->delete('IDPRODUCTCHILD = '.$idChild.' AND IDOPTION = '.$option);
						$productChildOption->insert($dataOption);
					}
				}
					
				$this->view->messageSuccess = "Le produit a �t� modifi�";
                $this->indexproductById($idProduct);
                
				return true;
			} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
				$this->view->messageError = "La r�f�rence existe d�ja";
				$this->view->populateChild = $dataChildReturn;
			}
		} else {
			foreach ($validator->getErrors() as $errorCode) {
				$this->view->messageError .=  $this->getErrorValidator($errorCode);
			}
			$this->view->populateChild = $dataChildReturn;
		}
		return false;
	}
	public function delchildAction() {

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->getParam('idchild')) {
			$idchild = (int)$this->_request->getParam('idchild');
			$id = (int)$this->_request->getParam('id');
			if ($idchild > 0 && $id > 0) {
				try {
					$childFTFDS = new ProductChildFTFDS();
					$child = $childFTFDS->fetchRow('ID_CHILD = '.$idchild);
					
					if (!$child) {
							$productChild = new ProductChild();
	
							$productChild->delete('ID = '.$idchild);
	
							$productChildOption = new ProductChildOption();
	
							$productChildOption->delete('IDPRODUCTCHILD = '.$idchild);
	
							$this->view->messageSuccess = "Le produit a �t� supprim�";
					} else {
						$this->view->messageError = "Un document est associ�e a ce produit, vous devez la supprimer avant de supprimer le produit";
					}


				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
				}
			}
		}
		$this->_forward('/edit');

	}
	public function addchildAction()
	{
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty())
			-> addValidator(new Zend_Validate_StringLength(3));

			//valideurs pour les chaines
			$validator2 = new Zend_Validate();
			$validator2 -> addValidator(new Zend_Validate_NotEmpty());

			//get the form params
			$params = $this->_request->getPost();

			$date = new Zend_Date();

			$adminNamespace = $this->getSession();

			$isDevisPrice = 1;
			if (isset($params['devisprice']) && $params['devisprice']) {
				$isDevisPrice = 0;
			}
			$quantiteMin = (int)$params['quantiteMin'];
			if ($quantiteMin == 0) {
				$quantiteMin = 1;
			}

			$dataChild = array (
			 		'REFERENCE' => $filter->filter($params['reference']),
			 		'DESIGNATION' => $filter->filter($params['designation']),
			 		'PRIX' => $filter->filter($params['prixNormal']),
			 		'ETATSTOCK' => $filter->filter($params['etatstock']),
			 		'QUANTITYMIN' => $filter->filter($quantiteMin),
			 		'isDEVIS' => $isDevisPrice,
			 		'IMAGEPROMO' => $filter->filter($params['imagePromo']),
			 		'DATEMODIF' => $date->toString('YYYY-MM-dd HH:mm:ss'),
			 		'IDPRODUCT' => (int)$this->_request->getParam('id')
			);
			$listOption = unserialize($params['listOption']);

			if ($validator->isValid($dataChild['REFERENCE']) &&
			$validator2->isValid($dataChild['PRIX'])&&
			$validator->isValid($dataChild['DESIGNATION'])
			) {

				try {
					$productChild = new ProductChild();
					$productChild->insert($dataChild);

					$lastid = $productChild->getAdapter()->lastInsertId();

					$productChildOption = new ProductChildOption();
					foreach ($listOption as $option) {
						$dataOption = array (
						 		'IDPRODUCTCHILD' => $lastid,
						 		'IDOPTION' => $option,
						 		'VALUE' => $params['option'.$option]
						);
						$productChildOption->insert($dataOption);
					}


					$this->view->messageSuccess = "Le produit a �t� ajout�";

				} catch (Zend_Exception $e) {

					$this->view->messageError = "La r�f�rence existe d�j�";

					$this->log($e->getMessage(),'err');
					$this->view->populateChild = $dataChild;
					$this->_forward('/edit');
				}
			} else {
				foreach ($validator->getErrors() as $errorCode) {
					$this->view->messageError .=  $this->getErrorValidator($errorCode);
				}
				$this->view->populateChild = $dataChild;
			}

		}
		$this->_forward('/edit');
	}
	public function addchildsAction()
	{
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//get the form params
			$params = $this->_request->getPost();
			for ($index = 0; $index < 2; $index++) {
				try {
					if (isset($params[$index."reference"]) && !empty($params[$index."reference"]) &&
					isset($params[$index."designation"]) && !empty($params[$index."designation"])
					) {
						$optionsValues = array();
						$listOption = unserialize($params['listOption']);
						foreach ($listOption as $option) {
							$optionsValues['option'.$option] = $params[$index."option".$option];
						}
						$isDevisPrice = 1;
						if (isset($params[$index.'devisprice']) && $params[$index.'devisprice']) {
							$isDevisPrice = 0;
						}
						$this->addSingleChild($index, $isDevisPrice,
						$params[$index.'quantiteMin'],
						$params[$index.'reference'],
						$params[$index.'poids'],
						$params[$index.'designation'],
						$params[$index.'prixNormal'],
						$params[$index.'etatstock'],
						$params[$index.'imagePromo'],
						$listOption,
						$optionsValues,
						(int)$this->_request->getParam('id'));
					}
				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = "V�rifier les param�tres";
				}
			}


		}
		$this->_forward('/edit');
	}

	private function addSingleChild($line, $isDevisPrice, $quantity, $reference, $poids, $designation, $prixNormal, $etatstock, $imagePromo, $listOption, $optionsValues, $idProduct) {

		//filtres pour changer les chaines
		$filter = new Zend_Filter();
		$filter	->addFilter(new Zend_Filter_StripTags())
		->addFilter(new Zend_Filter_StringTrim());

		//valideurs pour les chaines
		$validator = new Zend_Validate();
		$validator -> addValidator(new Zend_Validate_NotEmpty())
		-> addValidator(new Zend_Validate_StringLength(3));

		//valideurs pour les chaines
		$validator2 = new Zend_Validate();
		$validator2 -> addValidator(new Zend_Validate_NotEmpty());

		$quantiteMin = (int)$quantity;
		if ($quantiteMin == 0) {
			$quantiteMin = 1;
		}
		$date = new Zend_Date();
		$adminNamespace = $this->getSession();
		$dataChildReturn = array (
		$line.'REFERENCE' => $filter->filter($reference),
		$line.'POIDS' => $filter->filter($poids),
		$line.'DESIGNATION' => $filter->filter($designation),
		$line.'PRIX' => $filter->filter($prixNormal),
		$line.'ETATSTOCK' => $filter->filter($etatstock),
		$line.'QUANTITYMIN' => $filter->filter($quantiteMin),
		$line.'isDEVIS' => $isDevisPrice,
		$line.'IMAGEPROMO' => $filter->filter($imagePromo),
		$line.'DATEMODIF' => $date->toString('YYYY-MM-dd HH:mm:ss'),
		$line.'IDPRODUCT' => $idProduct
		);
		
		$poids = $filter->filter($poids);
		if (empty($poids)) { $poids = 0; }
		
		$quantiteMin = $filter->filter($quantiteMin);
		if (empty($quantiteMin)) {	$quantiteMin = 1;	}
		
		$imagePromo = $filter->filter($imagePromo);
		if (empty($imagePromo)) { $imagePromo = 0; }

		$dataChild = array (
		 		'REFERENCE' => $filter->filter($reference),
		 		'POIDS' => $poids,
		 		'DESIGNATION' => $filter->filter($designation),
		 		'PRIX' => $filter->filter($prixNormal),
		 		'ETATSTOCK' => $filter->filter($etatstock),
		 		'QUANTITYMIN' => $quantiteMin,
		 		'isDEVIS' => $isDevisPrice,
		 		'IMAGEPROMO' => $imagePromo,
		 		'DATEMODIF' => $date->toString('YYYY-MM-dd HH:mm:ss'),
		 		'IDPRODUCT' => $idProduct
		);

		if ($validator->isValid($dataChild['REFERENCE']) &&
		$validator2->isValid($dataChild['PRIX'])&&
		$validator->isValid($dataChild['DESIGNATION'])
		) {
			try {
				$productChild = new ProductChild();
				if (!$productChild->isChildReferenceExist($dataChild['REFERENCE'])){
					$productChild->insert($dataChild);
	
					$lastid = $productChild->getAdapter()->lastInsertId();
	
					$productChildOption = new ProductChildOption();
					foreach ($listOption as $option) {
						$dataOption = array (
						 		'IDPRODUCTCHILD' => $lastid,
						 		'IDOPTION' => $option,
						 		'VALUE' => $optionsValues['option'.$option]
						);
						$productChildOption->insert($dataOption);
					}
					$this->view->messageSuccess = "Le produit a �t� ajout�";
					return true;
				} else {
					$this->view->populateChild = $dataChildReturn;
					$this->view->messageError = "La r�f�rence existe d�ja";
					return false;
				}
			} catch (Zend_Exception $e) {
				$this->log($e->getMessage(),'err');
				$this->view->messageError = "La r�f�rence existe d�ja";
				$this->view->populateChild = $dataChildReturn;
			}
		} else {
			foreach ($validator->getErrors() as $errorCode) {
				$this->view->messageError =  $this->getErrorValidator($errorCode);
			}
			foreach ($validator2->getErrors() as $errorCode) {
				$this->view->messageError =  $this->getErrorValidator($errorCode);
			}
			$this->view->populateChild = $dataChildReturn;
		}
		return false;
	}

	public function addproductoptionAction() {

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {
			$params = $this->_request->getPost();

			$data = array (
			 		'IDPRODUCT' => (int)$this->_request->getParam('id'),
			 		'IDOPTION' => $params['idoption']
			);

			try {
				$product = new Product();
				$sql = 'SELECT p.NOM
					FROM product p 
					LEFT JOIN product_option AS po ON po.IDPRODUCT = p.ID
					WHERE p.ID = '.$data['IDPRODUCT'].'
					AND po.IDOPTION = '.$data['IDOPTION'];

				$isExistOption = $product->getAdapter()->fetchRow($sql);

				if (!$isExistOption) {

					$productOption = new ProductOption();

					$productOption->insert($data);

					$this->view->messageSuccess = "L'option a �t� ajout�e";
				} else {
					$this->view->messageError = "L'option existe d�ja";
				}
			} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
				$this->view->messageError = $e->getMessage();
			}
		}
		$this->_forward('/edit');
	}
	public function delproductoptionAction() {

		$this->view->messageSuccess = "";
		$this->view->messageError = "";
		$adminNamespace = $this->getSession();
		if($this->_request->getParam('idopt')) {
			$idopt = (int)$this->_request->getParam('idopt');
			$id = (int)$this->_request->getParam('id');
			if ($idopt > 0 && $id > 0) {
				try {

					$productOption = new ProductOption();
					$productChildOption = new ProductChildOption();
					$productOption->delete('IDOPTION = '.$idopt.' AND IDPRODUCT = '.$id);

					$sql = "
		    			 DELETE pco 
		    			 FROM productchild_option AS pco 
		    			 LEFT JOIN productchild AS pc ON pc.ID = pco.IDPRODUCTCHILD
						WHERE pco.IDOPTION = ".$idopt." 
						AND pc.IDPRODUCT = ".$id;

					$productChildOption->getAdapter()->query($sql);


					$this->view->messageSuccess = "L'option a �t� supprim�e";

				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
				}
			}
		}
		$this->_forward('/edit');
	}

	public function optionprofilAction() {
		$this->view->titlePage = "Listing des Profils d'options";
		if ($this->_request->isPost() && (int)$this->_request->getParam('id') ==0) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty())
			-> addValidator(new Zend_Validate_StringLength(3));


			//get the form params
			$params = $this->_request->getPost();

			$options = $params['profilOptions'];
			$optionValues = "";
			foreach ($options as $idOption) {
				$optionValues .= $idOption.";";
			}
			$data = array (
			 		'NOM' => $filter->filter($params['nom']),
					'OPTS' => $optionValues
			);

			if ($validator->isValid($data['NOM'])) {

				try {
					$optionProfil = new OptionProfil();
					$optionProfil->insert($data);

					$this->view->messageSuccess = "Le profil a �t� ajout�";

				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');

					$this->view->messageError = "Le profil existe d�ja";

				}
			} else {
				foreach ($validator->getErrors() as $errorCode) {
					$this->view->messageError .=  $this->getErrorValidator($errorCode);
				}
			}

		}

		$option = new Option();
		$listOptions = $option->select()->order('NOM ASC')->query()->fetchAll();
		$this->view->listoption = $listOptions;

		$optionProfil = new OptionProfil();
		$this->view->listprofils = $optionProfil->getProfils();
	}
	public function optionprofildelAction() {

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->getParam('id')) {
			$id = (int)$this->_request->getParam('id');
			if ($id > 0) {
				try {
					$optionProfil = new OptionProfil();

					$optionProfil->delete('ID = '.$id);

					$this->view->messageSuccess = "Le profil a �t� supprim�";

				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
					$this->_forward('/optionprofil');
				}
			}
		}
		$this->_forward('/optionprofil');
	}

	public function optionAction() {
		$this->view->titlePage = "Gestion des caract�ristiques du produit";
		$this->view->currentMenu = "Option";

		if ($this->_request->isPost() && (int)$this->_request->getParam('id') ==0) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty());


			//get the form params
			$params = $this->_request->getPost();

			$data = array (
			 		'NOM' => $filter->filter($params['nom'])
			);

			if ($validator->isValid($data['NOM'])) {

				try {
					$option = new Option();
					$option->insert($data);

					$this->view->messageSuccess = "La caract�ristique a �t� ajout�e";

				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = "La caract�ristique existe d�ja";

				}
			} else {
				foreach ($validator->getErrors() as $errorCode) {
					$this->view->messageError .=  $this->getErrorValidator($errorCode);
				}
			}

		}
		$option = new Option();
		$this->view->listoption = $option->select()->order('NOM ASC')->query()->fetchAll();

	}
	public function optioneditAction()
	{
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty());


			//get the form params
			$params = $this->_request->getPost();

			$data = array (
			 		'NOM' => $filter->filter($params['nom']),
			 		'ID' => $filter->filter($params['id'])
			);

			if ($validator->isValid($data['NOM'])
			) {

				try {
					$option = new Option();
					$option->update($data, 'ID = '.$data['ID']);

					$this->view->messageSuccess = "La caract�ristique a �t� modifi�e";

				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = "La caract�ristique existe d�j�";

					$this->_forward('option');
				}
			} else {
				foreach ($validator->getErrors() as $errorCode) {
					$this->view->messageError .=  $this->getErrorValidator($errorCode);
				}
			}
		}
		$this->_forward('option');
	}
	public function optiondelAction() {

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->getParam('id')) {
			$id = (int)$this->_request->getParam('id');
			if ($id > 0) {
				try {
					$product = new Product();
					$sql = 'SELECT p.NOM
					FROM product p 
					LEFT JOIN productchild AS pc ON pc.IDPRODUCT = p.ID
					LEFT JOIN productchild_option AS pco ON pco.IDPRODUCTCHILD = pc.ID
					WHERE pco.IDOPTION = '.$id ;
					$isExistProduct = $product->getAdapter()->fetchRow($sql);

					if (!$isExistProduct) {

						$option = new Option();

						$option->delete('ID = '.$id);

						$this->view->messageSuccess = "La caract�ristique a �t� supprim�e";
					} else {
						$this->view->messageError = "La caract�ristique est utilis�e par : <b>".$isExistProduct['NOM']."</b>";
					}
				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
					$this->_forward('/option');
				}
			}
		}
		$this->_forward('/option');
	}

	public function editftfdsAction() {

		$params = $this->_request->getPost();

		if(!empty($params['idchild_ftfds']) && !empty($_FILES['file_ftfds']) && !empty($_FILES['file_ftfds']['name'])) {
			$nomOrigine = $_FILES['file_ftfds']['name'];
			$elementsChemin = pathinfo($nomOrigine);
			$extensionFichier = strtolower($elementsChemin['extension']);
			$extensionsAutorisees = array("pdf");
			if (!(in_array($extensionFichier, $extensionsAutorisees))) {
				$this->view->messageError = "Le fichier n'a pas l'extension attendue";
			} else {
				// Copie dans le repertoire du script avec un nom
				// incluant l'heure a la seconde pres
				$repertoireDestination = 'items/ftfds/';
				$this->checkDirectoryExist($repertoireDestination);
				
				$nomDestination = $params['idchild_ftfds'].".".$extensionFichier;

				if (move_uploaded_file($_FILES["file_ftfds"]["tmp_name"],$repertoireDestination.$nomDestination)) {
					try {
						$childFTFDS = new ProductChildFTFDS();
						$data = array (
					 		'URL' => $repertoireDestination.$nomDestination,
					 		'ID_CHILD' => $params['idchild_ftfds']
						);
						$childFTFDS->insert($data);
						$this->view->messageSuccess = "Le document a �t� ajout�e ";
					} catch (Exception $e) {
						$this->view->messageError = $e->getMessage();
					}
				} else {
					$this->view->messageError = "Le fichier n'a pas �t� upload�";
				}
			}
		} else {
			$this->view->messageError = "Veuillez s�lectionner un document au format pdf";
		}

		$this->_forward('/edit');
	}

	public function delftfdsAction() {
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->getParam('idchild')) {
			$idchild = (int)$this->_request->getParam('idchild');
			if ($idchild > 0) {
				try {
					$childFTFDS = new ProductChildFTFDS();
					$child = $childFTFDS->fetchRow('ID_CHILD = '.$idchild);
					$childFTFDS->delete('ID_CHILD = '.$idchild);
					unlink($child['URL']);
					$this->view->messageSuccess = "Le document a �t� supprim�e";

				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
				}
			}
		}
		$this->_forward('/edit');
	}


	public function editdocAction() {

		$params = $this->_request->getPost();

		if(!empty($params['docname_product']) && !empty($_FILES['file_doc']) && !empty($_FILES['file_doc']['name'])) {
			$nomOrigine = $_FILES['file_doc']['name'];
			$elementsChemin = pathinfo($nomOrigine);
			$extensionFichier = strtolower($elementsChemin['extension']);
			$extensionsAutorisees = array("pdf");
			if (!(in_array($extensionFichier, $extensionsAutorisees))) {
				$this->view->messageError = "Le fichier n'a pas l'extension attendue";
			} else {
				// Copie dans le repertoire du script avec un nom
				// incluant l'heure a la seconde pres
				$repertoireDestination = 'items/doc/';
				$this->checkDirectoryExist($repertoireDestination);
				
				$nomDestination = $params['docid_product'].".".$extensionFichier;

				if (move_uploaded_file($_FILES["file_doc"]["tmp_name"],$repertoireDestination.$nomDestination)) {
					try {
						$product = new Product();
						$data = array (
					 		'DOCURL' => $repertoireDestination.$nomDestination,
					 		'DOCNAME' => $params['docname_product']
						);
						$product->update($data, "ID = ".$params['docid_product']);
						$this->view->messageSuccess = "Le document a �t� ajout� ";
					} catch (Exception $e) {
						$this->view->messageError = $e->getMessage();
					}
				} else {
					$this->view->messageError = "Le fichier n'a pas �t� upload�";
				}
			}
		} else {
			$this->view->messageError = "Veuillez s�lectionner un document au format pdf";
		}

		$this->_forward('/edit');
	}

	public function deldocAction() {
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->getParam('id')) {
			$id = (int)$this->_request->getParam('id');
			if ($id > 0) {
				try {
					$product = new Product();
					$row = $product->fetchRow('ID = '.$id)->toArray();
					$docurl = $row['DOCURL'];
					unlink($docurl);
					$data = array (
					 		'DOCURL' => "",
					 		'DOCNAME' => ""
					 		);
					 		$product->update($data, "ID = ".$id);
					 		$this->view->messageSuccess = "Le document a �t� supprim�";
				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
				}
			}
		}
		$this->_forward('/edit');
	}



	public function livraisonAction() {
		$this->view->titlePage = "Configuration de la livraison";

		$livraison_type = new LivraisonType();
		$this->view->livraisontypes = $livraison_type->getTypes();

		$livraison_poids = new LivraisonPoids();
		$this->view->livraisonpoids = $livraison_poids->getLists();
	}

	public function addlivraisontypeAction() {
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty())
			-> addValidator(new Zend_Validate_StringLength(3));


			//get the form params
			$params = $this->_request->getPost();

			$data = array (
			 		'NOM' => $filter->filter($params['livraison_nom']),
			 		'CMDFRANCO' => $filter->filter($params['livraison_franco'])
			);

			if ($validator->isValid($data['NOM'])
			) {

				try {
					$livraison_type = new LivraisonType();
					$livraison_type->insert($data);

					$this->view->messageSuccess = "Le type de livraison a �t� ajout�";

				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = "Le type de livraison existe d�ja";

					$this->_forward('/livraison');
				}
			} else {
				foreach ($validator->getErrors() as $errorCode) {
					$this->view->messageError .=  $this->getErrorValidator($errorCode);
				}
			}
		}
		$this->_forward('/livraison');
	}

	public function dellivraisontypeAction() {
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->getParam('id')) {
			$id = (int)$this->_request->getParam('id');
			if ($id > 0) {
				try {
					$livraison_type = new LivraisonType();
					$livraison_poids = new LivraisonPoids();
					$livraison_type->delete("ID = ".$id);
					$livraison_poids->delete("TYPE = ".$id);
					$this->view->messageSuccess = "Le type de livraison a �t� supprim�";
				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
				}
			}
		}
		$this->_forward('/livraison');
	}

	public function editlivraisontypeAction() {
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty())
			-> addValidator(new Zend_Validate_StringLength(3));


			//get the form params
			$params = $this->_request->getPost();

			$data = array (
			 		'NOM' => $filter->filter($params['livraison_nom']),
			 		'CMDFRANCO' => $filter->filter($params['livraison_franco'])
			);

			if ($validator->isValid($data['NOM'])
			) {

				try {
					$livraison_type = new LivraisonType();
					$livraison_type->update($data, "ID = ".$params['livraison_id']);

					$this->view->messageSuccess = "Le type de livraison a �t� modifi�";

				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = "Le type de livraison n'a pas �t� modifi�";

					$this->_forward('/livraison');
				}
			} else {
				foreach ($validator->getErrors() as $errorCode) {
					$this->view->messageError .=  $this->getErrorValidator($errorCode);
				}
			}
		}
		$this->_forward('/livraison');
	}

	public function addlivraisonpoidsAction() {
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty())
			-> addValidator(new Zend_Validate_StringLength(3));


			//get the form params
			$params = $this->_request->getPost();

			if (isset($params['livraison_poids_type'])) {
				$data = array (
				 		'TO' => floatval($params['livraison_poids_to']),
				 		'FROM' => floatval($params['livraison_poids_from']),
				 		'TYPE' => floatval($params['livraison_poids_type']),
				 		'PRICE' => floatval($params['livraison_poids_price'])
				);
				if ($data['TO'] > 0 && $data['TYPE'] > 0) {

					try {
						$livraison_poids = new LivraisonPoids();
						$livraison_poids->insert($data);

						$this->view->messageSuccess = "Le poids de la livraison a �t� ajout�";

					} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
						$this->view->messageError = "Le poids de la livraison n'a pas �t� ajout�";
						$this->_forward('/livraison');
					}
				} else {
					$this->view->messageError = "Le poids de la livraison n'a pas �t� ajout�";
					$this->_forward('/livraison');
				}
			}

		}
		$this->_forward('/livraison');
	}

	public function editlivraisonpoidsAction() {
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter	->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringTrim());

			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty())
			-> addValidator(new Zend_Validate_StringLength(3));


			//get the form params
			$params = $this->_request->getPost();

			$data = array (
			 		'TO' => floatval($params['livraison_poids_to']),
			 		'FROM' => floatval($params['livraison_poids_from']),
			 		'TYPE' => floatval($params['livraison_poids_type']),
			 		'PRICE' => floatval($params['livraison_poids_price'])
			);

			if ($data['TO'] > 0 && $data['TYPE'] > 0 ) {

				try {
					$livraison_poids = new LivraisonPoids();
					$livraison_poids->update($data, "ID = ".$params['livraison_poids_id']);

					$this->view->messageSuccess = "Le poids de la livraison a �t� modifi�";

				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = "Le poids de la livraison n'a pas �t� modifi�";

					$this->_forward('/livraison');
				}
			} else {
				$this->view->messageError = "Le poids de la livraison n'a pas �t� modifi�";

				$this->_forward('/livraison');
			}
		}
		$this->_forward('/livraison');
	}

	public function dellivraisonpoidsAction() {
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->getParam('id')) {
			$id = (int)$this->_request->getParam('id');
			if ($id > 0) {
				try {
					$livraison_poids = new LivraisonPoids();
					$livraison_poids->delete("ID = ".$id);
					$this->view->messageSuccess = "Le poids de la livraison a �t� supprim�";
				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
				}
			}
		}
		$this->_forward('/livraison');
	}

	public function livraisoncatAction(){
		$this->view->titlePage = "Configuration g�n�ralis�e du poids";

		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {
			//get the form params
			try {
					
				$params = $this->_request->getPost();

				if (isset($params["livraison_poids_id"]) && !empty($params["livraison_poids_id"])) {
					$listCatId = array();
					$listCatId = $params['livraison_poids_id'];
					$productChild = new ProductChild();
					foreach ($listCatId as $catId) {
						if (isset($params["livraison_poids_".$catId]) && !empty($params["livraison_poids_".$catId]) && $params["livraison_poids_".$catId] > 0) {
							$sql = "UPDATE productchild, product SET productchild.poids=".floatval($params["livraison_poids_".$catId])." WHERE productchild.idproduct=product.id AND product.idcategory=".$catId;
							$productChild->getAdapter()->query($sql);
						}
					}
					$this->view->messageSuccess = "Les produits ont �t� mis a jour";
				}
			} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
				$this->view->messageError = $e->getMessage();
			}
		}
	}

	public function keywordsengineAction() {
		$this->view->titlePage = "Configuration des mots cl�s";

		$keyword = new KeyWord();
		$listkeywords = $keyword->getLists();

		$this->setPaginator($listkeywords, $this->_getParam('page',1), 50);

	}


	public function keywordsengineresetAction() {
		try {
			$product = new Product();
			$sql = "SELECT KEYWORDS FROM product" ;
			$keyProducts = $product->getAdapter()->fetchAll($sql);
			$filter = new Zend_Filter();
			$filter->addFilter(new Zend_Filter_StringTrim())
			->addFilter(new Zend_Filter_StringToLower());

			$keys = array();
			foreach ($keyProducts as $row) {
				$keyArray = preg_split("/[\s]*[,][\s]*/", $row['KEYWORDS']);
				for ($index = 0; $index < sizeof($keyArray); $index++) {
					$keyTemp = $filter->filter($keyArray[$index]);
					if (!in_array($keyTemp, $keys) && !empty($keyTemp)) {
						array_push($keys, $keyTemp);
					}
				}
			}

			$keyword = new KeyWord();
			for ($index = 0; $index < sizeof($keys); $index++) {
				try {
					$data = array( "KEYWORD" => $keys[$index] );
					$keyword->insert($data);
				} catch (Zend_Exception $e) { }
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
		}
		$this->_forward('/keywordsengine');
	}


	public function addkeywordsengineAction() {
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter->addFilter(new Zend_Filter_StringTrim())
			->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringToLower())
			->addFilter(new Zend_Filter_CustomAlnum(array('allowwhitespace' => true)));


			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty());


			//get the form params
			$params = $this->_request->getPost();

			if (isset($params['keyword']) && $validator->isValid($params['keyword'])) {
				$data = array (
				 		'KEYWORD' => $filter->filter($params['keyword'])
				);
				$keyword = new KeyWord();
				if (!$keyword->isExist($data['KEYWORD'])) {
					try {
						$keyword->insert($data);

						$this->view->messageSuccess = "Le mot cl� a �t� ajout�";

					} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
						$this->view->messageError = "Le mot cl� n'a pas �t� ajout�";
					}
				} else {
					$this->view->messageError = "Le mot cl� existe";
				}
			} else {
				$this->view->messageError = "Le mot cl� n'a pas �t� ajout�";
			}

		}
		$this->_forward('/keywordsengine');
	}
	public function editkeywordsengineAction() {
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if ($this->_request->isPost()) {

			//filtres pour changer les chaines
			$filter = new Zend_Filter();
			$filter->addFilter(new Zend_Filter_StringTrim())
			->addFilter(new Zend_Filter_StripTags())
			->addFilter(new Zend_Filter_StringToLower())
			->addFilter(new Zend_Filter_CustomAlnum(array('allowwhitespace' => true)));


			//valideurs pour les chaines
			$validator = new Zend_Validate();
			$validator -> addValidator(new Zend_Validate_NotEmpty());


			//get the form params
			$params = $this->_request->getPost();

			$data = array (
			 		'KEYWORD' => $filter->filter($params['keyword'])
			);

			try {
				$keyword = new KeyWord();
				$result = $keyword->update($data, "ID = ".$params['keyword_id']);

				if ($result) {
					$this->view->messageSuccess = "Le mot cl� a �t� modifi�";
				} else {
					$this->view->messageError = "Le mot cl� existe";
				}
			} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
				$this->view->messageError = "Le mot cl� n'a pas �t� modifi�";
			}
		}
		$this->_forward('/keywordsengine');
	}

	public function delkeywordsengineAction() {
		$this->view->messageSuccess = "";
		$this->view->messageError = "";

		if($this->_request->getParam('id')) {
			$id = (int)$this->_request->getParam('id');
			if ($id > 0) {
				try {
					$keyword = new KeyWord();
					$keyword->delete("ID = ".$id);
					$this->view->messageSuccess = "Le mot cl� a �t� supprim�";
				} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
					$this->view->messageError = $e->getMessage();
				}
			}
		}
		$this->_forward('/keywordsengine');
	}


	public function ajaxautocompletekeywordAction() {
		$result = array();
		try {
			if ($this->getRequest()->isPost()) {
				$filter = new Zend_Filter();
				$filter->addFilter(new Zend_Filter_StringTrim())
				->addFilter(new Zend_Filter_StripTags())
				->addFilter(new Zend_Filter_StringToLower())
				->addFilter(new Zend_Filter_CustomAlnum(array('allowwhitespace' => true)));

				$keyword = new KeyWord();
				$key = $filter->filter(utf8_decode($this->getRequest()->getPost('search')));

				$result = $keyword->findByKeyword($key);
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
		}
		$this->view->messageSuccess = serialize($result);

		$layout = Zend_Layout::getMvcInstance();
		$layout->disableLayout();
		$this->render('ajaxvalue');
	}

	public function ajaxautocompletekeywordinsertAction() {
		$currentKeywords = "";
		$idproduct = 0;

		if ($this->getRequest()->isPost()) {
			try {
				$filter = new Zend_Filter();
				$filter->addFilter(new Zend_Filter_StringTrim())
				->addFilter(new Zend_Filter_StripTags())
				->addFilter(new Zend_Filter_StringToLower())
				->addFilter(new Zend_Filter_CustomAlnum(array('allowwhitespace' => true)));

				$key = $filter->filter(utf8_decode($this->getRequest()->getPost('search')));
				$idproduct = (int)$this->getRequest()->getPost('idproduct');

				$validator = new Zend_Validate();
				$validator -> addValidator(new Zend_Validate_NotEmpty());

				if ($validator->isValid($key) && $idproduct > 0) {
					$product = new Product();
					$row = $product->fetchRow('ID = '.$idproduct)->toArray();

					if (empty($row['KEYWORDS'])) {
						$currentKeywords = $key;
					} else {
						$currentKeywords = $row['KEYWORDS'].",".$key;
					}
					$data = array( "KEYWORDS" => $currentKeywords);
					$product->update($data, 'ID = '.$idproduct);
				}
			} catch (Zend_Exception $e) { 
					$this->log($e->getMessage(),'err');}
		}

		if (!empty($currentKeywords)) {
			$this->view->messageSuccess = $currentKeywords;
		} else {
			if ($idproduct > 0) {
				$product = new Product();
				$row = $product->fetchRow('ID = '.$idproduct)->toArray();
				$this->view->messageSuccess = $row['KEYWORDS'];
			}
		}

		$layout = Zend_Layout::getMvcInstance();
		$layout->disableLayout();
		$this->render('ajaxvalue');
	}

	public function autocompletekeywordaddAction() {
		$currentKeywords = "";
		$idproduct = 0;

		if ($this->getRequest()->isPost()) {
			try {
				$filter = new Zend_Filter();
				$filter->addFilter(new Zend_Filter_StringTrim())
				->addFilter(new Zend_Filter_StripTags())
				->addFilter(new Zend_Filter_StringToLower())
				->addFilter(new Zend_Filter_CustomAlnum(array('allowwhitespace' => true)));


				$key = $filter->filter($this->getRequest()->getPost('keywords_list'));
				$idproduct = (int)$this->getRequest()->getPost('id');

				$validator = new Zend_Validate();
				$validator -> addValidator(new Zend_Validate_NotEmpty());

				if ($validator->isValid($key) && $idproduct > 0) {
					$keyword = new KeyWord();
					if (!$keyword->isExist($key)) {
						$data = array( "KEYWORD" => $key);
						$keyword->insert($data);
					}
					$product = new Product();
					$row = $product->fetchRow('ID = '.$idproduct)->toArray();

					if (empty($row['KEYWORDS'])) {
						$currentKeywords = $key;
					} else {
						$currentKeywords = $row['KEYWORDS'].",".$key;
					}
					$data = array( "KEYWORDS" => $currentKeywords);
					$product->update($data, 'ID = '.$idproduct);
					$this->view->messageSuccess = "Le mot cl� a �t� ajout�";
				}
			} catch (Zend_Exception $e) {
					$this->log($e->getMessage(),'err');
				$this->view->messageError = "Le mot cl� n'a pas �t� ajout�";
			}
		}
		$this->_forward('/edit');
	}

	public function ajaxproductaccessoirelistbycatAction() {
		try {
			if ($this->getRequest()->isPost()) {
				$idcat = (int) $this->getRequest()->getPost('idcategory');
				$idcurrentproduct = (int) $this->getRequest()->getPost('idproduct');

				$product = new Product();
				$listproducts = $product->getProductsByIdCategory($idcat, 'NOM ASC');
				$this->view->listProducts = $listproducts;
				$this->view->currentProduct = $idcurrentproduct;

				$productAccessoire = new ProductAccessoire();
				$this->view->listAccessoires = $productAccessoire->getAccessoiresByProductID($idcurrentproduct, 'pa.REFACCESSOIRE ASC');;
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
		}
		$layout = Zend_Layout::getMvcInstance();
		$layout->disableLayout();
		$this->render('ajaxaccessoireproductlist');
	}


	public function addproductaccessoireAction() {
		$productAccessoire = new ProductAccessoire();
		$productChild = new ProductChild();
		try {
			if ($this->getRequest()->isPost()) {
				$params = $this->_request->getPost();
				$idproduct = (int) $params['id'];
				$refaccessoire = $params['reference_acc'];
				if ($idproduct > 0 && !empty($refaccessoire) ) {
					if ($productChild->isChildReferenceExist($params['reference_acc'])) {
						$isOk = $productAccessoire->insertAccessoire($idproduct, $refaccessoire);
						if ($isOk) {
							$this->view->messageSuccess = "L'accessoire a �t� ajout�";
						} else {
							$this->view->messageError = "L'accessoire n'a pas �t� ajout�, il est d�j� pr�sent pour ce produit";
						}
					} else {
						$this->view->messageError = "La r�f�rence n'existe pas";
					}

				}
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
		}
		$this->_forward('/edit');
	}

	public function ajaxdelproductaccessoireAction() {
		$productAccessoire = new ProductAccessoire();
		try {
			if ($this->getRequest()->isPost()) {
				$params = $this->_request->getPost();
				$idAccessoire = (int) $params['idAccessoire'];
				$idproduct = (int) $params['idproduct'];
				if ($idAccessoire > 0 ) {
					$productAccessoire->deleteAccessoire($idAccessoire);
				}
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
		}
		$listAccessoires = $productAccessoire->getAccessoiresByProductID($idproduct, 'pa.REFACCESSOIRE ASC');
		$this->view->listAccessoires = $listAccessoires ;
		$this->view->currentProduct = $idproduct;
			
		$layout = Zend_Layout::getMvcInstance();
		$layout->disableLayout();
		$this->render('ajaxaccessoirelist');
	}

	public function ajaxproductannexelistbycatAction() {
		try {
			if ($this->getRequest()->isPost()) {
				$idcat = (int) $this->getRequest()->getPost('idcategory');
				$idcurrentproduct = (int) $this->getRequest()->getPost('idproduct');

				$product = new Product();
				$listproducts = $product->getProductsByIdCategory($idcat, 'NOM ASC');
				$this->view->listProducts = $listproducts;
				$this->view->currentProduct = $idcurrentproduct;

				$productAnnexe = new ProductAnnexe();
				$this->view->listAnnexes = $productAnnexe->getAnnexesByProductID($idcurrentproduct, 'NOM ASC');;
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
		}
		$layout = Zend_Layout::getMvcInstance();
		$layout->disableLayout();
		$this->render('ajaxannexeproductlist');
	}

	public function ajaxaddproductannexeAction() {
		$productAnnexe = new ProductAnnexe();
		try {
			if ($this->getRequest()->isPost()) {
				$params = $this->_request->getPost();
				$idproduct = (int) $params['idproduct'];
				$idannexe = (int) $params['idannexe'];
				if ($idproduct > 0 && $idannexe > 0 && ($idproduct != $idannexe)) {
					$productAnnexe->insertAnnexe($idproduct, $idannexe);
				}
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
		}
		$listproducts = $productAnnexe->getAnnexesByProductID($idproduct, 'NOM ASC');
		$this->view->listProducts = $listproducts;
		$this->view->listAnnexes = $listproducts;
		$this->view->currentProduct = $idproduct;
			
		$layout = Zend_Layout::getMvcInstance();
		$layout->disableLayout();
		$this->render('ajaxannexeproductlist');
	}

	public function ajaxdelproductannexeAction() {
		$productAnnexe = new ProductAnnexe();
		try {
			if ($this->getRequest()->isPost()) {
				$params = $this->_request->getPost();
				$idproduct = (int) $params['idproduct'];
				$idannexe = (int) $params['idannexe'];
				if ($idproduct > 0 && $idannexe > 0 && ($idproduct != $idannexe)) {
					$productAnnexe->deleteAnnexe($idproduct, $idannexe);
				}
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
		}
		$listproducts = $productAnnexe->getAnnexesByProductID($idproduct, 'NOM ASC');
		$this->view->listProducts = $listproducts;
		$this->view->listAnnexes = $listproducts;
		$this->view->currentProduct = $idproduct;
			
		$layout = Zend_Layout::getMvcInstance();
		$layout->disableLayout();
		$this->render('ajaxannexeproductlist');
	}

	public function editnavheaderAction () {
		try {
			if ($this->getRequest()->isPost()) {
				$params = $this->_request->getPost();

				$filter = new Zend_Filter();
				$filter	->addFilter(new Zend_Filter_StripTags())
				->addFilter(new Zend_Filter_StringTrim());

				$filter2 = new Zend_Filter();
				$filter2->addFilter(new Zend_Filter_StringTrim())
				->addFilter(new Zend_Filter_StripTags())
				->addFilter(new Zend_Filter_StringToLower())
				->addFilter(new Zend_Filter_CustomAlnum(array('allowwhitespace' => true)));


				$key = $params['keywords_list'];
				$keyToAdd = "";
				
				$keyArray = explode(",", $key);
				
				$keyword = new KeyWord();
				for ($index = 0; $index < sizeof($keyArray); $index++) {
					$keyTemp = $filter2->filter($keyArray[$index]);		
					$keyTemp = $filter->filter($keyTemp);	
					if (!empty($keyTemp)) {
						if (empty($keyToAdd)) {
							$keyToAdd = $keyTemp;
						} else {
							$keyToAdd .=", ".$keyTemp;
						}
						if (!$keyword->isExist($keyTemp)) {
							$data = array( "KEYWORD" => $keyTemp);
							$keyword->insert($data);
						}
					}
				}
				$data = array (
					'NAVTITRE' => $filter->filter($params['navtitre']),
					'NAVDESC' => $filter->filter($params['navdesc']),
					'KEYWORDS' => $keyToAdd
				);
				$product = new Product();
				$product->update($data, 'ID = '.(int) $params['id']);
                $this->indexproductById((int) $params['id']);
			}				
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
		}
		$this->_forward('/edit');
	}

	public function editcustomnavnomAction() {
		try {
			if ($this->getRequest()->isPost()) {
				$params = $this->_request->getPost();

				$filter = new Zend_Filter();
				$filter	->addFilter(new Zend_Filter_StripTags())
				->addFilter(new Zend_Filter_StringTrim());
				//valideurs pour les chaines
				$validator = new Zend_Validate();
				$validator -> addValidator(new Zend_Validate_NotEmpty())
				-> addValidator(new Zend_Validate_StringLength(3));
					
				$data = array (
					'NAVNOM' => $this->verifyNavigationString($filter->filter($params['navnom']), $params['nom'], ''), 
					'CUSTOM_NAVNOM1' => $filter->filter($params['navnom_custom1']),
					'CUSTOM_NAVNOM2' => $filter->filter($params['navnom_custom2']),
					'CUSTOM_NAVNOM3' => $filter->filter($params['navnom_custom3'])
				);
					
				if ($validator->isValid($data['NAVNOM'])) {
					for ($index = 1; $index < 4; $index++) {
						if (!empty($data['CUSTOM_NAVNOM'.$index])) {
							$data['CUSTOM_NAVNOM'.$index] = $this->verifyNavigationString($data['CUSTOM_NAVNOM'.$index], $data['CUSTOM_NAVNOM'.$index], '');
						}
					}
					$product = new Product();
					$product->update($data, 'ID = '.(int) $params['id']);

                    $this->indexproductById((int) $params['id']);
					$this->view->messageSuccess = "Le nom de navigation a �t� modifi�";
				} else {
					$this->view->messageError = "Le nom de navigation n'a pas �t� modifi�";
				}
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
			$this->view->messageError = "Le nom de navigation n'a pas �t� modifi�";
		}
		$this->_forward('/edit');
	}
	
	public function addchildqteprixAction() {
		try {
			if ($this->_request->isPost()) { 
				//filtres pour changer les chaines
				$filter = new Zend_Filter();
				$filter	->addFilter(new Zend_Filter_StripTags())
				->addFilter(new Zend_Filter_StringTrim());
	 
				$params = $this->_request->getPost();
				$min = (int) $params['min'];
				$max = (int) $params['max'];
				$prix = $filter->filter($params['prix']);
				$item_id = (int) $params['item_id'];
				
				if (isset($params['maxend'])) {
					$maxend = $params['maxend'];
					if ($maxend) { $max = 999999999; }
				} 
				
				if ($min > 0 && $max > 0 && $prix > 0 && $item_id > 0) {
					if ($min < $max) {
						$dataQte = array (
						 		'MIN' => $min,
						 		'MAX' => $max,
						 		'PRIX' => $prix,
						 		'IDPRODUCTCHILD' => $item_id 
						); 
						$productChildQte = new ProductChildQte();
						$productChildQte->insert($dataQte);
						$this->view->messageSuccess = "Le prix d�gressif a �t� ajout�";
					} else { $this->view->messageError = "V�rifier les quantit�s"; }
				} else { $this->view->messageError = "V�rifier les param�tres"; }
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
			$this->view->messageError = "Le prix d�gressif n'a pas �t� ajout�";
		}
		$this->_forward('/edit');
	} 
	
	public function delchildqteprixAction() {
		try {
			if($this->_request->getParam('item_id')) {
				$id = (int)$this->_request->getParam('item_id');
				if ($id > 0) {
					$productChildQte = new ProductChildQte();
					$isDeleted = $productChildQte->delete('ID = '.$id); 
					if ($isDeleted) {
						$this->view->messageSuccess = "Le prix d�gressif a �t� supprim�";
					} else {
						$this->view->messageError = "Le prix d�gressif n'a pas �t� supprim�";
					} 
				}
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
			$this->view->messageError = "Le prix d�gressif n'a pas �t� supprim�";
		}
		$this->_forward('/edit');
	} 
	public function editchildqteprixactivationAction() {
		try {
			if ($this->_request->isPost()) {
				$params = $this->_request->getPost(); 
				
				$isActive = 0;
				if (isset($params['activateItemPrix'])) { $isActive = 1; }  
				
				$id = (int)$params['id'];  
				if ($id > 0) {
					$data = array (
						'isQTEPRIXACTIVE' => $isActive 
					);
					$product = new Product();
					$isUpdated = $product->update($data, 'ID = '.$id); 
					if ($isUpdated > 0) {
						$this->view->messageSuccess = "Le prix d�gressif a �t� modifi�";
					} else {
						$this->view->messageError = "Le prix d�gressif n'a pas �t� modifi�";
					} 
                    $this->indexproductById($id);
				} 
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
			$this->view->messageError = "Le prix d�gressif n'a pas �t� modifi�";
		}
		$this->_forward('/edit');
	} 
	
	public function addcaracteristiquelistAction() {
		try {
			if ($this->_request->isPost()) {
				$params = $this->_request->getPost(); 
				 
				$idoption = (int)$params['idoption'];   
				$id = (int)$params['id'];  
				if ($idoption > 0 && $id > 0) {
					$data = array (
						'ONSELECT_IDOPTION' => $idoption 
					);
					$product = new Product();
					$isUpdated = $product->update($data, 'ID = '.$id); 
					if ($isUpdated > 0) {
						$this->view->messageSuccess = "La liste des caract�ristiques a �t� modifi�";
					} else {
						$this->view->messageError = "La liste des caract�ristiques n'a pas �t� modifi�";
					} 
				} 
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
			$this->view->messageError = "La liste des caract�ristiques n'a pas �t� modifi�";
		}
		$this->_forward('/edit');
	} 
	
	public function delcaracteristiquelistAction() {
		try {
			if($this->_request->getParam('id')) {
				$id = (int)$this->_request->getParam('id');
				if ($id > 0) {
					$data = array (
						'ONSELECT_IDOPTION' => 0 
					);
					$product = new Product();
					$isUpdated = $product->update($data, 'ID = '.$id); 
					if ($isUpdated > 0) {
						$this->view->messageSuccess = "La liste des caract�ristiques a �t� modifi�";
					} else {
						$this->view->messageError = "La liste des caract�ristiques n'a pas �t� modifi�";
					} 
				}
			}
		} catch (Zend_Exception $e) {
			$this->log($e->getMessage(), 'err');
			$this->view->messageError = "La liste des caract�ristiques n'a pas �t� modifi�";
		}
		$this->_forward('/edit');
	} 
	
}
?>