Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.03 KB | None | 0 0
  1. <?php
  2. if(count($_FILES) > 0) {
  3. if(is_uploaded_file($_FILES['userImage']['tmp_name'])) {
  4. mysql_connect("", "", "");
  5. mysql_select_db ("");
  6. $imgData =addslashes(file_get_contents($_FILES['userImage']['tmp_name']));
  7. $imageProperties = getimageSize($_FILES['userImage']['tmp_name']);
  8. $sql = "INSERT INTO markers(imageFileType, image)
  9. VALUES('{$imageProperties['mime']}', '{$imgData}')";
  10. $current_id = mysql_query($sql) or die("Error:Problem on Image Insert" . mysql_error());
  11. if(isset($current_id)) {
  12. header("Location: imagedisplay.php");
  13. }
  14. }
  15. }
  16. ?>
  17.  
  18. <?php
  19. $conn = mysql_connect("", "", "");
  20. mysql_select_db("") or die(mysql_error());
  21. if(isset($_GET['image_id'])) {
  22. $sql = "SELECT imageFileType,image FROM markers WHERE id=" . $_GET['image_id'];
  23. $result = mysql_query("$sql") or die("Error: Problem retrieving Image BLOB" . mysql_error());
  24. $row = mysql_fetch_array($result);
  25. header("Content-type: " . $row["imageFileType"]);
  26. echo $row["image"];
  27. }
  28. mysql_close($conn);
  29. ?>
  30.  
  31. <?php
  32. $conn = mysql_connect("", "", "");
  33. mysql_select_db("");
  34. $sql = "SELECT id FROM markers ORDER BY id DESC LIMIT 1";
  35. $result = mysql_query($sql);
  36. ?>
  37.  
  38. <?php
  39. while($row = mysql_fetch_array($result)) {
  40. ?>
  41. <img src="imageview.php?image_id=<?php echo $row["id"]; ?>" width="150" height="150"/>
  42. <?php
  43. }
  44. ?>
  45.  
  46. // Google map API
  47. var map;
  48. function initMap() {
  49. var mapCenter = {lat: -35.2807, lng: 149.1306}; // Creates a variable called 'mapCenter' with Canberra's latitude and longitude
  50. mapInitialize(); // Loads map
  51.  
  52. function mapInitialize()
  53. {
  54. var googleMapOptions =
  55. {
  56. center: mapCenter, // 'mapCenter' is Canberra's latitude and longitude
  57. zoom: 14,
  58. maxZoom: 17,
  59. minZoom: 14,
  60. streetViewControl: false, // Removes street view control from map
  61. mapTypeControl: false, // Removes map controls from map
  62. zoomControl: true, // Includes zoom controls on map
  63. zoomControlOptions: {
  64. position: google.maps.ControlPosition.RIGHT_CENTER, // Positions zoom controls to the right, centered on the map.
  65. },
  66. scaleControl: true, // Includes scale control for map
  67. mapTypeId: google.maps.MapTypeId.ROADMAP,
  68. styles: [ // Map styles
  69. {
  70. featureType: 'all',
  71. stylers: [
  72. { saturation: 65 }
  73. ]
  74. },{
  75. featureType: 'road.arterial',
  76. elementType: 'geometry',
  77. stylers: [
  78. { hue: '#b82c5a' },
  79. { saturation: 70 }
  80. ]
  81. },{
  82. featureType: 'poi.business',
  83. elementType: 'labels',
  84. stylers: [
  85. { visibility: 'off' }
  86. ]
  87. }
  88. ]
  89. };
  90.  
  91. map = new google.maps.Map(document.getElementById("map"), googleMapOptions);
  92.  
  93. $.get("http://grace-portfolio.com/public-art-in-canberra/wp-content/themes/publicartincanberra/mapsql.php", function (data) {
  94. $(data).find("marker").each(function () {
  95. var title = $(this).attr('title');
  96. var image = $(this).attr('image');
  97. var description = $(this).attr('description');
  98. var location = $(this).attr('location');
  99. var point = new google.maps.LatLng(parseFloat($(this).attr('lat')),parseFloat($(this).attr('lng')));
  100. createMarker(point, title, image, description, location, false, false, false, false, "http://grace-portfolio.com/public-art-in-canberra/wp-content/uploads/2016/08/mapmarker.png");
  101. });
  102. });
  103.  
  104. // Content inside pop-up boxes for edit form
  105. google.maps.event.addListener(map, 'rightclick', function(event) {
  106. var editPopupInfo = '<div class="edit_popup">'+
  107. '<form action="ajax-save.php" method="POST" name="frmImage" id="SaveMarker" enctype="multipart/form-data">'+
  108. '<label for="popUpPhoto"><span id="photo_title">Select photo : </span><input name="userImage" type="file" class="inputFile" id="public_art_photo"/>'+
  109. '<label for="popUpName"><span>Title of public art : </span><input type="text" name="popupName" class="saveName" placeholder="Enter the title of the public art" maxlength="120" /></label>'+
  110. '<label for="popUpDescription"><span>Description : </span><textarea name="popUpDescription" class="saveDescription" placeholder="Enter a description for the photo" maxlength="120"></textarea></label>'+
  111. '<label for="dropDown"><span id="location_title">Location of public art : </span> <select name="dropDown" class="saveLocation"><option value="Belconnen">Belconnen</option><option value="Civic">Civic</option><option value="Gungahlin">Gungahlin</option><option value="North Canberra">North Canberra</option><option value="Parliamentary Triangle">Parliamentary Triangle</option><option value="South Canberra">South Canberra</option><option value="Tuggeranong">Tuggeranong</option>'+
  112. '<option value="Woden">Woden</option></select></label>'+
  113. '</form>'+
  114. '</div><button value="Upload" name="save_button" class="save_button">Save</button>';
  115.  
  116. createMarker(event.latLng, 'New photo', editPopupInfo, true, true, true, true, "http://grace-portfolio.com/public-art-in-canberra/wp-content/uploads/2016/08/mapmarker.png");
  117.  
  118. });
  119.  
  120. }
  121.  
  122. // Create marker function
  123. function createMarker(mapPosition, mapTitle, mapDescription, mapLocation, setDraggable, infoOpenDefault)
  124. {
  125. // New marker
  126. var marker = new google.maps.Marker({
  127. position: mapPosition,
  128. map: map,
  129. draggable: false, // Don't allow users to drag map markers they create
  130. animation: google.maps.Animation.DROP, // Animation for map markers
  131. icon: 'http://grace-portfolio.com/public-art-in-canberra/wp-content/uploads/2016/08/mapmarker.png'
  132. });
  133.  
  134.  
  135. // Structure of popup box information for the map markers
  136. var contentString = $('<div class="edit_popup">' + '<div class="markerpopUpInfoInner"><span class="markerpopUpInfoContent">' + '<h1 class="map_marker_heading">'+mapTitle+'</h1>' + '<p class="pop_up_info_description">'+mapDescription+'</p>' + '<p class="pop_up_location_description">'+mapLocation+'</p>' + '</span>' + '</div></div>');
  137.  
  138.  
  139. // Create a popup box (InfoWindow)
  140. var infowindow = new google.maps.InfoWindow();
  141.  
  142. //set the content of infoWindow
  143. infowindow.setContent(contentString[0]);
  144.  
  145. var saveButton = contentString.find('button.save_button')[0];
  146.  
  147. if(typeof saveButton !== 'undefined')
  148. {
  149. google.maps.event.addDomListener(saveButton, "click", function(event) {
  150. var aReplace = contentString.find('span.markerpopUpInfoContent');
  151. var aTitle = contentString.find('input.saveName')[0].value;
  152. var aImage = contentString.find('input.inputFile')[0].value;
  153. var aDescription = contentString.find('textarea.saveDescription')[0].value;
  154. var aLocation = contentString.find('select.saveLocation')[0].value;
  155.  
  156. if(aTitle =='' || aImage =='' || aDescription =='') // If title and description are blank, show alert.
  157. {
  158. alert("Please upload a photo, and enter a title and description for the photo.");
  159. } else {
  160. saveMarker(marker, aTitle, aImage, aDescription, aLocation, aReplace);
  161. }
  162. });
  163. }
  164.  
  165. google.maps.event.addListener(marker, 'click', function() {
  166. infowindow.open(map, marker);
  167. });
  168.  
  169. if(infoOpenDefault)
  170. {
  171. infowindow.open(map, marker);
  172. }
  173. }
  174.  
  175. // Save marker function
  176. function saveMarker(marker, aTitle, aImage, aDescription, aLocation, replaceWith)
  177. {
  178.  
  179. var aLatLang = marker.getPosition().toUrlValue();
  180. var myData = {
  181. title : aTitle,
  182. image: aImage,
  183. description : aDescription,
  184. latlang : aLatLang,
  185. location : aLocation
  186. };
  187.  
  188. console.log(replaceWith);
  189. $.ajax({
  190. type: "POST",
  191. url: "http://grace-portfolio.com/public-art-in-canberra/wp-content/themes/publicartincanberra/mapsql.php",
  192. data: myData,
  193. success: function(data){
  194. replaceWith.html(data);
  195. marker.setDraggable(false);
  196. marker.setIcon("http://grace-portfolio.com/public-art-in-canberra/wp-content/uploads/2016/08/mapmarker.png");
  197. },
  198. error:function (xhr, ajaxOptions, thrownError){
  199. alert(thrownError);
  200. }
  201. });
  202. }
  203.  
  204.  
  205. }
  206.  
  207. <?php
  208.  
  209. //PHP 5 +
  210.  
  211. include("imageupload.php"); // Includes imageupload.php file
  212. include("imageview.php"); // Includes imageview.php file
  213. include("imagedisplay.php"); // Includes imagedisplay.php file
  214.  
  215.  
  216. // Database settings
  217. $db_username = '';
  218. $db_password = '';
  219. $db_name = '';
  220. $db_host = '';
  221.  
  222. //mysqli
  223. $mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
  224.  
  225. if (mysqli_connect_errno())
  226. {
  227. die('Connect Error: ' . $mysqli->connect_errno);
  228. }
  229.  
  230.  
  231. if($_POST)
  232. {
  233.  
  234. $xhr = $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest';
  235. if (!$xhr){
  236. header('HTTP/1.1 500 Error: Request must come from Ajax!');
  237. exit();
  238. }
  239.  
  240. $aLatLang = explode(',',$_POST["latlang"]);
  241. $aLat = filter_var($aLatLang[0], FILTER_VALIDATE_FLOAT);
  242. $aLng = filter_var($aLatLang[1], FILTER_VALIDATE_FLOAT);
  243.  
  244. //Delete Marker
  245. if(isset($_POST["del"]) && $_POST["del"]==true)
  246. {
  247. $results = $mysqli->query("DELETE FROM markers WHERE lat=$aLat AND lng=$aLng");
  248. if (!$results) {
  249. header('HTTP/1.1 500 Error: Could not delete Markers!');
  250. exit();
  251. }
  252. exit();
  253. }
  254.  
  255. $aTitle = filter_var($_POST["title"], FILTER_SANITIZE_STRING);
  256. $aImage = filter_var($_POST["image"], FILTER_SANITIZE_STRING);
  257. $aDescription = filter_var($_POST["description"], FILTER_SANITIZE_STRING);
  258. $aLocation = filter_var($_POST["location"], FILTER_SANITIZE_STRING);
  259.  
  260. $results = $mysqli->query("INSERT INTO markers (title, imageFileType, image, description, lat, lng, location) VALUES ('$aTitle', '$aImageFileType', '$aImage', '$aDescription', $aLat, $aLng, '$aLocation')");
  261. if (!$results) {
  262. header('HTTP/1.1 500 Error: Could not create marker!');
  263. exit();
  264. }
  265.  
  266. $output = '<h1 class="map_marker_heading">'.$aTitle.'</h1><p class="photo_description">'.$aDescription.'</p><p class="photo_location">'.$aLocation.'</p>';
  267. exit($output);
  268. }
  269.  
  270.  
  271. //Create a new DOMDocument object
  272. $dom = new DOMDocument("1.0");
  273. $node = $dom->createElement("markers");
  274. $parnode = $dom->appendChild($node);
  275.  
  276. // Select all the rows in the markers table
  277. $results = $mysqli->query("SELECT * FROM markers WHERE 1");
  278. if (!$results) {
  279. header('HTTP/1.1 500 Error: Could not get markers!');
  280. exit();
  281. }
  282.  
  283. //set document header to text/xml
  284. header("Content-type: text/xml");
  285. header("Content-type: jpg");
  286.  
  287. // Iterate through the rows, adding XML nodes for each
  288. while($obj = $results->fetch_object())
  289. {
  290. $node = $dom->createElement("marker");
  291. $newnode = $parnode->appendChild($node);
  292. $newnode->setAttribute("title",$obj->title);
  293. $newnode->setAttribute("description", $obj->description);
  294. $newnode->setAttribute("lat", $obj->lat);
  295. $newnode->setAttribute("lng", $obj->lng);
  296. $newnode->setAttribute("location", $obj->location);
  297. }
  298.  
  299. echo $dom->saveXML();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement