Priceset.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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($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 .= ", '".str_replace("'", "\'", $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 get($priceset_id = "", $row_names = array(), $search = "")
  31. {
  32. if($priceset_id == "")
  33. {
  34. if(count($row_names) == 0)
  35. $query = "SELECT * FROM ".$this->db->priceset_table;
  36. else
  37. {
  38. $query = "SELECT ".$row_names[0];
  39. for($i = 1; $i < count($row_names); $i++)
  40. $query .= ", ".$row_names[$i];
  41. $query .= " FROM ".$this->db->priceset_table;
  42. }
  43. if($search != "")
  44. $query .= " WHERE ".$search;
  45. $query .= " ORDER BY priceset_id ASC";
  46. return $this->db->fetchRows($this->db->query($query));
  47. }
  48. else
  49. {
  50. $query = "SELECT * FROM ".$this->db->priceset_table." WHERE priceset_id='".$priceset_id."'";
  51. $query .= " ORDER BY priceset_id ASC";
  52. return $this->db->fetchRows($this->db->query($query));
  53. }
  54. }
  55. }
  56. ?>