| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?php
- require_once("DataBase/database.php");
- class Bill_Import
- {
- function Bill_Import()
- {
- $this->db = new Database();
- }
- function create($bill_id, $value)
- {
- $query = "INSERT INTO ".$this->db->bill_import_table." VALUES('".$bill_id."'";
- for($i = 0; $i < count($value); $i++)
- $query .= ", '".$value[$i]."'";
- $query .= ")";
- $this->db->query($query);
- $query = "SELECT bill_id from ".$this->db->bill_import_table." ORDER BY bill_id DESC";
- $tmp = $this->db->fetchRows($this->db->query($query));
- return $tmp[0][0];
- }
- function delete($bill_id)
- {
- $query = "DELETE FROM ".$this->db->bill_import_table." WHERE bill_id='$bill_id'";
- $this->db->query($query);
- }
- function get($bill_id = "")
- {
- if($bill_id == "")
- {
- $query = "SELECT * FROM ".$this->db->bill_import_table;
- $query .= " ORDER BY bill_number ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- else
- {
- $query = "SELECT * FROM ".$this->db->bill_import_table." WHERE bill_id='".$bill_id."'";
- $query .= " ORDER BY bill_number ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- }
- function clearTable()
- {
- $query = "TRUNCATE TABLE ".$this->db->bill_import_table;
- $this->db->query($query);
- }
- function hasTimestamp($timestamp)
- {
- $query = "SELECT * FROM ".$this->db->bill_import_table." WHERE timestamp='".$timestamp."'";
- if(count($this->db->fetchRows($this->db->query($query))) > 0)
- return True;
- else
- return False;
- }
- function import($path)
- {
- $file_access_ok = true;
- $file_open = false;
- $file_handle = false;
- $data = "";
- clearstatcache();
- try
- {
- if (!$file_handle = @fopen($path, "r"))
- return -1;
- if($file_handle)
- {
- while( $zeile = fgets($file_handle, 1024))
- {
- $values = explode("|", $zeile);
- for($i = 0; $i < count($values); $i++)
- $values[$i] = trim($values[$i]);
- if(!$this->hasTimestamp($values[6]))
- $this->create($values[0], array( $values[1],
- $values[2],
- $values[3],
- $values[4],
- $values[5],
- $values[6]));
- }
- fclose($file_handle);
- }
- return 0;
- }
- catch (Exception $e)
- {
- return -1;
- }
- }
- }
- ?>
|