Bill_Import.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. require_once("DataBase/database.php");
  3. class Bill_Import
  4. {
  5. function Bill_Import()
  6. {
  7. $this->db = new Database();
  8. }
  9. function create($bill_id, $value)
  10. {
  11. $query = "INSERT INTO ".$this->db->bill_import_table." VALUES('".$bill_id."'";
  12. for($i = 0; $i < count($value); $i++)
  13. $query .= ", '".$value[$i]."'";
  14. $query .= ")";
  15. $this->db->query($query);
  16. $query = "SELECT bill_id from ".$this->db->bill_import_table." ORDER BY bill_id DESC";
  17. $tmp = $this->db->fetchRows($this->db->query($query));
  18. return $tmp[0][0];
  19. }
  20. function delete($bill_id)
  21. {
  22. $query = "DELETE FROM ".$this->db->bill_import_table." WHERE bill_id='$bill_id'";
  23. $this->db->query($query);
  24. }
  25. function get($bill_id = "")
  26. {
  27. if($bill_id == "")
  28. {
  29. $query = "SELECT * FROM ".$this->db->bill_import_table;
  30. $query .= " ORDER BY bill_number ASC";
  31. return $this->db->fetchRows($this->db->query($query));
  32. }
  33. else
  34. {
  35. $query = "SELECT * FROM ".$this->db->bill_import_table." WHERE bill_id='".$bill_id."'";
  36. $query .= " ORDER BY bill_number ASC";
  37. return $this->db->fetchRows($this->db->query($query));
  38. }
  39. }
  40. function clearTable()
  41. {
  42. $query = "TRUNCATE TABLE ".$this->db->bill_import_table;
  43. $this->db->query($query);
  44. }
  45. function hasTimestamp($timestamp)
  46. {
  47. $query = "SELECT * FROM ".$this->db->bill_import_table." WHERE timestamp='".$timestamp."'";
  48. if(count($this->db->fetchRows($this->db->query($query))) > 0)
  49. return True;
  50. else
  51. return False;
  52. }
  53. function import($path)
  54. {
  55. $file_access_ok = true;
  56. $file_open = false;
  57. $file_handle = false;
  58. $data = "";
  59. clearstatcache();
  60. try
  61. {
  62. if (!$file_handle = @fopen($path, "r"))
  63. return -1;
  64. if($file_handle)
  65. {
  66. while( $zeile = fgets($file_handle, 1024))
  67. {
  68. $values = explode("|", $zeile);
  69. for($i = 0; $i < count($values); $i++)
  70. $values[$i] = trim($values[$i]);
  71. if(!$this->hasTimestamp($values[6]))
  72. $this->create($values[0], array( $values[1],
  73. $values[2],
  74. $values[3],
  75. $values[4],
  76. $values[5],
  77. $values[6]));
  78. }
  79. fclose($file_handle);
  80. }
  81. return 0;
  82. }
  83. catch (Exception $e)
  84. {
  85. return -1;
  86. }
  87. }
  88. }
  89. ?>