<?php 
	require_once('_approot.php');
	$ls_msg="最新公告操作";

	$notice=$_POST['notice'];
	//编辑器中的内链与图片转换成相对路径
	$notice = editorPath('http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'], $notice);//内链
	$notice = editorPath($_SERVER['PHP_SELF'], $notice);//图片
	
	$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)){
		$notice = internal_keyword_link($notice, $in_rows['title'], $in_rows['url']);
	}
	
	$aTitle=$_POST['newsTitle'];
	$aKeywords=$_POST['newsKeywords'];
	$aDescription=$_POST['newsDescription'];
	
	$ls=$_POST['ls'];
	switch($ls)
	{
		case "insert":
			$update_sql=sprintf("update ls_information set inTitle=%s, inKeywords=%s, inDescription=%s, content=%s where inMenu=%s " ,
							GetSQLValueString($aTitle, "text"),
							GetSQLValueString($aKeywords, "text"),
							GetSQLValueString($aDescription, "text"),
							GetSQLValueString($notice, "text"),
							GetSQLValueString("notice", "text")
						);
			$update_query=$opendb->query($update_sql);
			$ls_msg="修改操作成功！";
			break;
	}
	
	//如果标题为空，默认取ls_config表中的数据
	$select_sql="select * from ls_config ";
	$select_query=$opendb->query($select_sql);
	$select_rows=mysqli_fetch_assoc($select_query);
	$companyName = $select_rows['companyName'];
	$siteKeywords = $select_rows['siteKeywords'];
	$siteDescription = $select_rows['siteDescription'];
	
	$information_sql="select * from ls_information where inMenu='notice' ";
	$information_query=$opendb->query($information_sql);
	$information_rows=mysqli_fetch_assoc($information_query);
	$htmlData = $information_rows['content'];
	
	$inTitle = $information_rows['inTitle'];
	$inKeywords = $information_rows['inKeywords'];
	$inDescription = $information_rows['inDescription'];
	
?>
<!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="css/style2.css" />   
	<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="notice"]', {
				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($('#newsTitle').val().length == 0){
						$('#newsTitle').val('<?=$companyName?>');
						$('#newsKeywords').val('<?=$siteKeywords?>');
						var newsDescription = '<?=$siteDescription?>';
						$('#newsDescription').val(newsDescription.substr(0, 267).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="98%" 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;">最新公告</font></div>
				</td>
			</tr>
			<tr>
				<td height="213" valign="top"><br>
				 <form name="newsform" enctype="multipart/form-data" method="post" action="ls_notice.php" >
					<input type="hidden" value="insert" name="ls">
					<table border="0" width="98%" align="center">
						<tr>
							<td>提示：<font color="#FF0000"><?php echo $ls_msg; ?></font></td>
							<td align="right">&nbsp; &nbsp; &nbsp; <?php if(!(strpos($_SERVER['HTTP_REFERER'],"managearticle")===false)){ ?> <a href="managearticle.php">返回</a><?php } ?></td>
						</tr>
					</table>
                    <table width="98%" border="0" align="center" cellpadding="3" cellspacing="1" style="background-color: #f0f0ee;">
                      <tr>
                        <td width="65%" valign="top"><table width="100%" border="0" align="center" cellpadding="3" cellspacing="1">
					  <tr bgcolor="#f0f0ee"> 
						<td height="37" align="center" ><b>公告内容</b></td>
					  </tr>
					  <tr bgcolor="#f4f4f4"> 
						<td><textarea name="notice" style="width:100%;height:400px;visibility:hidden;"><?php echo $htmlData; ?></textarea></td>
						</tr>
					</table></td>
                        <td width="35%" valign="top">
                        	<table border="0" width="100%" align="center" cellpadding="3" cellspacing="1">
                    	<tr bgcolor="#f0f0ee">
							<td height="37" colspan="8"><span style="float:right; padding-right:6px;"><button type="button" name="button" id="button" value="SEO"  onclick="
                            if(confirm('您确定要修改SEO设置吗？')){
                            $('#newsTitle').val('<?=$companyName?>');
						$('#newsKeywords').val('<?=$siteKeywords?>');
						var newsDescription = '<?=$siteDescription?>';
						$('#newsDescription').val(newsDescription.substr(0, 267).replace(/<[^>]+>/g,'').replace(/	/g, '').replace(/\n/g, ''));
	}else{
		return false;
	}"/>SEO</button></span><b style="padding-left:190px; line-height:25px;">SEO优化</b></td>
							<?php file_exists("widget/generalpics/head.php")?include "widget/generalpics/head.php" :"" ?>
						</tr>
						  <tr>
						    <td width="212" bgcolor="#f4f4f4" align="right" >本页标题<br /> Title</td>
						    <td width="760"  bgcolor="#f4f4f4"  ><textarea name="newsTitle" id="newsTitle" cols="65" rows="6"><?php echo $inTitle;?></textarea></td>
					      </tr>
						  <tr>
						    <td bgcolor="#f4f4f4" align="right" >本页关键字<br /> Keywords</td>
						    <td  bgcolor="#f4f4f4"  ><textarea name="newsKeywords" id="newsKeywords" cols="65" rows="6"><?php echo $inKeywords;?></textarea></td>
					      </tr>
						  <tr>
						    <td bgcolor="#f4f4f4" align="right">本页描述<br /> Description</td>
						    <td bgcolor="#f4f4f4"  ><textarea name="newsDescription" cols="65" rows="13" id="newsDescription"><?php echo $inDescription;?></textarea></td>
					      </tr>
					    </table></td>
                      </tr>
                      <tr>
                      	<td colspan="2" height="47" align="center"><button type="submit" value="保存" onClick="if($('#newsTitle').val().length <= 0){
						$('#newsTitle').val('<?=$companyName?>');
						$('#newsKeywords').val('<?=$siteKeywords?>');
						$('#newsDescription').val('<?=$siteDescription?>');
					}" >保存</button>
						  <label>
						    <button type="reset" name="button" id="button" value="重置" />重置</button>
				        </label></td>
                      </tr>
                    </table>
				</form>
                <br />
				</td>
			</tr>
		</table>
	</body>
</html>