<?php 
	require_once('_approot.php');	
	$addcatestr=substr(str_replace(",","' and cateName!='",$defaultmenu),1)."' ";

	$ls_msg="修改文章操作";
	$id=$_GET['id'];
	$sort=$_GET['sort'];
	$fromInMenu=$_GET['fromInMenu'];

	$article_sql="select * from ls_article where ID=".$id." ";
	$article_query=$opendb->query($article_sql);
	$article_rows=mysqli_fetch_assoc($article_query);
	$selectcate=str_replace("'","''",$_GET['selectcate']);
	$selectfunctionName=str_replace("'","''",$_GET['selectfunctionName']);
	$submitForm = "'articleDate,functionName,Num,articleTitle','日期,栏目,序号,新闻标题'";
	
	$htmlData = '';
	$htmlData = $article_rows['articleText'];
	
	$title_sql = "select * from ls_config";
	$title_query = $opendb->query($title_sql);
	$title_value = mysqli_fetch_assoc($title_query);
?>
<!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.min.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="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="articleText"]', {
				filterMode: false,	
				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,
				afterBlur: function(){
					this.sync();
					if($('#newsDescription').val().length == 0){
						$('#newsDescription').val($('#articleText').val().replace(/<[^>]+>/g,'').replace(/	/g, '').replace(/\n/g, '').substr(0, <?=$descriptionLen?>));
					}
				},
				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();
		});
		KindEditor.ready(function(K) {
			var editor1 = K.create('textarea[name="articleBrief"]', {
				filterMode: false,	
				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,
				afterBlur: function(){
					this.sync();
					if($('#newsDescription').val().length == 0){
						$('#newsDescription').val($('#articleBrief').val().replace(/<[^>]+>/g,'').replace(/	/g, '').replace(/\n/g, '').substr(0, <?=$descriptionLen?>));
					}
				},
				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>
	<style type="text/css">
<!--
.hui {	color: #4B4B4B;
}
.hui {	color: #5C5C5C;
}
-->
    </style>
	</head>

<body>
		<table width="98%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#3c8dbc">
			<tr>
				<td height="27" background=""><div align="center"><font color="#ffffff"><strong>修改文章</strong></font></div>
				</td>
			</tr>
			<tr>
				<td height="213" valign="top" bgcolor="#f0f0ee"><br>
				 <form name="articleform" enctype="multipart/form-data" method="post" action="savearticle.php?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>&fromInMenu=<?=$fromInMenu?>&sort=<?=$sort?>" >
					<input type="hidden" value="update" name="ls">
					<input type="hidden" value="<?php echo $id;?>" name="id">
					<input type="hidden" value="<?php echo $download_rows['downloadName'];?>" name="Pic" />
                    <input type="hidden" name="ChangecatePagePic" value="no" />
					<table border="0" width="98%" align="center">
					  <tr>
							<td>提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
							<td align="right"><img src="images/shao.gif">&nbsp;<a href="managearticle.php?sort=<?=$sort?>">返回</a></td>
					  </tr>
					</table>
					<table width="98%" border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="#FFFFFF">
					  <tr bgcolor="#E4E4E4">
					    <td height="28" colspan="4"></td>
				      </tr>
					  <tr bgcolor="#E4E4E4">
					    <td style="padding-left:15px;">栏目：</td>
					    <td style="padding-left:10px;"><input type="text" name="functionName" id="functionName" style="width:52%;" value="<?=$selectfunctionName?>" readonly />
					      <span style="padding-left:20px;">
					        <select name="select2" id="select2"  onchange="articleform.functionName.value=this.options[this.selectedIndex].text;window.open('?id=<?=$id?>&articleTitle='+articleform.articleTitle.value+'&articleBrief='+articleform.articleBrief.value+'&functionName='+this.options[this.selectedIndex].text+'&Num='+this.value +'&selectfunctionName='+this.options[this.selectedIndex].text,'right','');">
					          <option value="0">栏目选择：</option>
					          <?php 			$news_sql="SELECT distinct(functionName) FROM ls_functioncates   where functionName!='新闻分类' and functionName!='singlePages' order by Num";//count the error by searchtype
			$news_query=$opendb->query($news_sql);
			while($news_rows2=mysqli_fetch_assoc($news_query))
		  	{
				echo "<option value=".$news_rows2['functionName'].">".$news_rows2['functionName']."</option>";
			}

			?>
				          </select>
				          </span></td>
					    <td width="51%" rowspan="5" valign="top"  bgcolor=""  ><table border="0" width="100%">
					      <tr>
					        <td width="29%" bgcolor="" >标题 Title</td>
					        <td width="71%"><input name="newsTitle" id="newsTitle" type="text" value="<?php echo $article_rows['title'];?>" style="width:95%;" /></td>
				          </tr>
					      <tr>
					        <td bgcolor="" >关键字 Keywords</td>
					        <td><input name="newsKeywords" id="newsKeywords" type="text" value="<?php echo $article_rows['keywords'];?>" style="width:95%;" /></td>
				          </tr>
					      <tr>
					        <td bgcolor=""  >描述 Description</td>
					        <td><textarea name="newsDescription" style="width:96%;" rows="5" id="newsDescription"><?php echo $article_rows['description'];?></textarea>
				            <?=$promlv>1?$seo:""?></td>
				          </tr>
					      </table></td>
				      </tr>
					  <?php 
					  $cateName_sql = $selectfunctionName?"SELECT distinct(cateName) FROM ls_functioncates   where functionName='".$selectfunctionName."' order by Num":"SELECT distinct(cateName) FROM ls_functioncates   where functionName!='新闻分类' and functionName!='singlePages' order by Num";//count the error by searchtype
					  $cateName_query=$opendb->query($cateName_sql);
					  $cateName_rows_num=mysqli_num_rows($cateName_query);
					  //echo $cateName_rows_num;
					  if($cateName_rows_num > 1){
						 $submitForm = "'articleDate,cateName,functionName,Num,articleTitle','日期,子栏目,栏目,序号,新闻标题'";
					  ?>
					  <tr bgcolor="#E4E4E4">
					    <td style="padding-left:15px;">子栏目：</td>
					    <?php 						  if($selectfunctionName != ""){
							  $news_sql = "SELECT distinct(cateName),Num FROM ls_functioncates   where functionName='".$selectfunctionName."' order by Num";
							}else{
								$news_sql = "SELECT distinct(cateName),Num FROM ls_functioncates   where functionName!='新闻分类' and functionName!='singlePages' order by Num";
							}
			$news_query=$opendb->query($news_sql);
			$news_rows2=mysqli_fetch_assoc($news_query);
			 
			?>
					    <td style="padding-left:10px;"><input name="cateName" type="text"  id="cateName" style="width:52%;" value="<?php echo $selectfunction?$news_rows2['cateName']:$article_rows['cateName'];?>" size="30" readonly />
					      <span style="padding-left:20px;">
					        <select name="select" id="select"  onchange="articleform.cateName.value=this.options[this.selectedIndex].text;articleform.Num.value=this.value;">
					          <option value="0">子栏目选择：</option>
					          <?php 			$news_sql=$selectfunctionName?"SELECT distinct(cateName),Num FROM ls_functioncates   where functionName='".$selectfunctionName."' order by Num":"SELECT distinct(cateName),Num FROM ls_functioncates   where functionName!='新闻分类' and functionName!='singlePages'  ".$addcatestr." order by Num";//count the error by searchtype
			$news_query=$opendb->query($news_sql);
			while($news_rows2=mysqli_fetch_assoc($news_query))
		  	{
				$select_sql2="select Num from ls_article where functionName='".$selectfunctionName."' and cateName ='".str_replace("'","''",$news_rows2['cateName'])."' and functionName!='新闻分类' and functionName!='singlePages' order by Num desc ";
				//echo $select_sql2;
				$select_query2=$opendb->query($select_sql2);
				$select_rows2_num=mysqli_num_rows($select_query2); //总数
				$select_rows2=mysqli_fetch_assoc($select_query2);
				//$select_rows2['Num']+5
				if($news_rows2['cateName']=="") continue;
				
				echo "<option value=".($select_rows2_num*5+5).">".$news_rows2['cateName']."</option>";

			}

			?>
				          </select>
				          </span></td>
				      </tr>
					  <?php }?>
					  <?php
					  if($article_rows['functionName']=='每日行情'){
					  ?>
					  <tr bgcolor="#E4E4E4">
					    <td style="padding-left:15px;">查看级别：</td>
					    <td style="padding-left:10px;"><select name="grade">
					      <option value="4" <?php echo $article_rows['grade']==4?"selected='selected'":'' ?> >游客</option>
					      <option value="0" <?php echo $article_rows['grade']==0?"selected='selected'":'' ?>>普通会员</option>
					      <option value="1" <?php echo $article_rows['grade']==1?"selected='selected'":'' ?>>理事</option>
					      <option value="2" <?php echo $article_rows['grade']==2?"selected='selected'":'' ?>>理事长</option>
					      </select></td>
				      </tr>
					  <?php }?>
					  <script>
						cateName2 ='';
						if(typeof($('#cateName').val()) == 'undefined'){
							cateName2 = '';
						}else{
							/*cateName2 = selectCateName + ', ';*/
						}
						</script>
					  <tr bgcolor="#E4E4E4">
					    <td style="padding-left:15px;" width="9%">文章标题：</td>
					    <td width="40%" style="padding-left:10px;"><input type="text" name="articleTitle" id="articleTitle" style="width:90%;" value="<?php echo ($selectfunction?$_GET[articleTitle]:$article_rows['articleTitle']);?>"  onblur="if($('#functionName').val().length > 0){$('#newsTitle').val(this.value+', '+cateName2+$('#functionName').val()+' - '+'<?=$title_value['companyName']?>'); 
                        $('#newsKeywords').val($('#functionName').val());}" /></td>
					    
				      </tr>
					  <tr bgcolor="#E4E4E4">
					    <td height="27" style="padding-left:15px;">序号：</td>
					    <td style="padding-left:10px;"><input name="Num" id="Num" type="text" value="<?php echo $selectfunction?$_GET[Num]:$article_rows['Num'];?>" style="width:12%;" maxlength="6" />
					      日期：
					      <input name="articleDate" id="articleDate" type="text" style="width:22%;" value="<?=$article_rows['articleDate']?>" size="20"  />
 <label for="newproduct"  >推荐</label>
 <input id="recommend" name="clickNum" type="text" 
                          style="width:12%;" value="<?php echo  $article_rows['clickNum'];?>" size="1" maxlength="2"
                        />
<!-- <input name="articleBrief" type="hidden" style="width:100px;" value="<?php echo ($selectfunction?$_GET[articleBrief]:$article_rows['articleBrief']);?>" />
-->				        首页 <input id="flag" name="flag" type="text" 
                          style="width:12%;" value="<?php echo  $article_rows['flag'];?>" size="1" maxlength="2" ondblclick= 'this.value=(this.value==1?0:1)'/></td>
					     
				      </tr>
					  <tr bgcolor="#E4E4E4">
					    <td style="padding-left:15px;"></td>
					    <td style="padding-left:10px;"></td>
				      </tr>
					  <tr bgcolor="#E4E4E4">
					    <td style="padding-left:15px;">附加文件：</td>
					    <td colspan="2" style="padding-left:10px;" ><input type="file" name="downloadName" style="" onchange="articleform.ChangecatePagePic.value='yes';" />
					      <?=$article_rows['downloadName']==""?"":$article_rows['downloadName']." : ".(round($article_rows['downloadSize']/1000,2))."K   " ?>					      &nbsp;  pdf、word、excel文件 </td>
				      </tr>
					  <tr bgcolor="#E4E4E4">
					    <td style="padding-left:15px;" >跳转链接：</td>
					    <td bgcolor="" style="padding-left:10px;"  >
					      <input name="headerurl" id="headerurl" type="text" style="width:90%;" value="<?=$article_rows['headerurl']?>" size="20"  />
					    </span></span></td>
					    <td bgcolor=""  ><span class="hui">填写跳转链接将忽略下面简介和内容，直接打开链接页面</span></td>
				      </tr>
					  <tr bgcolor="#E4E4E4">
					    <td style="padding-left:15px;" >简介：</td>
					    <td >&nbsp;</td>
					    <td style="padding-right:20px;"><div align="right">
					      <input type="submit" value="确定" onclick="return checkSubmitForm(<?=$submitForm;?>);" />
					      <input type="reset" name="button" id="button" value="重置" />
					      </div></td>
				      </tr>
					  <tr bgcolor="#E4E4E4">
					    <td style="padding-left:50px;" colspan="3" ><textarea name="articleBrief" id="articleBrief" style="width:98%;height:130px;visibility:hidden;"><?=$article_rows['articleBrief']?>
					    </textarea>
				        <?=$promlv>1?$brief_tips:""?></td>
				      </tr>
					  <tr bgcolor="#E4E4E4">
					    <td height="20" colspan="3" align="left" valign="bottom"><span style="padding-left:15px;">内容:</span></td>
				      </tr>
					  <tr bgcolor="#E4E4E4">
					    <td height="25" colspan="3" align="left" valign="top" style="padding-left:50px;" > <textarea name="articleText" id="articleText" style="width:98%;height:400px;visibility:hidden;"><?php echo $htmlData; ?></textarea>
				        <?=$promlv>1?$detail_tips:""?>
					     </td>
				      </tr>
					  <tr bgcolor="#E4E4E4">
					    <td height="25" align="center">&nbsp;</td>
					    <td height="25" align="right"><input type="submit" value="确定" onclick="return checkSubmitForm(<?=$submitForm;?>);" />
					      <input type="reset" name="button2" id="button2" value="重置" /></td>
					    <td height="25" align="right" style="padding-right:20px;"><img src="images/shao.gif" alt="" />&nbsp;<a href="managearticle.php?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>">返回</a></td>
				      </tr>
				   </table>
					<br />
                 </form>
				</td>
			</tr>
		</table>
        
	</body>
</html>