<?php
if(@$_POST["stype"]=="sys"){
	//print_r($_POST);
	//print_r($sysinfo);
	$Ptitle = $_POST["title"];
	$Pkeyword = $_POST["keyword"];
	$Pdescription = $_POST["description"];
	$jsonarr = $_POST;
	unset($jsonarr["title"]);		//删除数组成员
	unset($jsonarr["keyword"]);		//删除数组成员
	unset($jsonarr["description"]);	//删除数组成员
	//print_r($jsonarr);
	for($temp = 0;$temp < count($custom);$temp++){
		$nowname = $custom[$temp]["cename"];
		$custom[$temp]["cvalue"] = urlencode($jsonarr[$nowname]);
	}
	$custom = json_encode($custom);
	$sql = "UPDATE `".$qz."setting` SET `sitename` = '".$Ptitle."',`keyword` = '".$Pkeyword."',`description` = '".$Pdescription."',`custom` = '".$custom."' WHERE `id` =".$sysinfo["id"];
	mysql_query($sql);
	Msg("设置已更新");
	GoUrl("?m=system");
	die;
}elseif(@$_POST["stype"]=="email"){
	$mailpeizhi = json_encode($_POST);
	$sql = "UPDATE `".$qz."setting` SET `mail` = '".$mailpeizhi."' WHERE `id` =".$sysinfo["id"];
	mysql_query($sql);
	Msg("配置已保存");
	GoUrl("?m=system&a=mail");
	die;
}
?>
    <div class="main-wrap">
        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="/think/admin">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">系统设置</span></div>
        </div>
        <div class="result-wrap">
<!--邮件设置 开始-->
		<div id="emaili" style="display:none;">
			<form action="" method="post" id="myform" name="myform">
				<input type="hidden" name="stype" value="email" />
                <div class="config-items">
                    <div class="config-title">
                        <span><i class="icon-font">&#xe00e;</i> 邮件设置</span>
                    </div>
                    <div class="result-content">
                        <table width="100%" class="insert-tab">
                            <tbody>
                                <tr>
                                    <th width="160px"><i class="require-red">*</i>状态：</th>
                                    <td><select name="state" class="common-text select1">
											<option value="true">开启</option>
											<option value="false" <?php if($mail['state']=="false"){echo 'selected="selected"';}?>>关闭</option>
										</select></td>
                                </tr>
                                <tr>
                                    <th><i class="require-red">*</i>SMTP服务器：</th>
                                    <td><input type="text" id="" value="<?php echo $mail['server'];?>" size="85" name="server" class="common-text"></td>
                                </tr>
                                <tr>
                                    <th><i class="require-red">*</i>邮箱账号：</th>
                                    <td><input type="text" id="" value="<?php echo $mail['account'];?>" size="85" name="account" class="common-text"> 发件邮箱地址</td>
                                </tr>
                                <tr>
                                    <th><i class="require-red">*</i>邮箱密码：</th>
                                    <td><input type="password" id="" value="<?php echo $mail['password'];?>" size="85" name="password" class="common-text"> 发件邮箱密码</td>
                                </tr>
                                <tr>
                                    <th><i class="require-red">*</i>接收邮箱：</th>
                                    <td><input type="text" id="" value="<?php echo $mail['recaccount'];?>" size="85" name="recaccount" class="common-text"> 多个邮箱用英文逗号分割</td>
                                </tr>
                                    <th></th>
                                    <td>
                                        <input type="submit" value="保存配置" class="btn btn-primary btn6 mr10">
										<input type="button" value="返回" onclick="$('#emaili').hide();$('#sysi').show();" class="btn btn6">
                                    </td>
                                </tr>
                            </tbody></table>
                    </div>
                </div>

            </form>
		</div>
