<?php
//反解自訂表單項目欄位內容
function  neillibrary_reverseprojectfield($material="",$value="") {
	global $themefolder;
	$colmdvar=neillibrary_typesetting($fwidthoption=$material['fwidthoption']);
	switch($material['fypeoption']) {
		case "1":
		case "3":
		case "5":
		case "6":
		if(!empty($material['fieldval'])) 
		$box="
<div id='typebox".$material['fypeoption']."' class='typebox'>
<div class='row col-mdinitial'>
<div class='col-md-3 col-xs-5'>".$material['fieldtitle']._MS_CUSTOMFIELD41."</div>
<div class='col-md-9 col-xs-7'>".$material['fieldval']."</div>
</div></div> ";
		break;
		case "2":	
		if(!empty($material['fieldval'])){ 		
		$material['fieldval']=empty(judgeHtml($material['fieldval'])) ? neillibrary_textprocessing($val=$material['fieldval']) : $material['fieldval'];
		$box="
<div id='typebox".$material['fypeoption']."' class='typebox'>
<div class='row'>
<div class='col-md-3'>".$material['fieldtitle']._MS_CUSTOMFIELD41."</div>
<div class='col-md-9'>".$material['fieldval']."</div>
</div></div>	 ";
		}
		break;
		case "4":
		if(!empty($material['fieldval'])){ 			
		foreach($material['fieldval'] as $val) {
		$listval.="<li><span id='itnmlibox'>".$val."</span></li>";
		}
		$box="
<div id='typebox".$material['fypeoption']."' class='typebox'>
<div class='row'>
<div class='col-md-3 col-xs-5'>".$material['fieldtitle']._MS_CUSTOMFIELD41."</div>
<div class='col-md-9 col-xs-7'><div id='fieldtitlebox'><ul>".$listval."</ul></div></div>
</div></div>	 ";
		}
		break;
	}
	return $box;
}
	
	
//自訂表單項目欄位內容陣列化
function  neillibrary_itemfieldarrayization($post="") {
	foreach($Arr=$post['fypeoption'] as $key=> $val) {
		switch($val) {
			case "1":
		    case "3":
			case "5":
					$store[$key]['fieldval']=phpstrip_tags($notags=sqlinjectionfound($v=$post['invert'][$key],$coderemove=true));
			break;
			case "2":
					$store[$key]['fieldval']=sqlinjectionfound($v=$post['invert'][$key],$coderemove=true);
			break;
			case "4":
					foreach($post['invert'][$key]  as $i=> $va2) {
			    	$store[$key]['fieldval'][$i]=phpstrip_tags($notags=sqlinjectionfound($v=$va2));
		        	}
			break;
			case "6":
					$store[$key]['fieldval']=sqlinjectionfound($v=$post['invert'][$key],$coderemove=true);
			break;
		}
		$store[$key]['fnumber']=$post['fnumber'][$key];
		$store[$key]['fypeoption']=$val;
		$store[$key]['fieldtitle']=$post['fieldtitle'][$key];
		$store[$key]['fwidthoption']=$post['fwidthoption'][$key];
		$store[$key]['fieldArr']=$post['fieldArr'][$key];
		$store[$key]['fsetup']=$post['fsetup'][$key];
		$store[$key]['frequired']=$post['frequired'][$key];
		$store[$key]['fdirections']=$post['fdirections'][$key];
	}
	return $store;
}	
	
	
//反解可編輯項目欄位
function  neillibrary_reverseitemfield($moduleid="",$fieldtype="",$number="",$material="",$required="",$change=""){
global $themefolder;	


//備註說明
if(!empty($material['fdirections'])) $fdirectionsbox="<span id='helpBlock' class='help-block'>".$material['fdirections']."</span>";
//必填
if(!empty($material['frequired'])) $requiredbox="<span id='helpBlockfield".$number."'  class='red ".$required[0]."'>"._MS_SHARED22."</span><input type='hidden' name='required[]' value='".$number."'>";

switch($fieldtype){
  case "1":
 //文字輸入框
$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']." deletebox".$number." itemsort' name='".$number."'>
<span id='helpBlock' class='help-block handle'>".$material['fieldtitle']." <span title="._MS_CUSTOMFIELD48." style='font-size: 130%;' class='glyphicon glyphicon-remove red delete".$number."' aria-hidden='true'></span></span>  		
".inputtext($class="",$name="invert[".$number."]",$value=$material['fieldval'],$placeholder=_MS_SHARED21.$material['fieldtitle'],$id="invertid".$number."").$fdirectionsbox.$requiredbox."
<p>	  ";
if(!empty($material['frequired'])){
$box.="
<script> 	
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."');
</script>	
";
}
$box.="
<input type='hidden' name='fypeoption[".$number."]' value='".$material['fypeoption']."'>
<input type='hidden' name='fnumber[".$number."]' value='".$material['fnumber']."'>
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>
<input type='hidden' name='fwidthoption[".$number."]' value='".$material['fwidthoption']."'>
<input type='hidden' name='frequired[".$number."]' value='".$material['frequired']."'>
<input type='hidden' name='fdirections[".$number."]' value='".$material['fdirections']."'>	
</div>";

  break;
 
  case "2":  
  	  
 //大量文字輸入框
$classvar= !empty($material['fsetup']['0']) ? 'itemeditor' : 'itemvar'; // get TRUE
 
$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']." deletebox".$number." itemsort' name='".$number."'>
<span id='helpBlock' class='help-block handle'>".$material['fieldtitle']." <span title="._MS_CUSTOMFIELD48." style='font-size: 130%;' class='glyphicon glyphicon-remove red delete".$number."' aria-hidden='true'></span></span>  		
".inputtextarea($class=$classvar,$name="invert[".$number."]",$id="textarea".$number."",$rows=$material['fsetup']['1'],$cols="80",$value=$material['fieldval']).$fdirectionsbox.$requiredbox."
<p>
";
 
if(!empty($material['fsetup']['0'])) {
$box.="
<script> 	
var myToolbar = [
            { name: 'bar1', items: ['Source'] },
           // { name: 'bar2', items: ['Cut', 'Copy', 'Undo', 'Redo'] },
         // { name: 'bar3', items: ['Image', 'EqnEditor', 'Table', 'HorizontalRule', 'Smiley', 'Link', 'Unlink'] },
            { name: 'bar4', items: ['NumberedList', 'BulletedList', 'RemoveFormat', 'Syntaxhighlight', 'CodeSnippet'] },      
         // { name: 'bar5', items: ['Blockquote', 'CreateDiv'] },
            { name: 'bar6', items: ['PageBreak', 'WidgetTemplateMenu', 'Uploadcare'] },
         // { name: 'bar7', items: ['Styles', 'Format', 'Font', 'FontSize'] },
            { name: 'bar7', items: ['Styles', 'Format',  'FontSize'] },            	
            { name: 'bar7-1', items: ['TextColor', 'BGColor', 'Bold', 'Italic', 'Underline', 'Strike'] },
         //   { name: 'bar8', items: ['Outdent', 'Indent'] },
            { name: 'bar9', items: ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'] },
         // { name: 'bar10', items: ['Find', 'Replace', 'SelectAll', 'FontAwesome'] }
];	
	
CKEDITOR.replace( 'textarea".$number."', {
    toolbar : 'my' ,
    skin: 'moono' ,   	
    toolbar_my: myToolbar,	    		
    height: '".$material['fsetup']['1']."00'	
});
CKEDITOR.config.contentsCss=CKEDITOR.getUrl('".$themefolder."_contents.css');
</script>

";
}

if(!empty($material['frequired']) && !empty($material['fsetup']['0']) ){
$box.="
<script> 
   if (CKEDITOR.instances.textarea".$number.".getData()) {
      $('#helpBlockfield".$number."').hide().text(true);
   }	
    $('body').on('click', $(this), function() {
       if (CKEDITOR.instances.textarea".$number.".getData()) {
            $('#helpBlockfield".$number."').hide().text(true);
        } else {
            $('#helpBlockfield".$number."').show().text('"._MS_SHARED22."');
        }
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."',fsetup=".$material['fsetup']['0'].");
  
    })	
</script>	
";

}

if(!empty($material['frequired']) && empty($material['fsetup']['0'])){
$box.="
<script> 
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."',fsetup=".$material['fsetup']['0'].");
</script>	
";
}


foreach($material['fsetup'] as $key=> $val){
$box.="<input type='hidden' name='fsetup[".$number."][]' value='".$val."'>";
}


$box.="
<input type='hidden' name='fypeoption[".$number."]' value='".$material['fypeoption']."'>
<input type='hidden' name='fnumber[".$number."]' value='".$material['fnumber']."'>
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>
<input type='hidden' name='fwidthoption[".$number."]' value='".$material['fwidthoption']."'>
<input type='hidden' name='frequired[".$number."]' value='".$material['frequired']."'>
<input type='hidden' name='fdirections[".$number."]' value='".$material['fdirections']."'>
</div>";
 
  break;  
  
 
  case "3":
//單選按鈕

foreach($material['fieldArr'] as $key=> $val){
$radiobox.=radioinlinelist($dataid=$material['fieldArr'][$key],$class="",$name="invert[".$number."]",$text=$material['fieldArr'][$key],$value=$material['fieldArr'][$key],$oid=$material['fieldval'],$id="invertid".$number."");
if($themefolder=='phone' || !empty($material['fsetup']['0'])) $radiobox.="<div style='clear: both;'></div>";	
}


$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']." deletebox".$number." itemsort' name='".$number."'>
<span id='helpBlock' class='help-block handle'>".$material['fieldtitle']." <span title="._MS_CUSTOMFIELD48." style='font-size: 130%;' class='glyphicon glyphicon-remove red delete".$number."' aria-hidden='true'></span></span>  		
".$radiobox.$fdirectionsbox.$requiredbox."
<p>
 ";
 
if(!empty($material['frequired'])){
$box.="
<script> 	
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."');
</script>	
";
} 

foreach($material['fieldArr'] as $key=> $val){
$box.="<input type='hidden' name='fieldArr[".$number."][]' value='".$material['fieldArr'][$key]."'>";
}

$box.="
<input type='hidden' name='fypeoption[".$number."]' value='".$material['fypeoption']."'>
<input type='hidden' name='fnumber[".$number."]' value='".$material['fnumber']."'>
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>
<input type='hidden' name='fwidthoption[".$number."]' value='".$material['fwidthoption']."'>
<input type='hidden' name='fsetup[".$number."][0]' value='".$material['fsetup']['0']."'>
<input type='hidden' name='frequired[".$number."]' value='".$material['frequired']."'>
<input type='hidden' name='fdirections[".$number."]' value='".$material['fdirections']."'>	
</div>";

  break;
  
  case "4":  	  
//多選按鈕
foreach($material['fieldArr'] as $key=> $val){
	
if(!empty($material['fieldval']) && in_array("".$material['fieldArr'][$key]."", $material['fieldval'])){  //查詢->陣列
$oidvar[$key]=$key;
}else{
$oidvar[$key]='';
}

	
$radiobox.=checkbox($dataid=$key,$name="invert[".$number."][]",$value=$material['fieldArr'][$key],$optionname=$material['fieldArr'][$key],$oid=$oidvar[$key],$i="",$class="invertid".$number."");  
if($themefolder=='phone' || !empty($material['fsetup']['0'])) $radiobox.="<div style='clear: both;'></div>";	
}


$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']." deletebox".$number." itemsort' name='".$number."'>
<span id='helpBlock' class='help-block handle'>".$material['fieldtitle']." <span title="._MS_CUSTOMFIELD48." style='font-size: 130%;' class='glyphicon glyphicon-remove red delete".$number."' aria-hidden='true'></span></span>  		
".$radiobox.$fdirectionsbox.$requiredbox."
<p>
 ";
if(!empty($material['frequired'])){
$box.="
<script> 	
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."');
</script>	
";
} 

foreach($material['fieldArr'] as $key=> $val){
$box.="<input type='hidden' name='fieldArr[".$number."][]' value='".$material['fieldArr'][$key]."'>";
}

$box.="
<input type='hidden' name='fypeoption[".$number."]' value='".$material['fypeoption']."'>
<input type='hidden' name='fnumber[".$number."]' value='".$material['fnumber']."'>
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>
<input type='hidden' name='fwidthoption[".$number."]' value='".$material['fwidthoption']."'>
<input type='hidden' name='fsetup[".$number."][0]' value='".$material['fsetup']['0']."'>
<input type='hidden' name='frequired[".$number."]' value='".$material['frequired']."'>
<input type='hidden' name='fdirections[".$number."]' value='".$material['fdirections']."'>		
</div>";
  break;  
  
 
  case "5":
//下拉選單
foreach($material['fieldArr'] as $key=> $val){
$optionselect.=optionselect($dataid=$material['fieldArr'][$key],$optionname=$material['fieldArr'][$key],$oid=$material['fieldval'],$value=$material['fieldArr'][$key]);
}


$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']." deletebox".$number." itemsort' name='".$number."'>
<span id='helpBlock' class='help-block handle'>".$material['fieldtitle']." <span title="._MS_CUSTOMFIELD48." style='font-size: 130%;' class='glyphicon glyphicon-remove red delete".$number."' aria-hidden='true'></span></span>  		
<select id='invertid".$number."'  class='form-control' name='invert[".$number."]' >
<option value='0'  data-id='0' >".$material['fieldtitle']."</option>
".$optionselect."
</select>".$fdirectionsbox.$requiredbox."<p>
 ";
if(!empty($material['frequired'])){
$box.="
<script> 	
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."');
</script>	
";
} 

foreach($material['fieldArr'] as $key=> $val){
$box.="<input type='hidden' name='fieldArr[".$number."][]' value='".$material['fieldArr'][$key]."'>";
}

$box.="
<input type='hidden' name='fypeoption[".$number."]' value='".$material['fypeoption']."'>
<input type='hidden' name='fnumber[".$number."]' value='".$material['fnumber']."'>
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>
<input type='hidden' name='fwidthoption[".$number."]' value='".$material['fwidthoption']."'>
<input type='hidden' name='frequired[".$number."]' value='".$material['frequired']."'>
<input type='hidden' name='fdirections[".$number."]' value='".$material['fdirections']."'>		
</div>";
  break;
  
 
 case "6":
//日期時間

if($themefolder=='computer'){
//顯示時分
if(!empty($material['fsetup']['0'])){
$presettimebox="";
$presettime=!empty($material['fieldval']) ? $material['fieldval'] : timedate($datevar="Y-m-d H:i"); // get TRUE
}else{
//不顯示
if(empty($change)){
$presettimebox="
    $('body').on('change', '#field".$number."', function() {
        var date = $(this).val();
        var newDate = /\d{4}-\d{1,2}-\d{1,2}/g.exec(date);
        $(this).val(newDate);
        $('.ui-timepicker-div').remove();
    })
";
}
$presettime=!empty($material['fieldval']) ? $material['fieldval'] : timedate($datevar="Y-m-d"); // get TRUE
$typeval='text';
}
}else{
if(!empty($material['fsetup']['0'])){
//顯示時分
$typeval='datetime-local';
$presettime=!empty($material['fieldval']) ? $material['fieldval'] : timedate($datevar="Y-m-d H:i"); // get TRUE
}else{
$typeval='date';
$presettime=!empty($material['fieldval']) ? $material['fieldval'] : timedate($datevar="Y-m-d"); // get TRUE

}	
}




$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']." deletebox".$number." itemsort' name='".$number."'>
<span id='helpBlock' class='help-block handle'>".$material['fieldtitle']." <span title="._MS_CUSTOMFIELD48." style='font-size: 130%;' class='glyphicon glyphicon-remove red delete".$number."' aria-hidden='true'></span></span>  		
".inputtext($class="",$name="invert[".$number."]",$value=$presettime,$placeholder=$presettime,$id="field".$number."",$typeval).$fdirectionsbox.$requiredbox."
<p>

 ";
//若模組沒引入datepicker須由$signedupshow['inversejs']引入 
if($themefolder=='computer'){
$box.="
<script> 
    $('#field".$number."').datetimepicker({
      'dateFormat': 'yy-mm-dd',  
      'timeFormat': 'HH:mm'
    });
".$presettimebox."      
</script>
<style> 	
#ui-datepicker-div {
    margin-left: 0px;
}
</style> 

"; 
}

$box.="
<script> 	
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."',fsetup='',frequired='".$material['frequired']."');
</script>	
";
$box.="
<input type='hidden' name='fypeoption[".$number."]' value='".$material['fypeoption']."'>
<input type='hidden' name='fnumber[".$number."]' value='".$material['fnumber']."'>
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>
<input type='hidden' name='fwidthoption[".$number."]' value='".$material['fwidthoption']."'>
<input type='hidden' name='fsetup[".$number."][0]' value='".$material['fsetup']['0']."'>
<input type='hidden' name='frequired[".$number."]' value='".$material['frequired']."'>
<input type='hidden' name='fdirections[".$number."]' value='".$material['fdirections']."'>		
</div>";
  break;

}


if(empty($change)){
$box.="
<script id='deletescript".$number."'>
$('body').on('click', '.delete".$number."', function() {
    $('.deletebox".$number."').remove();
    $('#deletescript".$number."').remove();
    swal('"._MS_SHARED214."', 'Data deleted Update after saving');
})	
</script>	
";
}

return $box;	
}
	
	
	

