<?php
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/cmsask.php');
require($netsFileConfig['sysCoreRoot'].'Cache/DbDescription/cmsaskcont.php');
require($netsFileConfig['sysCoreRoot'].'Inc/m_Cms/Ask/cmsask.php');

class PaDefault extends CustomPage {
	public $ssetParid=2;
	
	public function PaDefault(){
		$this->CustomPage();
	}
	public function OnPInitial(){
		$this->sTable=array(
			array('sttTableName'=>$this->sysTableHead.'cmsask','sttColumnHead'=>'cast'),
			array('sttTableName'=>$this->sysTableHead.'cmsaskcont','sttColumnHead'=>'casct'),);
		$this->sUiName='User/cms/ask_public';
		
	}
	public function OnBInitial(){
		$this->sMetaTitle='发布我的问题';
		$this->sMessage='何用 当页上的选择一张图片，并将其保存，并显示在本页上';
		$this->getUser('1,2,3,4,5,');
		$this->sApp=new cmsask($this->sConnString);
		
		//Parid
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=' SELECT A.casgtID,A.casgtName,A.casgtParid 
			FROM '.$this->sysTableHead.'cmsaskgroup AS A
			WHERE 1=1 AND A.casgtRecycle=0 AND A.casgtChecked>1 AND A.casgtParid={Nets.Parid}
			ORDER BY A.casgtOrderBy DESC,A.casgtID DESC ';
		$tmpAR0['SQL0']=' SELECT A.casgtID,A.casgtName,A.casgtParid 
			FROM '.$this->sysTableHead.'cmsaskgroup AS A
			WHERE 1=1 AND A.casgtRecycle=0 AND A.casgtChecked>1 AND A.casgtID={Nets.Parid}
			ORDER BY A.casgtOrderBy DESC,A.casgtID DESC ';
		$tmpAR0['InitialString']=$this->ssetParid;
		$tmpAR0['Parid']='casgtID';
		$tmpAR0['Text']='casgtName';
		$tmpAR0['Value']='casgtID';
		$tmpAR0['Type']=0;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$this->sParid1=$this->sParid2=$this->sControl->bindDropdown($tmpAR0);
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有的分类]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sParid2,$tmpAR0);
		//Question_Code
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=71;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_Question_Code';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sQuestion_Code1);
		$this->sQuestion_Code2=$this->sQuestion_Code1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有悬赏分数]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sQuestion_Code2,$tmpAR0);
		//State
		$tmpAR0=$this->sControl->sDbInTemplate;
		$tmpAR0['Connection']=$this->sConnString;
		$tmpAR0['SQL']=$this->sOptionSQL;
		$tmpAR0['InitialString']=19;
		$tmpAR0['Parid']='sotID';
		$tmpAR0['Text']='sotName';
		$tmpAR0['Value']='sotValue';
		$tmpAR0['Type']=1;
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		$tmpCacheFlag='nets/options_Cmsask_State';
		$this->sControl->getOptions($tmpAR0,$tmpCacheFlag,$this->sControl->sDpReturnTemplate,$this->sState1);
		$this->sState2=$this->sState1;
		$tmpAR0=$this->sControl->sDpReturnTemplate;
		$tmpAR0['Text']='[所有状态]';
		$tmpAR0['Value']='-1';
		$tmpAR0['Style']='';
		$tmpAR0['Title']='';
		$tmpAR0['AddOne']='';
		array_push($this->sState2,$tmpAR0);
		
		
		
	}
	public function OnAdd(){
		$tmpDbDescriptions=array();
		foreach ($this->sTable as $tableCell){
			$tmpDbDescriptions[]=$this->sDbDescriptions[$tableCell['sttTableName']];
		}
		$tmpMainid=$this->AnalyerRequest('mainID',0,1);
		$this->sMainID=$tmpMainid[0];
		$tmpMainUserid=$this->AnalyerRequest('mainUserid',0,1);
		$this->sMainUserid=$tmpMainid[0];
		$tmpMainTableid=$this->AnalyerRequest('mainTableid',0,1);
		$this->sMainTableid=$tmpMainid[0];
		//-- ------ #Submit limit check ------ --
		$tmpINT=$this->submitLimitRead($this->sysPage,-1,-1,-1);
		if($tmpINT!=0){
			$this->sJscript=$this->Message('SUCCESS','','对不起，您登陆次数过多，请'.$this->sysFileConfig['SubmitLimitFreeze'].'秒后再尝试登陆。','');
			return 1;
		}
		//-- ------ #CCode ------ --
		$tmpSTR='CCode';
		$tmpAR0=$this->AnalyerRequest($tmpSTR.'Txt','',1);
		$tmpCCode=$tmpAR0[0];
		$tmpSTR=$tmpSTR.'Txt_IFrame';
		if(!array_key_exists($tmpSTR,$_SESSION)){
			$this->submitLimitWrite($this->sysPage,-1,-1,-1);
			$this->sJscript=$this->Message('ERROR','提交失败','验证码错误','');
			return 1;
		}
		if($_SESSION[$tmpSTR]=='' || $_SESSION[$tmpSTR]!=$tmpCCode){
			$this->submitLimitWrite($this->sysPage,-1,-1,-1);
			$this->sJscript=$this->Message('ERROR','提交失败','验证码错误','');
			return 1;
		}
		//-- ------ #Add ------ --
		$this->sApp->TransStart();
		//#Get numCode
		$tmpSTR=$this->sTable[0]['sttColumnHead'].'NumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$this->sApp->numCode($tmpDbDescriptions[0]);
		//#Set value
		$tmpDbDescription0=$tmpDbDescriptions;
		$Coun0=0;
		foreach ($tmpDbDescription0 as $tableCell){
			foreach ($tableCell['Columns'] as $Column){
				if($Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'ID' &&
					$Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'NumCode' &&
					$Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'CreateBy' &&
					$Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'CreateTime' &&
					$Column['stcotName']!=$this->sTable[$Coun0]['sttColumnHead'].'IndexID'){
					$tmpAR0=$this->AnalyerRequest($Column['stcotName'].'Txt',$Column['stcoctDefaultValue'],1);
					$tmpDbDescriptions[$Coun0]['Columns'][$Column['stcotName']]['Value']=$tmpAR0[0];
				}
			}
			$Coun0++;
		}
		//-- #Set conventional --
		if(isset($tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateBy']['Value'])){
			$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateBy']['Value']=$tmpMainUserid[0];
		}
		if(isset($tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateTime'])){
			$tmpDbDescriptions[0]['Columns'][$this->sTable[0]['sttColumnHead'].'CreateTime']['Value']=date($this->sysTimeFormat);
		}
		//DB name,Condition,User index,User column name
		$tmpFlag=0;
		foreach ($this->AnonymousUserData as $Row0){
			if (count($tmpDbDescriptions)>1) {
				if(isset($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]])){
					if ($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]]['Value']==$Row0[1]) {
						$tmpFlag=1;
					}
				}
			}
			if ($this->sUserInfo[0]['Columns']['uitID']['Value']==0 && $tmpFlag==1) {
				$tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]]['Value']=$Row0[4];
			}else if ($tmpFlag==1 && isset($tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]])) {
				$tmpDbDescriptions[1]['Columns'][$this->sTable[1]['sttColumnHead'].$Row0[0]]['Value']=$this->sUserInfo[$Row0[2]]['Columns'][$Row0[3]]['Value'];
			}
		}
		//Spical value array
		foreach ($this->sSpicalValue as $Cell){
			if(isset($tmpDbDescriptions[$Cell[0]]['Columns'][$Cell[1]]['Value'])){
				$tmpDbDescriptions[$Cell[0]]['Columns'][$Cell[1]]['Value']=$Cell[2];
			}
		}
		//-- #Set spical --
		
		//#Add
		$tmpINT=$this->sApp->Check($tmpDbDescriptions,array(),array());
		if($tmpINT!=0){
			$this->sApp->TransRollback();
			$this->sJscript=$this->Message('ERROR','',$this->sApp->sysLastError,'');
			return 1;
		}
		$Coun0=0;
		while (count($tmpDbDescriptions)>$Coun0){
			if($Coun0==0){
				$tmpDbDescriptions[$Coun0]['TableDescription']['SearchColumn']=$this->sTable[$Coun0]['sttColumnHead'].'NumCode,'.$this->sTable[$Coun0]['sttColumnHead'].'ID';
			}else {
				$tmpDbDescriptions[$Coun0]['TableDescription']['SearchColumn']=$this->sTable[$Coun0]['sttColumnHead'].'IndexID';
			}
			$Coun0++;
		}
		$tmpINT=$this->sApp->add_Question($tmpDbDescriptions);
		if($tmpINT!=0){
			$this->sApp->TransRollback();
			$this->sJscript=$this->Message('ERROR','',$this->sApp->sysLastError,'');
			return 1;
		}
		
		foreach ($this->sDb->sysDbCacheClear as $Cell){
			$this->clearCache($Cell);
		}
		foreach ($this->sysPageCacheClear as $Cell){
			$this->clearCache($Cell);
		}
		$this->sApp->TransCommit();
		$this->sJscript=$this->Message('SUCCESS','','您已成功发布问题',$this->sysPage.'?ActionType=Publish');
		/*
		$this->sJscript=$this->Message_Frame('A,0',
			$this->sysFileConfig['sysCoreRoot'].$this->sysFileConfig['PathManaFrameMessage'],
			$this->sCode->URL_MakeParameter('添加成功',0),
			$this->sCode->URL_MakeParameter($this->sApp->sysLastError,0),
			$this->sCode->URL_MakeParameter($this->sysFileConfig['sysCoreRoot'].'Mana/m_cms/doc/doc.php',0));
		*/
		return 0;
	}
	public function OnList(){
		
	}
	public function OnPublish(){
		
	}

	public function DefUiPanel(&$pColumn,$pFlag){
		parent::DefUiPanel($pColumn,$pFlag);
		if($pColumn['stcotName']=='castParid' && $pFlag=='Search'){
			$pColumn['Option']=$this->sParid2;
		}else if($pColumn['stcotName']=='castParid' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sParid1;
		}else if($pColumn['stcotName']=='castCode' && $pFlag=='Search'){
			$pColumn['Option']=$this->sQuestion_Code2;
		}else if($pColumn['stcotName']=='castCode' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sQuestion_Code1;
		}else if($pColumn['stcotName']=='casctOpen' && $pFlag=='Search'){
			$pColumn['Option']=$this->sBoolean2;
		}else if($pColumn['stcotName']=='casctOpen' && ($pFlag=='Normal' || $pFlag=='List')){
			$pColumn['Option']=$this->sBoolean1;
			
		}else if($pColumn['stcotName']=='castCreateBy'){
			$pColumn['Parameter']='chooseSearch;castCreateByTxt;External_Search;'.$this->sysFileConfig['sysCoreRoot'].'Mana/m_nets/user/userUserinfo.php';
		}else if($pColumn['stcotName']=='castTo'){
			$pColumn['Parameter']='chooseSearch;castToTxt;External_Search;'.$this->sysFileConfig['sysCoreRoot'].'Mana/m_nets/user/userUserinfo.php';
		}else if($pColumn['stcotName']=='castCreateTime'){
			$pColumn['Parameter']='chooseDay;castCreateTimeTxt;External_Day;'.$this->sysFileConfig['sysCoreRoot'].'Component/Nets/netsJscript/chooseDay.php?ID=A';
		}else if($pColumn['stcotName']=='castEndtime'){
			$pColumn['Parameter']='chooseDay;castEndtimeTxt;External_Day;'.$this->sysFileConfig['sysCoreRoot'].'Component/Nets/netsJscript/chooseDay.php?ID=A';
		}else if($pColumn['stcotName']=='cdctChannelid'){
			$pColumn['Parameter']='chooseSearch;cdctChannelidTxt;External_Search;'.$this->sysFileConfig['sysCoreRoot'].'Mana/m_cms/other/channel.php';
		}else if($pColumn['stcotName']=='cdctZoneChoose' && $pFlag=='Normal'){
			$tmpSimpleXml->loadXml_UiParameter($this->readFile($this->sysFileConfig['sysCoreRoot'].$this->sysFileConfig['sysUiParameterPath'].'Mana/nets/Zone_Parid.php'));
			$tmpSTR=str_replace($this->sysSPLIT10,'',$tmpSimpleXml->sXmlElement->Parameters[2]->Value);
			$pColumn['Parameter']=$tmpSTR;
			


		}
		return $pColumn;
	}
	public function DefUiButton($pFlag,$Exception){
		parent::DefUiButton($pFlag,array('List','Normal','ListChildLink',));
		if($pFlag=='List' && !in_array($pFlag,$Exception)){ ?>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpControl.onDelete_Multiple();tmpCommon.setActionType('','DDelete_Multiple','',''); tmpCommon.netsSubmit();">批量删除</a></li>
<!--<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpControl.onNormal_Multiple(''); tmpCommon.netsSubmit();">批量修改所选</a></li>-->
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpControl.onModify_Page();tmpCommon.setActionType('','DModify_Page','',''); tmpCommon.netsSubmit();">保存本页修改</a></li>

<?php }else if ($pFlag=='Normal' && !in_array($pFlag,$Exception)) { ?>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpCommon.confirmDo('删除后将不能恢复，您确定删除本信息吗?');tmpCommon.setActionType('','DDelete','',''); tmpCommon.netsSubmit();">删除</a></li>
<li class="ButBut Button_Normal"><a href="#Here" class="Link1 FBlack2" onclick="tmpCommon.setActionType('Normal','DModify','',''); tmpCommon.netsSubmit();">修改</a></li>

<?php }else if ($pFlag=='ListChildLink' && !in_array($pFlag,$Exception)) { ?>
<li id="ListTabChild_0" class="TabChildNormal"><a href="../../../Plus/Common/Cms/ask_public.php?ActionType=Publish" class="Link1 SBlue1">添加<?php echo ($this->sMetaTitle); ?></a></li>
<!--
<li class="TabChildSelected"><a href="#Here" class="Link2 FBlue1"><?php echo ($this->sMetaTitle); ?>管理</a></li>
<li class="DLeft"><img src="<?php echo($this->sysFileConfig['sysUiCoreRoot']); ?>Ui/m_nets/Img/Mana/34.jpg" /></li>
<li class="TabChildNomal"><a href="#Here" class="Link1 FBlue1"><?php echo ($this->sMetaTitle); ?>管理</a></li>
-->

<?php }
	}
	
	public function DefUiJscript($pFlag){
?>
function jsDCheck(pPara){
	var tmpControl="";
	var tmpError="";
	var tmpChecker=new netsChecker();
	var tmpActionWithOut=document.getElementById("ActionWithOut");
	var Coun0=0;
	//-- ------ #ActionWithOut ------ --
	if(tmpActionWithOut==undefined){
		return true;
	}
	if(tmpActionWithOut.value=="1"){
		return true;
	}else if(tmpActionWithOut.value=="2"){
		return false;
	}
	//-- ------ #Check ------ --
	//#casctContent
	tmpCheckCont=document.getElementById("casctContentTxt");
	tmpCheckCont.value=tmpChecker.Filter(tmpCheckCont.value,0);
	if(tmpCheckCont.value.length<3){
		Coun0++;
		tmpError+=Coun0+".问题内容不能小于3个字符。"+sysSPLIT8;
	}
	//#casctConEmail
	tmpCheckCont=document.getElementById("casctConEmailTxt");
	tmpCheckCont.value=tmpChecker.Filter(tmpCheckCont.value,0);
	if(tmpCheckCont.value.length<3){
		Coun0++;
		tmpError+=Coun0+".电子邮箱地址不正确。"+sysSPLIT8;
	}
	//#castCCode
	tmpCheckCont=document.getElementById("castCCodeTxt");
	tmpCheckCont.value=tmpChecker.Filter(tmpCheckCont.value,0);
	if(tmpCheckCont.value.length!=5){
		Coun0++;
		tmpError+=Coun0+".验证码为5位数字。"+sysSPLIT8;
	}
	//#FormChecked
	tmpCheckCont=document.getElementById(sysForm).FormChecked;
	if(!tmpCheckCont.checked){
		Coun0++;
		tmpError+=Coun0+".在提问前，您必须同意本站的用户协议。"+sysSPLIT8;
	}
	//-- ------ #Result ------ --
	if(tmpError!=""){
		tmpSTR="<span class=\"FStrong\">对不起，您提交的内容存在以下错误:</span>"+sysSPLIT8+tmpError;
		showMessage("系统消息 - <?php echo ($this->sysFileConfig['bussinessMetaTitle']); ?>",tmpSTR,"","0");
		return false;
	}else{
		return true;
	}
}
<?php
	}
	
	
	
}
?>