<?php
if(!defined('IN_GATEWEI')) {
	exit('access denied');
}
if($action=='save'){
if($ipost=='baseset'){
		$newsettings['sitename'] = cutstr(trim(ghtmlspecialchars($newsettings['sitename'])), 50 ,'');
		$newsettings['siteurl'] = ghtmlspecialchars($newsettings['siteurl']);
		$newsettings['sitekeywords'] = cutstr(trim(ghtmlspecialchars($newsettings['sitekeywords'])), 50 ,'');
		$newsettings['sitelogo'] = trim(ghtmlspecialchars($newsettings['sitelogo']));
		$newsettings['siteicp'] = cutstr(trim(ghtmlspecialchars($newsettings['siteicp'])), 70 ,'');
		$newsettings['companyname'] = cutstr(trim(ghtmlspecialchars($newsettings['companyname'])), 50,'');
		$newsettings['companyaddress'] = cutstr(trim(ghtmlspecialchars($newsettings['companyaddress'])), 50,'');
}
	if($ipost=='systemset'){
			$newsettings['allowedauthcode'] = bindec(intval($newsettings['allowedauthcode'][6]).intval($newsettings['allowedauthcode'][5]).intval($newsettings['allowedauthcode'][4]).intval($newsettings['allowedauthcode'][3]).intval($newsettings['allowedauthcode'][2]).intval($newsettings['allowedauthcode'][1]));

			$upload_max_filesize=ini_get("upload_max_filesize");
			$inisize=substr($upload_max_filesize,0,strpos($upload_max_filesize,'M'));
			$inisize=intval($inisize);
			$newsettings['attachmaxsize']=intval($newsettings['attachmaxsize']);
			if($newsettings['attachmaxsize']<0 || $newsettings['attachmaxsize']>$inisize){
						gadminmessage("必须输入整数且不能大于系统设置的附件上传值".$upload_max_filesize);
					}
			$newsettings['allowedregister']=intval($newsettings['allowedregister']);

			$newsettings['registerkeyword']= "{{".str_replace(array("\r\n","\n") , array(";",";") , $newsettings['registerkeyword'])."}}";
			$newsettings['allowedemailmsg']=intval($newsettings['allowedemailmsg']);

			if($newsettings['allowedemailmsg']){
				$newsettings['emailtitle']=trim($newsettings['emailtitle']);
				$newsettings['emailmsg']=trim(str_replace(array("\r\n","\n") , array("","") , $newsettings['emailmsg']));
			}
			$newsettings['registerinfomore']=intval($newsettings['registerinfomore']);
			$newsettings['forumisclosed']=intval($newsettings['forumisclosed']);
		foreach($nav as $key => $val){
			if($val['type']=='forum' && $val['id']==0){
					$nav[$key]['title']=$newsettings['forumname'];
					break;
				}
		}
		ksort($nav);
		w2navigation($nav,'update');
	}

	foreach ($newsettings as $key => $val){
		$db->query("REPLACE INTO g_settings (var, val) VALUES ('$key', '$val')");
	}
	w2setting();
	writelog($userid."修改基础设置、系统设置成功");
	gadminmessage('设置成功',"siteadmin.php?iframe=setting&ipost=".$ipost,1);
}

	$query = $db->query("SELECT * FROM g_settings");
	while($setting = $db->fetch_array($query)) {
	$settings[$setting['var']] = $setting['val'];
	}
