<?PHP
/* JAG Online -------------------------- 06/03/2004 ------------------ v1.31 [6.5~7.1] */
/*                                                                                     */
/*      ////////// //\\ \\\\\\\\\\       Created by Dashe at http://nsd.jagamarog.com  */
/*             // //  \\ \\                                                            */
/*            // //    \\ \\             Email Address:           dashe@jagamarog.com  */
/*           // /////\\\\\ \\   \\\\\                                                  */
/*          // //        \\ \\      \\                                                 */
/*         // //          \\ \\\\\\\\\\                                                */
/* /////////  a g a m a r o g . c o m   N u k e   S c r i p t   D e v e l o p m e n t  */
/*                                                                                     */     
/* Created By Dashe -> http://nsd.jagamarog.com                                        */ 
/*                                                                                     */
/* ----------------------------------------------------------------------------------- */

/* DO NOT EDIT BELOW UNLESS YOU KNOW WHAT YOU ARE DOING ------------------------------ */

/* Check For Admin Status ------------------------------------------------------------ */
CheckAdmin();

/* Stage 3 --------------------------------------------------------------------------- */
	echo "	<TR>\n";
	echo "		<TD CLASS='catLeft' COLSPAN='2' HEIGHT='28'>\n";
	echo "			<SPAN CLASS='cattitle'>Step 3: Creating Tables And Inserting Data</SPAN></TD>\n";
	echo "  </TR>\n";

/* Table 1 --------------------------------------------------------------------------- */
$QI0 = "DROP TABLE IF EXISTS $checktable1";
$RI0 = $db -> sql_query($QI0);
	
$QI1 = "CREATE TABLE $checktable1
			(
			  `jag_online_user_id` int(11) NOT NULL default '0',
			  `jag_online_username` varchar(25) NOT NULL default '',
			  `jag_online_user_from` varchar(100) NOT NULL default '',
			  `jag_online_time` varchar(14) NOT NULL default '',
			  `jag_online_ip` varchar(20) NOT NULL default '',
			  `jag_online_guest` int(1) NOT NULL default '0',
			  `jag_online_module` varchar(100) NOT NULL default '',
			  `jag_online_url` varchar(255) NOT NULL default ''
			) TYPE=MyISAM";
$RI1 = $db -> sql_query($QI1);
	
	echo "	<TR> \n";
	echo "		<TD CLASS='row1' ALIGN='LEFT' VALIGN='MIDDLE' COLSPAN='1'>\n";
	echo "			<FONT><NOBR>Creating table $checktable1</NOBR></FONT></TD>\n";
	echo "		<TD CLASS='row2' HEIGHT='20' ALIGN='LEFT' VALIGN='TOP'>\n";
	
if (table_exists($checktable1, $dbname)) 
	{
	echo "			<FONT STYLE='COLOR:$Green;'>Table Created</FONT></TD>\n";
	}
else
	{
	echo "			<FONT STYLE='COLOR:$Red;'>Unable To Create</FONT></TD>\n";
	$NotAllTables = 1;
	}
		
	echo "	</TR>\n";
	echo "	<TR> \n";
	echo "		<TD CLASS='row1' ALIGN='LEFT' VALIGN='TOP' COLSPAN='1'>\n";
	echo "			<NOBR>Inserting data into table $checktable1<BR>[No Data To Insert]</NOBR></TD>\n";
	echo "		<TD CLASS='row2' ALIGN='RIGHT' VALIGN='TOP' HEIGHT='20'>\n";
	echo "			<FONT STYLE='COLOR:$Green;'>0 Lines Verified</FONT></TD>\n";
	echo "	</TR>\n";
	
BlankRow();

/* Table 2 --------------------------------------------------------------------------- */
$QI2 = "DROP TABLE IF EXISTS $checktable2";
$RI2 = $db -> sql_query($QI2);
			
$QI3 = "CREATE TABLE $checktable2 
			(
			  `bot_id` int(5) unsigned zerofill NOT NULL auto_increment,
			  `bot_ip` varchar(15) NOT NULL default '',
			  `bot_name` varchar(50) NOT NULL default '',
			  PRIMARY KEY  (`bot_id`)
			) TYPE=MyISAM";
