<?php
session_start();
include "header.html";
require_once "../MessageBox.php";
include "../datasource.inc.php";
include "../Function.php";
$Message = new MessageBox;
if ( empty($_SESSION["usernumber"]) and $_SESSION["userjs"] != "1") {
    $Message->setMessage("对不起，您没有权限进入后台管理!","logout.php");
    $Message->showMessage();
}
$page    = $_REQUEST['page'];
$body    = $_REQUEST['body'];
$commet  = str_replace("\n", "<BR>", $_REQUEST['commet']);
$date     = Date("Y-m-d");
$datetime = Date("Y-m-d H:i:s");
$page     = $_REQUEST['page'];
$body     = $_REQUEST['body'];
if ( $_REQUEST['action'] == "insert") {
	$sql    = "insert into yxwl values ('','$_REQUEST[province]','$_REQUEST[qy]','$_REQUEST[company]','$_REQUEST[name]','$_REQUEST[tel]','$_REQUEST[address]')";
	$result = mysql_query($sql);
	ShowMessage(3,"添加成功！","");
}
if ( $_REQUEST['action'] == 'update') {
	$sql     = "update yxwl set province='$_REQUEST[select]',qy='$_REQUEST[qy]',company='$_REQUEST[company]',name='$_REQUEST[name]',tel='$_REQUEST[tel]',address='$_REQUEST[address]' where id='$_REQUEST[id]'";
	mysql_query($sql);
	ShowMessage(4,"编辑成功！","yxwl.php");
}
?>
<table width="700" border="0" cellspacing="0" cellpadding="0">
        <tr>
         <TD vAlign=top><FONT color=#565656><IMG height=14 
      src="../images/closedfold.gif" width=14>&nbsp;&nbsp;您当前的位置<BR><IMG 
      height=15 src="../images/bar.gif" width=15><IMG height=14 
      src="../images/openfold.gif" width=14>&nbsp;&nbsp;营销网络管理</FONT></TD>
        </tr>
</table>

