Przeglądaj źródła

Futher sync cleanup

Johannes Zellner 5 lat temu
rodzic
commit
d427d4d68a

+ 4 - 7
app/DataBase/database.php

@@ -2,7 +2,7 @@
 
 class Database
 {
-	function Database()
+	function __construct()
 	{
 		$this->customer_table = "customer";
 		$this->category_table = "category";
@@ -15,8 +15,7 @@ class Database
 		$this->tour_table = "tour";
 		$this->assistant_table = "assistant";
 		$this->group_table = "`group`";
-		$this->bill_import_table = "bill_import";
-		$this->bill_product_import_table = "bill_product_import";
+		$this->customer_template_table = "customer_template";
 		$this->ready = False;
 	}
 
@@ -30,10 +29,8 @@ class Database
 
 		$this->db_link = mysqli_connect($host, $user, $password, $db, $port);
 
-		if(!$this->db_link) {
-			echo "Error: ".mysqli_connect_error();
-            exit(1);
-        }
+		if(!$this->db_link)
+			exit("Error: ".mysqli_connect_error());
 
         mysqli_set_charset($this->db_link, "latin1");
 

+ 0 - 28
website/DataBase/Bill.php

@@ -89,34 +89,6 @@ class Bill
 		$result = $this->db->fetchRows($this->db->query($query));
 		return $result[0][0]+1;
 	}
-
-	function clearTable()
-	{
-		$query = "TRUNCATE TABLE ".$this->db->bill_table;
-		$this->db->query($query);
-	}
-
-	function export($path)
-	{
-		$csv_data = "";
-		$file_access_ok = true;
-		$file_open = false;
-
-		clearstatcache();
-
-		// $query = "SELECT * FROM ".$this->db->bill_table;
-		$query = "SELECT * FROM ".$this->db->bill_table."  WHERE timestamp >= (UNIX_TIMESTAMP(NOW() - INTERVAL 1 MONTH))";
-
-		$result = $this->db->query($query);
-		while ($row = mysqli_fetch_assoc($result))
-			$csv_data .= implode('|', $row)."\n";
-
-		$status = $this->db->writeToFile($path, $csv_data);
-
-		return $status;
-		// if($status)
-			// $this->clearTable();
-	}
 }
 
 ?>

+ 0 - 25
website/DataBase/Bill_Product.php

@@ -152,31 +152,6 @@ class Bill_Product
 		$query = "SELECT DISTINCT product.product_id, product.name, SUM(bill_product.amount), product.order_number FROM product, bill_product,bill WHERE product.product_id=bill_product.product_id AND bill_product.bill_id=bill.bill_id AND bill_product.amount > 0 AND bill.date>='".$date_from."' AND bill.date<='".$date_to."' GROUP BY product.product_id ORDER BY product.product_id";
 		return $this->db->fetchRows($this->db->query($query));
 	}
-
-	function clearTable()
-	{
-		$query = "TRUNCATE TABLE ".$this->db->bill_product_table;
-		$this->db->query($query);
-	}
-
-	function export($path)
-	{
-		$csv_data = "";
-
-		// $query = "SELECT * FROM ".$this->db->bill_product_table;
-		$query = "SELECT * FROM ".$this->db->bill_product_table."  WHERE timestamp >= (UNIX_TIMESTAMP(NOW() - INTERVAL 1 MONTH))";
-
-		$result = $this->db->query($query);
-		while ($row = mysqli_fetch_assoc($result))
-		$csv_data .= implode('|', $row)."\n";
-
-		$status = $this->db->writeToFile($path, $csv_data);
-
-		return $status;
-
-// 		if($status)
-// 			$this->clearTable();
-	}
 }
 
 ?>

+ 0 - 51
website/DataBase/Category.php

@@ -94,57 +94,6 @@ class Category
 
 			return $this->db->fetchRows($this->db->query($query));
 		}
