<?php 
session_start(); 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	$opendb=new mydb();
	require_once('inc/char_set.php');
	
	$openck=new cktb();
	if($openck->checktable("ls_pro_feedback","CREATE TABLE ls_pro_feedback (ID INT( 4 ) NOT NULL AUTO_INCREMENT PRIMARY KEY , requirement TEXT NULL , name VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL , company VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL , tel VARCHAR( 100 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL , email VARCHAR( 150 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL , date VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL , path VARCHAR( 1000 ) CHARACTER SET utf8 COLLATE utf8_general_ci NULL, address VARCHAR(500) NULL, fax VARCHAR(100) NUll, http VARCHAR(100)  NULL, proID INT( 4 ) NULL, ip VARCHAR( 50 ) NULL, explorer VARCHAR( 100 ) NULL, home VARCHAR( 300 ) NULL, system VARCHAR( 50 ) NULL, enable INT(1) NULL DEFAULT  '1') ENGINE = INNODB;"))	$ls_msg = $ls_msg .$openck->ls_msg;
	
	$ls=$_GET['ls'];
	$id=$_GET['id'];
	$modiid=$_POST['modiid'];
	$userName=trim($_POST['userName']);
	$userRealName=$_POST['userRealName'];
	$usercompany=$_POST['usercompany'];
	$userPwd=$_POST['userPwd'];
	$userEmail=strtolower(trim($_POST['userEmail']));
	$userWeb=strtolower(trim($_POST['userWeb']));
	$userMemo=$_POST['userMemo'];	
	$userTime=$_POST['userTime'];
	$userNum=$_POST['userNum'];
	
	$selectcate=$_GET['selectcate'];

	$lsc=$_GET['lsc'];
	$lsctype=$_GET['lsctype'];
	$searchproductName=trim($_POST['searchproductName']);
	if($searchproductName==''){$searchproductName=$_GET['searchproductName'];}// 分页传过来的变量

	
	$nowusernum=$_GET['userNum'];

	$ls_msg="询盘管理";
	
	switch ($ls)
	{
		case "del":
		
			$del_sql="delete from ls_pro_feedback where id=".$id." ";
			//echo $del_sql;
			$del_query=$opendb->query($del_sql);
			$ls_msg="删除操作成功！";
			
			break;
	}
	

