Priceset.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. require_once("DataBase/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. function export($path)
  56. {
  57. $csv_data = "";
  58. $query = "SELECT * FROM ".$this->db->priceset_table;
  59. $result = $this->db->query($query);
  60. while ($row = mysqli_fetch_assoc($result))
  61. $csv_data .= implode(', ', $row)."\n";
  62. $this->db->writeToFile($path, $csv_data);
  63. }
  64. function clearTable()
  65. {
  66. $query = "TRUNCATE TABLE ".$this->db->priceset_table;
  67. $this->db->query($query);
  68. }
  69. function import($path)
  70. {
  71. $file_access_ok = true;
  72. $file_open = false;
  73. $file_handle = false;
  74. $data = "";
  75. clearstatcache();
  76. if (!$file_handle = fopen($path, "r"))
  77. {
  78. echo "could not open file";
  79. $file_access_ok = false;
  80. }
  81. if($file_handle)
  82. {
  83. $this->clearTable();
  84. while( $zeile = fgets($file_handle, 1024))
  85. {
  86. $values = explode("|", $zeile);
  87. for($i = 0; $i < count($values); $i++)
  88. $values[$i] = trim($values[$i]);
  89. $this->create($values[0], array($values[1], $values[2]));
  90. }
  91. fclose($file_handle);
  92. }
  93. }
  94. }
  95. ?>