Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define ("DB_HOST", "127.0.0.1");
- define ("DB_NAME", "map");
- define ("DB_USER", "root");
- define ("DB_PASS", "Hackathon42");
- class Bdd
- {
- public $config = array(),
- $error,
- $requete,
- $histo_requetes = array(),
- $link,
- $result;
- function __construct($host=DB_HOST, $user=DB_USER, $pass=DB_PASS, $name=DB_NAME)
- {
- if ($host)
- $this->config['host'] = $host;
- if ($user)
- $this->config['user'] = $user;
- if ($name)
- $this->config['name'] = $name;
- $this->config['pass'] = $pass;
- $this->link = $this->connect();
- }
- function connect()
- {
- $id = mysqli_connect($this->config['host'], $this->config['user'], $this->config['pass']);
- if (!$id)
- {
- $this->error = mysqli_connect_error();
- return false;
- }
- $sel = mysqli_select_db($id, $this->config['name']);
- if (!$sel)
- {
- $this->error = "Base de donn�es introuvable";
- return false;
- }
- mysqli_set_charset($id, 'utf8');
- return $id;
- }
- function query($sql)
- {
- $this->requete[] = $sql;
- $query = mysqli_query($this->link, $sql);
- if (!$query)
- {
- $this->error = mysqli_error($this->link);
- return false;
- }
- if (preg_match("`^select`i", $sql))
- {
- $recordset = array();
- while ($data = mysqli_fetch_assoc($query))
- {
- $recordline = array();
- foreach($data as $key => $value)
- {
- $recordline[$key] = $value;
- }
- $recordset[] = $recordline;
- }
- $this->result = $recordset;
- return $recordset;
- }
- if (preg_match("`^insert`i", $sql))
- {
- return mysqli_insert_id($this->link);
- }
- }
- function escape($input) {
- if (is_array($input)) {
- $output = array();
- foreach($input as $k=>$v) {
- $output[$k] = $this->escape($v);
- }
- return $output;
- } else {
- return mysqli_real_escape_string($this->link, $input);
- }
- }
- }
- $bdd = new Bdd();
- $markers = $bdd->query("SELECT * FROM flag");
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>Presentation</title>
- <script src="http://maps.googleapis.com/maps/api/js?libraries=places"></script>
- <script>
- function getRandomInt(min, max) {
- return Math.floor(Math.random() * (max - min + 1)) + min;
- }
- function initialize() {
- var mapProp = {
- center:new google.maps.LatLng(48.859733, 2.341947),
- zoom:12,
- mapTypeId:google.maps.MapTypeId.ROADMAP,
- scrollwheel: false
- };
- var map=new google.maps.Map(document.getElementById("googleMap"), mapProp);
- <?php
- foreach($markers as $m) {
- if ($m['status'] == "safe") {
- echo '
- var marker = new google.maps.Marker({
- icon: \'http://maps.google.com/mapfiles/ms/icons/green-dot.png\',
- position: new google.maps.LatLng('.$m['lat'].', '.$m['lng'].'),
- map: map,
- animation: google.maps.Animation.DROP,
- title: \''.$m['status'].'\'
- });
- ';
- } else if ($m['status'] == "unsafe") {
- echo '
- var marker = new google.maps.Marker({
- icon: \'http://maps.google.com/mapfiles/ms/icons/red-dot.png\',
- position: new google.maps.LatLng('.$m['lat'].', '.$m['lng'].'),
- map: map,
- animation: google.maps.Animation.DROP,
- title: \''.$m['status'].'\'
- });
- ';
- }
- }
- ?>
- socket.on('flag', function(e) {
- var marker = new google.maps.Marker({
- position: new google.maps.LatLng(e.lat, e.lng),
- map: map,
- animation: google.maps.Animation.DROP,
- title: e.status
- });
- });
- }
- </script>
- </head>
- <body onload="initialize()">
- <div id="googleMap" style="width: 800px; height: 450px; margin: 40px auto; border: 1px solid black"></div>
- <script src="https://cdn.socket.io/socket.io-1.4.3.js"></script>
- <script>
- var socket = io('104.197.132.231'+':8080');
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement