| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- /**
- * @var int $id
- * @var string $action
- */
- JSON::header();
- $customer = Customer::get($id);
- if(!$customer) JSON::fail("Customer not found.");
- if(!Core::$user->hasPermission($customer)) throw new Exception(__("No permission."));
- switch($action) {
- case "get-locations":
- $nvp = ["customer_id" => $customer->id];
- $id = http::value("id", "int");
- $internal_id = http::value("internal_id", "trim");
- $name = http::value("name", "trim");
- $legal_entity_name = http::value("legal_entity_name", "trim");
- if($id) $nvp["id"] = $id;
- if($internal_id) $nvp["internal_id"] = db::escape($internal_id);
- if($name) $nvp["name"] = Constraint::contains($name);
- if($legal_entity_name) $nvp["$legal_entity_name"] = Constraint::contains($legal_entity_name);
- $locations = Location::query($nvp, ["sort" => "name", "order" => "asc"]);
- $output = [];
- foreach($locations as $location) {
- $filename = Util::slug($customer->name);
- $icon = false;
- if(file_exists("public/img/markers/$filename.png")) {
- $icon = $filename . ".png";
- }
- $output[] = [
- "id" => $location->id,
- "name" => $location->name,
- "icon" => $icon,
- "latitude" => (float) $location->latitude,
- "longitude" => (float) $location->longitude,
- "archived" => $location->isArchived()
- ];
- }
- JSON::success([
- "locations" => $output
- ]);
- break;
- }
|