switch ($lsc)
	{
		case "all":			
			$addsearchstr=" where   " ;
			$ls_msg="全部";
		 	break;
		case "type":			
			$addsearchstr=" where continent='".$lsctype."'  " ;
			$ls_msg="筛选条件： ".$lsctype." 的记录";
		 	break;
		case "unenable":
			$unenable_sql="update ls_pro_feedback set enable=0 where id=".$id." ";
			//echo $unenable_sql;
			$unenable_query=$opendb->query($unenable_sql);
			$ls_msg="操作成功！";
			echo "<script>window.open(\"menu.php\",   \"leftFrame\")   </script>";
			break;
}

	$download_sql="SELECT * FROM ls_functioncates where enable=1  and functionName='询盘分类' order by Num asc";//count the error by searchtype
	$download_query=$opendb->query($download_sql);
	
	function cateName_s($id){
		if($id != NULL){
		$function_sql ="select * from ls_functioncates where ID = ".$id;
		$opendb=new mydb();
		$function_query=$opendb->query($function_sql);
		$function_rows=mysql_fetch_assoc($function_query);
			if($function_rows['cateName'] != ""){
				return $function_rows['cateName'];
			}else{
				return "产品";
			}
		}else{
			return "其它";
		}
	}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link href="css/admin.css" rel="stylesheet" type="text/css">
		<script language="JavaScript" src="js/ls.js"></script>
		<title>询盘管理</title>
	</head>
	<body>
		<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#6396d6">
			<tr>
				<td height="18" background="images/admin_bg.gif"><div align="center"><font color="#ffffff"><strong>询盘管理</strong></font></div>
				</td>
			</tr>
			
			<tr>
			  <td height="213" valign="top" bgcolor="#dee7ff"><br>
                  <?php 
	if( isset($_GET['page']) )
	{$page = intval( $_GET['page'] );	}
	else
	{$page = 1;	}
	
	if($_POST['gopage']!="")
	{$page =$_POST['gopage']; 
	}

	// 每页数量
	if($usersNum!=0)
	{	$PageSize = $usersNum;}
	else
	{	$PageSize = 10;}
	
	// 获取总数据量
	/********************************************************************************/
	
	$sql="select * from ls_pro_feedback ";
	if($searchproductName!="")
		{
			$sql.=" where enable = 1 and requirement like '%".$searchproductName."%' or name like '%".$searchproductName."%' or tel like '%".$searchproductName."%' or company like '%".$searchproductName."%' or email like '%".$searchproductName."%' ".$wherestr1." and cateNameID = ".$selectcate;
			$ls_msg="包含".$searchproductName."的信息";
		}
	else
	{
		if( $lsc=="type" )
		{
			$sql.=$addsearchstr.$wherestr1." and cateNameID = ".$selectcate;
		}
		else
		{
			if($selectcate != NULL){
				$sql.="where enable = 1"." and cateNameID = ".$selectcate;
			}else{
				$sql.="where enable = 1
				AND (
				tel != ''
				OR email != ''
				)
				AND length( requirement ) >=15 and requirement!='Message'" ;
			}
		}
	}
	//echo $sql;
	$result=$opendb->query($sql);
	
	/********************************************************************************/
	// 获取总数据量
	
	$row = mysql_num_rows($result);
	$amount = $row;
	
	// 记算总共有多少页
	if( $amount ){
	   if( $amount < $PageSize ){ $page_count = 1; }			   //如果总数据量小于$PageSize，那么只有一页
	   if( $amount % $PageSize ){								  //取总数据量除以每页数的余数
		   $page_count = (int)($amount / $PageSize) + 1;		   //如果有余数，则页数等于总数据量除以每页数的结果取整再加一
	   }else{
		   $page_count = $amount / $PageSize;					  //如果没有余数，则页数等于总数据量除以每页数的结果
	   }
	}
	else{
	   $page_count = 0;
	}
	// 翻页链接
	$page_string = '';
	$pagecatestr="";
	if( $page == 1 ){
	   $page_string .= '首页 | 上一页 |';
	}
	else{
	   $page_string .= '<a href=?&page=1&'.$pagecatestr.'><u><font color=\"#0000FF\">首页</font></u></a> | <a href=?&page='.($page-1)."&".$pagecatestr.'><u><font color=\"#0000FF\">上一页</font></u></a> | ';
	}
	if( ($page == $page_count) || ($page_count == 0) ){
	   $page_string .= ' 下一页 | 尾页';
	}
	else{
	   $page_string .= ' <a href=?&page='.($page+1).'&'.$pagecatestr.'><u><font color=\"#0000FF\">下一页</font></u></a> | <a href=?&page='.$page_count.'&'.$pagecatestr.'><u><font color=\"#0000FF\">尾页</font></u></a>';
	}
		 $page_string .= " &nbsp;&nbsp;页次：<font color='#FF0000'><b>".$page."</b></font>/<b>".$page_count."</b>页";
		 $page_string .= " &nbsp;&nbsp;<b>".$PageSize."</b>个客户每页";
	
	
 
