<?php

if(!defined('DEDEINC'))
{
    exit("Request Error!");
}

function lib_fahao(&$ctag,&$refObj)

{
    global $dsql;
    $attlist="row|12,titlelen|24,type|0,orderby|-1,keyword|";
    FillAttsDefault($ctag->CAttribute->Items,$attlist);
    extract($ctag->CAttribute->Items, EXTR_SKIP);
    $innertext = trim($ctag->GetInnerText());
    $revalue = '';
	$lei = $lei;
	$flag = $flag;
	$typeid = $typeid;
	$orderby = $orderby;
	$limit = $limit;
	
	$addquery = " where arcrank='0' ";
	$wquery = ' ORDER BY kstime DESC';	

	
	if($type=='pt-fh'){//平台相关发号
	$aid = $refObj->Fields['aid'];
	$title = $refObj->Fields['title'];
	$nrow = $dsql->GetOne("SELECT * FROM `#@__addonpt` where aid='$aid'");
	$addquery .= " and pingtai='$title'";
	$wquery = ' ORDER BY kstime DESC ';
	}
	
	if($type=='yx-fh'){//游戏相关发号
	$aid = $refObj->Fields['aid'];
	$title = $refObj->Fields['title'];
	$nrow = $dsql->GetOne("SELECT * FROM `#@__archives` where id='$id'");
	$addquery .= " and title='$title'";
	$wquery = ' ORDER BY kstime DESC ';
	}
	if($type=='glfh'){//游戏关联发号
	$aid = $refObj->Fields['aid'];
	$title = $refObj->Fields['title'];
	$nrow = $dsql->GetOne("SELECT * FROM `#@__addonkf` where aid='$aid'");
	$addquery .= " and title='$title'";
	$wquery = ' ORDER BY kstime DESC ';
	}
	
	if($type=='ptfh'){//平台关联发号
	$aid = $refObj->Fields['aid'];
	$pingtai = $refObj->Fields['pingtai'];
	$nrow = $dsql->GetOne("SELECT * FROM `#@__addonfh` where aid='$aid'");
	$addquery .= " and pingtai='$pingtai'";
	$wquery = ' ORDER BY kstime DESC ';
	}
	
	if($type=='yxfh'){//游戏相关发号
	$aid = $refObj->Fields['aid'];
	$title = $refObj->Fields['title'];
	$nrow = $dsql->GetOne("SELECT * FROM `#@__addonfh` where id='$id'");
	$addquery .= " and title='$title'";
	$wquery = ' ORDER BY kstime DESC ';
	}
	
	if($type=='type'){//类型
	$addquery .= " and typeid='$typeid' ORDER BY $orderby DESC";
	$wquery = '';
	}	
	
	if($type=='orderby'){//排序
	$addquery .= " ORDER BY $orderby DESC";
	$wquery = '';
	}	
	
	if($type=='flag'){//属性
	$addquery .= " and flag LIKE '%$flag%'";
	$wquery = ' ORDER BY id DESC';
	}	

	if($type=='lei'){//标签
	$addquery .= " and fenlei='$lei'";
	$wquery = ' ORDER BY id DESC';
	}

    $equery = "SELECT * FROM `#@__addonfh` $addquery $wquery LIMIT $limit";


    $ctp = new DedeTagParse();
    $ctp->SetNameSpace('field','[',']');
    $ctp->LoadSource($innertext);
    $dsql->Execute('fb',$equery);
	$GLOBALS['autoindex'] = 0;
    while($arr=$dsql->GetArray('fb'))
    {
       
        $GLOBALS['autoindex']++;
        foreach($ctp->CTags as $tagid=>$ctag)
        {
            if(!empty($arr[$ctag->GetName()]))
            {
                $ctp->Assign($tagid,$arr[$ctag->GetName()]);
            }
        }
        $revalue .= $ctp->GetResult();
    }
    return $revalue;
}

