Price.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. require_once("DataBase/database.php");
  3. class Price
  4. {
  5. function Price()
  6. {
  7. $this->db = new Database();
  8. }
  9. function exists($priceset_id, $product_id)
  10. {
  11. $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'";
  12. if(count($this->db->fetchRows($this->db->query($query))) > 0)
  13. return true;
  14. else
  15. return false;
  16. }
  17. function create($priceset_id, $product_id, $value)
  18. {
  19. $query = "INSERT INTO ".$this->db->price_table." VALUES('', '".$priceset_id."', '".$product_id."'";
  20. for($i = 0; $i < count($value); $i++)
  21. $query .= ", '".$value[$i]."'";
  22. $query .= ")";
  23. $this->db->query($query);
  24. }
  25. function update($priceset_id, $product_id, $value)
  26. {
  27. $query = "UPDATE ".$this->db->price_table." SET ";
  28. $query .= "price='".$value[0]."' ";
  29. $query .= "WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'";
  30. $this->db->query($query);
  31. }
  32. function delete($price_id)
  33. {
  34. $query = "DELETE FROM ".$this->db->price_table." WHERE price_id='$price_id'";
  35. $this->db->query($query);
  36. }
  37. function get($price_id = "", $col_names = array(), $search = "")
  38. {
  39. if($price_id == "")
  40. {
  41. if(count($col_names) == 0)
  42. $query = "SELECT * FROM ".$this->db->price_table;
  43. else
  44. {
  45. $query = "SELECT ".$col_names[0];
  46. for($i = 1; $i < count($col_names); $i++)
  47. $query .= ", ".$col_names[$i];
  48. $query .= " FROM ".$this->db->price_table;
  49. }
  50. if($search != "")
  51. $query .= " WHERE ".$search;
  52. $query .= " ORDER BY price_id ASC";
  53. return $this->db->fetchRows($this->db->query($query));
  54. }
  55. else
  56. {
  57. $query = "SELECT * FROM ".$this->db->price_table." WHERE price_id='".$price_id."'";
  58. $query .= " ORDER BY price_id ASC";
  59. return $this->db->fetchRows($this->db->query($query));
  60. }
  61. }
  62. function getPrice($priceset_id, $product_id)
  63. {
  64. $query = "SELECT * FROM ".$this->db->price_table." WHERE priceset_id='".$priceset_id."' AND product_id='".$product_id."'";
  65. return $this->db->fetchRows($this->db->query($query));
  66. }
  67. function export($path)
  68. {
  69. $csv_data = "";
  70. $query = "SELECT * FROM ".$this->db->price_table;
  71. $result = $this->db->query($query);
  72. while ($row = mysqli_fetch_assoc($result))
  73. $csv_data .= implode('|', $row)."\n";
  74. $this->db->writeToFile($path, $csv_data);
  75. }
  76. }
  77. ?>