//反解自訂欄位-excel
function neillibrary_solutionfieldexcel($conversion="") {
	foreach($Arrfield=phpconversion($conversion,$type="unserialize") as $key=> $val) {
		switch($Arrfield[$key]['fypeoption']) {
			case "1":
			case "3": 	 
			case "5": 	 
			case "6": 		
	    	if(!empty($Arrfield[$key]['fieldval']))	$fieldvar.=$Arrfield[$key]['fieldtitle'].':'.str_replace ("T"," ",$Arrfield[$key]['fieldval']).' / ';
			break;
			case "2":
			if(!empty($Arrfield[$key]['fieldval'])) $fieldvar.=$Arrfield[$key]['fieldtitle'].':'.phpstrip_tags($notags=$Arrfield[$key]['fieldval']).' / ';
			break;
			case "4":
			 	foreach($Arrfield[$key]['fieldval'] as $val2) {
				$listval.=$val2.',';
			}
			if(!empty($Arrfield[$key]['fieldval'])) $fieldvar.=$Arrfield[$key]['fieldtitle'].':'.substr($listval,0,-1).' / ';
			unset($listval);
			break;
			case "7":
			 	foreach($Arrfield[$key]['fieldval'] as $val2) {
				$listval.=$val2['original'].',';
			}
			if(!empty($Arrfield[$key]['fieldval'])) $fieldvar.=$Arrfield[$key]['fieldtitle'].':'.substr($listval,0,-1).' / ';
			unset($listval);
			break;
		}
	}
	return  $fieldvar;
}

