#include <infodrom.style>
#include "zeitungen.inc"

<page func="Infodrom Oldenburg" title="Zeitungen">

<table class="font height border" width=100% cellspacing=0 cellpadding=0>
<tr bgcolor=#<colh>>
<th width=5%>Nr.</th>
<th width=10%>Changed</th>
<th width=10%>Typ</th>
<th width=75%>Name, Stadt</th>
</tr>

<?
  $dbh = pg_pconnect ("<dbhost>", "<dbport>", "<dbname>")
	       or die("Unable to connect to SQL server");

  pg_exec ($dbh, "SET DateStyle = 'ISO'") or die("Datenbank-Abfrage!");

  $query = "SELECT type,changed,name,city,oid FROM zeitungen ";

  $where = array ('deleted IS false');
  if ($_POST[key]) {
    $where[] = "(name ~* '$_POST[key]' OR url ~* '$_POST[key]')";
  }
  if ($_POST[city]) {
    $where[] = "city ~* '$_POST[city]'";
  }
  if ($_POST["class"]) {
    if (($_POST["class"] == "tag") || ($_POST["class"] == "woche")) {
      $where[] = sprintf("type = '%s' OR type = 'u%s'", $_POST["class"], $_POST["class"]);
    } else {
      $where[] = sprintf("type = '%s'", $_POST["class"]);
    }
  }

  if ($where) {
    $query .= " WHERE " . implode ($where, " AND ");
  }

#   if ($key) {
#     $query .= " WHERE name ~* '$key' OR url ~* '$key'";
#     if ($city) {
# 	$query .= " AND city = '$city'";
#     }
#   } elseif ($city) {
# 	$query .= " WHERE city = '$city'";
#   }
  $query .= " ORDER BY name,changed";
  $sth = pg_exec ($dbh, $query) or die("Datenbank-Abfrage!");

  $ztype['tag'] = "Tag";
  $ztype['utag'] = "Tag";
  $ztype['woche'] = "Woche";
  $ztype['uwoche'] = "Woche";
  $ztype['monat'] = "Monat";
  $ztype['comp'] = "Computer";
  $ztype['misc'] = "Misc";
  $ztype['search'] = "Info";

  $color = "<coln>";
  for ($nr=0; $nr < pg_NumRows ($sth); $nr++) {
    $row = pg_fetch_array ($sth, $nr);
    $date = explode (" ", $row['changed']);
    $date = explode ("-", $date[0]);
    $date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);
    $color = $color == "<coln>"?"<cold>":"<coln>";

    printf ("<tr bgcolor=\"#%s\"><td align=\"right\">%d</td>", $color, $nr+1);
    printf ("<td align=\"right\">%s</td>", $date);
    printf ("<td align=\"center\">%s</td>", $ztype[$row['type']]);
    printf ("<td><a href=\"edit.php?oid=%d\">%s</a>, %s</td></tr>",
      $row['oid'], $row['name'], $row['city']);
  }
?>

</table>


<h3>Neue Anfrage</h3>
<listform>
<infodromlink>
</page>

# Local variables:
# mode: text
# mode: auto-fill
# mode: iso-accents
# end:
