public function getBestellungenByKundenID($kundenNr)
 {
     $sql = sprintf($this->query_getBestellungenByKundenID, $kundenNr);
     $DB_result = $this->dbm->query($sql);
     /*
      * array(10) { ["BestellNr"]=> string(1) "1" ["KundenNr"]=> string(1) "1"
      *      ["BestellDatum"]=> string(19) "2012-12-05 19:15:15" ["Name"]=> string(6) "Bartel"
      *      ["Vorname"]=> string(4) "Sven" ["eMail"]=> string(12) "*****@*****.**"
      *      ["TNr"]=> string(1) "3" ["menge"]=> string(1) "2"
      *      ["Bezeichnung"]=> string(11) "Zylinder A5" ["Preis"]=> string(5) "22.80" }
      *
      * */
     $bestellung = null;
     $result = array();
     while ($row = mysql_fetch_assoc($DB_result)) {
         if (empty($bestellung) || $bestellung->getBestellNr() != $row["BestellNr"]) {
             $bestellung = Bestellung::neu($row["BestellNr"], $row["KundenNr"], $row["BestellDatum"]);
             $pushen = true;
         }
         $bestellung->addArtikel(Teile::neu($row["TNr"], $row["Bezeichnung"], $row["Preis"], null, null, null, null), $row["menge"]);
         $bestellung->addDerKunde(Kunde::create($row["KundenNr"], $row["Name"], $row["Vorname"], $row["eMail"], null));
         if ($pushen) {
             array_push($result, $bestellung);
             $pushen = false;
         }
     }
     return $result;
 }
 function handleOrder()
 {
     $values = $_SESSION["ticketDataAddress"];
     $F = new Factory("Adresse");
     $values["land"] = ISO3166::getCountryToCode($values["land"]);
     $F->fill($values);
     $exists = $F->exists(true);
     if (!$exists) {
         $AdresseID = $F->store(false, false);
         $K = new Kunden();
         $Kappendix = $K->createKundeToAdresse($AdresseID, false, true);
     } else {
         $AdresseID = $exists->getID();
         $Kappendix = Kappendix::getKappendixToAdresse($AdresseID);
     }
     if ($_SESSION["ticketDataPayment"]["via"] == "debit") {
         $Kappendix->changeA("KappendixKontonummer", $_SESSION["ticketDataPayment"]["debitKontonummer"]);
         $Kappendix->changeA("KappendixBLZ", $_SESSION["ticketDataPayment"]["debitBlz"]);
         $Kappendix->changeA("KappendixKontoinhaber", $_SESSION["ticketDataPayment"]["debitInhaber"]);
         $Kappendix->changeA("KappendixEinzugsermaechtigung", "1");
         $Kappendix->changeA("KappendixEinzugsermaechtigungAltZBTB", "5");
         $Kappendix->changeA("KappendixSameKontoinhaber", "0");
     }
     if (!$exists) {
         $Kappendix->newMe(false);
     } else {
         $Kappendix->saveMe();
     }
     $zahlungsart = 6;
     if ($_SESSION["ticketDataPayment"]["via"] == "debit") {
         $zahlungsart = 1;
     }
     if ($_SESSION["ticketDataPayment"]["via"] == "transfer") {
         $zahlungsart = 5;
     }
     if ($_SESSION["ticketDataPayment"]["via"] == "paypal") {
         $zahlungsart = 7;
     }
     $orderIDs = array();
     foreach ($_SESSION["ticketDataSelection"] as $SeminarID => $anzahl) {
         if ($anzahl == 0) {
             continue;
         }
         $F = new Factory("STeilnehmer");
         $F->sA("STeilnehmerSeminarID", $SeminarID);
         $F->sA("STeilnehmerAdresseID", $AdresseID);
         $F->sA("STeilnehmerAngemeldetAm", time());
         $F->sA("STeilnehmerErwachsene", $anzahl);
         $F->sA("STeilnehmerZahlungsart", $zahlungsart);
         $STeilnehmerID = $F->store();
         $Tickets = array();
         foreach ($_SESSION["ticketDataTickets"] as $k => $v) {
             $ex = explode("_", $k);
             if (count($ex) != 3) {
                 continue;
             }
             if ($ex[1] != $SeminarID) {
                 continue;
             }
             if (!isset($Tickets[$ex[2]])) {
                 $Tickets[$ex[2]] = array();
             }
             $Tickets[$ex[2]][$ex[0]] = $v;
         }
         foreach ($Tickets as $ticket) {
             $F = new Factory("STeilnehmerTicket");
             $F->sA("STeilnehmerTicketSeminarID", $SeminarID);
             $F->sA("STeilnehmerTicketSTeilnehmerID", $STeilnehmerID);
             $F->sA("STeilnehmerTicketVorname", $ticket["Vorname"]);
             $F->sA("STeilnehmerTicketNachname", $ticket["Nachname"]);
             $F->sA("STeilnehmerTicketPosition", $ticket["Position"]);
             $F->sA("STeilnehmerTicketUnternehmen", $ticket["Unternehmen"]);
             $F->sA("STeilnehmerTicketEMail", $ticket["Email"]);
             if ($this->fromPOS) {
                 $F->sA("STeilnehmerTicketFirstSeen", time());
             }
             $F->store();
         }
         $S = new Seminar($SeminarID);
         $S->createRechnungen($STeilnehmerID);
         foreach ($S->createdGRLBMs as $GRLBM) {
             $Auftrag = new Auftrag($GRLBM->A("AuftragID"));
             $Auftrag->sendViaEmail($GRLBM->getID(), "", "", "", false);
             $B = new Bestellung(-1);
             $orderIDs[] = $B->createFromInvoice($GRLBM->A("AuftragID"), $GRLBM, "MMDB/Seminare/STeilnehmer", $STeilnehmerID);
         }
     }
     $_SESSION["ticketStep"] = 6;
     $_SESSION["ticketDataOrderIDs"] = $orderIDs;
 }