<?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:#00C;margin-left: 30px">关联专题，编辑添加</span><br/>';

/* 得到关联专题的prid 数组 */
$db_table = $pre.'arti_tag';
$art_pro_type = 2;
$_GET[tpid] = $_GET[tpid] +0;
$whereArid = ($_GET[tpid] > 0)?" AND arid <> $_GET[tpid] ":' ';
$Aarid = array();
if($_GET[keys0] != '')
{
	 $keys = getUtf8( "$_GET[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($v[arid], $Aarid)) {
			 array_push($Aarid, $v[arid]);    
         }	   
     }
}
if($_GET[keys1] != '')
{
	 $keys = getUtf8( "$_GET[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($v[arid], $Aarid)) {
			 array_push($Aarid, $v[arid]);    
         }	   
     }

}
if($_GET[keys2] != '')
{
	 $keys = getUtf8( "$_GET[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($v[arid], $Aarid)) {
			 array_push($Aarid, $v[arid]);    
         }	   
     }
}
/* 查询关联专题 */
$strArid = implode(',',$Aarid);
$cltionnum = ($Aconf['cltion'] > 0 )?$Aconf['cltion']:10;
$n = 0;
if($strArid  != '')
{
   $db_table = $pre.'topictxt'; 
   $sql = "SELECT tpid ,name FROM ".$db_table." 
          WHERE  domain_id = $_SESSION[$un_domain_id]
		  AND tpid in($strArid) 
		  ORDER BY tpid DESC";
   $row = $oPub->select($sql);
   
   
   while( @list( $k, $v) = @each( $row ) ) {
       $strKeys .= '标题：<input type="text" name="keysname_topic[]" value="'.$v[name].'" size="50"/>';
       $strKeys .= '网址：<input type="text" name="keyshttp_topic[]" value="topic.php?tpid='.$v[tpid].'" size="50"/>';
       $strKeys .= '<A HREF="../topic.php?tpid='.$v[tpid].'" target="_blank"> 详情>> </A><br/>';
	   $n ++ ;
	   if($n >= $cltionnum)
	   {
		   break;
	   }
   }
}

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

echo $strKeys;
?>