Example #1
0
    public static function get_shortcut($id)
    {
        lDb::connect();
        do {
            if (isset($parent_id)) {
                $query = '
						SELECT parent_id, name
						FROM category
						WHERE self_id=\'' . $parent_id . '\';
						';
            } else {
                $query = '
						SELECT parent_id, name
						FROM category
						WHERE self_id=\'' . $id . '\';
						';
            }
            $result = mysql_query($query);
            while ($row = mysql_fetch_assoc($result)) {
                $return[] = $row;
                $parent_id = $row['parent_id'];
            }
        } while ($parent_id != 0);
        lDb::close();
        return $return;
    }
Example #2
0
 public static function connect()
 {
     if (!(self::$db = mysql_connect(self::$db_host, self::$db_user, self::$db_pass))) {
         echo "Database connection error.";
     } else {
         mysql_select_db('adm_webshop', self::$db);
     }
 }
Example #3
0
    public static function get_product($product_id)
    {
        lDb::connect();
        /* get product basic datas
         *****************************/
        $query = '
				SELECT *
				FROM product
				WHERE id=\'' . $product_id . '\';
				';
        $result = mysql_query($query);
        while ($row = mysql_fetch_assoc($result)) {
            $product['product'][] = $row;
        }
        /* get all photos of the products
         ***********************************/
        $query = '
				SELECT *
				FROM product_photo
				WHERE product_id=\'' . $product_id . '\';
				';
        $result = mysql_query($query);
        while ($row = mysql_fetch_assoc($result)) {
            $photo['photo'][] = $row;
        }
        /* get all downloads of the products
         ***********************************/
        $query = '
				SELECT *
				FROM product_download
				WHERE product_id=\'' . $product_id . '\';
				';
        $result = mysql_query($query);
        while ($row = mysql_fetch_assoc($result)) {
            $download['download'][] = $row;
        }
        lDb::close();
        if (!empty($product) and !empty($photo) and !empty($download)) {
            $return = array_merge($product, $photo, $download);
        } elseif (!empty($product) and !empty($photo)) {
            $return = array_merge($product, $photo);
        } elseif (!empty($product)) {
            $return = $product;
        }
        return $return;
    }
Example #4
0
    public function set_order()
    {
        if (isset($_SESSION['cart'])) {
            lDb::connect();
            // get the count of the orders to create new id
            $query = 'SELECT COUNT(*) as id
					 FROM `order`;';
            $result = mysql_query($query);
            echo mysql_error();
            while ($row = mysql_fetch_assoc($result)) {
                $id = $row['id'] + 1;
            }
            mysql_error();
            // insert basic data into order table
            $query = 'INSERT `order`
						(
							id,
							datetime,
							c_name,
							c_email,
							c_tel,
							c_country,
							c_postal_code,
							c_city,
							c_address,
							i_name,
							i_country,
							i_postal_code,
							i_city,
							i_address
						)
					 VALUES
						(
							\'' . $id . '\',
							NOW(),
							\'' . $_SESSION['c_name'] . '\',
							\'' . $_SESSION['c_email'] . '\',
							\'' . $_SESSION['c_tel'] . '\',
							\'' . $_SESSION['c_country'] . '\',
							\'' . $_SESSION['c_postal_code'] . '\',
							\'' . $_SESSION['c_city'] . '\',
							\'' . $_SESSION['c_address'] . '\',
							\'' . $_SESSION['i_name'] . '\',
							\'' . $_SESSION['i_country'] . '\',
							\'' . $_SESSION['i_postal_code'] . '\',
							\'' . $_SESSION['i_city'] . '\',
							\'' . $_SESSION['i_address'] . '\'
						);';
            if (!mysql_query($query)) {
                return 'Cannot insert basic order data into database.';
            }
            // insert products and amounts into order_product
            $array_end = count($_SESSION['cart']) - 1;
            // multiple insert
            if ($array_end > 0) {
                $query = 'INSERT order_product
						(
							order_id,
							product_id,
							quantity
						)
					 VALUES ';
                for ($j = 0; $j <= count($_SESSION['cart']) - 1; $j++) {
                    $query .= '	(
							\'' . $id . '\',
							\'' . $_SESSION['cart'][$j]['pid'] . '\',
						 	\'' . $_SESSION['cart'][$j]['q'] . '\'
							)';
                    if ($j < $array_end) {
                        $query .= ',';
                    } else {
                        $query .= ';';
                    }
                }
            } elseif ($array_end == 0) {
                $query = 'INSERT order_product
								(
									order_id,
									product_id,
									quantity
								)
							 VALUES
								(
									\'' . $id . '\',
									\'' . $_SESSION['cart'][0]['pid'] . '\',
									\'' . $_SESSION['cart'][0]['pid'] . '\'
								);';
            }
            if (!mysql_query($query)) {
                lDb::close();
                return 0;
                die('Cannot insert order products into database.');
            } else {
                lDb::close();
                return 1;
            }
        }
    }