<?php
	
//驗證資料重複
function neillibrary_verify_duplicate($dbneme="",$centerid="",$va1="") {
if(!empty(moduledb($dbneme,$where="   where `centerid` = '".$centerid."' &&  `email` = '".$va1."' "))) {
	//重複
	$back['value']='2';
    $back['box']=sprintf(_MS_CUSTOMFIELD34,$va1);
	$back['mail_val']=null;
} else {
	//不重複
	$back['value']=null;	
	$back['box']="<div  class='alert alert-green-customize text-center' role='alert'>".sprintf(_MS_CUSTOMFIELD35,$va1)."</div>";
	$back['mail_val']=$va1;
}	

	return $back;
}
	
//報名查詢操作
function neillibrary_signupoperate($operate) {
	global $uid,$suid,$checks,$xoopsModule,$isAdmin;
	if($operate=='1') {
		
		$dbneme=$xoopsModule->getVar("dirname")=='neilsignedup_a' ? 'neilsignedup_a_apply' : 'neilsignedup_c_apply'; 
		//刪除核取內容
		if(empty($isAdmin)) {
			if(empty($_POST['check'])) redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/signedupcenter.php?op=signupinquire&checks=".$checks."" ,0 , _MS_SHARED244);
			$where=" where  applyid  IN(".implode(',', $_POST['check']).")  && `uid` = '{$uid}' && `checks` != '1'  order by  applyid  DESC";
		} else {
			if(empty($_POST['check'])) redirect_header(XOOPS_URL. "/modules/".$xoopsModule->getVar("dirname")."/signedupcenter.php?op=signupinquire&suid=".$suid."&checks=".$checks."" ,0 , _MS_SHARED244);
			$where=" where  applyid  IN(".implode(',', $_POST['check']).")  && `checks` != '1'  order by  applyid  DESC";
		}
		foreach($Arr=databasetablewhile($dbneme,$where) as $key=> $val) {
			//刪除資料夾
			fileadminfunction($fileurl="",$type="1",$fileex="",$from=XOOPS_ROOT_PATH.'/uploads/'.$xoopsModule->getVar("dirname").'/'.$Arr[$key]['sortid'].'file/centerid_'.$Arr[$key]['centerid'].'/'.$Arr[$key]['applyid'].'_child');
			//刪除neilsignedup_c_apply資料
			deletefunction($where=" where `applyid` = '".$Arr[$key]['applyid']."'",$dbneme);
		}
	}
	return combinationvar($Arrvar=array("suid","checks"));
}
	
	
	
	
	
	
//建立資訊陣列	
function  neillibrary_createinformation($post=""){	
foreach($post['formnumber']  as $key=> $val){
if(!empty($post['formtitle'][$key])){	
$Arr[$key]['formtitle']=phpstrip_tags($notags=sqlinjectionfound($val=$post['formtitle'][$key]));	
$Arr[$key]['formcontent']=sqlinjectionfound($val=sqlinjectionfound($val=neillibrary_textprocessing($post['formcontent'][$key],$item="1")));
$Arr[$key]['formnumber']=$post['formnumber'][$key];
}

}
return $Arr;

}
	
	
	
	
	
	
//新增資訊欄位
function  neillibrary_defaultform($moduleid="",$title="",$content="",$number="",$of_sortid=""){
global $themefolder,$xoopsConfig;	

include_once XOOPS_ROOT_PATH."/modules/".$moduleid."/language/{$xoopsConfig['language']}/main.php";		




switch($moduleid){
  case "neilsignedup_c":
$text['0']=_MD_SIGNEDUPCENTERPHP235;         //輸入課程資訊標題
$text['1']=_MD_SIGNEDUPCENTERPHP236;         //輸入課程資訊說明

	
  break;
  case "neilsignedup_a":
$text['0']=_MD_SIGNEDUPCENTERPHP247;         //輸入活動資訊標題
$text['1']=_MD_SIGNEDUPCENTERPHP248;         //輸入活動資訊說明
  break;
  
  default:
  //預設動作
}



$moduleid="".$moduleid."/".$of_sortid."file";
 
$logList=moduledb($dbneme="neillibrary_layoutcsslog",$where=" where `ip` = '".get_real_ip()."' && `cookieid` = '".$_COOKIE['neil']['cookieid']."'  order by  logid DESC");
if(!empty($logList)){
$setvar="set mod_dir='".$moduleid."'  where logid='".$logList['logid']."'";
update($dbname="neillibrary_layoutcsslog",$set=$setvar);
}  



//說明標題
$product['0']=inputtext($class="",$name="formtitle[]",$value=htmlspecialchars($title),$placeholder=$text['0']); 
//說明內容
$product['1']=inputtextarea($class="formeditor",$name="formcontent[]",$id="formeditorvar".$number."",$rows="6",$cols="80",$value=htmlspecialchars($content));

if($themefolder=='computer') $handlebox="<div class='alert alert-warning handle text-center' role='alert'><i class='fa-solid fa-arrows-up-down'></i> "._MS_SHARED215."</div>";

$box.="<div id='contentbox".$number."' class='form-group contentbox sortablebox' name='".$number."' >
     ".$handlebox."	
<div class='row'>	
  <div class='col-md-4' >
      <label class='control-label'>".$text['0']."</label>
    ".$product['0']."<br />
    <button id='delete".$number."' type='button' class='btn btn-danger btn-lg btn-block'>"._MS_SHARED09."</button>
  </div>
  <div class='col-md-8'>
    <label class='control-label'>
     ".$text['1']."
    </label> ".$product['1']." <br />
  </div>
  </div>  
  <input type='hidden' name='formnumber[]' value='".$number."'>   
  	<div style='clear: both;'></div>        
     </div>




 	



<script id='deletescript".$number."'>
neillibrary_ckeditorlist(editorvar='formeditorvar".$number."',xoopsjsurl='".XOOPS_URL."',moduleid='".$moduleid."');
$('body').on('click', '#delete".$number."', function() {
    $('#contentbox".$number."').remove();
    $('#deletescript".$number."').remove();    
    swal('"._MS_SHARED214."', 'Data deleted Update after saving');
})
</script> 	
  ";

	return $box;
}
	
	
	
	
	
