db = new Database(); } function create($value) { $query = "INSERT INTO ".$this->db->bill_product_import_table." VALUES(''"; for($i = 0; $i < count($value); $i++) $query .= ", '".$value[$i]."'"; $query .= ")"; $this->db->query($query); } function delete($bill_product_id) { $query = "DELETE FROM ".$this->db->bill_product_import_table." WHERE bill_product_id='$bill_product_id'"; $this->db->query($query); } function get($bill_product_id = "", $row_names = array(), $search = "") { if($bill_product_id == "") { if(count($row_names) == 0) $query = "SELECT * FROM ".$this->db->bill_product_import_table; else { $query = "SELECT ".$row_names[0]; for($i = 1; $i < count($row_names); $i++) $query .= ", ".$row_names[$i]; $query .= " FROM ".$this->db->bill_product_import_table; } if($search != "") $query .= " WHERE ".$search; $query .= " ORDER BY product_id ASC"; return $this->db->fetchRows($this->db->query($query)); } else { $query = "SELECT * FROM ".$this->db->bill_product_import_table." WHERE bill_product_id='".$bill_product_id."'"; return $this->db->fetchRows($this->db->query($query)); } } function getByBillId($bill_id) { $query = "SELECT * FROM ".$this->db->bill_product_import_table." WHERE bill_id='".$bill_id."'"; $query .= " ORDER BY product_id ASC"; return $this->db->fetchRows($this->db->query($query)); } function clearTable() { $query = "TRUNCATE TABLE ".$this->db->bill_product_import_table; $this->db->query($query); } function hasTimestampProductPair($timestamp, $product_id) { $query = "SELECT * FROM ".$this->db->bill_product_import_table." WHERE timestamp='".$timestamp."' and product_id='".$product_id."'"; 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->hasTimestampProductPair($values[8], $values[2])) $this->create(array( $values[1], $values[2], $values[3], $values[4], $values[5], $values[6], $values[7], $values[8])); } fclose($file_handle); } return 0; } catch (Exception $e) { return -1; } } } ?>