Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * ../../ext/pok4/shop/ext.php
- *
- * @package default
- */
- namespace ext\pok4;
- use \PDO;
- use \ArrayIterator;
- if (count(get_included_files()) == 1) exit("Direct access not permitted."); //Don't edit
- require_once('ext/pok4/shop/stripe/init.php'); //stripe api library
- //Your Extension Script
- class shop extends \App\Controllers\BaseController {
- public function __construct() {
- parent::__construct();
- /*EPAY API*/
- #DEMO: https://demo.epay.bg/
- #LIVE: https://www.epay.bg/
- $this->submit_url = 'https://demo.epay.bg/';
- # XXX Secret word with which merchant make CHECKSUM on the ENCODED packet
- $this->epay_secret = 'QHW3EPHF0AXEWBR0C7ZJVV658XUDRH0FXOB5FYZCN81B3U1IUSS7R61M7M1X1GFI';
- $this->epay_client = 'D188604865'; //Client ID
- /*END EPAY API*/
- /*FB Comments API*/
- $this->fb_comments_enable = true; //set to false/true to off/on the comments
- $this->fb_appid = "157924284418157";
- /*STRIPE API credentials*/
- $this->stripe_api_key = "pk_test_51Muxv1CWj0Ml57h8hw2j0f9OKaHgQMaeYFwZqxwt5k80W4CbAobIU1wfVrahEh6vnhcthyn29i74u4O8nQ6FjDs900CEUdJy2d";
- $this->stripe_secret_key = "sk_test_51Muxv1CWj0Ml57h86e3s20ahaNkrunwTb0bmf23Ja58BJSXVYUQpdCJrqHpxBQ39d36TggapEaRb9GIV7hWvJBcy00gcnXQwCg";
- }
- /*for total price calculation*/
- public function compute_multi($v1, $v2){
- return $v1*$v2;
- }
- /*For EasyPay api*/
- public function hmac($algo,$data,$passwd){
- /* md5 and sha1 only */
- $algo=strtolower($algo);
- $p=array('md5'=>'H32','sha1'=>'H40');
- if(strlen($passwd)>64) $passwd=pack($p[$algo],$algo($passwd));
- if(strlen($passwd)<64) $passwd=str_pad($passwd,64,chr(0));
- $ipad=substr($passwd,0,64) ^ str_repeat(chr(0x36),64);
- $opad=substr($passwd,0,64) ^ str_repeat(chr(0x5C),64);
- return($algo($opad.pack($p[$algo],$algo($ipad.$data))));
- }
- public function ajax() {
- //stripe api
- if(str_contains($_SERVER['REQUEST_URI'],'?stripe=1')) {
- // Set API key (secret)
- $stripe = new \Stripe\StripeClient($this->stripe_secret_key);
- $response = array(
- 'status' => 0,
- 'error' => array(
- 'message' => 'Invalid Request!'
- )
- );
- if ($_SERVER['REQUEST_METHOD'] == 'POST') {
- $input = file_get_contents('php://input');
- $request = json_decode($input);
- }
- if (json_last_error() !== JSON_ERROR_NONE) {
- http_response_code(400);
- echo json_encode($response);
- exit;
- }
- if(!empty($request->createCheckoutSession)){
- //main things about products
- $get = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$this->user_id."'");
- $arr = [];
- $arr2 = []; //holds price
- $arr3 = []; //holds quantity
- $price_type = "";//globalize
- while($row = $get->fetch(PDO::FETCH_ASSOC)) {
- $arr[] = $row['product_id'];
- $get_prod = $this->db->query("SELECT product_price,product_price_type,product_promo_price FROM ".$this->argos_db_prefix."shop WHERE id='".$row['product_id']."'");
- $row2 = $get_prod->fetch(PDO::FETCH_ASSOC);
- if($row2['product_promo_price'] > 0) {
- $arr2[] = $row2['product_promo_price'];
- } else {
- $arr2[] = $row2['product_price'];
- }
- $arr3[] = $row['product_quantity'];
- $price_type = $row2['product_price_type'];
- }
- $string = "";//globalize
- foreach($arr as $v) {
- $string .= "$v,";
- }
- $total_price = array_sum(array_map("self::compute_multi", $arr2, $arr3));
- $product_ids = rtrim($string, ',');
- // Convert product price to cent
- $stripeAmount = round($total_price*100, 2);
- // Create new Checkout Session for the order
- try {
- $checkout_session = $stripe->checkout->sessions->create([
- 'line_items' => [[
- 'price_data' => [
- 'product_data' => [
- 'name' => 'Products IDS:('.$product_ids.')', //name of product
- 'metadata' => [
- 'pro_id' => ''.$product_ids.'' //product ids
- ]
- ],
- 'unit_amount' => $stripeAmount, //price amount
- 'currency' => ''.$price_type.'', //price type
- ],
- 'quantity' => 1
- ]],
- 'mode' => 'payment',
- 'success_url' => url().'/ajax/ext/pok4/shop?schecker=1&session_id={CHECKOUT_SESSION_ID}&user_id='.$this->user_id.'',
- 'cancel_url' => url().'/pages/cart?stripe_cancel',
- ]);
- } catch(Exception $e) {
- $api_error = $e->getMessage();
- }
- if(empty($api_error) && $checkout_session){
- $response = array(
- 'status' => 1,
- 'message' => 'Checkout Session created successfully!',
- 'sessionId' => $checkout_session->id
- );
- }else{
- $response = array(
- 'status' => 0,
- 'error' => array(
- 'message' => 'Checkout Session creation failed! '.$api_error
- )
- );
- }
- } ;
- // Return response
- echo json_encode($response);
- return;
- }
- if(str_contains($_SERVER['REQUEST_URI'],'?schecker=1&session_id')) {
- $payment_id = $statusMsg = '';
- $status = 'error';
- // Check whether stripe checkout session is not empty
- if(!empty($_GET['session_id'])){
- $session_id = $_GET['session_id'];
- // Set API key
- $stripe = new \Stripe\StripeClient($this->stripe_secret_key);
- // Fetch the Checkout Session to display the JSON result on the success page
- try {
- $checkout_session = $stripe->checkout->sessions->retrieve($session_id);
- } catch(Exception $e) {
- $api_error = $e->getMessage();
- }
- if(empty($api_error) && $checkout_session){
- // Retrieve the details of a PaymentIntent
- try {
- $paymentIntent = $stripe->paymentIntents->retrieve($checkout_session->payment_intent);
- } catch (\Stripe\Exception\ApiErrorException $e) {
- $api_error = $e->getMessage();
- }
- if(empty($api_error) && $paymentIntent){
- // Check whether the payment was successful
- if(!empty($paymentIntent) && $paymentIntent->status == 'succeeded'){
- $user_id = (int)$_GET['user_id'];
- $this->db->query("UPDATE ".$this->argos_db_prefix."shop_pending_orders SET pay_status='Payed' WHERE user_id='".$user_id."' ORDER by id DESC LIMIT 1");
- //remove all products from basket when everything is ok
- $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
- //location reload (header)
- header("Refresh:0; url=".url()."/pages/cart?stripe_succ");
- }else{
- $statusMsg = "Transaction has been failed!";
- }
- }else{
- $statusMsg = "Unable to fetch the transaction details! $api_error";
- }
- }else{
- $statusMsg = "Invalid Transaction! $api_error";
- }
- }else{
- $statusMsg = "Invalid Request!";
- }
- return;
- }
- //end stripe api
- //extension ajax calls
- if(is_ajax()) {
- //set solved status
- if(isset($_POST['status_set']) && $this->is_admin) {
- $order_id = (int)$_POST['order_id'];
- //get products ids by order id
- $get = $this->db->query("SELECT product_ids,pay_status FROM ".$this->argos_db_prefix."shop_pending_orders WHERE id='".$order_id."'");
- $row = $get->fetch(PDO::FETCH_ASSOC);
- $product_id = $row['product_ids'];
- $pay_status = $row['pay_status'];
- if($pay_status == 'Solved') {
- echo $this->lang['ext_shop_already_solved'];
- return;
- }
- $strArr = explode(',', $product_id);
- foreach ($strArr as $e) {
- $keyValue = explode('=>', $e);
- $product_id_s = $keyValue[0];
- $quantity = $keyValue[1];
- $this->db->query("UPDATE ".$this->argos_db_prefix."shop SET product_availability=product_availability-".$quantity." WHERE id='".$product_id_s."'");
- $this->db->query("UPDATE ".$this->argos_db_prefix."shop SET product_buy_count=product_buy_count+".$quantity." WHERE id='".$product_id_s."'");
- }
- $this->db->query("UPDATE ".$this->argos_db_prefix."shop_pending_orders SET pay_status='Solved' WHERE id='".$order_id."'");
- echo $this->lang['ext_shop_success'];
- return;
- }
- //remove product from basket
- if(isset($_POST['removepid'])) {
- $userid = $this->user_id;
- $pid = (int)$_POST['productid'];
- $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$userid."' AND product_id='".$pid."'");
- return;
- }
- //form 1 (standart delivery - couriers)
- if(isset($_POST['form_1'])) {
- $phone = $_POST['your_phone'];
- $address = $_POST['delivery_address'];
- $name = $_POST['your_name'];
- $pay_status = 'Not payed';
- $method = $this->lang['ext_shop_delivery_method'];
- $user_id = $this->user_id;
- //get products in basket
- $get = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
- $arr = [];
- while($row = $get->fetch(PDO::FETCH_ASSOC)) {
- $arr[] = $row['product_id']. '=>'.$row['product_quantity'];
- $get_prod = $this->db->query("SELECT product_price,product_promo_price FROM ".$this->argos_db_prefix."shop WHERE id='".$row['product_id']."'");
- $row2 = $get_prod->fetch(PDO::FETCH_ASSOC);
- if($row2['product_promo_price'] > 0) {
- $arr2[] = $row2['product_promo_price'];
- } else {
- $arr2[] = $row2['product_price'];
- }
- $arr3[] = $row['product_quantity'];
- }
- $total_price = array_sum(array_map("self::compute_multi", $arr2, $arr3));
- $string = "";//globalize
- foreach($arr as $v) {
- $string .= "$v,";
- }
- $product_ids = rtrim($string, ',');
- $go = $this->db->prepare("INSERT INTO ".$this->argos_db_prefix."shop_pending_orders (product_ids,user_id,address,phone,method_for_pay,pay_status,full_name,date,total_price) VALUES(?,?,?,?,?,?,?,?,?)");
- $go->bindParam(1, $product_ids, PDO::PARAM_STR);
- $go->bindParam(2, $user_id, PDO::PARAM_STR);
- $go->bindParam(3, $address, PDO::PARAM_STR);
- $go->bindParam(4, $phone, PDO::PARAM_STR);
- $go->bindParam(5, $method, PDO::PARAM_STR);
- $go->bindParam(6, $pay_status, PDO::PARAM_STR);
- $go->bindParam(7, $name, PDO::PARAM_STR);
- $go->bindParam(8, time(),PDO::PARAM_STR);
- $go->bindParam(9, $total_price,PDO::PARAM_STR);
- $go->execute();
- //remove all products from basket
- $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
- echo $this->lang['ext_shop_submit_succ'];
- return;
- }
- //form 2 (standart delivery - couriers) / payed with current balance
- if(isset($_POST['form_2'])) {
- $phone = $_POST['your_phone'];
- $address = $_POST['delivery_address'];
- $name = $_POST['your_name'];
- $pay_status = 'Payed';
- $method = $this->lang['ext_shop_delivery_method_f2'];
- $user_id = $this->user_id;
- //check if user have money to pay
- $check = $this->db->query("SELECT price FROM `".$this->forum_db."`.".$this->forum_db_prefix."_users where user_id='".$user_id."'");
- $row = $check->fetch(PDO::FETCH_ASSOC);
- $curr_balance = $row['price']; //phpbb3 column from users table
- //get products in basket
- $get = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
- $arr = [];
- $arr2 = []; //holds price
- $arr3 = []; //holds quantity
- while($row = $get->fetch(PDO::FETCH_ASSOC)) {
- $arr[] = $row['product_id']. '=>'.$row['product_quantity'];
- $get_prod = $this->db->query("SELECT product_price,product_promo_price FROM ".$this->argos_db_prefix."shop WHERE id='".$row['product_id']."'");
- $row2 = $get_prod->fetch(PDO::FETCH_ASSOC);
- if($row2['product_promo_price'] > 0) {
- $arr2[] = $row2['product_promo_price'];
- } else {
- $arr2[] = $row2['product_price'];
- }
- $arr3[] = $row['product_quantity'];
- }
- $string = "";//globalize
- foreach($arr as $v) {
- $string .= "$v,";
- }
- $total_price = array_sum(array_map("self::compute_multi", $arr2, $arr3));
- if($curr_balance < $total_price) {
- echo ''.$this->lang['ext_shop_you_dont_have'].' ('.$total_price.')';
- return;
- }
- //remove price from user
- $check = $this->db->query("UPDATE `".$this->forum_db."`.".$this->forum_db_prefix."_users set price=price-$total_price where user_id='".$user_id."'");
- $product_ids = rtrim($string, ',');
- $go = $this->db->prepare("INSERT INTO ".$this->argos_db_prefix."shop_pending_orders (product_ids,user_id,address,phone,method_for_pay,pay_status,full_name,date,total_price) VALUES(?,?,?,?,?,?,?,?,?)");
- $go->bindParam(1, $product_ids, PDO::PARAM_STR);
- $go->bindParam(2, $user_id, PDO::PARAM_STR);
- $go->bindParam(3, $address, PDO::PARAM_STR);
- $go->bindParam(4, $phone, PDO::PARAM_STR);
- $go->bindParam(5, $method, PDO::PARAM_STR);
- $go->bindParam(6, $pay_status, PDO::PARAM_STR);
- $go->bindParam(7, $name, PDO::PARAM_STR);
- $go->bindParam(8, time(),PDO::PARAM_STR);
- $go->bindParam(9, $total_price,PDO::PARAM_STR);
- $go->execute();
- //remove all products from basket
- $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
- echo $this->lang['ext_shop_submit_succ'];
- return;
- }
- //form 3 (standart delivery - couriers) / payed with epay
- if(isset($_POST['form_3'])) {
- $phone = $_POST['your_phone'];
- $address = $_POST['delivery_address'];
- $name = $_POST['your_name'];
- $pay_status = 'Not payed';
- $this->epay_invoice = mt_rand(10000, 10000000); // # XXX Invoice (facture number)
- $method = $this->lang['ext_shop_delivery_method_f3']." (".$this->epay_invoice.")";
- $user_id = $this->user_id;
- //get products in basket
- $get = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
- $arr = [];
- $arr2 = []; //holds price
- $arr3 = []; //holds quantity
- while($row = $get->fetch(PDO::FETCH_ASSOC)) {
- $arr[] = $row['product_id']. '=>'.$row['product_quantity'];
- $get_prod = $this->db->query("SELECT product_price,product_promo_price FROM ".$this->argos_db_prefix."shop WHERE id='".$row['product_id']."'");
- $row2 = $get_prod->fetch(PDO::FETCH_ASSOC);
- if($row2['product_promo_price'] > 0) {
- $arr2[] = $row2['product_promo_price'];
- } else {
- $arr2[] = $row2['product_price'];
- }
- $arr3[] = $row['product_quantity'];
- }
- $string = "";//globalize
- foreach($arr as $v) {
- $string .= "$v,";
- }
- $total_price = array_sum(array_map("self::compute_multi", $arr2, $arr3));
- $product_ids = rtrim($string, ',');
- $go = $this->db->prepare("INSERT INTO ".$this->argos_db_prefix."shop_pending_orders (product_ids,user_id,address,phone,method_for_pay,pay_status,full_name,date,total_price) VALUES(?,?,?,?,?,?,?,?,?)");
- $go->bindParam(1, $product_ids, PDO::PARAM_STR);
- $go->bindParam(2, $user_id, PDO::PARAM_STR);
- $go->bindParam(3, $address, PDO::PARAM_STR);
- $go->bindParam(4, $phone, PDO::PARAM_STR);
- $go->bindParam(5, $method, PDO::PARAM_STR);
- $go->bindParam(6, $pay_status, PDO::PARAM_STR);
- $go->bindParam(7, $name, PDO::PARAM_STR);
- $go->bindParam(8, time(),PDO::PARAM_STR);
- $go->bindParam(9, $total_price,PDO::PARAM_STR);
- $go->execute();
- //remove all products from basket
- $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
- /*EPAY API*/
- $this->exp_date = date('d.m.Y', strtotime('+1 day',time())); # XXX Expiration date (1 day)
- $this->descr = 'payment for product IDS: '.$product_ids.' (total price: '.$total_price.')';# XXX Description
- $this->URL_REDIRECT = url()."/pages/cart?easyp_success"; //redirect if success
- $this->CANCEL_URL = url()."/pages/cart?easyp_cancel"; //redirect if is cancel
- $this->epay_data = <<<DATA
- MIN={$this->epay_client}
- INVOICE={$this->epay_invoice}
- AMOUNT={$total_price}
- EXP_TIME={$this->exp_date}
- DESCR={$this->descr}
- DATA;
- $this->ENCODED = base64_encode($this->epay_data);
- $this->CHECKSUM = $this->hmac('sha1', $this->ENCODED, $this->epay_secret); # XXX SHA-1 algorithm REQUIRED
- /*EPAY API*/
- echo $this->lang['ext_shop_submit_succ'].'<br/>
- '.$this->lang['ext_shop_you_can_pay'].'<b>'.$this->epay_invoice.'</b> '.$this->lang['ext_shop_future'].')<br/>
- <form action="'.$this->submit_url.'" method="POST" target="_blank">
- <input type=hidden name="PAGE" value="paylogin">
- <input type=hidden name="ENCODED" value="'.$this->ENCODED.'">
- <input type=hidden name="CHECKSUM" value="'.$this->CHECKSUM.'">
- <input type=hidden name="URL_OK" value="'.$this->URL_REDIRECT.'">
- <input type=hidden name="URL_CANCEL" value="'.$this->CANCEL_URL.'">
- <INPUT type=image name="submit" src="ext/pok4/shop/template/img/logo-easypay-sm.svg" style="width: 50px;height:50px"/>
- </form>
- ';
- return;
- }
- //form 4 (standart delivery - couriers) / payed with stripe
- if(isset($_POST['form_4'])) {
- $phone = $_POST['your_phone'];
- $address = $_POST['delivery_address'];
- $name = $_POST['your_name'];
- $pay_status = 'Not payed';
- $method = $this->lang['ext_shop_delivery_method_f4'];
- $user_id = $this->user_id;
- //get products in basket
- $get = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."'");
- $arr = [];
- $arr2 = []; //holds price
- $arr3 = []; //holds quantity
- while($row = $get->fetch(PDO::FETCH_ASSOC)) {
- $arr[] = $row['product_id']. '=>'.$row['product_quantity'];
- $get_prod = $this->db->query("SELECT product_price,product_promo_price FROM ".$this->argos_db_prefix."shop WHERE id='".$row['product_id']."'");
- $row2 = $get_prod->fetch(PDO::FETCH_ASSOC);
- if($row2['product_promo_price'] > 0) {
- $arr2[] = $row2['product_promo_price'];
- } else {
- $arr2[] = $row2['product_price'];
- }
- $arr3[] = $row['product_quantity'];
- }
- $string = "";//globalize
- foreach($arr as $v) {
- $string .= "$v,";
- }
- $total_price = array_sum(array_map("self::compute_multi", $arr2, $arr3));
- $product_ids = rtrim($string, ',');
- $go = $this->db->prepare("INSERT INTO ".$this->argos_db_prefix."shop_pending_orders (product_ids,user_id,address,phone,method_for_pay,pay_status,full_name,date,total_price) VALUES(?,?,?,?,?,?,?,?,?)");
- $go->bindParam(1, $product_ids, PDO::PARAM_STR);
- $go->bindParam(2, $user_id, PDO::PARAM_STR);
- $go->bindParam(3, $address, PDO::PARAM_STR);
- $go->bindParam(4, $phone, PDO::PARAM_STR);
- $go->bindParam(5, $method, PDO::PARAM_STR);
- $go->bindParam(6, $pay_status, PDO::PARAM_STR);
- $go->bindParam(7, $name, PDO::PARAM_STR);
- $go->bindParam(8, time(),PDO::PARAM_STR);
- $go->bindParam(9, $total_price,PDO::PARAM_STR);
- $go->execute();
- echo $this->lang['ext_shop_submit_succ'].'<br/>
- '.$this->lang['ext_shop_you_can_pay2'].':<br/>
- <div id="paymentResponse" class="hidden"></div>
- <button class="stripe-button" id="payButton">
- <div class="spinner hidden" id="spinner"></div>
- <div id="buttonText" style="background:url(ext/pok4/shop/template/img/stripe.svg) no-repeat;width: 50px;height:50px;"> </div>
- </button>';
- echo $this->m->render(file_get_contents("ext/pok4/shop/template/stripe.js"),[
- 'api_key'=>$this->stripe_api_key,
- 'c_base_url'=>url(),
- ]);
- return;
- }
- //item quantity
- if(isset($_POST['set_quantity'])) {
- $item_quantity = $_POST['quantity'];
- $pid = (int)$_POST['product_id'];
- //get availability
- $get = $this->db->query("SELECT product_availability FROM ".$this->argos_db_prefix."shop WHERE id='".$pid."'");
- $row = $get->fetch(PDO::FETCH_ASSOC);
- //get current quantity
- $get2 = $this->db->query("SELECT product_quantity FROM ".$this->argos_db_prefix."shop_cart WHERE product_id='".$pid."'");
- $row2 = $get2->fetch(PDO::FETCH_ASSOC);
- //check
- if($row['product_availability'] < $row2['product_quantity']) {
- return;
- }
- if($item_quantity == '+1') {
- $this->db->query("UPDATE ".$this->argos_db_prefix."shop_cart SET product_quantity=product_quantity+1 WHERE product_id='".$pid."' AND user_id='".$this->user_id."'");
- } else {
- $this->db->query("UPDATE ".$this->argos_db_prefix."shop_cart SET product_quantity=product_quantity-1 WHERE product_id='".$pid."' AND user_id='".$this->user_id."'");
- }
- //return current quantity
- $go = $this->db->query("SELECT product_quantity,product_price,product_promo_price FROM ".$this->argos_db_prefix."shop_cart s INNER JOIN ".$this->argos_db_prefix."shop g ON g.id=s.product_id WHERE product_id='".$pid."' AND user_id='".$this->user_id."'");
- $row = $go->fetch(PDO::FETCH_ASSOC);
- if($row['product_quantity'] < 1) {
- if($row['product_promo_price'] > 0) {
- echo json_encode(array('product_quantity' => 1,'product_price'=>$row['product_promo_price']));
- } else {
- echo json_encode(array('product_quantity' => 1,'product_price'=>$row['product_price']));
- }
- $this->db->query("UPDATE ".$this->argos_db_prefix."shop_cart SET product_quantity=1 WHERE product_id='".$pid."' AND user_id='".$this->user_id."'");
- return;
- }
- if($row['product_promo_price'] > 0) {
- echo json_encode(array('product_quantity' => $row['product_quantity'],'product_price'=>$row['product_promo_price']));
- } else {
- echo json_encode(array('product_quantity' => $row['product_quantity'],'product_price'=>$row['product_price']));
- }
- return;
- }
- //vote / rating system
- if(isset($_POST['vote'])) {
- $user_ip = $_SERVER['REMOTE_ADDR'];
- $pid = (int)$_POST['productid'];
- //check if user is voted
- $go = $this->db->query("SELECT user_ip FROM ".$this->argos_db_prefix."shop_rating WHERE product_id='".$pid."' AND user_ip='".$user_ip."'");
- if($go->rowCount() > 0) {
- echo $this->lang['ext_shop_already_voted'];
- return;
- }
- $vote_type_now = $_POST['vote_type_now'];
- if($vote_type_now == "-1") {
- $this->db->query("UPDATE ".$this->argos_db_prefix."shop set product_rating = product_rating-1 WHERE id='".$pid."'");
- } else {
- $this->db->query("UPDATE ".$this->argos_db_prefix."shop set product_rating = product_rating+1 WHERE id='".$pid."'");
- }
- //add user ip to db for already vote check
- $this->db->query("INSERT INTO ".$this->argos_db_prefix."shop_rating (product_id,user_ip) VALUES('".$pid."','".$user_ip."')");
- //get current vote
- $go = $this->db->query("SELECT product_rating FROM ".$this->argos_db_prefix."shop WHERE id='".$pid."'");
- $row = $go->fetch(PDO::FETCH_ASSOC);
- echo $row['product_rating'];
- return;
- }
- //add to basket
- if(isset($_POST['addtobasket'])) {
- if($this->is_anonymous) {
- echo $this->lang['ext_shop_please_login'];
- return;
- }
- $pid = (int)$_POST['productid'];
- $user_id = $this->user_id;
- //check availability
- $check = $this->db->query("SELECT product_availability FROM ".$this->argos_db_prefix."shop WHERE id='".$pid."'");
- $row = $check->fetch(PDO::FETCH_ASSOC);
- if($row['product_availability'] == 0) {
- echo $this->lang['ext_shop_not_in_stock'];
- return;
- }
- //check if already exists
- $go = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart WHERE user_id='".$user_id."' AND product_id='".$pid."'");
- if($go->rowCount() > 0) {
- $this->db->query("UPDATE ".$this->argos_db_prefix."shop_cart SET product_quantity=product_quantity+1 WHERE user_id='".$user_id."' AND product_id='".$pid."'");
- } else {
- $this->db->query("INSERT INTO ".$this->argos_db_prefix."shop_cart (user_id,product_id,product_quantity) VALUES('".$user_id."','".$pid."','1')");
- }
- echo $this->lang['ext_shop_added_to_basket'];
- return;
- }
- //delete product
- if(isset($_POST['delete_product_id'])) {
- $id = (int)$_POST['delete_product_id'];
- //get product images
- $img = $this->db->query("SELECT product_images FROM ".$this->argos_db_prefix."shop WHERE id='".$id."'");
- $row = $img->fetch(PDO::FETCH_ASSOC);
- $imgs = $row['product_images'];
- $img_exp = explode(",",$imgs);
- foreach($img_exp as $v){
- //delete imgs
- unlink('ext/pok4/shop/product_images/'.$v);
- }
- $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop WHERE id='".$id."'");
- echo $this->lang['ext_shop_deleted'];
- return;
- }
- //product edit
- if(isset($_POST['edit_form'])) {
- $id = (int)$_POST['product_id'];
- $product_title = $_POST['product_title'];
- $product_price = $_POST['product_price'];
- $product_promo_price = $_POST['product_promo_price'];
- $product_price_type = $_POST['product_price_type'];
- $product_explain = $_POST['product_explain'];
- $product_availability = $_POST['product_availability'];
- //update db
- $go = $this->db->prepare("UPDATE ".$this->argos_db_prefix."shop SET product_title=?,product_price=?,product_promo_price=?,product_price_type=?,product_explain=?,product_availability=? WHERE id='".$id."'");
- $go->bindParam(1, $product_title, PDO::PARAM_STR);
- $go->bindParam(2, $product_price, PDO::PARAM_STR);
- $go->bindParam(3, $product_promo_price, PDO::PARAM_STR);
- $go->bindParam(4, $product_price_type, PDO::PARAM_STR);
- $go->bindParam(5, $product_explain, PDO::PARAM_STR);
- $go->bindParam(6, $product_availability, PDO::PARAM_STR);
- $go->execute();
- echo 'Success!';
- return;
- }
- //delete cat
- if(isset($_POST['cat_id'])) {
- $this->db->query("DELETE FROM ".$this->argos_db_prefix."shop_cats WHERE id='".$_POST['cat_id']."'");
- return;
- }
- //submit new product
- if(isset($_FILES['file']) && !empty($_POST['product_explain']) && !empty($_POST['product_title']) && !empty($_POST['product_cat']) && !empty($_POST['product_price_type']) && !empty($_POST['product_price'])) {
- $arr_files = "";
- foreach($_FILES['file']['tmp_name'] as $key => $tmp_name)
- {
- if(empty($_FILES['file']['tmp_name'][$key])) {
- continue;
- }
- $file_data = getimagesize($_FILES['file']['tmp_name'][$key]);
- if (is_array($file_data) && strpos($file_data['mime'], 'image') !== false) {
- $file_name = $key.$_FILES['file']['name'][$key];
- $file_size =$_FILES['file']['size'][$key];
- $file_tmp =$_FILES['file']['tmp_name'][$key];
- $file_type=$_FILES['file']['type'][$key];
- $arr_files .= time().$file_name.",";
- if(str_contains($file_name, ",")) {
- echo $this->lang['ext_shop_cannot_contain'];
- return;
- }
- move_uploaded_file($file_tmp,"ext/pok4/shop/product_images/".time().$file_name);
- }
- }
- //add product to db
- $string = rtrim($arr_files,',');
- $go = $this->db->prepare("INSERT INTO ".$this->argos_db_prefix."shop (product_title,product_date,product_price,product_promo_price,product_explain,product_buy_count,product_cat,product_images,product_rating,product_availability) VALUES(?,'".time()."',?,?,?,'0',?,?,'0',?)");
- $go->bindParam(1, $_POST['product_title'], PDO::PARAM_STR);
- $go->bindParam(2, $_POST['product_price'], PDO::PARAM_STR);
- $go->bindParam(3, $_POST['product_promo_price'], PDO::PARAM_STR);
- $go->bindParam(4, $_POST['product_explain'], PDO::PARAM_STR);
- $go->bindParam(5, $_POST['product_cat'], PDO::PARAM_STR);
- $go->bindParam(6, $string, PDO::PARAM_STR);
- $go->bindParam(7, $_POST['product_availability'], PDO::PARAM_STR);
- $go->execute();
- echo $this->lang['ext_shop_success'];
- return;
- } else {
- echo $this->lang['ext_shop_missing_input'];
- }
- }
- }
- public function admin_form() {
- if (strpos($_SERVER['REQUEST_URI'], 'apage=shop_config&add_cat=1') !== false) {
- return $this->add_cat();
- }
- if (strpos($_SERVER['REQUEST_URI'], 'apage=shop_config&add_product=1') !== false) {
- return $this->add_product();
- }
- if (strpos($_SERVER['REQUEST_URI'], 'apage=shop_config&product_list=1') !== false) {
- return $this->product_list();
- }
- if (strpos($_SERVER['REQUEST_URI'], 'apage=shop_config&queue_list=1') !== false) {
- return $this->queue_list();
- }
- if (strpos($_SERVER['REQUEST_URI'], 'apage=shop_config') !== false) {
- return $this->m->render(file_get_contents("ext/pok4/shop/template/shop_admin.html"),[
- 'current_url'=>url().$_SERVER['REQUEST_URI'],
- //lang definitions
- 'ext_shop_admin_expl'=>$this->lang['ext_shop_admin_expl'],
- 'ext_shop_add_category'=>$this->lang['ext_shop_add_category'],
- 'ext_shop_add_product'=>$this->lang['ext_shop_add_product'],
- 'ext_shop_product_list'=>$this->lang['ext_shop_product_list'],
- 'ext_shop_queue_list'=>$this->lang['ext_shop_queue_list'],
- ]);
- }
- }
- public function queue_list() { //ACP
- $results = $this->db->query("SELECT COUNT(`id`) FROM ".$this->argos_db_prefix."shop_pending_orders order by id DESC")->fetchColumn();
- if($results > 0) {
- $pagination = pagination($results, [
- 'get_vars' => [
- 'apage' => $_GET['apage'].'&queue_list=1',
- ],
- 'per_page' => 15, //how many results per page
- 'per_side' => 3,
- 'get_name' => 'page'
- ]);
- } else {
- //reset this variables to 0, to prevent errors
- $pagination['limit']['first'] = 0;
- $pagination['limit']['second'] = 0;
- }
- $get_results = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_pending_orders order by id DESC LIMIT {$pagination['limit']['first']}, {$pagination['limit']['second']}");
- $all_orders = []; //globalize
- if ($get_results->rowCount() > 0) {
- $order_appear = true; //we found results
- while ($row=$get_results->fetch(PDO::FETCH_ASSOC)) {
- $product_ids = $row['product_ids'];
- $order_date = date("d.m.Y, H:i",$row['date']);
- $user_id = $row['user_id'];
- $order_id = $row['id'];
- //get username by userid
- $get_name = $this->db->query("SELECT username FROM `".$this->forum_db."`.".$this->forum_db_prefix."_users where user_id='".$user_id."'");
- $row2=$get_name->fetch(PDO::FETCH_ASSOC);
- $username = $row2['username'];
- //other things
- $status = $row['pay_status'];
- $phone = $row['phone'];
- $address = $row['address'];
- $method = $row['method_for_pay'];
- $name = $row['full_name'];
- $total_price = $row['total_price'];
- $status_color = "black";//globalize
- if($status =='Solved') {
- $status_color = "green";
- }
- $strArr = explode(',', $product_ids);
- $string ="";//globalize
- foreach ($strArr as $e) {
- //re-format the details about products ids and quantity
- $keyValue = explode('=>', $e);
- $string .= '<a target="_blank" href="' .url().'/pages/shop/?view_item='. $keyValue[0] . '">' . $keyValue[0] . '</a> => '.$keyValue[1].' '.$this->lang['ext_shop_quantity'].',';
- }
- $products_renew = rtrim($string,',');
- $all_orders[] = ['total_price'=>$total_price,'products'=>$products_renew,'order_status_color'=>$status_color,'order_id'=>$order_id,'order_date'=>$order_date,'order_userid'=>$user_id,'order_username'=>$username,'order_status'=>$status,'user_fullname'=>$name,'user_address'=>$address,'user_phone'=>$phone,'method'=>$method];
- }
- } else {
- $order_appear = false; //we not found results
- }
- return $this->m->render(file_get_contents("ext/pok4/shop/template/queue_list_admin.html"), [
- //variables
- 'all_orders'=> new ArrayIterator($all_orders),
- 'ext_shop_pagination'=>($order_appear) ? $pagination['output'] : '',
- //lang definitions
- 'ext_shop_no_results_2'=>$this->lang['ext_shop_no_results_2'],
- 'ext_shop_if_you'=>$this->lang['ext_shop_if_you'],
- 'ext_shop_are_you'=>$this->lang['ext_shop_are_you'],
- 'ext_shop_fullname'=>$this->lang['ext_shop_fullname'],
- 'ext_shop_total_price'=>$this->lang['ext_shop_total_price'],
- 'ext_shop_user'=>$this->lang['ext_shop_user'],
- 'ext_shop_just_date'=>$this->lang['ext_shop_just_date'],
- 'ext_shop_status'=>$this->lang['ext_shop_status'],
- 'ext_shop_set'=>$this->lang['ext_shop_set'],
- 'ext_shop_view_details'=>$this->lang['ext_shop_view_details'],
- 'ext_shop_canceled'=>$this->lang['ext_shop_canceled'],
- 'ext_shop_mark_as'=>$this->lang['ext_shop_mark_as'],
- 'ext_shop_address'=>$this->lang['ext_shop_address'],
- 'ext_shop_phone'=>$this->lang['ext_shop_phone'],
- 'ext_shop_method'=>$this->lang['ext_shop_method'],
- 'ext_shop_just_products'=>$this->lang['ext_shop_just_products'],
- ]);
- }
- public function add_cat() { //ACP
- //get all active cats
- $dbh = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cats");
- if($dbh->rowCount() > 0) {
- $cats = "";//globalize
- while($row = $dbh->fetch(PDO::FETCH_ASSOC)) {
- $cats .= "<a href='#' class='delete_cat' data-catid='".$row['id']."'>".$row['product_cat']." [DELETE]</a><br/>";
- }
- } else {
- $cats = $this->lang['ext_shop_no_cats'];
- }
- return $this->m->render(file_get_contents("ext/pok4/shop/template/add_cat_admin.html"),[
- 'all_shop_cats'=>$cats,
- //lang definitions
- 'ext_shop_submit'=>$this->lang['ext_shop_submit'],
- 'ext_shop_product_cat_name'=>$this->lang['ext_shop_product_cat_name'],
- 'ext_shop_current_cats'=>$this->lang['ext_shop_current_cats'],
- ]).$this->submit_new_cat();
- }
- public function submit_new_cat() { //ACP
- //submit new cat
- if(isset($_POST['submit_product'])) {
- $cat_name = $_POST['cat_name'];
- $go = $this->db->prepare("INSERT INTO ".$this->argos_db_prefix."shop_cats (product_cat) VALUES(?)");
- $go->bindParam(1, $cat_name, PDO::PARAM_STR);
- $go->execute();
- return '<div class="alert alert-success">'.$this->lang['ext_shop_success'].'!</div>';
- }
- }
- public function add_product() { //ACP
- //get all active cats
- $dbh = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cats");
- if($dbh->rowCount() > 0) {
- $cats = "";//globalize
- while($row = $dbh->fetch(PDO::FETCH_ASSOC)) {
- $cats .= "<option value='".$row['product_cat']."'>".$row['product_cat']."</option>";
- }
- } else {
- $cats = "<option disabled>".$this->lang['ext_shop_no_cats']."</option>";
- }
- return $this->m->render(file_get_contents("ext/pok4/shop/template/add_product_admin.html"),[
- 'all_active_cats'=>$cats,
- //lang definitions
- 'ext_shop_price_type'=>$this->lang['ext_shop_price_type'],
- 'ext_shop_product_cat'=>$this->lang['ext_shop_product_cat'],
- 'ext_shop_product_price'=>$this->lang['ext_shop_product_price'],
- 'ext_shop_availability'=>$this->lang['ext_shop_availability'],
- 'ext_shop_promo_p_price'=>$this->lang['ext_shop_promo_p_price'],
- 'ext_shop_submit'=>$this->lang['ext_shop_submit'],
- ]);
- }
- public function product_list() { //ACP
- //get all products with pagination
- $results = $this->db->query("SELECT COUNT(`id`) FROM ".$this->argos_db_prefix."shop order by product_date DESC")->fetchColumn();
- if($results > 0) {
- $pagination = pagination($results, [
- 'get_vars' => [
- 'apage' => $_GET['apage'].'&product_list=1',
- ],
- 'per_page' => 15, //how many results per page
- 'per_side' => 3,
- 'get_name' => 'page'
- ]);
- } else {
- //reset this variables to 0, to prevent errors
- $pagination['limit']['first'] = 0;
- $pagination['limit']['second'] = 0;
- }
- $get_results = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop order by product_date DESC LIMIT {$pagination['limit']['first']}, {$pagination['limit']['second']}");
- $all_products = []; //globalize
- if ($get_results->rowCount() > 0) {
- $product_appear = true; //we found results
- while ($row=$get_results->fetch(PDO::FETCH_ASSOC)) {
- $product_title = $row['product_title'];
- $product_date = date("d.m.Y, H:i",$row['product_date']);
- $product_id = $row['id'];
- $product_price = $row['product_price'];
- $product_explain = $row["product_explain"];
- $product_price_type = $row['product_price_type'];
- $product_promo_price = $row['product_promo_price'];
- if($product_promo_price > 0) {
- $product_is_promo = true;
- } else {
- $product_is_promo = false;
- }
- //get images
- $product_images = $row['product_images'];
- $product_availability = $row['product_availability'];
- $all_imgs = explode(",",$product_images);
- $print_imgs = "";//globalize
- foreach($all_imgs as $v) {
- $print_imgs .= "<img style='display:inline-block;width:160px;height:160px;' src='".url()."/ext/pok4/shop/product_images/$v' alt=''/>";
- }
- $all_products[] = ['product_availability'=>$product_availability,'product_is_promo'=>$product_is_promo,'product_title'=>$product_title,'product_date'=>$product_date,'product_id'=>$product_id,'product_price'=>$product_price,'product_price_type'=>$product_price_type,'product_promo_price'=>$product_promo_price,'product_explain'=>$product_explain,'product_images'=>$print_imgs];
- }
- } else {
- $product_appear = false; //we not found results
- }
- return $this->m->render(file_get_contents("ext/pok4/shop/template/product_list_admin.html"), [
- //variables
- 'all_products'=> new ArrayIterator($all_products),
- 'ext_shop_pagination'=>($product_appear) ? $pagination['output'] : '',
- //lang definitions
- 'ext_shop_product_title'=>$this->lang['ext_shop_product_title'],
- 'ext_shop_product_price'=>$this->lang['ext_shop_product_price'],
- 'ext_shop_price_type'=>$this->lang['ext_shop_price_type'],
- 'ext_shop_product_date'=>$this->lang['ext_shop_product_date'],
- 'ext_shop_promo_price'=>$this->lang['ext_shop_promo_price'],
- 'ext_shop_descr'=>$this->lang['ext_shop_descr'],
- 'ext_shop_availability'=>$this->lang['ext_shop_availability'],
- 'ext_shop_product_images'=>$this->lang['ext_shop_product_images'],
- 'ext_shop_close'=>$this->lang['ext_shop_close'],
- 'ext_shop_submit'=>$this->lang['ext_shop_submit'],
- 'ext_shop_no_results_2'=>$this->lang['ext_shop_no_results_2'],
- ]);
- }
- public function js_acp() {
- return $this->m->render(file_get_contents("ext/pok4/shop/template/js_admin.js"));
- }
- public function custom_page() {
- //ORDER BY numeric
- $order_by = "";//globalize
- if(isset($_COOKIE['argos_shop_order'])) {
- switch($_COOKIE['argos_shop_order']) {
- case 'price_desc': {
- $order_by = "product_price DESC";
- break;
- }
- case 'price_asc': {
- $order_by = "product_price ASC";
- break;
- }
- case 'rating_desc': {
- $order_by = "product_rating DESC";
- break;
- }
- case 'rating_asc': {
- $order_by = "product_rating ASC";
- break;
- }
- case 'buy_desc': {
- $order_by = "product_buy_count DESC";
- break;
- }
- case 'buy_asc': {
- $order_by = "product_buy_count ASC";
- break;
- }
- case 'viewc_desc': {
- $order_by = "product_view_count DESC";
- break;
- }
- case 'view_asc': {
- $order_by = "product_view_count ASC";
- break;
- }
- }
- } else {
- $order_by = "product_date DESC";
- }
- //order by cat (game)
- $where = "";//globalize
- if(isset($_COOKIE['argos_shop_order2'])) {
- $where = "WHERE product_cat='". filter_var(truncate_chars($_COOKIE['argos_shop_order2'],25,''), FILTER_SANITIZE_STRING)."'";
- }
- if(empty($_COOKIE['argos_shop_order2'])) {
- $where ="";
- }
- $results = $this->db->query("SELECT COUNT(`id`) FROM ".$this->argos_db_prefix."shop $where order by $order_by")->fetchColumn();
- if($results > 0) {
- $pagination = pagination($results, [
- 'per_page' => 15, //how many results per page
- 'per_side' => 3,
- 'get_name' => 'page'
- ]);
- } else {
- //reset this variables to 0, to prevent errors
- $pagination['limit']['first'] = 0;
- $pagination['limit']['second'] = 0;
- }
- $get_results = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop $where order by $order_by LIMIT {$pagination['limit']['first']}, {$pagination['limit']['second']}");
- $all_products = []; //globalize
- if ($get_results->rowCount() > 0) {
- $product_appear = true; //we found results
- while ($row=$get_results->fetch(PDO::FETCH_ASSOC)) {
- $product_title = $row['product_title'];
- $product_id = $row['id'];
- $product_price = $row['product_price'];
- $product_price_type = $row['product_price_type'];
- $product_promo_price = $row['product_promo_price'];
- if($product_promo_price > 0) {
- $product_is_promo = true;
- } else {
- $product_is_promo = false;
- }
- //get first img
- $product_images = $row['product_images'];
- $all_imgs = explode(",",$product_images);
- $first_img = $all_imgs[0];
- $product_cat = $row['product_cat'];
- $all_products[] = ['product_is_promo'=>$product_is_promo,'product_title'=>$product_title,'product_id'=>$product_id,'product_price'=>$product_price,'product_price_type'=>$product_price_type,'product_promo_price'=>$product_promo_price,'product_first_img'=>$first_img,'product_cat'=>$product_cat];
- }
- } else {
- $product_appear = false; //we not found results
- }
- //get available categories
- $cats = "";//globalize
- $cats_get = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cats");
- if($cats_get->rowCount() > 0) {
- while ($row=$cats_get->fetch(PDO::FETCH_ASSOC)) {
- $cats .= "<option value='".$row['product_cat']."'>".$row['product_cat']."</option>";
- }
- }
- //product view
- if(isset($_GET['view_item'])) {
- return $this->product_view();
- } else { //product list view
- //print everything to shop_list.html
- return $this->m->render(file_get_contents("ext/pok4/shop/template/shop_list.html"),[
- //variables
- 'all_products'=> new ArrayIterator($all_products),
- 'ext_shop_pagination'=>($product_appear) ? $pagination['output'] : '',
- 'not_view_product'=>!isset($_GET['view_item']),
- 'sort_by_cat'=>$cats,
- //lang definitions
- 'ext_shop_select_option'=>$this->lang['ext_shop_select_option'],
- 'ext_shop_view'=>$this->lang['ext_shop_view'],
- 'ext_shop_no_results'=>$this->lang['ext_shop_no_results'],
- 'ext_shop_price_asc'=>$this->lang['ext_shop_price_asc'],
- 'ext_shop_price_desc'=>$this->lang['ext_shop_price_desc'],
- 'ext_shop_rating_asc'=>$this->lang['ext_shop_rating_asc'],
- 'ext_shop_rating_desc'=>$this->lang['ext_shop_rating_desc'],
- 'ext_shop_buyc_asc'=>$this->lang['ext_shop_buyc_asc'],
- 'ext_shop_buyc_desc'=>$this->lang['ext_shop_buyc_desc'],
- 'ext_shop_viewc_asc'=>$this->lang['ext_shop_viewc_asc'],
- 'ext_shop_viewc_desc'=>$this->lang['ext_shop_viewc_desc'],
- 'ext_shop_sort_by1'=>$this->lang['ext_shop_sort_by1'],
- 'ext_shop_sort_by2'=>$this->lang['ext_shop_sort_by2'],
- ]);
- }
- }
- public function product_view() {
- $product_id = (int)$_GET['view_item'];
- //update view count
- $this->db->query("UPDATE ".$this->argos_db_prefix."shop SET product_view_count=product_view_count+1 WHERE id='".$product_id."'");
- //proceed
- $get_results = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop WHERE id='".$product_id."'");
- $is_items_found = "";
- if ($get_results->rowCount() > 0) {
- $is_items_found = true;
- $row=$get_results->fetch(PDO::FETCH_ASSOC);
- $product_title = $row['product_title'] ?? '';
- $product_id = $row['id'] ?? '';
- $product_price = $row['product_price'] ?? '';
- $product_price_type = $row['product_price_type'] ?? '';
- $product_promo_price = $row['product_promo_price'] ?? '';
- $product_rating = $row['product_rating'] ?? 0;
- $product_buy_count = $row['product_buy_count'] ?? 0;
- $product_availability = $row['product_availability'];
- $product_view_count = $row['product_view_count'] ?? 0;
- if($product_promo_price > 0) {
- $product_is_promo = true;
- } else {
- $product_is_promo = false;
- }
- $product_explain = $row['product_explain'] ?? '';
- $product_images = $row['product_images'] ?? '';
- $product_imgs_arr = explode(",",$product_images);
- $arr_img_products = "";//globalize
- foreach ($product_imgs_arr as $v) {
- $arr_img_products .= "<div><img src='ext/pok4/shop/product_images/$v' data-lightbox='lightbox_imgs' style='width:100%;height:160px;' alt=''/></div>";
- }
- } else {
- $is_items_found = false;
- }
- return $this->m->render(file_get_contents("ext/pok4/shop/template/product_view.html"),[
- 'is_items_found'=>$is_items_found,
- 'product_title'=>$product_title,
- 'product_id'=>$product_id,
- 'product_price'=>$product_price,
- 'product_price_type'=>$product_price_type,
- 'product_promo_price'=>$product_promo_price,
- 'product_explain'=>$product_explain,
- 'product_images'=>$arr_img_products,
- 'product_is_promo'=>$product_is_promo,
- 'product_rating'=>$product_rating,
- 'product_buy_count'=>$product_buy_count,
- 'product_availability'=>$product_availability,
- 'product_view_count'=>$product_view_count,
- 'fb_app_id'=>$this->fb_appid,
- 'fb_comm_enable'=>$this->fb_comments_enable,
- 'c_base_url'=>url(),
- //lang definitions
- 'ext_shop_descr'=>$this->lang['ext_shop_descr'],
- 'ext_shop_details'=>$this->lang['ext_shop_details'],
- 'ext_shop_buy_count'=>$this->lang['ext_shop_buy_count'],
- 'ext_shop_view_count'=>$this->lang['ext_shop_view_count'],
- 'ext_shop_availability'=>$this->lang['ext_shop_availability'],
- 'ext_shop_rating'=>$this->lang['ext_shop_rating'],
- 'ext_shop_price'=>$this->lang['ext_shop_price'],
- 'ext_shop_add_to_cart'=>$this->lang['ext_shop_add_to_cart'],
- 'ext_shop_view_basket'=>$this->lang['ext_shop_view_basket'],
- 'ext_shop_item_not_found'=>$this->lang['ext_shop_item_not_found'],
- ]);
- }
- public function js_front() {
- return $this->m->render(file_get_contents("ext/pok4/shop/template/js_front.js")); //shop
- }
- public function js_front2() {
- return $this->m->render(file_get_contents("ext/pok4/shop/template/js_front2.js"),[
- 'ext_shop_js_explain1'=>$this->lang['ext_shop_js_explain1'],
- 'ext_shop_js_explain2'=>$this->lang['ext_shop_js_explain2'],
- ]); //shop_cart
- }
- public function custom_page2() {
- //get all products
- $user_id = $this->user_id;
- $all_products = []; //globalize
- $get_all = $this->db->query("SELECT * FROM ".$this->argos_db_prefix."shop_cart s INNER JOIN ".$this->argos_db_prefix."shop g ON g.id=s.product_id WHERE user_id='".$user_id."'");
- if($get_all->rowCount() > 0) {
- while ($row=$get_all->fetch(PDO::FETCH_ASSOC)) {
- $product_title = $row['product_title'];
- $product_quantity = $row['product_quantity'] ?? 1;
- $product_price = $row['product_price'] * $product_quantity;
- $product_promo_price = $row['product_promo_price'];
- if(!empty($product_promo_price) OR $product_promo_price > 0) {
- $product_price = $row['product_promo_price'] * $product_quantity;
- }
- $product_price_type = $row['product_price_type'];
- if($product_price_type =='BGN') {
- $flag = '<img src="https://flagcdn.com/16x12/bg.png" alt="flag"/>';
- } else {
- $flag = '<img src="https://flagcdn.com/16x12/eu.png" alt="flag"/>';
- }
- $pid = $row['product_id'];
- $all_products[] = ['product_flag'=>$flag,'product_title'=>$product_title,'product_price'=>$product_price,'product_price_type'=>$product_price_type,'product_id'=>$pid,'product_quantity'=>$product_quantity];
- }
- }
- //get user balance
- $get = $this->db->query("SELECT price FROM `".$this->forum_db."`.".$this->forum_db_prefix."_users where user_id='".$user_id."'");
- $row2=$get->fetch(PDO::FETCH_ASSOC);
- return $this->m->render(file_get_contents("ext/pok4/shop/template/shopping_cart.html"),[
- 'all_products'=> new ArrayIterator($all_products),
- 'no_products'=>empty($all_products) ? $this->lang['ext_shop_no_results_2'] : '',
- 'c_base_url'=>url(),
- 'current_balance'=>$row2['price'],
- //lang definitions
- 'ext_shop_product_title'=>$this->lang['ext_shop_product_title'],
- 'ext_shop_product_price'=>$this->lang['ext_shop_product_price'],
- 'ext_shop_price_type'=>$this->lang['ext_shop_price_type'],
- 'ext_shop_product_qty'=>$this->lang['ext_shop_product_qty'],
- 'ext_shop_remove'=>$this->lang['ext_shop_remove'],
- 'ext_shop_total_price'=>$this->lang['ext_shop_total_price'],
- 'ext_shop_goto'=>$this->lang['ext_shop_goto'],
- 'ext_shop_order'=>$this->lang['ext_shop_order'],
- 'ext_shop_choose_method'=>$this->lang['ext_shop_choose_method'],
- 'ext_shop_choose_option'=>$this->lang['ext_shop_choose_option'],
- 'ext_shop_on_delivery'=>$this->lang['ext_shop_on_delivery'],
- 'ext_shop_on_curr_balance'=>$this->lang['ext_shop_on_curr_balance'],
- 'ext_shop_curr_balance'=>$this->lang['ext_shop_curr_balance'],
- 'ext_shop_with'=>$this->lang['ext_shop_with'],
- 'ext_shop_fullname'=>$this->lang['ext_shop_fullname'],
- 'ext_shop_delivery_explain'=>$this->lang['ext_shop_delivery_explain'],
- 'ext_shop_your_phone'=>$this->lang['ext_shop_your_phone'],
- 'ext_shop_submit'=>$this->lang['ext_shop_submit'],
- 'ext_shop_now'=>$this->lang['ext_shop_now'],
- ]);
- }
- public function load() {
- if (strpos($_SERVER['REQUEST_URI'], '/pages/shop') !== false) {
- $this->dispatcher->emit('core_event_inside_custom_w_menu', [$this->custom_page()]);
- $this->dispatcher->emit('core_event_head_append', ['<link rel="stylesheet" href="ext/pok4/shop/template/css.css">']);
- $this->dispatcher->emit('core_event_head_append', ['<script type="text/javascript">head.load("//cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js");</script>']);
- $this->dispatcher->emit('core_event_head_append', ['<script type="text/javascript">head.load("//cdnjs.cloudflare.com/ajax/libs/slick-lightbox/0.2.12/slick-lightbox.min.js");</script>']);
- $this->dispatcher->emit('core_event_head_append', ['<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css">']);
- $this->dispatcher->emit('core_event_head_append', ['<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.min.css">']);
- $this->dispatcher->emit('core_event_head_append', ['<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-lightbox/0.2.12/slick-lightbox.css">']);
- $this->dispatcher->emit('core_event_inside_head_ready_front', [$this->js_front()]);
- }
- if (strpos($_SERVER['REQUEST_URI'], '/pages/cart') !== false) {
- $this->dispatcher->emit('core_event_head_append', ['<script type="text/javascript">head.load("//cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.5/jquery.validate.min.js");</script>']);
- $this->dispatcher->emit('core_event_inside_custom_w_menu', [$this->custom_page2()]);
- $this->dispatcher->emit('core_event_inside_head_ready_front', [$this->js_front2()]);
- $this->dispatcher->emit('core_event_head_append', ['<script src="https://js.stripe.com/v3/"></script>']);
- }
- //admin area
- $this->dispatcher->emit('core_admin_event_custom_pages_ext', [$this->admin_form()]);
- $this->dispatcher->emit('core_admin_event_ext_pages', ['<li><a href="custom_pages_ext.php?apage=shop_config">Shop Configuration</a></li>']);
- $this->dispatcher->emit('core_admin_event_inside_script_tag', [$this->js_acp()]);
- }
- };
- $load_ext = new shop;
- $load_ext->load();
Add Comment
Please, Sign In to add comment