//檔案下載區塊/管理
function neillibrary_fielddownloadbox($fileArr="",$url="",$pageadmin="",$value="",$fnumber="",$moduleid=""){
global $xoopsModule,$themefolder;

foreach($value as $val){	
global $$val;
}

$i=1;
$filebox.="<div class='row'>";
foreach($fileArr as $key=> $val){
if(!empty($pageadmin)){
switch($xoopsModule->getVar("dirname")){
  case "neilsignedup_a":
  $adminbtn[$key]="<button type='button' id='deletebotton".$fnumber."{$i}'   class='btn btn-danger btn-sm btn-block' name='186,".$centerid.",".$fileArr[$key]['original'].","._MS_CUSTOMFIELD42.",false,".$applyid.",".$xoopsModule->getVar("dirname").",,".$fileArr[$key]['filename'].",".$url.",neilsignedup_a_apply,applyid'>"._MS_CUSTOMFIELD43."</button>";
  $downloadbox[$key]="<div id='downloadbox'><a  target='_blank' href='".XOOPS_URL."/modules/neillibrary/download.php?modulesid=".$xoopsModule->getVar("dirname")."&centerid=".$centerid."&applyid=".$applyid."&namefile=".$url.'/'.$fileArr[$key]['filename']."' class='btn btn-line btn-sm btn-block'>"._MS_SHARED211."</a></div>";
  break;
  case "neilproduct":
  $adminbtn[$key]="<button type='button' id='deletebotton".$fnumber."{$i}'   class='btn btn-danger btn-sm btn-block' name='186,,".$fileArr[$key]['original'].","._MS_CUSTOMFIELD42.",false,".$pinquiryid.",".$xoopsModule->getVar("dirname").",,".$fileArr[$key]['filename'].",".$url.",productinquiry,pinquiryid'>"._MS_CUSTOMFIELD43."</button>";
  $downloadbox[$key]="<a id='downloadbox' target='_blank' href='".XOOPS_URL."/modules/neillibrary/download.php?modulesid=".$xoopsModule->getVar("dirname")."&pinquiryid=".$pinquiryid."&namefile=".$url.'/'.$fileArr[$key]['filename']."' class='btn btn-line btn-sm btn-block'>"._MS_SHARED211."</a>";
  break;
}

$operatebox[$key]="<div class='row row-initial operatebox'>
   <div class='col-md-6 col-mdinitial' style='padding: 0px 5px;'>".$downloadbox[$key]."</div>
   <div class='col-md-6 col-mdinitial' style='padding: 0px 5px;'>".$adminbtn[$key]."</div>
   </div>";
}


//檔案ICON
$fileArr[$key]['icombox']=neillibrary_openmethod($ftype=end(explode('.', $fileArr[$key]['filename'])),$ftitle=$fileArr[$key]['filename'],$modulesid,$furl="".$url."/".$fileArr[$key]['filename']."",$browse=true);
$filebox.="
    <div class='col-md-3 col-xs-4' id='deletebottonbox".$fnumber."{$i}'>
    <div class='thumbnail'>
    ".$fileArr[$key]['icombox']."
    <div id='datename'>".strriposfunction($fileArr[$key]['original'],$type="1")."</div>      
    ".$operatebox[$key]."
  	</div> 
  	</div>";

$filebox.="
<script >
$(document).ready(function() {	
btndeletefunction(centerid=".$fnumber.$i.");
});
</script>
";	

$i++;	
}

$filebox.="</div>";


return  $filebox;
}






