예제 #1
0
    /**
     * Draws side block with categories links
     * 		@param $draw
     **/
    public static function DrawSideBlock($draw = true)
    {
        global $objLogin;
        $listings_count_field = !$objLogin->IsLoggedIn() ? 'listings_count_public' : 'listings_count';
        $lang = Application::Get('lang');
        ob_start();
        $sql = 'SELECT ' . TABLE_CATEGORIES . '.id,
					' . TABLE_CATEGORIES . '.icon,
					' . TABLE_CATEGORIES . '.listings_count,
					' . TABLE_CATEGORIES . '.listings_count_public,
					' . TABLE_CATEGORIES . '.priority_order,
					' . TABLE_CATEGORIES_DESCRIPTION . '.language_id,
					' . TABLE_CATEGORIES_DESCRIPTION . '.name,									
					' . TABLE_CATEGORIES_DESCRIPTION . '.description
				FROM ' . TABLE_CATEGORIES . '
					LEFT OUTER JOIN ' . TABLE_CATEGORIES_DESCRIPTION . ' ON ' . TABLE_CATEGORIES . '.id = ' . TABLE_CATEGORIES_DESCRIPTION . '.category_id
				WHERE
					' . TABLE_CATEGORIES . '.parent_id = _CID_ AND
					' . TABLE_CATEGORIES_DESCRIPTION . '.language_id = \'' . $lang . '\'
				ORDER BY ' . TABLE_CATEGORIES . '.priority_order ASC';
        $sql_1 = str_replace('_CID_', '0', $sql);
        $result = database_query($sql_1, DATA_AND_ROWS, ALL_ROWS, FETCH_ASSOC);
        draw_block_top(_CATEGORIES);
        ## +---------------------------------------------------------------------------+
        ## | 1. Creating & Calling:                                                    |
        ## +---------------------------------------------------------------------------+
        ## *** define a relative (virtual) path to treemenu.class.php file
        define('TREEMENU_DIR', 'modules/treemenu/');
        /* Ex.: 'treemenu/' */
        ## *** include TreeMenu class
        require_once TREEMENU_DIR . 'treemenu.class.php';
        ## *** create TreeMenu object
        $treeMenu = new TreeMenu();
        $treeMenu->SetDirection(Application::Get('lang_dir'));
        ## +---------------------------------------------------------------------------+
        ## | 2. General Settings:                                                      |
        ## +---------------------------------------------------------------------------+
        ## *** set unique numeric (integer-valued) identifier for TreeMenu
        ## *** (if you want to use several independently configured TreeMenu objects on single page)
        $treeMenu->SetId(1);
        ## *** set style for TreeMenu
        $treeMenu->SetStyle('vista');
        ## *** set TreeMenu caption
        //$treeMenu->SetCaption('ApPHP TreeMenu v'.$treeMenu->Version());
        ## *** show debug info - false|true
        $treeMenu->Debug(false);
        ## *** specifies whether to show node(folder) icons
        $treeMenu->UseDefaultFolderIcons(false);
        ## *** set postback method: 'get', 'post' or 'ajax'
        $treeMenu->SetPostBackMethod('post');
        ## *** set variables that used to get access to the page (like: my_page.php?act=34&id=56 etc.)
        /// $treeMenu->SetHttpVars(array('id'));
        ## *** show number of subnodes to the left of every node - false|true
        $treeMenu->ShowNumSubNodes(false);
        ## +---------------------------------------------------------------------------+
        ## | 3. Adding nodes:                                                          |
        ## +---------------------------------------------------------------------------+
        ## *** add nodes
        ## arguments:
        ## arg #1 - node's caption
        ## arg #2 - file associated with this node (optional)
        ## arg #3 - icon associated with this node (optional)
        ## Example: $treeMenu->AddNode('Title', 'text.txt', 'icon.gif');
        $node = array();
        for ($i = 0; $i < $result[1]; $i++) {
            $node = $treeMenu->AddNode($result[0][$i]['name'] . ' (' . $result[0][$i][$listings_count_field] . ')', prepare_link('category', 'cid', $result[0][$i]['id'], '', $result[0][$i]['name'], '', '', true));
            $node->OpenNewWindow(true);
            $sql_2 = str_replace('_CID_', $result[0][$i]['id'], $sql);
            $result_2 = database_query($sql_2, DATA_AND_ROWS, ALL_ROWS, FETCH_ASSOC);
            for ($j = 0; $j < $result_2[1]; $j++) {
                $sub_node = $node->AddNode($result_2[0][$j]['name'] . ' (' . $result_2[0][$j][$listings_count_field] . ')', prepare_link('category', 'cid', $result_2[0][$j]['id'], '', $result_2[0][$j]['name'], '', '', true));
                $sub_node->OpenNewWindow(true);
                $sql_3 = str_replace('_CID_', $result_2[0][$j]['id'], $sql);
                $result_3 = database_query($sql_3, DATA_AND_ROWS, ALL_ROWS, FETCH_ASSOC);
                for ($k = 0; $k < $result_3[1]; $k++) {
                    $sub_sub_node = $sub_node->AddNode($result_3[0][$k]['name'] . ' (' . $result_3[0][$k][$listings_count_field] . ')', prepare_link('category', 'cid', $result_3[0][$k]['id'], '', $result_3[0][$k]['name'], '', '', true));
                    $sub_sub_node->OpenNewWindow(true);
                }
            }
        }
        ## +---------------------------------------------------------------------------+
        ## | 5. Draw TreeMenu:                                                         |
        ## +---------------------------------------------------------------------------+
        $treeMenu->ShowTree();
        echo '<ul><li>' . prepare_link('categories', '', '', 'all', _SEE_ALL . ' &raquo;', 'main_menu_link main_menu_last', _SEE_ALL) . '</li></ul>';
        draw_block_bottom();
        // save the contents of output buffer to the string
        $output = ob_get_contents();
        ob_end_clean();
        if ($draw) {
            echo $output;
        } else {
            return $output;
        }
    }