Customer.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. require_once("DataBase/database.php");
  3. class Customer
  4. {
  5. function Customer()
  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='".str_replace("'", "\'", $value[0])."', ";
  21. $query .= "prename='".str_replace("'", "\'", $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 exists($customer_id)
  46. {
  47. $query = "SELECT customer_id FROM ".$this->db->customer_table." WHERE customer_id='".$customer_id."'";
  48. $result = $this->db->fetchRows($this->db->query($query));
  49. if(count($result) > 0)
  50. return true;
  51. else
  52. return false;
  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. if(count($row_names) == 0)
  75. $query = "SELECT * FROM ".$this->db->customer_table;
  76. else
  77. {
  78. $query = "SELECT ".$row_names[0];
  79. for($i = 1; $i < count($row_names); $i++)
  80. $query .= ", ".$row_names[$i];
  81. $query .= " FROM ".$this->db->customer_table;
  82. }
  83. $query .= " WHERE customer_id='".$customer_id."'";
  84. $query .= " ORDER BY customer_id ASC";
  85. return $this->db->fetchRows($this->db->query($query));
  86. }
  87. }
  88. }
  89. ?>