-}
-
-	function clearTable()
-	{
-		$query = "TRUNCATE TABLE ".$this->db->category_table;
-		$this->db->query($query);
-	}
-
-	function export($path)
-	{
-		$csv_data = "";
-
-		$query = "SELECT * FROM ".$this->db->category_table;
-		$result = $this->db->query($query);
-		while ($row = mysqli_fetch_assoc($result))
-			$csv_data .= implode('|', $row)."\n";
-
-		$this->db->writeToFile($path, $csv_data);
-	}
-
-	function import($path)
-	{
-		$file_access_ok = true;
-		$file_open = false;
-		$file_handle = false;
-		$data = "";
-
-		clearstatcache();
-
-		if (!$file_handle = fopen($path, "r"))
-		{
-			echo "could not open file";
-			$file_access_ok = false;
-		}
-
-		if($file_handle)
-		{
-			$this->clearTable();
-
-			while( $zeile = fgets($file_handle, 1024))
-			{
-				$values = explode("|", $zeile);
-				for($i = 0; $i < count($values); $i++)
-					$values[$i] = trim($values[$i]);
-				$this->create(array(	$values[0],
-							$values[1],
-							$values[2]));
-			}
-
-			fclose($file_handle);
-		}
 	}
 }
 

+ 0 - 65
website/DataBase/Customer.php

@@ -52,18 +52,6 @@ class Customer
 		$this->db->query($query);
 	}
 
-	function export($path)
-	{
-		$csv_data = "";
-
-		$query = "SELECT * FROM ".$this->db->customer_table;
-		$result = $this->db->query($query);
-		while ($row = mysqli_fetch_assoc($result))
-			$csv_data .= implode(', ', $row)."\n";
-
-		$this->db->writeToFile($path, $csv_data);
-	}
-
 	function get($customer_id = "", $row_names = array(), $search = "")
 	{
 		if($customer_id == "")
@@ -110,59 +98,6 @@ class Customer
 		else
 			return false;
 	}
-
-	function clearTable()
-	{
-		$query = "TRUNCATE TABLE ".$this->db->customer_table;
-		$this->db->query($query);
-	}
-
-	function import($path)
-	{
-		$file_access_ok = true;
-		$file_open = false;
-		$file_handle = false;
-		$data = "";
-
-		clearstatcache();
-
-		if (!$file_handle = fopen($path, "r"))
-		{
-			echo "could not open file";
-			$file_access_ok = false;
-		}
-
-		if($file_handle)
-		{
-			$this->clearTable();
-
-			while( $zeile = fgets($file_handle, 1024))
-			{
-				$values = explode("|", $zeile);
-				for($i = 0; $i < count($values); $i++)
-					$values[$i] = trim($values[$i]);
-				$this->create($values[0], array(	$values[1],
-									$values[2],
-									$values[3],
-									$values[4],
-									$values[5],
-									$values[6],
-									$values[7],
-									$values[8],
-									$values[9],
-									$values[10],
-									$values[11],
-									$values[12],
-									$values[13],
-									$values[14],
-									$values[15],
-									$values[16],
-									$values[17]));
-			}
-
-			fclose($file_handle);
-		}
-	}
 }
 
 ?>

+ 0 - 49
website/DataBase/Price.php

@@ -111,55 +111,6 @@ class Price
 
 		return $price;
 	}
-
-	function export($path)
-	{
-		$csv_data = "";
-
-		$query = "SELECT * FROM ".$this->db->price_table;
-		$result = $this->db->query($query);
-		while ($row = mysqli_fetch_assoc($result))
-		$csv_data .= implode(', ', $row)."\n";
-
-		$this->db->writeToFile($path, $csv_data);
-	}
-
-	function clearTable()
-	{
-		$query = "TRUNCATE TABLE ".$this->db->price_table;
-		$this->db->query($query);
-	}
-
-	function import($path)
-	{
-		$file_access_ok = true;
-		$file_open = false;
-		$file_handle = false;
-		$data = "";
-
-		clearstatcache();
-
-		if (!$file_handle = fopen($path, "r"))
-		{
-			echo "could not open file";
-			$file_access_ok = false;
-		}
-
-		if($file_handle)
-		{
-			$this->clearTable();
-
-			while( $line = fgets($file_handle, 1024))
-			{
-				$values = explode("|", $line);
-				for($i = 0; $i < count($values); $i++)
-					$values[$i] = trim($values[$i]);
-				$this->create($values[1], $values[2], array($values[3]));
-			}
-
-			fclose($file_handle);
-		}
-	}
 }
 
 ?>

+ 0 - 49
website/DataBase/Priceset.php

@@ -66,55 +66,6 @@ class Priceset
 			return $this->db->fetchRows($this->db->query($query));
 		}
 	}
