<!--floating menu -->
<?php
if(in_array(Yii::app()->controller->action->id,array("productgroup","products")))
{
$link='';
$menuHeder='';
if(isset($_GET['product_type_id']))
{
    $link='';
    $menuHeder  = ProductType::model()->findByPK($_GET['product_type_id'])->type_name;
}
else if(isset($_GET['product_category_id']))
{
    $menuHeder  = ProductCategory::model()->findByPK($_GET['product_category_id'])->category_name;
//    $productTypes	=	ProductType::model()->findAll(array('order'=>'type_name','condition'=>'product_group_id ='.$_GET['id'].' AND category_id='.$_GET['product_category_id'].' AND user_group_id='.$_GET['user_group_id'].' AND isActive="Y" AND show_in_partner="Y"'));
//    foreach($productTypes as $i=>$eachProductType)
//    {
//            $p	=	Product::model()->with('productMapping')
//            ->together(true)
//            ->find(array(
//                             'select'=>'*, rand() as rand',
//                                    'order'=>'rand',
//                                    'condition'=>'(t.isActive="Y" AND  
//                                    t.type_id ='.$eachProductType->id.') OR
//
//                                    (t.isActive="Y" AND  
//                                    productMapping.type_id in ('.$eachProductType->id.'))
//                                    '));
//            if($p!=null)
//            {
//            $link   .=   '<a href="'.Yii::app()->createUrl('site/products',array(
//            'product_type_id'=>$eachProductType->id,
//            'id'=>$_GET['id'],
//            'product_category_id'=>$_GET['product_category_id'],
//            'user_group_id'=>$_GET['user_group_id'],
//            'name'=>preg_replace('/[^a-z0-9_]/','',strtolower( str_replace(" ", "_", $eachProductType->type_name))))).'" class="menu_item">'.$eachProductType->type_name.'</a>'; 
//            }
//    }   
}
else if(isset($_GET['id'])) //product_group_id
{
//    $menuHeder  = ProductGroup::model()->findByPK($_GET['id'])->product_group_name;
//    $productCategories	=	ProductCategory::model()->findAll(array('order'=>'category_name','condition'=>'product_group_id ='.$_GET['id'].' AND user_group_id='.$_GET['user_group_id'].' AND isActive="Y" AND show_in_partner="Y"'));
//    
//    foreach($productCategories as $i=>$eachProductCategory)
//    {
//            $p	=	Product::model()->with('productMapping')
//            ->together(true)
//            ->find(array(
//                             'select'=>'*, rand() as rand',
//                                    'order'=>'rand',
//                                    'condition'=>'( t.isActive="Y" AND  
//                                                    t.user_group_id ='.$_GET['user_group_id'].' AND 
//                                                    t.product_group_id ='.$_GET['id'].' AND 
//                                                    t.product_category_id ='.$eachProductCategory->id.'
//                                        ) OR
//
//                                    (               t.isActive="Y" AND 
//                                                    productMapping.user_group_id ='.$_GET['user_group_id'].' AND 
//                                                    productMapping.product_group_id ='.$_GET['id'].' AND 
//                                                    productMapping.category_id in ('.$eachProductCategory->id.'))
//                                    '));
//            if($p!=null)
//            {
//            $link   .=   '<a href="'.Yii::app()->createUrl('site/products',array(            
//            'product_category_id'=>$eachProductCategory->id,
//            'id'=>$_GET['id'],
//            'user_group_id'=>$_GET['user_group_id'],
//            'name'=>preg_replace('/[^a-z0-9_]/','',strtolower( str_replace(" ", "_", $eachProductCategory->category_name))))).'" class="menu_item">'.$eachProductCategory->category_name.'</a>'; 
//            }
//
//    }
}
else if(isset($_GET['user_group_id']))
{
    $menuHeder  = UserGroup::model()->findByPK($_GET['user_group_id'])->group_name;
    $productGroups	=	ProductGroup::model()->findAll(array('order'=>'product_group_name','condition'=>'user_group_id='.$_GET['user_group_id'].' AND isActive="Y" AND show_in_partner="Y"'));
    
    foreach($productGroups as $i=>$eachProductGroup)
    {
            $p	=	Product::model()->with('productMapping')
            ->together(true)
            ->find(array(
                             'select'=>'*, rand() as rand',
                                    'order'=>'rand',
                                    'condition'=>'(t.isActive="Y" AND  
                                    t.user_group_id='.$_GET['user_group_id'].' AND
                                    t.product_group_id ='.$eachProductGroup->id.') OR
                                    (t.isActive="Y" AND  
                                    productMapping.user_group_id='.$_GET['user_group_id'].' AND
                                    productMapping.product_group_id ='.$eachProductGroup->id.')'));
            if($p!=null)
            {
                $link   .=   '<a href="'.Yii::app()->createUrl('site/productgroup',array(
                'id'=>$eachProductGroup->id,
                'user_group_id'=>$_GET['user_group_id'],
                'name'=>preg_replace('/[^a-z0-9_]/','',strtolower( str_replace(" ", "_", $eachProductGroup->product_group_name))))).'" class="menu_item">'.$eachProductGroup->product_group_name.'</a>'; 
            }
    }
}
if(trim($menuHeder)!=''):
?>
<div id="fl_menu">
	<div class="label"><?php echo $menuHeder; ?></div>
	<div class="menu">
        <?php echo $link; ?>
        <a class="menu_item" href="javascript:history.back(1);"><< Back</a>
    </div>
</div>
<?php endif; 
}
?>