Kaynağa Gözat

Fixup shopping cart submission

Johannes Zellner 5 yıl önce
ebeveyn
işleme
b20a6b727f

+ 1 - 1
Dockerfile

@@ -17,7 +17,7 @@ RUN a2enmod rewrite headers rewrite expires cache
 RUN crudini --set /etc/php/7.3/apache2/php.ini PHP upload_max_filesize 64M && \
     crudini --set /etc/php/7.3/apache2/php.ini PHP post_max_size 64M && \
     crudini --set /etc/php/7.3/apache2/php.ini PHP memory_limit 128M && \
-    crudini --set /etc/php/7.3/apache2/php.ini Session session.save_path /run/sessions && \
+    crudini --set /etc/php/7.3/apache2/php.ini Session session.save_path /tmp/sessions && \
     crudini --set /etc/php/7.3/apache2/php.ini Session session.gc_probability 1 && \
     crudini --set /etc/php/7.3/apache2/php.ini Session session.gc_divisor 100 && \
     crudini --set /etc/php/7.3/apache2/php.ini PHP default_charset ""

+ 7 - 0
README.md

@@ -12,3 +12,10 @@ mysql --user=${CLOUDRON_MYSQL_USERNAME} --password=${CLOUDRON_MYSQL_PASSWORD} --
 ```
 
 Ensure charset for mysqli in database.php (2 of them) matches the tables!
+
+Dump customer_template table.
+Upload to /app/data/customer_template.sql
+Import
+```
+mysql --user=${CLOUDRON_MYSQL_USERNAME} --password=${CLOUDRON_MYSQL_PASSWORD} --host=${CLOUDRON_MYSQL_HOST} ${CLOUDRON_MYSQL_DATABASE} < /app/data/customer_template.sql
+```

+ 1 - 1
app/login.php

@@ -70,7 +70,7 @@ $table->add($password_label, 1, 0);
 $password_entry = new NTKPassword("password");
 $table->add($password_entry, 1, 1, 150);
 
-$submit_button = new NTKButton("submit", "Anmelden", "document.forms['customer'].submit();");
+$submit_button = new NTKButton("submit", "Anmelden", "document.forms['login'].submit();");
 $table->add($submit_button, 2, 1);
 
 $form = new NTKForm("login", "login.php", $table);

+ 1 - 1
start.sh

@@ -2,7 +2,7 @@
 
 set -eux
 
-mkdir -p /run/sessions
+mkdir -p /tmp/sessions
 
 chown -R www-data:www-data /app/data /run /tmp
 

+ 3 - 3
website/Class/ShoppingCart.php

@@ -196,14 +196,14 @@ class ShoppingCart
 			return -1;
 		}
 
-		$tour_data = $tour->getByAssistant($customer_data[0][12]);
-		$bill_id = $bill->create("", array($this->customer_id, $customer_data[0][12], "", $tour_data[0][2], -2, time()));
+		$tour_data = $tour->get($customer_data[0][12]);
+		$bill_id = $bill->create($this->customer_id, $customer_data[0][12], $tour_data[0][2], -2);
 
 		$list = $this->getItems();
 
 		for($i = 0; $i < count($list); $i++) {
 			if ($list[$i][2] > 0) {
-				$bill_product->create(array($bill_id, $list[$i][0], $list[$i][2], $list[$i][5], "", 0, 0, time()));
+				$bill_product->create($bill_id, $list[$i][0], $list[$i][2], $list[$i][5], 0, 0, 0);
 			}
 		}
 

+ 14 - 17
website/DataBase/Bill.php

@@ -9,30 +9,27 @@ class Bill
 		$this->db = new Database();
 	}
 
-	function create($bill_id, $value)
+	function create($customer_id, $tour_id, $assistant_id, $bill_number)
 	{
-		$query = "INSERT INTO ".$this->db->bill_table." VALUES('".$bill_id."'";
-		for($i = 0; $i < count($value); $i++)
-			$query .= ", '".$value[$i]."'";
-		$query .= ")";
-
+		$query = "INSERT INTO ".$this->db->bill_table." (customer_id, tour_id, date, assistant_id, bill_number, timestamp) VALUES(".$customer_id.", ".$tour_id.",CURRENT_DATE(),".$assistant_id.",".$bill_number.",CURRENT_TIMESTAMP())";
 		$this->db->query($query);
 
 		$query = "SELECT bill_id from ".$this->db->bill_table." ORDER BY bill_id DESC";
 		$tmp = $this->db->fetchRows($this->db->query($query));
+
 		return $tmp[0][0];
 	}
 
 	function update($bill_id, $value)
 	{
 		$query = "UPDATE ".$this->db->bill_table." SET ";
-		$query .= "customer_id='".$value[0]."', ";
-		$query .= "tour_id='".$value[1]."', ";
-		$query .= "date='".$value[2]."', ";
-		$query .= "assistant_id='".$value[3]."', ";
-		$query .= "bill_number='".$value[4]."' ";
+		$query .= "customer_id=".$value[0].", ";
+		$query .= "tour_id=".$value[1].", ";
+		$query .= "date=".$value[2].", ";
+		$query .= "assistant_id=".$value[3].", ";
+		$query .= "bill_number=".$value[4]." ";
 
-		$query .= "WHERE bill_id='".$bill_id."'";
+		$query .= "WHERE bill_id=".$bill_id."";
 		$this->db->query($query);
 	}
 
@@ -41,16 +38,16 @@ class Bill
 		$data = $this->get($bill_id);
 
 		$query = "UPDATE ".$this->db->bill_table." SET ";
-		$query .= "bill_number='".$this->getNextFreeNumberByAssistant($data[0][4])."' ";
+		$query .= "bill_number=".$this->getNextFreeNumberByAssistant($data[0][4])." ";
 
-		$query .= "WHERE bill_id='".$bill_id."'";
+		$query .= "WHERE bill_id=".$bill_id."";
 
 		$this->db->query($query);
 	}
 
 	function delete($bill_id)
 	{
-		$query = "DELETE FROM ".$this->db->bill_table." WHERE bill_id='$bill_id'";
+		$query = "DELETE FROM ".$this->db->bill_table." WHERE bill_id=".$bill_id."";
 
 		$this->db->query($query);
 	}
@@ -79,7 +76,7 @@ class Bill
 		}
 		else
 		{
-			$query = "SELECT * FROM ".$this->db->bill_table." WHERE bill_id='".$bill_id."'";
+			$query = "SELECT * FROM ".$this->db->bill_table." WHERE bill_id=".$bill_id."";
 			$query .= " ORDER BY bill_number ASC";
 
 			return $this->db->fetchRows($this->db->query($query));
@@ -88,7 +85,7 @@ class Bill
 
 	function getNextFreeNumberByAssistant($assistant_id)
 	{
-		$query = "SELECT bill_number FROM ".$this->db->bill_table." WHERE assistant_id='".$assistant_id."' ORDER BY bill_number DESC";
+		$query = "SELECT bill_number FROM ".$this->db->bill_table." WHERE assistant_id=".$assistant_id." ORDER BY bill_number DESC";
 		$result = $this->db->fetchRows($this->db->query($query));
 		return $result[0][0]+1;
 	}

+ 11 - 10
website/DataBase/Bill_Product.php

@@ -15,12 +15,13 @@ class Bill_Product
 		$this->db = new Database();
 	}
 
-	function create($value)
+	function create($bill_id, $product_id, $amount, $details, $rabatt, $price, $tax)
 	{
-		$query = "INSERT INTO ".$this->db->bill_product_table." VALUES(''";
-		for($i = 0; $i < count($value); $i++)
-			$query .= ", '".$value[$i]."'";
-		$query .= ")";
+
+		echo "create bill product -".$value[0]."-";
+
+		$query = "INSERT INTO ".$this->db->bill_product_table." (bill_id, product_id, amount, details, rabatt, price, tax) VALUES(".$bill_id.",'".$product_id."',".$amount.",'".$details."',".$rabatt.",".$price.",".$tax.")";
+		echo "=== ".$query." ===";
 
 		$this->db->query($query);
 	}
@@ -28,13 +29,13 @@ class Bill_Product
 	function update($bill_product_id, $value)
 	{
 		$query = "UPDATE ".$this->db->bill_product_table." SET ";
-		$query .= "bill_id='".$value[0]."', ";
+		$query .= "bill_id=".$value[0].", ";
 		$query .= "product_id='".$value[1]."', ";
-		$query .= "amount='".$value[2]."', ";
+		$query .= "amount=".$value[2].", ";
 		$query .= "details='".$value[3]."', ";
-		$query .= "rabatt='".$value[4]."', ";
-		$query .= "price='".$value[5]."', ";
-		$query .= "tax='".$value[6]."' ";
+		$query .= "rabatt=".$value[4].", ";
+		$query .= "price=".$value[5].", ";
+		$query .= "tax=".$value[6]." ";
 
 		$query .= "WHERE bill_product_id='".$bill_product_id."'";
 

+ 0 - 10
website/DataBase/database.php

@@ -28,16 +28,6 @@ class Database
         $db = getenv('CLOUDRON_MYSQL_DATABASE');
         $port = getenv('CLOUDRON_MYSQL_PORT');
 
-		// $host = "mysql5.nebulon.de";
-		// $user = "db30675_9";
-		// $password = "manda1337";
-		// $db = "db30675_9";
-
-// 		$host = "localhost";
-// 		$user = "root";
-// 		$password = "";
-// 		$db = "faursprung_net";
-
 		$this->db_link = mysqli_connect($host, $user, $password);
 
 		if(!$this->db_link)