<?php
	require_once('_approot.php');	

	require_once('generalpicrequire.php');  //generalpic类型选择语句, 表名、文件存储目录、字段变量名 存储变量在此定义

	$opertb=new mytb();
	$ls=$_GET['ls'];
	$id=$_GET['id'];
	$nowNum=$_GET['nowNum'];
	$searchproductName=($_POST['searchproductName']==""?$_GET['searchproductName']:$_POST['searchproductName']);
	if($searchproductName!="") $ls_msg="包含 $searchproductName 的内容 ";
	if($_POST['gopage']!=""){$gopage =(ctype_digit($_POST['gopage'])?$_POST['gopage']:1);}
	if($gopage!="") $ls_msg="第 $gopage 页的内容 ";
	
	
	if($_GET['skipup1']>1){
		$skipup=$_GET['skipup1'];	
	}else{
		$skipup=1;	
	}//编号排序时用到的数字索引	升序
	
	if($_GET['skipdown1']>1){
		$skipdown=$_GET['skipdown1'];
	}else{
		$skipdown=1;
	}//编号排序时用到的数字索引	降序

	$aTitle=$_POST['newsTitle'];
	$aKeywords=$_POST['newsKeywords'];
	$aDescription=$_POST['newsDescription'];
	$description=$_POST['description'];
	
	//编辑器中的内链与图片转换成相对路径
	$description = editorPath('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], $description);//内链
	$description = editorPath($_SERVER['PHP_SELF'], $description);//图片
	
	$in_sql="SELECT * FROM ls_internal where enable=1 order by Num asc"; //count the error by searchtype
	$in_query=$opendb->query($in_sql);
	while ($in_rows=mysqli_fetch_assoc($in_query)){
		$description = internal_keyword_link($description, $in_rows['title'], $in_rows['url']);
	}

	if ($_GET['ls_msg']=="")
	{
		$ls_msg.=$showstr."管理";
	}	
	else
	{
		$ls_msg.=$_GET['ls_msg'];	
	}
		
	$opertb->table=$generalTable;
	$opertb->id=$id;
	switch ($ls)
	{
		case "up":
			for($ui=0; $ui < $skipup; $ui++){
				$ls_msg=$opertb->up($nowNum+$ui);
			}
			break;

		case "down":
			for($di=0; $di < $skipdown; $di++){
				$ls_msg=$opertb->down($nowNum-$di);
			}
			break;
			
	 	case "unenable":
			$ls_msg=$opertb->unenable();
			break; 
			
		case "enable":
			$ls_msg=$opertb->enable();
			break;
			
		case "del":
			$ls_msg=$opertb->delwfile($folder1,$folder2,$generalpicsPic);
			break;
		
		case "description": //保存页面描述
			$modi_sql=sprintf("update ls_menu set inTitle=%s, inKeywords=%s, inDescription=%s, description=%s where argument=%s",
							GetSQLValueString($aTitle, "text"),
							GetSQLValueString($aKeywords, "text"),
							GetSQLValueString($aDescription, "text"),
							GetSQLValueString($description, "text"),
							GetSQLValueString($gen, "text")
							);
			//echo $modi_sql;
			$modi_query=$opendb->query($modi_sql);
			break;
			
		case "scan":
		
			$scan_sql = "select * from ".$generalTable." ORDER BY Num ";
			$scan_query = $opendb->query($scan_sql);
			$scan_num = 0;
			
			while($scan_rows=mysqli_fetch_assoc($scan_query)){
				$scan_num++;
				$modi_sql=sprintf("update ".$generalTable." set Num=%s where ID=%s",
							GetSQLValueString($scan_num, "text"),
							GetSQLValueString($scan_rows['ID'], "int")
						);
				//echo $modi_sql;
				$modi_query=$opendb->query($modi_sql);
			}
			
			break;
	}
	
	//echo $lssort."  ".$sortfield."---";
	//手动排序字段
	$orderstr=""; //排序串
	$sortfield=$_GET['sortfield'];
	$sortfield2=$_GET['sortfield2'];
    $lssort=$_GET['lssort'];    
	switch ($lssort)
	{	
		case "升序排列": 
		 	$orderstr= $sortfield ." DESC "; //主排序字段,与原来的相反
			$lssort="降序排列";
			$ls_msg="已按照 ".$sortfield2 ." 降序排列";
		break;
		
		case "降序排列":
			$orderstr=  $sortfield ." ASC "; //主排序字段,与原来的相反
			$lssort="升序排列";
			$ls_msg="已按照 ".$sortfield2 ." 升序排列";
		break;

	}
	//默认排序字段
		if($sortfield != "Num")
		{$lssort==""?($orderstr.= " Num Desc "):($orderstr.= ", Num Desc "); }  //第一个字段处理

		if($sortfield != "ID")
		{$orderstr.= ", ID DESC "; }
		
	$select_sql="select * from ls_config ";
	$select_query=$opendb->query($select_sql);
	$select_rows=mysqli_fetch_assoc($select_query);
	if(strpos($select_rows['companyName'],"-")){
		$pos = strpos($select_rows['companyName'], '-', 1);
		$companyName = substr($select_rows['companyName'], (mb_strlen($select_rows['companyName'],'utf-8') - $pos) * -1 );
	}else{
		$companyName = " - ".$select_rows['companyName'];
	}
	$siteDescription = $select_rows['siteDescription'];
	$siteKeywords= $select_rows['siteKeywords'];

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<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/jquery.js"></script>
		<script language="JavaScript" src="js/ls.js"></script>
		<title>管理</title>
        <link rel="stylesheet" href="kindeditor-4.1.10/themes/default/default.css" />
        <link rel="stylesheet" href="css/style2.css" />
<link rel="stylesheet" href="kindeditor-4.1.10/plugins/code/prettify.css" />
<script charset="utf-8" src="kindeditor-4.1.10/kindeditor.js"></script>
<script charset="utf-8" src="kindeditor-4.1.10/lang/zh_CN.js"></script>
<script charset="utf-8" src="kindeditor-4.1.10/plugins/code/prettify.js"></script>
<script>
    KindEditor.ready(function(K) {
        var editor1 = K.create('textarea[name="description"]', {
            cssPath : 'kindeditor-4.1.10/plugins/code/prettify.css',
            uploadJson : 'kindeditor-4.1.10/php/upload_json.php',
            fileManagerJson : 'kindeditor-4.1.10/php/file_manager_json.php',
            allowFileManager : true,
            afterCreate : function() {
                var self = this;
                K.ctrl(document, 13, function() {
                    self.sync();
                    K('form[name=example]')[0].submit();
                });
                K.ctrl(self.edit.doc, 13, function() {
                    self.sync();
                    K('form[name=example]')[0].submit();
                });
            }
        });
        prettyPrint();
    });
</script>
<script language="javascript">
$(function (){
	 var newsTitle = document.getElementById("newsTitle");
	 var newsKeywords = document.getElementById("newsKeywords");
	 var newsDescription = document.getElementById("newsDescription");
	 if ($.trim(newsTitle.value)==""){
	  newsTitle.value='<?=$companyName?>';
	 }
	 if ($.trim(newsKeywords.value)==""){
	  newsKeywords.value='<?=$siteKeywords?>';
	 }
	if ($.trim(newsDescription.value)==""){
	  newsDescription.value='<?=$siteDescription?>';
	 }
});
</script>
	</head>
 <body>
	<table width="100%" border="0" align="center" cellpadding="1" cellspacing="1">
			<tr>
				<td height="18" style="border-bottom:2px solid #00c0ef; padding-bottom:5px;"><div align="center"><font color="#3c8dbc" style="font-size:16px;"><?=$showstr?>管理</font></div>
				</td>
			</tr>
			<tr>
				<td height="213" valign="top" ><br>
					<form name="del" method="Post" action="delall.php?gen=<?=$gen?>&page=<?=$page?>&searchproductName=<?=$searchproductName?>" onSubmit="return ConfirmDel();">
					<table border="0" width="98%" align="center">
						<tr>
							<td style="border-bottom:1px solid #FFF;">提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
							<td align="right" style="border-bottom:1px solid #FFF;"><img src="images/shao.gif">&nbsp;<a href="addmodigenpics.php?gen=<?=$gen?>&ls=insert&page=<?=$page?>&searchproductName=<?=$searchproductName?>">添加
							</a> &nbsp; &nbsp; <?php if(!(strpos($_SERVER['HTTP_REFERER'],"managearticle")===false)){ ?> <a href="managearticle.php">返回</a><?php } ?></td>
						</tr>
					</table><br>
					
					<?php
					// 获取当前页数
					if( isset($_GET['page']) ){
					   $page = intval( $_GET['page'] );
					}
					else{
					   $page = 1;
					}
					// 每页数量
					$PageSize = $PageNum;
					
					// 获取总数据量
					/********************************************************************************/
						if($searchproductName!="") {
							$searhprostr=" and (".$generalpicsTitle." like '%".$searchproductName."%' or ".$generalpicsText." like '%".$searchproductName."%'    ) ";
							$searhprostr2=" where (".$generalpicsTitle." like '%".$searchproductName."%' or ".$generalpicsText." like '%".$searchproductName."%'    ) ";
						}
						$sql = "select * from ".$generalTable." ". $searhprostr2." order by ID desc";
						$result=$opendb->query($sql);
					
					/********************************************************************************/
					// 获取总数据量
					
					$row = mysqli_num_rows($result);
					$news_nums = $row;
					$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 = '';
						
					if( $page == 1 ){
					   $page_string .= '首页 | 上一页 |';
					}
					else{
					   $page_string .= '<a href=?gen='.$gen.'&page=1><u><font color=\"#0000FF\">首页</font></u></a> | <a href=?gen='.$gen.'&page='.($page-1).'><u><font color=\"#0000FF\">上一页</font></u></a> | ';
					}
					if( ($page == $page_count) || ($page_count == 0) ){
					   $page_string .= ' 下一页 | 尾页';
					}
					else{
					   $page_string .= ' <a href=?gen='.$gen.'&page='.($page+1).'><u><font color=\"#0000FF\">下一页</font></u></a> | <a href=?gen='.$gen.'&page='.$page_count.'><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>个每页";
						 
					$ls_msg2="".$showstr."管理 >> 所有".$showstr."图片";
					
					?>

				
				<table border="0" width="100%" align="center">
						<tr>
							<td width="20%"><?php echo $ls_msg2; ?></td>
                            <td width="60%" align="right"><a href="?gen=<?=$gen?>&ls=scan">重新排序</a></td>
							<td width="20%" align="right">共 <b><?php echo $row; ?></b> 个</td>
						</tr>
					 </table>
					 <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1"  style="background-color: #f0f0ee;">
						<tr height="37">
							<td height="45" align="center" width="4%"></td>
					      <td align="center" width="20%"><?=$showstr?>图片</td>
							<?php file_exists("widget/generalpics/head.php")?include "widget/generalpics/head.php" :"" ?>
							<td align="center" width="">名称(标题) / 详细</td>
							<td align="center" colspan="2" width="6%">排序</td>
							<td align="center" colspan="2" width="6%">操作</td>
							<td align="center" width="6%">允许</td>
						</tr>
						<?php
					$news_sql="select * from ".$generalTable."  ". $searhprostr2."  order by ".$orderstr." limit ". ($page-1)*$PageSize .",".$PageSize." ";	
					$news_query=$opendb->query($news_sql);
					$i= ($page-1)*$PageNum+1;
					$inName = "";
					while($news_rows=mysqli_fetch_assoc($news_query))
					{
					?>
					 <tr bgcolor='#f9f9f9' height='37'
							onMouseOver=
						 	this.style.backgroundColor='#e5e5e5' 
						onMouseOut=
						 	this.style.backgroundColor='#f9f9f9' 
						>
						<td align='center'>
							<input name='select_id<?=$i?>' type='checkbox' onclick="unselectall()" id="select_id<?=$i?>" value='<?=$news_rows['ID']?>'><?=$news_rows['ID']?>
						</td>
						<td style='padding-left:10px;'>
							<img src="<?=$_SESSION['dda']?>../<?=$folder2?>/<?=$news_rows[$generalpicsPic]."?i=".rand()?>" width="<?=$SmallPicW/4?>" height="<?=$SmallPicH/4?>" border="1"></td>
							<?php file_exists("widget/generalpics/list.php")?include "widget/generalpics/list.php" :"" ?>
						<td valign="top" style='padding-left:10px;'>
						
                        <?=htmlspecialchars_decode($news_rows[$generalpicsTitle])?>
                        <?php 
						if($news_rows[$generalpicsTitle] != ''){
							$inName .= htmlspecialchars_decode($news_rows[$generalpicsTitle])." | ";
						}
						?>
						<br /><?=mb_substr(strip_tags(trim(preg_replace("/([\s]{2,})/"," ",$news_rows[$generalpicsText]))),0,80)?>
					  </td>
						<td align='center'> 
                    <?php 					if(($i>1&&$page==1)||$page>1)
					{
					?>
							<a id='upp<?=$news_rows['ID']?>' href='?gen=<?=$gen?>&page=<?=$page?>&id=<?=$news_rows['ID']?>&nowNum=<?=$news_rows['Num']?>&ls=up&searchproductName=<?=$searchproductName?>' title='向上移动'><img src='images/up.gif' border='0'></a>
                            <input type="text" name="up" size="1" maxlength="5"  style="width:10px;"  value="1" onblur="document.getElementById('upp<?=$news_rows['ID']?>').href=document.getElementById('upp<?=$news_rows['ID']?>').href+'&skipup1='+this.value">			
                       <?php } ?>
					  </td>
						<td align='center'> 
                    <?php 					 if(($i!=$news_nums&&$page=$page_count)||$page<$page_count)
					{ ?>
							 <a id='dpp<?=$news_rows['ID']?>' href='?gen=<?=$gen?>&page=<?=$page?>&id=<?=$news_rows['ID']?>&nowNum=<?=$news_rows['Num']?>&ls=down&&searchproductName=<?=$searchproductName?>' title='向下移动'><img src='images/down.gif' border='0'></a>
                             <input type="text" name="down" size="1" maxlength="5"  style="width:10px;" value="1" onblur="document.getElementById('dpp<?=$news_rows['ID']?>').href=document.getElementById('dpp<?=$news_rows['ID']?>').href+'&skipdown1='+this.value">
                     <?php } ?>
					  </td>
						<td align='center'> 
						<a href='addmodigenpics.php?gen=<?=$gen?>&page=<?=$page?>&id=<?=$news_rows['ID']?>&ls=update&page=<?=$page?>&searchproductName=<?=$searchproductName?>' title='编辑'><img src='images/b_edit.png' border='0'></a>
					  </td>
					<td align='center'> 
					<a href='?gen=<?=$gen?>&page=<?=$page?>&id=<?=$news_rows['ID']?>&ls=del&page=<?=$page?>&searchproductName=<?=$searchproductName?>' onclick='return ConfirmDelSubCate();' title='删除'><img src='images/b_drop.png' border='0'></a>
					  </td>
						<td align='center'>
											  
					 <?php  if($news_rows['enable']==1)
						{?>
							<a href='?gen=<?=$gen?>&page=<?=$page?>&id=<?=$news_rows['ID']?>&ls=unenable&page=<?=$page?>&searchproductName=<?=$searchproductName?>' title='显示'><img src='images/enable.gif' border='0'></a>
						<?php }
					  if($news_rows['enable']==0)
					  	{ ?>
							<a href='?gen=<?=$gen?>&page=<?=$page?>&id=<?=$news_rows['ID']?>&ls=enable&page=<?=$page?>&searchproductName=<?=$searchproductName?>' title='不显示'><img src='images/unenable.gif' border='0'></a>
						<?php } ?>
												
						</td>
					</tr>
					
					<?php $i++; 
						 }?>
						<tr>
					 
					</tr>
					</table>
					<table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" style="background-color: #f0f0ee;" height="60">
					<tr >
							<td width="17%" height="58" style="padding-left:6px;">
								<input name="chkAll" type="checkbox" id="chkAll" onclick=CheckAll(this.form) value="checkbox">
							    所有 
						        <button name="submit" type='submit' value='删除'>删除</button>
						  <input name="Action" type="hidden" id="Action" value="<?=$gen?>Del" /></td>
					  <td width="47%" height="58" align="center" style="padding-left:6px;"><?=$page_string?></td>
							<td width="26%" height="58" style="padding-left:6px;">
                            
                            </td>
							<td width="10%" align="center" style="padding-left:6px;"><span style="border-bottom:1px solid #FFF;"><img src="images/shao.gif" alt="" />&nbsp;<a href="addmodigenpics.php?gen=<?=$gen?>&ls=insert&page=<?=$page?>&searchproductName=<?=$searchproductName?>"><u>添加</u></a></span></td>
					  </tr>
					</table>
				  </form>
                   <form name="searcharticle" method="Post" action="?gen=<?=$gen?>&selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>" >  
			  <table align="center"  cellpadding="4px;" style="width:100%;background-color:#f0f0ee"><tr>
						<td width="98%" height="" align="right" valign="top"><span style="padding-left:6px;">
			      <input type="text" name="searchproductName" size="16" maxlength="50"  value="" />
			      <input type='submit'    value="查询" style="height:24px;"    />
			      </span>  <input type='button'    value="全部" style="height:24px;"  onclick="this.form.searchproductName.value='';this.form.submit();"   /><span style="padding-left:26px;">
			      <input name="gopage" id="gopage" type="text" size="3" />
			      页
<input type='submit'    value="GO"  style="height:24px;"   />
			      </span></td>
						<td width="2%" align="right">&nbsp;</td>
						</tr>
			      </table>
				</form> 
                  					   <table width="100%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#fff">
                       <tr>
                        <td colspan="2" height="24" align="center">&nbsp;</td>
                      </tr>
                       </table>
                  <?php                   	$menu_sql2="select * from ls_menu where argument='".$gen."' ";
					$menu_query2=$opendb->query($menu_sql2);
					$menu_rows2_num=mysqli_num_rows($menu_query2);
					if($menu_rows2_num==1)
					{
						$menu_rows2=mysqli_fetch_assoc($menu_query2);
						$inTitle=$menu_rows2['inTitle'];
						$inKeywords=$menu_rows2['inKeywords'];
						$inDescription=$menu_rows2['inDescription'];
						$description=$menu_rows2['description'];
				  ?>
					<form id="form1" name="form1" method="post" action="?ls=description&gen=<?=$gen?>">
                    <table width="100%" border="0" style="background-color: #f0f0ee;">
                      <tr>
                        <td width="63%" valign="top"><table width="98%" border="0" align="center"  cellpadding="3" cellspacing="1" bgcolor="#f0f0ee">
					    <tr bgcolor="#f0f0ee"> 
						<td height="37" align="center" ><b><?=$showstr?> 介绍</b></td>
					  </tr>
					    <tr >
					      <td style="padding-left:10px;">
                            <textarea name="description" style="width:100%;height:420px;visibility:hidden;"><?php echo $description ?></textarea>
					        <!-- <textarea name="modiGeneralpicsText" style="width:400px; height:80px;" ><?php echo $modiGeneralpicsText;?></textarea></td> --></td>
				        </tr>
					    
				      </table></td>
                        <td width="37%" valign="top" style="padding-right:15px;"><table border="0" width="98%" align="center" cellpadding="3" cellspacing="1" bgcolor="#f0f0ee">
                    	<tr bgcolor="#f0f0ee">
							<td height="37" colspan="8" ><span style="float:right; padding-right:6px;"><input type="button" name="button" id="button" value="SEO" onClick="
						$('#newsTitle').val('<?=$inName.$companyName;?>');
						$('#newsKeywords').val('<?=$inName?>');
						$('#newsDescription').val('<?=$siteDescription?>');
					" /></span><b style="padding-left:190px; line-height:25px;">SEO优化</b></td>
						</tr>
						  <tr>
						    <td width="70" align="right" >标题<br /> 
						    Title *</td>
						    <td width="299" valign="middle"  ><textarea name="newsTitle" id="newsTitle" style="width:96%;" rows="6"><?php echo $inTitle;?></textarea></td>
					      </tr>
						  <tr>
						    <td align="right" >关键字<br /> Keywords</td>
						    <td   ><textarea name="newsKeywords" id="newsKeywords" style="width:96%;" rows="6"><?php echo $inKeywords;?></textarea></td>
					      </tr>
						  <tr>
						    <td  align="right">描述<br /> Description<br />
*</td>
						    <td ><textarea name="newsDescription" style="width:96%;" rows="9" id="newsDescription"><?php echo $inDescription;?></textarea>
					        <?=$promlv>1?$seo:""?></td>
					      </tr>
					    </table></td>
                      </tr>
                      <tr>
						<td height="47" colspan="2" align="center"><label>
					        <button type="submit" name="button" id="button" value="保存" />保存</button>
				          </label>
                          &nbsp;
				          <label>
				            <button type="reset" name="button2" id="button2" value="重置" />重置</button>
				          </label></td>
			          </tr>
                    </table>
	            </form>
                <?php 	}  //if($menu_rows2_num==1) ?>
                
                </td>
			</tr>
	</table>
 </body>
</html>