#include <infocon.style>
#include "shop.inc"

<page func=InfoCon title="Online Shop">

<h3><font face="Helvetica,Arial">Offene Aufträge</font></h3>
<table width=100% border=0 cellpadding=0 cellspacing=0>
<tr bgcolor="<colh>">
  <th width=5%><font face="Helvetica,Arial">Nr.</font></th>
  <th width=15%><font face="Helvetica,Arial">Auftrag</font></th>
  <th width=15%><font face="Helvetica,Arial">Datum</font></th>
  <th width=55%><font face="Helvetica,Arial">Kunde</font></th>
  <th width=10%><font face="Helvetica,Arial">Status</font></th>
</tr>

<status>
<?
  $cd = "<cold>";
  $cn = "<coln>";

  $tline = "<tr bgcolor=\"%s\"><td align=\"right\"><font face=\"Helvetica,Arial\">%d.&nbsp;&nbsp;</font></td>"
          ."<td><font face=\"Helvetica,Arial\"><a href=\"dispatch.php3?dispatch=%d\">%d</a></font></td>"
	  ."<td><font face=\"Helvetica,Arial\">%s</font></td>"
          ."<td><font face=\"Helvetica,Arial\"><a href=\"customer.php3?customer=%d\">%s</a></font></td>"
	  ."<td><font face=\"Helvetica,Arial\">%s</font></td></tr>";

  $dbh = dbconnect();
  $sth = dbquery ($dbh, "SET DateStyle = 'ISO'");
  $sth = dbquery ($dbh, "SELECT dispatch.dispatch,dispatch.date,status.status,customer.customer,"
		       ."customer.company,customer.firstname,customer.lastname "
		       ."FROM dispatch,status,customer "
		       ."WHERE dispatch.dispatch = status.dispatch AND dispatch.customer = customer.customer "
		       ."ORDER BY dispatch.date,dispatch.dispatch,status.status DESC");

  $color = $cd;
  $dispatch = 0;
  $nr = 0;
  for ($i=0; $i < pg_NumRows ($sth); $i++) {
    $row = pg_fetch_array ($sth, $i);
    if ($row['dispatch'] != $dispatch) {
      $dispatch = $row['dispatch'];
      if (($row['status'] != <st_paid>) && ($row['status'] != <st_cancel>)) {
        $nr++;
	$color = $color == $cd?$cn:$cd;
	$date = explode (" ", $row['date']);
	$date = explode ("-", $date[0]);
	$date = sprintf ("%d.%d.%d", $date[2], $date[1], $date[0]);

	if (strlen ($row['company']) > 0) {
	  $customer = $row['company'];
	} else {
	  $customer = $row['firstname'] . " " . $row['lastname'];
	}

	printf ($tline, $color, $nr,
	        $row['dispatch'], $row['dispatch'], $date, $row['customer'], $customer, $status[$row['status']]);
      }
    }
  }

?>
</table>

</page>

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