<?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 6: Creating Tables And Inserting Data</SPAN></TD>\n";
	echo "  </TR>\n";

/* Table 5 --------------------------------------------------------------------------- */
$QI2 = "DROP TABLE IF EXISTS $checktable5";
$RI2 = $db -> sql_query($QI2);
			
$QI3 = "CREATE TABLE $checktable5 
			(
  			ip_from int(10) unsigned NOT NULL default '0',
  			ip_to int(10) unsigned NOT NULL default '0',
  			country varchar(50) NOT NULL default '',
  			KEY code (ip_from, ip_to, country)
			) 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 $checktable5</NOBR></FONT></TD>\n";
	echo "		<TD CLASS='row2' HEIGHT='20' ALIGN='LEFT' VALIGN='TOP'>\n";

if (table_exists($checktable5, $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";	

$FileCount = 1;
$PrevTotal = 0;

while($FileCount <= 5)
	{	
	$i = 0;	
	$csv_filename = "JAG_Online_Install/JAG_Online_Step_6_IPLookup_".$FileCount.".csv";
	
	$fp = fopen($csv_filename, 'r');
	while(!feof($fp))
		{
		$row 	= fgets($fp, 4096);
		$data 	= explode(",", $row);
	
		$ip_from   	= $data[0];
		$ip_to 		= $data[1];
		$country	= $data[2];
		$country    = ucwords(strtolower($country));
		
		$db -> sql_query("INSERT INTO $checktable5 VALUES('$ip_from', '$ip_to', '$country')");
		$i++;
		}
	
	fclose( $fp );

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

	$QI8 = "SELECT * FROM $checktable5";
	$RI8 = $db -> sql_query($QI8);
	$NI8 = sql_num_rows($RI8);
	$TotalInserted = $NI8 - $PrevTotal;
	
	if ($TotalInserted == $i)
		{
		echo "			<FONT STYLE='COLOR:$Green;'>".number_format($i)." Lines Verified</FONT></TD>\n";
		}
	else
		{
		echo "			<FONT STYLE='COLOR:$Red;'><B><NOBR>Data Missing<BR>".number_format($i)." Lines Inserted</NOBR></B></FONT></TD>\n";
		$NotAllData = 1;
		}		
		
	echo "	</TR>\n";
	
	$PrevTotal = $NI8;
	$FileCount++;
	}
	
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 insalation.";
	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);
	}		
	
BlankRow();	

$i 		 = 0;	
$updates = array("show_mem_detail_flag_auto, show_gue_detail_flag, show_spd_detail_flag");
$updates = explode(",", $updates);

while($i < 3)
	{	
	$db -> sql_query("UPDATE $checktable3 SET ".$updates[$i]." = 1");
	$i++;
	}
	
	echo "	<TR> \n";
	echo "		<TD CLASS='row1' ALIGN='LEFT' VALIGN='TOP' COLSPAN='1'>\n";
	echo "			<NOBR>Updating Data in $checktable3<BR>[Number of Lines: ".number_format($i)."]</NOBR></TD>\n";
	echo "		<TD CLASS='row2' ALIGN='RIGHT' VALIGN='TOP' HEIGHT='20'>\n";
	
	if ($i == 3)
		{
		echo "			<FONT STYLE='COLOR:$Green;'>".number_format($i)." Fields Updated</FONT></TD>\n";
		}
	else
		{
		echo "			<FONT STYLE='COLOR:$Red;'><B><NOBR>Not Updated<BR>".number_format($i)." Fields Updated</NOBR></B></FONT></TD>\n";
		}		
		
	echo "	</TR>\n";
	
NextStep($goto);
?>