<?php 
	session_start(); 
	require_once('inc/conn.php');
	require_once('inc/constant.php');
	require_once('inc/ls_syscode.php');
	require_once('inc/check.php');
	$ls_msg="添加文章操作";
	$opendb=new mydb();
	require_once('inc/char_set.php');
	$selectcate=$_GET['selectcate'];
	$selectfunctionName=$_GET['selectfunctionName'];
	
	$title_sql = "select * from ls_config";
	$title_query = $opendb->query($title_sql);
	$title_value = mysql_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.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"]', {
            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($('#articleTitle').val().length >= 0){
						$('#newsDescription').val(($('#articleText').val().substr(0, 86).replace(/<[^>]+>/g,'').replace(/	/g, '').replace(/\n/g, ''));
					}*/
					 if($('#articleText').val().length >= 0){
                        	$('#newsDescription').val($('#articleText').val().substr(0, 86).replace(/<[^>]+>/g,'').replace(/	/g, '').replace(/\n/g, ''));
				},
            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>
	</head>

	<body>
		<table width="96%" 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>
				 <form name="articleform" enctype="multipart/form-data" method="post" action="savearticle.php?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>"  onSubmit="return checkSubmitForm('articleDate,cateName,functionName,Num,articleTitle','日期,子栏目,栏目,序号,新闻标题');">
					<input type="hidden" value="insert" name="ls">
					<table border="0" width="96%" 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?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>"><u>返回</u></a></td>
						</tr>
					</table>
					<table width="96%" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
					 
					  <tr bgcolor="#B9DAFF"> 
						<td height="28" colspan="3"></td>
					  </tr>
					  <tr bgcolor="#f4f4f4">
						<td width="9%" style="padding-left:15px;">栏目：</td>
						<td width="49%"><input type="text" name="functionName" id="functionName" style="width:150px;" 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>
							<?
			$news_sql="SELECT distinct(functionName) FROM ls_functioncates   where functionName!='新闻分类' and functionName!='博客分类' and functionName!='常见问题' and functionName!='singlePages' order by Num";//count the error by searchtype
			$news_query=$opendb->query($news_sql);
			while($news_rows2=mysql_fetch_assoc($news_query))
		  	{
				
				$select_sql2="select Num from ls_article where functionName='".$news_rows2['functionName']."' and functionName!='新闻分类' and functionName!='博客分类' and functionName!='常见问题' and functionName!='singlePages'   order by Num desc ";
				//echo $select_sql2;
				$select_query2=$opendb->query($select_sql2);
				$select_rows2_num=mysql_num_rows($select_query2); //总数
				$select_rows2=mysql_fetch_assoc($select_query2);
				//$select_rows2['Num']+5
				echo "<option value=".($select_rows2_num*5+5).">".$news_rows2['functionName']."</option>";

				
			}
			?>
						  </select>
						</span></td>
						<td width="42%" rowspan="4"><table border="0" width="100%">
						  <tr>
						    <td bgcolor="#f4f4f4" >标题 Title</td>
						    <td><input name="newsTitle" id="newsTitle" type="text" value="" size="70" /></td>
					      </tr>
						  <tr>
						    <td bgcolor="#f4f4f4" >关键字 Keywords</td>
						    <td><input name="newsKeywords" id="newsKeywords" type="text" value="" size="70" /></td>
					      </tr>
						  <tr>
						    <td bgcolor="#f4f4f4"  >描述 Description<br /></td>
						    <td><textarea name="newsDescription" cols="72" rows="3" id="newsDescription"></textarea></td>
					      </tr>
					    </table></td>
					  </tr>
					  <tr bgcolor="#f4f4f4">
						<td style="padding-left:15px;">子栏目：</td>
						<td><input type="text" name="cateName"  id="cateName" value="<?=$selectcate?>" style="width:150px;" readonly>
							<span style="padding-left:20px;">
							<select name="select2" id="select2"  onChange="articleform.cateName.value=this.options[this.selectedIndex].text;articleform.Num.value=this.value;">
							  <option value="0">请选择一个子栏目：</option>
							  <?
			$news_sql=$selectfunctionName?"SELECT distinct(cateName) FROM ls_functioncates   where functionName='".$selectfunctionName."' order by Num":"SELECT distinct(cateName) FROM ls_functioncates   where functionName!='新闻分类' and functionName!='博客分类' and functionName!='常见问题' and functionName!='singlePages' order by Num";//count the error by searchtype
			echo $news_sql;
			$news_query=$opendb->query($news_sql);
			while($news_rows2=mysql_fetch_assoc($news_query))
		  	{
				$select_sql2="select Num from ls_article where functionName='".$selectfunctionName."' and cateName ='".$news_rows2['cateName']."' and functionName!='新闻分类' and functionName!='博客分类' and functionName!='常见问题' and functionName!='singlePages' order by Num desc  ";
				echo $select_sql2;
				//echo $select_sql2;
				$select_query2=$opendb->query($select_sql2);
				$select_rows2_num=mysql_num_rows($select_query2); //总数
				$select_rows2=mysql_fetch_assoc($select_query2);
				//$select_rows2['Num']+5
				
				echo "<option value=".($select_rows2_num*5+5).">".$news_rows2['cateName']."</option>";

			}

			?>
							</select>
						  </span></td>
                      </tr>
                       <script>
						cateName2 ='';
						if(typeof($('#cateName').val()) == 'undefined'){
							cateName2 = '';
						}else{
							/*cateName2 = selectCateName + ', ';*/
						}
						</script>
					  <tr bgcolor="#f4f4f4">
					    <td style="padding-left:15px;">文章标题：</td>
					    <td><input name="articleTitle" id="articleTitle" type="text"   style="width:500px;" onblur="if($('#functionName').val().length > 0){$('#newsTitle').val(this.value+', '+cateName2+$('#functionName').val()+' - '+'<?=$title_value['companyName']?>'); 
                        $('#newsKeywords').val(cateName2+$('#functionName').val());}" /></td>
				      </tr>
					  <tr bgcolor="#f4f4f4">
						<td style="padding-left:15px;">序号：</td>
						<td><?
						  	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_rows2_num=mysql_num_rows($select_query2); //总数
								$select_rows2=mysql_fetch_assoc($select_query2);
							}
							//$select_rows2['Num']+5
						?>
                          <input name="Num" id="Num" type="text" style="width:40px;" value="<?=$_GET['Num']==''?($select_rows2_num*5+5):$_GET['Num']?>" size="6" maxlength="6" />