$RI3 = $db -> sql_query($QI3);
	
	echo "	<TR> \n";
	echo "		<TD CLASS='row1' ALIGN='LEFT' VALIGN='MIDDLE' COLSPAN='1'>\n";
	echo "			<FONT><NOBR>Creating table $checktable2</NOBR></FONT></TD>\n";
	echo "		<TD CLASS='row2' HEIGHT='20' ALIGN='LEFT' VALIGN='TOP'>\n";

if (table_exists($checktable2, $dbname)) 
	{
	echo "			<FONT STYLE='COLOR:$Green;'>Table Created</FONT></TD>\n";
	}
else
	{
	echo "			<FONT STYLE='COLOR:$Red;'><NOBR><B>Unable To Create Table</B></NOBR></FONT></TD>\n";
	$NotAllTables = 1;
	}
		
	echo "	</TR>\n";	

$BotCount  = 0;
$BotFiles  = "AltaVista,AskJeeves,Fast,Google,Inktomi,Lycos,Misc,NonEngine,WiseNut";
$BotData   = explode(",", $BotFiles);
$PrevTotal = 0;

while($BotCount < 9)
	{	
	$i = 0;	
	$csv_filename = "JAG_Online_Install/JAG_Online_Step_3_".$BotData[$BotCount].".csv";
	
	$fp = fopen($csv_filename, 'r');
	while(!feof($fp))
		{
		$row 	= fgets($fp, 4096);
		$data 	= explode(",", $row);
	
		$bot_ip   = $data[0];
		$bot_name = $data[1];
	
		$db -> sql_query("INSERT INTO $checktable2 VALUES('', '$bot_ip', '$bot_name')");
		$i++;
		}
	
	fclose( $fp );

	echo "	<TR> \n";
	echo "		<TD CLASS='row1' ALIGN='LEFT' VALIGN='TOP' COLSPAN='1'>\n";
	echo "			<NOBR>Inserting ".$BotData[$BotCount]." Spider data into $checktable2<BR>[Number of Lines: ".number_format($i)."]</NOBR></TD>\n";
	echo "		<TD CLASS='row2' ALIGN='RIGHT' VALIGN='TOP' HEIGHT='20'>\n";

	$QI8 = "SELECT * FROM $checktable2";
	$RI8 = $db -> sql_query($QI8);
	$NI8 = sql_num_rows($RI8);
	$TotalInserted = $NI8 - $PrevTotal;
	
	if ($TotalInserted == $i)
		{
		echo "			<FONT STYLE='COLOR:$Green;'>".number_format($TotalInserted)." Lines Verified</FONT></TD>\n";
		}
	else
		{
		echo "			<FONT STYLE='COLOR:$Red;'><B><NOBR>Data Missing<BR>".number_format($TotalInserted)." Lines Inserted</NOBR></B></FONT></TD>\n";
		$NotAllData = 1;
		}		
		
	echo "	</TR>\n";
	
	$PrevTotal = $NI8;
	$BotCount++;
	}
	
if ($NotAllData == 1)
	{	
	$ErrorMsg = "It appears that not all the data was inserted into the appropriate tables, the $BlockName block will not work correctly unless all the data is inserted into the tables on your database. Please use the SQL file to insert the data into the tables via phpMyAdmin (or similar). The file is located in sql/jag_online.sql";
	EndNow($ErrorMsg);
	}
		
BlankRow();

/* Table 3 --------------------------------------------------------------------------- */
$QI4 = "DROP TABLE IF EXISTS $checktable3";
$RI4 = $db -> sql_query($QI4);
				