//報名費用選項	
function neillibrary_feeoptions($pricetype="",$typevar="",$price=""){	


switch($typevar){
  case "1":
 
switch($pricetype){
  case "0": //無須費用
$returnval=sprintf(_MD_SIGNEDUPCENTERPHP185,_MS_ACTIVITY02);  
  break;
  
  case "1": //需報名費
$returnval=sprintf(_MD_SIGNEDUPCENTERPHP185,$price)._MD_SIGNEDUPCENTERPHP183;    
  break;

  case "2": //線上洽詢
$returnval=sprintf(_MD_SIGNEDUPCENTERPHP185,_MS_ACTIVITY04);    
  break;
}
  
  
  break;
  
  default:
  	  
$pricetypeArr = array(); //建構陣列
$i=0;
$pricetypeArr[$i]['id']='0';  //無須費用
$pricetypeArr[$i]['title']=_MS_ACTIVITY02;
$i++;

$pricetypeArr[$i]['id']='1';  //需報名費
$pricetypeArr[$i]['title']=_MS_ACTIVITY03;
$i++;

$pricetypeArr[$i]['id']='2';  //線上洽詢
$pricetypeArr[$i]['title']=_MS_ACTIVITY04;
$i++;

//下拉選單(狀態)
foreach($pricetypeArr as $key=> $val){
$returnval.=optionselect($dataid=$pricetypeArr[$key]['id'],$optionname=$pricetypeArr[$key]['title'],$oid="".$pricetype."",$value=$pricetypeArr[$key]['id']);
}
  	  

}


	





return $returnval;  
}
	
	
//共用時間欄位/上架-下架-開課-結束
function neillibrary_timeinputtext($signedupshow="",$signedupList=""){	

if(empty($signedupList)){
$signedupList['starttime']=timedate($datevar="Y-m-d H:i");
$signedupList['endtime']=timedate($datevar="Y-m-d H:i");
$signedupList['startclasstime']=timedate($datevar="Y-m-d H:i");
$signedupList['endclasstime']=timedate($datevar="Y-m-d H:i");		
}

	
//課程上架時間
$signedupshow['starttimebox']=inputtext($class="mydate",$name="starttime",$value="".$signedupList['starttime']."",$placeholder="".$signedupList['starttime']."",$id="mydate1",$typeval="datetime-local");
  
//課程下架時間
$signedupshow['endtimebox']=inputtext($class="mydate",$name="endtime",$value="".$signedupList['endtime']."",$placeholder="".$signedupList['endtime']."",$id="mydate2",$typeval="datetime-local");
  
//課程開課時間
$signedupshow['startclasstimebox']=inputtext($class="mydate",$name="startclasstime",$value="".$signedupList['startclasstime']."",$placeholder="".$signedupList['startclasstime']."",$id="mydate3",$typeval="datetime-local");
  
//課程結束時間
$signedupshow['endclasstimebox']=inputtext($class="mydate",$name="endclasstime",$value="".$signedupList['endclasstime']."",$placeholder="".$signedupList['endclasstime']."",$id="mydate4",$typeval="datetime-local");
  
  
return $signedupshow;  
}





	
//活動星期
function neillibrary_activityweek($week="",$typeop="",$modulesid=""){	

switch($typeop){
  case "1":  //開啟字串轉陣列解出數值
foreach(phpconversion($conversion=$week,$type="unserialize") as  $val){	
$weektext.="<i class='fa-solid fa-check'></i>".neillibrary_activityweek($week=$val,$typeop="2")."  &nbsp;" ;
}
$weektext=neillibrary_activityweek($week=$weektext,$typeop="3",$modulesid);

  break;
  
  case "2":   //按數值對應星期	  
switch($week){
  case "1":
$weektext=_MS_SHARED162;  //星期一
  break; 
  
  case "2":
$weektext=_MS_SHARED163;  //星期二
  break;  
  
  case "3":
$weektext=_MS_SHARED164;  //星期二
  break;
  
  case "4":
$weektext=_MS_SHARED165;  //星期四
  break;
  
  case "5":
$weektext=_MS_SHARED166;  //星期五
  break;
  
  case "6":
$weektext=_MS_SHARED167;  //星期六
  break;
  
  case "7":
$weektext=_MS_SHARED168;  //星期日
  break;
}
  
   break; 
   
  case "3": //輸出樣式  	 

$weeklanguage=$modulesid=='neilsignedup_c' ? _MS_ACTIVITY07 : _MS_ACTIVITY01; // get TRUE
$weektext="
<div class='alert alert-primary text-center' role='alert'>".sprintf($weeklanguage,$week)."</div>";
  break;   
  
  default:  //選單
  	  
//選擇活動星期
$weekArr = array(); //建構陣列
$i=0;
$weekArr[$i]['id']='1';  //星期一
$weekArr[$i]['title']=_MS_SHARED162;
$i++;
$weekArr[$i]['id']='2';  //星期二
$weekArr[$i]['title']=_MS_SHARED163;
$i++;
$weekArr[$i]['id']='3';  //星期三
$weekArr[$i]['title']=_MS_SHARED164;
$i++;
$weekArr[$i]['id']='4';  //星期四
$weekArr[$i]['title']=_MS_SHARED165;
$i++;
$weekArr[$i]['id']='5';  //星期五
$weekArr[$i]['title']=_MS_SHARED166;
$i++;
$weekArr[$i]['id']='6';  //星期六
$weekArr[$i]['title']=_MS_SHARED167;
$i++;
$weekArr[$i]['id']='7';  //星期日
$weekArr[$i]['title']=_MS_SHARED168;
$i++;

//下拉選單
foreach($weekArr as $key=> $val){
if(!empty(phpconversion($conversion=$week,$type="unserialize")) &&  in_array($weekArr[$key]['id'], phpconversion($conversion=$week,$type="unserialize"))){  //單值-> 陣列
$oidvar['1'][$key]=$weekArr[$key]['id'];
}
$weektext.=optionselect($dataid=$weekArr[$key]['id'],$optionname=$weekArr[$key]['title'],$oid=$oidvar['1'][$key],$value=$weekArr[$key]['id'],$id="");
} 
}
return $weektext;  

}


