<?php
if (!defined('IN_CONTEXT')) die('access violation error!');

class ModCategoryP extends Module {
    protected $_filters = array(
        'check_login' => '{category_p_menu}'
    );
    
    public function category_p_menu() {
    	$curr_locale = trim(SessionHolder::get('_LOCALE', DEFAULT_LOCALE));
        $user_role = trim(SessionHolder::get('user/s_role', '{guest}'));
        
        // 28/4/2010 Add >>
        $type_a = ParamHolder::get('product_category_list', '');
        $extra = '';
        $arr1 = $arr2 = $arr3 = array();
        if ( !empty($type_a) ) {
        	// 一级菜单列表
	        $menu_no1 = array();
	        $menu_no1 = & ProductCategory::getCategoryArray();
	        
	        $arr1 = array_keys( $menu_no1 );
	        $arr2 = explode( ',', $type_a.',0' ); // 包含"最上层"菜单
	        $arr3 = array_diff( $arr1, $arr2 );
	        
	        if( sizeof($arr3) )
	        $extra = 'AND `id` NOT IN('.join( ',', $arr3 ).')';
        }
        // 28/4/2010 Add <<
        
        if ($user_role == '{admin}') {
        	$all_categories =& ProductCategory::listCategories(0, 
				"published='1' ".$extra." AND s_locale=?", array($curr_locale));
        } else {
        	$all_categories =& ProductCategory::listCategories(0, 
				"published='1' ".$extra." AND  for_roles LIKE ? AND s_locale=?", 
				array('%'.$user_role.'%', $curr_locale));
        }
        $this->assign('categories', $all_categories);
    }
}
?>