//反解自訂欄位內容
function  neillibrary_undeletefieldcontent($moduleid="",$material="",$url="",$value="",$pageadmin="") {
	global $themefolder;
	foreach($value as $val) {
		global $$val;
	}
	$colmdvar=neillibrary_typesetting($fwidthoption=$material['fwidthoption']);
	
	if($material['fypeoption']=='6') $material['fieldval']=str_replace ("T"," ",$material['fieldval']);
	switch($material['fypeoption']) {
		case "1":
		case "3":
		case "5":
		case "6":
if(!empty($material['fieldval'])) $box="<div id='fieldcontentbox'  class='col-md-".$material['fwidthoption']."'>
<div class='row'>
<div class='col-md-".$colmdvar['0']." col-xs-5'><label class='control-label'>".$material['fieldtitle']._MS_CUSTOMFIELD41."</label></div>
<div class='col-md-".$colmdvar['1']." col-xs-7'>".$material['fieldval']."</div>
</div></div>	 ";
		break;
		case "2":		
		$material['fieldval']=empty(judgeHtml($material['fieldval'])) ? neillibrary_textprocessing($val=$material['fieldval']) : $material['fieldval'];
		// get TRUE
if(!empty($material['fieldval']))  $box="<div id='fieldcontentbox'  class='col-md-".$material['fwidthoption']."'>
<div class='row'>
<div class='col-md-".$colmdvar['0']."'><label class='control-label'>".$material['fieldtitle']._MS_CUSTOMFIELD41."</label></div>
<div class='col-md-".$colmdvar['1']."'>".$material['fieldval']."</div>
</div></div>	 ";
		break;
		case "4":
			foreach($material['fieldval'] as $val) {
			$listval.="<div>".$val."</div>";
		}
if(!empty($material['fieldval']))  $box="<div id='fieldcontentbox'  class='col-md-".$material['fwidthoption']."'>
<div class='row'>
<div class='col-md-".$colmdvar['0']." col-xs-5'><label class='control-label'>".$material['fieldtitle']._MS_CUSTOMFIELD41."</label></div>
<div class='col-md-".$colmdvar['1']." col-xs-7'>".$listval."</div>
</div></div>	 ";
		break;
		case "7":
if(!empty($material['fieldval'])) $box="<div id='fieldcontentbox'  class='col-md-12'>
<div class='row'>
<div class='col-md-2'><label class='control-label'>".$material['fieldtitle']._MS_CUSTOMFIELD41."</label></div>
<div class='col-md-10' id='filedivbox'>".neillibrary_fielddownloadbox($fileArr=$material['fieldval'],$url,$pageadmin,$value,$fnumber=$material['fnumber'],$moduleid)."</div>
</div></div>	 ";
		break;
	}
	return $box;
}
	
	
//自訂表單欄位內容陣列化
function  neillibrary_lineupoftableinside($conversion="",$post="",$files="",$urlfile="",$spelling="") {
	
foreach($value as $val){	
global $$val;
}	
foreach($Arr=phpconversion($conversion,$type="unserialize") as $key=> $val) {	
	
	switch($Arr[$key]['fypeoption']) {
		case "1":
		case "3":
		case "5":
		$store[$key]['fieldval']=phpstrip_tags($notags=sqlinjectionfound($v=$post['invert'][$Arr[$key]['fnumber']],$coderemove=true));
		break;		
		case "2":
		$store[$key]['fieldval']=sqlinjectionfound($v=$post['invert'][$Arr[$key]['fnumber']],$coderemove=true);
		break;
		
		case "4":
		foreach($post['invert'][$Arr[$key]['fnumber']]  as $i=> $va2) {
			$store[$key]['fieldval'][$i]=phpstrip_tags($notags=sqlinjectionfound($v=$va2));
		}	
		break;		
		case "6":
		$store[$key]['fieldval']=sqlinjectionfound($v=$post['invert'][$Arr[$key]['fnumber']],$coderemove=true);
		break;
		
		case "7":
			if(!empty($files['invert'.$Arr[$key]['fnumber'].'']['name'][0])) {
			foreach($files['invert'.$Arr[$key]['fnumber'].'']['name'] as $i=> $val) {
				//檔名+前置
				$filename[$i]=$spelling.'_'.$Arr[$key]['fnumber'].'_'.$i.'_'.strriposfunction($val,$type="1");
				//副檔名
				$fileextension[$i]=strriposfunction($val,$type="2");
				//存資料庫+前置
				$store[$key]['fieldval'][$i]['filename']=$filename[$i].'.'.$fileextension[$i];
				//存資料庫+原始
				$store[$key]['fieldval'][$i]['original']=strriposfunction($val,$type="1").'.'.$fileextension[$i];
			}
			//建立目錄
	//		fileadminfunction($fileurl="",$type="4",$fileex="",$from=XOOPS_ROOT_PATH . "/uploads/".$urlfile.'/'.$spelling.'"_child',$fileurlnew="",$exclude="");

			//製作檔案
			save_pic($up_id=$filename,$width="",$height="",$modules="".$urlfile."",$plural=false,$convert=$fileextension,$arr=false,$process=1,$crop=false,$upfile=$files['invert'.$Arr[$key]['fnumber'].''],$type="3");
		}
	
		break;
	}
		$store[$key]['fieldtitle']=phpstrip_tags($notags=sqlinjectionfound($v=$post['fieldtitle'][$Arr[$key]['fnumber']],$coderemove=true));
		$store[$key]['fypeoption']=$Arr[$key]['fypeoption'];
		$store[$key]['fwidthoption']=$Arr[$key]['fwidthoption'];	
		$store[$key]['fnumber']=$Arr[$key]['fnumber'];	
}


	return $store;
}



	
	

	
//自訂欄位驗證	
function  neillibrary_customfieldvalidation($conversion="",$post="") {
	foreach($Arr=phpconversion($conversion,$type="unserialize") as $key=> $val) {
		//欄位標題-HTML  
		if(judgeHtml($post['fieldtitle'][$Arr[$key]['fnumber']])==true) {
			$harmful=true;
			break;
		}
		switch($Arr[$key]['fypeoption']) {
			case "1":
			//必填	  
			if(!empty($Arr[$key]['frequired'])) {
				if(empty($post['invert'][$Arr[$key]['fnumber']])) {
					$harmful=true;
					break;
				}
			}
			//HTML  
			if(judgeHtml($post['invert'][$Arr[$key]['fnumber']])==true) {
				$harmful=true;
				break;
			}
			break;
			case "2":
			//必填	  
			if(!empty($Arr[$key]['frequired'])) {
				if(empty($post['invert'][$Arr[$key]['fnumber']])) {
					$harmful=true;
					break;
				}
			}
			//HTML  
			if(empty($Arr[$key]['fsetup']['0'])  &&   judgeHtml($post['invert'][$Arr[$key]['fnumber']])==true) {
				$harmful=true;
				break;
			}
			break;
			case "3":
			//必填
			if(!empty($Arr[$key]['frequired'])) {
				if(empty($post['invert'][$Arr[$key]['fnumber']])) {
					$harmful=true;
					break;
				}
			}
			//HTML  
			if(judgeHtml($post['invert'][$Arr[$key]['fnumber']])==true) {
				$harmful=true;
				break;
			}
			break;
			case "4":
			//必填	  
			if(!empty($Arr[$key]['frequired'])) {
				if(empty($post['invert'][$Arr[$key]['fnumber']])) {
					$harmful=true;
					break;
				}
			}
			//HTML 
			foreach($post['invert'][$Arr[$key]['fnumber']] as   $val) {
				if(judgeHtml($val)==true) {
					$harmful=true;
					break;
				}
			}
			break;
			case "5":
			//必填	  
			if(!empty($Arr[$key]['frequired'])) {
				if(empty($post['invert'][$Arr[$key]['fnumber']])) {
					$harmful=true;
					break;
				}
			}
			//HTML  
			if(judgeHtml($post['invert'][$Arr[$key]['fnumber']])==true) {
				$harmful=true;
				break;
			}
			break;
			case "6":
			//必填	  
			if(!empty($Arr[$key]['frequired'])) {
				if(empty($post['invert'][$Arr[$key]['fnumber']])) {
					$harmful=true;
					break;
				}
			}
			//HTML  
			if(judgeHtml($post['invert'][$Arr[$key]['fnumber']])==true) {
				$harmful=true;
				break;
			}
			
			//時間格式
			if(!empty($post['invert'][$Arr[$key]['fnumber']])  &&  validateDate($date=substr($post['invert'][$Arr[$key]['fnumber']], 0, 10), $format="Y-m-d")==false) {
				$harmful=true;
				break;
			}
			break;
			case "7":
			//必填	  
			if(!empty($Arr[$key]['frequired'])) {
				if(empty($_FILES['invert'.$Arr[$key]['fnumber'].'']['name'][0])) {
					$harmful=true;
					break;
				}
			}
			//數量
			$quantity = is_array($_FILES['invert'.$Arr[$key]['fnumber'].'']['name']) ? count($_FILES['invert'.$Arr[$key]['fnumber'].'']['name']) : 0 ;
			if($quantity > $Arr[$key]['fsetup']['0']) {
				$harmful=true;
				break;
			}
			if(!empty($_FILES['invert'.$Arr[$key]['fnumber'].'']['name'][0])){
			foreach($_FILES['invert'.$Arr[$key]['fnumber'].'']['tmp_name'] as $i=> $val) {
				//檢測文件的 MIME 內容類型	
				$mime_type = mime_content_type($val);
				//可上傳MIME類型
				foreach($fieldArr=$Arr[$key]['fieldArr'] as $val) {
					switch($val) {
						case "1":
						//圖片類型檔案						
						$allowed_file_types = ['image/png', 'image/jpeg','image/gif'];
						break;
						case "2":
					   //文件類型檔案
						$allowed_file_types = ['application/msword','application/vnd.ms-excel','application/vnd.ms-powerpoint','application/pdf','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
						break;
					}
				}
				
											
				if(empty($Arr[$key]['fieldArr'])  ||   (!empty($Arr[$key]['fieldArr']['0']) &&  !empty($Arr[$key]['fieldArr']['1']))){
				$allowed_file_types = ['image/png', 'image/jpeg','image/gif','application/msword','application/vnd.ms-excel','application/vnd.ms-powerpoint','application/pdf','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'];
				}
			
				if (!in_array($mime_type, $allowed_file_types)) {
					// File type is NOT allowed.
	        	  	$harmful=true;
					break;
				}
				}
			}
			break;
		}
	}
	
	
	return $harmful;
}
	
	
	
	
function  neillibrary_uploadfiletype($val="") {
	
switch($val){
  case "1":
  //圖片類型檔案
$box="JPG,PNG,GIF";
  
  break;
   case "2":
  //文件類型檔案
$box="Word,Excel,PowerPoint,pdf";
  break; 
  
  default:
$box=neillibrary_uploadfiletype($val="1").','.neillibrary_uploadfiletype($val="2").',';

}
	

	return $box;
}	
	
//col-md配置	
function  neillibrary_typesetting($fwidthoption="") {
	switch($fwidthoption) {
		case "5":
		case "4":
		$Arr['0']=4;
		$Arr['1']=8;
		break;
		
		case "7":	
		case "6":
		$Arr['0']=3;
		$Arr['1']=9;
		break;	
		
		case "12":
		case "8":
		$Arr['0']=2;
		$Arr['1']=10;
		break;

	}
	return $Arr;
}
	
	
	
	
//反解自訂欄位
function  neillibrary_invertfield($moduleid="",$fieldtype="",$number="",$material="",$required=""){
global $themefolder;	


//col-md值
$colmdvar=neillibrary_typesetting($fwidthoption=$material['fwidthoption']);
//備註說明
if(!empty($material['fdirections'])) $fdirectionsbox="<span id='helpBlock' class='help-block'>".$material['fdirections']."</span>";
//必填
if(!empty($material['frequired'])) $requiredbox="<span style='display: block;' id='helpBlockfield".$number."'  class='red ".$required[0]."'>"._MS_SHARED22."</span>";


switch($fieldtype){
  case "1":
 //文字輸入框
$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']."'>
<div class='row'>
<div class='col-md-".$colmdvar['0']."'><label class='control-label'>".$material['fieldtitle']."</label></div>
<div class='col-md-".$colmdvar['1']."'>".inputtext($class="",$name="invert[".$number."]",$value="",$placeholder=_MS_SHARED21.$material['fieldtitle'],$id="invertid".$number."").$fdirectionsbox.$requiredbox."</div>
</div></div>	 
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>  
 ";
if(!empty($material['frequired'])){
$box.="
<script> 	
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."');
</script>	
";
}

  break;
 
  case "2":  
  	  
 //大量文字輸入框
$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']."'>
<div class='row'>
<div class='col-md-".$colmdvar['0']."'><label class='control-label'>".$material['fieldtitle']."</label></div>
<div class='col-md-".$colmdvar['1']."'>".inputtextarea($class="",$name="invert[".$number."]",$id="textarea".$number."",$rows=$material['fsetup']['1'],$cols="80",$value="").$fdirectionsbox.$requiredbox."</div>
</div></div>	 
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>
";
 
if(!empty($material['fsetup']['0'])) {
$box.="	
<script> 	
CKEDITOR.replace( 'textarea".$number."', {
    height: '".$material['fsetup']['1']."00'
});
CKEDITOR.config.contentsCss=CKEDITOR.getUrl('".$themefolder."_contents.css');
</script>

";
}

if(!empty($material['frequired']) && !empty($material['fsetup']['0']) ){
$box.="
<script> 
    $('body').on('click', $(this), function() {
    if (CKEDITOR.instances.textarea".$number.".getData()) {
            $('#helpBlockfield".$number."').hide().text(true);
        } else {
            $('#helpBlockfield".$number."').show().text('"._MS_SHARED22."');
        }
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."',fsetup=".$material['fsetup']['0'].");
  
    })	
</script>	
";
}



if(!empty($material['frequired']) && empty($material['fsetup']['0'])){
$box.="
<script> 
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."',fsetup=".$material['fsetup']['0'].");
</script>	
";
}

 
  break;
  
  
 
  case "3":
//單選按鈕

foreach($material['fieldArr'] as $key=> $val){
$radiobox.=radioinlinelist($dataid="0",$class="",$name="invert[".$number."]",$text=$material['fieldArr'][$key],$value=$material['fieldArr'][$key],$oid="",$id="invertid".$number."");
if($themefolder=='phone' || !empty($material['fsetup']['0'])) $radiobox.="<div style='clear: both;'></div>";	
	
}


$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']."'>
<div class='row'>
<div class='col-md-".$colmdvar['0']."'><label class='control-label'>".$material['fieldtitle']."</label></div>
<div class='col-md-".$colmdvar['1']."'>".$radiobox.$fdirectionsbox.$requiredbox."</div>
</div></div>	 
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>  
	
 ";
 
if(!empty($material['frequired'])){
$box.="
<script> 	
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."');
</script>	
";
} 
  break;
  
  case "4":
//多選按鈕
foreach($material['fieldArr'] as $key=> $val){
$radiobox.=checkbox($dataid="0",$name="invert[".$number."][]",$value=$material['fieldArr'][$key],$optionname=$material['fieldArr'][$key],$oid="",$i="",$class="invertid".$number."");  
if($themefolder=='phone' || !empty($material['fsetup']['0'])) $radiobox.="<div style='clear: both;'></div>";	
}


$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']."'>
<div class='row'>
<div class='col-md-".$colmdvar['0']."'><label class='control-label'>".$material['fieldtitle']."</label></div>
<div class='col-md-".$colmdvar['1']."'>".$radiobox.$fdirectionsbox.$requiredbox."</div>
</div></div>	 
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>  
 ";
if(!empty($material['frequired'])){
$box.="
<script> 	
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."');
</script>	
";
} 

  break;
  
  
  
 
  case "5":
//下拉選單
foreach($material['fieldArr'] as $key=> $val){
$optionselect.=optionselect($dataid='0',$optionname=$material['fieldArr'][$key],$oid="",$value=$material['fieldArr'][$key]);
}


$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']."'>
<div class='row'>
<div class='col-md-".$colmdvar['0']."'><label class='control-label'>".$material['fieldtitle']."</label></div>
<div class='col-md-".$colmdvar['1']."'>
<select id='invertid".$number."'  class='form-control' name='invert[".$number."]' >
<option value='0'  data-id='0' >".$material['fieldtitle']."</option>
".$optionselect."
</select>".$fdirectionsbox.$requiredbox."</div>
</div></div>	 
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>  
 ";
if(!empty($material['frequired'])){
$box.="
<script> 	
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."');
</script>	
";
} 
  break;
  
 
 case "6":
//日期時間

if($themefolder=='computer'){
//顯示時分秒
if(!empty($material['fsetup']['0'])){
$presettimebox="";
}else{
//不顯示
$presettimebox="
    $('body').on('change', '#field".$number."', function() {
        var date = $(this).val();
        var newDate = /\d{4}-\d{1,2}-\d{1,2}/g.exec(date);
        $(this).val(newDate);
        $('.ui-timepicker-div').remove();
    })
";
$typeval='text';
}
}else{
if(!empty($material['fsetup']['0'])){
//顯示時分秒	
$typeval='datetime-local';
}else{
$typeval='date';
}	

}

$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']."'>
<div class='row'>
<div class='col-md-".$colmdvar['0']."'><label class='control-label'>".$material['fieldtitle']."</label></div>
<div class='col-md-".$colmdvar['1']."'>".inputtext($class="",$name="invert[".$number."]",$value=$presettime,$placeholder=$presettime,$id="field".$number."",$typeval).$fdirectionsbox.$requiredbox."</div>
</div></div>	 
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>  
	
 ";
//若模組沒引入datepicker須由$signedupshow['inversejs']引入 
if($themefolder=='computer'){
$box.="
<script> 	
    $('#field".$number."').datetimepicker({
      'dateFormat': 'yy-mm-dd',  
      'timeFormat': 'HH:mm'
    });
".$presettimebox."      
</script>
<style> 	
#ui-datepicker-div {
    margin-left: 0px;
}
</style> 

"; 
}

$box.="
<script> 	
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."',fsetup='',frequired='".$material['frequired']."');
</script>	
";

  break;
  
     case "7":
//檔案上傳
foreach($material['fieldArr'] as $key=> $val){
$uploadtype.=neillibrary_uploadfiletype($val=$material['fieldArr'][$key]).',';
}
if(empty($material['fieldArr'])){
$uploadtype.=neillibrary_uploadfiletype($val="");
}

$uploadtypetext="<span id='helpBlock' class='help-block'>".sprintf(_MS_CUSTOMFIELD38,substr($uploadtype,0,-1)).' / '.sprintf(_MS_CUSTOMFIELD39,$material['fsetup']['0'])."</span>";

$box.="
<div id='invertfieldbox' class='col-md-".$material['fwidthoption']."'>
<div class='row'>
<div class='col-md-".$colmdvar['0']."'><label class='control-label'>".$material['fieldtitle']."</label></div>
<div class='col-md-".$colmdvar['1']."'>".typefile($multiple=true,$name="invert".$number."[]",$id="field".$number."").'<span id="warningbox'.$number.'"></span>'.$fdirectionsbox.$uploadtypetext.$requiredbox."</div>
</div></div>	 
<input type='hidden' name='fieldtitle[".$number."]' value='".$material['fieldtitle']."'>  
	
 ";
$box.="
<script> 	
".$moduleid."_customfieldvalidation(fieldtype=".$fieldtype.",number=".$number.",blockeach='".$required[0]."',id='".$required[1]."',fsetup='".$material['fsetup']['0']."',frequired='".$material['frequired']."',fieldArr='".phpconversion($conversion=$material['fieldArr'],$type="serialize")."');
</script>	
"; 
  break;

}

return $box;	
}




	
//建立自訂欄位設定陣列
function  neillibrary_fieldsettingarr($post="") {
	foreach($post['fnumber']  as $key=> $val) {
		if(!empty($post['fieldtitle'][$key])) {
			$Arr[$key]['fieldtitle']=phpstrip_tags($notags=sqlinjectionfound($v=$post['fieldtitle'][$key]));
			//欄位名稱
			$Arr[$key]['fypeoption']=$post['fypeoption'][$key];
			//欄位類型
			$Arr[$key]['fdirections']=phpstrip_tags($notags=sqlinjectionfound($v=$post['fdirections'][$key]));
			//欄位說明
			$Arr[$key]['fwidthoption']=$post['fwidthoption'][$key];
			//欄位寬度
			//設定	
			foreach($post['fsetup'.$val.'']  as $i=> $va2) {
				$Arr[$key]['fsetup'][$i]=$va2;
			}
			$Arr[$key]['frequired']=$post['frequired'][$val];
			//是否必填
			$Arr[$key]['fnumber']=$post['fnumber'][$key];
			//編號
			//陣列
			foreach($post['fieldArr'.$val.'']  as $i=> $va3) {
				if(!empty($va3)) {
					$Arr[$key]['fieldArr'][$i]=phpstrip_tags($notags=sqlinjectionfound($v=$va3));
					$Arr[$key]['optionsname'][$i]=$post['optionsname'.$val.''][$i];
				}
			}
		}
	}
	return $Arr;
}




