Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class shopproduct {
- private $db;
- public $iProductID;
- public $vcProductNumber;
- public $vcTitle;
- public $txShortDesc;
- public $txLongDesc;
- public $txSpecfications;
- public $vcImage1;
- public $vcImage2;
- public $vcImage3;
- public $iPrice;
- public $iOfferPrice;
- public $iStock;
- public $iWeight;
- public $daCreated;
- public $iIsActive;
- public $iDeleted;
- public $iSortNum;
- public $arrColumns = array();
- public $arrLabels = array();
- public $arrValues = array();
- public function __construct() {
- global $db;
- $this->db = $db;
- $this->arrColumns = array(
- "iProductID" => "ID",
- "vcProductNumber" => "Produkt Nummer",
- "vcTitle" => "Titel",
- "txShortDesc" => "Kort Beskrivelse",
- "txLongDesc" => "Lang Beskrivelse",
- "txSpecfications" => "Speficiationer",
- "vcImage1" => "Billede 1",
- "vcImage2" => "Billede 2",
- "vcImage3" => "Billede 3",
- "iPrice" => "Pris",
- "iOfferPrice" => "Tilbuds Pris",
- "iStock" => "Lagerbeholdning",
- "iWeight" => "Vægt",
- "daCreated" => "Oprettet",
- "iIsActive" => "Aktiv",
- "iSortNum" => "Sortering"
- );
- $this->iProductID = -1;
- $this->vcProductNumber = "";
- $this->vcTitle = "";
- $this->txShortDesc = "";
- $this->txLongDesc = "";
- $this->txSpecfications = "";
- $this->vcImage1 = "";
- $this->vcImage2 = "";
- $this->vcImage3 = "";
- $this->iPrice = "";
- $this->iOfferPrice = "";
- $this->iStock = "";
- $this->iWeight = "";
- $this->daCreated = "";
- $this->iIsActive = 1;
- $this->iSortNum = 1;
- }
- /**
- * Get all data from table
- * @return array
- */
- public function getlist() {
- $sql = "SELECT * FROM shopproduct " .
- "WHERE iDeleted = 0 ORDER BY iProductID ASC";
- return $this->db->_fetch_array($sql);
- }
- /*
- * Get a single record
- * param int $iItemID
- */
- public function getitem($iProductID) {
- $this->iProductID = $iProductID;
- // $this->arrValues["arrProductGroups"] = $this->getGroupRelations();
- $sql = "SELECT * FROM shopproduct WHERE iProductID = ? AND iDeleted = 0";
- $row = $this->db->_fetch_array($sql, array($this->iProductID));
- foreach ($row as $key => $value) {
- $this->$key = $value;
- }
- }
- // public function getGroupRelations() {
- // $params = array($this->arrValues["iProductID"]);
- // $strSelect = "SELECT c.iCategoryID, c.vcTitle " .
- // "FROM shopcategory c " .
- // "JOIN shopcatprodrel x " .
- // "ON x.iCategoryID = c.iCategoryID " .
- // "WHERE x.iProductID = ? " .
- // "AND c.iDeleted = 0";
- // return $this->db->_fetch_array($strSelect, $params);
- // }
- /**
- * Save item
- */
- public function save() {
- // Hvis iProductID er større end 0 opdaterer functionen
- if ($this->iProductID > 0) {
- $params = array(
- $this->vcProductNumber,
- $this->vcTitle,
- $this->txShortDesc,
- $this->txLongDesc,
- $this->txSpecfications,
- $this->vcImage1,
- $this->vcImage2,
- $this->vcImage3,
- $this->iPrice,
- $this->iOfferPrice,
- $this->iStock,
- $this->iWeight,
- $this->daCreated,
- $this->iIsActive,
- $this->iSortNum,
- $this->iProductID
- );
- $sql = "UPDATE shopproduct SET " .
- "vcProductNumber = ?, " .
- "vcTitle = ?, " .
- "txShortDesc = ?, " .
- "txLongDesc = ?, " .
- "txSpecfications = ?, " .
- "vcImage1 = ?, " .
- "vcImage2 = ?, " .
- "vcImage3 = ?, " .
- "iPrice = ?, " .
- "iOfferPrice = ?, " .
- "iStock = ?, " .
- "iWeight = ?, " .
- "daCreated = ?, " .
- "iIsActive = ?, " .
- "iSortNum = ? " .
- "WHERE iProductID = ?";
- // _query sender et array af data til db
- $this->db->_query($sql, $params);
- return $this->iProductID;
- } else {
- // Når iProductID er under 0 skal der laves nyt produkt
- $params = array(
- $this->vcProductNumber,
- $this->vcTitle,
- $this->txShortDesc,
- $this->txLongDesc,
- $this->txSpecfications,
- $this->vcImage1,
- $this->vcImage2,
- $this->vcImage3,
- $this->iPrice,
- $this->iOfferPrice,
- $this->iStock,
- $this->iWeight,
- $this->daCreated,
- $this->iIsActive,
- $this->iSortNum
- );
- foreach ($params as $a){
- echo $a."<br>";
- }
- $sql = "INSERT INTO shopproduct (" .
- "vcProductNumber, " .
- "vcTitle, " .
- "txShortDesc, " .
- "txLongDesc, " .
- "txSpecfications, " .
- "vcImage1, " .
- "vcImage2, " .
- "vcImage3, " .
- "iPrice, " .
- "iOfferPrice, " .
- "iStock, " .
- "iWeight, " .
- "daCreated, " .
- "iIsActive, " .
- "iSortNum) " .
- "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
- // _query sender data array til db
- $this->db->_query($sql, $params);
- // returnere det sidste indsatte id
- return $this->db->_getinsertid();
- }
- // $iProductID = array(
- // $this->iProductID,
- // $this->vcProductNumber,
- // $this->vcTitle,
- // $this->txShortDesc,
- // $this->txLongDesc,
- // $this->txSpecfications,
- // $this->vcImage1,
- // $this->vcImage2,
- // $this->vcImage3,
- // $this->iPrice,
- // $this->iOfferPrice,
- // $this->iStock,
- // $this->iWeight,
- // $this->daCreated,
- // $this->iIsActive,
- // $this->iSortNum
- // );
- //
- //
- // /* Remove all group relations for the product */
- // $params = array($iProductID);
- // $strDelete = "DELETE FROM shopcatprodrel WHERE iProductID = ?";
- // $this->db->_query($strDelete, $params);
- //
- // /* Create arguments for post filtering */
- // $args = array(
- // "arrProductGroups" => array(
- // "filter" => FILTER_VALIDATE_INT,
- // "flags" => FILTER_REQUIRE_ARRAY
- // )
- // );
- // $arrInputVal = filter_input_array(INPUT_POST, $args);
- //
- // /* Save user related groups if any */
- // if(count($arrInputVal["arrProductGroups"])) {
- // $arrValues = array_values($arrInputVal["arrProductGroups"]);
- // foreach($arrValues as $value) {
- // $params = array($iProductID, $value);
- // $strInsert = "INSERT INTO shopcatprodrel(iProductID, iCategoryID) VALUES(?,?)";
- // $this->db->_query($strInsert,$params);
- // }
- // }
- //
- // return $iProductID;
- }
- /**
- * Opdatere user og sætter user til at være "slettet" (iDeleted til 1)
- */
- public function delete() {
- $params = array($this->iProductID);
- $sql = "UPDATE shopproduct SET iDeleted = 1 WHERE iProductID = ?";
- $this->db->_query($sql, $params);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement