<?php
/***************************************************************************
 *                                                                          *
 * Copyright (c) 2005 ISPG Technologies (I) Pvt Ltd. All rights reserved.   *
 *                                                                          *
 * This  is  commercial  software,  only  users  who have purchased a valid *
 * license  and  accept  to the terms of the  License Agreement can install *
 * and use this program.                                                    *
 *                                                                          *
 ****************************************************************************
 * PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
 * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
 ****************************************************************************/
//
//$Id: BroucherController, v 1.0 2018/12/27 12:56:15
//
class BroucherController extends Controller {
        public function indexAction()    {
                $ObjBroucher    	= 	new BroucherModel();
                $languageIDs		= 	$this->ObjView->languageIDs;		
                $link	=	'broucher/index/';
               /*  if (isset($_POST['search'])){			
                        if (isset($_POST['offerGroupID']) && $_POST['offerGroupID'] != ""){
                                $link .= "offerGroupID/" . (int)$_POST['offerGroupID'] . "/";
                        }			
                        if (isset($_POST['offerTypeID']) && $_POST['offerTypeID'] != ""){
                                $link .= "offerTypeID/" . (int)$_POST['offerTypeID'] . "/";
                        }			
                        if (isset($_POST['offerTitle']) && $_POST['offerTitle'] != ""){
                                $link .= "offerTitle/" . $this->encodeUrlString($_POST['offerTitle']) . "/";
                        }
                        $this->setRedirect($link);
                }
                else{
                        $sortby		=	$this->getRequestValue("sortby");
                        $orderby	=	($this->getRequestValue("orderby")=="")?"asc":$this->getRequestValue("orderby");
                $offerTitle='';			
                        if($this->getRequestValue('offerTitle')){
                                $offerTitle		= 	$this->decodeUrlString($this->getRequestValue('offerTitle'));
                                $link.="offerTitle/".$this->encodeUrlString($offerTitle). "/";
                        }$offerDescription='';			
                        if($this->getRequestValue('offerDescription')){
                                $offerDescription		= 	$this->getRequestValue('offerDescription');
                                $link.="offerDescription/".$offerDescription. "/";
                        }
                        if($this->getRequestValue('offerGroupID')){
                                $offerGroupID		= 	$this->getRequestValue('offerGroupID');
                                $link.="offerGroupID/".$offerGroupID. "/";
                        }
                        if($this->getRequestValue('offerTypeID')){
                                $offerTypeID		= 	$this->getRequestValue('offerTypeID');
                                $link.="offerTypeID/".$offerTypeID. "/";
                        }
                }		
                if (isset($_POST['select_status'])){
                        $params=array(
                                'status'=>$_POST['select_status'],
                                'offerIDs'=>$_POST['offerID']
                        );
                        $ObjOffer->changeStatus($params);
                        $this->setMessage('language.lblOfferstatusUpdatedSuccess','success');
                        $this->setRedirect($link);
                }
                if($sortby=='')$sortby='sort_priority'; */
                list($limitFrom, $limitTo) = $this->getPageSettings($key = 'page', $rows = 10); 

                $params =array(
                        'limitFrom'=>$limitFrom,
                        'limitTo'=>$limitTo,
                        'languageIDs'=>$languageIDs
                );
                $listBroucher   = $ObjBroucher->listbroucher($params);	
//print_r($listBroucher);exit;
                $resPagesCount = $this->setPagesCount($key = 'page');
                $this->ObjView->assign("page", $page);	
                $this->ObjView->assign('listBroucher', $listBroucher);	

                $editPrivilege	=	$this->ObjCommon->hasPrivilege('broucher/edit/');
                $this->ObjView->assign("editPrivilege", $editPrivilege);
                $deletePrivilege	=	$this->ObjCommon->hasPrivilege('broucher/destroy/');
                $this->ObjView->assign("deletePrivilege", $deletePrivilege);
				$addPrivilege	=	$this->ObjCommon->hasPrivilege('broucher/new/');
                $this->ObjView->assign("addPrivilege", $addPrivilege);
                $this->ObjView->assign("link", $link);
                /* $this->ObjView->assign("offerGroupID", $offerGroupID);
                $this->ObjView->assign("offerTypeID", $offerTypeID); */
                
                $this->ObjView->display('BroucherList.tpl');
        }




