<?php
class auszugversand {
    var $id;
    var $datum;
    var $auszugname;
    var $startdate;
    var $enddate;
    var $u18;
    var $wechsler;
    var $versand;
    var $plusnurverfaller;
    var $nobalance;
    var $anzahl;

    function __construct ($id = 0) {
        if ($id) {
          $query = "SELECT * FROM auszugversandlog
                    WHERE pkey = $id";
          $result = dbQuery($query) or error("Cannot read Versandlog: " . dbError());
          $row = dbFetchRow($result);
              $this->id = $row['pkey'];
              $this->datum = $row['datum'];
              $this->auszugname = $row['auszugname'];
              $this->startdate = $row['startdate'];
              $this->enddate = $row['enddate'];
              $this->u18 = $row['u18'];
              $this->wechsler = $row['wechsler'];
              $this->versand = $row['versand'];
              $this->plusnurverfaller = $row['plusnurverfaller'];
              $this->nobalance = $row['nobalance'];
              $this->anzahl = $row['anzahl'];
          }
          if ($result) {
              dbFreeResult($result);
          }
          return $this;
    }

    function delete() {
        if (! $this->id) {
            return;
        }
        $query = "DELETE FROM auszugversandlog WHERE pkey = " . $this->id;
        dbQuery($query) or error("Cannot read Versandlog: " . dbError());
    }

    function readauszuege () {
        $query = "SELECT pkey FROM auszugversandlog
                  WHERE 1
                  ORDER BY datum DESC";
        $result = dbQuery($query) or error("Cannot read Versandlog: " . dbError());
        $auszuege = array();
        while($row = dbFetchRow($result)) {
            $id = $row['pkey'];
            $auszuege[] = new auszugversand($id);
        };
        return $auszuege;
    }

    function logauszug() {
        $this->datum = date("Y-m-d H:i:s", time());
        $query = "INSERT INTO auszugversandlog 
                  SET datum = '" . $this->datum . "',
                      auszugname = '" . $this->auszugname . "', 
                      startdate = '" . $this->startdate . "',
                      enddate = '" . $this->enddate . "', 
                      u18 = '" . $this->u18 . "',
                      wechsler = '" . $this->wechsler . "',
                      versand = '" . $this->versand . "',
                      anzahl = '" . $this->anzahl . "',
                      nobalance = '" . $this->nobalance . "',
                      plusnurverfaller = '" . $this->plusnurverfaller . "'";
        dbQuery($query) or error("Can't insert: $query" . dbError());
    }
}
