<?php
include_once XOOPS_ROOT_PATH."/modules/neillibrary/function.php";
function xoops_module_update_neillibrary(&$module, $old_version) {
    GLOBAL $xoopsDB;
    
 //建立neillibrary資料夾
fileadminfunction($fileurl="",$type="4",$fileex="",$from=XOOPS_ROOT_PATH . "/uploads/neillibrary",$fileurlnew="",$exclude="");
fileadminfunction($fileurl="",$type="4",$fileex="",$from=XOOPS_ROOT_PATH . "/uploads/neillibrary/qrcode",$fileurlnew="",$exclude="");   
    
	go_update1();
    go_update2();	
    go_update3();
    go_update4();
    go_update5(); 
    go_update6(); 
    go_update7();    
    go_update8();      
    go_update9();     
    go_update10();     
    go_update11();    
    go_update12();  
   // go_update13();         
    return true;
}


//模組加入防護模組網路爬蟲例外
function go_update1(){
 global $xoopsDB;
protectorexception($modulesid="neillibrary");
}

//增加紀錄機器人IP表單
function go_update2(){
	
  global $xoopsDB;
  $sql="select count(*) from ".$xoopsDB->prefix("robotip");
  $result=$xoopsDB->query($sql);
  if(empty($result)){

  $sql="CREATE TABLE `".$xoopsDB->prefix("robotip")."` (
  `rip` bigint(255) unsigned NOT NULL AUTO_INCREMENT,
  `ip` varchar(255) NOT NULL default '', /*IP位置*/    
  `robottime`  date NOT NULL, /*審核日期*/   
  `riptime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,  /*紀錄日期*/   
  `enable` enum('1','0') NOT NULL default '0', /*是否封鎖*/  
  PRIMARY KEY (`rip`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;";
  $xoopsDB->queryF($sql);
  
  
  }
}	


//增加紀錄機器人IP表單
function go_update3(){
	
  global $xoopsDB;
  $sql="select  count(`url`) from ".$xoopsDB->prefix("robotip");
  $result=$xoopsDB->query($sql);
  if(empty($result)){

     $sql="ALTER TABLE ".$xoopsDB->prefix("robotip")." 
	ADD  `url` varchar(255)  NOT NULL default ''  AFTER `enable`	";	
     $xoopsDB->queryF($sql);   
  
  }
}




//增加模組自訂選單資料表
function go_update4(){
	
  global $xoopsDB;
  $sql="select count(*) from ".$xoopsDB->prefix("neillibrary_modulesmenu");
  $result=$xoopsDB->query($sql);
  if(empty($result)){

  $sql="CREATE TABLE `".$xoopsDB->prefix("neillibrary_modulesmenu")."` (
  `menuid` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT,
  `modulesid` varchar(255) NOT NULL default '', 
  `menutype` enum('1','0') NOT NULL default '0',  
  `pageid` bigint(255) unsigned NOT NULL default '0', 
  `btntitle` varchar(255) NOT NULL default '', 
  `url` text NOT NULL, 
  `btnsort` bigint(255) UNSIGNED NOT NULL default 0, 
  `target` enum('1','0') NOT NULL default '0',  
  `enable` enum('1','0') NOT NULL default '1',
   PRIMARY KEY (`menuid`)
) ENGINE=MyISAM;";  
  $xoopsDB->queryF($sql);  
  
  }
}	

//增加neilayoutcsslog資料表
function go_update5(){	
  global $xoopsDB;
  $sql="select count(*) from ".$xoopsDB->prefix("neillibrary_layoutcsslog");
  $result=$xoopsDB->query($sql);
  if(empty($result)){

   //建立neilayoutcsslog資料表
  $sql="CREATE TABLE `".$xoopsDB->prefix("neillibrary_layoutcsslog")."` (
  `logid` bigint(255) unsigned NOT NULL AUTO_INCREMENT,
  `ip` varchar(255) NOT NULL default '', /*IP位置*/    
  `layoutcss` varchar(255)  NOT NULL default '', /*layoutcss*/     
  `logtime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,  /*紀錄日期*/   
  PRIMARY KEY (`logid`)
) ENGINE=MyISAM;";
  $xoopsDB->queryF($sql);  
  
  
  }

}


//增加neillibrary_citydate資料表
function go_update6(){	
	
global $xoopsDB,$xoopsConfig;  
include_once XOOPS_ROOT_PATH."/modules/neillibrary/include/{$xoopsConfig['language']}_onInstall.php";	


  $sql="select count(*) from ".$xoopsDB->prefix("neillibrary_citydate");
  $result=$xoopsDB->query($sql);
  if(empty($result)){
   //建立neillibrary_citydate資料表
  $sql="CREATE TABLE `".$xoopsDB->prefix("neillibrary_citydate")."` (
  `cityid` mediumint(8) UNSIGNED NOT NULL AUTO_INCREMENT,
  `of_cityid` mediumint(8) unsigned NOT NULL default 0,   
  `country` smallint(5) UNSIGNED NOT NULL default 0, 
  `citytitle` varchar(255) NOT NULL default '',
  `enable` enum('1','0') NOT NULL default '1', 
  `sortidsort` mediumint(8) UNSIGNED NOT NULL default 0, 
   PRIMARY KEY (`cityid`),KEY sortidsort (sortidsort)
) ENGINE=MyISAM;";
  $xoopsDB->queryF($sql);    
  
  } 
  
  