?>
<?php if($ipost=='baseset'){?>
<form method="post" action="siteadmin.php?iframe=setting&ipost=baseset&action=save">
<table>
<caption>网站基础信息设置</caption>
  <tr>
    <td  width="40%"><span>网站名称</span></td>
    <td ><input name="newsettings[sitename]" type="text" class="formtext" value="<?php echo $settings['sitename']?>"></td>
  </tr>
  <tr>
    <td><span> 网站URL: </span></td>
    <td ><input name="newsettings[siteurl]" type="text" class="formtext" value="<?php echo $settings['siteurl']?>"></td>
  </tr>
   <tr>
    <td><span>Meta关键字(仅主页显示):</span></td>
    <td ><input name="newsettings[sitekeywords]" type="text" class="formtext" value="<?php echo $settings['sitekeywords']?>"></td>
  </tr>
  <tr>
    <td><span>网站徽标:</span></td>
    <td ><input name="newsettings[sitelogo]" type="text" class="formtext" value="<?php echo $settings['sitelogo']?>"></td>
  </tr>
  <tr>
    <td><span>ICP备案号:</span></td>
    <td ><input name="newsettings[siteicp]" type="text" class="formtext" value="<?php echo $settings['siteicp']?>"></td>
  </tr>
     <tr>
          <td colspan="2">
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
	      </td>
   </tr>
     <tr>
    <td ><span>公司名称: </span></span></td>
    <td ><input name="newsettings[companyname]" type="text" class="formtext" value="<?php echo $settings['companyname']?>"></td>
  </tr>
  <tr>
    <td ><span>公司地址: </span></td>
    <td ><input name="newsettings[companyaddress]" type="text" class="formtext" value="<?php echo $settings['companyaddress']?>"></td>
  </tr>
  <tr>
    <td ><span>公司邮编:</span></td>
    <td ><input name="newsettings[companyzip]" type="text" class="formtext" value="<?php echo $settings['companyzip']?>"></td>
  </tr>
  <tr>
    <td ><span>公司电话(填写多个电话号码以逗号隔离): </span></td>
    <td ><input name="newsettings[companyphone]" type="text" class="formtext" value="<?php echo $settings['companyphone']?>"></td>
  </tr>
   <tr>
    <td ><span>公司传真: </span></td>
    <td ><input name="newsettings[companyfax]" type="text" class="formtext" value="<?php echo $settings['companyfax']?>"></td>
  </tr>
   <tr>
    <td ><span>联系邮箱: </span></td>
    <td ><input name="newsettings[companyemail]" type="text" class="formtext" value="<?php echo $settings['companyemail']?>"></td>
  </tr>
     <tr>
    <td ><span>联系QQ(填写多个QQ号以逗号隔离): </span></td>
    <td ><input name="newsettings[companyqq]" type="text" class="formtext" value="<?php echo $settings['companyqq']?>"></td>
  </tr>
    <tr>
    <td ><span>招聘邮箱: </span></td>
    <td ><input name="newsettings[companyhremail]" type="text" class="formtext" value="<?php echo $settings['companyhremail']?>"></td>
  </tr>
     <tr>
          <td colspan="2">
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
	      </td>
   </tr>
</table>
<div id="submitdiv"><input name="settingsubmit" type="submit" value="提&nbsp;&nbsp;交"></div>
</form>
<?php }
?>

