Customer.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. require_once(__DIR__."/database.php");
  3. class Customer
  4. {
  5. function __construct()
  6. {
  7. $this->db = new Database();
  8. }
  9. function create($customer_id, $password, $prename, $postname, $street, $streetnumber, $plz, $city, $telephone, $telefax, $email, $pricelist_id, $tour_id, $rabatt, $details, $bank_name, $bank_account, $blz)
  10. {
  11. $customer_id = $customer_id ? $customer_id : 0;
  12. $plz = $plz ? $plz : 0;
  13. $pricelist_id = $pricelist_id ? $pricelist_id : 0;
  14. $tour_id = $tour_id ? $tour_id : 0;
  15. $rabatt = $rabatt ? $rabatt : 0;
  16. $blz = $blz ? $blz : 0;
  17. $query = "INSERT INTO ".$this->db->customer_table." ";
  18. $query .= " (customer_id, password, prename, postname, street, streetnumber, plz, city, telephone, telefax, email, pricelist_id, tour_id, rabatt, details, bank_name, bank_account, blz) ";
  19. $query .= " VALUES ";
  20. $query .= " (".$customer_id.", '".str_replace("'", "\'", $password)."', '".str_replace("'", "\'", $prename)."', '".str_replace("'", "\'", $postname)."', '".str_replace("'", "\'", $street)."', '".str_replace("'", "\'", $streetnumber)."', ".$plz.", '".str_replace("'", "\'", $city)."', '".str_replace("'", "\'", $telephone)."', '".str_replace("'", "\'", $telefax)."', '".str_replace("'", "\'", $email)."', ".$pricelist_id.", ".$tour_id.", ".$rabatt.", '".str_replace("'", "\'", $details)."', '".str_replace("'", "\'", $bank_name)."', '".str_replace("'", "\'", $bank_account)."', ".$blz.") ";
  21. $this->db->query($query);
  22. }
  23. function update($customer_id, $value)
  24. {
  25. $query = "UPDATE ".$this->db->customer_table." SET ";
  26. $query .= "password='".str_replace("'", "\'", $value[0])."', ";
  27. $query .= "prename='".str_replace("'", "\'", $value[1])."', ";
  28. $query .= "postname='".str_replace("'", "\'", $value[2])."', ";
  29. $query .= "street='".str_replace("'", "\'", $value[3])."', ";
  30. $query .= "streetnumber='".str_replace("'", "\'", $value[4])."', ";
  31. $query .= "plz=".$value[5].", ";
  32. $query .= "city='".str_replace("'", "\'", $value[6])."', ";
  33. $query .= "telephone='".str_replace("'", "\'", $value[7])."', ";
  34. $query .= "telefax='".str_replace("'", "\'", $value[8])."', ";
  35. $query .= "email='".str_replace("'", "\'", $value[9])."', ";
  36. $query .= "pricelist_id=".$value[10].", ";
  37. $query .= "tour_id=".$value[11].", ";
  38. $query .= "rabatt=".$value[12].", ";
  39. $query .= "details='".str_replace("'", "\'", $value[13])."', ";
  40. $query .= "bank_name='".str_replace("'", "\'", $value[14])."', ";
  41. $query .= "bank_account='".str_replace("'", "\'", $value[15])."', ";
  42. $query .= "blz=".$value[16]." ";
  43. $query .= "WHERE customer_id=".$customer_id."";
  44. $this->db->query($query);
  45. }
  46. function delete($customer_id)
  47. {
  48. $query = "DELETE FROM ".$this->db->customer_table." WHERE customer_id=".$customer_id."";
  49. $this->db->query($query);
  50. }
  51. function exists($customer_id)
  52. {
  53. $query = "SELECT customer_id FROM ".$this->db->customer_table." WHERE customer_id=".$customer_id."";
  54. $result = $this->db->fetchRows($this->db->query($query));
  55. if(count($result) > 0)
  56. return true;
  57. else
  58. return false;
  59. }
  60. function get($customer_id = "", $row_names = array(), $search = "")
  61. {
  62. if($customer_id == "")
  63. {
  64. if(count($row_names) == 0)
  65. $query = "SELECT * FROM ".$this->db->customer_table;
  66. else
  67. {
  68. $query = "SELECT ".$row_names[0];
  69. for($i = 1; $i < count($row_names); $i++)
  70. $query .= ", ".$row_names[$i];
  71. $query .= " FROM ".$this->db->customer_table;
  72. }
  73. if($search != "")
  74. $query .= " WHERE ".$search;
  75. $query .= " ORDER BY customer_id ASC";
  76. return $this->db->fetchRows($this->db->query($query));
  77. }
  78. else
  79. {
  80. if(count($row_names) == 0)
  81. $query = "SELECT * FROM ".$this->db->customer_table;
  82. else
  83. {
  84. $query = "SELECT ".$row_names[0];
  85. for($i = 1; $i < count($row_names); $i++)
  86. $query .= ", ".$row_names[$i];
  87. $query .= " FROM ".$this->db->customer_table;
  88. }
  89. $query .= " WHERE customer_id=".$customer_id."";
  90. $query .= " ORDER BY customer_id ASC";
  91. return $this->db->fetchRows($this->db->query($query));
  92. }
  93. }
  94. function checkPassword($customer_id, $password)
  95. {
  96. if($customer_id == "" || $password == "")
  97. return false;
  98. /* TODO: use hash (sha512) for password */
  99. $query = "SELECT * FROM ".$this->db->customer_table." WHERE customer_id=".$customer_id."";
  100. $result = $this->db->fetchRows($this->db->query($query));
  101. if(count($result) == 0)
  102. return false;
  103. if($result[0][1] == $password)
  104. return true;
  105. else
  106. return false;
  107. }
  108. }
  109. ?>