| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- require_once("DataBase/database.php");
- class Category
- {
- function __construct()
- {
- $this->db = new Database();
- }
- function create($value)
- {
- $query = "INSERT INTO ".$this->db->category_table." VALUES('".$value[0]."'";
- for($i = 1; $i < count($value); $i++)
- $query .= ", '".str_replace("'", "\'", $value[$i])."'";
- $query .= ")";
- $this->db->query($query);
- }
- function update($category_id, $value)
- {
- $query = "UPDATE ".$this->db->category_table." SET ";
- $query .= "name='".$value[0]."', ";
- $query .= "details='".$value[1]."' ";
- $query .= "WHERE category_id='".$category_id."'";
- $this->db->query($query);
- }
- function delete($category_id)
- {
- $query = "DELETE FROM ".$this->db->category_table." WHERE category_id='$category_id'";
- $this->db->query($query);
- }
- function get($category_id = "", $row_names = array(), $search = "")
- {
- if($category_id == "")
- {
- if(count($row_names) == 0)
- $query = "SELECT * FROM ".$this->db->category_table;
- else
- {
- $query = "SELECT ".$row_names[0];
- for($i = 1; $i < count($row_names); $i++)
- $query .= ", ".$row_names[$i];
- $query .= " FROM ".$this->db->category_table;
- }
- if($search != "")
- $query .= " WHERE ".$search;
- $query .= " ORDER BY category_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- else
- {
- $query = "SELECT * FROM ".$this->db->category_table." WHERE category_id='".$category_id."' ORDER BY category_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- }
- function getABC($category_id = "", $row_names = array(), $search = "")
- {
- if($category_id == "")
- {
- if(count($row_names) == 0)
- $query = "SELECT * FROM ".$this->db->category_table;
- else
- {
- $query = "SELECT ".$row_names[0];
- for($i = 1; $i < count($row_names); $i++)
- $query .= ", ".$row_names[$i];
- $query .= " FROM ".$this->db->category_table;
- }
- if($search != "")
- $query .= " WHERE ".$search;
- $query .= " ORDER BY name ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- else
- {
- $query = "SELECT * FROM ".$this->db->category_table." WHERE category_id='".$category_id."' ORDER BY category_id ASC";
- return $this->db->fetchRows($this->db->query($query));
- }
- }
- function clearTable()
- {
- $query = "TRUNCATE TABLE ".$this->db->category_table;
- $this->db->query($query);
- }
- function export($path)
- {
- $csv_data = "";
- $query = "SELECT * FROM ".$this->db->category_table;
- $result = $this->db->query($query);
- while ($row = mysqli_fetch_assoc($result))
- $csv_data .= implode('|', $row)."\n";
- $this->db->writeToFile($path, $csv_data);
- }
- 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(array( $values[0],
- $values[1],
- $values[2]));
- }
- fclose($file_handle);
- }
- }
- }
- ?>
|