$QI5 = "CREATE TABLE $checktable3 
			(
			  `Block1` varchar(20) NOT NULL default '',
			  `Block1Show` varchar(20) NOT NULL default '',
			  `Block2` varchar(20) NOT NULL default '',
			  `Block2Show` varchar(20) NOT NULL default '',
			  `Block3` varchar(20) NOT NULL default '',
			  `Block3Show` varchar(20) NOT NULL default '',
			  `Block4` varchar(20) NOT NULL default '',
			  `Block4Show` varchar(20) NOT NULL default '',
			  `show_login_register` int(1) NOT NULL default '0',
			  `show_login_admin` int(1) NOT NULL default '0',
			  `show_login_logout` int(1) NOT NULL default '0',
			  `show_memb_newt` int(1) NOT NULL default '1',
			  `show_memb_newy` int(1) NOT NULL default '1',
			  `show_memb_total` int(1) NOT NULL default '1',
			  `show_memb_latest` int(1) NOT NULL default '1',
			  `show_memb_latest_num` int(2) NOT NULL default '15',
			  `show_online_total` int(1) NOT NULL default '0',
			  `show_mem` int(1) NOT NULL default '0',
			  `show_mem_detail` int(1) NOT NULL default '0',
			  `show_mem_detail_num` int(1) NOT NULL default '0',
			  `show_mem_detail_per` int(1) NOT NULL default '0',
			  `show_mem_detail_name_size` int(2) NOT NULL default '17',
			  `show_mem_detail_group` int(1) NOT NULL default '0',
			  `show_mem_detail_flag` int(1) NOT NULL default '0',
			  `show_mem_detail_flag_auto` int(1) NOT NULL default '0',
			  `show_mem_detail_loca` int(1) NOT NULL default '0',
			  `show_mem_detail_modu_size` int(1) NOT NULL default '0',
			  `show_gue` int(1) NOT NULL default '0',
			  `show_gue_detail` int(1) NOT NULL default '0',
			  `show_gue_detail_num` int(1) NOT NULL default '0',
			  `show_gue_detail_per` int(1) NOT NULL default '0',
			  `show_gue_detail_ipadd` int(1) NOT NULL default '0',
			  `show_gue_detail_flag` int(1) NOT NULL default '0',
			  `show_gue_detail_loca` int(1) NOT NULL default '0',
			  `show_spd` int(1) NOT NULL default '0',
			  `show_spd_detail` int(1) NOT NULL default '0',
			  `show_spd_detail_num` int(1) NOT NULL default '0',
			  `show_spd_detail_per` int(1) NOT NULL default '0',
			  `show_spd_detail_qty` int(1) NOT NULL default '0',
			  `show_spd_detail_flag` int(1) NOT NULL default '0',
			  `show_spd_detail_loca` int(1) NOT NULL default '0',
			  `show_module_unknown` varchar(50) NOT NULL default '0',
			  `past_time` int(10) NOT NULL default '0'
			) TYPE=MyISAM";
$RI5 = $db -> sql_query($QI5);
	
	echo "	<TR> \n";
	echo "		<TD CLASS='row1' ALIGN='LEFT' VALIGN='MIDDLE' COLSPAN='1'>\n";
	echo "			<FONT><NOBR>Creating table $checktable3</NOBR></FONT></TD>\n";
	echo "		<TD CLASS='row2' HEIGHT='20' ALIGN='LEFT' VALIGN='TOP'>\n";

if (table_exists($checktable3, $dbname)) 
	{
	echo "			<FONT STYLE='COLOR:$Green;'>Table Created</FONT></TD>\n";
	}
else
	{
	echo "			<FONT STYLE='COLOR:$Red;'><NOBR><B>Unable To Create Table</B></NOBR></FONT></TD>\n";
	$NotAllTables = 1;
	}
		
	echo "	</TR>\n";
	
