Customer.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 get($customer_id = "", $row_names = array(), $search = "")
  46. {
  47. if($customer_id == "")
  48. {
  49. if(count($row_names) == 0)
  50. $query = "SELECT * FROM ".$this->db->customer_table;
  51. else
  52. {
  53. $query = "SELECT ".$row_names[0];
  54. for($i = 1; $i < count($row_names); $i++)
  55. $query .= ", ".$row_names[$i];
  56. $query .= " FROM ".$this->db->customer_table;
  57. }
  58. if($search != "")
  59. $query .= " WHERE ".$search;
  60. $query .= " ORDER BY customer_id ASC";
  61. return $this->db->fetchRows($this->db->query($query));
  62. }
  63. else
  64. {
  65. $query = "SELECT * FROM ".$this->db->customer_table." WHERE customer_id='".$customer_id."'";
  66. $query .= " ORDER BY customer_id ASC";
  67. return $this->db->fetchRows($this->db->query($query));
  68. }
  69. }
  70. function checkPassword($customer_id, $password)
  71. {
  72. if($customer_id == "" || $password == "")
  73. return false;
  74. /* TODO: use hash (sha512) for password */
  75. $query = "SELECT * FROM ".$this->db->customer_table." WHERE customer_id='".$customer_id."'";
  76. $result = $this->db->fetchRows($this->db->query($query));
  77. if(count($result) == 0)
  78. return false;
  79. if($result[0][1] == $password)
  80. return true;
  81. else
  82. return false;
  83. }
  84. }
  85. ?>