Customer.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. require_once("DataBase/database.php");
  3. class Customer
  4. {
  5. function __construct()
  6. {
  7. $this->db = new Database();
  8. }
  9. function create($customer_id, $value)
  10. {
  11. $query = "INSERT INTO ".$this->db->customer_table." VALUES('".$customer_id."'";
  12. for($i = 0; $i < count($value); $i++)
  13. $query .= ", '".str_replace("'", "\'", $value[$i])."'";
  14. $query .= ")";
  15. $this->db->query($query);
  16. }
  17. function update($customer_id, $value)
  18. {
  19. $query = "UPDATE ".$this->db->customer_table." SET ";
  20. $query .= "password='".$value[0]."', ";
  21. $query .= "prename='".$value[1]."', ";
  22. $query .= "postname='".$value[2]."', ";
  23. $query .= "street='".$value[3]."', ";
  24. $query .= "streetnumber='".$value[4]."', ";
  25. $query .= "plz='".$value[5]."', ";
  26. $query .= "city='".$value[6]."', ";
  27. $query .= "telephone='".$value[7]."', ";
  28. $query .= "telefax='".$value[8]."', ";
  29. $query .= "email='".$value[9]."', ";
  30. $query .= "pricelist_id='".$value[10]."', ";
  31. $query .= "tour_id='".$value[11]."', ";
  32. $query .= "rabatt='".$value[12]."', ";
  33. $query .= "details='".$value[13]."', ";
  34. $query .= "bank_name='".$value[14]."', ";
  35. $query .= "bank_account='".$value[15]."', ";
  36. $query .= "blz='".$value[16]."' ";
  37. $query .= "WHERE customer_id='".$customer_id."'";
  38. $this->db->query($query);
  39. }
  40. function delete($customer_id)
  41. {
  42. $query = "DELETE FROM ".$this->db->customer_table." WHERE customer_id='$customer_id'";
  43. $this->db->query($query);
  44. }
  45. function export($path)
  46. {
  47. $csv_data = "";
  48. $query = "SELECT * FROM ".$this->db->customer_table;
  49. $result = $this->db->query($query);
  50. while ($row = mysqli_fetch_assoc($result))
  51. $csv_data .= implode(', ', $row)."\n";
  52. $this->db->writeToFile($path, $csv_data);
  53. }
  54. function get($customer_id = "", $row_names = array(), $search = "")
  55. {
  56. if($customer_id == "")
  57. {
  58. if(count($row_names) == 0)
  59. $query = "SELECT * FROM ".$this->db->customer_table;
  60. else
  61. {
  62. $query = "SELECT ".$row_names[0];
  63. for($i = 1; $i < count($row_names); $i++)
  64. $query .= ", ".$row_names[$i];
  65. $query .= " FROM ".$this->db->customer_table;
  66. }
  67. if($search != "")
  68. $query .= " WHERE ".$search;
  69. $query .= " ORDER BY customer_id ASC";
  70. return $this->db->fetchRows($this->db->query($query));
  71. }
  72. else
  73. {
  74. $query = "SELECT * FROM ".$this->db->customer_table." WHERE customer_id='".$customer_id."'";
  75. $query .= " ORDER BY customer_id ASC";
  76. return $this->db->fetchRows($this->db->query($query));
  77. }
  78. }
  79. function checkPassword($customer_id, $password)
  80. {
  81. if($customer_id == "" || $password == "")
  82. return false;
  83. /* TODO: use hash (sha512) for password */
  84. $query = "SELECT * FROM ".$this->db->customer_table." WHERE customer_id='".$customer_id."'";
  85. $result = $this->db->fetchRows($this->db->query($query));
  86. if(count($result) == 0)
  87. return false;
  88. if($result[0][1] == $password)
  89. return true;
  90. else
  91. return false;
  92. }
  93. function clearTable()
  94. {
  95. $query = "TRUNCATE TABLE ".$this->db->customer_table;
  96. $this->db->query($query);
  97. }
  98. function import($path)
  99. {
  100. $file_access_ok = true;
  101. $file_open = false;
  102. $file_handle = false;
  103. $data = "";
  104. clearstatcache();
  105. if (!$file_handle = fopen($path, "r"))
  106. {
  107. echo "could not open file";
  108. $file_access_ok = false;
  109. }
  110. if($file_handle)
  111. {
  112. $this->clearTable();
  113. while( $zeile = fgets($file_handle, 1024))
  114. {
  115. $values = explode("|", $zeile);
  116. for($i = 0; $i < count($values); $i++)
  117. $values[$i] = trim($values[$i]);
  118. $this->create($values[0], array( $values[1],
  119. $values[2],
  120. $values[3],
  121. $values[4],
  122. $values[5],
  123. $values[6],
  124. $values[7],
  125. $values[8],
  126. $values[9],
  127. $values[10],
  128. $values[11],
  129. $values[12],
  130. $values[13],
  131. $values[14],
  132. $values[15],
  133. $values[16],
  134. $values[17]));
  135. }
  136. fclose($file_handle);
  137. }
  138. }
  139. }
  140. ?>