| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?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,
- "archived" => 0,
- "closed" => 0
- ];
- $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");
- $include_archived = http::value("include_archived", "int");
- $include_closed = http::value("include_closed", "int");
- 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);
- if($include_archived) unset($nvp["archived"]);
- if($include_closed) unset($nvp["closed"]);
- $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;
- }
|