<?php 
	require_once('_approot.php');	
	$addcatestr=substr(str_replace(",","' and cateName!='",$defaultmenu),1)."' ";
	
	$ls_msg="添加文章操作";
	$fromInMenu=$_GET['fromInMenu'];
	$opendb=new mydb();
	$selectcate=str_replace("'","''",$_GET['selectcate']);
	$selectfunctionName=str_replace("'","''",$_GET['selectfunctionName']);
	if($selectfunctionName=="常见问题") echo "	<script>location='addfaq.php';</script>";
	if($selectfunctionName=="博客分类") echo "	<script>location='addblog.php';</script>";
	if($selectfunctionName=="新闻分类") echo "	<script>location='addnews.php';</script>";
	
	$submitForm = "'articleDate,functionName,Num,articleTitle','日期,栏目,序号,新闻标题'";
	
	$title_sql = "select * from ls_config";
	$title_query = $opendb->query($title_sql);
	$title_value = mysqli_fetch_assoc($title_query);
	/******/
	$sql = "select * from ls_admin";
	$rs = $opendb->query($sql);
	$list = mysqli_fetch_assoc($rs);
?>
<!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>
		selectCateName = "";
		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>
     <script>
        	$(document).ready(function(){
					$("#show").click(function(){
						$("#xianshi").attr("class","xianshi");
						var loading = "<div id='loading' align='center' style='margin-top:30px;'><img src='images/load.gif'/></div>";
						$("#innerH").empty().html(loading);
						$.post("checksina.php?ls=sinainfo",function(data){
							var ob = data;
							$("#loading").remove();
							$("#innerH").html(ob);
							
														
						});					
					});	
					$("#close").click(function(){
						$("#xianshi").attr("class","yincang");						
					});
			});
	</script>
    <style type="text/css">
<!--
.hui {
	color: #4B4B4B;
}
.hui {
	color: #5C5C5C;
}
-->
    </style>
	</head>

<body>
    
		<table width="99%" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#3c8dbc">
			<tr>
				<td height="28" background=""><div align="center"><font color="#ffffff"><strong>添加文章</strong></font></div>
				</td>
			</tr>
			<tr>
				<td height="213" valign="top" bgcolor="#f0f0ee" colspan="2" ><form name="articleform" enctype="multipart/form-data" method="post" action="savearticle.php?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>&fromInMenu=<?=$fromInMenu?>" >
		         <br />
		         <table border="0" width="96%" align="center">
					  <tr>
							<td>提示：<font color="#FF0000"><?php echo $ls_msg; ?>
							  <input type="hidden" value="insert" name="ls" />
						</font></td>
							<td align="right"><img src="images/shao.gif">&nbsp;<a href="managearticle.php"> 返回 </a></td>
						</tr>
					</table>
		         <table width="100%" border="0" align="center" cellpadding="3" cellspacing="0" bgcolor="#E4E4E4" style="padding-left:20px;">
		           <tr bgcolor="#E4E4E4">
		             <td style="padding-left:15px;">&nbsp;</td>
		             <td>&nbsp;</td>
		             <td colspan="2" rowspan="6"><table width="100%" border="0" cellpadding="4" cellspacing="0">
		               <tr bgcolor="#E4E4E4">
		                 <!--					        <td>微信微博同步</td>
-->
		                 <td colspan="2"><?php 
                            $sql = "select * from ls_admin where adminName='".$_SESSION['username']."'";
                            $rs = $opendb->query($sql);
                            $list = mysqli_fetch_assoc($rs); 