<?php
switch ($page){
	case "add":
?>
<center>
<p align="center">&nbsp;<b><font size="3">请输入营销网络</font></b></p>
<form action="yxwl.php?action=insert" method="post" name="form1" onsubmit="return chin()">
<table width=553 height="154" border=0 cellpadding=0 cellspacing=1 bgcolor="#6795B4">
  <tr>
    <td width="20%" bgColor=#EBF1F5><center><b>选择省份</b></center></td>
    <td width="80%" bgcolor=ffffff>
<SELECT 
                              size=1 name=province> <OPTION value=福建 
                                selected>福建</OPTION> <OPTION 
                                value=安徽>安徽</OPTION> <OPTION 
                                value=北京>北京</OPTION> <OPTION 
                                value=重庆>重庆</OPTION> <OPTION 
                                value=甘肃>甘肃</OPTION> <OPTION 
                                value=广东>广东</OPTION> <OPTION 
                                value=广西>广西</OPTION> <OPTION 
                                value=贵州>贵州</OPTION> <OPTION 
                                value=海南>海南</OPTION> <OPTION 
                                value=河北>河北</OPTION> <OPTION 
                                value=黑龙江>黑龙江</OPTION> <OPTION 
                                value=河南>河南</OPTION> <OPTION 
                                value=湖北>湖北</OPTION> <OPTION 
                                value=湖南>湖南</OPTION> <OPTION 
                                value=内蒙古>内蒙古</OPTION> <OPTION 
                                value=江苏>江苏</OPTION> <OPTION 
                                value=江西>江西</OPTION> <OPTION 
                                value=吉林>吉林</OPTION> <OPTION 
                                value=辽宁>辽宁</OPTION> <OPTION 
                                value=宁夏>宁夏</OPTION> <OPTION 
                                value=青海>青海</OPTION> <OPTION 
                                value=山西>山西</OPTION> <OPTION 
                                value=陕西>陕西</OPTION> <OPTION 
                                value=山东>山东</OPTION> <OPTION 
                                value=上海>上海</OPTION> <OPTION 
                                value=四川>四川</OPTION> <OPTION 
                                value=天津>天津</OPTION> <OPTION 
                                value=西藏>西藏</OPTION> <OPTION 
                                value=新疆>新疆</OPTION> <OPTION 
                                value=云南>云南</OPTION> <OPTION 
                                value=浙江>浙江</OPTION> <OPTION 
                                value=其他>其他</OPTION></SELECT>

    </td>
  </tr>
  <tr>
    <td width="20%" bgColor=#EBF1F5><center><b>区域</b></center></td>
    <td width="80%" bgcolor=ffffff><input type="text" size="20" name="qy"></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>公司名称</b></center></td>
    <td width="80%" bgColor=#ffffff><input type="text" size="40" name="company"></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>联系人</b></center></td>
    <td width="80%" bgColor=#ffffff><input type="text" size="40" name="name"></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>联系方式</b></center></td>
    <td width="80%" bgColor=#ffffff><input type="text" size="40" name="tel"></td>
  </tr>
  <tr height=24>
    <td width="20%" bgColor=#EBF1F5><center><b>联系地址</b></center></td>
    <td width="80%" bgColor=#ffffff><input type="text" size="40" name="address"></td>
  </tr>
</table>
<br>
<input type="submit" value="提 交" >&nbsp;&nbsp;<input type="reset"  value="取 消">
</form>
</center>
<?
		break;
	case "delete":
		$query    = "delete from yxwl where id='$_REQUEST[id]'";
		mysql_query($query);
		ShowMessage(3,"删除成功！","");
		break;
	case "update":
		$sql      = "select * from yxwl where id='$_REQUEST[id]'";
		$result   = mysql_query($sql);
		$row      = mysql_fetch_array($result);
		$body     = str_replace("<BR>", "\n", $row['body']);
		$description  = str_replace("<BR>", "\n", $row['description']);
		$keywords  = str_replace("<BR>", "\n", $row['keywords']);
?>
<center>
<p align="center">&nbsp;<b><font size="3">请修改新闻内容</font></b></p>
<form action="yxwl.php?action=update" method="post" name="form" onsubmit="return chin()">
<table width="553" height="154" border="0" cellpadding="0" cellspacing="1" bgcolor="#6795B4">
  <tr>
    <td width="20%" bgcolor="#EBF1F5"><center>
      <b>选择省份</b>
    </center></td>
    <td width="80%" bgcolor="ffffff"><select 
                              size="1" name="select">
      <option value="<?php echo $row['province ']?>" 
                                selected="selected"><?php echo $row['province ']?></option>
 <option 
                                value="福建">福建</option>								
      <option 
                                value="安徽">安徽</option>
      <option 
                                value="北京">北京</option>
      <option 
                                value="重庆">重庆</option>
      <option 
                                value="甘肃">甘肃</option>
      <option 
                                value="广东">广东</option>
      <option 
                                value="广西">广西</option>
      <option 
                                value="贵州">贵州</option>
      <option 
                                value="海南">海南</option>
      <option 
                                value="河北">河北</option>
      <option 
                                value="黑龙江">黑龙江</option>
      <option 
                                value="河南">河南</option>
      <option 
                                value="湖北">湖北</option>
      <option 
                                value="湖南">湖南</option>
      <option 
                                value="内蒙古">内蒙古</option>
      <option 
                                value="江苏">江苏</option>
      <option 
                                value="江西">江西</option>
      <option 
                                value="吉林">吉林</option>
      <option 
                                value="辽宁">辽宁</option>
      <option 
                                value="宁夏">宁夏</option>
      <option 
                                value="青海">青海</option>
      <option 
                                value="山西">山西</option>
      <option 
                                value="陕西">陕西</option>
      <option 
                                value="山东">山东</option>
      <option 
                                value="上海">上海</option>
      <option 
                                value="四川">四川</option>
      <option 
                                value="天津">天津</option>
      <option 
                                value="西藏">西藏</option>
      <option 
                                value="新疆">新疆</option>
      <option 
                                value="云南">云南</option>
      <option 
                                value="浙江">浙江</option>
      <option 
                                value="其他">其他</option>
    </select>
    </td>
  </tr>
  <tr>
    <td width="20%" bgcolor="#EBF1F5"><center>
      <b>区域</b>
    </center></td>
    <td width="80%" bgcolor="ffffff"><input type="text" size="20" name="qy" value="<?php echo $row['qy']?>"/></td>
  </tr>
  <tr height="24">
    <td width="20%" bgcolor="#EBF1F5"><center>
      <b>公司名称</b>
    </center></td>
    <td width="80%" bgcolor="#ffffff"><input type="text" size="40" name="company"  value="<?php echo $row['company']?>"/> </td>
  </tr>
  <tr height="24">
    <td width="20%" bgcolor="#EBF1F5"><center>
      <b>联系人</b>
    </center></td>
    <td width="80%" bgcolor="#ffffff"><input type="text" size="40" name="name"  value="<?php echo $row['name']?>"/></td>
  </tr>
  <tr height="24">
    <td width="20%" bgcolor="#EBF1F5"><center>
      <b>联系方式</b>
    </center></td>
    <td width="80%" bgcolor="#ffffff"><input type="text" size="40" name="tel"  value="<?php echo $row['tel']?>"/></td>
  </tr>
  <tr height="24">
    <td width="20%" bgcolor="#EBF1F5"><center>
      <b>联系地址</b>
    </center></td>
    <td width="80%" bgcolor="#ffffff"><input type="text" size="40" name="address"  value="<?php echo $row['address']?>"/></td>
  </tr>
</table>
<br>
<input type="hidden" value="update" name="action">
<?php echo "<input type=hidden name=id  value=$row[id]>"; ?>
<input type="submit" value="编 辑" >&nbsp;&nbsp;<input type="reset"  value="取 消">
</form>
</center>
<?php
		break;
	case "text":
		$sql     = "select * from yxwl where id='$id'";
		$result  = mysql_query($sql);
		$row     = mysql_fetch_array($result);
		$imagetype = ( substr($row['picpath'],-3,3));
		if ( $imagetype=="gif" or $imagetype=="GIF" or $imagetype=="jpg" or $imagetype=="JPG" or $imagetype=="png" or $imagetype=="PNG" or $imagetype=="bmp" or $imagetype=="BMP" or $imagetype=="jpe" or $imagetype=="JPE") {
			$size    = getimagesize ("../upload-images/$row[picpath]");
			$arr     = imgspec( 400, $size[0], $size[1]);
			$imgwidth  = $arr[0];
			$imgheight = $arr[1];
			$pic       = "<img src=../upload-images/$row[picpath] width=$imgwidth height=$imgheight align=center>";
		} else {
			$pic       = "";
		}
?>
<br>
<center>
<table border=0 cellpadding=0 cellspacing=0 width=620>
  <tr height=22> 
    <td><b>类型：</b><?php echo $row['fl']; ?></td>
  </tr>
  <tr> 
    <td align="center"><font size=3><b><?php echo $row['title']?></b></font><br><hr><?php echo "发布时间：<font color=red>$row[date]</font><br>"; ?></td>
  </tr>
  <tr>
    <td height=10></td>
  </tr>
  <tr>
    <td align="center"><?php echo $pic?></td>
  </tr>
  <tr>
    <td height=10></td>
  </tr>
  <tr> 
    <td style="line-height:150%"><?php echo $row['body']?></td>
  </tr>
</table>
<br><a href="yxwl.php">返回</a>
</center>
<?php
		break;
	default:
    echo "<center>";
    echo "<table border=0 width=520>";
    echo "<form action=\"yxwl.php\" method=post><tr>";
    echo "<td bgColor=#ffffff>分类：<select name=\"fl\">";
	$sql1    = "select * from yxwl order by id asc";
	$result1 = mysql_query($sql1);
	echo "<option value=\"\">请选择</option>";
	while ($row1 = mysql_fetch_array($result1) ) {
		echo "<option value=\"$row1[fl]\">$row1[fl]</option>"; 
	}
	echo "</select>";
    echo "</td>";
    echo "<td bgColor=#ffffff>";
	echo "信息标题：<input type=text size=20 name=\"search\" maxlength=20>";
    echo "&nbsp;<input type=submit value=搜索>";
    echo "</td>";
    echo "</tr>";
    echo "</form>";
    echo "</table>";
	if ( $_REQUEST['fl'] && $_REQUEST['search']){
	   	$sql    = "select * from yxwl where fl='$_REQUEST[fl]' && title like '%$_REQUEST[search]%' order by id desc;";
	} elseif ( $_REQUEST['fl']) {
		$sql    = "select * from yxwl where fl='$_REQUEST[fl]' order by id desc;";
	} elseif ( $_REQUEST['search']){
		$sql    = "select * from yxwl where title like '%$_REQUEST[search]%' order by id desc;";
	} else{
	   	$sql    = "select * from yxwl order by id desc;";
	}	
    $result = mysql_query($sql);
	$num    = mysql_num_rows($result);		
    if ( $num>0 ){
    	$last   = intval(($num-1)/30)+1;
    	if ( $page < 1 ) $page=1;
    	if ( $page > $last ) $page=$last;
    	mysql_data_seek($result,($page-1)*30);
		echo "<table border=0 cellpadding=0 cellspacing=1 bgcolor=#6795B4 width=620>";
    	echo "<tr>";
		echo "<td width=80 height=18 bgColor=#EBF1F5><div align=center><b>区域</b></div></td>";
    	echo "<td width=100 height=18 bgColor=#EBF1F5><div align=center><b>公司名称</b></div></td>";    	
    	echo "<td width=100 height=18 bgColor=#EBF1F5><div align=center><b>联系人</b></div></td>";    	
    	echo "<td width=100 height=18 bgColor=#EBF1F5><div align=center><b>联系方式</b></div></td>";		
    	echo "<td width=40 height=18 bgColor=#EBF1F5><div align=center><b>编辑</b></div></td>";		
    	echo "<td width=40 height=18 bgColor=#EBF1F5><div align=center><b>删除</b></div></td>";		 		 	 		 
    	echo "</tr>"; 		 	
		for ( $i=0;$i<30;$i++ ) {
        	$row     = mysql_fetch_array($result);
	     	$id      = $row['id'];
		 	$body    = substr($row['body'],0,30);
		 	if ( $id ) {
				echo "<tr bgColor=#ffffff>";
				echo "<td width=80 height=18 bgColor=#ffffff><div align=center>$row[province] $row[qy]</div></td>";
				echo "<td width=100 height=18 bgColor=#ffffff><div align=center>$row[company]</div></td>";
				echo "<td width=100 height=18 bgColor=#ffffff><div align=center>$row[name]</div></td>";
				echo "<td width=100 height=18 bgColor=#ffffff><div align=center>$row[tel]</div></td>";
				echo "<td width=40 height=18 bgColor=#ffffff><div align=center><a title=点击编辑内容 href=yxwl.php?page=update&id=$row[id]><img src=../images/edit.gif border=0></a></div></td>";
				echo "<td width=40 height=18 bgColor=#ffffff><div align=center><a title=点击删除本条记录 href=yxwl.php?page=delete&id=$row[id] onclick=\"return confirm('确定要删除吗？')\"><img src=../images/clearicon.gif border=0></a></div></td>";
				echo "</tr>";
			}
		}
		echo "</table><br>";
		echo "<table width=500 border=0 cellspacing=0 cellpadding=0 height=24>";
		echo "<tbody>";
		echo "<tr><td colspan=4><center>";	
		echo "总共找到<font color=red>$num</font>条记录,第<font color=red>$page</font>页,共<font color=red>$last</font>页。";		  
		echo "</center></td></tr><tr>";	  
		if ( $page <> 1 ) {
			echo "<td align=center>&nbsp;&nbsp;&nbsp;<a href=yxwl.php?page=1&fl=$_REQUEST[fl]&search=$_REQUEST[search]>第一页</a></td>";
			echo "<td align=center><a href=yxwl.php?page=".($page-1)."&fl=$_REQUEST[fl]&search=$_REQUEST[search]>上一页</a></td>";
		}
		if ( $page <> $last ) {
			echo "<td align=center><a href=yxwl.php?page=".($page+1)."&fl=$_REQUEST[fl]&search=$_REQUEST[search]>下一页</a></td>";
			echo "<td align=center><a href=yxwl.php?page=$last&fl=$_REQUEST[fl]&search=$_REQUEST[search]>最后一页</a></td>";
		}
		echo "</tbody>";
		echo "</tr>";
		echo "</table><br>";
		echo "</center>";
	} else {
		echo "<center>对不起，找不到符合条件的记录,<a href=javascript:history.go(-1)>重新查询</a>!</center>";
	}
	break;
}
?>