if(function_exists('city_DBfunction')){  
city_DBfunction(); //建立城市管理資料
}

}





//增加紀錄機器人錯誤次數
function go_update7(){	
  global $xoopsDB;
  $sql="select  count(`counter`) from ".$xoopsDB->prefix("robotip");
  $result=$xoopsDB->query($sql);
  if(empty($result)){
    $sql="ALTER TABLE ".$xoopsDB->prefix("robotip")." 
	ADD  `counter` smallint(255) unsigned NOT NULL default 0  AFTER `url`";	
    $xoopsDB->queryF($sql);     
  }
}





//增加neillibrary_class資料表
function go_update8(){		
global $xoopsDB;  

  $sql="select count(*) from ".$xoopsDB->prefix("neillibrary_class");
  $result=$xoopsDB->query($sql);
  if(empty($result)){
   //建立neillibrary_citydate資料表
  $sql="CREATE TABLE `".$xoopsDB->prefix("neillibrary_class")."` (
  `classid` mediumint(8) UNSIGNED NOT NULL AUTO_INCREMENT, 
  `of_classid` mediumint(8) unsigned NOT NULL default 0, /*父分類id*/  
  `classtitle` varchar(255) NOT NULL default '', /*班級名稱*/  
  `sortidsort` mediumint(8) UNSIGNED NOT NULL default 0, /*排序*/     
  `enable` enum('1','0') NOT NULL default '1', /*是否啟用*/   
   PRIMARY KEY (`classid`)
) ENGINE=MyISAM;";
  $xoopsDB->queryF($sql);   
  } 

}

//增加neillibrary_dateitem資料表
function go_update9(){		
global $xoopsDB;  
  $sql="select count(*) from ".$xoopsDB->prefix("neillibrary_dateitem");
  $result=$xoopsDB->query($sql);
  if(empty($result)){
   //建立neillibrary_citydate資料表
  $sql="CREATE TABLE `".$xoopsDB->prefix("neillibrary_dateitem")."` (
  `itemid` mediumint(8) UNSIGNED NOT NULL AUTO_INCREMENT,
  `itemtext` varchar(255) NOT NULL default '', /*項目名稱*/
  `modulesid` varchar(255) NOT NULL default '', /*模組ID*/       
  `btnsort` smallint(5) UNSIGNED NOT NULL default 0, /*排序*/   
  `enable` enum('1','0') NOT NULL default '1', /*是否啟用*/  
   PRIMARY KEY (`itemid`)
) ENGINE=MyISAM;";
  $xoopsDB->queryF($sql);   
  } 
}



//增加cookieid欄位
function go_update10(){	
  global $xoopsDB;
  $sql="select  count(`cookieid`) from ".$xoopsDB->prefix("robotip");
  $result=$xoopsDB->query($sql);
  if(empty($result)){
    $sql="ALTER TABLE ".$xoopsDB->prefix("robotip")." 
	ADD  `cookieid` varchar(255) NOT NULL default ''  AFTER `counter`";	
    $xoopsDB->queryF($sql);     
  }
  
  $sql="select  count(`cookieid`) from ".$xoopsDB->prefix("neillibrary_layoutcsslog");
  $result=$xoopsDB->query($sql);
  if(empty($result)){
    $sql="ALTER TABLE ".$xoopsDB->prefix("neillibrary_layoutcsslog")." 
	ADD  `cookieid` varchar(255) NOT NULL default ''  AFTER `logtime`";	
    $xoopsDB->queryF($sql);     
  }  
}

//增加紀錄機器人觸發類型
function go_update11(){	
  global $xoopsDB;
  $sql="select  count(`operate`) from ".$xoopsDB->prefix("robotip");
  $result=$xoopsDB->query($sql);
  if(empty($result)){
    $sql="ALTER TABLE ".$xoopsDB->prefix("robotip")." 
	ADD  `operate` int(255) unsigned NOT NULL default 0  AFTER `cookieid`, 
	ADD  `uid` mediumint(8) unsigned NOT NULL default 0  AFTER `operate`";	
    $xoopsDB->queryF($sql);     
  }
  
}

//更改欄位類型
function go_update12(){	
  global $xoopsDB;
	$sql="ALTER TABLE ".$xoopsDB->prefix("neillibrary_layoutcsslog")." 
	CHANGE `logid` `logid` bigint(255) unsigned NOT NULL AUTO_INCREMENT";
	$xoopsDB->queryF($sql);	
	$sql="ALTER TABLE ".$xoopsDB->prefix("neillibrary_modulesmenu")." 
	CHANGE `menuid` `menuid` bigint(255) UNSIGNED NOT NULL AUTO_INCREMENT";
	$xoopsDB->queryF($sql);	
}


//增加商品展示區塊ID
/*function go_update13(){	
  global $xoopsDB;
  $sql="select  count(`product_block`) from ".$xoopsDB->prefix("neillibrary_layoutcsslog");
  $result=$xoopsDB->query($sql);
  if(empty($result)){
    $sql="ALTER TABLE ".$xoopsDB->prefix("neillibrary_layoutcsslog")." 
	ADD  `product_block` text NOT NULL  AFTER `mod_dir`";	
    $xoopsDB->queryF($sql);     
  }
}
*/

?>