locations.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. $sorts = [
  8. "name" => "Name",
  9. "last-added" => "Last Added",
  10. "internal-id" => "Internal ID",
  11. ];
  12. $page_title = "$customer->name Locations";
  13. Core::addBreadcrumb("/account/locations?customer_id=$customer->id", $page_title);
  14. $nvp = ["customer_id" => $customer->id];
  15. $id = http::value("id", "int");
  16. $internal_id = http::value("internal_id", "trim");
  17. $name = http::value("name", "trim");
  18. if($id) $nvp["id"] = $id;
  19. if($internal_id) $nvp["internal_id"] = db::escape($internal_id);
  20. if($name) $nvp["name"] = (new Constraint("CONTAINS"))->setValues(db::escape($name));
  21. $sort = http::value("sort");
  22. switch($sort) {
  23. case "last-added":
  24. $query_sort = "id";
  25. $order = "desc";
  26. break;
  27. default:
  28. $query_sort = "name";
  29. $order = "asc";
  30. break;
  31. }
  32. $locations = Location::query($nvp, ["sort" => $query_sort, "order" => $order]);
  33. if($sort == "internal-id") {
  34. usort($locations, function($a, $b) {
  35. return strnatcasecmp($a->internal_id, $b->internal_id);
  36. });
  37. }
  38. $filter_count = count($nvp) - 1;
  39. View::includeOnce("header", compact("page_title"));
  40. View::include("locations", compact("customer", "filter_count", "sorts", "sort", "locations"));
  41. View::includeOnce("footer");
  42. ?>