<!--邮件设置 结束-->
		<div id="sysi">
            <form action="" method="post" id="myform" name="myform">
				<input type="hidden" name="stype" value="sys" />
                <div class="config-items">
                    <div class="config-title">
                        <span><i class="icon-font">&#xe00a;</i> 网站信息设置</span>
						<span style="float:right"><a class="btn btn3" href="javascript:;" onclick="$('#emaili').show();$('#sysi').hide();">邮件配置</a> <a class="btn btn3" href="?m=custom">自定义变量</a></span> 
                    </div>
                    <div class="result-content">
                        <table width="100%" class="insert-tab">
                            <tbody>
                                <tr>
                                    <th><i class="require-red">*</i>站点标题：</th>
                                    <td><input type="text" id="" value="<?php echo $sysinfo['sitename'];?>" size="85" name="title" class="common-text"></td>
                                </tr>
                                <tr>
                                    <th><i class="require-red">*</i>关键字：</th>
                                    <td><input type="text" id="" value="<?php echo $sysinfo['keyword'];?>" size="85" name="keyword" class="common-text"></td>
                                </tr>
                                <tr>
                                    <th><i class="require-red">*</i>描述：</th>
                                    <td><textarea type="text" size="85" name="description" class="common-text" style="width:616px;height:80px; margin-top:8px"><?php echo $sysinfo['description'];?></textarea></td>
                                </tr>
<?php
	for($temp = 0;$temp < count($custom);$temp++){
		$ctype = $custom[$temp]["ctype"];
		$cname = urldecode(@$custom[$temp]["cname"]);
		$cename = urldecode(@$custom[$temp]["cename"]);
		$cvalue = urldecode(@$custom[$temp]["cvalue"]);
		if($ctype=="text"){
			$string = '<tr><th><i class="require-red">*</i>'.$cname.'：</th><td><input type="text" id="" value="'.$cvalue.'" size="85" name="'.$cename.'" class="common-text"></td></tr>';
			echo $string;
		}elseif($ctype=="img"){
			$string = '<tr><th><i class="require-red">*</i>'.$cname.'：</th><td><input type="text" id="img'.$temp.'" value="'.$cvalue.'" size="85" name="'.$cename.'" class="common-text"> &nbsp; <input type="button" value="上传图片" onclick="upImage(\'img'.$temp.'\')" class="btn btn6"></td></tr>';
			echo $string;
		}
	
	}
?>
                                <tr>
                                    <th></th>
                                    <td>
                                        <input type="submit" value="提交" class="btn btn-primary btn6 mr10">
                                        <input type="button" value="返回" onclick="history.go(-1)" class="btn btn6">
                                    </td>
                                </tr>
                            </tbody></table>
                    </div>
                </div>

            </form>
		</div>

        </div>
    </div>
    <!-- 配置文件 -->
    <script type="text/javascript" src="UEditor/ueditor.config.js"></script>
    <!-- 编辑器源码文件 -->
    <script type="text/javascript" src="http://apps.bdimg.com/libs/ueditor/1.4.3.1/ueditor.all.js"></script>
    <!-- 实例化编辑器 -->
	<script type="text/plain" id="j_ueditorupload" style="height:5px;display:none;"></script>
    <script>
	var ainputid;
      //实例化编辑器
      var o_ueditorupload = UE.getEditor('j_ueditorupload',
      {
        autoHeightEnabled:false
      });
      o_ueditorupload.ready(function ()
      {
	
	o_ueditorupload.hide();//隐藏编辑器
	
	//监听图片上传
	o_ueditorupload.addListener('beforeInsertImage', function (t,arg)
	{
          //alert('这是图片地址：'+arg[0].src);
		$("#"+ainputid).val(arg[0].src);
	});
      });
      
      //弹出图片上传的对话框
      function upImage(inputid)
      {
		ainputid = inputid;
        var myImage = o_ueditorupload.getDialog("insertimage");
        myImage.open();
      }
    </script>
<?php
if($a=="mail"){
	echo "<script>$('#emaili').show();$('#sysi').hide();</script>";
}
?>