<?php

/*========佈景引入JS設定==============*/
function neillibrary_introducesettings($themesvar="",$xoops_dirname=""){

//排除引入JS設定-區塊
$bidArr=bidnamefunction($op="",$bid="",$type="3",$var=" `visible` = '1' && `isactive` = '1' &&  `dirname` = 'tad_cal'   ",$id="dirname",$selectkey="DISTINCT dirname");
//取消預設引入
if($xoops_dirname!='tad_cal' &&  (empty($xoops_dirname=='system')  ||   empty($bidArr))){ 
$themesvar['jqueryjs']['0']='<script src="'.XOOPS_URL.'/browse.php?Frameworks/jquery/jquery.js" type="text/javascript"></script>';
$themesvar['jqueryjs']['1']='<script src="'.XOOPS_URL.'/modules/tadtools/jquery/jquery-migrate-3.0.0.min.js" type="text/javascript"></script>';
$themesvar['jqueryjs']['2']='<script src="'.XOOPS_URL.'/browse.php?Frameworks/jquery/plugins/jquery.ui.js" type="text/javascript"></script>';
}
$themesvar['sweetalert']='<script src="'.XOOPS_URL.'/modules/tadtools/sweet-alert/sweet-alert.js" type="text/javascript"></script>';  
$themesvar['bootstrapcss']['0']='<link rel="stylesheet" href="'.XOOPS_URL.'/modules/tadtools/bootstrap3/css/bootstrap.css" type="text/css" />'; 
$themesvar['bootstrapcss']['1']='<link rel="stylesheet" href="'.XOOPS_URL.'/modules/tadtools/bootstrap/css/bootstrap.css" type="text/css" />'; 
$themesvar['bootstrapcss']['2']='<script src="'.XOOPS_URL.'/modules/tadtools/fancyBox/source/jquery.fancybox.js" type="text/javascript"></script>'; 



//預設引入module_header
//jquery->jquery-3.6.0.min.js
//jquery-ui->jquery-ui-1.12.1
//jquery-migrate->jquery-migrate-3.3.2.min.js

if($xoops_dirname!='tad_cal' &&  (empty($xoops_dirname=='system')  ||   empty($bidArr))){ 
$themesvar['module_header'].="
<script src='".XOOPS_URL."/modules/neillibrary/js/tpl-jquery/jquery.js' type='text/javascript'></script>
<script src='".XOOPS_URL."/modules/neillibrary/js/tpl-jquery/jquery-ui/jquery-ui.js' type='text/javascript'></script>
<script src='".XOOPS_URL."/modules/neillibrary/js/tpl-jquery/jquery-migrate.js' type='text/javascript'></script>";}
//define("_MS_SHARED246","請填寫正確的時間格式"); 

$jsonArr=array(
	'required' => _MS_SHARED22,      //必填欄位
	'phonetext' => _MS_SHARED238,    //請填寫正確的手機格式
	'mailtext' => _MS_SHARED237,     //請填寫正確的E-MAIL格式
	'timetext' => _MS_SHARED246,     //請填寫正確的時間格式
	'urltext' =>  _MS_SHARED261      //請填寫正確的時間格式
	);
		
$themesvar['module_header'].="
<script>var jstext='".json_encode($jsonArr)."';</script>";//JS中語言-全體

return $themesvar;
}

/*==========判斷profile模組是否有啟用============*/
function neillibrary_profiletype(){
//判斷profile模組是否有啟用
if(!empty(modulesmidvar($modulesid="profile",$val="isactive"))){
$url="modules/profile/register.php";  //啟用
}else{
$url="register.php";         //未啟用
}

return $url;
}

/*==========判斷布景選單模組是否有啟用============*/
function neillibrary_themesmodulesmenutype($modulesid){
//判斷按鈕模組是否有啟用
if(!empty(modulesmidvar($modulesid,$val="isactive"))){
$url[$modulesid]="modules/".$modulesid."/";  //啟用
}

return $url;
}




/*====布景布局設定================*/
function neillibrary_layoutcsstype($xoops_dirname="",$httphosturl="",$iframe=""){
global  $xoopsTpl,$xoopsModule,$xoopsConfig;
new XoopsTpl(); //宣告

//判斷User Agent 
$userAgent="facebook";
if(preg_match("/".$userAgent."/i", "".$_SERVER['HTTP_USER_AGENT']."")) {
  $tplvar['noleadinto']=true;
} 

$configvar=configvar($modulesid="neothemesadmin");
//判斷更新通知天數
$maturitytime=timedate($datevar="".timedate($datevar="Y-m-d H:i:s")."",$type="2",$calculate="-",$m="",$d=$configvar['neothemesadmin2'],$y="");
if($configvar['neothemesadmin1'] < $maturitytime){
update($dbname="neothemesconfig",$set="set enable='0' where nsn='1'");
update($dbname="config",$set="set conf_value='".timedate($datevar="Y-m-d H:i:s")."'  where conf_name='neothemesadmin1'");    
}


//引入模組DB函數-初始化設定
$configList=moduledb($dbneme="neothemesconfig",$where=" where `nsn` = '1'");
$fieldsplit=phpconversion($conversion=$configList['field'],$type="unserialize"); //字串轉陣列
//是否啟用LOGO動畫
$tplvar['animation']=$fieldsplit[11];
//是否啟用首頁視差
$tplvar['parallax']=$fieldsplit[12];
//版型配置
$tplvar['layout']=$fieldsplit[13];
//右浮動選單
$tplvar['rmenufloat']=$fieldsplit[14];

//判斷布景選單模組是否有啟用(網站導覽/流量統計)
$tplvar['menutype1']=neillibrary_themesmodulesmenutype($modulesid=$fieldsplit[17]);

//判斷布景選單模組是否有啟用(網站導覽/流量統計)
$tplvar['menutype2']=neillibrary_themesmodulesmenutype($modulesid=$fieldsplit[18]);

//頁腳輔助說明
$tplvar['foottext']=$fieldsplit[22];


$op=isset($_REQUEST['op'])?$_REQUEST['op']:"";



//底區塊判斷
//底左中右開啟
if(!empty($xoopsTpl->tpl_vars['xoBlocks']->value['footer_left']) and !empty($xoopsTpl->tpl_vars['xoBlocks']->value['footer_center']) and !empty($xoopsTpl->tpl_vars['xoBlocks']->value['footer_right'])) {
$tplvar['footerstyle']="1";
}elseif(!empty($xoopsTpl->tpl_vars['xoBlocks']->value['footer_left']) and !empty($xoopsTpl->tpl_vars['xoBlocks']->value['footer_center'])){ //底左中開啟
$tplvar['footerstyle']="2";
}elseif(!empty($xoopsTpl->tpl_vars['xoBlocks']->value['footer_right']) and !empty($xoopsTpl->tpl_vars['xoBlocks']->value['footer_center'])){ //底中右開啟
$tplvar['footerstyle']="3";
}elseif(!empty($xoopsTpl->tpl_vars['xoBlocks']->value['footer_left'])  and !empty($xoopsTpl->tpl_vars['xoBlocks']->value['footer_right'])){ //底左右開啟
$tplvar['footerstyle']="5";
}elseif(!empty($xoopsTpl->tpl_vars['xoBlocks']->value['footer_left']) or !empty($xoopsTpl->tpl_vars['xoBlocks']->value['footer_center']) or !empty($xoopsTpl->tpl_vars['xoBlocks']->value['footer_right'])){ //底中右只開一區塊
$tplvar['footerstyle']="4";
}

//克隆區塊
$canvas_right=$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_right'];
$canvas_left=$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_left'];


//底區塊-左
$tplvar['b_canvas_left']=$canvas_left;
//右上4區塊
if($tplvar['layout']=='4'){
//取得陣列總數
$rightcount = is_array($canvas_right) ? count($canvas_right) : 0 ;
//底區塊-上
$tplvar['b_canvas_right_top']=array_slice($canvas_right, 0, 4);
//底區塊-下
$tplvar['b_canvas_right_bottom']=array_slice($canvas_right, 4, $rightcount);
//底區塊-右
$tplvar['b_canvas_right']=$tplvar['b_canvas_right_bottom'];
}else if(!empty(check_mobile())  &&  $tplvar['layout']=='2'){ //中右布局(手機版)
$tplvar['b_canvas_right']=true;	
$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_left']=$canvas_right;
$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_right']=$canvas_left;
}else{
//底區塊-右
$tplvar['b_canvas_right']=$canvas_right;
}




if($tplvar['layout']!='3'){
//強制關閉右區塊
$modulesid=array("tad_assignment","tad_lunch2","tad_repair","tad_web","tad_meeting","neilfilefolder","neilmfdcms","kw_club","neilsignedup_c","neilsignedup_a","neilperiodical","tad_repair","neilenglishresults","neilproduct","neilhonorlist","neilcurriculum"); //模組ID
foreach($modulesid as $val){	
if($xoops_dirname==$val){
$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_right']=false;
}
}

$pageop=array("custommenu","form","added"); //頁面OP	
foreach($pageop as $val){	
if($op==$val){
$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_right']=false;
}
}	



//強制關閉左區塊
$modulesid=array("neilfilefolder","neilmfdcms","kw_club","neilsignedup_c","neilsignedup_a","neilperiodical","tad_repair","neilenglishresults","neilproduct","neilhonorlist","neilcurriculum"); //模組ID
foreach($modulesid as $val){	
if($xoops_dirname==$val){
$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_left']=false;
}
}


$pageop=array("custommenu","form","added"); //頁面OP	
foreach($pageop as $val){	
if($op==$val){
$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_left']=false;
}
}
}


//頁面ID-關閉左右區塊	
foreach($pageid=array("officeid","centerid") as $val){
if(isset($_GET[$val])){
$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_left']=false;
$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_right']=false;
}
}



//瀏覽裝置判斷
if(!check_mobile()){  //電腦版執行

//布景布局判斷
if($tplvar['layout']=='1' && (!empty($xoopsTpl->tpl_vars['xoBlocks']->value['canvas_left']) ||  !empty($xoopsTpl->tpl_vars['xoBlocks']->value['canvas_right'])) ){ //左中配置
$tplvar['layoutcss']="ldivtrue";
}elseif($tplvar['layout']=='2' && (!empty($xoopsTpl->tpl_vars['xoBlocks']->value['canvas_left']) ||  !empty($xoopsTpl->tpl_vars['xoBlocks']->value['canvas_right']))){ //中右配置
$tplvar['layoutcss']="rdivtrue";
}else{
$tplvar['layoutcss']="rdivfalse";
}

}else{ //手機版執行

//布景布局判斷
if($tplvar['layout']=='2' && (!empty($xoopsTpl->tpl_vars['xoBlocks']->value['canvas_left']) ||  !empty($xoopsTpl->tpl_vars['xoBlocks']->value['canvas_right']))){ //中右配置
$canvas_right=$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_right'];
$canvas_left=$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_left'];
$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_left']=$canvas_right;
$xoopsTpl->tpl_vars['xoBlocks']->value['canvas_right']=$canvas_left;
} 
}



//判斷cookieid欄位式否有建立
if(empty($tplvar['noleadinto'])){
//增加zoomsize欄位
  global $xoopsDB;
  $sql="select  count(`zoomsize`) from ".$xoopsDB->prefix("neillibrary_layoutcsslog");
  $result=$xoopsDB->query($sql);
  if(empty($result)){
    $sql="ALTER TABLE ".$xoopsDB->prefix("neillibrary_layoutcsslog")." 
	ADD  `zoomsize` varchar(255) NOT NULL default ''  AFTER `cookieid`";	
    $xoopsDB->queryF($sql);     
  }	
//增加mod_dir欄位
  $sql="select  count(`mod_dir`) from ".$xoopsDB->prefix("neillibrary_layoutcsslog");
  $result=$xoopsDB->query($sql);
  if(empty($result)){
    $sql="ALTER TABLE ".$xoopsDB->prefix("neillibrary_layoutcsslog")." 
	ADD  `mod_dir` varchar(255) NOT NULL default ''  AFTER `zoomsize`";	
    $xoopsDB->queryF($sql);     
  }	
  

//開啟neillibrary_layoutcsslog	
$logList=moduledb($dbneme="neillibrary_layoutcsslog",$where=" where `ip` = '".get_real_ip()."' && `cookieid` = '".$_COOKIE['neil']['cookieid']."'  order by  logid DESC");	
$tplvar['logList']=$logList;
if(!empty($xoopsDB->query($sql="select  count(`cookieid`) from ".$xoopsDB->prefix("neillibrary_layoutcsslog")))){		
if(empty($logList) && !empty($_COOKIE['neil']['cookieid'])){
$valuesvar="(ip,layoutcss,cookieid,zoomsize,mod_dir,product_block) values('".get_real_ip()."','".$tplvar['layoutcss']."','".$_COOKIE['neil']['cookieid']."','','','')";	  
insert($dbname="neillibrary_layoutcsslog",$values=$valuesvar);
if(!empty($xoopsModule) && !check_mobile()){
header("refresh:0;URL={$httphosturl['url']}");
exit;
}
}
if(!empty($logList) && empty($iframe) && $logList['layoutcss']!=$tplvar['layoutcss']){	
$setvar="set layoutcss='".$tplvar['layoutcss']."' ,logtime='".timedate($datevar="Y-m-d H:i:s")."'  where logid='".$logList['logid']."'";
update($dbname="neillibrary_layoutcsslog",$set=$setvar);
if(!check_mobile()){
header("refresh:0;URL={$httphosturl['url']}");
exit;
}
}
}
}  


//GTM代碼
if(!empty($configvar['neothemesadmin4'])) $tplvar['gtm']=phpconversion($conversion=base64_decode($configvar['neothemesadmin3']),$type="unserialize"); 

$tplvar['sitename']=$xoopsConfig['sitename'];


return array($tplvar,$fieldsplit,$configList,$op); 
}




?>