        public function newAction()    {
                $ObjBroucher    	= 	new BroucherModel();
                $ObjImage           =   new ImageModel();
                $languageIDs        = $this->ObjView->languageIDs;
				$ObjProductCategory        = new ProductCategoryModel();
			$resProductCategories      = $ObjProductCategory->listallProductCategories($languageIDs);
                if($this->ObjForm->isValid('formBroucher','submitBroucher')){
                     
					$broucherID    =   $ObjBroucher->insert($languageIDs,$_POST);
                      $this->setMessage('language.lblBroucheraddSuccess','success');
                        $this->setRedirect('broucher/index/');
                }
				
				$this->ObjView->assign("resProductCategories", $resProductCategories);
                $this->ObjView->display('BroucherAdd.tpl');
        }

        public function editAction()    {
                $ObjImage           =   new ImageModel();
                $broucherID =   $this->getRequestValue('id');
                $ObjBroucher    	= 	new BroucherModel();
                $languageIDs        = 	$this->ObjView->languageIDs;
				$ObjProductCategory        = new ProductCategoryModel();
			$resProductCategories      = $ObjProductCategory->listallProductCategories($languageIDs);
                $params=array(
                        'broucherID'=>$broucherID,
                        'languageIDs'=>$languageIDs
                );
                $getBroucher	= $ObjBroucher->getBroucher($params);
				//echo "<pre>";print_r($getBroucher);exit;
                if(empty($getBroucher)){
                         $this->setRedirect('broucher');
                }


                if($this->ObjForm->isValid('formBroucher','submitBroucher')){


                        $broucherID    =   $ObjBroucher->insert($languageIDs,$_POST,$broucherID);
                        $this->setMessage('language.lblBroucherupdatedSuccess','success');
                        $this->setRedirect('broucher/index/');

                } 
               
                $this->ObjView->assignValues($getBroucher);
                $this->ObjView->assign('broucherID', $broucherID);
				$this->ObjView->assign("resProductCategories", $resProductCategories);
                $this->ObjView->display('BroucherAdd.tpl');

        }

        

        public function ajaxstatusAction()    {
                $broucherID 	=   $this->getRequestValue('id');
                $status					  	=   $this->getRequestValue('status');
                $ObjBroucher    	= 	new BroucherModel();
                $params=array(
                        'status'=>$status,
                        'broucherIDs'=>array($broucherID)
                );
                $changeStatus = $ObjBroucher->changeStatus($params);
                $this->setMessage('language.lblBroucherstatusUpdatedSuccess','success');

        }

        public function destroyAction()    {
                $broucherID  =   $this->getRequestValue('id');
                if(isset($broucherID)){
                        $ObjBroucher    	= 	new BroucherModel();
                        $params=array(
                                'status'=>'D',
                                'broucherIDs'=>array($broucherID)
                        );
                        $changeStatus = $ObjBroucher->changeStatus($params);
                        $this->setMessage('language.lblBroucherdeletedSuccess','success');
                        $this->setRedirect('broucher/index/');

                }
        }
    public function ajaxGetBodytypeAction() {
	  $languageIDs       = $this->ObjView->languageIDs;
	  $ObjBroucher    	= 	new BroucherModel();
	  $category			 = 	$_POST['category'];
	  $args              = array(
								'languageIDs' => $languageIDs,
								'categoryID' => $category,
								'type'		 => 'bodyStyle',
                                'orderby' => 'bodyStyle',
                                'sortby' => 'ASC',
							);
       
	 $resProducts		= 	$ObjBroucher->listAllProductBodystyleDtls($args);
	 //print_r($resProducts);exit;
	 $selectStr = '';
	 if(!empty($resProducts)) {	
			$selectStr .= '<option value="">'.$this->getLanguageValue('lblSelect').'</option>';
		 foreach ($resProducts as $key => $value) {
			 $selectStr .= '<option value="'.$value['bodyStyle'].'">'.$value['bodyStyle'].'</option>';
		 } 
	 }
	  echo $selectStr;
   } 
    
     
}