customer_ajax.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. JSON::header();
  3. $customer = Customer::get($id);
  4. if(!$customer) JSON::fail("Customer not found.");
  5. switch($action) {
  6. case "get-locations":
  7. $nvp = ["customer_id" => $customer->id];
  8. $id = http::value("id", "int");
  9. $internal_id = http::value("internal_id", "trim");
  10. $name = http::value("name", "trim");
  11. if($id) $nvp["id"] = $id;
  12. if($internal_id) $nvp["internal_id"] = db::escape($internal_id);
  13. if($name) $nvp["name"] = (new Constraint("CONTAINS"))->setValues(db::escape($name));
  14. $locations = Location::query($nvp, ["sort" => "name", "order" => "asc"]);
  15. $output = [];
  16. foreach($locations as $location) {
  17. $filename = Util::slug($customer->name);
  18. $icon = false;
  19. if(file_exists("public/img/markers/$filename.png")) {
  20. $icon = $filename . ".png";
  21. }
  22. $output[] = [
  23. "id" => $location->id,
  24. "name" => $location->name,
  25. "icon" => $icon,
  26. "latitude" => (float) $location->latitude,
  27. "longitude" => (float) $location->longitude
  28. ];
  29. }
  30. JSON::success([
  31. "locations" => $output
  32. ]);
  33. break;
  34. }