locations.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. Core::addScript("public/js/app-locations.js");
  3. Core::addBreadcrumb("/account", "Account");
  4. Core::addBreadcrumb("/account/locations", "Locations");
  5. $customer = Customer::getForAdmin();
  6. if(!$customer) throw new Exception("You do not have permission to access this page.");
  7. $page_title = "$customer->name Locations";
  8. Core::addBreadcrumb("/account/locations?customer_id=$customer->id", $page_title);
  9. $nvp = ["customer_id" => $customer->id];
  10. $id = http::value("id", "int");
  11. $internal_id = http::value("internal_id", "trim");
  12. $name = http::value("name", "trim");
  13. if($id) $nvp["id"] = $id;
  14. if($internal_id) $nvp["internal_id"] = db::escape($internal_id);
  15. if($name) $nvp["name"] = (new Constraint("CONTAINS"))->setValues(db::escape($name));
  16. $sort = http::value("sort");
  17. switch($sort) {
  18. case "last_added":
  19. $query_sort = "id";
  20. $order = "desc";
  21. break;
  22. default:
  23. $query_sort = "name";
  24. $order = "asc";
  25. break;
  26. }
  27. $locations = Location::query($nvp, ["sort" => $query_sort, "order" => $order]);
  28. $filter_count = count($nvp) - 1;
  29. View::includeOnce("header", compact("page_title"));
  30. View::include("locations", compact("customer", "filter_count", "locations"));
  31. View::includeOnce("footer");
  32. ?>