| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- <?php
- require_once("DataBase/database.php");
- class Customer
- {
- function __construct()
- {
- $this->db = new Database();
- }
- function create($customer_id, $value)
- {
- $query = "INSERT INTO ".$this->db->customer_table." VALUES('".$customer_id."'";
- for($i = 0; $i < count($value); $i++)
- $query .= ", '".str_replace("'", "\'", $value[$i])."'";
- $query .= ")";
- $this->db->query($query);
- }
- function update($customer_id, $value)
- {
- $query = "UPDATE ".$this->db->customer_table." SET ";
- $query .= "password='".$value[0]."', ";
- $query .= "prename='".$value[1]."', ";
- $query .= "postname='".$value[2]."', ";
- $query .= "street='".$value[3]."', ";
- $query .= "streetnumber='".$value[4]."', ";
- $query .= "plz='".$value[5]."', ";
- $query .= "city='".$value[6]."', ";
- $query .= "telephone='".$value[7]."', ";
- $query .= "telefax='".$value[8]."', ";
- $query .= "email='".$value[9]."', ";
- $query .= "pricelist_id='".$value[10]."', ";
- $query .= "tour_id='".$value[11]."', ";
- $query .= "rabatt='".$value[12]."', ";
- $query .= "details='".$value[13]."', ";
- $query .= "bank_name='".$value[14]."', ";
- $query .= "bank_account='".$value[15]."', ";
- $query .= "blz='".$value[16]."' ";
- $query .= "WHERE customer_id='".$customer_id."'";
- $this->db->query($query);
- }
- function delete($customer_id)
- {
- $query = "DELETE FROM ".$this->db->customer_table." WHERE customer_id='$customer_id'";
- $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 == "")
- {
- if(count($row_names) == 0)
- $query = "SELECT * FROM ".$this->db->customer_table;
- else
- {
- $query = "SELECT ".$row_names[0];
- for($i = 1; $i < count($row_names); $i++)
- $query .= ", ".$row_names[$i];
- $query .= " FROM ".$this->db->customer_table;
- }
- if($search != "")
- $query .= " WHERE ".$search;
- $query .= " ORDER BY customer_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- else
- {
- $query = "SELECT * FROM ".$this->db->customer_table." WHERE customer_id='".$customer_id."'";
- $query .= " ORDER BY customer_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- }
- function checkPassword($customer_id, $password)
- {
- if($customer_id == "" || $password == "")
- return false;
- /* TODO: use hash (sha512) for password */
- $query = "SELECT * FROM ".$this->db->customer_table." WHERE customer_id='".$customer_id."'";
- $result = $this->db->fetchRows($this->db->query($query));
- if(count($result) == 0)
- return false;
- if($result[0][1] == $password)
- return true;
- 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);
- }
- }
- }
- ?>
|