<?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: MenuModel.php, v 1.0 2013/03/14 17:30:11
//
class MenuModel extends Model {
    private $httpURLArr;
    var $languageIDs;
    var $selBrandID;
    private $httpImagePath;
    function __construct($params = array()) {
        parent::__construct();
        if (!empty($params)) {
			if($params[2] == 'mobile')
				$this->httpURLArr    = ((WEB_BASE_DIR != '/') ? WEB_BASE_DIR : '/') .'mobile/'. ((isset($params[1]) && $params[1] != '') ? ($params[1] . '/') : '');
            else
				$this->httpURLArr    = ((WEB_BASE_DIR != '/') ? WEB_BASE_DIR : '/') . ((isset($params[1]) && $params[1] != '') ? ($params[1] . '/') : '');
			$this->httpImagePath = $params[3]; 
            if (!empty($params[0])) {
                $this->languageIDs = $params[0];
            }
            if (!empty($params[4])) {
                $this->selBrandID = $params[4];
            }
        }
    }
    public function showMenu($params,$show=true)
	{
        
		$menuKey	=	$params['menukey'];
		$positionKey	=	isset($params['position'])?$params['position']:'';
		$ObjSession 			= Registry::getInstance('Session');
		$userSubgroupID    = ($ObjSession->getSession("REGISTERED_USER_GROUP_ID")>0)?$ObjSession->getSession("REGISTERED_USER_GROUP_ID"):'0';
		$menuActive 	= $ObjSession->getSession("ACTIVE_MENUID");
		// get currrent language	  
		$currentLanguageID	=	$this->languageIDs['Current'];
		$bgImage	=	'';
                
		// language ends
		$menuDetailsAll	=	$this->getMenu($menuKey,$positionKey,$currentLanguageID,$userSubgroupID);                
		if($menuDetailsAll){			
			foreach($menuDetailsAll as $menuDetails){
                            $menuID			=	$menuDetails['menuID'];			
                            //check for class style
                            $classvar = "";
                            if($menuDetails['cssStyle']!=''){$classvar	=	'class="'.$menuDetails['cssStyle'].'" ';}
                            if($menuDetails['showBgImage']=='Yes'){
                                            $bgImage 	=	'style="background-repeat: no-repeat;overflow:hidden;background-image:url('.$this->httpImagePath.'/public/uploads/menus/'.$menuDetails['imageName'].')"';
                                    }	
                            $linkMenuShow	=	'';
                            if($menuDetails['showTitle']=='Yes'){
                                    $linkMenuShow	=	 "<span $classvar>" ."<strong>".$menuDetails['menuName']."</strong></span>";	
                            }		//show description
                            if($menuDetails['showDesc']=='Yes'){$linkMenuShow	.=	'<p>'. $menuDetails['MenuDesc'].'</p>';}					
                            $showItemStatus	=	true;	
				
                            if($showItemStatus==true){
                                echo $linkMenuShow;		
                                $resListMenus	=	 $this->listMenuTree($currentLanguageID,$menuID,0);
                                   if(count($resListMenus)>0){
                                        echo $linkMenuShow	=	"<ul $classvar $bgImage>";                                                
                                        $this->createMenu($currentLanguageID,$params,$resListMenus,$menuActive,$userSubgroupID);
                                        echo $linkMenuShow	=	 "</ul>";	//menu end
                                    }
                                     
                            }
			} //menu details loop ends
		}//if menudetails end
	}
   
