| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- 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");
- if($id) $nvp["id"] = $id;
- if($internal_id) $nvp["internal_id"] = db::escape($internal_id);
- if($name) $nvp["name"] = (new Constraint("CONTAINS"))->setValues(db::escape($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
- ];
- }
- JSON::success([
- "locations" => $output
- ]);
- break;
- }
|