| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- require_once("DataBase/database.php");
- class Priceset
- {
- function __construct()
- {
- $this->db = new Database();
- }
- function create($priceset_id, $value)
- {
- $query = "INSERT INTO ".$this->db->priceset_table." VALUES('".$priceset_id."'";
- for($i = 0; $i < count($value); $i++)
- $query .= ", '".str_replace("'", "\'", $value[$i])."'";
- $query .= ")";
- $this->db->query($query);
- }
- function update($priceset_id, $value)
- {
- $query = "UPDATE ".$this->db->priceset_table." SET ";
- $query .= "name='".$value[0]."', ";
- $query .= "netto='".$value[1]."' ";
- $query .= "WHERE priceset_id='".$priceset_id."'";
- $this->db->query($query);
- }
- function delete($priceset_id)
- {
- $query = "DELETE FROM ".$this->db->priceset_table." WHERE priceset_id='$priceset_id'";
- $this->db->query($query);
- }
- function get($priceset_id = "", $row_names = array(), $search = "")
- {
- if($priceset_id == "")
- {
- if(count($row_names) == 0)
- $query = "SELECT * FROM ".$this->db->priceset_table;
- else
- {
- $query = "SELECT ".$row_names[0];
- for($i = 1; $i < count($row_names); $i++)
- $query .= ", ".$row_names[$i];
- $query .= " FROM ".$this->db->priceset_table;
- }
- if($search != "")
- $query .= " WHERE ".$search;
- $query .= " ORDER BY priceset_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- else
- {
- $query = "SELECT * FROM ".$this->db->priceset_table." WHERE priceset_id='".$priceset_id."'";
- $query .= " ORDER BY priceset_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- }
- function export($path)
- {
- $csv_data = "";
- $query = "SELECT * FROM ".$this->db->priceset_table;
- $result = $this->db->query($query);
- while ($row = mysqli_fetch_assoc($result))
- $csv_data .= implode(', ', $row)."\n";
- $this->db->writeToFile($path, $csv_data);
- }
- function clearTable()
- {
- $query = "TRUNCATE TABLE ".$this->db->priceset_table;
- $this->db->query($query);
- }
- function import($path)
- {
- $file_access_ok = true;
- $file_open = false;
- $file_handle = false;
- $data = "";
- clearstatcache();
- if (!$file_handle = fopen($path, "r"))
- {
- echo "could not open file";
- $file_access_ok = false;
- }
- if($file_handle)
- {
- $this->clearTable();
- while( $zeile = fgets($file_handle, 1024))
- {
- $values = explode("|", $zeile);
- for($i = 0; $i < count($values); $i++)
- $values[$i] = trim($values[$i]);
- $this->create($values[0], array($values[1], $values[2]));
- }
- fclose($file_handle);
- }
- }
- }
- ?>
|