Advertisement
Guest User

Untitled

a guest
Jul 29th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. <?php
  2. define ("DB_HOST", "127.0.0.1");
  3. define ("DB_NAME", "map");
  4. define ("DB_USER", "root");
  5. define ("DB_PASS", "Hackathon42");
  6.  
  7.  
  8. class Bdd
  9. {
  10. public $config = array(),
  11. $error,
  12. $requete,
  13. $histo_requetes = array(),
  14. $link,
  15. $result;
  16.  
  17. function __construct($host=DB_HOST, $user=DB_USER, $pass=DB_PASS, $name=DB_NAME)
  18. {
  19. if ($host)
  20. $this->config['host'] = $host;
  21. if ($user)
  22. $this->config['user'] = $user;
  23. if ($name)
  24. $this->config['name'] = $name;
  25. $this->config['pass'] = $pass;
  26. $this->link = $this->connect();
  27. }
  28.  
  29. function connect()
  30. {
  31. $id = mysqli_connect($this->config['host'], $this->config['user'], $this->config['pass']);
  32. if (!$id)
  33. {
  34. $this->error = mysqli_connect_error();
  35. return false;
  36. }
  37. $sel = mysqli_select_db($id, $this->config['name']);
  38. if (!$sel)
  39. {
  40. $this->error = "Base de donn�es introuvable";
  41. return false;
  42. }
  43. mysqli_set_charset($id, 'utf8');
  44. return $id;
  45. }
  46.  
  47. function query($sql)
  48. {
  49. $this->requete[] = $sql;
  50. $query = mysqli_query($this->link, $sql);
  51. if (!$query)
  52. {
  53. $this->error = mysqli_error($this->link);
  54. return false;
  55. }
  56. if (preg_match("`^select`i", $sql))
  57. {
  58. $recordset = array();
  59. while ($data = mysqli_fetch_assoc($query))
  60. {
  61. $recordline = array();
  62. foreach($data as $key => $value)
  63. {
  64. $recordline[$key] = $value;
  65. }
  66. $recordset[] = $recordline;
  67. }
  68. $this->result = $recordset;
  69. return $recordset;
  70. }
  71. if (preg_match("`^insert`i", $sql))
  72. {
  73. return mysqli_insert_id($this->link);
  74. }
  75. }
  76.  
  77. function escape($input) {
  78. if (is_array($input)) {
  79. $output = array();
  80. foreach($input as $k=>$v) {
  81. $output[$k] = $this->escape($v);
  82. }
  83. return $output;
  84. } else {
  85. return mysqli_real_escape_string($this->link, $input);
  86. }
  87. }
  88. }
  89.  
  90.  
  91. $bdd = new Bdd();
  92. $markers = $bdd->query("SELECT * FROM flag");
  93. ?>
  94. <!DOCTYPE html>
  95. <html>
  96. <head>
  97. <meta charset="utf-8" />
  98. <title>Presentation</title>
  99. <script src="http://maps.googleapis.com/maps/api/js?libraries=places"></script>
  100. <script>
  101. function getRandomInt(min, max) {
  102. return Math.floor(Math.random() * (max - min + 1)) + min;
  103. }
  104. function initialize() {
  105. var mapProp = {
  106. center:new google.maps.LatLng(48.859733, 2.341947),
  107. zoom:12,
  108. mapTypeId:google.maps.MapTypeId.ROADMAP,
  109. scrollwheel: false
  110. };
  111. var map=new google.maps.Map(document.getElementById("googleMap"), mapProp);
  112. <?php
  113. foreach($markers as $m) {
  114. if ($m['status'] == "safe") {
  115. echo '
  116. var marker = new google.maps.Marker({
  117. icon: \'http://maps.google.com/mapfiles/ms/icons/green-dot.png\',
  118. position: new google.maps.LatLng('.$m['lat'].', '.$m['lng'].'),
  119. map: map,
  120. animation: google.maps.Animation.DROP,
  121. title: \''.$m['status'].'\'
  122. });
  123. ';
  124. } else if ($m['status'] == "unsafe") {
  125. echo '
  126. var marker = new google.maps.Marker({
  127. icon: \'http://maps.google.com/mapfiles/ms/icons/red-dot.png\',
  128. position: new google.maps.LatLng('.$m['lat'].', '.$m['lng'].'),
  129. map: map,
  130. animation: google.maps.Animation.DROP,
  131. title: \''.$m['status'].'\'
  132. });
  133. ';
  134. }
  135. }
  136. ?>
  137. socket.on('flag', function(e) {
  138. var marker = new google.maps.Marker({
  139. position: new google.maps.LatLng(e.lat, e.lng),
  140. map: map,
  141. animation: google.maps.Animation.DROP,
  142. title: e.status
  143. });
  144. });
  145.  
  146. }
  147. </script>
  148. </head>
  149. <body onload="initialize()">
  150. <div id="googleMap" style="width: 800px; height: 450px; margin: 40px auto; border: 1px solid black"></div>
  151. <script src="https://cdn.socket.io/socket.io-1.4.3.js"></script>
  152. <script>
  153. var socket = io('104.197.132.231'+':8080');
  154. </script>
  155. </body>
  156. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement