|
@@ -1,5 +1,8 @@
|
|
|
<?php /** @noinspection PhpUnhandledExceptionInspection */
|
|
<?php /** @noinspection PhpUnhandledExceptionInspection */
|
|
|
|
|
|
|
|
|
|
+use Exports\LocationCsvExport;
|
|
|
|
|
+use Exports\LocationKmlExport;
|
|
|
|
|
+
|
|
|
Core::addScript("public/js/app-locations.js");
|
|
Core::addScript("public/js/app-locations.js");
|
|
|
|
|
|
|
|
Core::addBreadcrumb("/account", "Account");
|
|
Core::addBreadcrumb("/account", "Account");
|
|
@@ -93,67 +96,16 @@ $action = http::value("action");
|
|
|
if(!empty($action)) {
|
|
if(!empty($action)) {
|
|
|
switch($action) {
|
|
switch($action) {
|
|
|
case "export":
|
|
case "export":
|
|
|
|
|
+ if(!Core::$user->canAdmin()) throw new RuntimeException("You do not have permission to access this resource.");
|
|
|
|
|
|
|
|
- if(!Core::$user->canAdmin()) throw new Exception("You do not have permission to access this resource.");
|
|
|
|
|
-
|
|
|
|
|
- header("Content-Type: text/csv; charset=utf-8");
|
|
|
|
|
- header("Content-Disposition: attachment; filename=$customer_slug-export.csv");
|
|
|
|
|
-
|
|
|
|
|
- $handle = fopen("php://output", "w");
|
|
|
|
|
-
|
|
|
|
|
- fputcsv($handle, [
|
|
|
|
|
- "ID", "Internal ID", "City", "Legal Entity", "Region", "Area Manager", "Area Manager Email", "Open", "Close", "Name", "Address", "Postcode", "Email", "Latitude", "Longitude"
|
|
|
|
|
- ]);
|
|
|
|
|
-
|
|
|
|
|
- foreach($locations as $location) {
|
|
|
|
|
- fputcsv($handle, [
|
|
|
|
|
- $location->id,
|
|
|
|
|
- $location->internal_id,
|
|
|
|
|
- $location->city,
|
|
|
|
|
- $location->legal_entity_name,
|
|
|
|
|
- $location->region,
|
|
|
|
|
- $location->area_manager,
|
|
|
|
|
- $location->area_manager_email,
|
|
|
|
|
- "",
|
|
|
|
|
- "",
|
|
|
|
|
- $location->name,
|
|
|
|
|
- $location->address_1,
|
|
|
|
|
- $location->postal_code,
|
|
|
|
|
- $location->email,
|
|
|
|
|
- $location->latitude,
|
|
|
|
|
- $location->longitude,
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- fclose($handle);
|
|
|
|
|
-
|
|
|
|
|
- exit;
|
|
|
|
|
|
|
+ $export = new LocationCsvExport($locations);
|
|
|
|
|
+ $export->export("$customer_slug-export.csv");
|
|
|
|
|
+ exit();
|
|
|
|
|
|
|
|
case "export-kml":
|
|
case "export-kml":
|
|
|
-
|
|
|
|
|
- header("Content-Type: application/vnd.google-earth.kml+xml; charset=utf-8");
|
|
|
|
|
- header("Content-Disposition: attachment; filename=$customer_slug-export.kml");
|
|
|
|
|
-
|
|
|
|
|
- $xml = simplexml_load_file(ROOT_DIR . "/files/empty.kml");
|
|
|
|
|
-
|
|
|
|
|
- $folder_node = $xml->addChild("Folder");
|
|
|
|
|
- $folder_node->addChild("name", $customer->name);
|
|
|
|
|
- $folder_node->addChild("open", 1);
|
|
|
|
|
- $folder_node->addChild("description", $customer->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();
|
|
|
|
|
-
|
|
|
|
|
|
|
+ $export = new LocationKmlExport($locations);
|
|
|
|
|
+ $export->setCustomer($customer);
|
|
|
|
|
+ $export->export("$customer_slug-export.kml");
|
|
|
exit;
|
|
exit;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|