/*                            if($list['sina']!=''){?>
					          <input type="checkbox" name="sina" value="1" checked />
					          新浪微博【<a id="show" href="javascript:void(0)">查看</a>】</td>
					        <?php }else{ ?>
					        <a href="<?=$code_url?>" >点击绑定新浪微博账号</a>
					        <?php }*/
							
							?></td>
	                   </tr>
		               <tr>
		                 <td width="30%" bgcolor="" >标题 Title *</td>
		                 <td width="70%"><input name="newsTitle" id="newsTitle" type="text" value="" style="width:96%;" /></td>
	                   </tr>
		               <tr>
		                 <td bgcolor="" >关键字 Keywords</td>
		                 <td><input name="newsKeywords" id="newsKeywords" type="text" value="" style="width:96%;" /></td>
	                   </tr>
		               <tr>
		                 <td bgcolor=""  >描述 Description *<br /></td>
		                 <td><textarea name="newsDescription" style="width:96%;" rows="5" id="newsDescription"></textarea>
		                   <?=$promlv>1?$seo:""?></td>
	                   </tr>
		               <tr>
		                 <td bgcolor=""  >跳转链接：</td>
		                 <td bgcolor=""  ><span style="padding-left:10px;"><span style="padding-left:;">
		                   <input name="headerurl" id="headerurl" type="text" style="width:94%;" value="<?=$article_rows['headerurl']?>" size="20"  />
		                   </span></span></td>
	                   </tr>
		               <tr>
		                 <td colspan="2" bgcolor=""  ><span class="hui">填写跳转链接将忽略下面简介和内容，直接打开链接页面</span></td>
	                   </tr>
		               </table></td>
	               </tr>
		           <tr bgcolor="#E4E4E4">
		             <td width="9%" style="padding-left:15px;"><p>栏目</p></td>
		             <td width="45%"><input type="text" name="functionName" id="functionName" style="width:52%;" value="<?=$selectfunctionName?>" readonly />
		               <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),Num FROM ls_functioncates   where   functionName!='singlePages' 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='".str_replace("'","''",$news_rows2['functionName'])."' 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
				echo "<option value='".($select_rows2_num*5+5)."'>".$news_rows2['functionName']."</option>";

				
			}
			?>
	                   </select></td>
	               </tr>
		           <?php 
					  $cateName_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' 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>
		             <td><input type="text" name="cateName"  id="cateName" value="<?=$selectcate?>" style="width:52%;" readonly />
		               <select name="select" id="select"  onchange="if(this.options[this.selectedIndex].value!=0){articleform.cateName.value=this.options[this.selectedIndex].text;articleform.Num.value=this.value;selectCateName=this.options[this.selectedIndex].text;}">
		                 <option value="0">选择子栏目：</option>
		                 <?php 			$news_sql=$selectfunctionName?"SELECT distinct(cateName),Num FROM ls_functioncates   where functionName='".$selectfunctionName."' ".$addcatestr." order by Num":"SELECT distinct(cateName),Num FROM ls_functioncates   where functionName!='新闻分类'  ".$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 ='".$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)."'>".substr($news_rows2['cateName'],0,24)."</option>";

			}

			?>
	                   </select></td>
	               </tr>
		           <?php }?>
		           <?php
					  if($_GET['functionName']=='每日行情'){
					  ?>
		           <tr bgcolor="#E4E4E4">
		             <td style="padding-left:15px;">查看级别</td>
		             <td><select name="grade">
		               <option value="4">游客</option>
		               <option value="0">普通会员</option>
		               <option value="1">理事</option>
		               <option value="2">理事长</option>
		               </select></td>
	               </tr>
		           <?php }?>
		           <tr bgcolor="#E4E4E4">
		             <td height="45" style="padding-left:15px;">文章标题 *</td>
		             <script>
						cateName2 ='';
						if(typeof($('#cateName').val()) == 'undefined'){
							cateName2 = '';
						}else{
							/*cateName2 = selectCateName + ', ';*/
						}
						</script>
		             <td><input name="articleTitle" id="articleTitle" type="text"  style="width:88%;" 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="39" style="padding-left:15px;">附加文件</td>
		             <td><input type="file" name="downloadName" style="width:260px;" />
		               pdf,word,excel等</td>
	               </tr>
		           <tr bgcolor="#E4E4E4">
		             <td height="38" style="padding-left:15px;">序 号</td>
		             <td><?php 						  	if($selectcate==''&&$selectfunctionName==''){$select_sql2="select Num from ls_article  order by Num desc  ";}
							else
							{
								if($selectcate==''&&$selectfunctionName!=''){$select_sql2="select Num from ls_article where functionName='".$selectfunctionName."'  order by Num desc   ";}
								else
								{$select_sql2="select Num from ls_article where functionName='".$selectfunctionName."' and cateName='".$selectcate."' 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
						?>
		               <input name="Num" id="Num" type="text"  value="<?=$_GET['Num']==''?($select_rows2_num*5+5):$_GET['Num']?>"  style="width:12%;" maxlength="6" />
		               日期：
		               <input name="articleDate" id="articleDate" type="text"  style="width:12%;" value="<?=date('y-m-d')?>" size="20"  />
<!--		               <input name="articleBrief" type="hidden" style="width:100px;" />
-->		               <span style="padding-left:10px;">
		                 <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 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)'/>
	                   </span></td><td>&nbsp;</td>
	               </tr>
		           <tr bgcolor="#E4E4E4">
		             <td height="39" bgcolor="#E4E4E4" style="padding-left:15px;">简介 *</td>
		             <td style="padding-left: px;"></td>
		             <td colspan="2" align="right" bgcolor="#E4E4E4" style="padding-right:20px;"><input type="submit" value="添加"  onclick="if( $('#newsDescription').val()== '' && $('#articleText').val()!=''){
                        	$('#newsDescription').val($('#articleText').val().substr(0, 86).replace(/<[^>]+>/g,'').replace(/	/g, '').replace(/\n/g, ''));
                        }" />
		               <input type="reset" name="button" id="button" value="重置" /></td>
	               </tr>
		           <tr>
		             <td colspan="4"><textarea name="articleBrief" id="articleBrief" style="width:98%;height:130px;visibility:hidden;"></textarea>
                     <?=$promlv>1?$brief_tips:""?></td>
	               </tr>
		           <tr bgcolor="#E4E4E4">
		             <td height="37" colspan="4" align="left"><span style="padding-left:15px;">内容 *</span></td>
	               </tr>
		           <tr bgcolor="#E4E4E4">
		             <td height="37" colspan="4" align="left"><textarea name="articleText" id="articleText" style="width:98%;height:370px;visibility:hidden;"><?php echo $htmlData ?></textarea>
	                 <?=$promlv>1?$detail_tips:""?></td>
	               </tr>
		           <tr bgcolor="#E4E4E4">
		             <td height="37" colspan="2" align="right"><input type="submit" value="添加" onclick="return checkSubmitForm(<?=$submitForm;?>);" />
		               <input type="reset" name="button2" id="button2" value="重置" /></td>
		             <td height="37" colspan="2" align="right"  style="padding-right:20px;"><a href="managearticle.php?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>">返回</a></td>
	               </tr>
	              </table>
		         <br />
                 </form>
				</td>
			</tr>
		</table>

	</body>
</html>