Alan Lam 8 лет назад
Родитель
Сommit
ec173b0a16
3 измененных файлов с 35 добавлено и 0 удалено
  1. 33 0
      controllers/project_kml.php
  2. 1 0
      routes.php
  3. 1 0
      views/project.php

+ 33 - 0
controllers/project_kml.php

@@ -0,0 +1,33 @@
+<?php
+
+$project = Project::get($id);
+if(!$project) throw new Exception("Project cannot be found.");
+if(!Core::$user->hasPermission($project)) throw new Exception("You do not have permission to access this resource.");
+
+$slug = Util::slug($project->name);
+
+$locations = $project->getLocations();
+
+header("Content-Type: text/xml; charset=utf-8");
+//header("Content-Disposition: attachment; filename={$slug}-export.kml");
+
+$xml = simplexml_load_file(ROOT_DIR . "/files/empty.kml");
+
+$folder_node = $xml->addChild("Folder");
+$folder_node->addChild("name", $project->name);
+$folder_node->addChild("open", 1);
+$folder_node->addChild("description", $project->name . " Locations");
+
+foreach($locations as $location) {
+	$placemark_node = $folder_node->addChild("Placemark");
+
+	$placemark_node->addChild("name", htmlspecialchars($location->name));
+	$placemark_node->addChild("description", htmlspecialchars($location->getDisplayAddress()));
+
+	$point_node = $placemark_node->addChild("Point");
+	$point_node->addChild("coordinates", $location->longitude . "," . $location->latitude);
+}
+
+echo $xml->asXML();
+
+?>

+ 1 - 0
routes.php

@@ -65,6 +65,7 @@ $routes = [
 	"/^account\/projects\/$id_pattern\/edit$/" => ["controller" => "project_edit", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/projects\/$id_pattern\/export-csv$/" => ["controller" => "project_csv", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/projects\/$id_pattern\/export-customer-csv$/" => ["controller" => "project_customer_csv", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
+	"/^account\/projects\/$id_pattern\/export-kml$/" => ["controller" => "project_kml", "params" => ["id"], "require_user_level" => User::LEVEL_ADMIN],
 	"/^account\/projects\/$id_pattern\/(get-locations|get-testers|create-test|assign-tester)$/" => ["controller" => "project_ajax", "params" => ["id", "action"], "type" => "json", "require_user_level" => User::LEVEL_ADMIN],
 
 	// Tests

+ 1 - 0
views/project.php

@@ -31,6 +31,7 @@ var projectID = <?=$project->id?>;
 					<a class="dropdown-item" href="/account/projects/<?=$project->id?>/edit">Edit</a>
 					<a class="dropdown-item" href="/account/projects/<?=$project->id?>/export-csv">Export CSV</a>
 					<a class="dropdown-item" href="/account/projects/<?=$project->id?>/export-customer-csv">Export Customer CSV</a>
+					<a class="dropdown-item" href="/account/projects/<?=$project->id?>/export-kml">Export KML</a>
 				</div>
 			</div>
 			<?php