<?php if($ipost=='systemset'){?>
<form method="post" action="siteadmin.php?iframe=setting&ipost=systemset&action=save">
<table>
<caption>系统设置</caption>

 <tr>
    <th width="40%"><span>启用验证码功能</span></th>
	<th width="60%"><span>启用</span></th>
    <?php $value=sprintf('%06b', $settings['allowedauthcode']);?>
  <tr>
      <td> <span>用户登录时要求输入验证码</span></td>
	<td ><span><input type="checkbox" name="newsettings[allowedauthcode][1]"  value="1"	
	<?php echo $value{5}?'checked':'';?>> </span></td>
  </tr>
  <tr>
      <td> <span>用户注册时要求输入验证码</span></td>
	<td ><span><input type="checkbox" name="newsettings[allowedauthcode][2]"  value="1"	
	<?php echo $value{4}?'checked':'';?>> </span></td>
  </tr>
   <tr>
      <td> <span>发布论坛主题时要求输入验证码</span></td>
	<td ><span><input type="checkbox" name="newsettings[allowedauthcode][3]"  value="1"	
	<?php echo $value{3}?'checked':'';?>> </span></td>
  </tr>
      <tr>
    <td> <span>回复主题时要求输入验证码</span></td>
	<td ><span><input type="checkbox" name="newsettings[allowedauthcode][4]"  value="1"	
	<?php echo $value{2}?'checked':'';?>
	></span></td>
  </tr>
    <tr>
    <td> <span>发表文章评论时要求输入验证码</span></td>
	<td ><span><input type="checkbox" name="newsettings[allowedauthcode][5]" value="1"	
	<?php echo $value{1}?'checked':'';?>
	></span></td>
  </tr>
      <tr>
    <td> <span>发表产品评论时被要求输入验证码</span></td>
	<td ><span><input type="checkbox" name="newsettings[allowedauthcode][6]" value="1" 
	<?php echo $value{0}?'checked':'';?>
	></span></td>
  </tr>
     		<tr>
          <td colspan="2">&nbsp;
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
			 
	      </td>
   </tr>

 <tr>
    <th colspan="2"><span>附件设置</span></th>
  </tr>
  <tr>
    <td><span> 允许附件大小</span></td>
    <td ><span><input type="text" name="newsettings[attachmaxsize]" class="formtext" value="<?php echo $settings['attachmaxsize']?>"></span>&nbsp;MB</td>
  </tr>
    <tr>
    <td><span> 允许附件类型</span></td>
    <td ><span><input type="text" name="newsettings[attachallowedextname]" class="formtext" 
	value="<?php echo $settings['attachallowedextname']?>"></span></td>
	<td >&nbsp;</td>
  </tr>
  		<tr>
          <td colspan="2">&nbsp;
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
			 
	      </td>
   </tr>

    <tr>
    <th width="40%"><span>系统Email设置</span></th>
	<th width="60%">&nbsp;</th>
  <tr>
   <tr>
		<td ><span>SMTP服务器: </span></td>
		<td ><span><input name="newsettings[smtpserver]" type="text" class="formtext" value="<?php echo $settings['smtpserver']?>"></span></td>
   </tr>
	<tr>
		<td ><span>Email地址: </span></td>
		<td ><span><input name="newsettings[emailaddress]" type="text" class="formtext" value="<?php echo $settings['emailaddress']?>"></span></td>
	</tr>

  <tr>
		<td ><span>Email登陆账号: </span></td>
		<td ><span><input name="newsettings[emailid]" type="text" class="formtext" value="<?php echo $settings['emailid']?>"></span></td>
  </tr>

  <tr>
		<td ><span>Email登录密码: </span></td>
		<td ><span><input name="newsettings[emailpwd]" type="password" class="formtext" value="<?php echo $settings['emailpwd']?>"></span></td>
  </tr>

  <tr>
          <td colspan="2">&nbsp;
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div> 
	      </td>
   </tr>
	<tr>
    <th colspan="2"><span>用户注册</span></th>
  </tr>
  <tr>
    <td><span> 允许用户注册</span></td>
    <td ><span>
	<input type="checkbox" name="newsettings[allowedregister]" value="1" 
	<?php echo $settings['allowedregister']?'checked':'';?>></span></td>
  </tr>
  <tr>
    <td><span> 注册文件名<span class="font_12">(须修改服务器上相应的文件名称)</span></span></td>
    <td ><span><input type="text" name="newsettings[registerfilename]" class="formtext" value="<?php echo $settings['registerfilename']?>"></span></td>
  </tr>
  <tr>
    <td><span> 注册链接文字</span></td>
    <td ><span>
	<input type="text" name="newsettings[registerlinkword]" class="formtext" value="<?php echo $settings['registerlinkword']?>">
	</td>
  </tr>

  <tr>
		<td><span>注册时是否显示高级选项</span></td>
		<td ><span><input type="checkbox" name="newsettings[registerinfomore]" value="1" 	<?php echo $settings['registerinfomore']?'checked':'';?>>
		</span></td>
  </tr>
<?php 
  $settings['registerkeyword']=str_replace(array("{{","}}",";"), array("","","\n"), $settings['registerkeyword']);
  ?>
  <tr>
    <td valign="top"><span>用户信息保留关键字</span></td>
    <td ><span><textarea name="newsettings[registerkeyword]" class="formtextarea"><?php echo $settings['registerkeyword']?></textarea></span></td>
  </tr>

  <tr>
    <td> <span>发送Email信息</span></td>
	<td ><span><input type="checkbox" name="newsettings[allowedemailmsg]" value="1" 
	<?php echo intval($allowedemailmsg)?'checked':'';?>  id="emailshowway" onclick="showemailtext()"></span></td>
  </tr>

	<tbody id="emailtext" <?php if(!$allowedemailmsg){?>style="display:none;"<?php }?>>
     <tr >
    <td><span>Email信息标题</span> </td>
	<td ><span><input type="text" name="newsettings[emailtitle]" class="formtext" value="<?php echo $settings['emailtitle']?>" ></span></td>
     </tr>
   <tr>
    <td valign="top"> <span>Email信息内容</span>
	<br /><span class="font_12">欢迎Email信息的标题、内容均支持使用如下变量替换</span>
	<br /><span class="font_12">{username} : 用户名</span>
	<br /><span class="font_12">{sitename} : 站点名称</span>
	<br /><span class="font_12">{username} : 用户名</span>
	<br /><span class="font_12">{adminemail} : 管理员email</span>
</td>
	<td ><span><textarea name="newsettings[emailmsg]" class="formtextarea">
	<?php echo $settings['emailmsg']?>
	</textarea></span></td>
  </tr>
   </tbody>

  		<tr>
          <td colspan="2">&nbsp;
	         <div id="hr_u"> </div>
	         <div id="hr_d"> </div>
			 
	      </td>
   </tr>

    <tr>
    <th width="40%"><span>论坛设置</span></th>
	<th width="60%">&nbsp;</th>
  <tr>
   <tr>
		<td ><span>论坛名称: </span></td>
		<td ><span><input name="newsettings[forumname]" type="text" class="formtext" value="<?php echo $settings['forumname']?>"></span></td>
   </tr>
	<tr>
		<td ><span>论坛关闭: </span></td>
		<td ><span><input type="checkbox" name="newsettings[forumisclosed]" value="1" 	<?php echo $forumisclosed?'checked':'';?>></span></td>
	</tr>
  <tr>
		<td ><span>论坛关闭原因: </span></td>
		<td ><span><textarea name="newsettings[forumclosedreason]" type="text" class="formtextarea" ><?php echo $settings['forumclosedreason']?></textarea></span></td>
  </tr>
     <tr>
    <td  colspan="2"><div id="submitdiv"><input name="settingsubmit" type="submit" value="提&nbsp;&nbsp;交" ></div></td>
    </tr>

</table>

</form>
<?php
			  }
?>


<SCRIPT LANGUAGE="JavaScript">
function showemailtext(){
if($('emailshowway').checked == true){
	$('emailtext').style.display = "";
}else{
	$('emailtext').style.display = "none";
	}
}
</SCRIPT>