-
-	function export($path)
-	{
-		$csv_data = "";
-
-		$query = "SELECT * FROM ".$this->db->priceset_table;
-		$result = $this->db->query($query);
-		while ($row = mysqli_fetch_assoc($result))
-		$csv_data .= implode(', ', $row)."\n";
-
-		$this->db->writeToFile($path, $csv_data);
-	}
-
-	function clearTable()
-	{
-		$query = "TRUNCATE TABLE ".$this->db->priceset_table;
-		$this->db->query($query);
-	}
-
-	function import($path)
-	{
-		$file_access_ok = true;
-		$file_open = false;
-		$file_handle = false;
-		$data = "";
-
-		clearstatcache();
-
-		if (!$file_handle = fopen($path, "r"))
-		{
-			echo "could not open file";
-			$file_access_ok = false;
-		}
-
-		if($file_handle)
-		{
-			$this->clearTable();
-
-			while( $zeile = fgets($file_handle, 1024))
-			{
-				$values = explode("|", $zeile);
-				for($i = 0; $i < count($values); $i++)
-					$values[$i] = trim($values[$i]);
-				$this->create($values[0], array($values[1], $values[2]));
-			}
-
-			fclose($file_handle);
-		}
-	}
 }
 
 ?>

+ 0 - 56
website/DataBase/Product.php

@@ -164,62 +164,6 @@ class Product
 
 		return $this->db->fetchRows($this->db->query($query));
 	}
-
-	function export($path)
-	{
-		$csv_data = "";
-
-		$query = "SELECT * FROM ".$this->db->product_table;
-		$result = $this->db->query($query);
-		while ($row = mysqli_fetch_assoc($result))
-		$csv_data .= implode(', ', $row)."\n";
-
-		$this->db->writeToFile($path, $csv_data);
-	}
-
-	function clearTable()
-	{
-		$query = "TRUNCATE TABLE ".$this->db->product_table;
-		$this->db->query($query);
-	}
-
-	function import($path)
-	{
-		$file_access_ok = true;
-		$file_open = false;
-		$file_handle = false;
-		$data = "";
-
-		clearstatcache();
-
-		if (!$file_handle = fopen($path, "r"))
-		{
-			echo "could not open file";
-			$file_access_ok = false;
-		}
-
-		if($file_handle)
-		{
-			$this->clearTable();
-
-			while( $zeile = fgets($file_handle, 1024))
-			{
-				$values = explode("|", $zeile);
-				for($i = 0; $i < count($values); $i++)
-					$values[$i] = trim($values[$i]);
-				$this->create($values[0], array(	$values[1],
-									$values[2],
-									$values[3],
-									$values[4],
-									$values[5],
-									$values[6],
-									$values[7],
-									$values[8]));
-			}
-
-			fclose($file_handle);
-		}
-	}
 }
 
 ?>

+ 3 - 35
website/DataBase/database.php

@@ -16,29 +16,25 @@ class Database
 		$this->assistant_table = "assistant";
 		$this->group_table = "`group`";
 		$this->customer_template_table = "customer_template";
-		$this->ready = false;
+		$this->ready = False;
 	}
 
 	function connectToDb()
 	{
-
         $host = getenv('CLOUDRON_MYSQL_HOST');
         $user = getenv('CLOUDRON_MYSQL_USERNAME');
         $password = getenv('CLOUDRON_MYSQL_PASSWORD');
         $db = getenv('CLOUDRON_MYSQL_DATABASE');
         $port = getenv('CLOUDRON_MYSQL_PORT');
 
-		$this->db_link = mysqli_connect($host, $user, $password);
+		$this->db_link = mysqli_connect($host, $user, $password, $db, $port);
 
 		if(!$this->db_link)
 			exit("Error: ".mysqli_connect_error());
 
-		if(!mysqli_select_db($this->db_link, $db))
-			exit("Error: selecting db");
-
 		mysqli_set_charset($this->db_link, "latin1");
 
-		$this->ready = TRUE;
+		$this->ready = True;
 	}
 
 	function query($query)
@@ -64,34 +60,6 @@ class Database
 
 		return $all_rows;
 	}
-
-	function writeToFile($path, $data)
-	{
-		$file_access_ok = true;
-		$file_open = false;
-
-		clearstatcache();
-
-		if (file_exists($path))
-			if (!is_writable($path))
-			$file_access_ok = false;
-
-		if ($file_access_ok and (!$file_handle = fopen($path, "w+b")))
-			$file_access_ok = false;
-
-		if ($file_access_ok)
-		{
-			if (!fwrite($file_handle, $data) and ($data != ''))
-				$file_access_ok = false;
-			else
-				$file_open = true;
-		}
-
-		if ($file_open)
-			fclose($file_handle);
-
-		return $file_access_ok;
-	}
 }
 
 ?>