?>
	         <form action="<?php echo "?&lsc=".$lsc."&lsctype=".$lsctype."&searchproductName=".$searchproductName; ?>" method="post" name="searchfm" id="searchfm">
				<table border="0" width="100%" align="center">
						<tr>
							<td width="34%">提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
                            <td width="19%" align="right"><span style="padding-left:6px;"><strong>查找：</strong>
                              <input type="text" name="searchproductName" size="12" maxlength="50" />
                              <input type="submit"  value="查询" />
                            </span></td>
                            <td width="3%" align="left"><span style="padding-left:6px;"><a href="?lsc=all">全部</a></span></td>
							<td width="10%" align="center" style="padding-left:6px;"><div align="">到
                              <input name="gopage" type="text" size="3" />
                              页
                              <input type="submit" name="Submit" value="GO" />
                            </div></td>
                            <td width="8%" align="left">共 <b>
                              <?=$row?>
                            </b> 条</td>
                          <td width="9%" align="left"><a href="managefunctioncate.php?functionName=询盘分类" target="right">询盘分类</a></td>
                            <td width="17%" align="left">&nbsp;</td>
                        </tr>
			   </table>
	    </form>
        <table border="0" width="100%" align="center">
            <tr>
              <td>
              
               <?
               if($selectcate=="")
				{echo "<a href='?selectcate=".$selectcate."'><span style=\"color:#930\" >全部</span></a> | ";}
				else
				{echo "<a href='?selectcate='><span style=\"\" >全部</span></a> | ";}
				if($selectcate=='0'){
					echo "<a href='?selectcate=0'><span style=\"color:#930\" >产品</span></a> | ";
				}else{
					echo "<a href='?selectcate=0'>产品</a> | ";
				}
                while($news_rows2=mysql_fetch_assoc($download_query))
                {
                    if($selectcate==$news_rows2['ID'])
                    {echo "<a href='?selectcate=".$news_rows2['ID']."'><span style=\"color:#930\" >".$news_rows2['cateName']."</span></a> | ";}
                    else
                    {echo "<a href='?selectcate=".$news_rows2['ID']."'>".$news_rows2['cateName']."</a> | ";}
                }
              ?>
              </td>
      </tr>
         </table>
		<table width="1500" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#FFFFFF">
        <tr bgcolor="#B9DAFF">
            <td width="3%" align="center" >序号</td> 
            <td width="16%" height="38" align="center">反馈信息</td>
            <td width="5%" height="38" align="center">姓名</td>
            <td width="6%" height="38" align="center">公司</td>
            <td width="9%" height="38" align="center">电话/传真</td>
            <td width="7%" height="38" align="center">邮箱</td>
            <td width="9%" height="38" align="center">地址</td>
            <td width="9%" height="38" align="center">网址</td>
            <td width="5%" height="38" align="center">IP</td>
            <td width="7%" height="38" align="center">时间</td>
            <td width="5%" height="38" align="center">询盘产品</td>
            <td width="5%" height="38" align="center">类型</td>
           <td width="5%" align="center" >删除</td>
          </tr>
					 <?php 
					 		//查询数据
					$user_sql=$sql." order by date desc  limit ". ($page-1)*$PageSize .",".$PageSize." ";
					$user_query=$opendb->query($user_sql);
			
					 $i=1;
					  while ($user_rows=mysql_fetch_assoc($user_query))
					  {
					  ?>
					<tbody id='ZH_<?=$user_rows['ID']?>'>
						<tr bgcolor='#f4f4f4' onmouseover="this.style.backgroundColor='#e5e5e5'" onmouseout="this.style.backgroundColor='#f4f4f4'" >
							<td align='center' height='38' onclick="javascript:secBoard(<?=$user_rows['ID']?>)" title='单击展开'><?=$user_rows['ID']?><a name="f_<?=$user_rows['ID']?>">&nbsp;</a></td>
                            <td onclick="javascript:secBoard(<?=$user_rows['ID']?>)" title='单击展开'><div style="width:460px; height:56px; overflow:hidden; white-space:warp; text-overflow:ellipsis; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; ">  <?=$user_rows['requirement'] ?> </div></td>
                            <td align="center" onclick="javascript:secBoard(<?=$user_rows['ID']?>)" title='单击展开'><?=trim($user_rows['name'])?></td>
                            <td align="center" onclick="javascript:secBoard(<?=$user_rows['ID']?>)" title='单击展开'><?=trim($user_rows['company'])?></td>
                            <td align="center"><?=$user_rows['tel']?><? if($user_rows['fax'] != null) echo "/ ".$user_rows['fax'];?></td>
                            <td align="center"><a href="mailto:<?=$user_rows['email']?>" target="_blank"><?=$user_rows['email']?></a></td>
                            <td><?=$user_rows['address'] ?></td>
                            <td align="center"><a href="<?=$user_rows['http']?>" target="_blank"><?=str_replace("www.","",str_replace("https://","",str_replace("http://","",$user_rows['http'])) )?></a></td>
                            <td align="center"><?=$user_rows['ip'] ?></td>
                            <td align="center"><?=substr($user_rows['date'], 2, -3);?></td>
                            <td align="center" valign="middle"><?php
                                $path = explode(",",$user_rows['path']);  //产品路径数组
								$proName = explode(",",$user_rows['proName']);  //产品名称数组
								
								$subject = array();  //产品路径数组与产品名称数组合并为二维数组
								foreach ($path as $k => $v) {
									$temp = array('path'=>$v,'proName'=>$proName[$k]);  
									$subject[] = $temp;  
								}
								
                                foreach($subject as $val){
                                    echo "<a href='".$val['path']."' target=\"_blank\">".$val['proName']."</a><br />";
                                }
                                ?></td>
                           <td align='center'><?=cateName_s($user_rows['cateNameID'])?></td>
						   <td align='center'><?
						if($user_rows['userAdmin']==1)
						{
							echo "	<img src='images/b_undrop.png' border='0'>";
						}
						if($user_rows['userAdmin']==0)
						{
							echo "<a href='?page=$page&id=".$user_rows['ID']."&lsc=unenable' onclick='return ConfirmDel();' title='删除'><img src='images/b_drop.png' border='0'></a>";
						 }?></td>
						</tr>
						</tbody>
                       <tbody id='Z_<?=$user_rows['ID']?>' style='display:none;'>
						<tr bgcolor='#f4f4f4' onmouseover="this.style.backgroundColor='#e5e5e5'" onmouseout="this.style.backgroundColor='#f4f4f4'" >
							<td align='center' height='38' onclick="javascript:secBoard2(<?=$user_rows['ID']?>)"  title='单击收起'><?=$user_rows['ID']?><a name="f_<?=$user_rows['ID']?>">&nbsp;</a></td>
                            <td onclick="javascript:secBoard2(<?=$user_rows['ID']?>)"  title='单击收起'><div> <?=$user_rows['requirement'] ?></div></td>
                            <td align="center" onclick="javascript:secBoard2(<?=$user_rows['ID']?>)"  title='单击收起'><?=trim($user_rows['name'])?></td>
                            <td align="center" onclick="javascript:secBoard2(<?=$user_rows['ID']?>)"  title='单击收起'><?=trim($user_rows['company'])?></td>
                            <td align="center"><?=$user_rows['tel']?><? if($user_rows['fax'] != null) echo "/ ".$user_rows['fax'];?></td>
                            <td align="center"><a href="mailto:<?=$user_rows['email']?>"><?=$user_rows['email']?></a></td>
                            <td><?=$user_rows['address'] ?></td>
                            <td align="center"><?=$user_rows['http'] ?></td>
                            <td align="center"><?=$user_rows['ip'] ?></td>
                            <td align="center"><?=substr($user_rows['date'], 0, -3);?></td>
                            <td><?php
                                $array = explode(", ",$user_rows['path']);
                                foreach($array as $url){
                                    echo "<a href='".$url."' target=\"_blank\">".$url."</a><br />";
                                }
                                ?></td>
                            <td align='center'><?=cateName_s($user_rows['cateNameID'])?></td>
						   <td align='center'><?
						if($user_rows['userAdmin']==1)
						{
							echo "	<img src='images/b_undrop.png' border='0'>";
						}
						if($user_rows['userAdmin']==0)
						{
							echo "<a href='?page=$page&id=".$user_rows['ID']."&lsc=unenable' onclick='return ConfirmDel();' title='删除'><img src='images/b_drop.png' border='0'></a>";
						 }?></td>
						</tr>
						</tbody>
					   <?
						$i++;
					  }
					 ?> 
                     

							<tr>
							<td align="center" colspan="13" bgcolor="#B9DAFF" height="30"><? echo( $amount>$PageSize?$page_string:""); ?> </td>
					  </tr>
				</table>
				</td>
			</tr>
		</table>
	</body>
</html>