Source for file class.BUCHUNGEN.php

Documentation is available at class.BUCHUNGEN.php

  1. <?php
  2.  
  3. /**
  4.  * Stellt die Verbindung zur Datenbank 'buchungen' her.
  5.  * Stellt Methoden zum Einfügen, Löschen und Bestätigen von Buchungen zur
  6.  *
  7.  * @author Kay Koch
  8.  * @package src
  9.  * @since 1.12.04
  10.  * @subpackage foundation_tables
  11.  * @version 1
  12.  */
  13.  
  14. if (version_compare(PHP_VERSION'5')) {
  15.     die('This file was generated for PHP 5');
  16. }
  17.  
  18. /**
  19.  * Basisklasse aller Klassen mit Datenbankzugriff.
  20.  *
  21.  * stellt Methoden und Objekte zur Fehlermeldung und zum Datenbankzugriff zur
  22.  *
  23.  * @author Kay Koch
  24.  * @since 1.12.04
  25.  * @version 1.1
  26.  */
  27. require_once ('src/foundation/tables/class.PARENTTABLES.php');
  28.  
  29. /* user defined includes */
  30. // section -64--88-122--2-10f41e9:1009dd996d0:-7fbe-includes begin
  31. // section -64--88-122--2-10f41e9:1009dd996d0:-7fbe-includes end
  32.  
  33. /* user defined constants */
  34. // section -64--88-122--2-10f41e9:1009dd996d0:-7fbe-constants begin
  35. // section -64--88-122--2-10f41e9:1009dd996d0:-7fbe-constants end
  36.  
  37. /**
  38.  * Stellt die Verbindung zur Datenbank 'buchungen' her.
  39.  * Stellt Methoden zum Einfügen, Löschen und Bestätigen von Buchungen zur
  40.  *
  41.  * @access public
  42.  * @author Kay Koch
  43.  * @package src
  44.  * @since 1.12.04
  45.  * @subpackage foundation_tables
  46.  * @version 1
  47.  */
  48.     // --- ATTRIBUTES ---
  49.  
  50.     
  51.     /**
  52.      * Beinhaltet den Datenbanknamen (buchungen)
  53.      *
  54.      * @access protected
  55.      * @var string 
  56.      */
  57.     protected $dbTableName'buchungen';
  58.  
  59.     /**
  60.      * Array mit Daten der (nicht) bestätigten Buchung
  61.      *
  62.      * @access private
  63.      * @var array 
  64.      */
  65.     private static $dataarray ();
  66.  
  67.     // --- OPERATIONS ---
  68.  
  69.     
  70.     /**
  71.      * Fügt einen neue Datensatz in die Datenbank ein
  72.      *
  73.      * @access public
  74.      * @author Kay Koch, <kay.koch@gmx.de>
  75.      * @param array 
  76.      * @return boolean 
  77.      */
  78.     public function insertBuchung($buchung{
  79.         $returnValue= (bool) false;
  80.  
  81.         // section -64--88-122--2-10f41e9:1009dd996d0:-7fad begin
  82.         $buchung['pwd']$this->createPWD()// Password erstellen
  83.         $sql"INSERT IGNORE INTO $this->dbTableName
  84.                                 SET see_id = '$buchung['see_id'"',
  85.                                     name = '" $buchung['name'"',
  86.                                     vorname = '" $buchung['vorname'"',
  87.                                     email = '" $buchung['email'"',
  88.                                     telefon = '" $buchung['telefon'"',
  89.                                     verein_nr = '" $buchung['verein_nr'"',
  90.                                     brevet = '" $buchung['brevet'"',
  91.                                     datum = '" $buchung['datum'"',
  92.                                     stunde = '" $buchung['stunde'"',
  93.                                     anzahl = " $buchung['anzahl'",
  94.                                     anzahlZahler = " $buchung['anzahlZahler'",
  95.                                     orderDatum = now(),
  96.                                     pwd = '" $buchung['pwd'"'";
  97.         try {
  98.             if (!$buchung['buch_id']$this->insert($sql)) // Buchung eintragen
  99.                 throw new Exception(8);
  100.             // Wenn weniger als 2 Plätze übrigbleiben, alle abziehen
  101.             if (($buchung['restPlaetze'$buchung['anzahl']2)
  102.                 $buchung['anzahl']$buchung['restPlaetze'];
  103.             // Frei Plätze aktualisieren
  104.             if (!$this->oNF->decrease($buchung['see_id']$buchung['datum']$buchung['stunde']$buchung['anzahl']))
  105.                 throw new Exception(9);
  106.             // PDF erstellen
  107.             if (!$this->oPDF->createUserPDF($buchung$this->getSea()))
  108.                 throw new Exception(10);
  109.             // Mail verschicken
  110.             $oMailsrc_mail_MAIL :: singleton();
  111.             if (!$oMail->sendUserMail($buchung$this->getSea()))
  112.                 throw new Exception(11);
  113.             $returnValuetrue;
  114.         catch (Exception $e{
  115.             src_tools_ERROR :: setError($e__METHOD__);
  116.         }
  117.         // section -64--88-122--2-10f41e9:1009dd996d0:-7fad end
  118.  
  119.         return (bool) $returnValue;
  120.     }
  121.  
  122.     /**
  123.      * Markiert eine Buchung als abgerufen
  124.      *
  125.      * @access public
  126.      * @author Kay Koch, <kay.koch@gmx.de>
  127.      * @param int 
  128.      * @param string 
  129.      * @return boolean 
  130.      */
  131.     public function setAsTaken($buch_id$pwd{
  132.         $returnValue= (bool) false;
  133.  
  134.         // section -64--88-122--2-10f41e9:1009dd996d0:-7fa8 begin
  135.         try {
  136.             if (!isset (self :: $data[$buch_id]))
  137.                 throw new Exception(12);
  138.             if (!(self :: $data[$buch_id]['pwd'== $pwd))
  139.                 throw new Exception(12);
  140.             if (!self :: $data[$buch_id]['istAbgeholt']// Buchung ist noch nicht abgeholt
  141.                 $sql"UPDATE $this->dbTableName SET istAbgeholt='1' WHERE buch_id = '$buch_idAND pwd = '$pwdLIMIT 1";
  142.                 if (!$this->update($sql)) // als abgeholt markieren
  143.                     throw new Exception(13);
  144.             }
  145.             self :: $data[$buch_id]['istAbgeholt']1;
  146.             $returnValuetrue;
  147.         catch (Exception $e{
  148.             src_tools_ERROR :: setError($e__METHOD__);
  149.         }
  150.         // section -64--88-122--2-10f41e9:1009dd996d0:-7fa8 end
  151.  
  152.         return (bool) $returnValue;
  153.     }
  154.  
  155.     /**
  156.      * liefert im Erfolgsfall TRUE
  157.      *
  158.      * @access public
  159.      * @author Kay Koch, <kay.koch@gmx.de>
  160.      * @param int 
  161.      * @param string 
  162.      * @return boolean 
  163.      */
  164.     public function deleteBuchung($buch_id$pwd{
  165.         $returnValue= (bool) false;
  166.  
  167.         // section -64--88-122--2-933bcb:100f60e4e57:-7ffc begin
  168.         try {
  169.             if (!isset (self :: $data[$buch_id]))
  170.                 throw new Exception(12);
  171.             if (!(self :: $data[$buch_id]['pwd'== $pwd))
  172.                 throw new Exception(12);
  173.             $this->cleanEntries(self :: $data[$buch_id])// Plätze freimachen und PDF löschen
  174.             $sql"DELETE FROM $this->dbTableName WHERE buch_id = '$buch_idAND pwd = '$pwd'";
  175.             if (!$this->delete($sql)) // Buchung löschen
  176.                 throw new Exception(14);
  177.             unset (self :: $data[$buch_id])// Buchung aus array löschen
  178.             $returnValuetrue;
  179.         catch (Exception $e{
  180.             src_tools_ERROR :: setError($e__METHOD__);
  181.         }
  182.         // section -64--88-122--2-933bcb:100f60e4e57:-7ffc end
  183.  
  184.         return (bool) $returnValue;
  185.     }
  186.  
  187.     /**
  188.      * säubert Datenbank von nicht abgeholten Buchungen
  189.      *
  190.      * @access public
  191.      * @author Kay Koch, <kay.koch@gmx.de>
  192.      * @return boolean 
  193.      */
  194.     public function cleanBuchungen($allfalse{
  195.         $returnValue= (bool) false;
  196.  
  197.         // section -64--88-122--2-933bcb:100f60e4e57:-7f8f begin
  198.         $whereit($all"" "AND now() > DATE_ADD(orderDatum, INTERVAL 1 DAY) ";
  199.         $sql"DELETE FROM $this->dbTableName WHERE istAbgeholt ='0' $whereit;
  200.         $this->delete($sql)// Buchungen löschen
  201.         $this->updateData();
  202.         // section -64--88-122--2-933bcb:100f60e4e57:-7f8f end
  203.  
  204.         return (bool) $returnValue;
  205.     }
  206.  
  207.     /**
  208.      * erstellt ein Passwort
  209.      *
  210.      * @access private
  211.      * @author Kay Koch, <kay.koch@gmx.de>
  212.      * @return string 
  213.      */
  214.     private function createPWD({
  215.         $returnValue= (string) '';
  216.  
  217.         // section -64--88-122--2-1328c7a:1027db0d532:-7ff1 begin
  218.         $pwdLength5// Länge des Passwortes
  219.         while ($pwdLength-- > 0{
  220.             $returnValue .= chr(rand(97122));
  221.         }
  222.         // section -64--88-122--2-1328c7a:1027db0d532:-7ff1 end
  223.  
  224.         return (string) $returnValue;
  225.     }
  226.  
  227.     /**
  228.      * liefert eine Buchung
  229.      *
  230.      * @access public
  231.      * @author Kay Koch, <kay.koch@gmx.de>
  232.      * @param void 
  233.      * @param string 
  234.      * @return array 
  235.      */
  236.     public function getBuchung($buch_id$pwd{
  237.         $returnValuearray ();
  238.  
  239.         // section -64--88-122--2-1328c7a:10292f82497:-7ff9 begin
  240.         if (isset (self :: $data[$buch_id]AND self :: $data[$buch_id]['pwd'== $pwd)
  241.             $returnValueself :: $data[$buch_id];
  242.         // section -64--88-122--2-1328c7a:10292f82497:-7ff9 end
  243.  
  244.         return (array) $returnValue;
  245.     }
  246.  
  247.     /**
  248.      * nichtabgeholte Buchungen werden aus Datenbank gelöscht
  249.      *
  250.      * @access private
  251.      * @author Kay Koch, <kay.koch@gmx.de>
  252.      * @param array 
  253.      * @return void 
  254.      */
  255.     private function cleanEntries($buchung{
  256.         // section -64--88-122--2-1328c7a:10297cab611:-7ff7 begin
  257.         // Plätze wieder frei machen
  258.         $this->oNF->increase($buchung['see_id']$buchung['datum']$buchung['stunde']$buchung['anzahl']);
  259.         // PDF-Dokument löschen
  260.         $this->oPDF->deleteUserPDF($buchung['buch_id'$buchung['pwd']);
  261.         // section -64--88-122--2-1328c7a:10297cab611:-7ff7 end
  262.     }
  263.  
  264.     /**
  265.      * liefert den Pfad eines PDF-Dokuments aufgrund der Buch_id
  266.      *
  267.      * @access public
  268.      * @author Kay Koch, <kay.koch@gmx.de>
  269.      * @param string 
  270.      * @return string 
  271.      */
  272.     public function getPDFLocation($filename{
  273.         $returnValue= (string) '';
  274.  
  275.         // section -64--88-122--2-1328c7a:102988386a1:-7ffe begin
  276.         try {
  277.             $returnValue$this->oPDF->getPDFPath($filename);
  278.             if (!file_exists($returnValue))
  279.                 throw new Exception(17);
  280.         catch (Exception $e{
  281.             src_tools_ERROR :: setError($e__METHOD__);
  282.         }
  283.         // section -64--88-122--2-1328c7a:102988386a1:-7ffe end
  284.  
  285.         return (string) $returnValue;
  286.     }
  287.  
  288.     /**
  289.      * liefert alle Buchungen innerhalb der nächsten $interval Tage
  290.      *
  291.      * @access public
  292.      * @author Kay Koch, <kay.koch@gmx.de>
  293.      * @param int 
  294.      * @return array 
  295.      */
  296.     public function getOldBuchungen({
  297.         $returnValuearray ();
  298.  
  299.         // section -64--88-122--2-1328c7a:102a6f94cac:-7fe7 begin
  300.         // auslesen aller alten Buchungen
  301.         $weekLimit$this->getFlags()->getWhereWeekLimit();
  302.         $sql"SELECT * FROM " $this->dbTableName . $weekLimit " AND istAbgeholt='1' ORDER by see_id,datum ASC";
  303.         $arrOldBuchungen$this->select($sql);
  304.         foreach ($arrOldBuchungen as $buchung{
  305.             $buchung['name']substr($buchung['name'"," $buchung['vorname']016)// Länge auf 18 Buchstaben begrenzen
  306.             $returnValue[$buchung['see_id']][$buchung['datum']][$buchung['stunde']][]array (
  307.                 "name" => $buchung['name'],
  308.                 "verein" => $buchung['verein_nr'],
  309.                 "anzahl" => $buchung['anzahl'],
  310.                 "anzahlZahler" => $buchung['anzahlZahler']
  311.             );
  312.         }
  313.         // section -64--88-122--2-1328c7a:102a6f94cac:-7fe7 end
  314.  
  315.         return (array) $returnValue;
  316.     }
  317.  
  318.     /**
  319.      * liefert einen link zum pdf-Dokument
  320.      *
  321.      * @access public
  322.      * @author Kay Koch, <kay.koch@gmx.de>
  323.      * @param string 
  324.      * @return string 
  325.      */
  326.     public function getPDFLink($filename{
  327.         $returnValue= (string) '';
  328.  
  329.         // section -64--88-122--2-5a4368f4:103efc100ac:-7fad begin
  330.         try {
  331.             $filepath$this->oPDF->getPDFPath($filename);
  332.             if (!file_exists($filepath))
  333.                 throw new Exception(17);
  334.             $returnValue"<a href='$filepath'>Link zur Reservierung</a>";
  335.         catch (Exception $e{
  336.             src_tools_ERROR :: setError($e__METHOD__);
  337.         }
  338.         // section -64--88-122--2-5a4368f4:103efc100ac:-7fad end
  339.  
  340.         return (string) $returnValue;
  341.     }
  342.  
  343.     /**
  344.      * löscht alte Buchungen
  345.      *
  346.      * @access public
  347.      * @author Kay Koch, <kay.koch@gmx.de>
  348.      * @param int 
  349.      * @return boolean 
  350.      */
  351.     public function deleteOldBuchungen({
  352.         $returnValue= (bool) false;
  353.  
  354.         // section -64--88-122--2--6176e79b:103fa06a375:-7fbd begin
  355.         // lädt buch_id und Passwort aller alten Buchungen bis zum nächsten Update
  356.         $weekLimit$this->getFlags()->getWhereWeekLimit();
  357.         $sql"SELECT buch_id,pwd FROM " $this->dbTableName . $weekLimit;
  358.         $arrOldBuchungen$this->select($sql);
  359.         // löscht die pdf-Dokumente der alten Buchungen
  360.         foreach ($arrOldBuchungen as $oldBuchung{
  361.             $this->oPDF->deleteUserPDF($oldBuchung['buch_id'$oldBuchung['pwd']);
  362.         }
  363.         // löscht alle alten, abgeholten  Buchungen bis zum nächsten Update
  364.         #$sql = "DELETE FROM " . $this->dbTableName . $weekLimit;
  365.         #if ($this->delete($sql))
  366.         #    $returnValue = true;
  367.         // section -64--88-122--2--6176e79b:103fa06a375:-7fbd end
  368.  
  369.         return (bool) $returnValue;
  370.     }
  371.     /**
  372.      * aktualisiert die Daten im gegenwertigen Objekt
  373.      *
  374.      * @access public
  375.      * @author Kay Koch, <kay.koch@gmx.de>
  376.      * @return boolean 
  377.      */
  378.     public function updateData({
  379.         $returnValue= (bool) false;
  380.  
  381.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7f9c begin
  382.         $sql"SELECT * FROM  $this->dbTableName";
  383.         self :: $data$this->select($sqltrue"buch_id");
  384.         // section -64--88-122--2--3d9a0b58:1040f000f1b:-7f9c end
  385.  
  386.         return (bool) $returnValue;
  387.     }
  388.  
  389.     /**
  390.      * Konstruktor
  391.      *
  392.      * lädt alle Buchungen
  393.      * erstellt Objekte der Klassen
  394.      *   nochfrei
  395.      *   mail
  396.      *   pdf
  397.      *
  398.      * @access public
  399.      * @author Kay Koch, <kay.koch@gmx.de>
  400.      * @return void 
  401.      */
  402.     public function __construct({
  403.         // section -64--88-122--2-7471698e:1046ab3b89c:-7fe7 begin
  404.         parent :: __construct();
  405.         if (empty (self :: $data))
  406.             $this->updateData();
  407.         $this->oNFnew src_foundation_tables_NOCHFREI;
  408.         $this->oPDFnew src_pdf_MYFPDF;
  409.         // section -64--88-122--2-7471698e:1046ab3b89c:-7fe7 end
  410.     }
  411.  
  412.     /**
  413.      * Fügt eine Blockade mit veringerten Informationen ein
  414.      *
  415.      * @access public
  416.      * @author Kay Koch, <kay.koch@gmx.de>
  417.      * @param array 
  418.      * @return boolean 
  419.      */
  420.     private function insertBlockade($blockade{
  421.         $returnValue= (bool) false;
  422.         // section -64--88-0-1-1328c7a:105f3567fa3:-7ff7 begin
  423.         $sql"INSERT IGNORE INTO $this->dbTableName
  424.                                 SET see_id = '$blockade['see_id'"',
  425.                                     name = '" $blockade['name'"',
  426.                                     datum = '" $blockade['datum'"',
  427.                                     stunde = '" $blockade['stunde'"',
  428.                                     anzahl = " $blockade['anzahl'",
  429.                                     anzahlZahler = " $blockade['anzahlZahler'",
  430.                                     verein_nr = '" $blockade['verein_nr'"',
  431.                                     istAbgeholt ='1',
  432.                                     block_id = '" $blockade['block_id'"',
  433.                                     orderDatum = now()";
  434.         try {
  435.             if (!$buchung['buch_id']$this->insert($sql)) // Buchung eintragen
  436.                 throw new Exception(8);
  437.             $returnValuetrue;
  438.         catch (Exception $e{
  439.             src_tools_ERROR :: setError($e__METHOD__);
  440.         }
  441.         // section -64--88-0-1-1328c7a:105f3567fa3:-7ff7 end
  442.  
  443.         return (bool) $returnValue;
  444.     }
  445.  
  446.     /**
  447.      * Erstellt Buchungen für eine Blockade
  448.      * in Abhängidkeit der Wiederholungsart
  449.      *
  450.      * @author kaykoch
  451.      * @access private
  452.      * @since 1 - 02.03.2007
  453.      * @uses blockDays Methode für tägliche Wiederholungen
  454.      * @uses blockWeekly Methode für wöchentliche Wiederholungen
  455.      * @uses insertBlockade Methode zum Einfügen der Blockade
  456.      * @param array $data Daten der Blockade
  457.      * @return boolean 
  458.      *
  459.      */
  460.     public function blockDates($data$resetfalse{
  461.         $returnValuefalse;
  462.         if ($reset{
  463.             $sql"DELETE FROM $this->dbTableName WHERE `block_id` = '$data['block_id'"';";
  464.             $returnValue$this->delete($sql);
  465.         else {
  466.             switch ($data['wiederholung']{
  467.                 case // Anzahl Tage
  468.                     $this->blockDays($data);
  469.                     break;
  470.                 case // wöchentlich
  471.                     $this->blockWeekly($data);
  472.                     break;
  473.                 default :
  474.                     $this->blockhours($data);;
  475.                     break;
  476.             }
  477.         }
  478.         return $returnValue;
  479.     }
  480.     /**
  481.      *  Wiederholungen, die eine Anzahl von Tagen stattfinden
  482.      *
  483.      * @author kaykoch
  484.      * @access private
  485.      * @since 1 - 02.03.2007
  486.      * @uses blockhours Methode für stündliche Wiederholungen
  487.      * @param array $data Daten der Blockade
  488.      * @return boolean 
  489.      *
  490.      */
  491.     private function blockDays($data{
  492.         $returnValuefalse;
  493.         $startDatum$data['datum'];
  494.         for ($k0$k $data['anzahlWiederholung']$k++{
  495.             $data['datum']src_tools_TIME :: addDays2SQL($startDatum$k);
  496.             $this->blockhours($data);
  497.         }
  498.         return $returnValue;
  499.     }
  500.     /**
  501.      *
  502.      * Wiederholungen, die wöchentlich stattfinden
  503.      *
  504.      * @author kaykoch
  505.      * @access private
  506.      * @since 1 - 02.03.2007
  507.      * @uses blockhours Methode für stündliche Wiederholungen
  508.      * @param array $data Daten
  509.      * @return boolean 
  510.      *
  511.      */
  512.     private function blockWeekly($data{
  513.         $returnValuefalse;
  514.         $data['datum'src_tools_TIME :: addDays2SQL($data['datum'],-7);
  515.         $endDatum $this->getSeen($data['see_id'])->saisonEnde;
  516.         while ($data['datum'$endDatum){
  517.             $data['datum'src_tools_TIME :: addDays2SQL($data['datum']7);
  518.             $this->blockhours($data);
  519.         }
  520.         return $returnValue;
  521.     }
  522.  
  523.     /**
  524.      *
  525.      * Wiederholungen, die mehrere Stunden stattfinden
  526.      *
  527.      * @author kaykoch
  528.      * @access private
  529.      * @since 1 - 02.03.2007
  530.      * @uses insertBlockade Methode zum Einfügen der Blockade
  531.      * @param array $data Daten
  532.      * @return boolean 
  533.      *
  534.      */
  535.     private function blockhours($data{
  536.         $returnValuefalse;
  537.         $startZeit= (int) substr($data['stunde']03)// Beginn der Blockade als Int
  538.             for ($i0$i $data['anzahlStunden']$i++{
  539.                 $data['stunde']src_tools_TIME :: formatHour($startZeit$i);
  540.                 $this->insertBlockade($data);
  541.             }
  542.         return $returnValue;
  543.     }
  544.  
  545.     /**
  546.      *
  547.      * liefert alle Buchungen, die aus Blockaden stammen
  548.      *
  549.      * wird kein Datum angegeben, werden alle Buchungen geliefert,
  550.      * die sich im für diesen See erlaubten Anmeldezeitraum
  551.      * befinden. Ansonsten nur die an diesem Datum
  552.      *
  553.      * @author kaykoch
  554.      * @access private
  555.      * @since 1 - 02.03.2007
  556.      * @param string $datum Datum der abzuliefernden Buchungen
  557.      * @return boolean 
  558.      *
  559.      */
  560.     public function getBlockedBuchungen($datum null){
  561.        $returnValue=array();
  562.        if($datum == null){
  563.           $datum src_tools_TIME::addDays2SQL($this->getFlags()->lastBackupDate,-6);
  564.           $endDatum src_tools_TIME::addDays2SQL($this->getFlags()->lastBackupDate,$this->getSea()->wochenImVorraus*7+1);
  565.        }else{
  566.           $endDatum $datum;
  567.        }
  568.        foreach (self::$data as $buchung){
  569.           if($buchung['block_id']==OR $buchung['datum'$datum OR $buchung['datum'$endDatum)
  570.               continue;
  571.           $returnValue[$buchung['see_id']][$buchung['datum']][$buchung['stunde']][$buchung;
  572.        }
  573.        return $returnValue;
  574.     }
  575.  
  576. /* end of class src_foundation_tables_BUCHUNGEN */
  577. ?>

Documentation generated on Sat, 24 Mar 2007 09:58:59 +0100 by phpDocumentor 1.3.1