<?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: CoustommenuController.php, v 1.0 2013/01/09 20:52:11
//
class CustommenuController extends controller {
    //FUNCTION TO LIST MENUS
    public function indexAction() {
        $ObjCustommenu          = new CustommenuModel();
        $languageIDs            = $this->ObjView->languageIDs;
        $languageIDs['Current'] = $languageIDs['Content'];
        $sortByOption           = $this->getRequestValue("sortby");
        $sortByOrder            = $this->getRequestValue("orderby");
        if (isset($_POST['bulkStatus'])) {
            if ($_POST['menuBulkStatus']) {
                $respBulkUpdate = $ObjCustommenu->updateMenuBulkStatus($_POST['menuBulkStatus'], $_POST['bulkStatus']);
                if ($respBulkUpdate) {
                    $this->setMessage("language.msgMenuStatusUpdate", 3);
                }
                $this->setRedirect();
            }
        }
        list($limitFrom, $limitTo) = $this->getPageSettings($key = 'page');
        $resMenus = $ObjCustommenu->listMenus($languageIDs, $limitFrom, $limitTo, '', '', 'all', $sortByOption, $sortByOrder, 'itemCount');
        $this->setPagesCount($key = 'page');
        // sort by
        if ($sortByOption == 'sname' && $sortByOrder == "asc") {
            $sortByName = "desc";
        } else {
            $sortByName = "asc";
        }
        if ($sortByOption == 'spos' && $sortByOrder == "asc") {
            $sortByPosition = "desc";
        } else {
            $sortByPosition = "asc";
        }
        foreach ($resMenus as $key => $menus) {
            if ($menus['access'] == '') {
                $resMenus[$key]['defAccess'] .= $this->getLanguageValue('lblAll');
            }
        }
        $this->ObjView->assign('resMenus', $resMenus);
        $this->ObjView->assign('contentLang', $languageIDs['Current']);
        $this->ObjView->assign("sortByName", $sortByName);
        $this->ObjView->assign("sortByPosition", $sortByPosition);
        $this->ObjView->assign('sortByOrder', $sortByOrder);
        $this->ObjView->assign('sortByOption', $sortByOption);
        if (!$sortByOption) {
            $this->ObjView->assign('sortByOption', 'sname');
            $this->ObjView->assign('sortByOrder', 'asc');
            $this->ObjView->assign('sortByName', 'desc');
        }
        $this->ObjView->assign('editPrivilege', $this->ObjCommon->hasPrivilege('custommenu/edit/'));
        $this->ObjView->assign('deletePrivilege', $this->ObjCommon->hasPrivilege('custommenu/destroy/'));
        $this->ObjView->assign('listItemPrivilege', $this->ObjCommon->hasPrivilege('custommenu/listitems/'));
        $this->ObjView->display('MenusList.tpl');
    }
    //FUNCTION TO LIST ADD MENUS
    public function newAction() {
        // $this->ObjView->clearAllCache();
        $this->ObjView->clearCache('menu/FooterMenu.tpl', null, null, null, null, __CORE_PUBLIC_FRONTEND_CACHE_PATH);
        $ObjCustommenu          = new CustommenuModel();
        $ObjUsergroup           = new UsergroupModel();
        $settingsDateFormat     = $this->getSettingValue("site_settings", "date_format");
        $languageIDs            = $this->ObjView->languageIDs;
        $languageIDs['Current'] = $languageIDs['Content'];
        $resPositionList        = $ObjCustommenu->listPositions();
        /* START : list Usergroups */
        $params                 = array(
            'languageIDs' => $languageIDs
        );
        $resUserTypesList       = $ObjUsergroup->listUsergroups($params);
        /* END : list Usergroups */
        //create access array for dropdown
        $resUserTypes[]         = array(
            '0' => '',
            '1' => $this->getLanguageValue('lblAll'),
            '3' => 'selected="selected"'
        );
        foreach ($resUserTypesList as $value) {
            $resUserTypes[] = array(
                '0' => $value['userGroupID'],
                '1' => $value['userGroupName']
            );
        }
        if ($this->ObjForm->isValid('frmMenu', 'submitMenu')) {
            if ($_POST['publishFrom'] || $_POST['publishTo']) {
                $_POST['publishFrom'] = $this->convertDateForSQL($_POST['publishFrom'], $settingsDateFormat);
                $_POST['publishTo']   = $this->convertDateForSQL($_POST['publishTo'], $settingsDateFormat);
            }
            $arr2 = array();
            foreach ($resUserTypesList as &$list) {
                array_push($arr2, $list['userGroupID']);
            }
            if (isset($_POST['access'])) {
                if (in_array('', $_POST['access'])) {
                    $_POST['access'] = '';
                } else if ((count($_POST['access'])) == (count($arr2))) {
                    $_POST['access'] = '';
                } else {
                    $_POST['access'] = implode(',', $_POST['access']);
                }
            }
            $ObjCustommenu->saveMenuDetails($languageIDs, $_POST, '');
            if (!empty($_POST['backgroundImage_temp'])) {
                $ObjImage = new ImageModel();
                $ObjImage->copy_file($_POST["backgroundImage_temp"], '/' . __UPLOADS_FOLDER . 'menus/' . $_POST['backgroundImage']);
                @unlink($_POST["backgroundImage_temp"]);
            }
            $this->setMessage("language.msgMenuUpdate", 3);
            $this->setRedirect("/custommenu/");
        }
        $this->ObjView->assign('resUserTypesList', $resUserTypes);
        $this->ObjView->assign('resPositionList', $resPositionList);
        $this->ObjView->display('MenuAdd.tpl');
    }
    //FUNCTION TO EDIT MENUS
    public function editAction() {
        $ObjCustommenu          = new CustommenuModel();
        $ObjUsergroup           = new UsergroupModel();
        $languageIDs            = $this->ObjView->languageIDs;
        $languageIDs['Current'] = $languageIDs['Content'];
        $menuID                 = $this->getRequestValue("id");
        $settingsDateFormat     = $this->getSettingValue("site_settings", "date_format");
        $resPositionList        = $ObjCustommenu->listPositions();
        /* START : list Usergroups */
        $params                 = array(
            'languageIDs' => $languageIDs
        );
        $resUserTypesList       = $ObjUsergroup->listUsergroups($params);
        /* END : list Usergroups */
        //create access array for dropdown
        $resUserTypes[]         = array(
            '0' => '',
            '1' => $this->getLanguageValue('lblAll')
        );
        foreach ($resUserTypesList as $key => $value) {
            $resUserTypes[] = array(
                '0' => $value['userGroupID'],
                '1' => $value['userGroupName']
            );
        }
        if ($menuID) {
            $menuResult = $ObjCustommenu->listMenus($languageIDs, '', '', $menuID, '', 'all');
            if (!$menuResult) {
                $this->setRedirect("/custommenu/");
                exit;
            }
            $this->ObjView->assign('menuResult', $menuResult[0]);
            if ($menuResult[0]['publishFrom'])
                $publishFrom = substr($menuResult[0]['publishFrom'], 0, 10);
            if ($menuResult[0]['publishTo'])
                $publishTo = substr($menuResult[0]['publishTo'], 0, 10);
            $defAccess = explode(',', $menuResult[0]['access']);
            foreach ($resUserTypes as $key => $value) {
                if (($defAccess[0] == '')) {
                    $resUserTypes[0][3] = 'selected="selected"';
                } else if ((in_array($value[0], $defAccess)) && (($defAccess[0] != ''))) {
                    $resUserTypes[$key][3] = 'selected="selected"';
                }
            }
            $this->ObjView->assign('publishFrom', ($publishFrom > 0) ? $publishFrom : '');
            $this->ObjView->assign('publishTo', ($publishTo > 0) ? $publishTo : '');
            $this->ObjView->assign('imageName', $menuResult[0]['imageName']);
        }
        if ($this->ObjForm->isValid('frmMenu', 'submitMenu')) {
            $menuID = ($menuID) ? $menuID : '';
            if ($_POST['publishFrom'] || $_POST['publishTo']) {
                $_POST['publishFrom'] = $this->convertDateForSQL($_POST['publishFrom'], $settingsDateFormat);
                $_POST['publishTo']   = $this->convertDateForSQL($_POST['publishTo'], $settingsDateFormat);
            }
            $arr2 = array();
            foreach ($resUserTypesList as &$list) {
                array_push($arr2, $list['userGroupID']);
            }
            if (isset($_POST['access'])) {
                if (in_array('', $_POST['access'])) {
                    $_POST['access'] = '';
                } else if ((count($_POST['access'])) == (count($arr2))) {
                    $_POST['access'] = '';
                } else {
                    $_POST['access'] = implode(',', $_POST['access']);
                }
            }
            $ObjCustommenu->saveMenuDetails($languageIDs, $_POST, $menuID);
            if (!empty($_POST['backgroundImage_temp'])) {
                $ObjImage  = new ImageModel();
                $imagePath = __UPLOADS_FOLDER . 'menus/' . trim($menuResult[0]['imageName']);
                $ObjImage->unlinkImage($imagePath);
                $ObjImage->copy_file($_POST["backgroundImage_temp"], '/' . __UPLOADS_FOLDER . 'menus/' . $_POST['backgroundImage']);
                @unlink($_POST["backgroundImage_temp"]);
            }
            $this->cleanCache();
            $this->setMessage("language.msgMenuUpdate", 3);
            $this->setRedirect("/custommenu/");
        }
        $this->ObjView->assign('resPositionList', $resPositionList);
        $this->ObjView->assign('resUserTypesList', $resUserTypes);
        $this->ObjView->assign('menuID', $menuID);
        $this->ObjView->display('MenuAdd.tpl');
    }
    //FUNCTION to change menu Status
    public function ajaxchangeStatusAction() {
        $ObjCustommenu = new CustommenuModel();
        $newstatus     = $_POST['newstatus'];
        $id            = isset($_POST['id']) ? $_POST['id'] : '';
        $itemId        = isset($_POST['itemId']) ? $_POST['itemId'] : '';
        $orderID       = isset($_POST['orderID']) ? $_POST['orderID'] : '';
        if ($newstatus && $id) {
            $ObjCustommenu->changeMenuStatus($id, $newstatus);
        } else if ($itemId) {
            $ObjCustommenu->changeMenuItemStatus($itemId, $newstatus);
        } else if ($orderID) {
            $_POST['bulkStatus'] = $newstatus;
            $ObjCustommenu->updateMenuItemOrderStatus($_POST, $orderID);
        }
        $this->cleanCache();
        $this->setMessage("language.msgStatus", 3);
    }
    //FUNCTION TO DELETE MENU
    public function destroyAction() {
        $ObjCustommenu = new CustommenuModel();
        $id            = $this->getRequestValue('id');
        if ($id) {
            $menuBulkStatusIds = array(
                $id
            );
            $ObjCustommenu->updateMenuBulkStatus($menuBulkStatusIds, 'Deleted');
            $this->setMessage("language.msgMenuDelete", "success");
            $this->cleanCache();
            $this->setRedirect('/custommenu/');
        }
    }
    //FUNCTION TO DELETE MENU ITEM AND MENU ORDERS
    public function destroyMenuItemAction() {
        $ObjCustommenu       = new CustommenuModel();
        $itemId              = $this->getRequestValue('itemId');
        $menuID              = $this->getRequestValue('menuID');
        $lang                = $this->getRequestValue('lang');
        $brandID             = $this->getRequestValue('brandID');
        $link                = ($lang!=0) ? 'lang/' . $lang . '/' : '';
        $link                .= ($brandID != '') ? 'brandID/' . $brandID . '/' : '';
        $orderID             = $this->getRequestValue('orderID');
        $_POST['bulkStatus'] = 'Deleted';
        $this->cleanCache();
        if ($itemId) {
            $ObjCustommenu->updateMenuItemBulkStatus($_POST, $itemId);
            //delete Url Rewite Details
            //$ObjUrl = new UrlrewriteModel();
            //$ObjUrl->deleteUrlRewrites('', 'menu', $itemId);
            $this->setMessage("language.msgMenuItemDelete", "success");
            //$this->setRedirect('/custommenu/frontendmenus/');
			$this->setRedirect('/custommenu/menuitems/brandID/' . $brandID . '/');
        }
        if ($orderID) {
            $ObjCustommenu->updateMenuItemOrderStatus($_POST, $orderID);
            $this->setMessage("language.msgMenuItemDelete", "success");
            $this->setRedirect('/custommenu/frontendmenus/menuID/' . $menuID . '/' . $link);
            
        }
    }
     //FUNCTION TO LIST MENUS ITEMS
  public function frontendmenusAction() {
	    $ObjCustommenu = new CustommenuModel();
		$languageIDs    = 	$this->ObjView->languageIDs;
		$brandID        = 	$this->getRequestValue('brandID');
		
		$listMenus		=	$ObjCustommenu->listMenus($languageIDs);		
		$link = 'custommenu/frontendmenus/';
		//SEARCH
		if (isset($_POST['submitSearch'])) {
			if (isset($_POST['menuID']) && $_POST['menuID'] >= 0) {
				$link .= 'menuID/' . $_POST['menuID'] . '/';
			}
			if (is_numeric($_POST['lang'])) {
				$link .= 'lang/' . $_POST['lang'] . '/';
			}
			if (isset($_POST['brandID']) && $_POST['brandID'] > 0) {
				$link .= 'brandID/' . $_POST['brandID'] . '/';
			}
			$this->setRedirect($link);
		}
		if($this->getRequestValue('menuID') > 0) 
		$menuID  		= 	$this->getRequestValue('menuID') ;
		else 
		$menuID 		= 	$listMenus[0][0];
		
		$language  		= $this->getRequestValue('lang');
		if(is_numeric($language))  {
			$selLanguage =  array($language) ;
		} 
		else  $selLanguage = array('0');
		
				
		$ObjBrand       		= new BrandModel();	
		$brandParams         	= array(
			'languageIDs' 		=> $languageIDs
		);       
		$listBrand      		= $ObjBrand->listBrand($brandParams);  
		$brandID = (!empty($brandID )) ? $brandID : $listBrand[0]['brandID'];
		$this->ObjView->assign('brandID', $brandID);
		$this->ObjView->assign('listBrand', $listBrand);
		
		$parentParams         	= array(
			'languageIDs' 				=> $languageIDs,
			'selLanguages' 				=> $selLanguage,
			'list' 						=> 'list',
			'languageXml' 				=> $this->ObjView->_languageXML,
			'brandID' 					=> $brandID
		);
		$resMenusItems		= 	$ObjCustommenu->getParentMenusItems($parentParams);
		$listItemsInOrder	= 	$ObjCustommenu->getMenusItemsInOrder($languageIDs, $menuID, $selLanguage, $this->ObjView->_languageXML,$brandID);
	    $this->ObjView->assign('listMenus', $listMenus);	
		$this->ObjView->assign('defLang', $language);
		$this->ObjView->assign('menuItemAction', "listing");
		$this->ObjView->assign('menuID', $menuID);  
		$this->ObjView->assign('resMenusItems', $resMenusItems);
		$this->ObjView->assign('listItemsInOrder', $listItemsInOrder);
		$this->ObjView->assign('editPrivilege', $this->ObjCommon->hasPrivilege('custommenu/edititem/'));
		$this->ObjView->assign('deletePrivilege',$this->ObjCommon->hasPrivilege('custommenu/destroymenuitem/'));
		$this->ObjView->display('FrontendMenus.tpl');
  }
    //FUNCTION TO LIST MENUS ITEMS
    public function listItemsAction() {
        $ObjCustommenu = new CustommenuModel();
        $languageIDs   = $this->ObjView->languageIDs;
        $listMenus     = $ObjCustommenu->listMenus($languageIDs);
        $link          = 'custommenu/listItems/';
        //SEARCH
        if (isset($_POST['submitSearch'])) {
            if (isset($_POST['menuID']) && $_POST['menuID'] >= 0) {
                $link .= 'menuID/' . $_POST['menuID'] . '/';
            }
            if (is_numeric($_POST['lang'])) {
                $link .= 'lang/' . $_POST['lang'] . '/';
            }
            $this->setRedirect($link);
        }
        if ($this->getRequestValue('menuID') > 0)
            $menuID = $this->getRequestValue('menuID');
        else
            $menuID = $listMenus[0][0];
        $language = $this->getRequestValue('lang');
        if (is_numeric($language)) {
            $selLanguage = array(
                $language
            );
        } else
            $selLanguage = array(
                '0'
            );
        //$resMenusItems    = $ObjCustommenu->getParentMenusItems($languageIDs, '', '',  $selLanguage, 'list', $this->ObjView->_languageXML);
		$parentParams         	= array(
			'languageIDs' 				=> $languageIDs,
			'selLanguages' 				=> $selLanguage,
			'list' 						=> 'list',
			'languageXml' 				=> $this->ObjView->_languageXML
			//'brandID' 					=> $brandID
		);
		$resMenusItems		= 	$ObjCustommenu->getParentMenusItems($parentParams);
        $listItemsInOrder = $ObjCustommenu->getMenusItemsInOrder($languageIDs, $menuID, $selLanguage, $this->ObjView->_languageXML);
        $this->ObjView->assign('listMenus', $listMenus);
        $this->ObjView->assign('defLang', $language);
        $this->ObjView->assign('menuID', $menuID);
        $this->ObjView->assign('resMenusItems', $resMenusItems);
        $this->ObjView->assign('listItemsInOrder', $listItemsInOrder);
        $this->ObjView->assign('editPrivilege', $this->ObjCommon->hasPrivilege('custommenu/edititem/'));
        $this->ObjView->assign('deletePrivilege', $this->ObjCommon->hasPrivilege('custommenu/destroymenuitem/'));
        $this->ObjView->display('FrontendMenus.tpl');
    }
    //FUNCTION TO LIST ALL MENUS ITEMS
    public function menuitemsAction() {
        $ObjCustommenu = new CustommenuModel();
		$brandID       = $this->getRequestValue('brandID');
        $languageIDs   = $this->ObjView->languageIDs;
        $selLanguage   = '';
		
		$ObjBrand       		= new BrandModel();	
		$brandParams         	= array(
			'languageIDs' 		=> $languageIDs
		);       
		$listBrand      		= $ObjBrand->listBrand($brandParams);  
		$brandID = (!empty($brandID )) ? $brandID : $listBrand[0]['brandID'];
		$this->ObjView->assign('listBrand', $listBrand);
		$this->ObjView->assign('brandID', $brandID);

		$parentParams         	= array(
			'languageIDs' 				=> $languageIDs,
			'selLanguages' 				=> $selLanguage,
			'list' 						=> 'listdetails',
			'languageXml' 				=> $this->ObjView->_languageXML,
			'brandID' 					=> $brandID
		);
		$resMenusItems		= 	$ObjCustommenu->getParentMenusItems($parentParams);
        $this->ObjView->assign('resMenusItems', $resMenusItems);
        $this->ObjView->assign('editPrivilege', $this->ObjCommon->hasPrivilege('custommenu/edititem/'));
        $this->ObjView->assign('deletePrivilege', $this->ObjCommon->hasPrivilege('custommenu/destroymenuitem/'));
        $this->ObjView->display('MenuItemListDetails.tpl');
    }
    //FUNCTION TO ADD MENUS ITEMS
    public function addItemAction() {
        $ObjCustommenu          = new CustommenuModel();
        $ObjUsergroup           = new UsergroupModel();
        $ObjUrlrewrite          = new UrlrewriteModel();
        $settingsDateFormat     = $this->getSettingValue("site_settings", "date_format");
        //URL Rewrite Settings		
        $suffix                 = $this->getSettingValue("seo_settings", "menu_url_suffix");
        //URL Rewrite Settings
        $languageIDs            = $this->ObjView->languageIDs;
        $languageIDs['Current'] = $languageIDs['Content'];
        /* START : list Usergroups */
        $params                 = array(
            'languageIDs' => $languageIDs
        );
        $resUserTypesList       = $ObjUsergroup->listUsergroups($params);
        /* END : list Usergroups */
        $defaultOption          = (isset($_POST['menuItemType']) && $_POST['menuItemType'] != '') ? $_POST['menuItemType'] : '';
        $resFrontendModules     = $ObjCustommenu->listFrontendModules($defaultOption, $this->ObjView->_languageXML);
        //$parentMenuItems		= 	$ObjCustommenu->getParentMenusItems($languageIDs,'','',array(0));
		$parentParams         	= array(
			'languageIDs' 				=> $languageIDs,
			'selLanguages' 				=> array(0),
			//'brandID' 					=> $brandID
		);
		$parentMenuItems		= 	$ObjCustommenu->getParentMenusItems($parentParams);
        $this->ObjView->assign('resFrontendModules', $resFrontendModules);
        $resUserTypes[] = array(
            '0' => '',
            '1' => $this->getLanguageValue('lblAll'),
            '3' => 'selected="selected"'
        );
        foreach ($resUserTypesList as $value) {
            $resUserTypes[] = array(
                '0' => $value['userGroupID'],
                '1' => $value['userGroupName']
            );
        }
        if ($this->ObjForm->isValid('frmMenuItem', 'submitMenuItem')) {
            if ($_POST['publishFrom'] || $_POST['publishTo']) {
                $_POST['publishFrom'] = $this->convertDateForSQL($_POST['publishFrom'], $settingsDateFormat);
                $_POST['publishTo']   = $this->convertDateForSQL($_POST['publishTo'], $settingsDateFormat);
            }
            if (isset($_POST['settings']) && is_array($_POST['settings'])) {
                $_POST['params'] = json_encode($_POST['settings']);
            }else if($_POST['itemparams']!='') { 
				//itemparams - field used to save json data in case of product listing
				$_POST['params'] =  $_POST['itemparams'] ;
            }
            if (isset($_POST['access'])) {
                $arr2 = array();
                foreach ($resUserTypesList as &$list) {
                    array_push($arr2, $list['userGroupID']);
                }
                if (in_array('', $_POST['access'])) {
                    $_POST['access'] = '';
                } else if ((count($_POST['access'])) == (count($arr2))) {
                    $_POST['access'] = '';
                } else {
                    $_POST['access'] = implode(',', $_POST['access']);
                }
            }
           
           // echo $sourceUrl;exit;
            $urlKey = ($_POST['menuItemKey']) ? $_POST['menuItemKey'] : $this->ObjCommon->generateKey("menuitem", $_POST['menuItemTitle'], 0, "unique");
            list($menuItemID, $itemOrderID) = $ObjCustommenu->saveMenuItemDetails($languageIDs, '', $urlKey);
            if (!empty($_POST['menuIcon_temp'])) {
                $ObjImage = new ImageModel();
                $ObjImage->copy_file($_POST["menuIcon_temp"], '/' . __UPLOADS_FOLDER . 'menus/menu-items/' . $_POST['menuIcon']);
                @unlink($_POST["menuIcon_temp"]);
            }
            $this->cleanCache();
			
			$link  = ($_POST['brandID'] != '') ? 'brandID/' . $_POST['brandID'] . '/' : '';
            $this->setMessage("language.msgMenuItemUpdate", 3);
            $this->setRedirect("/custommenu/menuitems/".$link);
        }
        if ($_POST) {
            $itemTypeSel = $_POST["itemTypeSel"];
            if ($itemTypeSel != '') {
                $params = $this->ajaxMenuItemSettingsAction($itemTypeSel);
                $this->ObjView->assign('parameters', $params);
                $this->ObjView->assign('paramsValues', $_POST["settings"]);
                $this->ObjView->assign('moduleID', $itemTypeSel);
            }
        }
		
		$ObjBrand       		= new BrandModel();	
		   $brandParams         = array(
            'languageIDs' 		=> $languageIDs
        );       
        $listBrand      		= $ObjBrand->listBrand($brandParams);  
        $this->ObjView->assign('listBrand', $listBrand);
		
        $this->ObjView->assign('menuItemAction', "Add");
        $this->ObjView->assign('resUserTypesList', $resUserTypes);
        $this->ObjView->assign('sysKeys', SYSTEM_DIR_KEYS);
        $this->ObjView->assign('parentItems', $parentMenuItems);
        $this->ObjView->display('MenuItemAdd.tpl');
    }
    //FUNCTION TO EDIT MENUS ITEMS
    public function editItemAction() {
        
        $ObjCustommenu          = new CustommenuModel();
        $ObjLanguage            = new LanguageModel();
        $ObjBanner              = new BannerModel();
        $ObjUsergroup           = new UsergroupModel();
        $ObjSaleTracking        = new SaleTrackingModel();
        $ObjUrlrewrite          = new UrlrewriteModel();
        $languageIDs            = $this->ObjView->languageIDs;
        $languageIDs['Current'] = $languageIDs['Content'];
        /*privileges*/
        $this->ObjView->assign('bannerprivilege', $this->ObjCommon->hasPrivilege('banner/index/'));
        $this->ObjView->assign('blockprivilege', $this->ObjCommon->hasPrivilege('staticblock/index/'));
        /*privileges*/
        $menuItemID         = $this->getRequestValue("id");
        $settingsDateFormat = $this->getSettingValue("site_settings", "date_format");
        //banners
        $resBanner          = $ObjBanner->listBanner($languageIDs, '', '', '', '', '', '', '', '', '', 'manage', '1');
        $listItemBanner     = $ObjBanner->listMenuItemBanners($languageIDs, $menuItemID, 'manage');
        //end banners
        //static blocks
        $resBlocks          = $ObjCustommenu->listStaticBlocks($languageIDs);
        $resItemBlocks      = $ObjCustommenu->listStaticBlocks($languageIDs, '', '', '', '', '', 'menuItemlist', $menuItemID);
        //static blocks
        /* START : list Usergroups */
        $params             = array(
            'languageIDs' => $languageIDs
        );
        $resUserTypesList   = $ObjUsergroup->listUsergroups($params);
        /* END : list Usergroups */
        $listMenus          = $ObjCustommenu->listMenus($languageIDs);
        //Tracking Code
        $resSaleTrackDet    = $ObjSaleTracking->listTrackingCodesForPage($menuItemID, 'Menu');
        $resUserTypes[]     = array(
            '0' => '',
            '1' => $this->getLanguageValue('lblAll'),
            '3' => ''
        );
        foreach ($resUserTypesList as $key => $value) {
            $resUserTypes[] = array(
                '0' => $value['userGroupID'],
                '1' => $value['userGroupName'],
                '3' => ''
            );
        }
        $this->ObjView->assign('listMenus', $listMenus);
        //URL Rewrite Settings
        $settingsRedirectUrl = $this->getSettingValue("seo_settings", "redirect_for_url");
        $suffix              = $this->getSettingValue("seo_settings", "menu_url_suffix");
       
        //URL Rewrite Settings
        if ($menuItemID) {
            $contentLanguages = $ObjCustommenu->getContentSelectedLang($menuItemID);
            if ($contentLanguages && $contentLanguages['availableLang'] != '0') {
                $contentLangArr = explode(",", $contentLanguages['availableLang']);
                if (!in_array($languageIDs['Current'], $contentLangArr)) {
                    $languageIDs['Current'] = $contentLangArr[0];
                }
                $contentLangSelctdDet = $ObjLanguage->getLanguageDetails($languageIDs['Current']);
                $this->ObjView->assign('contentLangSelctdDet', $contentLangSelctdDet);
            }
            $menuResultItem = $ObjCustommenu->listMenusItems($languageIDs, $menuItemID);
            if (!$menuResultItem) {
                $this->setRedirect("/custommenu/menuitems/");
                exit;
            }
            $menuResultItem     = $menuResultItem[0];
            $resFrontendModules = $ObjCustommenu->listFrontendModules($menuResultItem['moduleID'], $this->ObjView->_languageXML);
            if ($menuResultItem['publishDateFrom'])
                $publishFrom = substr($menuResultItem['publishDateFrom'], 0, 10);
            if ($menuResultItem['publishDateTo'])
                $publishTo = substr($menuResultItem['publishDateTo'], 0, 10);
            if ($menuResultItem['availableLang'] == 0)
                $deflang = array(
                    0
                );
            else {
                $deflang = explode(",", $menuResultItem['availableLang']);
            }
            $defAccess = explode(',', $menuResultItem['access']);
            foreach ($resUserTypes as $key => $value) {
                if (($defAccess[0] == '')) {
                    $resUserTypes[0][3] = 'selected="selected"';
                } else {
                    if ((in_array($value[0], $defAccess)) && (($defAccess[0] != ''))) {
                        $resUserTypes[$key][3] = 'selected="selected"';
                    }
                }
            }
            //children languages
            $orderchildsLanguages = explode(",", $menuResultItem['orderchildsLanguages']);
            if ($orderchildsLanguages)
                $orderchildsLanguages = (array_unique($orderchildsLanguages));
            $menuResultItem['orderchildsLanguages'] = implode(',', $orderchildsLanguages);
            $childrenLanguages                      = explode(",", $menuResultItem['childrenLanguages']);
            if ($childrenLanguages)
                $childrenLanguages = (array_unique($childrenLanguages));
            $menuResultItem['childrenLanguages'] = implode(',', $childrenLanguages);
            //$parentMenuItems        = $ObjCustommenu->getParentMenusItems($languageIDs, $menuItemID, $menuResultItem['parentID'], $deflang);
			
			 $parentParams         	= array(
				'languageIDs' 				=> $languageIDs,
				'menuItemID' 				=> $menuItemID,
				'parentID' 					=> $menuResultItem['parentID'],
				'selLanguages' 				=> $deflang,
				'brandID' 					=> $menuResultItem['brandID']
			  ); 
			$parentMenuItems		= 	$ObjCustommenu->getParentMenusItems($parentParams);
            $params                 = $this->ajaxMenuItemSettingsAction($menuResultItem['moduleID'], $deflang,$menuResultItem['brandID']);
            $this->ObjView->assign('parameters', $params);
            $this->ObjView->assign('moduleID', $menuResultItem['moduleID']);
           
            //Language
            $resLanguageSel     = array();
            $resLanguageSelects = explode(',', $menuResultItem['availableLang']);
            $this->ObjView->assign('resLanguageSelects', $resLanguageSelects);
            //content language select
            if (count($resLanguageSelects) > 1) {
                foreach ($resLanguageSelects as $key => $value) {
                    $resLanguageSel[] = $ObjLanguage->getLanguageDetails($value);
                }
            }
        }
        if ($this->ObjForm->isValid('frmMenuItem', 'submitMenuItem')) {
            $menuItemID              = ($menuItemID) ? $menuItemID : '';
            $_POST['redirectOption'] = isset($_POST['redirectOption']) ? $_POST['redirectOption'] : '';
            if ($_POST['publishFrom'] || $_POST['publishTo']) {
                $_POST['publishFrom'] = $this->convertDateForSQL($_POST['publishFrom'], $settingsDateFormat);
                $_POST['publishTo']   = $this->convertDateForSQL($_POST['publishTo'], $settingsDateFormat);
            }
            if (isset($_POST['settings']) && is_array($_POST['settings'])) {
                if (!empty($_POST['menuIcon_temp'])) {
                    $_POST['settings']['showSectionImage'] = '';
                }
                $_POST['params'] = json_encode($_POST['settings']);
            }else if($_POST['itemparams']!='') { 
				//itemparams - field used to save json data in case of product listing
				$_POST['params'] =  $_POST['itemparams'] ;
            }
            if (isset($_POST['access'])) {
                $arr2 = array();
                foreach ($resUserTypesList as &$list) {
                    array_push($arr2, $list['userGroupID']);
                }
                if (in_array('', $_POST['access'])) {
                    $_POST['access'] = '';
                } else if ((count($_POST['access'])) == (count($arr2))) {
                    $_POST['access'] = '';
                } else {
                    $_POST['access'] = implode(',', $_POST['access']);
                }
            }
            
            // else
            $urlKey = ($_POST['menuItemKey']) ? $_POST['menuItemKey'] : $this->ObjCommon->generateKey("menuitem", $_POST['menuItemTitle'], 0, "unique");
            //$urlKey = "led-cables";
			
            list($itemID, $itemOrderID) = $ObjCustommenu->saveMenuItemDetails($languageIDs, $menuItemID, $urlKey);
           
            
            if (!empty($_POST['menuIcon_temp'])) {
                $ObjImage  = new ImageModel();
                $imagePath = __UPLOADS_FOLDER . 'menus/menu-items/' . trim($menuResultItem['iconName']);
                $ObjImage->unlinkImage($imagePath);
                $ObjImage->copy_file($_POST["menuIcon_temp"], '/' . __UPLOADS_FOLDER . 'menus/menu-items/' . $_POST['menuIcon']);
                @unlink($_POST["menuIcon_temp"]);
            }
            $this->cleanCache();
			
			$link  = ($_POST['brandID'] != '') ? 'brandID/' . $_POST['brandID'] . '/' : '';
            $this->setMessage("language.msgMenuItemUpdate", 3);
            $this->setRedirect("/custommenu/menuitems/".$link);
        }
        if (isset($_POST['submitTracking'])) {
            $_POST['trackingTypeID'] = $menuItemID;
            $_POST['trackingType']   = 'Menu';
            $ObjSaleTracking->saveTrackingCodeDetails($_POST, $resSaleTrackDet['trackingID']);
            $history = $this->getPreviousURL();
            if ($resSaleTrackDet['trackingID']) {
                $this->setMessage("language.msgTrackUpdate", 3);
            } else {
                $this->setMessage("language.msgTrackAdd", 3);
            }
            $this->setRedirect($history);
        }
		
		$ObjBrand       		= new BrandModel();	
		   $brandParams         = array(
            'languageIDs' 		=> $languageIDs
        );       
        $listBrand      		= $ObjBrand->listBrand($brandParams);  
        $this->ObjView->assign('listBrand', $listBrand);
		
		
        $this->ObjView->assign('currentContentLanguageID', $languageIDs['Current']);
        $this->ObjView->assign('settingsRedirectUrl', $settingsRedirectUrl);
        $this->ObjView->assignValues($resSaleTrackDet);
        $this->ObjView->assign('resUserTypesList', $resUserTypes);
        $this->ObjView->assign('publishFrom', ($publishFrom > 0) ? $publishFrom : '');
        $this->ObjView->assign('publishTo', ($publishTo > 0) ? $publishTo : '');
        $this->ObjView->assign('imageName', $menuResultItem['iconName']);
        $this->ObjView->assign('menuResultItem', $menuResultItem);
        $this->ObjView->assign('resFrontendModules', $resFrontendModules);
        $this->ObjView->assign('parentItems', $parentMenuItems);
        $this->ObjView->assign('orderItems', isset($listOrderItems) ? $listOrderItems : '');
        $this->ObjView->assign('paramsValues', isset($_POST['settings']) ? $_POST["settings"] : json_decode($menuResultItem['params'], true));
        $this->ObjView->assign('resBanner', $resBanner);
        $this->ObjView->assign('resBlocks', $resBlocks);
        $this->ObjView->assign('resItemBlocks', $resItemBlocks);
        $this->ObjView->assign('listItemBanner', $listItemBanner);
        $this->ObjView->assign('paramsEncoded', $menuResultItem['params']);
        $this->ObjView->assign('defmoduleID', $menuResultItem['moduleID']);
        $this->ObjView->assign('menuItemID', $menuItemID);
        $this->ObjView->assign('listItemLang', isset($resLanguageSel) ? $resLanguageSel : '');
        $this->ObjView->assign('resLanguageSelect', isset($resLanguageSel) ? $resLanguageSel : '');
        $this->ObjView->assign('sysKeys', SYSTEM_DIR_KEYS);
        $this->ObjView->assign('menuItemAction', "Edit");
        $this->ObjView->display('MenuItemAdd.tpl');
    }
    //AJAX FUNCTION TO LIST MENU ITEMS BY ORDER IN PARENT DROPDOWN
  public function ajaxListMenuItemsAction() {
	 $ObjCustommenu 			= 	new CustommenuModel();
	  $languageIDs   			= 	$this->ObjView->languageIDs;
	  $languageIDs['Current'] 	= 	$languageIDs['Content'];
	  $parentID					= 	$_POST['parentID'];
	  $menuItemID				= 	$_POST['itemId'];
	  $brandID					= 	$_POST['brandID'];
	 if($_POST['AllLang']=='No')
            $selLanguages		=	explode(',',$_POST['selLanguages']);   
          else 
            $selLanguages		=	array('0');
      
	  $parentParams         	= array(
		'languageIDs' 				=> $languageIDs,
		'menuItemID' 				=> $menuItemID,
		'parentID' 					=> $parentID,
		'selLanguages' 				=> $selLanguages,
		'brandID' 					=> $brandID
	  ); 	
	  $resMenuItems				= 	$ObjCustommenu->getParentMenusItems($parentParams);
	  echo $resMenuItems;
  } 
    //AJAX FUNCTION TO SET MENU ITEMS IN ORDER IN LEFT SIDE OF LIST ITEMS
    public function ajaxListOrderItemsAction() {
        $ObjCustommenu = new CustommenuModel();
        $itemsList     = json_decode($_POST['items'], true);
        $menuID        = isset($_POST['menuID']) ? $_POST['menuID'] : '';
        $brandID       = isset($_POST['brandID']) ? $_POST['brandID'] : '';
        $languageIDs   			= 	$this->ObjView->languageIDs;
        $ObjCustommenu->setMenusItemsInOrder($menuID, $itemsList, 0, array(),$languageIDs['AllList'],$brandID);
        $this->cleanCache();
        $this->setMessage("language.msgMenuOrderSavedSuccessfully", "success");
        echo '1';
    }
    //AJAX FUNCTION TO SET MENU ITEMS IN ORDER IN MENU ITEMS FULL DETAILS LISTING
    public function ajaxListOrderParentItemsAction() {
        $ObjCustommenu = new CustommenuModel();
        $itemsList     = json_decode($_POST['items'], true);
        $ObjCustommenu->setItemsInOrder($itemsList, 0, array());
        $this->cleanCache();
        $this->setMessage("language.msgMenuItemsSavedSuccessfully", "success");
        echo '1';
    }
    //AJAX FUNCTION TO GET MENU ITEM TYPE DETAILS BASED ON MENU ITEM ID
    public function ajaxGetItemTypeDetailsAction() {
        $itemId                 = $_POST['itemId'];
        $moduleID               = $_POST['moduleID'];
        $lang                   = $_POST['lang'];
        $languageIDs            = $this->ObjView->languageIDs;
        $languageIDs['Current'] = ($lang != '' && $lang>0) ? $lang : $languageIDs['Current'];
        $ObjCustommenu          = new CustommenuModel();
        $caption                = $ObjCustommenu->GetItemTypeDetails($languageIDs, $itemId, $moduleID);
        echo $caption;
    }
      //TO SET ORDER OF MENU ITEM BANNERS USING AJAX
    public function ajaxSetBannersAction() {
        $ObjCustommenu = new CustommenuModel();
        $menuItemID    = $_POST['menuItemID'];
        $deleteBanner  = $_POST['deleteBanner'];
        $bannerArray   = json_decode($_POST['items'], true);
        echo $ObjCustommenu->setMenuItemBanners($menuItemID, $bannerArray, $deleteBanner);
    }
    //TO SET ORDER OF MENU ITEM BLOCKS USING AJAX
    public function ajaxSetStaticBlocksAction() {
        $ObjCustommenu = new CustommenuModel();
        $menuItemID    = $_POST['menuItemID'];
        $deleteBlock   = $_POST['deleteBlock'];
        $blockArray    = json_decode($_POST['items'], true);
        echo $ObjCustommenu->setMenuItemStaticBlocks($menuItemID, $blockArray, $deleteBlock);
    }
    //AJAX FUNCTION TO DISPLAY REQUIRED SETTINGS ACCORDING TO MENU ITEM TYPE SELECTED
    public function ajaxMenuItemSettingsAction($moduleID = '', $deflang = '', $brandID = '') {
        $ObjCustommenu          = new CustommenuModel();
        $languageIDs            = $this->ObjView->languageIDs;
        $languageIDs['Current'] = $languageIDs['Content'];
        $type                   = (isset($moduleID) && $moduleID != '') ? $moduleID : $_POST['type'];
        $paramsEncoded          = isset($_POST['defaultData']) ? $_POST['defaultData'] : '';
        $selLanguages           = (!empty($deflang)) ? $deflang : explode(',', $_POST['selLanguages']);
        $resModuleDetails       = $ObjCustommenu->getFrontendModulesDetails($type);
        $paramsValues           = (!empty($paramsEncoded)) ? json_decode($paramsEncoded, true) : '';
		$brandID          		= (!empty($brandID)) ? $brandID : $_POST['brandID'];
        $params                 = array();
        if ($resModuleDetails['params'] != '') {
            $params      = json_decode($resModuleDetails['params'], true);
            $moduleKey   = $resModuleDetails['moduleKey'];
            $optionsList = '';
            switch ($moduleKey) {
                case 'singlepage':
                    $ObjContent     = new ContentModel();
                    $ObjTheme       = new ThemeModel();
                    $optionsList    = $ObjContent->listContentPagesOptions($languageIDs, $selLanguages,$brandID);
                    $currPageLayout = $ObjTheme->getTplFile('standard', 'contentPage');
                    break;
                case 'categorylist':
                    $producttypes = array(
                        array(
                            1,
                            'Products',
                            'product_product',
                            'productTypeID' => 1,
                            'productTypeName' => 'Products',
                            'productTypeKey' => 'product_product'
                        )
                    );
                    break;
                case 'singlecategory':
                    $ObjProductCategory = new ProductCategoryModel();
                    //$resCategoryTree    = $ObjProductCategory->listProductCategoryItems($languageIDs, 0, 0, 0, '', true, '', '', '1');
					//$resCategoryTree    = array_slice($resCategoryTree, 1);
                    list($CategoryTree,$resCategoryTree)    = $ObjProductCategory->listCategoryItems(array('languageIDs' =>$languageIDs,'brandID'=>$brandID));
					
					foreach($resCategoryTree as $keycat => $valuecat) {
						$productCategoryKey = $valuecat['productCategoryKey'];
						if(isset($valuecat['children']) && !empty($valuecat['children'])) {
							foreach($valuecat['children'] as $keychild => $valuechild) {
								$productCategoryKey .= '~'.$valuechild['productCategoryKey'];
							}
						}
						$resCategory[]	= array(
										$productCategoryKey,
										$valuecat['productCategoryName']
						);
						
					}
                    break;
                case 'singlebrand':
                    $ObjBrand  = new BrandModel();
                    $args      = array(
                        'languageIDs' => $languageIDs
                    );
                    $listBrand = $ObjBrand->listBrand($args);
                    break;
                case 'singlestore':
                    $ObjBusiness  = new BusinessModel();
                    $listBusiness = $ObjBusiness->listBusiness($languageIDs);
                    break;
            }
            if (isset($producttypes) && $producttypes != '') {
                foreach ($producttypes as $key => $value) {
                    if ($value['productTypeKey'] == "product_product") {
                        $productTypeLink = "products";
                    } else if ($value['productTypeKey'] == "getaway_product") {
                        $productTypeLink = "getaways";
                    } else if ($value['productTypeKey'] == "now_product") {
                        $productTypeLink = "now";
                    } else {
                        $productTypeLink = "activeproducts/producttypekey/" . $value['productTypeUrlKey'];
                    }
                    $productTypeLink = (($moduleKey != 'categorylist') && ($moduleKey != 'singlecategory')) ? $productTypeLink : $productTypeLink . "/category/";
                    $optionsList[]   = array(
                        '0' => $value['productTypeID'],
                        '1' => $value['productTypeName'],
                        '2' => 'key="' . $productTypeLink . '"'
                    );
                }
            }
            if ($moduleKey == 'categorylist' || $moduleKey == 'singlecategory') {
                $all  = $this->getLanguageValue('lblAll');
                $dont = $this->getLanguageValue('lblDontShowSubLevels');
                foreach ($params as $key => $value) {
                    $params[$key]['language'] = $this->getLanguageValue($value['label']);
                    $params[$key]['options']  = ($moduleKey == 'categorylist') ? $optionsList : (($moduleKey == 'singlecategory') ? $resCategory : '');
                    ($value['name'] == 'subLevels') ? $params[$key]['options'] = '->' . $dont . '~*0->' . $all . '~*1~*2~*3~*4~*5~*6~*7' : '';
                }
            } else if ($moduleKey == 'singlepage') {
                $theme      = __THEME;
                $pageLayout = $this->getCmsPageLayout();
                if (!isset($paramsValues['layout-' . $theme])) {
                    $paramsValues['layout-' . $theme] = $currPageLayout;
                }
                foreach ($params as $key => $value) {
                    $params[$key]['language'] = $this->getLanguageValue($value['label']);
                    if ($value['name'] == 'selectedID') {
                        $params[$key]['options'] = $optionsList;
                    }
                    if ($value['name'] == 'layout') {
                        $params[$key]['name']    = 'layout-' . $theme;
                        $params[$key]['options'] = $pageLayout;
                    }
                }
            }  else if ($moduleKey == 'singlebrand') {
                foreach ($params as $key => $value) {
                    $params[$key]['language'] = $this->getLanguageValue($value['label']);
                    if ($value['type'] == 'select') {
                        foreach ($listBrand as $brand) {
                            $optionsList[] = array(
                                '0' => $brand['brandID'],
                                '1' => $brand['brandName'],
                                '2' => 'key="' . $brand['brandKey'] . '"'
                            );
                        }
                        $params[$key]['options'] = $optionsList;
                    }
                }
            } else if ($moduleKey == 'singlestore') {
                foreach ($params as $key => $value) {
                    $params[$key]['language'] = $this->getLanguageValue($value['label']);
                    if ($value['type'] == 'select') {
                        foreach ($listBusiness as $business) {
                            $optionsList[] = array(
                                '0' => $business['businessID'],
                                '1' => $business['businessName'],
                                '2' => 'key="' . $business['businessKey'] . '"'
                            );
                        }
                        $params[$key]['options'] = $optionsList;
                    }
                }
            } else {
                foreach ($params as $key => $value) {
                    $params[$key]['language'] = $this->getLanguageValue($value['label']);
                    if ($value['type'] == 'select') {
                        $params[$key]['options'] = $optionsList;
                    }
                }
            }
        }
        $this->ObjView->assign('moduleKey', isset($moduleKey) ? $moduleKey : ''); //echo '<pre>'; print_r($params);
        if ($moduleID)
            return $params;
        $this->ObjView->assign('moduleKey', $moduleKey);
        $this->ObjView->assign('parameters', $params);
        $this->ObjView->assign('moduleID', $type);
        $this->ObjView->assign('paramsValues', $paramsValues);
        $this->ObjView->display('AjaxMenuItemSettings.tpl');
    }
    //TO GET CMS PAGE LAYOUTS FROM template.xml
    public function getCmsPageLayout() {
        $themeDir     = __CORE_PATH . "/views/" . __DIR_FRONTEND . "/" . __THEME;
        $templateFile = $themeDir . "/theme-config/template.xml";
        if (is_dir($themeDir)) {
            if (file_exists($templateFile)) {
                $xml = simplexml_load_file($templateFile);
                foreach ($xml->children() as $group) {
                    $group     = (array) $group;
                    $groupPage = (array) $group['page'];
                    if (($group['@attributes']['type'] == 'cms') && ($groupPage['key'] == 'contentPage')) {
                        $pageLayout = array();
                        foreach ($group['page'] as $child) {
                            $child = (array) $child;
                            if (!empty($child['name'])) {
                                $pageLayout[] = array(
                                    $child['tpl'],
                                    $child['name']
                                );
                            }
                        }
                    }
                }
            } else {
                echo "<h3>Info : Template file (template.xml) not found in /view/" . strtolower(__THEME) . "/theme-config/</h3>";
                exit;
            }
        } else {
            echo "<h3>Info : Directory not found in /view/" . strtolower(__THEME) . "/<h3>";
            exit;
        }
        return $pageLayout;
    }
    //==============  CALL BACK FUNCTIONS ==============================		
    public function CheckItemKey() {
        $menuItemID    = isset($_POST['menuItemID']) ? $_POST['menuItemID'] : '';
        $brandID       = isset($_POST['brandID']) ? $_POST['brandID'] : '';
        $key           = isset($_POST['key']) ? $_POST['key'] : '';
        $ObjCustommenu = new CustommenuModel();
        $reskeyExists  = $ObjCustommenu->checkMenuItemKeyExists($menuItemID, $key, $brandID);
        if ($reskeyExists[0][0] == '1')
            return false;
        else
            return true;
    }
    public function ajaxCheckItemKeyAction() {
        $menuItemID    = $_POST['menuItemID'];
        $brandID       = $_POST['brandID'];
        $key           = $_POST['key'];
        $ObjCustommenu = new CustommenuModel();
        $reskeyExists  = $ObjCustommenu->checkMenuItemKeyExists($menuItemID, $key, $brandID);
        echo $reskeyExists[0][0];
    }
    public function checkMenuKey() {
        $menuID        = isset($_POST['menuID']) ? $_POST['menuID'] : '';
        $key           = isset($_POST['key']) ? $_POST['key'] : '';
        $ObjCustommenu = new CustommenuModel();
        $reskeyExists  = $ObjCustommenu->checkMenuKeyExists($menuID, $key);
        if ($reskeyExists[0][0] == '1')
            return false;
        else
            return true;
    }
    public function ajaxcheckMenuKeyAction() {
        $menuID        = $_POST['menuID'];
        $key           = $_POST['key'];
        $ObjCustommenu = new CustommenuModel();
        $reskeyExists  = $ObjCustommenu->checkMenuKeyExists($menuID, $key);
        echo $reskeyExists[0][0];
    }
    public function ajaxSectionDetailsAction() {
        $selModID    = $_POST['selModID'];
        $sectiontype = $_POST['sectiontype'];
        $itemType    = $_POST['itemType'];
        $languageIDs = $this->ObjView->languageIDs;
        if ($itemType == 'singlepage') {
            $ObjContent             = new ContentModel();
            $languageIDs['Current'] = $_POST['selLanguages'][0];
            $result                 = $ObjContent->getContentPageDet($languageIDs, $selModID, 'yes');
        }
        if ($itemType == 'singlecategory') {
            $ObjProductCategory = new ProductCategoryModel();
            $result             = $ObjProductCategory->getProductCategoryByID($languageIDs, $selModID, 'Active', 'yes');
        }
        if ($itemType == 'singlepage') {
            if ($sectiontype == 'title') {
                echo $result['contentTitle'];
            } else if ($sectiontype == 'desc') {
                echo strip_tags(htmlspecialchars_decode($result['introText']));
            }
        } else if ($itemType == 'singlecategory') {
            if ($sectiontype == 'desc') {
                echo strip_tags(htmlspecialchars_decode($result['productCategoryDescription']));
            } else {
                echo $result['productCategoryIcon'] . '~*' . WEB_BASE_DIR . __DIR_PUBLIC . '/' . __UPLOADS_FOLDER . 'product-category/' . $result['productCategoryIcon'];
            }
        }
    }
    public function cleanCache() {
        $languageIDs      = $this->ObjView->languageIDs;
        $ObjUsergroup     = new UsergroupModel();
        $params           = array(
            'languageIDs' => $languageIDs
        );
        $resUserTypesList = $ObjUsergroup->listUsergroups($params);
        foreach ($languageIDs['All'] as $langauge) {
            $this->ObjView->setCacheDir(__CORE_PUBLIC_FRONTEND_CACHE_PATH . "/" . $langauge . '/');
            foreach ($resUserTypesList as $value) {
                $this->ObjView->clearCache(null, $value['userGroupID']);
            }
        }
    }
}