$db -> sql_query("INSERT INTO $checktable3 (`Block1`, `Block1Show`, `Block2`, `Block2Show`, `Block3`, `Block3Show`, `Block4`, `Block4Show`, `show_login_register`, `show_login_admin`, `show_login_logout`, `show_memb_newt`, `show_memb_newy`, `show_memb_total`, `show_memb_latest`, `show_memb_latest_num`, `show_online_total`, `show_mem`, `show_mem_detail`, `show_mem_detail_num`, `show_mem_detail_per`, `show_mem_detail_name_size`, `show_mem_detail_group`, `show_mem_detail_flag`, `show_mem_detail_flag_auto`, `show_mem_detail_loca`, `show_mem_detail_modu_size`, `show_gue`, `show_gue_detail`, `show_gue_detail_num`, `show_gue_detail_per`, `show_gue_detail_ipadd`, `show_gue_detail_flag`, `show_gue_detail_loca`, `show_spd`, `show_spd_detail`, `show_spd_detail_num`, `show_spd_detail_per`, `show_spd_detail_qty`, `show_spd_detail_flag`, `show_spd_detail_loca`, `show_module_unknown`, `past_time`) 
									VALUES ('Login', 'All', 'PMS', 'Mem', 'Members', 'All', 'Online', 'All', 1, 1, 1, 1, 1, 1, 1, 10, 1, 1, 1, 1, 1, 17, 1, 1, 0, 1, 15, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 'Admin Section', 180);");
            
$QI9 = "SELECT * FROM $checktable3";
$RI9 = $db -> sql_query($QI9);
$NI9 = sql_num_rows($RI9);
		
	echo "	<TR> \n";
	echo "		<TD CLASS='row1' ALIGN='LEFT' VALIGN='TOP' COLSPAN='1'>\n";
	echo "			<NOBR>Inserting data into table $checktable3<BR>[Number of Lines: 1]</NOBR></TD>\n";
	echo "		<TD CLASS='row2' ALIGN='RIGHT' VALIGN='TOP' HEIGHT='20'>\n";
	
if ($NI9 == 1)
	{
	echo "			<FONT STYLE='COLOR:$Green;'>".number_format($NI9)." Line Verified</FONT></TD>\n";
	}
elseif ($NI9 == 0)
	{
	echo "			<FONT STYLE='COLOR:$Red;'><B><NOBR>Failed To Insert Data<BR>".number_format($NI9)." Lines Inserted</NOBR></B></FONT></TD>\n";
	$NotAllData = 1;
	}
		
	echo "	</TR>\n";	

BlankRow();

/* Table 4 --------------------------------------------------------------------------- */
$QI6 = "DROP TABLE IF EXISTS $checktable4";
$RI6 = $db -> sql_query($QI6);
				
$QI7 = "CREATE TABLE $checktable4 
			(
			  `icon_id` int(5) NOT NULL auto_increment,
			  `icon_username` varchar(50) NOT NULL default '',
			  `icon_image` varchar(50) NOT NULL default '',
			  PRIMARY KEY  (`icon_id`)
			) TYPE=MyISAM";
$RI7 = $db -> sql_query($QI7);
	
	echo "	<TR> \n";
	echo "		<TD CLASS='row1' ALIGN='LEFT' VALIGN='MIDDLE' COLSPAN='1'>\n";
	echo "			<FONT><NOBR>Creating table $checktable4</NOBR></FONT></TD>\n";
	echo "		<TD CLASS='row2' HEIGHT='20' ALIGN='LEFT' VALIGN='TOP'>\n";

if (table_exists($checktable4, $dbname)) 
	{
	echo "			<FONT STYLE='COLOR:$Green;'>Table Created</FONT></TD>\n";
	}
else
	{
	echo "			<FONT STYLE='COLOR:$Red;'><NOBR><B>Unable To Create Table</B></NOBR></FONT></TD>\n";
	$NotAllTables = 1;
	}
		
	echo "	</TR>\n";	
	echo "	<TR> \n";
	echo "		<TD CLASS='row1' ALIGN='LEFT' VALIGN='TOP' COLSPAN='1'>\n";
	echo "			<NOBR>Inserting data into table $checktable1<BR>[No Data To Insert]</NOBR></TD>\n";
	echo "		<TD CLASS='row2' ALIGN='RIGHT' VALIGN='TOP' HEIGHT='20'>\n";
	echo "			<FONT STYLE='COLOR:$Green;'>0 Lines Verified</FONT></TD>\n";
	echo "	</TR>\n";
		
if ($NotAllTables == 1)
	{	
	$ErrorMsg = "It appears that one or more of the tables failed to create, the $BlockName block will not work correctly unless all tables are created in your database. Please use the SQL file to create the correct table structure via phpMyAdmin (or similar). The file is located in sql/jag_online.sql. Then rerun this file to complete the installation.";
	EndNow($ErrorMsg);
	}
	
if ($NotAllData == 1)
	{	
	$ErrorMsg = "It appears that not all the data was inserted into the appropriate tables, the $BlockName block will not work correctly unless all the data is inserted into the tables on your database. Please use the SQL file to insert the data into the tables via phpMyAdmin (or similar). The file is located in sql/jag_online.sql";
	EndNow($ErrorMsg);
	}	
	
NextStep($goto);
?>