public static function getDBH()
 {
     if (empty(self::$dbh)) {
         self::$dbh = DBManager::create();
         self::$dbh->connect();
     }
     return self::$dbh;
 }
 public function route()
 {
     $pagename = Registry::$controller[strtolower($this->getRequestedPage($_SERVER['REQUEST_URI']))];
     if ($pagename === "Controller" || $pagename == null) {
         $pagename = Registry::$controller["default"];
     }
     MonitorEntry::updateEntry($_SERVER['REQUEST_URI']);
     $request = Request::val($_GET, $_POST);
     $controller = $this->getController($pagename);
     $controller->showPage($request);
 }
    public function showPage(Request $request)
    {
        // creating MainPage and modifing header information
        $page = MainPage::create();
        $page->getLayoutElem("header")->addHeaderElem('<link rel="stylesheet" type="text/css" href="' . Registry::$settings['config']['CSS_PATH'] . 'products_view_layout.css">');
        $page->getLayoutElem("header")->addHeaderElem('
        <script type="text/javascript">
                 var edi_feld_focused = false;
                 var basket = new Basket();
                 document.onkeydown = function(e){
                     var evt = e ? e:event;
                     var keyCode = evt.keyCode;
                     if(keyCode == 13 && edi_feld_focused){
                         search();
                     }
                 };
                function search(){
                    //alert(document.getElementById("search_string").value);
                     var url ="products?search="+document.getElementById("search_string").value;
                     window.location.href = url;
                }
                function addToBasket(productid){
                 var oldCookie = document.cookie;
                 document.cookie = oldCookie+""

                }
                function Basket(){
                    this.items = {};

                }
                Basket.prototype.addItem = function(itemID){
                    if(this.items[itemID] == undefined){
                        this.items[itemID] = 1;

                    }else{
                       var tmp = this.items[itemID];
                       this.items[itemID] = tmp+1;

                    }
                };
                Basket.prototype.removeItem = function(itemID){
                    if(!this.items[itemID] == undefined){
                       var tmp = this.items[itemID];
                       this.items[itemID] = tmp-1;

                    }
                };
         </script>');
        // deciding which content to build
        // this $request->get doesnt mean get, its the PHP $_GET which is wraped in Request class
        ErrorReporter::logVarExport(__CLASS__ . "::showPage(request) => request get export", $request->get);
        ErrorReporter::logVarExport(__CLASS__ . "::showPage(request) => request post export", $request->post);
        $search_string = $request->get["search"];
        $basketItem = $request->get["itemID"];
        if (!empty($basketItem)) {
            if (empty($_SESSION["basket"])) {
                $_SESSION["basket"] = array();
            }
            $itemID = mysql_real_escape_string($basketItem);
            $count = $_SESSION["basket"][$itemID];
            if (!empty($count)) {
                $_SESSION["basket"][$itemID] = $count + 1;
            } else {
                $_SESSION["basket"][$itemID] = 1;
            }
        }
        if (!empty($search_string)) {
            // fetch sql data
            //            var_dump(mysql_real_escape_string($search_string));
            $resultSet = TeileMapperImpl::make()->getListOfTeileByBezeichnung(mysql_real_escape_string($search_string));
            if (count($resultSet) == 1) {
                MonitorEntry::updateEntry($resultSet[0]->getBezeichnung);
            }
            $prev_search = "search=" . $search_string . "&";
        } else {
            // fetch sql data
            //            $resultSet = TeileMapperImpl::make()->getAlleProdukte();
            $resultSet = TeileMapperImpl::make()->getProdukte();
        }
        // fetch view and apply data to view
        $page->setContentView(Products_View::create());
        $page->getLayoutElem("contentview")->applyData(array("products" => $resultSet, "prev_search" => $prev_search));
        // show view
        $page->showPage($page->layoutElementMap);
    }
    public function show()
    {
        ?>
        <div id="adminpanel">
              <div id="stueckliste">
                  <div style='float: left;'>
                      Erstelle Stueckliste von <input id='stueckliste_produkt' type='text' value='<?php 
        if (isset($this->dataMap["stueckliste_produkt"])) {
            echo $this->dataMap["stueckliste_produkt"]->name();
        } else {
            echo "Produkt1";
        }
        ?>
'>
                  </div>
                  <div style='float:left;cursor: pointer;' onclick='javascript:stueckListeVonAnfordern();'>
                       Erstellen
                  </div>
                  <?php 
        if (!empty($this->dataMap["stueckliste_produkt"])) {
            Stueckliste::printTeil($this->dataMap["stueckliste_produkt"]);
        }
        ?>
</div>
              <div id="abc_analyse">
                  ABC Analyse
                  <?php 
        echo "<div class='abc_row'><div class='abc_col'> TeilID </div> <div class='abc_col'> TeilBezeichnung </div><div class='abc_col'> Preis </div><div class='abc_col'> Kategorie</div></div>";
        foreach ($this->dataMap["abc_analyse_array"] as $abc_adt) {
            echo "<div class='abc_row' onmouseout='javascript:unhighlight_row(this);' onmouseover='javascript:highlight_row(this);'>\r\n                                <div class='abc_col'>" . $abc_adt->productID() . "</div>" . "<div class='abc_col' style='cursor:pointer;' onclick=\"location.href='products?search=" . $abc_adt->productName() . "'\">" . $abc_adt->productName() . "</div>" . "<div class='abc_col'>" . number_format($abc_adt->wholePrice(), 2, ',', '.') . "</div>" . "<div class='abc_col'>" . $abc_adt->categorie() . "</div>\r\n                           </div>";
        }
        //            echo("Name: ".$abc_adt->productName() ." :: Kategorie: ".$abc_adt->categorie()." :: Preis: ".number_format($abc_adt->wholePrice(),2,',','.')."<br>");
        ?>
</div>
              <div id="bedarfs_analyse">

                  <div>
                      <div> Primaerbedarfs Analyse </div>
                      <div>TeilName<input id="teilname" value="<?php 
        echo $this->dataMap["bedarfsanalyse_teilname"];
        ?>
"></div>
                      <div>Letzter Monat<input id="monat" value="<?php 
        echo $this->dataMap["bedarfsanalyse_monat"];
        ?>
"></div>
                      <div>Jahr<input id="jahr" value="<?php 
        echo $this->dataMap["bedarfsanalyse_jahr"];
        ?>
"></div>
                      <div>Glaettungfaktor <input id="glaettungsfaktor" value="<?php 
        echo $this->dataMap["bedarfsanalyse_faktor"];
        ?>
"></div>
                      <button onclick="javascript:berechnen()">Berechnen</button>
                      <div>Ergebnis <input id="ergebnis" value="<?php 
        echo $this->dataMap["bedarfsanalyse_ergebnis"];
        ?>
"></div>

                  </div>
              </div>
              <div id="operationen">
                <div id ="einfuegen">
                    <div id="teil">
                        Teil erstellen
                        <input type="text" id="teil_bezeichnung" value="Produkt1">
                        <input type="text" id="teil_preis" value="Preis">
                        <input type="text" id="teil_typ" value="Kategorie">
                        <input type="text" id="teil_angeboten" value="wird es angeboten?">
                        <input type="text" id="teil_bild" value="bildurl">
                        <input type="text" id="teil_beschreibung" value="beschreibung" size="94">
                        <button onclick="javascript:teil_hinzufuegen()">Eintragen</button>
                    </div>
                    <div id="struktur">
                        Struktur erstellen
                        <input type="text" id="struktur_otnr" value="OTNR">
                        <input type="text" id="struktur_utnr" value="UTNR">
                        <input type="text" id="struktur_menge" value="Menge">
                        <button onclick="javascript:struktur_hinzufuegen()">Eintragen</button>
                    </div>
                    <div id="kunde">
                        Kunde erstellen
                        <input type="text" id="kunde_Name" value="Name">
                        <input type="text" id="kunde_Vorname" value="Vorname">
                        <input type="text" id="kunde_eMail" value="eMail">
                        <button onclick="javascript:kunde_hinzufuegen()">Eintragen</button>
                    </div>
                    <div id="bestellung">
                        Bestellung erstellen
                        <input type="text" id="bestellung_KundenNr" value="KundenNr">
                        <button onclick="javascript:bestllung_hinzufuegen()">Eintragen</button>
                        Artikel der Bestellung hinzufuegen
                        <input type="text" id="bestellung_BestellungsNr" value="BestellungsNr">
                        <input type="text" id="bestellung_TNr" value="TeileNr">

                        <button onclick="javascript:artikel_bestellung_hinzufuegen()">Eintragen</button>
                    </div>
                    <div id="pagehits">
                        Seiten Statistik
                         <?php 
        MonitorEntry::showPageHits();
        ?>
                    </div>

                    <div id="artikelhits">

                    </div>

                    <div id="bedarfs_daten">
                        Bedarfs Daten
                        <?php 
        AuftragsVerfolgung::printBedarfTabelle($this->dataMap["bedarfs_daten"]);
        ?>
                    </div>
                    <div id="bedarfsableitungs_daten">
                        Bedarfsableitungen
                        <?php 
        AuftragsVerfolgung::printBedarfAbleitungsTabelle($this->dataMap["bedarfsableitungs_daten"]);
        ?>
                    </div>

                </div>
               </div>
        </div>

    <?php 
    }