      public function createMenu($currentLanguageID, $params, $resListMenus, $menuActive, $registeredUserID = 0) {
       $target	=	'';
        $ObjSession 			= Registry::getInstance('Session');
        $catActive 		= $ObjSession->getSession("ACTIVE_CATEGORY");
	foreach ($resListMenus as $menuItem) {
            //check menu access, if menu access = all
            $menuitemparams	=	$moduleDetails	=	array();
            $imageICon	=	'';
            $listoutput	=	'';
            $activeclass='';
            $classvar	=	'';
            $urlForMenuItem	='';
            $moduleKey	=	'';
            $moduleDetails='';
            $displayhide	=	'';
            $enableSSL	=	$itemcaption	=	$classvarActive=$hrefelmnt='';
			$relval    = '';
			$relvar = '';
            $showItemStatus	=	false;
            $menuItemAccess = explode(",", $menuItem['access']);        
           if ($menuItem['access'] == '')
            {
                $showItemStatus = true;
            }       
            else if (in_array($registeredUserID, $menuItemAccess))
            {  
                    $showItemStatus = true;
            }
            if ($showItemStatus == true) {
                //check for class style
                if ($menuActive == $menuItem['keyOrderID'] ) {
                    $activeclass    = 'active';
                    $classvarActive = 'class="' . $activeclass . '" ';
                }
                $menuItemStyle = ($menuItem['cssStyle'] != '') ? $menuItem['cssStyle'] . ' ' : '';
                
                /*to assign no-child class for last items*/
                $noChild = "";
                if($menuItem['subItemCount'] == 0){
                        $noChild = "no-child";
                }

                if ($menuItemStyle != '' || $activeclass != '') {
                    $classvar = 'class="' . $menuItemStyle . (($activeclass != '') ? 'current' : '') . ' '.$noChild.'" ';
                    if (!($params['seperator'])) {
                        $classvar = 'class="' . $menuItemStyle . $activeclass . ' '.$noChild.'" ';
                    }
                }elseif($noChild != ""){
					$classvar = 'class="' .$noChild.'" ';
		}
                //target
                if ($menuItem['target'] != '') {
                    $target = 'target="' . $menuItem['target'] . '" ';
                }
                //item name
                $itemcaption    = $menuItem['menuItemName'];
                $showTitle      = $menuItem['ShowTitle'];
                //item desc
                $showDesc       = $menuItem['showDesc'];
                $menuItemDesc   = $menuItem['menuItemDesc'];
                $menuItemIcon   = $menuItem['iconName'];
                $menuIconPath   = __DIR_PUBLIC . '/' . __UPLOADS_FOLDER . 'menus/menu-items/';
                $showIcon       = $menuItem['showIcon'];
                // create link
                $hrefelmnt      = $this->httpURLArr;
                $menuitemparams = json_decode($menuItem['params'], true);
                $moduleKey      = isset($menuItem['moduleKey']) ? $menuItem['moduleKey'] : '';
				if($moduleKey=='url'){
					$relval    = 'no follow';
					$relvar = 'rel="' . $relval . '" ';
				}
				if ($menuItem['params'] != '') {
                    //check the reference
                    if ($moduleKey != 'categorylist') {
                        //required parameter settings
                        $showTitle	=	(isset($menuitemparams['showSectionName']) && $menuitemparams['showSectionName']=='Yes' && $showTitle=='Yes')?$menuitemparams['showSectionName']:$showTitle;
			$showDesc	=	$showDesc;
			$showIcon	=	(isset($menuitemparams['showSectionImage']) && $menuitemparams['showSectionImage']=='Yes' && $showIcon=='Yes')?$menuitemparams['showSectionImage']:$showIcon;					
                    }
                    //single category
                    if ($moduleKey == 'singlecategory' || $moduleKey == 'categorylist') {
                   		$subLevels         = $menuitemparams['subLevels'];
                        $maxLevel          = $subLevels > 0 ? $subLevels : 999;
                        $showEmptyCategory = isset($menuitemparams['showEmptyCat']) ? $menuitemparams['showEmptyCat'] : 'No';
                        $singleCatID       = ($subLevels != '') ? '0' : $menuitemparams['selectedID'];
                        if($subLevels!=''){
							$categoryList      = $this->listAllCategoryItems($currentLanguageID, $showEmptyCategory, $menuitemparams['selectedID'], $moduleKey, $singleCatID);
							//echo "<pre>"; print_r($categoryList);	
							$listoutput        = $this->listCategoryTreeMenu($categoryList, $menuItem, $menuitemparams, $this->httpURLArr, $activeclass, $maxLevel);
                         } 					
                    }
                } //icon for menu item
                if ($showIcon == 'Yes' && $menuItemIcon != '') {
                    $imageICon = '<img src="' . $this->httpImagePath . $menuIconPath . $menuItemIcon . '" alt="'.$itemcaption.'" />';
                }
                //create item link
                $linkMenuItem = '';
                if ($showTitle != 'Yes') {
                    $itemcaption = '';
                }
                if ($moduleKey == 'text' || $moduleKey == 'seperator') {
                    if ($imageICon == '' && $showTitle != 'Yes') {
                        $displayhide = 'style="display:none;"';
                    }
                    $linkMenuItem = "<span $classvar $displayhide> " . $imageICon . $itemcaption;
                } else {
                    if ($menuItem['iconLinkable'] == 'Yes') {
                        $itemcaption = $imageICon . $itemcaption;
                    } else {
                        $linkMenuItem = $imageICon;
                    }
                    if($moduleKey=='url'){
                                    if(strpos($menuItem['itemLink'],'{site-url}') !== false) {
						$menuItem['itemLink'] = str_replace("{site-url}",rtrim($this->site_url,'/'),$menuItem['itemLink']);
					}
                                    $urlForMenuItem = "https://" . str_replace(array("http://","https://"),"",$menuItem['itemLink']);   
                    }
                    else
                        $urlForMenuItem = $hrefelmnt . $menuItem['requestPath'];
                    if ($showTitle == 'Yes' || $imageICon != '') {
                        if ($menuItem['descLinkable'] == 'Yes' && $showDesc == 'Yes') {
                            $itemcaption .= '<br /><span style="padding:10px;">' . $menuItemDesc . "</span>";
                        }
                        $linkMenuItem .= " <a href='" . $urlForMenuItem . "' $classvarActive $target $relvar>" . $itemcaption . "</a>";
                    }
                }
                if (($moduleKey == 'singlecategory' || $moduleKey == 'categorylist')  && $menuitemparams['subLevels']!='') {
                    $linkMenuItem = '';
                }
                //show description
                if ($showDesc == 'Yes' && $menuItem['descLinkable'] != 'Yes') {
                    $linkMenuItem .= '<span>' . $menuItemDesc . '</span>';
                }
                if ($moduleKey == 'text' || $moduleKey == 'seperator') {
                    $linkMenuItem .= "</span> ";
                }
                if (($linkMenuItem != ''))
                    $linkMenuItem = (($params['seperator']) ? "<li $classvar>" : '') . $linkMenuItem;
                echo $linkMenuItem;
                if(isset($menuItem['submenu']) && count($menuItem['submenu'])>0){
                    //check for sub menu
                    if($menuItem['subItemCount']>0 ){
                            echo "<ul>";
                            $this->createMenu($currentLanguageID,$params,$menuItem['submenu'],$menuActive,$registeredUserID);
                            echo "</ul>";	
                    } 
					
		}
                if ($listoutput != '')
                    echo $listoutput;
                if (($params['seperator'] != ''))
                    echo "</li>";
            }
            //$levels++;
        } //for loop end		 	
    }
    public function listMenuTree($currentLanguageID,$menuID,$parentID=0,$menuActive=0 ,$mobileapp='',$mobileapptest='')
	{
		$objCache	= new Cache(CACHE_DRIVER); // Load Dynamic cache Library
		$ObjSession 			= Registry::getInstance('Session');
		$registeredUserID 		= $ObjSession->getSession("REGISTERED_USER_GROUP_ID");
		if($registeredUserID>0)
			$cacheUserID	=	1;
		else
			$cacheUserID	=	0;

		$currDateTime = "'".date('Y-m-d')."'" ;
		$currentlanguage_id = isset($currentLanguageID) && $currentLanguageID>0 ? $currentLanguageID : '';
		$sql 		= 	"SELECT 
				SQL_CALC_FOUND_ROWS 
				menItmOrdr.orderID,
				menItm.menuItemID,
				menItm.parentID,
				menItm.itemLink,
				menItm.target,
				menItm.access,
				menItm.params,
				iconName,
				showIcon,
				iconLinkable,
				showDesc,
				descLinkable,
				ShowTitle,
				showBreadCrumb,
				cssStyle,
				menu_item_details.menuItemName,
				menu_item_details.menuItemDesc, 
				menItmOrdr.orderID as keyOrderID,
				menItmOrdr.parentID as keyParentID,
				menItmOrdr.level as menu_item_level,
				(
					SELECT 
						COUNT(*) 
					FROM 
						" . DB_PREFIX . "menu_item_order
					WHERE 
						parentID=menItmOrdr.orderID
				) AS subItemCount,
				frnMod.moduleID,
				frnMod.moduleKey
			FROM 
					" . DB_PREFIX . "frontend_modules AS frnMod 
				INNER JOIN 
					" . DB_PREFIX . "menu_item AS menItm 
						ON	(
							menItm.moduleID=frnMod.moduleID 
							)
				INNER JOIN  
					" . DB_PREFIX . "menu_item_order AS menItmOrdr
						ON 	(
						menItmOrdr.menuItemID=menItm.menuItemID
								)						
				INNER JOIN 
					" . DB_PREFIX . "menu_item_details AS menu_item_details
						ON 	(
							menItm.menuItemID=menu_item_details.menuItemID 
							AND  
							(
								menu_item_details.languageID = '" . $currentlanguage_id . "'
								OR 
								menu_item_details.languageID = 0
							)
						) 				";
			 $sql .= " WHERE 
				1
				AND  
				frnMod.moduleStatus='Active'
				AND 
				menItm.status='Active' 				
				AND 
				menItmOrdr.status='Active'
				AND
				IF(
					menItm.publishDateFrom != '0000-00-00 00:00:00', 
					menItm.publishDateFrom <= " . $currDateTime . " 
					,1) 
				AND 
				IF( 
					menItm.publishDateTo!='0000-00-00 00:00:00', 
					menItm.publishDateTo >=" . $currDateTime . "
					,1)";
        if($this->selBrandID!='') {
            $sql .= "	AND menItm.brandID='".$this->selBrandID."' ";
        }
        if ($menuID){
            $sql .= "	AND menItmOrdr.menuID='".$menuID."' ";
		}

        if($menuActive)	
            $sql .= "AND  menItmOrdr.orderID='$menuActive'";

         $sql .= " ORDER BY menItmOrdr.order ";
        $reslistMenus =	$this->ObjDatabase->readValues($sql);
            // get request path
        $menuItemIDArr = $mainTree = $menuTree=array();
        $menuItemIDArr =  array_unique(@array_map(array($this,'filterIDs'),$reslistMenus));
        $reslistMenus  =   $this->appendSefPath($menuItemIDArr,$reslistMenus); 
        foreach ($reslistMenus as $key => $value)
        {
             if($mobileapp == 'mobileapp'){
                $param=  array();
                $urlsplit=  array();
                $urlsplit2=  array();
                $urlsplit3=  array();
                $urlsplit5=  array();
                $urlsplit4=  array();
                $paramnew =  array();
                $paramvars = array();
                $urlsplit2new=  array();
                $urlsplit3new=  array();
                $params = json_decode($reslistMenus[$key]['params']);   
                if($params->selectedID=='') {
                    $params->selectedID = $params->categories;
                }
                $reslistMenus[$key]['linkCategoryID'] = $params->selectedID;
                if($value['moduleKey'] == 'productfilterurl' ){
                    $value['itemLinkOther'] = $value['itemLink'];
                }  else {
                    $value['itemLinkOther'] = "[{\"price\":\"\",\"discount\":\"\",\"term\":\"\",\"productPref\":\"\",\"dealCatID\":\"'".$params->selectedID."'\",\"brand\":\"\",\"businessID\":\"\",\"search\":\"\"}]";
                }
                $reslistMenus[$key]['menuLink'] = json_decode($value['itemLinkOther'],true)[0];               
                
                /*if($value['parentModuleKey'] == 'Otherslabel' && $value['moduleKey'] == 'productfilterurl' ){

                   $urlsplit=explode("catalog/", $value['itemLink']);

                       $urlsplit2new=explode("/?", $urlsplit[1]);
                       if(!empty($urlsplit2new[1]))
                       $urlsplit3new=explode("&amp;", $urlsplit2new[1]);

                       $schema	= array 
                                           (
                                                   'price' => '-',
                                                   'attributes' => '--',
                                                   'attribute' => ':',
                                                   'attrOption' => '^',
                                                   'attrOptionID' => '~*'
                                           );



                           if(!empty($urlsplit3new[0])){

                               foreach ($urlsplit3new as $key2 => $arrLast) {
                                   $urlsplit4=explode("=", $arrLast);
                                   $paramvars[$urlsplit4[0]]=$urlsplit4[1];
                                   if($urlsplit4[0]!='search') {
                                       $paramnew[$urlsplit4[0]]=$urlsplit4[1];
                                   }
                               }

                                   $str = '';
                                   if (isset($paramvars['search'])) {
                                           $attrArray = explode($schema['attributes'], $paramvars['search']);
                                           //echo "<pre>";print_r($attrArray);exit;

                                           foreach ($attrArray as $attrRes) {
                                               if ($attrRes) {
                                                   //Attribute - Attribute Options
                                                   $attrName = explode($schema['attribute'], $attrRes);
                                                   //$attrName[0] => Attribute Key ; $attrName[1] => Attribute Option
                                                   if ($attrName[0]) {
                                                       $sql = "select attributeID from " . DB_PREFIX . "attributes where attributeKey='".$attrName[0]."' and attrStatus='A'";
                                                       $resAttrDet  = $this->ObjDatabase->readValue($sql);
                                                       $str = ($str=='') ? $attrName[0]."->".$resAttrDet['attributeID'].$schema['attribute'].$attrName[1]:$str.$schema['attributes'].$attrName[0]."->".$resAttrDet['attributeID'].$schema['attribute'].$attrName[1];
                                                   }
                                                   if ($attrName[1]) {

                                                       
                                                   }
                                               }
                                           }
                                           $str = 'search='.$str;
                                           //echo "<pre>";print_r($attrQueryStringArray);exit;
                                       }


                           }

                           if(!empty($paramnew)){                            
                               foreach($paramnew as $keyv=>$new) {
                                   $str = $str."&amp;".$keyv."=".$new;
                               }

                           } 

                           $str =  'catalog'.$urlsplit2new[0].'/?'.$str;


                   if(!empty($urlsplit[1]))
                   $urlsplit2=explode("/?&amp;", $urlsplit[1]);
                   if(!empty($urlsplit2[1]))
                   $urlsplit3=explode("&amp;", $urlsplit2[1]);

                   if(!empty($urlsplit2[0]))
                      $urlsplit5=explode("/", $urlsplit2[0]); 
                   if(count($urlsplit5)>1){
                           for ($index = 0; $index < count($urlsplit5);) {
                               $param[$urlsplit5[$index]]=$urlsplit5[$index+1];
                              $index = $index+2;
                           }

                       }
                   if(!empty($urlsplit3[0])){

                           foreach ($urlsplit3 as $key2 => $arrLast) {
                               $urlsplit4=explode("=", $arrLast);
                               $param[$urlsplit4[0]]=$urlsplit4[1];
                           }

                       }
               $reslistMenus[$key]['Param']=$param;
               $reslistMenus[$key]['itemLink']=$str;
               }*/
               
            } 
            $menuTree[$reslistMenus[$key]['keyParentID']][] = $reslistMenus[$key];
        } // for loop end for menu item	
        //exit;
        if(isset($menuTree[$parentID]))
        $mainTree = $this->createTree($menuTree, $menuTree[$parentID]);
        //echo "<pre>";print_r($menuTree);	exit;
        return $mainTree;
    }
    public function filterIDs($reslistMenus)
    {
	return	$reslistMenus['keyOrderID'];
    }
    public function appendSefPath($menuItemIDArr,$reslistMenus,$type = 'menu')
    {
	if ($type == 'menu') {
            $valuetype = 'menuItemID';
        } else {
            $valuetype = 'productCategoryID';
        }
        if(!empty($menuItemIDArr)){           
            $sql = " SELECT objectID,requestPath  FROM " . DB_PREFIX . "url_rewrite 
                     WHERE type = '".$type."'  AND  isSystem=1  AND
                     languageID =  '" . $this->languageIDs['Current'] . "' 
                     AND  objectID IN (" . implode(",", $menuItemIDArr) . ") ";
            $resDet = $this->ObjDatabase->getHashArray($sql,'objectID'); 
            foreach($reslistMenus as $key => $value)
            {
               if ($type != 'menu') {
               $reslistMenus[$key]['requestPath'] = isset($resDet[$value[$valuetype]]['requestPath']) ? $resDet[$value[$valuetype]]['requestPath'] : '';
               } else {
               $reslistMenus[$key]['requestPath'] = isset($resDet[$value['keyOrderID']]['requestPath'])?$resDet[$value['keyOrderID']]['requestPath']:'';
               }
            }
        }
       return $reslistMenus;
    }
    private function createTree(&$list, $parent)
    {
        $tree = array();
        if (is_array($parent))
        {
            foreach ($parent as $k => $l)
            {
                if (isset($list[$l['keyParentID']]) && isset($list[$l['keyOrderID']]))
                {
                    $l['submenu'] = $this->createTree($list, $list[$l['keyOrderID']]);
                }
                $tree[] = $l;
            }
        }
        return $tree;
    }
    public function getReferenceTableDetails($moduleDetails, $referenceIDValue, $currentLanguageID, $catList = '', $all = '') {
        $referenceTablesArr = explode(",", $moduleDetails['referenceKey']);
        if ($catList) {
            $referenceTable    = $referenceTablesArr[1];
            $referenceTableDet = $referenceTablesArr[2];
        } else {
            $referenceTable    = $referenceTablesArr[0];
            $referenceTableDet = $referenceTablesArr[1];
        }
        $sql = "SELECT 
									* 
								FROM 
									" . DB_PREFIX . $referenceTable . " as table1 
								JOIN 
									" . DB_PREFIX . $referenceTableDet . "  as table2 
								ON 
									table1." . $moduleDetails['referenceIDField'] . "= table2." . $moduleDetails['referenceIDField'] . "
								WHERE 1 ";
        if (!$all) {
            if ($catList)
                $sql .= " AND productTypeStatus='" . $moduleDetails['referenceValue'] . "' ";
            else
                $sql .= " AND " . $moduleDetails['referenceField'] . "='" . $moduleDetails['referenceValue'] . "' ";
        }
        $sql .= " AND table1." . $moduleDetails['referenceIDField'] . "='" . $referenceIDValue . "' 
								AND table2." . $moduleDetails['referenceIDField'] . "='" . $referenceIDValue . "' 
								AND   (table2.languageID = " . $currentLanguageID . " OR  table2.languageID =0) ";
        $sql .= " LIMIT 1";
        $resDet = $this->ObjDatabase->readValue($sql); //echo $sql;
        return $resDet;
    }
    // menu detail;s from menukey
    public function getMenu($menuKey = '', $positionkey = '', $currentLanguageID, $userSubgroupID = '') {
        $currDateTime = "'" . date('Y-m-d') . "'";
        $sql          = "SELECT 
							 menu.*,
                                        menDet.menuName,
                                        menDet.MenuDesc
		 				FROM " . DB_PREFIX . "menu as menu
						JOIN " . DB_PREFIX . "menu_details AS menDet
                                        ON (menu.menuID=menDet.menuID 
										AND menDet.languageID = " . $currentLanguageID . " )";
        if ($positionkey != '')
            $sql .= " LEFT JOIN " . DB_PREFIX . "menu_positions AS menu_positions
                                        ON (menu.positionID=menu_positions.positionID)";
        $sql .= " WHERE                                        
                                        IF(menu.publishFrom != '0000-00-00 00:00:00', 
                                        menu.publishFrom <= " . $currDateTime . " 
                                        ,1) 
                                        AND 
                                        IF( menu.publishTo!='0000-00-00 00:00:00', 
                                         menu.publishTo >=" . $currDateTime . ",1) 										
                                        AND menu.status='Active' ";
        if ($menuKey != '')
            $sql .= "AND menu.menuKey='" . $menuKey . "' ";
        if ($positionkey != '')
            $sql .= "AND menu_positions.positionKey='" . $positionkey . "' ";
        if ($userSubgroupID != '' || $userSubgroupID == 0) {
            $sql .= " AND (FIND_IN_SET('" . $userSubgroupID . "',access) 
													OR  access='' OR access IS NULL)";
        } else {
            $sql .= " AND (access='0' OR access='' OR  access IS NULL)";
        }        
        $reslistMenus = $this->ObjDatabase->readValuesSlave($sql, MYSQLI_ASSOC);
        return $reslistMenus;
    }
    public function getActiveParentCategories($catKey, $breadcrumb = '', $currentLanguageID = '') {
        $parentactiveIds = $parentCatArr = array();
        $sqlJoin         = $sqlSelect = '';
        if ($breadcrumb != '') {
            $sqlJoin   = " JOIN 
                                                        " . DB_PREFIX . "product_category_details as dcd 
                                                        ON (dcd.productCategoryID=dc.productCategoryID
                                                         AND dcd.languageID=" . $currentLanguageID . ")";
            $sqlSelect = ",dcd.productCategoryName,dc.productCategoryKey";
        }
        $sql = "SELECT 
                                            (SELECT productCategoryKey 
                                                    FROM 
                                                            " . DB_PREFIX . "product_categories 
                                                    WHERE 
                                                            productCategoryID=dc.productCategoryParent ) AS parentKey,
                                                    (SELECT 
                                                            count(*) 
                                                    FROM 
                                                            " . DB_PREFIX . "product_categories 
                                                    WHERE 
                                                            productCategoryID=dc.productCategoryParent ) AS parentCount 
                                             " . $sqlSelect . "
                                             ,urlRew.requestPath
                                            FROM 
                                             " . DB_PREFIX . "product_categories    AS dc
                                                 JOIN 
                                           " . DB_PREFIX . "url_rewrite  AS urlRew
                                            ON (
                                            urlRew.objectID = dc.productCategoryID
                                            AND
                                            urlRew.type = 'catalog'                                           
                                            AND
                                            isSystem=1
                                            AND
                                            urlRew.languageID =  '" . $currentLanguageID . "' 
                                            )
                                            ";
        $sql .= $sqlJoin;
        $sql .= " WHERE 1 AND dc.productCategoryKey='" . $catKey . "' 
									AND dc.productCategoryStatus='Active' ";
        $sql .= " ORDER BY dc.productCategorySortOrder ";
        $resParentItems = $this->ObjDatabase->readValues($sql);
        foreach ($resParentItems as $parents) {
            if ($breadcrumb != '') {
                $parentactiveIds[$parents['productCategoryKey']] = $parents['productCategoryName'];
            } else {
                $parentactiveIds[] = $parents['parentKey'];
            }
            if ($parents['parentCount'] > 0) {
                $parentactiveId = $this->getActiveParentCategories($parents['parentKey']);
                foreach ($parentactiveId as $key => $id) {
                    $parentactiveIds[$key] = $id;
                }
            }
        }
        return $parentactiveIds;
    }
    public function listCategoryTreeMenu($categoryList, $menuItem, $menuitemparams, $httpURL, $activeclass, $maxLevel, $level = 1) {
        $imageICon = $classvar = $classvarActive = '';
        $hrefelmnt = $httpURL;
        //check for class style
        if ($menuItem['cssStyle'] != '')
            $classvar = 'class="' . $menuItem['cssStyle'] . '" ';
        $target = '';
        if ($menuItem['target'] != '')
            $target = 'target="' . $menuItem['target'] . '" ';
        $showDesc     = (isset($menuitemparams['showSectionDesc']) && $menuitemparams['showSectionDesc'] == 'Yes') ? $menuitemparams['showSectionDesc'] : $menuItem['showDesc'];
        $menuItemIcon = $menuItem['iconName'];
        $menuIconPath = __DIR_PUBLIC . '/' . __UPLOADS_FOLDER . 'menus/menu-items/';
        $showIcon     = $menuItem['showIcon'];
        if (count($categoryList) > 0) {
            $output = "<ul>";
            foreach ($categoryList as $category) {
                $i            = $level; //icon for menu item
                $levels       = '';
                $imageICon    = '';
                $menuItemIcon = '';
                if (isset($menuitemparams['showSectionImage']) && $menuitemparams['showSectionImage'] == 'Yes' && trim($category['productCategoryImage']) != '') {
                    $menuIconPath = __DIR_PUBLIC . '/' . __UPLOADS_FOLDER . 'product-category/';
                    $menuItemIcon = trim($category['productCategoryImage']);
                }
                if ($showIcon == 'Yes' && $menuItemIcon != '') {
                    $imageICon = '<img src="' . $this->httpImagePath . $menuIconPath . $menuItemIcon . '" alt="'.$itemcaption.'"/>';
                }
                //create item link
                for ($j = 1; $j <= $level; $j++) {
                    $levels .= '&raquo;&nbsp;&nbsp;';
                }
                $linkMenuItem = '';
                $itemcaption  = $category['productCategoryName'];
                $menuItemDesc = $category['productCategoryDescription'];
                if ($menuItem['iconLinkable'] == 'Yes') {
                    $itemcaption = $imageICon . $itemcaption;
                } else {
                    $linkMenuItem .= $imageICon;
                }
                if ($activeclass != '') {
                    $classvarActive = 'class="active" ';
                }
                $itemLink = $category['requestPath'];
                $linkMenuItem .= " <a href='" . $hrefelmnt . $itemLink . "' $classvarActive $target>" . $itemcaption;
                //show description
                if ($menuItemDesc) {
                    if ($menuItem['descLinkable'] == 'Yes' && $showDesc == 'Yes') {
                        $linkMenuItem .= '<br /><span>' . $menuItemDesc . '</span></a>';
                    } else if ($showDesc == 'Yes') {
                        $linkMenuItem .= '</a><br /><span>' . $menuItemDesc . '</span>';
                    } else {
                        $linkMenuItem .= '</a>';
                    }
                } else {
                    $linkMenuItem .= '</a>';
                }
                // check the item seperator
                if ($linkMenuItem != '')
                    $linkMenuItem = "<li $classvar>" . $levels . $linkMenuItem;
                // registered user only			
                $output .= $linkMenuItem;
                if ($category['subCount'] > 0 && $i <= $maxLevel) {
                    $i++;
                    if (isset($category['subCategories'])) {
                        $subCategoryList = $category['subCategories'];
                        $output .= $this->listCategoryTreeMenu($subCategoryList, $menuItem, $menuitemparams, $httpURL, $activeclass, $maxLevel, $i);
                    }
                }
                $output .= "</li>";
            } //for ends			
            $output .= "</ul>";
        } //if count ends
        return $output;
    }
    public function getParentOfOrder($order, $mod = '') {
        $join = "";
        if ($mod != '') {
            $join = "JOIN  " . DB_PREFIX . "frontend_modules AS frnMod 
                        ON
                       (menItm.moduleID=frnMod.moduleID AND  frnMod.moduleStatus='Active')";
        }
        $sql         = "SELECT 
						menItmOrdr.parentID,menItmOrdr.menuID,
						menItm.params,menItm.moduleID ,
                                                menItm.relatedMenuLevel,
                                                menItm.showBreadCrumb
					 FROM 
					 	" . DB_PREFIX . "menu_item_order  AS menItmOrdr
					LEFT JOIN
						`" . DB_PREFIX . "menu_item` AS menItm 
							ON menItm.menuItemID=menItmOrdr.menuItemID
                                                        " . $join . "
					WHERE menItmOrdr.orderID='$order' 
                    LIMIT 1";
        $resParentID = $this->ObjDatabase->readValueSlave($sql);
        return $resParentID;
    }
    public function getPageMenuItemStatus($mkey, $languageIDs, $userSubgroupID = '') {
        $sql = "SELECT
							menItm.menuItemID,
							menItm.showBreadCrumb
							FROM 
							" . DB_PREFIX . "menu_item AS menItm
							JOIN " . DB_PREFIX . "menu_item_order AS menItmOrdr 
								ON 
								(menItmOrdr.menuItemID=menItm.menuItemID 
								AND menItmOrdr.orderID='$mkey')							
							JOIN " . DB_PREFIX . "menu AS menu 
								ON menu.menuID=menItmOrdr.menuID                                                      
							WHERE 1
							AND menItmOrdr.status='Active' 
							AND menItm.status='Active'
                                                        AND menu.status='Active'";
        if ($userSubgroupID != '' || $userSubgroupID == 0) {
            $sql .= " AND (FIND_IN_SET('" . $userSubgroupID . "',menItm.access) 
													OR  menItm.access='' OR menItm.access IS NULL)";
            $sql .= " AND (FIND_IN_SET('" . $userSubgroupID . "',menu.access) 
													OR  menu.access='' OR menu.access IS NULL)";
        } else {
            $sql .= " AND (menItm.access='0' OR menItm.access='' OR  menItm.access IS NULL)";
            $sql .= " AND (menu.access='0' OR menu.access='' OR  menu.access IS NULL)";
        }
        
        $currDateTime = "'" . date('Y-m-d') . "'";
        $sql .= " AND   IF(menItm.publishDateFrom != '0000-00-00 00:00:00', 
                                        menItm.publishDateFrom <= " . $currDateTime . " 
                                        ,1) 
                                        AND 
                                        IF( menItm.publishDateTo!='0000-00-00 00:00:00', 
                                         menItm.publishDateTo >=" . $currDateTime . ",1) 	";
        $sql .= "       LIMIT 1";
        $resItem = $this->ObjDatabase->readValueSlave($sql);
        return $resItem;
    }
    //added by sariya on 7/2/13
    public function listAllCategoryItems($currentLanguageID, $showEmptyCategory = '', $rootID = 0, $moduleKey = '', $singleCatID = '0') {
        if (($moduleKey == 'singlecategory' && $showEmptyCategory == 'Yes') || $singleCatID > 0) {
            $join = " " . DB_PREFIX . "product_categories AS productCat ";
        } else {
            $join = DB_PREFIX . "products AS products  
								INNER JOIN " . DB_PREFIX . "product_to_category   AS productToCat 
									ON (products.productID=productToCat.productID)    
								INNER JOIN " . DB_PREFIX . "product_categories    AS productCat 
									ON (productCat.productCategoryID=productToCat.productCategoryID) ";
        }
        $sql = "SELECT  productCatdet.productCategoryName,
							 productCatdet.productCategoryDescription,
							 productCat.productCategoryIcon AS productCategoryImage,
							 productCat.productCategoryParent ,
							 productCat.productCategoryKey,
							 productCat.productCategoryID,
							 productCat.categoryLevel,
							 (SELECT count(*) FROM " . DB_PREFIX . "product_categories 
								 WHERE productCategoryParent=productCat.productCategoryID) 
							AS subCount";
        $sql .= " FROM   " . $join . " JOIN " . DB_PREFIX . "product_category_details AS productCatdet 
						ON (productCatdet.productCategoryID=productCat.productCategoryID 
			AND  productCatdet.languageID=" . $currentLanguageID . ")  
                                            WHERE";
        if (($moduleKey != 'singlecategory' || $showEmptyCategory == 'No') && $singleCatID == '0') {
            $sql .= "	products.productStatus='Active' AND ";
        }
        $sql .= " productCat.productCategoryStatus = 'Active'    ";
        if ($singleCatID > 0 && $moduleKey == 'singlecategory') {
             $sql .= " GROUP BY productCat.productCategoryID "; 
            $sql .= " AND productCat.productCategoryID='" . $singleCatID . "' ";
        } else {
           $sql .= " GROUP BY productCat.productCategoryID "; 
            $sql .= " ORDER BY productCat.productCategorySortOrder ASC";
        }
        $resCategories = $this->ObjDatabase->readValues($sql);
        $catIDArr      = array();
        $catIDArr      = array_unique(@array_map(array(
            $this,
            'filtercatIDs'
        ), $resCategories));
        $resCategories = $this->appendSefPath($catIDArr, $resCategories, 'catalog');
        if ($singleCatID > 0) {
            return $resCategories;
        }
        foreach ($resCategories as $key => $value) {
            $menuTree[$resCategories[$key]['productCategoryParent']][] = $resCategories[$key];
        } // for loop end for menu item			
        $mainTree = $this->createCatTree($menuTree, $menuTree[0]);
        //echo "<pre>";print_r($mainTree);
        if ($rootID > 0 && ($moduleKey == 'singlecategory'))
            $resultArr[] = $this->getSubCatmenu($mainTree, $rootID);
        else
            return $mainTree;
        //  echo "<pre>";print_r($resultArr);
        return $resultArr;
    }
    public function filtercatIDs($resCategories) {
        return $resCategories['productCategoryID'];
    }
    private function getSubCatmenu($menuArr, $rootID) {
        $parra = array();
        $parra = $this->loopArr($menuArr, $rootID);
        if (isset($parra[0]))
            return $parra[0];
    }
    private function loopArr($arr, $level) {
        $result = array();
        foreach ($arr as $key => $array) {
            if ($level == $key) {
                $result[] = $array;
                break;
            } else if ($array['subCount'] > 0 && isset($array['subCategories'])) {
                $results = $this->loopArr($array['subCategories'], $level);
            }
            if (isset($results))
                foreach ($results as $row) {
                    if (!empty($row))
                        $result[] = $row;
                }
        }
        return $result;
    }
    private function createCatTree(&$list, $parent) {
        $tree = array();
        if (is_array($parent)) {
            foreach ($parent as $k => $l) {
                if (isset($list[$l['productCategoryParent']]) && isset($list[$l['productCategoryID']])) {
                    $l['subCategories'] = $this->createCatTree($list, $list[$l['productCategoryID']]);
                }
                $tree[$l['productCategoryID']] = $l;
            }
        }
        return $tree;
    }
    //Set Admin menu
    public function setAdminMenu($params) {
        extract($params);
        $treeString = "";
        $treeLevel  = 0;
        //print_r($privilegeData);
        //MENU SCHEMA
        include_once(__CORE_PUBLIC_SCHEMA_PATH . '/menu.php');
        $params = array(
            'schemaData' => $schemaMenu,
            'treeString' => $treeString,
            'treeLevel' => $treeLevel,
            'languageXml' => $languageXml,
            'campignEnable' => $campignEnable,
            'userTypeID' => $userTypeID,
            'manageUserID' => $manageUserID,
            '_url_path' => $_url_path,
            'privilegeData' => $privilegeData
        );
        return $this->setAdminMenuItems($params);
    }
    //Set menu Items
    private function setAdminMenuItems($params) {
        extract($params);
        //last sublevel menu if its parent is in  root
        static $lastMenuItem;
        //Normal limit is 10 including parent,if subcount greater 9,$newBlkLmt=$resSubMenuCount+$blockLimit;
        static $blockLimit;
        //For inner tree level ul li closing
        static $flag;
        //last sublevel menu if its paren having subcount greater 9
        static $endCurrentBlk;
        //If root parent having  one tree level,list sublevels in single block 
        static $singleBlockMenu;
        //blk limit exceeds default block length   
        static $maxBlkLimit = '';
        if ($treeLevel == 0) {
            $treeString = '<ul class="main_menu">';
        } else {
            $treeString = '<ul class="submenu-list">';
        }
        $treeLevel++;
        if (!empty($schemaData)) {
            foreach ($schemaData as $schema) {
                //print_r($schema);	
                $currMenuURL               = $schema['adminModuleURLKey'];
                $currAdminModuleStyleClass = $schema['adminModuleStyleClass'];
                $currAdminModuleLabel      = $schema['adminModuleLabel'];
                $currRootLevel             = isset($schema['rootLevel']) ? $schema['rootLevel'] : '';
                $currAdminSectionKey       = $schema['adminSectionKey'];
                $adminModuleStatus         = $schema['adminModuleStatus'];
                $xmlLabel                  = $languageXml[$currAdminModuleLabel];
                $currAdminModuleCaption    = ($xmlLabel != '') ? $xmlLabel : $currAdminModuleLabel;
                $resSubMenuCount           = isset($schema['adminSubMenu']) ? count($schema['adminSubMenu']) : 0;
                //Exceptions For Main Admin
                if ($campignEnable != '' && $currMenuURL == 'emailqueue/index/') {
                    continue;
                }
                //Checking Addon Module
                if ($currAdminSectionKey != '' && !constant($currAdminSectionKey)) {
                    continue;
                }
                //Checking Status
                if ($adminModuleStatus != 'Active') {
                    continue;
                }
                //For Privilege Starts
                if ($resSubMenuCount == 0 && !empty($privilegeData)) {
                    //Checking Privilege Data. If no Privilege, skip current menu formation
                    if ($currMenuURL != "" && $currMenuURL != "index/" && !in_array($currMenuURL, $privilegeData)) {
                        continue;
                    }
                }
                //For Privilege ends
                if ($currMenuURL != "" && $currMenuURL != "#" && $resSubMenuCount < 1 || $currRootLevel == "Yes") {
                    $currMenuURL = $_url_path . ltrim($currMenuURL, "/");
                    if ($currRootLevel == "Yes") {
                        $currAdminModuleStyleClassLi = ' style="visibility:hidden;" class="menudrop ' . $currAdminModuleStyleClass . '"';
                        $currAdminModuleStyleClass   = 'menu_a';
                    }
                    $currMenuURL = '<a href="' . $currMenuURL . '" class="' . $currAdminModuleStyleClass . '" >';
                    $closeUrl    = '</a>';
                } else {
                    $currMenuURL = '<h6>';
                    $closeUrl    = '</h6>';
                }
                // if submenu count from 2nd tree level of a menu grater than 9,then thats sublevels also comes under same bloack
                if ($resSubMenuCount >= 10 && $treeLevel > 1 && $endCurrentBlk == '') {
                    $endCurrentBlk = isset($schema[count($schema) - 1]) ? $schema[count($schema) - 1] : '';
                    ;
                }
                //Normal limit is 10 including parent,if subcount greater 9,$newBlkLmt=$resSubMenuCount+$blockLimit;
                if ($blockLimit != 0) {
                    $blockLimit = $blockLimit + 1;
                    $newBlkLmt  = $resSubMenuCount + $blockLimit;
                    // $blockLimit!=2 :for avoiding blank block when subcount >9 
                    if (($newBlkLmt > $maxBlkLimit) && $blockLimit != 2 && $currRootLevel != "Yes" && $endCurrentBlk == '' && $singleBlockMenu != 0 && $treeLevel == 2) {
                        if ($blockLimit > 11 && $blockLimit > $maxBlkLimit) {
                            $maxBlkLimit = $blockLimit - 2;
                        }
                        $treeString .= '</ul>
														</div>
														<div  class="nav-block">
													<ul>';
                        $blockLimit = 1;
                    }
                }
                if ($schema == $endCurrentBlk) {
                    $endCurrentBlk = '';
                }
                if ($currRootLevel == "Yes") {
                    $flag = '';
                }
                $currAdminModuleStyleClassLi = isset($currAdminModuleStyleClassLi) ? $currAdminModuleStyleClassLi : '';
                $treeString .= '<li' . $currAdminModuleStyleClassLi . '>';
                $treeString .= $currMenuURL;
                $treeString .= '' . $currAdminModuleCaption . '';
                $treeString .= $closeUrl;
                //echo $treeString;
                if ($currRootLevel == "Yes" && $resSubMenuCount > 0) {
                    $maxBlkLimit     = 10;
                    $lastMenuItem    = isset($schema[count($schema) - 1]) ? $schema[count($schema) - 1] : '';
                    //If root parent having  one tree level,list sublevels in single block 
                    $singleBlockMenu = 1;
                    if (isset($schema['singleLevel']) && ($schema['singleLevel'] == "Yes")) {
                        $singleBlockMenu = 0;
                    }
                    $style = isset($style) ? $style : '';
                    $treeString .= '<div  class="navigation-block ' . $style . ' "><div  class="nav-block">';
                    $blockLimit = 1;
                }
                if ($resSubMenuCount > 0) {
                    $params = array(
                        'schemaData' => $schema['adminSubMenu'],
                        'treeString' => $treeString,
                        'treeLevel' => $treeLevel,
                        'languageXml' => $languageXml,
                        'campignEnable' => $campignEnable,
                        'userTypeID' => $userTypeID,
                        'manageUserID' => $manageUserID,
                        '_url_path' => $_url_path,
                        'blockLimit' => $blockLimit,
                        'lastMenuItem' => $lastMenuItem,
                        'endCurrentBlk' => $endCurrentBlk,
                        'singleBlockMenu' => $singleBlockMenu,
                        'flag' => $flag,
                        'maxBlkLimit' => $maxBlkLimit,
                        'privilegeData' => $privilegeData
                    );
                    $treeString .= $this->setAdminMenuItems($params);
                }
                if ($flag != 1) {
                    $treeString .= '</li>';
                }
                //echo $treeString;
            }
            //echo $treeString;	
        }
        if ($flag != 1) {
            $treeString .= '</ul>';
        }
        if ($lastMenuItem == $schema) {
            for ($k = 2; $k < $treeLevel; $k++) {
                $flag = 1;
                $treeString .= ' </li></ul>';
            }
            $treeString .= ' </div></div>';
        }
        return $treeString;
    }
     //Set breadcrumb according to menus
	public function createMenuBreadCrumb($params) {
		extract($params);
		$breadCrumb = array();$fields=array();$tables=array();$moreTable = '';
		$menuLevel++;
		for($level=1; $level<=$menuLevel; $level++){
			array_push($fields,"
							menIteOrd_".($menuLevel-($level-1)).".menuItemID AS menuItemID_".$level.",
							menIteOrd_".($menuLevel-($level-1)).".status AS status_".$level.",
							menIteOrd_".($menuLevel-($level-1)).".orderID AS orderID_".$level.",
							menIteDet_".($menuLevel-($level-1)).".menuItemName AS menuItemName_".$level.",
							menIte_".($menuLevel-($level-1)).".moduleID AS moduleID_".$level.",	
							menIte_".($menuLevel-($level-1)).".access AS access_".$level.",
							menIte_".($menuLevel-($level-1)).".status AS menIteStatus_".$level.",
							".$level." AS level_".$level."
					");
			
			if($level > 1){
				$moreTable="
						ON (
							menIteOrd_".($level-1).".parentID =menIteOrd_".$level.".orderID
						)";
			}
			array_push($tables, "".DB_PREFIX."menu_item_order AS menIteOrd_".$level."
								".$moreTable."
								INNER JOIN 
									".DB_PREFIX."menu_item_details AS menIteDet_".$level."
									ON	(
										menIteOrd_".$level.".menuItemID =menIteDet_".$level.".menuItemID 
										AND 
										(menIteDet_".$level.".languageID='".$language_ids['Current']."'
										OR  menIteDet_".$level.".languageID='0')
									)
								INNER JOIN 
									".DB_PREFIX."menu_item AS menIte_".$level."
									ON	(
										menIteOrd_".$level.".menuItemID =menIte_".$level.".menuItemID		
									)		
						");
			
		}
		if(!empty($tables)){
			$sql="	
				SELECT 
					".implode(",",$fields)."
				FROM 
					".implode(' INNER JOIN ',$tables)."
				WHERE 
					menIteOrd_1.orderID      = '".$orderID."'
					LIMIT 1"; 
			//echo $sql.'<br>';
			//menIte_1.showBreadCrumb,
			$result	= $this->ObjDatabase->readValue($sql);
			for($i=0; $i<$menuLevel*7; $i=$i+8){
				$breadCrumb[]=array(
					"menuItemID"	=> $result[$i],
					"status"  		=> $result[$i+1],
					"orderID"  		=> $result[$i+2],
					"menuItemName"  => $result[$i+3],
					"moduleID"  	=> $result[$i+4],
					"access"  		=> $result[$i+5],
					"menIteStatus"  => $result[$i+6],
					"level"			=> $result[$i+7]
				);
			}
			return $breadCrumb;
		}
		else{
			return array();
		}	
		
	}
        //Get current MenuItem Details.
	public function getMenuItemDetails($params) {
		extract($params);
		$sql = "SELECT 
				  menIteOrd.level,
				  menIte.showBreadCrumb,
				  menIteDet.metaTitle,
				  menIteDet.metaDescription,
				  menIteDet.menuItemName
				FROM 
				  " . DB_PREFIX . "menu_item_order AS menIteOrd 
				  INNER JOIN " . DB_PREFIX . "menu_item AS menIte ON (
					menIte.menuItemID = menIteOrd.menuItemID
				  ) 
				  INNER JOIN " . DB_PREFIX . "menu_item_details AS menIteDet ON (
					menIte.menuItemID = menIteDet.menuItemID 
					AND (languageID = " . $language_ids['Current'] . " OR languageID = 0)
				  ) 
				WHERE 
				  menIteOrd .`orderID` 	      = " . (int)$orderID . "
				  AND 
				  menIte .`brandID` 	      = " . (int)$brandID . "				  
				  LIMIT 1";
				 // echo $sql.'<br>';
		return $this->ObjDatabase->readValueSlave($sql);
	}
        //Get moduleIDs to be ignored in breadcrumb
	public function skipModuleKeys() {
		$sql = "SELECT 
				   	moduleID
				FROM 
				  " . DB_PREFIX . "frontend_modules 
				  WHERE  
				  moduleKey IN ('url','text')";
		return $this->ObjDatabase->getFieldsSlave($sql);
	}
        public function showMenuMobileapp($params) {
            $menuKey           = $params['menukey'];
            $positionKey       = isset($params['position']) ? $params['position'] : '';
            $checkParentActive = array();
            $ObjSession        = Registry::getInstance('Session');
            $userSubgroupID    = ($ObjSession->getSession("REGISTERED_USER_GROUP_ID") > 0) ? $ObjSession->getSession("REGISTERED_USER_GROUP_ID") : '0';
            $menuActive        = $ObjSession->getSession("ACTIVE_MENUID");
            if ($menuActive)
                $checkParentActive = $this->checkParentActive($menuActive);
            // get currrent language
            if(empty($params['currentLanguageID'])){
             $currentLanguageID = $this->languageIDs['Current'];   
            }else{
                $currentLanguageID = $params['currentLanguageID'];
            }

            $bgImage           = $classvar = '';
            // language ends
            $menuDetailsAll    = $this->getMenu($menuKey, $positionKey, $currentLanguageID, $userSubgroupID);
            if ($menuDetailsAll) {
                foreach ($menuDetailsAll as $menuDetails) {

                    //$showSubItems = $menuDetails['showSubItems'];
                    //if ($showSubItems == 'Yes') {
                        $noOfSubLevelsMenu = ($menuDetails['numOfLevels'] > 0) ? $menuDetails['numOfLevels'] + 1 : 0;                        
                        $resListMenus      = $this->listMenuTree($currentLanguageID, $menuDetails['menuID'], 0, 0,$params['mobileapp'],$params['mobileapptest']);

                    //} //if end for $showSubItems
                } //menu details loop ends
            } //if menudetails end

            return  $resListMenus;
    }
    public function checkParentActive($activeID) {
        $sql = "SELECT 
						menItmOrdr.parentID,
						(SELECT orderID 
							FROM " . DB_PREFIX . "menu_item_order 
						WHERE orderID=menItmOrdr.parentID ) AS activeID,
						(SELECT count(*) 
							FROM " . DB_PREFIX . "menu_item_order 
						WHERE orderID=menItmOrdr.parentID ) AS parentCount
					FROM " . DB_PREFIX . "menu_item as menItm";
        $sql .= " LEFT JOIN " . DB_PREFIX . "menu_item_order as menItmOrdr 
						ON (menItmOrdr.menuItemID=menItm.menuItemID)";
        $sql .= " WHERE 1 AND menItmOrdr.orderID='$activeID' AND menItm.status='Active' ";
        $sql .= " ORDER BY menItm.itemOrder 
                    LIMIT 1";
        $resParentItems    = $this->ObjDatabase->readValueSlave($sql);
        $parentactiveIds[] = $resParentItems['parentID'];
        if ($resParentItems['parentCount'] > 0) {
            $parentactiveId = $this->checkParentActive($resParentItems['activeID']);
            foreach ($parentactiveId as $id)
                $parentactiveIds[] = $id;
        }
        return $parentactiveIds;
    }
}