<?php
/**
 *      [XCECP] (C) COLNET Inc.
 *      This is NOT a freeware, use is subject to license terms
 */
if(!defined("IN_QKWEB")){exit("Access Denied");}
class PostAction extends BaseAction{
	function index(){
		$act = getgpc("act","P");
		$inajax = getgpc("inajax","P");
		if($inajax==1){
			$ret=array('success'=>false,'message'=>'对不起，留言失败，请使用电话联系');
			if($act=="post" || $act=="add"){
				$c=true;
				$email = getgpc('email','P');if(!$email){$ret['message']='请填写电子邮件';$c=false;}
				$mobile = getgpc('mobile','P');if(!$mobile || !is_numeric($mobile) || strlen($mobile)!=11){$ret['message']='请填写11位数字手机号码';$c=false;}
				if($c){
					load_class("post");
					$pm = new PostModel();
					$ret['success'] = $pm->add($_POST);
					$ret['message']=$pm->msg;
				}
			}
			echo json_encode($ret);exit;
		}
		display();
	}
	function add(){
		global $siteConf;
		load_class('post');
		$pm = new PostModel();
		$inajax = getgpc("inajax","P");
		$act = getgpc('act','P');
		if($inajax==1){
			$c = true;
			$ret = array('success'=>false,'message'=>'参数不完整');
			if($act=='add'){
				$content = getgpc('content','P');$goodsId=getgpc('goodsId','P');
				if(!$content){$ret['message']='请填写留言内容';$c=false;}
				if($content && strlen($content)>420){$ret['message']='留言内容长度大于140个字';$c=false;}
				if($c){
					$ret['success'] = $pm->add($_POST);
				}
			}
			if($pm->msg){$ret['message']=$pm->msg;}
			echo json_encode($ret);
			exit;
		}
		$sm = new SeoModel();
		$pageInfo = $sm->pageInfo(10);
		$pageInfo['title'] = $pageInfo['title']?$pageInfo['title']:$siteConf['siteName'];
		assign("pageInfo",$pageInfo);
		display("post/add");
	}
	function feedback(){
		global $siteConf;
		load_class('post');
		$pm = new PostModel();
		$inajax = getgpc("inajax","P");
		$act = getgpc('act','P');
		if($inajax==1){
			$c = true;
			$ret = array('success'=>false,'message'=>'参数不完整');
			if($act=='add'){
				$content = getgpc('content','P');$goodsId=getgpc('goodsId','P');
				if(!$content){$ret['message']='请填写您的建议内容';$c=false;}
				if($content && strlen($content)>420){$ret['message']='建议内容长度大于140个字';$c=false;}
				if($c){
					$_POST['catId']=4;
					$ret['success'] = $pm->add($_POST);
				}
			}
			if($pm->msg){$ret['message']=$pm->msg;}
			echo json_encode($ret);
			exit;
		}
		$sm = new SeoModel();
		$pageInfo = $sm->pageInfo(10);
		$pageInfo['title'] = $pageInfo['title']?$pageInfo['title']:$siteConf['siteName'];
		assign("pageInfo",$pageInfo);
		display("post/feedback");
	}
}
?>