Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 8.06 KB | None | 0 0
  1. <?php
  2.  
  3. class shopproduct {
  4.     private $db;
  5.     public $iProductID;
  6.     public $vcProductNumber;
  7.     public $vcTitle;
  8.     public $txShortDesc;
  9.     public $txLongDesc;
  10.     public $txSpecfications;
  11.     public $vcImage1;
  12.     public $vcImage2;
  13.     public $vcImage3;
  14.     public $iPrice;
  15.     public $iOfferPrice;
  16.     public $iStock;
  17.     public $iWeight;
  18.     public $daCreated;
  19.     public $iIsActive;
  20.     public $iDeleted;
  21.     public $iSortNum;
  22.  
  23.     public $arrColumns = array();
  24.     public $arrLabels = array();
  25.     public $arrValues = array();
  26.  
  27.     public function __construct() {
  28.         global $db;
  29.         $this->db = $db;
  30.  
  31.         $this->arrColumns = array(
  32.             "iProductID" => "ID",
  33.             "vcProductNumber" => "Produkt Nummer",
  34.             "vcTitle" => "Titel",
  35.             "txShortDesc" => "Kort Beskrivelse",
  36.             "txLongDesc" => "Lang Beskrivelse",
  37.             "txSpecfications" => "Speficiationer",
  38.             "vcImage1" => "Billede 1",
  39.             "vcImage2" => "Billede 2",
  40.             "vcImage3" => "Billede 3",
  41.             "iPrice" => "Pris",
  42.             "iOfferPrice" => "Tilbuds Pris",
  43.             "iStock" => "Lagerbeholdning",
  44.             "iWeight" => "Vægt",
  45.             "daCreated" => "Oprettet",
  46.             "iIsActive" => "Aktiv",
  47.             "iSortNum" => "Sortering"
  48.         );
  49.  
  50.         $this->iProductID = -1;
  51.         $this->vcProductNumber = "";
  52.         $this->vcTitle = "";
  53.         $this->txShortDesc = "";
  54.         $this->txLongDesc = "";
  55.         $this->txSpecfications = "";
  56.         $this->vcImage1 = "";
  57.         $this->vcImage2 = "";
  58.         $this->vcImage3 = "";
  59.         $this->iPrice = "";
  60.         $this->iOfferPrice = "";
  61.         $this->iStock = "";
  62.         $this->iWeight = "";
  63.         $this->daCreated = "";
  64.         $this->iIsActive = 1;
  65.         $this->iSortNum = 1;
  66.  
  67.     }
  68.  
  69.     /**
  70.      * Get all data from table
  71.      * @return array
  72.      */
  73.     public function getlist() {
  74.         $sql = "SELECT * FROM shopproduct " .
  75.             "WHERE iDeleted = 0 ORDER BY iProductID ASC";
  76.         return $this->db->_fetch_array($sql);
  77.     }
  78.  
  79.     /*
  80.      * Get a single record
  81.      * param int $iItemID
  82.      */
  83.     public function getitem($iProductID) {
  84.         $this->iProductID = $iProductID;
  85. //        $this->arrValues["arrProductGroups"] = $this->getGroupRelations();
  86.         $sql = "SELECT * FROM shopproduct WHERE iProductID = ? AND iDeleted = 0";
  87.         $row = $this->db->_fetch_array($sql, array($this->iProductID));
  88.  
  89.         foreach ($row as $key => $value) {
  90.             $this->$key = $value;
  91.         }
  92.     }
  93.  
  94. //    public function getGroupRelations() {
  95. //        $params = array($this->arrValues["iProductID"]);
  96. //        $strSelect = "SELECT c.iCategoryID, c.vcTitle " .
  97. //                    "FROM shopcategory c " .
  98. //                    "JOIN shopcatprodrel x " .
  99. //                    "ON x.iCategoryID = c.iCategoryID " .
  100. //                    "WHERE x.iProductID = ? " .
  101. //                    "AND c.iDeleted = 0";
  102. //        return $this->db->_fetch_array($strSelect, $params);
  103. //    }
  104.  
  105.     /**
  106.      * Save item
  107.      */
  108.     public function save() {
  109.         //        Hvis iProductID er større end 0 opdaterer functionen
  110.         if ($this->iProductID > 0) {
  111.             $params = array(
  112.                 $this->vcProductNumber,
  113.                 $this->vcTitle,
  114.                 $this->txShortDesc,
  115.                 $this->txLongDesc,
  116.                 $this->txSpecfications,
  117.                 $this->vcImage1,
  118.                 $this->vcImage2,
  119.                 $this->vcImage3,
  120.                 $this->iPrice,
  121.                 $this->iOfferPrice,
  122.                 $this->iStock,
  123.                 $this->iWeight,
  124.                 $this->daCreated,
  125.                 $this->iIsActive,
  126.                 $this->iSortNum,
  127.                 $this->iProductID
  128.             );
  129.  
  130.             $sql = "UPDATE shopproduct SET " .
  131.                 "vcProductNumber = ?, " .
  132.                 "vcTitle = ?, " .
  133.                 "txShortDesc = ?, " .
  134.                 "txLongDesc = ?, " .
  135.                 "txSpecfications = ?, " .
  136.                 "vcImage1 = ?, " .
  137.                 "vcImage2 = ?, " .
  138.                 "vcImage3 = ?, " .
  139.                 "iPrice = ?, " .
  140.                 "iOfferPrice = ?, " .
  141.                 "iStock = ?, " .
  142.                 "iWeight = ?, " .
  143.                 "daCreated = ?, " .
  144.                 "iIsActive = ?, " .
  145.                 "iSortNum = ? " .
  146.                 "WHERE iProductID = ?";
  147.  
  148. //            _query sender et array af data til db
  149.             $this->db->_query($sql, $params);
  150.             return $this->iProductID;
  151.         } else {
  152. //            Når iProductID er under 0 skal der laves nyt produkt
  153.             $params = array(
  154.                 $this->vcProductNumber,
  155.                 $this->vcTitle,
  156.                 $this->txShortDesc,
  157.                 $this->txLongDesc,
  158.                 $this->txSpecfications,
  159.                 $this->vcImage1,
  160.                 $this->vcImage2,
  161.                 $this->vcImage3,
  162.                 $this->iPrice,
  163.                 $this->iOfferPrice,
  164.                 $this->iStock,
  165.                 $this->iWeight,
  166.                 $this->daCreated,
  167.                 $this->iIsActive,
  168.                 $this->iSortNum
  169.             );
  170.             foreach ($params as $a){
  171.                 echo $a."<br>";
  172.             }
  173.             $sql = "INSERT INTO shopproduct (" .
  174.                 "vcProductNumber, " .
  175.                 "vcTitle, " .
  176.                 "txShortDesc, " .
  177.                 "txLongDesc, " .
  178.                 "txSpecfications, " .
  179.                 "vcImage1, " .
  180.                 "vcImage2, " .
  181.                 "vcImage3, " .
  182.                 "iPrice, " .
  183.                 "iOfferPrice, " .
  184.                 "iStock, " .
  185.                 "iWeight, " .
  186.                 "daCreated, " .
  187.                 "iIsActive, " .
  188.                 "iSortNum) " .
  189.                 "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  190.  
  191. //            _query sender data array til db
  192.             $this->db->_query($sql, $params);
  193. //            returnere det sidste indsatte id
  194.             return $this->db->_getinsertid();
  195.         }
  196.  
  197. //        $iProductID = array(
  198. //            $this->iProductID,
  199. //            $this->vcProductNumber,
  200. //            $this->vcTitle,
  201. //            $this->txShortDesc,
  202. //            $this->txLongDesc,
  203. //            $this->txSpecfications,
  204. //            $this->vcImage1,
  205. //            $this->vcImage2,
  206. //            $this->vcImage3,
  207. //            $this->iPrice,
  208. //            $this->iOfferPrice,
  209. //            $this->iStock,
  210. //            $this->iWeight,
  211. //            $this->daCreated,
  212. //            $this->iIsActive,
  213. //            $this->iSortNum
  214. //        );
  215. //
  216. //
  217. //        /* Remove all group relations for the product */
  218. //        $params = array($iProductID);
  219. //        $strDelete = "DELETE FROM shopcatprodrel WHERE iProductID = ?";
  220. //        $this->db->_query($strDelete, $params);
  221. //
  222. //        /* Create arguments for post filtering */
  223. //        $args = array(
  224. //            "arrProductGroups" => array(
  225. //                "filter" => FILTER_VALIDATE_INT,
  226. //                "flags" => FILTER_REQUIRE_ARRAY
  227. //            )
  228. //        );
  229. //        $arrInputVal = filter_input_array(INPUT_POST, $args);
  230. //
  231. //        /* Save user related groups if any */
  232. //        if(count($arrInputVal["arrProductGroups"])) {
  233. //            $arrValues = array_values($arrInputVal["arrProductGroups"]);
  234. //            foreach($arrValues as $value) {
  235. //                $params = array($iProductID, $value);
  236. //                $strInsert = "INSERT INTO shopcatprodrel(iProductID, iCategoryID) VALUES(?,?)";
  237. //                $this->db->_query($strInsert,$params);
  238. //            }
  239. //        }
  240. //
  241. //        return $iProductID;
  242.  
  243.  
  244.     }
  245.  
  246.  
  247.     /**
  248.      * Opdatere user og sætter user til at være "slettet" (iDeleted til 1)
  249.      */
  250.     public function delete() {
  251.         $params = array($this->iProductID);
  252.         $sql = "UPDATE shopproduct SET iDeleted = 1 WHERE iProductID = ?";
  253.         $this->db->_query($sql, $params);
  254.     }
  255.  
  256.  
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement