name); $sorts = [ "name" => "Name", "last-added" => "Last Added", "internal-id" => "Internal ID", ]; $page_title = "$customer->name Locations"; Core::addBreadcrumb("/account/locations?customer_id=$customer->id", $page_title); $nvp = [ "customer_id" => $customer->id, "archived" => 0, "closed" => 0, ]; $id = http::value("id", "int"); $ids = http::value("ids", "int"); $internal_id = http::value("internal_id", "trim"); $name = http::value("name", "trim"); $legal_entity_name = http::value("legal_entity_name", "trim"); $include_archived = (int) http::value("include_archived"); $include_closed = (int) http::value("include_closed"); $filter_count = 0; if($id) { $nvp["id"] = $id; $filter_count++; } if($ids) { $nvp["id"] = $ids; } if($internal_id) { $nvp["internal_id"] = Constraint::contains($internal_id); $filter_count++; } if($name) { $nvp["name"] = Constraint::contains($name); $filter_count++; } if($legal_entity_name) { $nvp["legal_entity_name"] = Constraint::contains($legal_entity_name); $filter_count++; } if($include_archived) { unset($nvp["archived"]); $filter_count++; } if($include_closed) { unset($nvp["closed"]); $filter_count++; } $sort = http::value("sort"); switch($sort) { case "last-added": $query_sort = "id"; $order = "desc"; break; default: $query_sort = "name"; $order = "asc"; break; } $locations = Location::query($nvp, ["sort" => $query_sort, "order" => $order]); if($sort == "internal-id") { usort($locations, function($a, $b) { return strnatcasecmp($a->internal_id, $b->internal_id); }); } $action = http::value("action"); if(!empty($action)) { switch($action) { case "export": if(!Core::$user->canAdmin()) throw new RuntimeException("You do not have permission to access this resource."); $export = new LocationCsvExport($locations); $export->export("$customer_slug-export.csv"); exit(); case "export-kml": $export = new LocationKmlExport($locations); $export->setCustomer($customer); $export->export("$customer_slug-export.kml"); exit; } } View::includeOnce("header", compact("page_title")); View::include("locations", compact("customer", "include_archived", "include_closed", "filter_count", "sorts", "sort", "locations")); View::include("modal_add_locations_to_project", compact("customer")); View::includeOnce("footer");