日期：
<input name="articleDate" id="articleDate" type="text" style="width:90px;" value="<?=date('y-m-d')?>" size="20"  /></td>
                      </tr>
					  <tr bgcolor="#f4f4f4"> 
						<td style="padding-left:15px;">文章内容：</td>
						<td style="padding-left:15px;">&nbsp;</td>
						<td align="right" style="padding-left:15px;"><input type="submit" value="添加" />
                        <input type="reset" name="button" id="button" value="重置" /></td>
					  </tr>
					  <tr>
					  	<td colspan="3"><!--
					  	<input type="hidden" name="articleText" value="">
							<iframe ID="eWebEditor1" src="ewebeditor/ewebeditor.php?id=articleText&style=coolblue" frameborder="0" scrolling="no" width="100%" HEIGHT="350"></iframe>-->	
                            <textarea name="articleText" id="articleText" style="width:100%;height:400px;visibility:hidden;"></textarea>
						</td>
					  </tr>
					  <tr bgcolor="#B9DAFF"> 
						<td height="25" colspan="3" align="center"><u style=" float:right;"><a href="managearticle.php?selectcate=<?=$selectcate?>&selectfunctionName=<?=$selectfunctionName?>">返回</a></u><input type="submit" value="保存" onclick="if($('#articleTitle').val().length >= 0){
						$('#newsDescription').val($('#articleText').val().substr(0, 86).replace(/<[^>]+>/g,'').replace(/	/g, '').replace(/\n/g, ''));
					}"> &nbsp; 
					    <input type="reset" name="button2" id="button2" value="重置" /></td>
					  </tr>
					</table>
					<br />
                 </form>
				</td>
			</tr>
		</table>
	</body>
</html>