<?php
//建立資訊陣列	
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'><span class='glyphicon glyphicon-sort' aria-hidden='true'></span> "._MS_SHARED215."</div>";

$box.="<div id='contentbox".$number."' class='form-group contentbox sortablebox' name='".$number."' >
     ".$handlebox."	
<div class='row'>	
  <div class='col-sm-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-sm-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:s");
$signedupList['endtime']=timedate($datevar="Y-m-d H:i:s");
$signedupList['startclasstime']=timedate($datevar="Y-m-d H:i:s");
$signedupList['endclasstime']=timedate($datevar="Y-m-d H:i:s");		
}
	
//課程上架時間
$signedupshow['starttimebox']=inputtext($class="mydate",$name="starttime",$value="".$signedupList['starttime']."",$placeholder="".$signedupList['starttime']."",$id="mydate1");
  
//課程下架時間
$signedupshow['endtimebox']=inputtext($class="mydate",$name="endtime",$value="".$signedupList['endtime']."",$placeholder="".$signedupList['endtime']."",$id="mydate2");
  
//課程開課時間
$signedupshow['startclasstimebox']=inputtext($class="mydate",$name="startclasstime",$value="".$signedupList['startclasstime']."",$placeholder="".$signedupList['startclasstime']."",$id="mydate3");
  
//課程結束時間
$signedupshow['endclasstimebox']=inputtext($class="mydate",$name="endclasstime",$value="".$signedupList['endclasstime']."",$placeholder="".$signedupList['endclasstime']."",$id="mydate4");
  
  
return $signedupshow;  
}





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

switch($typeop){
  case "1":  //開啟字串轉陣列解出數值
foreach(phpconversion($conversion=$week,$type="unserialize") as  $val){	
$weektext.="<span class='glyphicon glyphicon-check' aria-hidden='true'></span>".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='well well-sm text-center wellbox'>".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;  

}

?>