Ver Fonte

Fix filters on "Locations" page

Alan Lam há 4 anos atrás
pai
commit
4f04e8d31c
1 ficheiros alterados com 20 adições e 8 exclusões
  1. 20 8
      controllers/locations.php

+ 20 - 8
controllers/locations.php

@@ -41,38 +41,44 @@ $include_closed = (int) http::value("include_closed");
 
 $filter_count = 0;
 
+$where_strings = [];
+
 if($id) {
-	$nvp["id"] = $id;
+	$where_strings[] = "`location`.`id`='$id'";
 	$filter_count++;
 }
 
 if($ids) {
-	$nvp["id"] = $ids;
+	$where_strings[] = sprintf("`location`.`id` IN (%s)", implode(",", $ids));
 }
 
 if($internal_id) {
-	$nvp["internal_id"] = Constraint::contains($internal_id);
+	$where_strings[] = sprintf("`location`.`internal_id` LIKE '%%%s%%'", DB::escape($internal_id));
 	$filter_count++;
 }
 
 if($name) {
-	$nvp["name"] = Constraint::contains($name);
+	$where_strings[] = sprintf("`location`.`name` LIKE '%%%s%%'", DB::escape($name));
 	$filter_count++;
 }
 if($legal_entity_name) {
-	$nvp["legal_entity_name"] = Constraint::contains($legal_entity_name);
+	$where_strings[] = sprintf("`location`.`legal_entity_name` LIKE '%%%s%%'", DB::escape($legal_entity_name));
 	$filter_count++;
 }
 
 if($include_archived) {
-	unset($nvp["archived"]);
 	$filter_count++;
 }
+else {
+	$where_strings[] = "`location`.`archived`='0'";
+}
 
 if($include_closed) {
-	unset($nvp["closed"]);
 	$filter_count++;
 }
+else {
+	$where_strings[] = "`location`.`closed`='0'";
+}
 
 $sort = http::value("sort");
 switch($sort) {
@@ -97,12 +103,18 @@ switch($sort) {
 		break;
 }
 
+$where_string = "";
+if($where_strings) {
+	$where_string = "AND " . implode(" AND ", $where_strings);
+}
+
+
 [$date_start, $date_end] = $customer->getYearCycleDates();
 
 $sql = "SELECT `location`.*, COUNT(`test`.`id`) AS `test_count`, SUM(IF(`test`.`retest` = 1, 1, 0)) AS `retest_count` 
 	FROM `location` 
     LEFT JOIN `test` ON `test`.`location_id`=`location`.`id` AND `dts_start` BETWEEN '$date_start' AND '$date_end' 
-	WHERE `customer_id`='$customer->id' GROUP BY `location`.`id`
+	WHERE `customer_id`='$customer->id' $where_string GROUP BY `location`.`id`
 	ORDER BY $query_sort $order
 ";