<?php
define('IN_OUN', true); 
include_once( "./includes/command.php");
include_once( ROOT_PATH."includes/item_set.php");
include_once( ROOT_PATH."includes/ckeditor/ckeditor.php"); 
include_once( ROOT_PATH."ads.php");
/* 产品页显示的模块 */   
$Aconf['header_title'] = $Aweb_url['links'][0]."|".$Aconf["web_title"];
/* 友情连接提交 */  

$db_table = $pre."links"; 
if( $_POST['action'] == 'install' ) { 

	if($_SESSION['authnum'] != strtoupper($_POST["authnum"]) || empty($_POST["authnum"])){ 
		$strMessage = '验证码错误!!'; 
	}elseif($_POST['action'] == 'install' && $_POST['site_url'] && $_POST['lk_name'] && !empty($_POST['authnum']))
	{ 
		$sql = "SELECT lkid FROM ".$db_table." 
				where (lk_name = '".$_POST['lk_name']."' 
				OR  site_url = '".$_POST['site_url']."')  
				AND domain_id=".$_SESSION[$un_domain_id].
				" LIMIT 1";
		$Anorm = $oPub->selectrow($sql);
		if($Anorm[lkid] > 0 ) {
			$strMessage = '此连接已存在,不能重复添加';
		} else
		{
			$is_show = ($Aconf['links'])?0:1;
			$_POST['site_url'] =  str_replace('http://','', $_POST['site_url']);
			$_POST['site_url'] = "http://".$_POST['site_url'];
			$_POST['sort_order'] = 9999;

			if($img_name) {
				$Afields=array('lk_name'=>$_POST['lk_name'],'lk_logo'=>$img_name,'lk_desc'=>$_POST['lk_desc'],'site_url'=>$_POST['site_url'],'sort_order'=>$_POST['sort_order'],'is_show'=>$is_show,'domain_id'=>$_SESSION[$un_domain_id]);
			} else
			{
				$Afields=array('lk_name'=>$_POST['lk_name'],'lk_desc'=>$_POST['lk_desc'],'site_url'=>$_POST['site_url'],'sort_order'=>$_POST['sort_order'],'is_show'=>$is_show,'domain_id'=>$_SESSION[$un_domain_id]);
			} 
			$tlkid = $oPub->install($db_table,$Afields);
			$strMessage = '添加成功';
		}  

	}else{
		$strMessage = '请填写完整资料';
	}

	if(!empty($strMessage)){
		$url = ($Aconf['rewrite'])?'links-0.html':'links.php';
		echo "<SCRIPT language='javascript'>\nalert('".$strMessage."!!');top.location='".$url."';</script>";
		exit;
	}

	unset($Anorm);unset($_POST);
}
/* 连接列表 */
//page
$strWhere = ($Aconf['links'])?" is_show=1 AND ":"  ";
$strWhere = " WHERE ".$strWhere."  domain_id=".$_SESSION[$un_domain_id];
$sql = "SELECT count( * ) AS count FROM ".$db_table.$strWhere;
$row = $oPub->selectrow($sql);
$count = $row['count'];
unset($row);
$page = new ShowPage;
$Aconf['set_pagenum'] = 30;
$page->PageSize = $Aconf['set_pagenum'];
$page->Total = $count;
$pagenew = $page->PageNum();
$page->LinkAry = array(); 
$strOffSet = $page->OffSet();
/* 翻页 */
$Ahome["showpage"] = ($count  > $Aconf['set_pagenum'])?$page->ShowLink_num():''; 

$sql = "SELECT lk_name,lk_logo,lk_desc,site_url  FROM ".$db_table.$strWhere."  ORDER BY sort_order,lkid ASC limit ".$strOffSet;
$Alinks = $oPub->select($sql);
$n = 0;
while( @list( $key, $value ) = @each( $Alinks) ) {
	  $Alinks[$key][lk_logo] = ($value[lk_logo] == '')?false:'data/links/'.$value[lk_logo]; 
	  $Alinks[$key][lk_desc] = sub_str(clean_html($value['lk_desc']),60);
}
$Ahome["links"] = $Alinks;unset($Alinks);
$Ahome["nowNave"]  = '<A HREF="./">首页</A> >  友情连接';  

//提交验证编码
$ychar="0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
$Acolor = array("#FFFF00","#FFCC00","#FF9900","#FF6600","#FF3300","#FF0000","#660000","#663300","#669900","#83CC00","#93CC00","#a3CC00","#b3CC00","#c3CC00","#d3CC00","#e3CC00","#f3CC00","#30CC00","#31CC00","#32CC00","#33CC00","#34CC00","#35CC00","#36CC00","#37CC00","#38CC00","#39CC00","#3aCC00","#3bCC00","#3cCC00","#3dCC00","#3eCC00","#3fCC00","#3cfC00","#32C800",);
$list=explode(",",$ychar);
for($i=0;$i<4;$i++){
	$randnum=rand(0,35);
	$authnumcolor .= '<span style="color:'.$Acolor[$randnum].';font-size: 20px">'.$list[$randnum].'</span>';
	$authnum .= $list[$randnum];
}
$_SESSION["authnum"] = $authnum;
$Ahome["authnum"] = $authnumcolor;  
if ((DEBUG_MODE & 2) != 2) {
    $smarty->caching = true;
}
/* 调用模板 */
 
/*------------------------------------------------------ */
//-- 判断是否存在缓存，如果存在则调用缓存，反之读取相应内容
/*------------------------------------------------------ */
/* 缓存编号 */
$cache_id = sprintf('%X', crc32($_SESSION[$un_domain_id].$_REQUEST[page]));
if (!$smarty->is_cached($Aconf["displayFile"], $cache_id)) {
    assign_template($Aconf); 
    $smarty->assign('home', $Ahome ); 
    $smarty->assign('user_info', $_SESSION );
	create_html_pre('lk_desc');
    unset($Ahome); 
}
$smarty->display($Aconf["displayFile"], $cache_id);


?>
