<?php
if(!defined('IN_GATEWEI')) {	exit('access denied');}

 if($ipost=="priority"){
	if(!$frlink_check){
		gadminmessage("没有友情网站被选中");
	}
	$frlink_check_str=implode(",",$frlink_check);
	$db->query("update g_friendlylink set top =$timestamp where frid in ($frlink_check_str)");
	w2friendlylink();
	gadminmessage("友情网站删除成功","siteadmin.php?iframe=friendlylink",1);
}


 if($ipost=="delete"){
	if(!$frlink_check){
		gadminmessage("没有友情网站被选中");
	}
	$frlink_check_str=implode(",",$frlink_check);
	$db->query("delete from g_friendlylink where frid in ($frlink_check_str)");
	w2friendlylink();
	writelog($userid."删除".count($frlink_check)."条友情链接成功(".$frlink_check_str.")");
	gadminmessage("调查友情网站删除成功","siteadmin.php?iframe=friendlylink",1);
}

if($ipost=="update")
{
	$get_id=intval($get_id);
    $fr_sitename=trim($fr_sitename);
    $fr_siteurl=filterurl($fr_siteurl);
    $fr_sitelogo=filterurl($fr_sitelogo);
	if(empty($fr_sitename) || empty($fr_siteurl)){
		gadminmessage("网站名或网站链接不能为空","siteadmin.php?iframe=friendlylink",1);
	}
    $db->query("update g_friendlylink set sitename = '$fr_sitename' , siteurl = '$fr_siteurl' , sitelogo ='$fr_sitelogo' where frid=$get_id limit 1 ");
	w2friendlylink();
	writelog($userid."修改友情链接".$fr_sitename."成功");
	gadminmessage("友情链接修改成功","siteadmin.php?iframe=friendlylink",1);
}

if($ipost == 'save')
{

    $fr_sitename=trim($fr_sitename);
    $fr_siteurl=filterurl($fr_siteurl);
    $fr_sitelogo=filterurl($fr_sitelogo);
	if( empty($fr_sitename) || empty($fr_siteurl) ){
		gadminmessage("网站名或网站链接不能为空");
	}
	$db->query("insert into g_friendlylink (frid , top , sitename , siteurl , sitelogo ) values (null , $timestamp , '$fr_sitename' , '$fr_siteurl' , '$fr_sitelogo' )");
	w2friendlylink();
	writelog($userid."添加友情链接".$fr_sitename."成功");
	gadminmessage("友情链接添加成功","siteadmin.php?iframe=friendlylink",1);
}

if($ipost== 'modify')
{
	$get_id=intval($get_id);
	$q=$db->query("select * from g_friendlylink where frid = $get_id limit 1");
	$sites=$db->fetch_array($q);
	
?>

<table>
<caption>友情链接修改</caption>
 <tr >
    <th colspan="2">修改友情链接</th>
  </tr>
  
  <form action="siteadmin.php?iframe=friendlylink&ipost=update&get_id=<?php echo $sites['frid']?>" method="post" name="mfriendlylink">
  <tr>
    <td  width="30%" >网站名称</td>
    <td width="70%" > <input name="fr_sitename" type="text" class="formtext"  value="<?php echo $sites['sitename']?>">
     </td>
    </tr>
   <tr>
    <td >网站网址链接
    </td>
    <td ><input name="fr_siteurl" type="text" class="formtext" value="<?php echo $sites['siteurl']?>"></td>
</tr>
   <tr>
    <td  >网站徽标[ 填入友情网站徽标的url]</td>
    <td ><input name="fr_sitelogo" type="text" class="formtext" value="<?php echo $sites['sitelogo']?>"></td>
   </tr>
   </table>
      <div id="submitdiv"><input type="submit" value="提  交"></div>
  </form>
	 <tr>
          <td colspan="5">&nbsp;
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
	      </td>
   </tr>
   </table>

<?php
	exit();
}
?>




<table>
<caption>友情链接设置</caption>
 <tr >
    <th colspan="2">添加友情链接</th>
  </tr>
  
  <form action="siteadmin.php?iframe=friendlylink&ipost=save" method="post" name="friendlylink">
  <tr>
    <td  width="40%" >网站名称</td>
    <td width="60%" > <input name="fr_sitename" type="text" class="formtext" >
     </td>
    </tr>
   <tr>
    <td >网站网址链接
    </td>
    <td >      <input name="fr_siteurl" type="text" class="formtext" value="http://"></td>
</tr>
   <tr>
    <td  >网站徽标[ 设置为空将显示网站名称文字]</td>
    <td ><input name="fr_sitelogo" type="text" class="formtext"></td>
   </tr>
   </table>
      <div id="submitdiv"><input type="submit" value="提  交"></div>
  </form>
	 <tr>
          <td colspan="5">&nbsp;
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
	      </td>
   </tr>
   </table>
<table>
 <tr >
    <th colspan="6">友情链接管理</th>
  </tr>
<tr>
     <td width="5%" >
	 	<input type="checkbox" name="friendlylink_check_all" id="friendlylink_check_all" onclick="checkall_onclick('friendlylink')"> </td>
	 	<td  width="5%" >修改</td>
	<td width="30%" >网站徽标（logo）</td>
    <td width="25%" >联盟网站名称</td>
	<td width="30%" >url链接</td>

  </tr>
  <form id="friendlylink_check_form" method="post">
  <?php

  $totalrecord=$db->result($db->query("select count(*) from g_friendlylink"),0);
  $pagerecords=6;
  $curpage=isset($page)?$page:1;
  $startrecord=($curpage-1)*$pagerecords;
  $multipage=multi($totalrecord, $pagerecords, $curpage, "siteadmin.php?iframe=friendlylink");
   $q = $db->query("select * from g_friendlylink order by top desc limit $startrecord , $pagerecords");
  $i=0;
  while($sites = $db->fetch_array($q)) 
	{?>
  <tr>
    <td ><input type="checkbox" name="frlink_check[]" id="friendlylink_check_<?php echo $i?>" value="<?php echo $sites['frid'] ?>"></td>
    <td ><a href="siteadmin.php?iframe=friendlylink&ipost=modify&get_id=<?php echo $sites['frid']?>"><img src="./images/siteadmin/g_admin_edit.gif"></a></td>
    <td ><?php echo $sitelogo=empty($sites['sitelogo'])?$sites['sitename']:$sites['sitelogo']?></td>
	<td ><?php echo $sites['sitename']?></td>
	<td ><?php echo $sites['siteurl']?></td>
  </tr>
  <?
  $i++;
  }?>
  </form>
   <tr>
          <td colspan="5">
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
	      </td>
   </tr>
   <tr>
	<td colspan="5"> 

	<input type="button" value="删  除" onclick="friendlylink_delete()">   
	<input type="button" value="优  先" onclick="friendlylink_priority()">
<?php echo $multipage?>
	</td>
   </tr>
</table>


<script language="javascript">

//优先调查
function friendlylink_priority(){
	if(!is_checked('friendlylink')){
		return alert("没有友情网站被选中");
	}
		$('friendlylink_check_form').action="siteadmin.php?iframe=friendlylink&ipost=priority";
		$('friendlylink_check_form').submit();
}

//删除调查
function friendlylink_delete(){
	if(!is_checked('friendlylink')){
		return alert("没有友情网站被选中");
	}
		$('friendlylink_check_form').action="siteadmin.php?iframe=friendlylink&ipost=delete";
		$('friendlylink_check_form').submit();
}

</script>