public function render() { // Here comes the rendering process $htmlContent = ""; //Main Content $bookList = BookModel::findList(null, null); //id und class Bezeichnungen der HTML Elementen $idContent = "content"; $classProduct = "product"; $classImage = "img-preview"; $classDescription = "description"; $classDescriptionText = "description-text"; $label1 = "label1"; //local configs, path are saved in book db table $maxDescriptionCharlenght = 300; $imagePath = "/src/theme/images/"; //translations $label_prefix = ": "; $lang_title = i("Title") . $label_prefix; $lang_author = i("Author") . $label_prefix; $lang_description = i("Description") . $label_prefix; $lang_price = i("Price") . $label_prefix; $lang_available = i("Available") . $label_prefix; $lang_pageTitel = i("Home"); $lang_isbn_nr = i("isbn"); //detail link $detailProductLink = "index.php?view=productdetail"; $textDetails = i('To the details'); $products = $bookList; // Array aus DB holen und verifizieren foreach ($products as $book) { //too long text? $modDescription = Utilities::cutText($book['description'], $maxDescriptionCharlenght); $book['author'] = trim($book['author']); $htmlContent .= "\n <div class=\"{$classProduct}\">\n <div class=\"col col_3_12\"><img class=\"{$classImage}\" src=\"" . $book['cover'] . "\" /></div>\n <div class=\"{$classDescription} col col_9_12\">\n <p><div class=\"{$label1}\">{$lang_title}</div>{$book['title']}</p>\n <p><div class=\"{$label1}\">{$lang_author}</div><span data-wiki=\"{$book['author']}\">{$book['author']}</span></p>\n <div class=\"{$classDescriptionText}\"><div class=\"{$label1}\">{$lang_description}</div>{$modDescription}</div>\n <p><div class=\"{$label1}\">{$lang_price}</div> {$book['currency']} {$book['price']}</p>\n <p><div class=\"{$label1}\">{$lang_available}</div>{$book['available']}</p>\n <a href=\"{$detailProductLink}&id={$book['isbn']}\" class=\"button button-primary clearfix\">{$textDetails}</a>\n </div>\n </div>"; } $htmlContentBody = "\n <h1> {$lang_pageTitel}</h1>\n {$htmlContent}\n "; return $htmlContentBody; }
public function displayCart() { $TID = 0; if (sizeof($this->items) == 0) { return i("Your shopping cart is empty."); } $table = ""; //Erstellen des HTML Contents, der von der displayCart() Funktion dann zurückgegeben wird $table = "<p>" . i('Your shoppingcart contains') . ": " . sizeof($this->items) . " " . i('product(s)') . "</p>" . "<table id='shoppingTable'>" . "<tr id='tableTopics'>\n\t\t<td>" . i('isbn') . "</td>\n\t\t<td>" . i('Amount') . "</td>\n\t\t<td>" . i('Title') . "</td>\n\t\t<td></td>\n\t\t<td></td>\n\t\t<td>" . i('Price') . "</td>\n\t\t<td></td>"; /* Die Tabelle zur Anzeige der in den Korb gelegten Items wird aufbereitet. Der Remove Button wird hinter jeden Zeileneintrag mit der entsprechenden Post Variable * gesetzt und die + und - Buttons werden angehängt * Update 30.12: Anstatt meiner Lösung unten hätte ich besser die +/- Buttons auch schon bei der Generierung mit den Actions belegen sollen. */ foreach ($this->items as $index) { $ID2del = $index->ID; $list = BookModel::findList(array('isbn' => array($index->ID)), null); $title = $list[0]['title']; $price = $list[0]['price']; $totPrice = $price * $index->amount; $table = $table . "<tr id={$TID} onclick=''><td>{$index->ID}</td>\n\t\t\t<td>{$title}</td>\n\t\t\t<td name='amount'>{$index->amount}</td>\n\t \t \t<td>\n\t \t \t<input type='button' id='plusButton' value='+'></input></td>\n\t \t \t<td><input type='button' id='minusButton' value='-'></input></td>\n\t \t \t<td>{$totPrice}</td>\n\t \t \t<td><form action='" . Controller::instance()->getViewUrl('shoppingcart') . "&remove={$ID2del}' method='post'><input type='submit' value='" . i('Remove') . "'></input></form></td>\n\t \t \t</tr>"; $TID++; $this->subTotal += $totPrice; } /* * Totaler Wert des Warenkorbs */ $table = $table . "\n\t\t\t\t<tr>\n\t\t<td></td><td></td><td></td><td></td>\n\t\t<td></td>\n\t\t<td></td>\n\t\t<td></td>\n\t\t</tr>\n\t\t<tr>\n\t\t<td></td><td></td><td></td><td></td>\n\t\t<td>Sub Total:</td>\n\t\t<td>{$this->subTotal}</td>\n\t\t<td></td>\n\t\t</tr>"; /* * */ $table = $table . "</table>\n\t \t\t\t<div class='action-wrapper'><form action='index.php?view=shoppingcart' method='post' class='clear-form'>\n\t \t\t\t<input type='submit' value='" . i('Empty cart') . "' class='button button-primary'></input>\n\t \t\t\t<input type='hidden' name='clearCart'></input></form>"; //Add Button go to payment $table = $table . "\n\t\t\t\t<a href='index.php?view=payment' class='next'>\n <input class='button button-primary' type='button' value='" . i('Go to payment') . "'></input>\n </a></div>\n\t\t\t"; // Hier den JavascriptCode rein: Erhöhen liest Anzahl aus, zählt eins dazu und reloaded the page mit dem GET Paramter: &update=ID&Amount=NEUER AMOUNT $table = $table . "\n\t \t\t\t<script type='text/javascript'>\n\n\t \t\t\tvar theTbl = document.getElementById('shoppingTable');\n\t \t\t\tvar rows = theTbl.rows;\n\n\t\t\t\tconsole.log(rows.length);\n\n\t\t\t\tfor(var i=0;i<rows.length;i++) {\n\n \t\t\t\t \t\t\tfor(var j=0;j<rows[i].cells.length;j++)\t{\n\t \t\t\t\t\t\tconsole.log('set');\n \t\t\t \t\t\t\trows[i].cells[j].onclick = alertInnerHTML;\n\t \t\t\t\t\t\t}\n\t\t\t\t}\n\n\t \t\t\trowIndex = 0;\n\n\t \t\t\tfunction myFunction(x) {\n\t \t\t\trowIndex = x.rowIndex\n\t \t\t\twindow.alert(rowIndex)\n\t\t\t\t}\n\n\n\n\t \t\t\tfunction alertInnerHTML(e) {\n \t\t\t\t\t e = e || window.event;//IE\n\t \t\t\t\trownumber = this.parentNode.id;\n\t \t\t\t\tcellNumber = this.cellIndex;\n\n\t \t\t\t\tconsole.log('Zeilennummer: '+rownumber + ' Spalte:' +cellNumber);\n\n\t \t\t\t\tif(cellNumber==3) {\n\t \t\t\t\tconsole.log('increase');\n\t \t\t\t\tincrease(rownumber);\n\t \t\t\t\t}\n\n\t \t\t\t\tif(cellNumber==4) {\n\t \t\t\t\tdecrease(rownumber);\n\t \t\t\t\t}\n\n\t \t\t\t\t}\n\n\t \t\t \tfunction increase(rownumber) {\n\t\t\t\trownumber++;\n\t \t\t\tvar table = document.getElementById('shoppingTable');\n\t\t\t\tproductID = table.rows[rownumber].cells[0].innerHTML;\n\t \t\t\twindow.open('index.php?view=shoppingcart&action=mod&id2Change='+productID+'&change=up','_self')\n\n\t \t\t\t}\n\n\t \t\t\tfunction decrease(rownumber) {\n\t\t\t\trownumber++;\n\t \t\t\tvar table = document.getElementById('shoppingTable');\n\t\t\t\tproductID = table.rows[rownumber].cells[0].innerHTML;\n\n\t\t\t\twindow.open('index.php?view=shoppingcart&action=mod&id2Change='+productID+'&change=down','_self')\n\t \t\t\treturn false;\n\t \t\t\t}\n\n\n\n\t \t</script>"; return $table; }
public function render() { //call functions to catch form executes $this->createBook(); $this->createUser(); //get the an array for all the labels //check admin rights $isAdmin = Utilities::checkIsAdmin(); if (!$isAdmin) { return '<h1>' . i("no_rights_msg") . '</h1>'; //";header( 'Location: http://localhost/src/index.php?view=home' ) ; } //---- //---- create book //---- //Product array $products = array(); //get the product list $products = BookModel::findList(null, null); //create an arraylist //only need one array to set up the product list with the right names $i = 0; foreach ($products as $book) { if ($i > 0) { continue; } $inputBook = Utilities::buildInput($book); $i++; } //---- //---- create user //---- //Product array $users = array(); //get the product list $users = UserModel::findList(null, null); //create an arraylist //only need one array to set up the product list with the right names $i = 0; foreach ($users as $user) { if ($i > 0) { continue; } $inputUser = Utilities::buildInput($user); $i++; } // Here comes the rendering process return ' <div id="content"> <h1>' . i("Administration") . '</h1> <br /> <hr> <br /> <h1>' . i("Book") . '</h1> <form name="formBook" action="index.php?view=administration" method="post" > <div class="profil"> <div class="picture"><img src="theme/images/book_1.png" height="80" width="80" /> </div> <div class="settings" > ' . $inputBook . ' <input class="button button-primary hidden" type="submit" id="createBook" name="createBook" value="' . i("Add Book") . '" /> <input class="button button-primary" type="button" onclick="validateBook()" value="' . i("Add Book") . '" /> </div> </div> </form> </div> <br /> <hr> <br /> <div id="content"> <h1>' . i("Benutzer") . '</h1> <form name="formUser" action="index.php?view=administration" method="post"> <div class="profil"> <div class="picture"><img src="theme/images/user.png" height="80" width="80" /> </div> <div class="settings" > ' . $inputUser . ' <input class="button button-primary hidden" type="submit" id="createUser" name="createUser" value="' . i("Add user") . '" /> <input class="button button-primary" type="button" onclick="validateUser()" value="' . i("Add user") . '" /> </div> </div> </form> </div> <br /> <hr> <br /> '; }
public function render() { // Here comes the rendering process $htmlContent = ""; //Main Content //id und class Bezeichnungen der HTML Elementen $idContent = "content"; $classProduct = "product-detail"; $classImage = "img-preview-detail"; $classDescription = "description"; $classDescriptionText = "description-text-detail"; $label1 = "label1"; //local config $maxDescriptionCharlenght = 20000; $imagePath = "/src/theme/images/"; $lang_pageTitel = i("Productview"); $button1 = i("Buy"); //Product array $products = array(); //get the product list $products = BookModel::findList(null, null); //save id if (isset($_GET['id'])) { $_SESSION['productdetail_id_selected'] = $_GET['id']; } //create an arraylist foreach ($products as $book) { if ($_SESSION['productdetail_id_selected'] != $book['isbn']) { continue; } $paragraph = Utilities::buildParagraph($book); //too long text? if (strlen($book['description']) > $maxDescriptionCharlenght) { $book['description'] = substr($book['description'], 0, $maxDescriptionCharlenght); $book['description'] = $book['description'] . "..."; } else { //not too long, display it all $modDescription = $book['description']; } /* * schwf5: Element in Warenkorb legen */ $note = ""; $found = false; //Auslesen der BuchID if (isset($_GET["id"])) { $currentID = $_GET["id"]; } else { $currentID = 0; } //Prüfen ob Seite mit added action geladen wurde (d.h. dass Buch in Korb gelegt wurde) if (isset($_GET["action"]) && $_GET["action"] == "added") { $amount = $_POST["amountSelection"]; //Seite wurde neu geladen. Prüfen, ob bereits ein Warenkorb existiert //Korb existiert schon. Items also in den Warenkorb hinzufügen if (isset($_COOKIE["shoppingCart"])) { //Prüfen, ob dieser Artikel schon hinzugefügt wurde. Wenn ja, den Amount hinzutun $cartArray = json_decode($_COOKIE["shoppingCart"]); foreach ($cartArray as $index) { if ($index->ID == $currentID) { $note = "Buch war schon im Korb - Anzahl aktualisiert"; $index->amount += $amount; setcookie("shoppingCart", json_encode($cartArray)); $found = true; } } if (!$found) { array_push($cartArray, array("ID" => $currentID, "amount" => $amount)); setcookie("shoppingCart", json_encode($cartArray)); } } else { $cartArray = array(array("ID" => $currentID, "amount" => $amount)); setcookie("shoppingCart", json_encode($cartArray)); } // } else { } $htmlContent .= "\n <div class=\"{$classProduct}\">\n <div class=\"{$classImage}\"><img src=\"" . $book['cover'] . "\" />\n </div>\n <div class=\"{$classDescription}\">\n\n {$paragraph}\n\n <div>\n <br>" . i('Amount') . ":\n <form action='index.php?view=productdetail&id={$currentID}&action=added' method='post'>\n <select name='amountSelection' class='input-border'>\n\n \t\t\t\t\t <option value='1'>1</option>\n \t\t\t\t\t <option value='2'>2</option>\n \t\t\t\t\t <option value='3'>3</option>\n \t\t\t\t\t <option value='4'>4</option>\n \t\t\t\t\t <option value='5'>5</option>\n\n\t\t\t\t\t</select>\n\t\t\t\t\t<input class='button button-primary' type='submit' name='submit' value='" . i('Add to cart') . "' />\n\t\t\t\t\t</form>\n\n\n\n </div>\n\n </div>\n </div>"; } //textmessage, after a product was placed in shoppingcart if (isset($_GET["action"])) { $buyState = "Produkt wurde in den Warenkorb gelegt.<br>"; } else { $buyState = ""; } //display page $htmlContentBody = "\n\t\t<div id=\"content\">\n <span style='color:red'>{$buyState}</span>\n \t\t{$note}\n <h1>" . $lang_pageTitel . "</h1>\n {$htmlContent}\n </div>\n\n"; return $htmlContentBody; }
public function render() { // Here comes the rendering process $js = ' '; //add Product to session //Only if its not yet there if (isset($_SESSION['shoppingCart']['id']) && isset($_GET['id'])) { if (!in_array($_GET['id'], $_SESSION['shoppingCart']['id'])) { $_SESSION['shoppingCart']['id'][] = $_GET['id']; } } //add chosen values to session //adress data if (isset($_POST['lastname'])) { $_SESSION['payment_lastname'] = $_POST['lastname']; } if (isset($_POST['firstname'])) { $_SESSION['payment_firstname'] = $_POST['firstname']; } if (isset($_POST['street'])) { $_SESSION['payment_street'] = $_POST['street']; } if (isset($_POST['plz'])) { $_SESSION['payment_plz'] = $_POST['plz']; } if (isset($_POST['country'])) { $_SESSION['payment_country'] = $_POST['country']; } //shipping method if (isset($_POST['shippingMethod'])) { $_SESSION['payment_shippingMethod'] = $_POST['shippingMethod']; } //payment method if (isset($_POST['paymentMethod'])) { $_SESSION['payment_paymentMethod'] = $_POST['paymentMethod']; } //gift box if (isset($_POST['giftBox'])) { $_SESSION['payment_giftBox'] = $_POST['giftBox']; } if (isset($_POST['comment'])) { $_SESSION['payment_comment'] = $_POST['comment']; } $htmlList = ""; //translations $title1 = i("Delivery Address"); $title2 = i("Shipping Method"); $title3 = i("Payment Method"); $title4 = i("Gift Box"); $title5 = i("Order"); $html = ""; $html .= $htmlList; //input all posted Values $inputs = Utilities::hiddenInputsFromPost(); $html .= ' <div> ' . $inputs . ' </div> '; //Use Userdata if logged in if (UserHandler::instance()->loggedin()) { if (UserHandler::instance()->user()) { $firstName = UserHandler::instance()->user()->getValue('first_name'); $lastName = UserHandler::instance()->user()->getValue('last_name'); $streetname = UserHandler::instance()->user()->getValue('streetname'); $zip = UserHandler::instance()->user()->getValue('zip'); $city = UserHandler::instance()->user()->getValue('city'); $email = UserHandler::instance()->user()->getValue('email'); } else { $firstName = ""; $lastName = ""; $streetname = ""; $zip = ""; $city = ""; $email = ""; } $greeting = i('Hello'); $loginMask = $greeting . ' ' . $firstName . ' ' . $lastName; } //a form to submit to myself $html .= "<div id='deliveryAddress' class=" . GrootPaymentView::visibility("deliveryAddress") . ">"; $html .= ' <div class="hidden"><input name="deliveryAddressStore"></input></div> <form action="" method="POST"> <h1>' . $title1 . '</h1> <div class="column1">' . i("first_name") . '</div><div class=""><input class="input1 " value="' . $firstName . '" name="firstname"></input></div> <div class="column1">' . i("last_name") . '</div><div class=""><input class="input1" value="' . $lastName . '" name="lastname"></input></div> <div class="column1">' . i("streetname") . '</div><div class=""><input class="input1" value="' . $streetname . '" name="street"></input></div> <div class="column1">' . i("zip") . '</div><div class=""><input class="input1" value="' . $zip . '" name="plz"></input></div> <div class="column1">' . i("city") . '</div><div class=""><input class="input1" value="' . $city . '" name="country"></input></div><br /> <input type="reset" class="button button-primary" value="' . i("Reset") . '"><input type="submit" class="button button-primary" value="' . i("Confirm") . '"/> <input class="input1" type="hidden" name="poster" value="deliveryAddress"></input> </form>'; $html .= '</div>'; //a form to submit to myself $html .= "<div id='shippingMethod' class=" . GrootPaymentView::visibility("shippingMethod") . ">"; $html .= ' <div class="hidden"><input name="shippingMethodStore"></input></div> <form action="" method="POST"> <h1>' . $title2 . '</h1><br /> <div class="column2">' . i("Home delivery") . '</div><div class="column2"><input type="radio" name="shippingMethod" value="Home delivery" checked></input></div> <div class="column2" >' . i("Nearest store") . '</div><div class="column2"><input type="radio" name="shippingMethod" value="Nearest Store"></input></div> <div class="column2">' . i("Other") . '</div><div class="column2"><input type="radio" name="shippingMethod" value="Other"></input></div> <div class="bottomButton"><input type="reset" class="button button-primary" value="' . i("Reset") . '"><input type="submit" class="button button-primary" value="' . i("Confirm") . '"/></div> <input class="input1" type="hidden" name="poster" value="shippingMethod"></input> </form>'; $html .= '</div>'; //a form to submit to myself $html .= "<div id='paymentMethod' class=" . GrootPaymentView::visibility("paymentMethod") . ">"; $html .= ' <div class="hidden"><input name="paymentMethodStore"></input></div> <form action="" method="POST"> <h1>' . $title3 . '</h1><br /> <div class="column2">' . i("Visa") . '</div><div class="column2"><input type="radio" name="paymentMethod" value="Visa" checked></input></div> <div class="column2">' . i("Postfinance") . '</div><div class="column2"><input type="radio" name="paymentMethod" value="Postfinance"></input></div> <div class="column2">' . i("Maestro") . '</div><div class="column2"><input type="radio" name="paymentMethod" value="Maestro"></input></div> <div class="column2">' . i("Check") . '</div><div class="column2"><input type="radio" name="paymentMethod" value="Check"></input></div> <div class="column2">' . i("PayPal") . '</div><div class="column2"><input type="radio" name="paymentMethod" value="PayPal"></input></div> <div class="column2">' . i("Other") . '</div><div class="column2"><input type="radio" name="paymentMethod" value="Other"></input></div> <div class="bottomButton"><input type="reset" class="button button-primary" value="' . i("Reset") . '"><input type="submit" class="button button-primary" value="' . i("Confirm") . '"/></div> <input class="input1" type="hidden" name="poster" value="paymentMethod"></input> </form>'; $html .= '</div>'; //a form to submit to myself //onclick JS funktion $html .= "<div id='giftBox' class=" . GrootPaymentView::visibility("giftBox") . ">"; $html .= ' <div class="hidden"><input name="giftBox"></input></div> <form action="" method="POST"> <h1>' . $title4 . '</h1><br /> <h3>' . i("Is it a gift?") . '</h3> <div class="column2">' . i("No") . '</div><div class="column2"><input type="radio" name="giftBox" value="No" checked></input></div> <div class="column2">' . i("Yes") . '</div><div class="column2"><input type="radio" name="giftBox" value="Yes"></input></div> <div class="column2">' . i("Bemerkung") . ':</div><div class="column2"><textarea name="comment" rows="10" cols="80"></textarea></div> <div class="bottomButton"><input id="realSubmitButton" type="submit" class="button button-primary hidden" value="' . i("Confirm") . '"/><input type="reset" class="button button-primary" value="' . i("Reset") . '"><input id="fakeSubmitButton" type="button" onclick="orderConfirmation()" class="button button-primary" value="' . i("Confirm") . '"/></div> <input class="input1" type="hidden" name="poster" value="giftBox"></input> </form>'; $html .= '</div>'; //a form to submit to myself $html .= "<div id='orderComplete' class=" . GrootPaymentView::visibility("orderComplete") . ">"; $html .= ' <div class="hidden"><input name="orderComplete"></input></div> <h1>' . $title5 . '</h1><br /> <h3>' . i("thx_for_order_msg") . '</h3> ' . i("email_send_msg") . ' ' . $email . ' <br> <a href="index.php?view=home"> <input class="button button-primary" type="button" value="' . i('back_to_main') . '"></input> </a> '; //if the order is completed and accepted, send an email to the user email with the previous saved content if (GrootPaymentView::visibility("orderComplete") != "hidden") { $email_adress = $email; //"*****@*****.**"; $email_title = i("Order from Groot Shop"); $emailContent = ""; $emailContent .= "" . i("Order from Groot Shop") . " \n"; $emailContent .= i("order_confirmation_msg") . " \n"; $emailContent .= " \n"; $emailContent .= $title1 . " \n"; $emailContent .= "--------------------------------\n"; $emailContent .= i('first_name') . ": " . $_SESSION['payment_firstname'] . " \n"; $emailContent .= i('last_name') . ": " . $_SESSION['payment_lastname'] . " \n"; $emailContent .= i('streetname') . ": " . $_SESSION['payment_street'] . " \n"; $emailContent .= i('zip') . ": " . $_SESSION['payment_plz'] . " \n"; $emailContent .= i('city') . ": " . $_SESSION['payment_country'] . " \n"; $emailContent .= " \n"; $emailContent .= $title2 . ": " . i($_SESSION['payment_shippingMethod']) . " \n"; $emailContent .= $title3 . ": " . i($_SESSION['payment_paymentMethod']) . " \n"; $emailContent .= $title4 . ": " . i($_SESSION['payment_giftBox']) . " \n"; $emailContent .= i('Note') . ": " . $_SESSION['payment_comment'] . " \n"; $emailContent .= "--------------------------------\n"; $emailContent .= " \n"; $emailContent .= $title5 . " \n"; //shoppingcart content $myArray = json_decode($_COOKIE["shoppingCart"]); $myCart = new ShoppingCart($myArray); $cart = $myCart->getCart(); foreach ($cart as $cartIsbn => $cartAmount) { $list = BookModel::findList(array('isbn' => array($cartIsbn)), null); $title = $list[0]['title']; $emailContent .= i('title') . " " . $title . " " . i('isbn') . ": " . $cartIsbn . " " . $cartAmount . "x \n"; } $emailContent .= "--------------------------------\n"; $emailContent .= " \n"; $emailContent .= " \n"; $emailContent .= i("greetings_from_groot_team_msg") . " \n"; $email_message = $emailContent; //TSCM Bitte beim Testen auskommentiert, weil es jedes mal wieder eine Email an mich versantd hat mail($email_adress, $email_title, $email_message); } $html .= '</div>'; //show post values $postedValues = ""; foreach ($_POST as $key => $value) { $postedValues .= "key = {$key} und value = {$value} </br>"; } return $html; }