1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
|
<?
$CONFIG{'hostname'} = 'imysql04';
$CONFIG{'user'} = 'i5653113';
$CONFIG{'password'} = '2vn89r6eiw1u9cwo';
$CONFIG{'db'} = 'i5653113';
//mysql_connect("imysql04","i5653113","2vn89r6eiw1u9cwo");
//mysql_select_db("i5653113");
# WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING
#
# This script will attempt to create the database specified in $CONFIG{'db'}
# and a table called 'geo' in that database.
#
# WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING - WARNING
$DBH = DB_Connect();
// Make sure the table exists
assertTable();
// define vars
$desc = '';
$lat = '';
$lon = '';
// read POST variables if present
foreach ($_POST as $name => $value) {
$$name = $value;
}
// If post variables desc,lat and long are not empty then we're inserting
if ($desc && $lat && $lon) {
if (is_numeric($lat) && is_numeric($lon) && is_string($desc)) {
if ($lat < -85 || $lat > 85 || $lon < -180 || $lon > 180) {
print "You've entered invalid values";
exit;
}
$desc = addslashes(substr($desc,0,200));
$sql = "insert into geoPoints values ( null , $lat, $lon, '$desc' )";
$result = mysql_query($sql,$DBH) or DBError("LINE: " .__LINE__. " $sql");
print "Point inserted<br><a href=\"{$_SERVER{'PHP_SELF'}}\">Back to the map</a>\n";
exit;
}
}
// Get the javascript defining the points after inserting.
$jsPointsArray = getPointsJS();
$pageHTML = <<<EOH
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAZYj6ryHchNChWJyfjWe7dhRhFDjtz6VBwLd5IOO4cR9lBva98BQeJ2Y8C7tS_5bnsru_ZctimVXyOQ"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(40.0727, 2.1339), 5);
}
}
//]]>
var mArray = Array();
var map;
var centerPoint = new GLatLng(40.078071,2.189453);
function load() {
doLoad();
$jsPointsArray
addMarkers();
}
function doLoad() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.setCenter(centerPoint, 10);
map.addControl(new GScaleControl());
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
GEvent.addListener(map, 'click', mapClick);
}
}
function addMarkers() {
if (mArray.length) {
var bounds = new GLatLngBounds();
for (n=0 ; n < mArray.length ; n++ ) {
var mData = mArray[n].split(';');
var point = new GLatLng(mData[0],mData[1]);
var chemicone = mData[6];
print mdata[6];
bounds.extend(point);
var marker = createMarker(point, mData[2]);
//var marker = new GMarker(point,{'icon': icon[n], 'title': tooltip});
//map.addMarkerIcon("RF.png");
map.addOverlay(marker);
}
map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
}
}
function createMarker(point, title,chemicone) {
var icon = [];
icon[0] = new GIcon();
icon[0].image = "http://arawn45.ifrance.com/index_fichiers/" + chemicone;
icon[0].shadow = "http://arawn45.ifrance.com/index_fichiers/" + chemicone;
icon[0].shadowSize = new GSize(16,16);
icon[0].iconSize = new GSize(16,16);
icon[0].iconAnchor = new GPoint(17,0);
icon[0].infoWindowAnchor = new GPoint(23,10);
var marker = new GMarker(point,{'icon': icon[0], title:title});
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml('<div style="width:250px;">' + title + '<hr>Lat: ' + point.y + '<br>Lon: ' + point.x + '</div>');
});
return marker;
}
function mapClick(marker, point) {
if (!marker) {
oLat = document.getElementById("lat");
oLat.value = point.y;
oLon = document.getElementById("lon");
oLon.value = point.x;
oDesc = document.getElementById("desc");
oDesc.value = 'New point';
}
}
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="msg" style="width: 680px; border: 1px solid gray;font: bold 12px verdana;padding:3px;margin:10px;">
Note: text a definir.<br>
text a definir.
</div>
<div id="map" style="width: 700px; height: 500px"></div>
<div id="formDiv">
<table cellspacing="0" cellpadding="2">
<form method="POST">
<tr>
<td colspan="2" align="center">Add a marker</td>
</tr>
<tr>
<td>Description</td>
<td><input id="desc" name="desc"> Example: 'My marker</td>
</tr>
<tr>
<td>Latitude</td>
<td><input id="lat" name="lat"> Example: 40.0</td>
</tr>
<tr>
<td>Longitude</td>
<td><input id="lon" name="lon"> Example: -101.5</td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Add Point"></td>
</tr>
<tr>
<td colspan="2" align="center"><a href="googlemap.txt">View PHP source</a></td>
</tr>
</form>
</table>
</div>
</body>
</html>
EOH;
print $pageHTML;
print DoQueriy('Table contents',"select * from geoPoints order by id");
print $chemicone;
///////////////////////////// Functions ///////////////////////////////////////
function getPointsJS() {
global $DBH;
$sql = "select * from geoPoints";
$result = mysql_query($sql,$DBH) or DBError("LINE: " .__LINE__. " $sql");
$nRows = mysql_num_rows($result);
$javaScript = '';
if ($nRows) {
while ($row = mysql_fetch_assoc($result)) {
$row{'description'} = addslashes($row{'description'});
$row{'description'} = str_replace(';',',',$row{'description'});
$javaScript .= "mArray.push('{$row{'lat'}};{$row{'lon'}};{$row{'description'}};{$row{'bddtype'}};{$row{'categorie'}};{$row{'souscate'}};{$row{'bddicone'}}')\n";
}
print "Selected $nRows rows\n";
}
else {
print "No points found in database\n";
}
return $javaScript;
}
function assertTable() {
global $DBH;
// Create table, if it does not already exist
$createTableSQL = <<<EOS
CREATE TABLE IF NOT EXISTS geoPoints (
id int(11) NOT NULL auto_increment,
lat decimal(12,8) NOT NULL,
lon decimal(12,8) NOT NULL,
description varchar(255) NOT NULL,
bddtype varchar(255) NOT NULL,
categorie varchar(255) NOT NULL,
souscate varchar(255) NOT NULL,
bddicone varchar(255) NOT NULL,
PRIMARY KEY (id)
) TYPE=MyISAM;
EOS;
$sql = $createTableSQL;
$result = mysql_query($sql,$DBH) or DBError("LINE: " .__LINE__. " $sql");
}
function DBError($sql){
print "Error: \n" . mysql_error() . "\n";
print "<hr>\n";
print "$sql\n";
print "<hr>\n";
exit;
}
function DB_Connect() {
global $CONFIG;
$DBH = mysql_connect($CONFIG{'hostname'}, $CONFIG{'user'}, $CONFIG{'password'}) or DBError("LINE: " .__LINE__. " Connect");;
$sql = "create database IF NOT EXISTS {$CONFIG{'db'}}";
$result = mysql_query($sql,$DBH) or DBError("LINE: " .__LINE__. " $sql");
mysql_select_db($CONFIG{'db'}, $DBH) or DBError("LINE: " .__LINE__. " Select DB");;
return $DBH;
}
function DoQueriy($title,$sql){
global $DBH;
$HTML = '';
$result = mysql_query($sql,$DBH) or DBError($sql);
$colCount = mysql_num_fields($result);
$rowCount = mysql_num_rows($result);
$HTML .= "<table cellspacing=\"0\" cellpadding=\"0\" border>\n";
$HTML .= "<tr>\n";
$HTML .= " <td colspan=\"$colCount\" style=\"padding:3px;font-weight:bold;text-align:center;\">\n";
$HTML .= " $title\n";
$HTML .= " </td>\n";
$HTML .= "</tr>\n";
if ($rowCount) {
if ($row = mysql_fetch_assoc($result)) {
$HTML .= "<tr>\n";
foreach ($row as $name => $value) {
$HTML .= " <td style=\"padding:3px;\">\n";
$HTML .= $name;
$HTML .= " </td>\n";
}
$HTML .= "</tr>\n";
}
mysql_data_seek($result,0);
while ($row = mysql_fetch_assoc($result)) {
$HTML .= "<tr>\n";
foreach ($row as $name => $value) {
$HTML .= " <td style=\"padding:3px;\">\n";
$HTML .= $value;
$HTML .= " </td>\n";
}
$HTML .= "</tr>\n";
}
}
else {
$HTML .= "<tr>\n";
$HTML .= " <td colspan=\"$colCount\" style=\"padding:3px;font-weight:bold;text-align:center;\">\n";
$HTML .= " Empty\n";
$HTML .= " </td>\n";
$HTML .= "</tr>\n";
}
$HTML .= "</table>\n";
$HTML .= "<br>\n";
return $HTML;
}
?>
</body>
</html> |
Partager