Priceset.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. require_once("DataBase/database.php");
  3. class Priceset
  4. {
  5. function Priceset()
  6. {
  7. $this->db = new Database();
  8. }
  9. function create($priceset_id, $value)
  10. {
  11. $query = "INSERT INTO ".$this->db->priceset_table." VALUES('".$priceset_id."'";
  12. for($i = 0; $i < count($value); $i++)
  13. $query .= ", '".$value[$i]."'";
  14. $query .= ")";
  15. $this->db->query($query);
  16. }
  17. function update($priceset_id, $value)
  18. {
  19. $query = "UPDATE ".$this->db->priceset_table." SET ";
  20. $query .= "name='".$value[0]."', ";
  21. $query .= "netto='".$value[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. ?>