<?php
define('IN_OUN', true);
include_once( "includes/command.php");
//header('Content-type: text/html; charset=utf-8');
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
$strKeys = '<span style="color:#CC0000;margin-left: 30px">关联文章，编辑添加</span><br/>';

/* 得到关联文章的arid 数组 */
$db_table = $pre.'arti_tag';
$art_pro_type = 0;
$arid = $arid +0;
$whereArid = ($arid > 0)?" AND arid <> $arid ":' ';
$Aarid = array();
if($keys0 != '')
{
	 $keys = getUtf8( "$keys0");
     $sql = "SELECT arid FROM ".$db_table." 
             WHERE `keys` = '$keys' 
			 AND art_pro_type = '$art_pro_type' 
			 AND domain_id = $_SESSION[$un_domain_id]
			 ".$whereArid." 
			 ORDER BY atid DESC
			 LIMIT 5";
     $row = $oPub->select($sql);
     while( @list( $k, $v) = @each( $row) ) {
		 if (!in_array($arid, $Aarid)) {
			 array_push($Aarid, $arid);    
         }	   
     }
}
if($keys1 != '')
{
	 $keys = getUtf8( "$keys1");
     $sql = "SELECT arid FROM ".$db_table." 
             WHERE `keys` = '$keys' 
			 AND art_pro_type = '$art_pro_type' 
			 AND domain_id = $_SESSION[$un_domain_id]
			 ".$whereArid."  
			 ORDER BY atid DESC
			 LIMIT 5";
     $row = $oPub->select($sql);
     while( @list( $k, $v) = @each( $row) ) {
		 if (!in_array($arid, $Aarid)) {
			 array_push($Aarid, $arid);    
         }	   
     }

}
if($keys2 != '')
{
	 $keys = getUtf8( "$keys2");
     $sql = "SELECT arid FROM ".$db_table." 
             WHERE `keys` = '$keys' 
			 AND art_pro_type = '$art_pro_type' 
			 AND domain_id = $_SESSION[$un_domain_id]
			 ".$whereArid." 
			 ORDER BY atid DESC
			 LIMIT 5";
     $row = $oPub->select($sql);
     while( @list( $k, $v) = @each( $row) ) {
		 if (!in_array($arid, $Aarid)) {
			 array_push($Aarid, $arid);    
         }	   
     }
}
/* 查询关联文章 */
$strArid = implode(',',$Aarid);
$cltionnum = 10;
$n = 0;
if($strArid  != '')
{
   $db_table = $pre.'artitxt'; 
   $sql = "SELECT arid,name FROM ".$db_table." 
          WHERE  domain_id = $_SESSION[$un_domain_id]
		  AND arid in($strArid) 
		  ORDER BY arid DESC";
   $row = $oPub->select($sql);
   
   
   while( @list( $k, $v) = @each( $row ) ) {
       $strKeys .= '标题：<input type="text" name="keysname[]" value="'.$v[name].'" size="50"/>';
       $strKeys .= '网址：<input type="text" name="keyshttp[]" value="article.php?arid='.$arid.'" size="50"/>';
       $strKeys .= '<A HREF="../article.php?arid='.$arid.'" target="_blank"> 详情>> </A><br/>';
	   $n ++ ;
	   if($n >= $cltionnum)
	   {
		   break;
	   }
   }
}

for($n; $n < $cltionnum; $n++)
{
    $strKeys .= '标题：<input type="text" name="keysname[]" value="" size="50"/>';
    $strKeys .= '网址：<input type="text" name="keyshttp[]" value="" size="50"/><br/>';
}

echo $strKeys;
?>