Added support for a year and a city
authorJoey Schulze <joey@infodrom.org>
Wed, 18 Oct 2006 13:07:25 +0000 (13:07 +0000)
committerJoey Schulze <joey@infodrom.org>
Wed, 18 Oct 2006 13:07:25 +0000 (13:07 +0000)
src/Infodrom/events/find.wml

index c0f0a87..ade18e5 100644 (file)
   pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");
 
   $query = "SELECT $event_cols FROM events WHERE ";
+
+  $where = '';
+
+  if (strlen ($city)) {
+    if (strlen ($where)) $where .= "AND ";
+    $where .= sprintf ("city = '%s' ", $city);
+  }
+
+  if (strlen ($country)) {
+    if (strlen ($where)) $where .= "AND ";
+    $where .= sprintf ("country = '%s' ", $country);
+  }
+
+  if (strlen ($year)) {
+    if (strlen ($where)) $where .= "AND ";
+    $where .= sprintf ("( start >= %d AND start < %d ) ", $year, (integer)$year + 1);
+  }
+
   if (strlen ($key)) {
-    $where = sprintf ("name ~* '%s' OR city ~* '%s' OR url ~* '%s' OR comment ~* '%s' ",
-                    addslashes ($key), addslashes ($key), addslashes ($key), addslashes ($key));
-    if (strlen ($country)) {
-      $where = sprintf ("country = '%s' AND ( %s ) ",
-                       addslashes ($country), $where);
-    }
-  } else {
-    if (strlen ($country)) {
-      $where = sprintf ("country = '%s' ", addslashes ($country));
+    if (strlen ($where)) $where .= "AND ";
+    if (strlen ($city) || strlen ($country)) {
+      $where = sprintf ("( name ~* '%s' OR url ~* '%s' OR comment ~* '%s' ) ",
+                      addslashes ($key), addslashes ($key), addslashes ($key));
     } else {
-      $where = '';
-      echo "<h3>Empty search?  Euh?</h3>";
+      $where = sprintf ("( name ~* '%s' OR city ~* '%s' OR url ~* '%s' OR comment ~* '%s' ) ",
+                      addslashes ($key), addslashes ($key), addslashes ($key), addslashes ($key));
     }
   }
+  if (!strlen ($where)) {
+    echo "<h3>Empty search?  Euh?</h3>";
+  }
   $query .= $where . " ORDER BY start,name";
 
   if (strlen ($where)) {