<?php
/**
 * 
 * @file channel_tree_ifr.php
 * @copyright (c) 2005 - 2007 eifr.com
 * @license http://www.gnu.org/copyleft/gpl.html gnu/gpl
 * eifr is free software
 */
require_once(dirname(__FILE__) . '/includes/inc_general.php');

function getSubChannelTree($parentid = '') {
    global $db, $subChannelTree_array; 
    // $rtn = array();
    if ($parentid == '') return $subChannelTree_array;
    $sql = "select * from " . TB_CHANNEL . " where id like '" . $parentid . "__' and status=0 and flag<>2 order by ordernum ";
    $rs = $db -> Execute($sql); 
    // echo $sql;
    while (!$rs -> EOF) {
        $rs -> fields['eifr_aritcle'] = array();
        $sql_sub = "select id,title,issuetime from " . TB_ARTICLE . " where channel_id='" . $rs -> fields['id'] . "' and status=0 and flag<>4 order by ordernum desc, issuetime asc ";
        $rs_sub = $db -> Execute($sql_sub); 
        // echo $sql_sub.'<br>';
        while (!$rs_sub -> EOF) {
            $rs -> fields['eifr_aritcle'][] = $rs_sub -> fields;
            $rs_sub -> MoveNext();
        } 
        $rs_sub -> Close();
        $subChannelTree_array[] = $rs -> fields;
        getSubChannelTree($rs -> fields['id']);
        $rs -> MoveNext();
    } 
    $rs -> Close(); 
    // return $rtn;
} 

function getCurChannelArticle($id = '') {
    global $db;
    $rtn = array();
    if ($id == '') return $rtn;
    $sql = "select id,title,issuetime from " . TB_ARTICLE . " where channel_id='" . $id . "' and status=0 and flag<>4 order by ordernum desc, issuetime asc ";
    $rs = $db -> Execute($sql); 
    // echo $sql;
    while (!$rs -> EOF) {
        $rtn[] = $rs -> fields;
        $rs -> MoveNext();
    } 
    $rs -> Close();

    return $rtn;
} 

$curChannelTree_array = getCurChannelArticle($id);
$subChannelTree_array = array();
getSubChannelTree($id);
$tpl_file = 'book_tree';
if ($tpl != '')$tpl_file = $tpl . '_tree';
require_once(getTemplatePath($tpl_file));

?>