__construct($id, $data); } public function __construct($id = NULL, $data = NULL){ $this->conn = db_connect(); $this->id = $id; if ($id == NULL){//New division if ($data == NULL){ error("Product: No data supplied."); } }else {//ID set, existing article if ($data != NULL){//Update existing article if($_FILES['userfile']['error'] != 4){ $temp_name = new_file($_FILES['userfile'], 'products'); rename_file($temp_name, $this->id, 'products'); $ext = strtolower( pathinfo($temp_name, PATHINFO_EXTENSION) ); $this->picture = $this->id . "." . $ext; }else { $this->picture = 0; } }else {//Retrieve data from backend for display or other actions $data = $this->_retrieveData(); $this->picture = $data['picture']; } } //Common initializations $this->title = $data['title']; $this->description = $data['description']; $this->price = $data['price']; $this->allow_comment = $data['allow_comment']; $this->display_in_shop = $data['display_in_shop']; } public function store(){ if ($this->id == NULL){ $this->id = getNextId("din_product"); $sql = sprintf("INSERT INTO din_product (id, title, description, price, allow_comment, display_in_shop) VALUES (%s, %s, %s, %s, %s, %s)", $this->conn->quoteSmart($this->id), $this->conn->quoteSmart($this->title), $this->conn->quoteSmart($this->description), $this->conn->quoteSmart($this->price), $this->conn->quoteSmart($this->allow_comment), $this->conn->quoteSmart($this->display_in_shop) ); $result = $this->conn->query($sql); if (DB::isError($result) != true){ if($_FILES['userfile']['error'] != 4){ $temp_name = new_file($_FILES['userfile'], 'products'); rename_file($temp_name, $this->id, 'products'); $ext = strtolower( pathinfo($temp_name, PATHINFO_EXTENSION) ); $this->picture = $this->id . "." . $ext; }else { $this->picture = 0; } $this->_storeFilenames(); notify("Nytt produkt lagret."); }else { error("New product: " . $result->toString()); } }else { $sql = sprintf("UPDATE din_product SET title = %s, description = %s, price = %s, allow_comment = %s, display_in_shop = %s WHERE id = %s", $this->conn->quoteSmart($this->title), $this->conn->quoteSmart($this->description), $this->conn->quoteSmart($this->price), $this->conn->quoteSmart($this->allow_comment), $this->conn->quoteSmart($this->display_in_shop), $this->conn->quoteSmart($this->id) ); $result = $this->conn->query($sql); if (DB::isError($result) != true){ $this->_storeFilenames(); notify("Produkt oppdatert."); }else { notify("Problemer med lagring av produkt. Ingen endringer utført."); error("Update product: " . $result->toString()); } } } private function _storeFilenames() { if ($this->picture != 0) { $sql = "UPDATE din_product "; $sql .= "SET picture = '$this->picture' "; $sql .= "WHERE id = $this->id"; $result = $this->conn->query($sql); } } public function _retrieveData(){ $sql = "SELECT * "; $sql .= "FROM din_product p "; $sql .= "WHERE p.id = $this->id"; $result =& $this->conn->query($sql); if (DB::isError($result) != true) { if ($row =& $result->fetchRow(DB_FETCHMODE_ASSOC)) { return $row; } } else { error("Product: " . $result->toString()); } } public function delete($id){ $conn = db_connect(); $sql = "DELETE FROM din_product "; $sql .= "WHERE id = $id "; $sql .= "LIMIT 1"; $result = $conn->query($sql); if (DB::isError($result) != true) { if ($conn->affectedRows() > 0) { notify("Produktet er slettet."); } else { notify("Ugyldig produktid, ingen handling utført."); } } else { error($result->toString()); } } // return number of sold items public function getNumSold() { $sql = "SELECT SUM(oi.quantity) AS num "; $sql .= "FROM din_product p, din_order_item oi, din_order o "; $sql .= "WHERE oi.product_id = p.id AND oi.order_id = o.id AND o.order_status_id = 4 AND p.id = $this->id"; $result =& $this->conn->query($sql); if (DB::isError($result) != true) { if ($row =& $result->fetchRow(DB_FETCHMODE_ASSOC)) { if ($row['num'] > 0) return $row['num']; else return 0; } } else { error("Product: " . $result->toString()); } } // is it in shop ? public function getDisplay() { if ($this->display_in_shop) return "Ja"; return "Nei"; } // return number of items not marked as delivered public function getNumNew(){ $sql = "SELECT COUNT(*) AS num "; $sql .= "FROM din_product p, din_order_item oi, din_order o "; $sql .= "WHERE oi.product_id = p.id AND oi.order_id = o.id AND o.order_status_id = 4 AND p.id = $this->id AND order_deliverystatus_id='0'"; $result =& $this->conn->query($sql); if (DB::isError($result) != true) { if ($row =& $result->fetchRow(DB_FETCHMODE_ASSOC)) { return $row['num']; } } else { error("Product: " . $result->toString()); } } public function display(){ ?>
picture != 0){ print('
'); print(''); print('
'); } ?>

title; ?>

description); ?>

Pris: price); ?>

"", "type" => "cart_product", "attributes" => Array("name" => "cart_product", "product_id" => $this->id, "order_id" => $order_id, "allow_comment" => $this->allow_comment)); $form = new Form($title, $enctype, $method, $action, $fields); $form->display("horizontal"); ?>
picture != 0){ print('
'); print(''); print('
'); } ?>

title; ?>

Pris: price); ?>

title; ?> description); ?> price); ?> getDisplay();?> getNumSold(); ?> getNumNew(); ?> id, PRODUCT, "product", "view-edit-options-product"); ?> id"; $result =& $this->conn->query($sql); if (DB::isError($result) == true){ notify('Liste over kjøpere er ikke tilgjengelig.'); error('List buyers: ' . $result->toString()); } ?> fetchRow(DB_FETCHMODE_ASSOC)){ $user = new User($row['id']); ?>
# kjøper antall status endre status dato
getName(); ?>