Priceset.php 2.0 KB

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