distancefinder/install.php

90 lines
2 KiB
PHP
Raw Normal View History

<center>
<h3>Installation</h3>
<?php if(!$_POST) { ?>
<table>
<tr>
<td>
<ul>
<li>Create table df_distances</li>
<li>Create table df_locations</li>
<li>Create table df_geocities</li>
<li>Insert data into df_geocities (might take a while...)</li>
</ul>
</td>
</tr>
</table>
<form method="post"><input type="submit" name="btn-submit" value="Install"></form>
<?php exit; } ?>
<?php
require_once 'bootstrap.php';
set_time_limit(0);
$query = "
CREATE TABLE `df_distances` (
`id1` int(11) NOT NULL,
`id2` int(11) NOT NULL,
`distance` varchar(50) character set latin1 NOT NULL,
UNIQUE KEY `city1` (`id1`,`id2`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
";
dbQuery($query);
$query = "
CREATE TABLE `df_locations` (
`id` int(11) NOT NULL auto_increment,
`address` varchar(250) character set latin1 NOT NULL,
`latitude` varchar(50) character set latin1 NOT NULL,
`longitude` varchar(50) character set latin1 NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `address` (`address`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
";
dbQuery($query);
$query = "
CREATE TABLE `df_geocities` (
`city` varchar(50) character set latin1 NOT NULL,
`countrycode` varchar(2) character set latin1 NOT NULL,
`statecode` varchar(50) character set latin1 NOT NULL,
`population` int(11) NOT NULL,
`latitude` varchar(50) character set latin1 NOT NULL,
`longitude` varchar(50) character set latin1 NOT NULL,
KEY `city` (`city`),
KEY `countrycode` (`countrycode`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
";
dbQuery($query);
if(1){
$file = file_get_contents(DIRPATH.CSVFILE);
$columns = array('city', 'countrycode', 'statecode', 'population', 'latitude', 'longitude');
foreach(explode("\n", $file) as $i => $line){
if(!trim($line))continue;
$insert = array_combine($columns, explode(',', $line));
dbInsert('df_geocities', $insert);
echo 'row '.$i.' inserted<br>';
}
}
?>
<h2>Install complete.</h2>
<a href="index.php">Go to panel</a>
</center>