//新增文字框欄位(排序/刪除)
function  neillibrary_inputboxfield($optionsname="",$number="",$val=""){	
global $themefolder;	
	
if($themefolder=='computer'){
$handle="<div class='col-md-1'>
    <div title='"._MS_SHARED215."' id='projectsort' class='project".$number."'><span class='glyphicon glyphicon-sort' aria-hidden='true'></span></div>
    </div>";
$scriptbox="
<script>dragmenufunctionnoajax(itemsvar='.sortbox".$number."',handlevar='.project".$number."',axisvar='y',editor='',cktype='',sortableid='#optionsbox".$number."');</script>
	
<style type='text/css'> 
.project".$number."{
cursor: move; 
}
</style>
";
}	
	
$box.="<div id='optionseachbox'  name='".$optionsname."' class='optionseach".$number." deleteoptionsbox".$number.$optionsname." sortbox".$number."'>
<div class='row'>
<div class='col-xs-10' >
".inputtext($class="",$name="fieldArr".$number."[]",$value=htmlspecialchars($val),$placeholder='',$id="fieldArreach".$number."")."
</div>
".$handle."
<div class='col-xs-1'><button id='deleteoptions".$number.$optionsname."' type='button' class='btn btn-danger btn-sm'>"._MS_SHARED09."</button></div>
</div><input id='optionsnameeach".$number."' type='hidden' name='optionsname".$number."[]' value='".$optionsname."'>

<script>	
$('body').on('click', '#deleteoptions".$number.$optionsname."', function() {
    $('.deleteoptionsbox".$number.$optionsname."').remove();
})	
</script>	
".$scriptbox."	
	</div>
";


return $box;
}

	
//新增自訂欄位
function  neillibrary_dcustomfield($moduleid="",$fieldtype="",$number="",$centerid="",$change="",$material="",$ajaxid="",$fromtype=""){
global $themefolder,$xoopsConfig;	

//空值刪除變數
if(empty($material)) unset($material);

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



switch($fromtype){
  case "1":
  $closure['0']=true; //關閉檔案上傳功能
  $closure['1']=true; //欄位寬度指定100%
  //
  break;
  
  default:
  $fromtype="0";
}






//選擇欄位類型
$fypeArr = array(); //建構陣列
$i=0;
$fypeArr[$i]['id']='1';  //文字輸入框
$fypeArr[$i]['title']=_MS_CUSTOMFIELD08;
$i++;

$fypeArr[$i]['id']='2';  //大量文字輸入框
$fypeArr[$i]['title']=_MS_CUSTOMFIELD09;
$i++;

$fypeArr[$i]['id']='3';  //單選按鈕
$fypeArr[$i]['title']=_MS_CUSTOMFIELD10;
$i++;

$fypeArr[$i]['id']='4';  //多選核取
$fypeArr[$i]['title']=_MS_CUSTOMFIELD11;
$i++;

$fypeArr[$i]['id']='5';  //下拉選單
$fypeArr[$i]['title']=_MS_CUSTOMFIELD12;
$i++;

$fypeArr[$i]['id']='6';  //日期時間
$fypeArr[$i]['title']=_MS_CUSTOMFIELD13;
$i++;
if(empty($closure['0'])){
$fypeArr[$i]['id']='7';  //檔案上傳
$fypeArr[$i]['title']=_MS_CUSTOMFIELD14;
$i++;
}

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


//選擇欄位寬度
$fwidthArr = array(); //建構陣列
$i=0;
if(empty($closure['1'])){
$fwidthArr[$i]['id']='4';  
$fwidthArr[$i]['title']='col-md-'.$fwidthArr[$i]['id'].'->33%';
$i++;
$fwidthArr[$i]['id']='5';  
$fwidthArr[$i]['title']='col-md-'.$fwidthArr[$i]['id'].'->42%';
$i++;
$fwidthArr[$i]['id']='6';  
$fwidthArr[$i]['title']='col-md-'.$fwidthArr[$i]['id'].'->50%';
$i++;
$fwidthArr[$i]['id']='7';  
$fwidthArr[$i]['title']='col-md-'.$fwidthArr[$i]['id'].'->58%';
$i++;
$fwidthArr[$i]['id']='8';  
$fwidthArr[$i]['title']='col-md-'.$fwidthArr[$i]['id'].'->67%';
$i++;
}
$fwidthArr[$i]['id']='12';  
$fwidthArr[$i]['title']='col-md-'.$fwidthArr[$i]['id'].'->100%';
$i++;

//下拉選單(狀態)
foreach($fwidthArr=array_reverse($fwidthArr) as $key=> $val){
$fieldshow['2'].=optionselect($dataid=$fwidthArr[$key]['id'],$optionname=$fwidthArr[$key]['title'],$oid="".$material['fwidthoption']."",$value=$fwidthArr[$key]['id']);
}









if($themefolder=='computer'){
$handle="<div class='col-md-1'>
    <div title='"._MS_SHARED215."' class='handle'><span class='glyphicon glyphicon-sort' aria-hidden='true'></span></div>
    </div>";
}

switch($fieldtype){
  case "1":
//文字說明框
$box.="<span id='fcontent".$number."' class='itemssort'><div id='fieldbox".$number."' class='alert alert-green-customize fieldbox' role='alert' name='".$number."'>
	
<div class='form-group'>
<div class='row'>
".$handle."	
  <div class='col-md-2'>"._MS_CUSTOMFIELD06."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fieldtitle[]",$value=htmlspecialchars($material['fieldtitle']),$placeholder=_MS_CUSTOMFIELD06,$id="fieldtitle".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD07."</div>
  <div class='col-md-3'><select id='fypeoption".$number."' class='form-control' name='fypeoption[]' >
  ".$fieldshow['1']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD15."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fdirections[]",$value=htmlspecialchars($material['fdirections']),$placeholder=_MS_CUSTOMFIELD15,$id="fdirections".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD16."</div>
  <div class='col-md-3'><select id='fwidthoption".$number."' class='form-control' name='fwidthoption[]' >
  ".$fieldshow['2']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD18."</div>
  <div class='col-md-4'>".radioinline($class="frequired".$number."",$name="frequired[".$number."]",$text=array(_MS_SHARED04,_MS_SHARED03),$checked=$material['frequired'])."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD20."</div>
  <div class='col-md-3'>
    
    
    <button id='delete".$number."' type='button' class='btn btn-danger btn-sm '>"._MS_SHARED09."</button>
    <button id='copy".$number."' type='button' class='btn btn-success btn-sm'>"._MS_CUSTOMFIELD21."</button>
    	
    	
    </div>
</div>
</div>
	
	
</div>
<input type='hidden' name='fnumber[]' value='".$number."'>
<div style='clear: both;'></div>      	   	
</span>";


  break;
  
  case "2":
  	  
$material['fsetup']['1']=empty($material['fsetup']['1']) ? '5' : $material['fsetup']['1']; // get TRUE  	  
//大量文字框  	  
$box.="<span id='fcontent".$number."' class='itemssort'><div id='fieldbox".$number."' class='alert alert-blue-customize fieldbox' role='alert' name='".$number."'>
	
	
<div class='form-group'>
<div class='row'>
".$handle."	
  <div class='col-md-2'>"._MS_CUSTOMFIELD06."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fieldtitle[]",$value=htmlspecialchars($material['fieldtitle']),$placeholder=_MS_CUSTOMFIELD06,$id="fieldtitle".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD07."</div>
  <div class='col-md-3'><select id='fypeoption".$number."' class='form-control' name='fypeoption[]' >
  ".$fieldshow['1']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD15."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fdirections[]",$value=htmlspecialchars($material['fdirections']),$placeholder=_MS_CUSTOMFIELD15,$id="fdirections".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD16."</div>
  <div class='col-md-3'><select id='fwidthoption".$number."' class='form-control' name='fwidthoption[]' >
  ".$fieldshow['2']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD22."</div>
  <div class='col-md-4'>".radioinline($class="fsetup".$number."0",$name="fsetup".$number."[0]",$text=array(_MS_SHARED04,_MS_SHARED03),$checked=$material['fsetup']['0'])."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD23."</div>
  <div class='col-md-3'>".inputtext($class="fsetup".$number."1",$name="fsetup".$number."[1]",$value=htmlspecialchars($material['fsetup']['1']),$placeholder=_MS_CUSTOMFIELD23,$id="fsetup".$number."")."</div>
</div>
</div>

	
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD18."</div>
  <div class='col-md-4'>".radioinline($class="frequired".$number."",$name="frequired[".$number."]",$text=array(_MS_SHARED04,_MS_SHARED03),$checked=$material['frequired'])."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD20."</div>
  <div class='col-md-3'>
    <button id='delete".$number."' type='button' class='btn btn-danger btn-sm'>"._MS_SHARED09."</button>
    <button id='copy".$number."' type='button' class='btn btn-success btn-sm'>"._MS_CUSTOMFIELD21."</button>
    </div>
</div>
</div>
	
	
</div>
<input type='hidden' name='fnumber[]' value='".$number."'> 
<div style='clear: both;'></div>      	  		
</span>";
  break;
  
  
  case "3":
	  
foreach($material['fieldArr']  as $key=> $val){

$optionsList.=neillibrary_inputboxfield($optionsname=$material['optionsname'][$key],$number,$val);
}
  	  
//單選按鈕	  
$box.="<span id='fcontent".$number."' class='itemssort'><div id='fieldbox".$number."' class='alert alert-orange-customize fieldbox' role='alert' name='".$number."'>
	
<div class='form-group'>
<div class='row'>
".$handle."	
  <div class='col-md-2'>"._MS_CUSTOMFIELD06."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fieldtitle[]",$value=htmlspecialchars($material['fieldtitle']),$placeholder=_MS_CUSTOMFIELD06,$id="fieldtitle".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD07."</div>
  <div class='col-md-3'><select id='fypeoption".$number."' class='form-control' name='fypeoption[]' >
  ".$fieldshow['1']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD15."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fdirections[]",$value=htmlspecialchars($material['fdirections']),$placeholder=_MS_CUSTOMFIELD15,$id="fdirections".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD16."</div>
  <div class='col-md-3'><select id='fwidthoption".$number."' class='form-control' name='fwidthoption[]' >
  ".$fieldshow['2']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD24."</div>
  <div class='col-md-4'>".radioinline($class="fsetup".$number."0",$name="fsetup".$number."[0]",$text=array(_MS_CUSTOMFIELD25,_MS_CUSTOMFIELD26),$checked=$material['fsetup']['0'])."</div>
 </div>
</div>
	

<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'><button id='newoptions".$number."' name='".$centerid."' type='button' class='btn btn-primary btn-block'>"._MS_CUSTOMFIELD27."</button>	</div>
  <div class='col-md-9'>
    <div id='optionsbox".$number."' class='optionsbox'>
    ".$optionsList."    
    </div>
    
    
    </div>
 </div>
</div>

	
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD18."</div>
  <div class='col-md-4'>".radioinline($class="frequired".$number."",$name="frequired[".$number."]",$text=array(_MS_SHARED04,_MS_SHARED03),$checked=$material['frequired'])."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD20."</div>
  <div class='col-md-3'>
    <button id='delete".$number."' type='button' class='btn btn-danger btn-sm'>"._MS_SHARED09."</button>
    <button id='copy".$number."' type='button' class='btn btn-success btn-sm'>"._MS_CUSTOMFIELD21."</button>
    </div>
</div>
</div>
	
	
</div>
<input type='hidden' name='fnumber[]' value='".$number."'> 
<div style='clear: both;'></div>
</span>";


  break;
  
  case "4":
foreach($material['fieldArr']  as $key=> $val){
$optionsList.=neillibrary_inputboxfield($optionsname=$material['optionsname'][$key],$number,$val);
}
  	  
//多選按鈕	  
$box.="<span id='fcontent".$number."' class='itemssort'><div id='fieldbox".$number."' class='alert alert-red-customize fieldbox' role='alert' name='".$number."'>
	
<div class='form-group'>
<div class='row'>
".$handle."	
  <div class='col-md-2'>"._MS_CUSTOMFIELD06."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fieldtitle[]",$value=htmlspecialchars($material['fieldtitle']),$placeholder=_MS_CUSTOMFIELD06,$id="fieldtitle".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD07."</div>
  <div class='col-md-3'><select id='fypeoption".$number."' class='form-control' name='fypeoption[]' >
  ".$fieldshow['1']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD15."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fdirections[]",$value=htmlspecialchars($material['fdirections']),$placeholder=_MS_CUSTOMFIELD15,$id="fdirections".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD16."</div>
  <div class='col-md-3'><select id='fwidthoption".$number."' class='form-control' name='fwidthoption[]' >
  ".$fieldshow['2']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD24."</div>
  <div class='col-md-4'>".radioinline($class="fsetup".$number."0",$name="fsetup".$number."[0]",$text=array(_MS_CUSTOMFIELD25,_MS_CUSTOMFIELD26),$checked=$material['fsetup']['0'])."</div>
 </div>
</div>
	

<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'><button id='newoptions".$number."' name='".$centerid."' type='button' class='btn btn-primary btn-block'>"._MS_CUSTOMFIELD27."</button>	</div>
  <div class='col-md-9'>
    <div id='optionsbox".$number."' class='optionsbox'>
    ".$optionsList."    
    </div>
    
    
    </div>
 </div>
</div>

	
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD18."</div>
  <div class='col-md-4'>".radioinline($class="frequired".$number."",$name="frequired[".$number."]",$text=array(_MS_SHARED04,_MS_SHARED03),$checked=$material['frequired'])."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD20."</div>
  <div class='col-md-3'>
    <button id='delete".$number."' type='button' class='btn btn-danger btn-sm'>"._MS_SHARED09."</button>
    <button id='copy".$number."' type='button' class='btn btn-success btn-sm'>"._MS_CUSTOMFIELD21."</button>
    </div>
</div>
</div>
	
	
</div>
<input type='hidden' name='fnumber[]' value='".$number."'> 
<div style='clear: both;'></div>
</span>";
  break;
  
    case "5":
foreach($material['fieldArr']  as $key=> $val){
$optionsList.=neillibrary_inputboxfield($optionsname=$material['optionsname'][$key],$number,$val);
}
  	  
//下拉選單	  
$box.="<span id='fcontent".$number."' class='itemssort'><div id='fieldbox".$number."' class='alert alert-grey-customize fieldbox' role='alert' name='".$number."'>
	
<div class='form-group'>
<div class='row'>
".$handle."	
  <div class='col-md-2'>"._MS_CUSTOMFIELD06."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fieldtitle[]",$value=htmlspecialchars($material['fieldtitle']),$placeholder=_MS_CUSTOMFIELD06,$id="fieldtitle".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD07."</div>
  <div class='col-md-3'><select id='fypeoption".$number."' class='form-control' name='fypeoption[]' >
  ".$fieldshow['1']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD15."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fdirections[]",$value=htmlspecialchars($material['fdirections']),$placeholder=_MS_CUSTOMFIELD15,$id="fdirections".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD16."</div>
  <div class='col-md-3'><select id='fwidthoption".$number."' class='form-control' name='fwidthoption[]' >
  ".$fieldshow['2']."
  </select></div>
</div>
</div>

<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'><button id='newoptions".$number."' name='".$centerid."' type='button' class='btn btn-primary btn-block'>"._MS_CUSTOMFIELD27."</button>	</div>
  <div class='col-md-9'>
    <div id='optionsbox".$number."' class='optionsbox'>
    ".$optionsList."    
    </div>
    
    
    </div>
 </div>
</div>

	
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD18."</div>
  <div class='col-md-4'>".radioinline($class="frequired".$number."",$name="frequired[".$number."]",$text=array(_MS_SHARED04,_MS_SHARED03),$checked=$material['frequired'])."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD20."</div>
  <div class='col-md-3'>
    <button id='delete".$number."' type='button' class='btn btn-danger btn-sm'>"._MS_SHARED09."</button>
    <button id='copy".$number."' type='button' class='btn btn-success btn-sm'>"._MS_CUSTOMFIELD21."</button>
    </div>
</div>
</div>
	
	
</div>
<input type='hidden' name='fnumber[]' value='".$number."'> 
<div style='clear: both;'></div>
</span>";
  break;  
  
    case "6":
//日期時間
$box.="<span id='fcontent".$number."' class='itemssort'><div id='fieldbox".$number."' class='alert alert-yellow-customize fieldbox' role='alert' name='".$number."'>
	
<div class='form-group'>
<div class='row'>
".$handle."	
  <div class='col-md-2'>"._MS_CUSTOMFIELD06."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fieldtitle[]",$value=htmlspecialchars($material['fieldtitle']),$placeholder=_MS_CUSTOMFIELD06,$id="fieldtitle".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD07."</div>
  <div class='col-md-3'><select id='fypeoption".$number."' class='form-control' name='fypeoption[]' >
  ".$fieldshow['1']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD15."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fdirections[]",$value=htmlspecialchars($material['fdirections']),$placeholder=_MS_CUSTOMFIELD15,$id="fdirections".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD16."</div>
  <div class='col-md-3'><select id='fwidthoption".$number."' class='form-control' name='fwidthoption[]' >
  ".$fieldshow['2']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'></div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD28."</div>
  <div class='col-md-4'>".radioinline($class="fsetup".$number."0",$name="fsetup".$number."[0]",$text=array(_MS_SHARED131,_MS_SHARED130),$checked=$material['fsetup']['0'])."</div>
</div>
</div>

	
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD18."</div>
  <div class='col-md-4'>".radioinline($class="frequired".$number."",$name="frequired[".$number."]",$text=array(_MS_SHARED04,_MS_SHARED03),$checked=$material['frequired'])."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD20."</div>
  <div class='col-md-3'>
    <button id='delete".$number."' type='button' class='btn btn-danger btn-sm'>"._MS_SHARED09."</button>
    <button id='copy".$number."' type='button' class='btn btn-success btn-sm'>"._MS_CUSTOMFIELD21."</button>
    </div>
</div>
</div>
	
	
</div>
<input type='hidden' name='fnumber[]' value='".$number."'> 
<div style='clear: both;'></div>      	  		
</span>";
  break;  
  

    case "7":

//預設檔案類型-圖片
//if(empty($material['fieldArr'])) $material['fieldArr']['0']=1;

//選擇檔案類型
$filetypeArr = array(); //建構陣列
$i=0;
$filetypeArr[$i]['id']='1';  
$filetypeArr[$i]['title']=_MS_CUSTOMFIELD29;
$i++;

$filetypeArr[$i]['id']='2';  
$filetypeArr[$i]['title']=_MS_CUSTOMFIELD30;
$i++;


foreach($filetypeArr as $key=> $val){
//比對陣列	
if(!empty($material['fieldArr']) && in_array($filetypeArr[$key]['id'], $material['fieldArr'])){
 $goid[$key]=$filetypeArr[$key]['id'];	
	}else{
 $goid[$key]=0;		
	}
$fieldshow['3'].="<div class='col-sm-6 col-xs-6'>".checkbox($dataid=$filetypeArr[$key]['id'],$name="fieldArr".$number."[]",$value=$filetypeArr[$key]['id'],$optionname="".$filetypeArr[$key]['title']."",$oid="".$goid[$key]."")."</div>";
}
    	
//檔案數量    	
foreach(array('1','5','10') as $key=> $val){
$fieldshow['4'].=optionselect($dataid=$val,$optionname=$val,$oid="".$material['fsetup']['0']."",$value=$val);
}	
    	
    	
    	
    	
//檔案上傳
$box.="<span id='fcontent".$number."' class='itemssort'><div id='fieldbox".$number."' class='alert alert-purple-customize fieldbox' role='alert' name='".$number."'>
	
<div class='form-group'>
<div class='row'>
".$handle."	
  <div class='col-md-2'>"._MS_CUSTOMFIELD06."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fieldtitle[]",$value=htmlspecialchars($material['fieldtitle']),$placeholder=_MS_CUSTOMFIELD06,$id="fieldtitle".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD07."</div>
  <div class='col-md-3'><select id='fypeoption".$number."' class='form-control' name='fypeoption[]' >
  ".$fieldshow['1']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD15."</div>
  <div class='col-md-4'>".inputtext($class="",$name="fdirections[]",$value=htmlspecialchars($material['fdirections']),$placeholder=_MS_CUSTOMFIELD15,$id="fdirections".$number."")."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD16."</div>
  <div class='col-md-3'><select id='fwidthoption".$number."' class='form-control' name='fwidthoption[]' >
  ".$fieldshow['2']."
  </select></div>
</div>
</div>
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'></div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD31."</div>
  <div class='col-md-4'>
  <div id='filecheckbox".$number."' class='filetypecheckbox row'>
   ".$fieldshow['3']."
    </div>
    </div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD32."</div>
  <div class='col-md-3'><select   class='form-control fsetup".$number."0' name='fsetup".$number."[0]' >
  ".$fieldshow['4']."
  </select>
  	  </div>   
</div>
</div>

	
	
<div class='form-group'>
<div class='row'>
  <div class='col-md-1'>
    </div>	
  <div class='col-md-2'>"._MS_CUSTOMFIELD18."</div>
  <div class='col-md-4'>".radioinline($class="frequired".$number."",$name="frequired[".$number."]",$text=array(_MS_SHARED04,_MS_SHARED03),$checked=$material['frequired'])."</div>
  <div class='col-md-2'>"._MS_CUSTOMFIELD20."</div>
  <div class='col-md-3'>
    <button id='delete".$number."' type='button' class='btn btn-danger btn-sm'>"._MS_SHARED09."</button>
    <button id='copy".$number."' type='button' class='btn btn-success btn-sm'>"._MS_CUSTOMFIELD21."</button>
    </div>
</div>
</div>
	
	
</div>
<input type='hidden' name='fnumber[]' value='".$number."'> 
<div style='clear: both;'></div>      	  		
</span>";
  break;  

}

if(empty($change)){	
$box.="
<script id='deletescript".$number."'>

neillibrary_customfield(id='".$ajaxid."',modulesid='".$moduleid."',btn='#newoptions".$number."',eachid='.optionseach".$number."',foundid='#optionsbox".$number."',types='1',oldnumber='".$number."',fromtype='".$fromtype."');			


$('body').on('click', '#copy".$number."', function() {
    var number = neillibrary_latestnumber(eachid = '.fieldbox', foundid = '#fieldcontent');
    
    var material = {};
    material['fieldtitle'] = $('#fieldtitle".$number."').val(); //欄位名稱
    material['fdirections'] = $('#fdirections".$number."').val(); //欄位說明
    material['fwidthoption'] = $('#fwidthoption".$number."').find(':selected').attr('data-id'); //欄位寬度
    material['frequired'] = $('.frequired".$number.":checked').val(); //是否必填
    	
    var fsetup = {};
    fsetup['0'] = $('.fsetup".$number."0:checked').val(); //設定0
    fsetup['1'] = $('.fsetup".$number."1').val(); //設定1    	
    material['fsetup'] = fsetup; //設定Arr
    	
    if ($('#fypeoption".$number."').find(':selected').attr('data-id') != '7') {
        var fieldArr = {};
        $('#optionsbox".$number." #fieldArreach".$number."').each(function(index) {
            fieldArr[index] = $(this).val();
        });
        var optionsname = {};
        $('#optionsbox".$number." #optionsnameeach".$number."').each(function(index) {
            optionsname[index] = $(this).val();
        });
    } else {
        var fieldArr = {};
        $('#filecheckbox".$number." input:checkbox[id=checkbox]:checked').each(function(index) {
            fieldArr[index] = $(this).val();
        });
        fsetup['0'] = $('.fsetup".$number."0').find(':selected').attr('data-id'); //設定0
    }
    material['fieldArr'] = fieldArr;
    material['optionsname'] = optionsname;
    $.ajax({
        url: '".XOOPS_URL."/modules/".$moduleid."/ajax.php',
        type: 'POST',
        data: {
            id: '".$ajaxid."',
            fieldtype: $('#fypeoption".$number."').find(':selected').attr('data-id'),
            va1: ".$centerid.",
            material: material,
            number: Number(number) + 1,
            fromtype: ".$fromtype.",           	
            copyval: 1
        },
        success: function(response) {
            $('#fieldcontent').attr('count', (Number(number) + 1));
            $('#fieldcontent').prepend(response);
            SmoothScrollTo('#fieldcontent', 500);
        },
        error: function() {
            console.log('ajax error!');
        }
    })
})


$('body').on('change', '#fypeoption".$number."', function() {
	
    var material = {};
    material['fieldtitle'] = $('#fieldtitle".$number."').val();
    material['fdirections'] = $('#fdirections".$number."').val();
    material['fwidthoption'] = $('#fwidthoption".$number."').find(':selected').attr('data-id');    
    
    var fieldArr = {};
       $('#optionsbox".$number." #fieldArreach".$number."').each(function(index) {
        fieldArr[index] = $(this).val();
    });    
    var optionsname = {};
    $('#optionsbox".$number." #optionsnameeach".$number."').each(function(index) {
        optionsname[index] = $(this).val();
    });
    material['fieldArr'] = fieldArr;
    material['optionsname'] = optionsname;
    material['frequired'] = $('.frequired".$number.":checked').val();
    
    $.ajax({
        url: '".XOOPS_URL."/modules/".$moduleid."/ajax.php',
        type: 'POST',
        data: {
            id: '".$ajaxid."',
            fieldtype: $(this).find(':selected').attr('data-id'),
            material: material,
            va1: ".$centerid.",
            number: ".$number.",
            fromtype: ".$fromtype.",                	
            change: 1
        },
        success: function(response) {
            $('#fcontent".$number."').html(response);
        },
        error: function() {
            console.log('ajax error!');
        }
    })
})
$('body').on('click', '#delete".$number."', function() {
    $('#fcontent".$number."').remove();
    $('#deletescript".$number."').remove();
    swal('"._MS_SHARED214."', 'Data deleted Update after saving');
})
	
</script>";
}




return $box;
}
	

?>