shopping-list/php/classes.list.php

111 lines
3.4 KiB
PHP
Raw Normal View History

2018-10-24 15:00:27 +02:00
<?php
class item {
public $ID, $Anzahl, $Einheit, $Name, $Erledigt;
function item($ID, $Anzahl, $Einheit, $Name, $Erledigt){
$this->ID = $ID;
$this->Anzahl = $Anzahl;
$this->Einheit = $Einheit;
$this->Name = $Name;
$this->Erledigt = $Erledigt;
}
}
class shopping {
public $list = array();
private function addItem($ID, $Anzahl, $Einheit, $Name, $Erledigt){
$current = new item($ID, $Anzahl, $Einheit, $Name, $Erledigt);
array_push($this->list, $current);
}
function shopping(){
include $_SESSION["docroot"].'/config/config.php';
include $_SESSION["docroot"].'/php/connect.php';
$result = $mysqli->query("SELECT * FROM `ViewEinkauf` ORDER BY `ViewEinkauf`.`Name` ASC");
while($item = $result->fetch_assoc()){
$this->addItem($item["ID"], $item["Anzahl"], $item["Einheit"], $item["Name"], $item["Erledigt"]);
}
$mysqli->close();
}
function newItem($anzahl, $einheit, $name){
include $_SESSION["docroot"].'/config/config.php';
include $_SESSION["docroot"].'/php/connect.php';
if(!is_int($einheit)){
2019-05-22 08:42:36 +02:00
$unit_query = $mysqli->prepare("SELECT * FROM `Einheit` WHERE `Name` = ?");
$unit_query->bind_param("s", $einheit);
$unit_query->execute();
$result = $unit_query->get_result();
2018-10-24 15:00:27 +02:00
while($row = $result->fetch_assoc()){
$einheit = $row["ID"];
}
}
$insertQuery = $mysqli->prepare("INSERT INTO `Einkauf` (`Anzahl`, `Einheit`, `Name`, `Erledigt`) VALUES (?, ?, ?, 0)");
$insertQuery->bind_param("sss", $anzahl, $einheit, $name);
$result = $insertQuery->execute();
2018-10-24 15:00:27 +02:00
$mysqli->close();
}
function newItems($itemList){
foreach ($itemList as $item) {
$this->newItem($item["amount"], $item["unit"], $item["name"]);
}
}
function removeChecked(){
include $_SESSION["docroot"].'/config/config.php';
include $_SESSION["docroot"].'/php/connect.php';
$mysqli->query("DELETE FROM `Einkauf` WHERE `Erledigt`=1");
$mysqli->close();
}
function check($id, $status){
include $_SESSION["docroot"].'/config/config.php';
include $_SESSION["docroot"].'/php/connect.php';
$mysqli->query("UPDATE `Einkauf` SET `Erledigt` = $status WHERE `Einkauf`.`ID` = $id");
$mysqli->close();
}
2018-11-14 16:25:50 +01:00
function import(){
$import = json_decode($_POST["content"]);
$units = new units();
foreach($import->list as $item){
$this->newItem($item->Anzahl, $units->getID($item->Einheit), $item->Name);
}
2019-05-19 18:37:00 +02:00
print_r("0");
2018-11-14 16:25:50 +01:00
}
2018-10-24 15:00:27 +02:00
}
class unit {
public $ID, $Name, $Standard;
function unit($ID, $Name, $Standard){
$this->ID = $ID;
$this->Name = $Name;
$this->Standard = $Standard;
}
}
class units {
public $list = array();
private function addItem($ID, $Name, $Standard){
$current = new unit($ID, $Name, $Standard);
array_push($this->list, $current);
}
function units(){
include $_SESSION["docroot"].'/config/config.php';
include $_SESSION["docroot"].'/php/connect.php';
$result = $mysqli->query("SELECT * FROM `Einheit`");
while($item = $result->fetch_assoc()){
$this->addItem($item["ID"], $item["Name"], $item["Standard"]);
}
$mysqli->close();
}
2018-11-14 16:25:50 +01:00
function getID($Name){
foreach($this->list as $units){
if($units->Name==$Name){
return $units->ID;
}
}
}
2018-10-24 15:00:27 +02:00
}
?>