public function userRegister() { try { $request = \Slim\Slim::getInstance()->request(); $body = json_decode($request->getBody()); // Validate request body has email, zipcode and password parameters if (!static::checkParamsExist($body, ['email' => 'Email address is required', 'zipcode' => 'Zipcode is required', 'password' => 'Password is required'])) { return; } $email = strtoupper($body->email); // Check if the user already exists in the database $userData = $this->dbService->getUserByEmail($email); if ($userData->code == DbService::SUCCESS_CODE) { $this->setResponse(static::SYSTEM_FAILURE_CODE, "User with Email address already exists", array()); } else { // Has Password $passwordHash = createHashedPassword($body->password); // Register the user $registerUser = $this->dbService->registerUser($body->email, $body->zipcode, $passwordHash); if ($registerUser->code !== DbService::SUCCESS_CODE || $registerUser->user_id == null) { $this->setResponse(static::SYSTEM_FAILURE_CODE, "User registration has failed to complete - " . $registerUser->code, array()); return; } // Auto register user in products service (iamdata) $productService = new productService(); $productAddUser = $productService->productsAddUserLocalAPI(); if ($productAddUser->code !== static::SUCCESS_CODE) { $this->setResponse($productAddUser->code, $productAddUser->msg, $productAddUser->payload); } else { $this->setResponse(static::SUCCESS_CODE, "User was registered", array()); } } } catch (Exception $e) { $this->setResponse(static::SYSTEM_FAILURE_CODE, "System error occurred, unable save user", array()); } finally { try { if ($this->code !== static::SUCCESS_CODE) { $this->dbService->deleteUser($registerUser->user_id); } } catch (Exception $e) { // Do nothing, we tried to clean up the account, so just give up at this point } $this->outputResponse(); } }
public static function totaalBestelling($arrBestelRegel) { /* return totaalprijs van de bestelling */ $Prijs = 0; foreach ($arrBestelRegel as $regel) { $product = productService::getProductFromId($regel->productID); $Prijs += $product->prijs * $regel->aantal; } return $Prijs; }
public function bestellingDoorvoeren($arrBestelRegel, $datum, $prijs, $KlantID) { // Voert een bestelling door naar DB $albestelddiedag = bestellingService::alBesteldDieDag($datum, $KlantID); if (!$albestelddiedag) { $BestelID = BestellingDAO::createBestelling($KlantID, $datum, $arrBestelRegel, $prijs); foreach ($arrBestelRegel as $regel) { $Aantal = $regel->aantal; if ($Aantal) { $ProductID = $regel->productID; $product = productService::getProductFromId($ProductID); $productPrijs = $product->prijs; $Prijs = $Aantal * $productPrijs; BestelRegelDAO::createBestelRegel($BestelID, $ProductID, $Aantal, $Prijs); $Aantal = 0; } } unset($_SESSION['bestelregelarray']); return TRUE; } if ($albestelddiedag) { return FALSE; } }
<?php setlocale(LC_TIME, 'NL_nl'); require_once "business/productservice.php"; require_once "business/klantenservice.php"; require_once "business/bestellingservice.php"; require_once "business/bestelregelservice.php"; require_once "business/loginservice.php"; session_start(); if (!isset($_SESSION['bestelregelarray'])) { $_SESSION['bestelregelarray'] = array(); } // MAAK PRODUCTLIJST AAN $arrCategories = productService::getAllCategories(); $arrProducten = productService::getAllProducts(); // MAAK WINKELKAR AAN include 'presentation/homepage.php'; /* Uw Login gegevens. Login : scoofy@gmail.com Paswoord : aXBvnR Login : ely@telenet.be Paswoord : SqXrkn Login : jan.vandorpe@vdab.be Paswoord : 7GRftr */
$klantnaam = $klant->Naam . " " . $klant->VNaam; if ($nextdatum == "") { print $datum . "<hr/>"; } else { if ($nextdatum != $dbDatum) { print "<hr/>" . $datum . "<hr/>"; } } print "<div class='innercontainer txtL'> "; print "<dl><dt>Bestelling voor " . $klantnaam . " op " . $datum . "</dt>"; $totPrijs = $bestelling->Prijs; $arrBestelRegel = bestelRegelService::getBestelRegelsFromId($BestelID); foreach ($arrBestelRegel as $regel) { $productID = $regel->productID; $aantal = $regel->aantal; $product = productService::getProductFromId($productID); $productPrijs = $product->prijs; $prijs = $aantal * $productPrijs; if ($aantal) { print "<dd>" . $aantal . " x " . $product->product . " <strong>€ " . $productPrijs . "</strong> = € " . $prijs . "</dd>"; } } print "<dt>Totaalprijs = € " . $totPrijs . "</dt>"; print "</dl><a href='?page=overzicht&verwijder=" . $BestelID . "'>bestelling verwijderen</a>"; print "</div>"; $nextdatum = $dbDatum; } if (!$arrBestellingen) { print "<dt>Geen bestellingen geplaatst.</dt>"; } ?>
$product = productService::getProductFromId($productID); $productPrijs = $product->prijs; $prijs = $aantal * $productPrijs; if ($aantal) { print "<dd><a href='?page=wijzigen&winkelkar=wijzigen&product=" . $productID . "'>" . $aantal . " x " . $product->product . " <strong>€ " . $productPrijs . "</strong></a> = € " . $prijs . " <a href='?page=wijzigen&winkelkar=wijzigen&product=" . $productID . "&aantal=0'> Haal dit uit winkelmand</a></dd>"; } $totprijs += $prijs; } print "<dt>Totaalprijs = € " . $totprijs . "</dt>"; ?> </dl> </div> </div> <?php if (isset($_GET['product']) && !isset($_GET['aantal'])) { $IDproduct = productService::getProductFromId($_GET['product']); ?> <div class="wrapper clearfix"> <div class="txtC"> <h1>Hoeveel <?php print $IDproduct->categorie; ?> had u er dan gewenst?</h1> <form action="index.php" method="get"> <input type="hidden" name="page" value="wijzigen"> <input type="hidden" name="winkelkar" value="wijzigen"> <input type="hidden" name="product" value="<?php print $IDproduct->id; ?> "> <input type="text" name="aantal" value="" style="width: 30px;" autofocus=""><?php
<?php session_start(); require_once './Business/productenService.php'; require_once './Business/klantService.php'; require_once './Business/bestellinglijnService.php'; require_once './Business/bestellingService.php'; //als niet aangemeld doorsturen if (!isset($_SESSION['user']) || !isset($_SESSION['winkelmandje']) || !isset($_SESSION)) { header('location: loginController.php'); exit(0); } //info ophalen over product aan de hand van productID $productservice = new productService(); $prijs = $productservice->getPrijsEnNaam($_SESSION['winkelmandje']); //afrekenenen moet true zijn if (isset($_GET['betalen']) && ($_GET['betalen'] = true)) { //de klant moet toelating hebben om te bestellen $klantService = new KlantService(); $status = $klantService->checkStatus($_SESSION['user']); if ($status = false) { header('location: afrekenController.php?error=verboden'); exit(0); } //als de klant toestemming heeft word er gekeken naar de datum, als deze hoger is dan vandaag dan word er gesubmit naar de databank. if ($_POST['bestellingsdatum'] > strtotime('now') && $_POST['bestellingsdatum'] < strtotime('+3 day')) { $bestellinglijnService = new bestellingLijnService(); $bestellingService = new bestellingService(); //resultaat ophalen of er een bestelling bestaat of niet. //Werkt in realiteit niet omdat de datum uit de databank komt met minuten en seconden en die waarmee vergeleken word //is de gekozen datum met het uur + minuten van de bestelling. Want het is bv: now +1 day.
<?php session_start(); require_once './Business/productenService.php'; require_once './Business/bestellinglijnService.php'; //lijst producten om uit te loopen $productenservice = new productService(); $productenLijst = $productenservice->getProductenOverview(); //laatste bestellingsID ophalen voor in de sessie te stoppen met alle bestellingslijnen $bestellinglijnService = new bestellingLijnService(); $laatstebestellingsID = $bestellinglijnService->getLaatsteLijn(); //echo $laatstebestellingsID; //als de user doorkomt van de login pagina dan word de sessie gebruiker als ingelogd gezet if (isset($_GET['action']) && ($_GET['action'] = "succes")) { $_SESSION['gebruiker'] = "ingelogd"; } //als de user niet ingelogd is dan word die doorgestuurd naar de loginController if (!isset($_SESSION['user'])) { header('location: loginController.php'); } //Als er een product toegevoegd is if (isset($_GET['product'])) { //dan word er in een array winkelmandje het productid gestopt en de hoeveelheid $_SESSION['winkelmandje'][] = array("BestellingsID" => $laatstebestellingsID + 1, "productID" => $_GET['product'], "hoeveelheid" => $_POST['hoeveelheid']); } include './Presentation/productenOverzicht.php';
/** * match a purchase pulled in from Information Machine to FDA recall data * POST body - the purchase */ public function openFDAProductMatch($type, $days, $minMatchingScore, $minQualityScore) { $start = date("Ymd", strtotime("-" . $days . " days")); $end = date("Ymd"); $maxPieceCompare = 10; // Word exclusion list that will not be searched upon or scored upon $words = "about,above,across,after,against,around,at,before,behind,below,beneath,beside,besides,between,beyond," . "by,down,during,except,for,from,in,inside,into,like,near,off,out,outside,over,since,through,throughout," . "till,toward,under,until,up,upon,with,without,according,to,because,addition,front,place,regard," . "spite,instead,on,account,the,and,aboard,along,amid,among,as,behind,but,concerning,considering,despite," . "excepting,excluding,following,minus,of,on,onto,opposite,past,per,plus,regarding,round,save,than,then," . "towards,underneath,unlike,versus,via,within,oz,net,wt,inc,rd,city,no,is,it,fl,ml,us,size,lb,or,all," . "count,ct,pk,all,feel,about,wegmans,food,you,feel,good,about,pack,world,finest,product,combination"; $exclusionWords = array_map('strtolower', explode(",", $words)); try { // Initialize post request capture fields $productSource = ""; $productId = ""; $productName = ""; $productUpc = ""; //get the request body $request = \Slim\Slim::getInstance()->request(); $body = json_decode($request->getBody()); // Initialize payload $payload = array(); $payload["purchase"] = $body; // Fail if product source is not found if (!property_exists($body, 'source')) { $this->setResponse(static::SYSTEM_FAILURE_CODE, "Product source is a required parameter", array()); return; } else { $productSource = $body->source; } //retrieve request body attributes if ($productSource === "iamdata") { if (property_exists($body, 'name')) { $productName = $body->name; } if (property_exists($body, 'upc')) { $productUpc = $body->upc; } if (property_exists($body, 'product') && property_exists($body->product, 'id')) { $productId = $body->product->id; } } else { $this->setResponse(static::SYSTEM_FAILURE_CODE, "No support exists for the product source provided", array()); return; } // Replace all hyphens with a space in the product name and convert to lower case $productName = str_replace('-', ' ', strtolower($productName)); // Build array of search terms for product name, filter out common words and special characters $productNamePieces = $this->productNameParser($productName, $exclusionWords); // Remove all hyphens in the product upc and convert to lower case $productUpc = str_replace('-', '', strtolower($productUpc)); // Build array of search terms for product name, filter out common words and special characters $productUpcPieces = $this->productUpcParser($productUpc, $exclusionWords); //get openFDA api key if ($this->openFdaApiData->code !== DbService::SUCCESS_CODE) { $response->set(static::SYSTEM_FAILURE_CODE, "openFDA api keys are not configured", array()); return; } $searchParams = "("; $first = true; // Build Searches for product name foreach ($productNamePieces as &$value) { if (!$first) { $searchParams .= "+"; } else { $first = false; } if ($value !== NULL && $value !== "") { $searchParams .= "product_description:" . $value; } } // Build Searches for product upc foreach ($productUpcPieces as &$value) { if (!$first) { $searchParams .= "+"; } else { $first = false; } if ($value !== NULL && $value !== "") { $searchParams .= "product_description:" . $value . "+code_info:" . $value; } } // Add search dates $searchParams .= ")+AND+report_date:[" . $start . "+TO+" . $end . "]"; // Build the URL $url = "https://api.fda.gov/" . $type . "/enforcement.json?search=" . $searchParams . "&limit=100&api_key=" . $this->openFdaApiData->api_key; // Retrieve the content $context = stream_context_create($this->getRequestOptions()); $result = file_get_contents($url, false, $context); $bigArr = json_decode($result, true, 20); // If the API call has returned an error then capture it and return the code/message to the caller if (array_key_exists('error', $bigArr)) { $this->setResponse($bigArr['error']['code'], $bigArr['error']['message'], array()); return; } // Exit with an error if the service did not contain a results array if (!array_key_exists('results', $bigArr)) { $this->setResponse(static::NO_DATA_FOUND_CODE, "The api did not contain any results", array()); return; } $foundAMatch = false; // Iterate thru each search result foreach ($bigArr['results'] as $idx => &$idxVal) { // Build array of terms for product name, filter out common words and special characters if (!array_key_exists('product_description', $idxVal)) { $resultProductNamePieces = array(); } else { $resultProductName = str_replace('-', ' ', strtolower($idxVal['product_description'])); $resultProductNamePieces = $this->productNameParser($resultProductName, $exclusionWords); } // Find matching terms for product upc $matchingProductNamePieces = array_intersect($resultProductNamePieces, $productNamePieces); // Build array of terms for product ups, filter out common words and special characters if (!array_key_exists('code_info', $idxVal)) { $resultProductUpcPieces = array(); } else { $resultProductUpc = str_replace('-', ' ', strtolower($idxVal['code_info'])); $resultProductUpcPieces = $this->productUpcParser($resultProductUpc, $exclusionWords); } // Find matching terms $matchingProductUpcPieces = array_intersect($resultProductUpcPieces, $productUpcPieces); // Calculating matching score $nameWeight = count($matchingProductNamePieces) * 0.5; $upcWeight = 1000; // Initialize Matching Score $matchingScore = 0; // Calculate the Product Name matching Score if (count($productNamePieces) > 0) { $matchingScore += count($matchingProductNamePieces) / count($productNamePieces) * $nameWeight; } // Calculate the Product Upc matching Score if (count($productUpcPieces) > 0) { $matchingScore += count($matchingProductUpcPieces) / count($productUpcPieces) * $upcWeight; } // Initialize Quality Score $qualityScore = 0; // Determine size of quality match for product names if (count($resultProductNamePieces) > $maxPieceCompare) { $cntResultProductNamePieces = $maxPieceCompare; } else { $cntResultProductNamePieces = count($resultProductNamePieces); } // Calculate Quality Score if product name pieces were found if ($cntResultProductNamePieces > 0) { // Generate associative array to find product names $flippedResultProductNamePieces = array_flip($resultProductNamePieces); foreach ($productNamePieces as $idx1 => &$value) { if (array_key_exists($value, $flippedResultProductNamePieces) && $idx1 <= $maxPieceCompare && $flippedResultProductNamePieces[$value] <= $maxPieceCompare) { $qualityScore += ($cntResultProductNamePieces - $flippedResultProductNamePieces[$value]) * (1 / $cntResultProductNamePieces); } } } // Determine size of quality match on Product UPCs if (count($resultProductUpcPieces) > $maxPieceCompare) { $cntResultProductUpcPieces = $maxPieceCompare; } else { $cntResultProductUpcPieces = count($resultProductUpcPieces); } // Calculate Quality Score if product upc pieces were found if ($cntResultProductUpcPieces > 0) { // Generate associative array to find product upc codes $flippedResultProductUpcPieces = array_flip($resultProductUpcPieces); // Iterate thru all product upc pieces and calculate score based upon position of match foreach ($productUpcPieces as $idx1 => &$value) { if (array_key_exists($value, $flippedResultProductUpcPieces) && $idx1 <= $maxPieceCompare && $flippedResultProductUpcPieces[$value] <= $maxPieceCompare) { $qualityScore += ($cntResultProductUpcPieces - $flippedResultProductUpcPieces[$value]) * (1 / $cntResultProductUpcPieces); } } } // Remove array entry if minimum matching score has not been met if ($matchingScore >= $minMatchingScore && $qualityScore >= $minQualityScore) { // Adding matching score to output and flag result as a match $bigArr['results'][$idx]['matching_score'] = round($matchingScore, 2); $foundAMatch = true; } else { unset($bigArr['results'][$idx]); } } // Retrieve product information $productAmazonLink = null; $productManufacturer = null; $productLargeImage = null; $productSmallImage = null; $productDescription = null; $productBrand = null; $productCategory = null; if ($productId !== "" && $foundAMatch) { try { // Retrieve product id information thru product service $productService = new productService(); $productQuery = $productService->productsGetProductLocalAPI($productId); if ($productQuery->code === "success") { $productAmazonLink = $productQuery->payload['amazon_link']; $productManufacturer = $productQuery->payload['manufacturer']; $productLargeImage = $productQuery->payload['large_image']; $productSmallImage = $productQuery->payload['small_image']; $productDescription = $productQuery->payload['description']; $productBrand = $productQuery->payload['brand']; $productCategory = $productQuery->payload['category']; } } catch (Exception $e) { // Nothing } } // Add results to the payload $payload["results"] = $bigArr['results']; // Inject product attributes into purchase element $payload["purchase"]->amazon_link = $productAmazonLink; $payload["purchase"]->manufacturer = $productManufacturer; $payload["purchase"]->large_image = $productLargeImage; $payload["purchase"]->small_image = $productSmallImage; $payload["purchase"]->description = $productDescription; $payload["purchase"]->brand = $productBrand; $payload["purchase"]->category = $productCategory; $this->setResponse(static::SUCCESS_CODE, static::SUCCESS_MESSAGE, $payload); } catch (Exception $e) { $this->setResponse(static::SYSTEM_FAILURE_CODE, $e->getMessage(), array()); } finally { $this->outputResponse(); } }