//常見問題
function neillibrary_commonproblem($val="",$typeop="",$oidArr="",$modulesid=""){	
global $xoopsModuleConfig;


if(empty(modulesmidvar($mar="neilmfdcms",$var="isactive"))) return false;  

switch($typeop){
  case "1": //輸出內容
foreach(phpconversion($conversion=$val,$type="unserialize") as  $val){	//解出分類ID
$sortid.=" `sortid` = '".$val."'  || ";
}


if($modulesid=='neilsignedup_c'){
$Config['0']=$xoopsModuleConfig['neilsignedup_c20']; //內容顯示方式
$Config['1']=$xoopsModuleConfig['neilsignedup_c19']; //顯示筆數	
}else{	
$Config['0']=$xoopsModuleConfig['neilsignedup_a14']; //內容顯示方式
$Config['1']=$xoopsModuleConfig['neilsignedup_a13']; //顯示筆數
}

//排列方式
if($Config['0']=="0"){ //最新內容排序
$arrangeDB='centerid';
$turn='DESC';
}else if($Config['0']=="1"){ //自訂排序
$arrangeDB='productsort';
$turn='ASC';
}else if($Config['0']=="2"){ //瀏覽數排序
$arrangeDB='counter';
$turn='DESC';
}else if($Config['0']=="3"){ //瀏覽數排序
$arrangeDB='';
$turn='RAND()';
}


$dbneme="neilmfdcmscenter";
$where=" where (".substr($sortid,0,-3).")  &&  `enable` = '1'  order by  ".$arrangeDB."  ".$turn."  limit  ".$Config['1']."";  //解出內容
$problem=databasetablewhile($dbneme,$where); 

  break;
  
  default: //選單
$dbneme="neilmfdcmstypes";
$where=" where `types` = '3'  &&  `enable` = '1'  order by  sortidsort  ASC";  //where數值
$neilmfdcmstypesArr=databasetablewhile($dbneme,$where); 
foreach($neilmfdcmstypesArr as $key=> $val){
$typesid.=" `typesid` = '".$neilmfdcmstypesArr[$key]['typesid']."'  || ";
}

$dbneme="neilmfdcmssort";
$where=" where (".substr($typesid,0,-3).")  &&  `enable` = '1'  order by  sortidsort  ASC";  //where數值
$neilmfdcmssortArr=databasetablewhile($dbneme,$where); 

foreach($neilmfdcmssortArr as $key=> $val){	
	
if(!empty(phpconversion($conversion=$oidArr,$type="unserialize")) && in_array($neilmfdcmssortArr[$key]['sortid'], phpconversion($conversion=$oidArr,$type="unserialize"))){  //單值-> 陣列
$oidvar['1'][$key]=$neilmfdcmssortArr[$key]['sortid'];
}
	
$problem.=optionselect($dataid=$neilmfdcmssortArr[$key]['sortid'],$optionname=$neilmfdcmssortArr[$key]['sorttitle'],$oid=$oidvar['1'][$key].$classid."",$value=$neilmfdcmssortArr[$key]['sortid']);
}  
}

return $problem;  

}

?>