Source for file class.ADMINBLOCKADEN.php

Documentation is available at class.ADMINBLOCKADEN.php

  1. <?php
  2. /**
  3.  * Verwaltet die Adminitration der Datenbanktabelle 'blockaden'
  4.  *
  5.  * @author Kay Koch, <kay.koch@gmx.de>
  6.  * @package src
  7.  * @subpackage foundation_admin
  8.  */
  9. if (version_compare(PHP_VERSION'5')) {
  10.    die('This file was generated for PHP 5');
  11. }
  12. /**
  13.  * Parentklasse zur Administration der Tabellen
  14.  *
  15.  * @author Kay Koch, <kay.koch@gmx.de>
  16.  */
  17. require_once ('src/foundation/admin/class.PARENTADMIN.php');
  18. /**
  19.  * Interface zur Administration der Datenbank
  20.  *
  21.  * @author Kay Koch
  22.  * @since 06.2005
  23.  * @version 1.0
  24.  */
  25. require_once ('src/interfaces/interface.ADMININTERFACE.php');
  26. /* user defined includes */
  27. // section -64--88-122--2--78ecc2cb:103d1b5ef00:-7fc5-includes begin
  28. // section -64--88-122--2--78ecc2cb:103d1b5ef00:-7fc5-includes end
  29. /* user defined constants */
  30. // section -64--88-122--2--78ecc2cb:103d1b5ef00:-7fc5-constants begin
  31. // section -64--88-122--2--78ecc2cb:103d1b5ef00:-7fc5-constants end
  32.  
  33. /**
  34.  * Verwaltet die Adminitration der Datenbanktabelle 'blockaden'
  35.  *
  36.  * @access public
  37.  * @author Kay Koch, <kay.koch@gmx.de>
  38.  * @package src
  39.  * @subpackage foundation_admin
  40.  */
  41.    // --- ATTRIBUTES ---
  42.    
  43.    /**
  44.     * Objekt der aktellen Datenbankklasse
  45.     *
  46.     * @access private
  47.     * @var BLOCKADEN 
  48.     */
  49.    private $oBlock null;
  50.    /**
  51.     * Array mit den Feldnamen der aktuellen Datebank
  52.     *
  53.     * @access protected
  54.     * @var array 
  55.     */
  56.    protected $arrKeys = array ();
  57.    /**
  58.     * Name des Haupttemplates
  59.     *
  60.     * @access protected
  61.     * @var string 
  62.     */
  63.    protected $pageTemplate = '';
  64.  
  65.    /**
  66.     * Möglichkeiten, Daten zu blockieren
  67.     *
  68.     * @access protected
  69.     * @var array 
  70.     */
  71.    protected $arrKindOfBlocks = array (
  72.       "einmalig",
  73.       "wöchentlich",
  74.       "Anzahl Tage"
  75.    );
  76.  
  77.    protected $arrOldData = array ();
  78.    // --- OPERATIONS ---
  79.    
  80.    /**
  81.     * zeigt alle Einträge einer Tabelle
  82.     *
  83.     * @access public
  84.     * @author Kay Koch, <kay.koch@gmx.de>
  85.     * @return void 
  86.     */
  87.    public function show({
  88.       // section -64--88-122--2--6176e79b:103fa06a375:-7fad begin
  89.       if ($this->loginOK{
  90.          $this->todo "change";
  91.          $this->rows "";
  92.          $this->arrOldData = $this->oBlock->getRowByID();
  93.          foreach ($this->arrOldData as $this->data// alle Seen
  94.             $this->seename $this->getSeen($this->data['see_id'])->name;
  95.             $this->realstunde ($this->data['ganzerTag']"ganztägig" $this->data['stunde'];
  96.             $this->realstunde2 src_tools_TIME :: sqlT2realT($this->data['datum']);
  97.             $this->data['anzahlStunden'($this->data['ganzerTag']"" $this->data['anzahlStunden'];
  98.             $this->oVereine->setParams($this->data['verein_nr']);
  99.             $this->data['info'(!empty ($this->data['info'])) $this->oVereine->name ", " $this->data['info'$this->oVereine->name;
  100.             switch ($this->data['wiederholung']{
  101.                case // einmalig
  102.                   $this->wiederholung $this->arrKindOfBlocks[$this->data['wiederholung']] " (" src_tools_TIME :: sqlT2realT($this->data['datum']")";
  103.                   break;
  104.                case // wöchentlich
  105.                   $this->wiederholung $this->arrKindOfBlocks[$this->data['wiederholung']] " (" src_tools_TIME :: dayNr2dayName(src_tools_TIME :: sqlT2realT($this->data['datum']"%w")) "s)";
  106.                   break;
  107.                case // anzahl Tage
  108.                   $this->wiederholung $this->arrKindOfBlocks[$this->data['wiederholung']] " (bis einschließ. " src_tools_TIME :: sqlT2realT(src_tools_TIME :: addDays2SQL($this->data['datum']$this->data['anzahlWiederholung'1)) ")";
  109.                   break;
  110.             }
  111.             $this->rows .= src_tools_TEMPLATE :: getTemplate("admin_" $this->pageTemplate . "_row"$this);
  112.          }
  113.          $this->makePage("admin_" $this->pageTemplate);
  114.       }
  115.       // section -64--88-122--2--6176e79b:103fa06a375:-7fad end
  116.    }
  117.    /**
  118.     * liefert ein Formular zur Änderung bzw. Neueingabe eines Datensatzes
  119.     *
  120.     * Wenn die Tabellenspezifischen Parameter vorhergesetzt wurden wird der
  121.     * Datensatz ausgegeben. Ansonsten erscheint ein leeres Formular
  122.     *
  123.     * @access public
  124.     * @author Kay Koch, <kay.koch@gmx.de>
  125.     * @return void 
  126.     */
  127.    public function change({
  128.       // section -64--88-122--2--6176e79b:103fa06a375:-7fa9 begin
  129.       if ($this->loginOK{
  130.          if (!empty ($this->block_idAND !empty ($this->arrOldData)) {
  131.             $this->data $this->arrOldData;
  132.             $this->todo "update";
  133.             $startTime $this->oSeen->getSeen($this->data['see_id'])->getStartTime($this->data['datum']);
  134.          else
  135.             if (!empty ($this->data['see_id'])) {
  136.                $this->todo "insert";
  137.                $startTime $this->oSeen->getSeen($this->data['see_id'])->getStartTime($this->data['datum']);
  138.             else {
  139.                $this->todo "insert";
  140.                $this->checked "";
  141.                $this->readonly "";
  142.                $this->data['datum'date("Y-m-")"01";
  143.                $this->data['anzahlZahler'"0";
  144.                $this->data['anzahlStunden'"1";
  145.                $this->data['stunde'$this->oSeen->getMinStartTime();
  146.                $startTime $this->data['stunde'];
  147.             }
  148.          list ($this->data['jahr']$m$dsplit("-"$this->data['datum']);
  149.          $this->vereinOptionList $this->getVereinOptionList($this->data['verein_nr']);
  150.          $this->seeOptionList $this->oSeen->getOptionList($this->data['see_id']);
  151.          $this->monthOptionList src_tools_TIME :: getMonthOL($m);
  152.          $this->dayOptionList src_tools_TIME :: getDayOL($d);
  153.          $this->nrHourOptionList src_tools_TIME :: getDayOL($this->data['anzahlStunden']5);
  154.          $this->hourOptionList src_tools_TIME :: getHourOL($this->data['stunde']$startTime$this->oSeen->getMaxStartTime());
  155.          $this->repeatOptionList $this->getRepeatOptionList($this->data['wiederholung']);
  156.          $this->checked ($this->data['ganzerTag']"checked" "";
  157.          $this->readonly ($this->data['ganzerTag']"readonly" "";
  158.          $this->makePage("admin_" $this->pageTemplate . "_input");
  159.       }
  160.       // section -64--88-122--2--6176e79b:103fa06a375:-7fa9 end
  161.    }
  162.    /**
  163.     * Aktualisieet den vorher durch setzen der Parameter ausgewählten
  164.     *
  165.     * Die Neuen Daten befinden sich im Übergabefeld $data
  166.     *
  167.     * @access public
  168.     * @author Kay Koch, <kay.koch@gmx.de>
  169.     * @param array 
  170.     * @return void 
  171.     */
  172.    public function update($data{
  173.       // section -64--88-122--2--6176e79b:103fa06a375:-7f83 begin
  174.       if ($this->loginOK{
  175.          if ($this->checkData($data)) {
  176.             $this->oVereine->setParams($data['verein_nr']);
  177.             $this->checkHoleDay($data);
  178.             $this->oNF->blockDates($this->arrOldDatatrue);
  179.             $this->oNF->blockDates($data);
  180.             $oBuchungen new src_foundation_tables_BUCHUNGEN();
  181.             $oBuchungen->blockDates($this->arrOldDatatrue);
  182.             $oBuchungen->blockDates($data);
  183.             $this->oBlock->updateRow($data);
  184.             $this->saveRegularyBlockInfo();
  185.             $this->show();
  186.          else
  187.             $this->change();
  188.       }
  189.       // section -64--88-122--2--6176e79b:103fa06a375:-7f83 end
  190.    }
  191.    /**
  192.     * Löscht den Datensatz der vorher durch Parameter ausgewählt wurde
  193.     *
  194.     * @access public
  195.     * @author Kay Koch, <kay.koch@gmx.de>
  196.     * @return void 
  197.     */
  198.    public function delete({
  199.       // section -64--88-122--2--6176e79b:103fa06a375:-7f7f begin
  200.       if ($this->loginOK{
  201.          $this->oNF->blockDates($this->arrOldDatatrue);
  202.          $oBuchungen new src_foundation_tables_BUCHUNGEN();
  203.          $oBuchungen->blockDates($this->arrOldDatatrue);
  204.          $this->oBlock->deleteRow();
  205.          $this->show();
  206.       }
  207.       // section -64--88-122--2--6176e79b:103fa06a375:-7f7f end
  208.    }
  209.    /**
  210.     * Fügt einen neuen Datensatz mit den Werten des Übergabeparameter $data
  211.     *
  212.     * @access public
  213.     * @author Kay Koch, <kay.koch@gmx.de>
  214.     * @param array 
  215.     * @return void 
  216.     */
  217.    public function insert($data{
  218.       // section -64--88-122--2--6176e79b:103fa06a375:-7f7d begin
  219.       if ($this->loginOK{
  220.          if ($this->checkData($data)) {
  221.             $this->checkHoleDay($data);
  222.             $this->oBlock->insertRow($data);
  223.             $data['block_id'$this->oBlock->block_id;
  224.             $this->oNF->blockDates($data);
  225.             $oBuchungen new src_foundation_tables_BUCHUNGEN();
  226.             $oBuchungen->blockDates($data);
  227.             $this->show();
  228.          else {
  229.             $this->data $data;
  230.             $this->change();
  231.          }
  232.       }
  233.       // section -64--88-122--2--6176e79b:103fa06a375:-7f7d end
  234.    }
  235.    /**
  236.     * überprüft die Korrektheit der eingebenen bzw. geänderten Daten
  237.     *
  238.     * @access public
  239.     * @author Kay Koch, <kay.koch@gmx.de>
  240.     * @param void 
  241.     * @return boolean 
  242.     */
  243.    public function checkData($data{
  244.       $returnValue = (bool) false;
  245.       // section -64--88-122--2--62c31de:1048594e50f:-7fef begin
  246.       try {
  247.          $this->zahlerInfo "";
  248.          $data['ganzerTag'(isset ($data['ganzerTag']AND $data['ganzerTag'== 1"1" "0";
  249.          if (!src_tools_CHECK :: checkID($data['see_id']))
  250.             throw new Exception("19,Seename");
  251.          if (empty ($data['verein_nr']))
  252.             throw new Exception("26,VereinNr");
  253.          if (!src_tools_CHECK :: checkVnum($data['verein_nr']))
  254.             throw new Exception("26,VereinNr");
  255.          if (empty ($data['tag']or empty ($data['monat']or empty ($data['jahr']))
  256.             throw new Exception("49,Datum");
  257.          if (!isset ($data['datum']or empty ($data['datum']))
  258.             $data['datum'src_tools_TIME :: formatDate($data['tag']$data['monat']$data['jahr']);
  259.          if (!src_tools_CHECK :: checkDatum($data['datum'])) // YYYY-MM-TT
  260.             throw new Exception("51,Datum");
  261.          if (!src_tools_CHECK :: checkHour($data['stunde'src_tools_TIME :: time2longTime($data['stunde']))) // hh:mm:ss
  262.             throw new Exception("52,Stunde");
  263.          if (!$this->oSeen->getSeen($data['see_id'])->isInDiveRange($data['datum']$data['stunde']))
  264.             throw new Exception("111,Datum/Stunde");
  265.          if (!src_tools_CHECK :: checkAnzahl($data['anzahl'])) // int
  266.             throw new Exception("28,Anzahl");
  267.          if (($diff $this->tooManyDivers($data)) 0// Feld
  268.             throw new Exception("41,Anzahl: maximal " ($data['anzahl'$diff" Plätze");
  269.          if (!src_tools_CHECK :: checkAnzahl($data['anzahlZahler'])) // int
  270.             throw new Exception("28,Anzahl Zahler");
  271.           if ($data['anzahlZahler'$data['anzahl'])
  272.               throw new Exception("29,Anzahl Zahler");
  273.          $returnValue true;
  274.       catch (Exception $e{
  275.          $message explode(","$e->getMessage());
  276.          $this->errorMsg "<b>[" $message[1"] : </b>" src_tools_ERROR :: getErrTxt($message[0]"<br>" $this->zahlerInfo;
  277.          $this->error src_tools_TEMPLATE :: getTemplate('error'$this);
  278.       }
  279.       // section -64--88-122--2--62c31de:1048594e50f:-7fef end
  280.       return (bool) $returnValue;
  281.    }
  282.    /**
  283.     * Konstruktor
  284.     *
  285.     * erstellt ein Obejkt der zu beabeitenden Klassen
  286.     * list alle erlaubten Datenbankschlüssel ein
  287.     * liest das Template
  288.     *
  289.     * @access public
  290.     * @author Kay Koch, <kay.koch@gmx.de>
  291.     * @param string 
  292.     * @param int 
  293.     * @param date 
  294.     * @param time 
  295.     * @return void 
  296.     */
  297.    public function __construct($token$block_id ""{
  298.       // section -64--88-122--2-66879486:104007981a3:-7f92 begin
  299.       parent :: __construct($token);
  300.       $this->oBlock new src_foundation_tables_BLOCKADEN();
  301.       $this->oNF new src_foundation_tables_NOCHFREI();
  302.       $this->oVereine new src_foundation_tables_VEREINE();
  303.       $this->block_id $block_id;
  304.       $this->arrOldData = $this->oBlock->getRowByID($block_id);
  305.       $this->setStartParameters($this$this->oBlock);
  306.       // section -64--88-122--2-66879486:104007981a3:-7f92 end
  307.    }
  308.    /**
  309.     * Erstellt eine Liste mit allen Vereinen
  310.     *
  311.     * @access public
  312.     * @author Kay Koch, <kay.koch@gmx.de>
  313.     * @param void 
  314.     * @return string 
  315.     */
  316.    private function prepareVereinList({
  317.       $returnValue = (string) "";
  318.       //
  319.       $this->oVereine new src_foundation_tables_VEREINE();
  320.       $arrVereine $this->oVereine->getRow();
  321.       foreach ($arrVereine as $arrVerband{
  322.          foreach ($arrVerband as $verein{
  323.             $returnValue .= "arrVereine[\"" $verein['verband_nr'"/" $verein['verein_nr'"\"]=\"" $verein['name'"\"\n";
  324.          }
  325.       }
  326.       //
  327.       return (string) $returnValue;
  328.    }
  329.  
  330.    /**
  331.     * Erstellt eine Liste mit allen Vereinen
  332.     *
  333.     * @access public
  334.     * @author Kay Koch, <kay.koch@gmx.de>
  335.     * @param void 
  336.     * @return string 
  337.     */
  338.    private function getVereinOptionList($index ""{
  339.       $returnValue = (string) "";
  340.       //
  341.       $arrVereine $this->oVereine->getRow();
  342.       foreach ($arrVereine as $verband_id => $arrVerband{
  343.          foreach ($arrVerband as $verein_id => $verein{
  344.             $vereinNr $verband_id "/" $verein_id;
  345.             $selected ($vereinNr == $index"SELECTED" "";
  346.             $returnValue .= "<option $selected value='$vereinNr'>$verein['stadt'" (" $verein['name'")</option>\n";
  347.          }
  348.       }
  349.       //
  350.       return (string) $returnValue;
  351.    }
  352.  
  353.    /**
  354.     * überprüft, ob die gewählte Anzahl an Tauchern für diesen Termin erlaubt ist
  355.     *
  356.     * @access public
  357.     * @author Kay Koch, <kay.koch@gmx.de>
  358.     * @param array 
  359.     * @return boolean 
  360.     */
  361.    /**
  362.    private function checkMaxFrei($data) {
  363.        $returnValue = (boolean) false;
  364.        //
  365.        $oMaxFrei = new src_foundation_tables_MAXFREI();
  366.        $oMaxFrei->setParams($data['see_id'], $data['datum']);
  367.        $arrMaxFrei = $oMaxFrei->getRow();
  368.        $maxFrei = ($this->oSeen-> $data['see_id']->buchbarProTag ? $arrMaxFrei['sumTag'] : $arrMaxFrei[substr($data['stunde'], 0, 5)]);
  369.        if ($data['anzahl'] > $maxFrei) // Anzahl zu groß
  370.            $this->zahlerInfo = "Die maximale Anzahl zu dieser Zeit beträgt: <b>" . $maxFrei . "</b> Taucher";
  371.        else
  372.            $returnValue = true;
  373.        //
  374.        return (boolean) $returnValue;
  375.    }
  376.    */
  377.  
  378.    /**
  379.     * liefert die Differenz zwischen angeforderten und verfügbaren Plätzen
  380.     * Das Ergebnis ist positiv, wenn zuviele angefordert wurden
  381.     *
  382.     * @access public
  383.     * @author Kay Koch, <kay.koch@gmx.de>
  384.     * @param array 
  385.     * @return boolean 
  386.     */
  387.    private function tooManyDivers($data{
  388.       // frei Plätze am gewünschten Zeitpunkt
  389.       $arrPlaces $this->oNF->getEntry($data['see_id']$data['datum']);
  390.       $stunde ($this->getSeen($data['see_id'])->buchbarProTag"sumTag" src_tools_TIME :: time2shortTime($data['stunde']);
  391.       $freePlaces $arrPlaces[0][$stunde];
  392.       // Der See, Datum und Zeit bleiben gleich
  393.       if (!empty ($this->block_idAND $data['see_id'== $this->arrOldData['see_id'AND $data['datum'== $this->arrOldData['datum'AND $data['stunde'== $this->arrOldData['stunde']{
  394.          $freePlaces += $this->arrOldData['anzahl']// freie Plätze werden um alten Betrag erhöht
  395.       }
  396.       // Differenz von angeforderten zu verfügbaren Plätzen
  397.       return $data['anzahl'$freePlaces;
  398.    }
  399.    /**
  400.     * speichert Informationen über regelmäßige Reservierungen als HTMl-Datei
  401.     * Die Pfad der Datei lautet /infos/blockaden_SEENAME.html
  402.     * wobei SEENAME der kleingeschriebene Name ohne Umlaute ist.
  403.     *
  404.     * @author kaykoch
  405.     * @access private
  406.     * @since 1 - 01.03.2007
  407.     * @return boolean 
  408.     *
  409.     */
  410.    private function saveRegularyBlockInfo({
  411.       $returnValue = (boolean) false;
  412.       $arrBlockRow array ();
  413.       $rowtpl "<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td>";
  414.       $this->arrOldData = $this->oBlock->getRowByID();
  415.       // Alle Blockaden durchlaufen
  416.       foreach ($this->arrOldData as $block{
  417.          // Zwischenspeicher initialisieren
  418.          if (!isset ($arrBlockRow[$block['see_id']]))
  419.             $arrBlockRow[$block['see_id']] "";
  420.          $this->oVereine->setParams($block['verein_nr']);
  421.          $block['info'(!empty ($block['info'])) $this->oVereine->name ", " $block['info'$this->oVereine->name;
  422.          switch ($block['wiederholung']{
  423.             case // wöchentlich
  424.                $arrBlockRow[$block['see_id']] .= sprintf($rowtplsrc_tools_TIME :: dayNr2dayName(src_tools_TIME :: sqlT2realT($block['datum']"%w"))$block['stunde']$block['anzahlStunden']$block['anzahl']$block['info']);
  425.                break;
  426.             case // Tage
  427.                $stunde ($block['ganzerTag']"ganztägig" $block['stunde'];
  428.                $anzahl ($block['ganzerTag']"" $block['anzahl'];
  429.                $anzahlStunden ($block['ganzerTag']"" $block['anzahlStunden'];
  430.                $zeitraum src_tools_TIME :: sqlT2realT($block['datum']" bis " src_tools_TIME :: sqlT2realT(src_tools_TIME :: addDays2SQL($block['datum']$block['anzahlWiederholung'1));
  431.                $arrBlockRow[$block['see_id']] .= sprintf($rowtpl$zeitraum$stunde$anzahlStunden$anzahl$block['info']);
  432.                break;
  433.          }
  434.       }
  435.       foreach ($arrBlockRow as $see_id => $this->blockRow{
  436.          $this->seename $this->getSeen($see_id)->name;
  437.          $filename "infos/blockaden_" src_tools_MULTI :: cleanUmlaute($this->seename".html";
  438.          src_tools_MULTI :: saveFile(src_tools_TEMPLATE :: getTemplate("regularyblocks_tpl"$this)$filename);
  439.       }
  440.       return (boolean) true;
  441.       ;
  442.    }
  443.  
  444.    /**
  445.     * liefert ein Optionlist mit den Möglichkeiten von Wiederholungsarten
  446.     *
  447.     * @access protected
  448.     * @author Kay Koch, <kay.koch@gmx.de>
  449.     * @param string 
  450.     * @return string 
  451.     */
  452.    private function getRepeatOptionList($index ''{
  453.       $returnValue = (string) '';
  454.  
  455.       // section -64--88-122--2-339007d5:1043cd4e8c9:-7f92 begin
  456.       foreach ($this->arrKindOfBlocks as $key => $title{
  457.          $selected ($key == $index"SELECTED" "";
  458.          $returnValue .= "<option $selected value='$key'> $title</option>\n";
  459.       }
  460.       // section -64--88-122--2-339007d5:1043cd4e8c9:-7f92 end
  461.  
  462.       return (string) $returnValue;
  463.    }
  464.  
  465.    /**
  466.     *
  467.     * checkHoleDay
  468.     *
  469.     * @author kaykoch
  470.     * @access public
  471.     * @since 1.0 - 27.05.2007
  472.     * @param array $data Übergabeparameter
  473.     * @return void 
  474.     *
  475.     */
  476.    private function checkHoleDay($data{
  477.       if (isset ($data['ganzerTag']AND ($data['ganzerTag'== 1)) {
  478.          $oMaxFrei new src_foundation_tables_MAXFREI();
  479.          $oMaxFrei->setParams($data['see_id']$data['datum']);
  480.          $arrMaxFrei $oMaxFrei->getRow();
  481.          $data['anzahl'$arrMaxFrei['sumTag'];
  482.       else {
  483.          $data['ganzerTag'"0";
  484.       }
  485.       $this->oVereine->setParams($data['verein_nr']);
  486.       $data['name'(!empty ($data['info'])) $this->oVereine->name ", " $data['info'$this->oVereine->name;
  487.    }
  488. /* end of class src_foundation_admin_ADMINBLOCKADEN */
  489. ?>

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